Skip to content

Commit

Permalink
py3: path: some fixes to make path py3-compileable
Browse files Browse the repository at this point in the history
  • Loading branch information
looooo authored and wwmayer committed May 6, 2017
1 parent 6ba65d4 commit 226dd17
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Mod/Path/App/AppPath.cpp
Expand Up @@ -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();
Expand Down
6 changes: 5 additions & 1 deletion src/Mod/Path/App/AppPathPy.cpp
Expand Up @@ -416,8 +416,12 @@ class Module : public Py::ExtensionModule<Module>
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
}
Expand Down
6 changes: 5 additions & 1 deletion src/Mod/Path/App/AreaPyImp.cpp
Expand Up @@ -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;
Expand Down
22 changes: 19 additions & 3 deletions src/Mod/Path/App/ParamsHelper.h
Expand Up @@ -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
Expand All @@ -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), \
Expand Down Expand Up @@ -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
*
Expand Down

0 comments on commit 226dd17

Please sign in to comment.