py3: path: some fixes to make path py3-compileable

This commit is contained in:
looooo
2017-05-05 15:30:13 +02:00
committed by wmayer
parent 6ba65d4d63
commit 226dd17e5f
4 changed files with 30 additions and 6 deletions

View File

@@ -58,7 +58,7 @@ PyMOD_INIT_FUNC(Path)
}
catch(const Base::Exception& e) {
PyErr_SetString(PyExc_ImportError, e.what());
return;
PyMOD_Return(NULL);
}
PyObject* pathModule = Path::initModule();

View File

@@ -416,8 +416,12 @@ private:
PyTuple_SetItem(ret,0,list);
PyTuple_SetItem(ret,1,new Base::VectorPy(
Base::Vector3d(pend.X(),pend.Y(),pend.Z())));
if(need_arc_plane)
if(need_arc_plane)
#if PY_MAJOR_VERSION < 3
PyTuple_SetItem(ret,2,PyInt_FromLong(arc_plane));
#else
PyTuple_SetItem(ret,2,PyLong_FromLong(arc_plane));
#endif
return Py::asObject(ret);
} PATH_CATCH
}

View File

@@ -92,9 +92,13 @@ static PyObject * areaGetParamsDesc(PyObject *, PyObject *args, PyObject *kwd) {
if (!PyArg_ParseTupleAndKeywords(args, kwd, "|O",kwlist,&pcObj))
return 0;
#if PY_MAJOR_VERSION < 3
if(PyObject_IsTrue(pcObj))
return PyString_FromString(PARAM_PY_DOC(NAME,AREA_PARAMS_STATIC_CONF));
#else
if(PyObject_IsTrue(pcObj))
return PyUnicode_FromString(PARAM_PY_DOC(NAME,AREA_PARAMS_STATIC_CONF));
#endif
PyObject *dict = PyDict_New();
PARAM_PY_DICT_SET_DOC(dict,NAME,AREA_PARAMS_STATIC_CONF)
return dict;

View File

@@ -858,9 +858,14 @@
#define PARAM_REF(_src,_seq) \
BOOST_PP_SEQ_FOR_EACH_I(PARAM_REF_,_src,_seq)
#if PY_MAJOR_VERSION < 3
#define PARAM_CAST_PYOBJ_short(_v) PyInt_FromLong(_v)
#define PARAM_CAST_PYOBJ_long(_v) PyInt_FromLong(_v)
#else
#define PARAM_CAST_PYOBJ_short(_v) PyLong_FromLong(_v)
#define PARAM_CAST_PYOBJ_long(_v) PyLong_FromLong(_v)
#endif
#define PARAM_CAST_PYOBJ_short(_v) PyInt_FromLong(_v)
#define PARAM_CAST_PYOBJ_long(_v) PyInt_FromLong(_v)
#define PARAM_CAST_PYOBJ_double(_v) PyFloat_FromDouble(_v)
#define PARAM_CAST_PYOBJ_bool(_v) ((_v)?Py_True:Py_False)
#define PARAM_CAST_PYOBJ_enum PARAM_CAST_PYOBJ_short
@@ -870,9 +875,13 @@
/** Stringize field to a Python string
* \ingroup ParamPy ParamStringizer
*/
#if PY_MAJOR_VERSION < 3
#define PARAM_PY_STR(_field,_param) \
PyString_FromString(PARAM_FIELD_STR(_field,_param))
#else
#define PARAM_PY_STR(_field,_param) \
PyUnicode_FromString(PARAM_FIELD_STR(_field,_param))
#endif
/** Helper for #PARAM_PY_DICT_SET_VALUE */
#define PARAM_PY_DICT_SET_VALUE_(_1,_args,_param) \
PyDict_SetItem(BOOST_PP_TUPLE_ELEM(0,_args), \
@@ -920,10 +929,17 @@
#define PARAM_PY_DICT_DOC_enum2 PARAM_PY_DICT_DOC_enum
/** Helper for #PARAM_PY_DICT_SET_DOC */
#if PY_MAJOR_VERSION < 3
#define PARAM_PY_DICT_SET_DOC_(_1,_args,_param) \
PyDict_SetItem(BOOST_PP_TUPLE_ELEM(0,_args), \
PARAM_PY_STR(BOOST_PP_TUPLE_ELEM(1,_args),_param),\
PyString_FromString(PARAM_TYPED(PARAM_PY_DICT_DOC_,_param)(_param)));
#else
#define PARAM_PY_DICT_SET_DOC_(_1,_args,_param) \
PyDict_SetItem(BOOST_PP_TUPLE_ELEM(0,_args), \
PARAM_PY_STR(BOOST_PP_TUPLE_ELEM(1,_args),_param),\
PyUnicode_FromString(PARAM_TYPED(PARAM_PY_DICT_DOC_,_param)(_param)));
#endif
/** Populate a Python dict with the doc field of the parameter sequence
*