From adc5ffa803bacba951917cfcb9b77c58845733ff Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 26 Apr 2021 11:11:35 +0200 Subject: [PATCH] Path: remove some more deprecated Py2 code --- src/Mod/Path/App/AreaPyImp.cpp | 6 +----- src/Mod/Path/App/CommandPyImp.cpp | 29 ----------------------------- src/Mod/Path/App/ParamsHelper.h | 22 +++------------------- src/Mod/Path/App/PathPyImp.cpp | 4 ---- src/Mod/Path/App/ToolPyImp.cpp | 15 ++++----------- src/Mod/Path/App/TooltablePyImp.cpp | 15 ++++----------- 6 files changed, 12 insertions(+), 79 deletions(-) diff --git a/src/Mod/Path/App/AreaPyImp.cpp b/src/Mod/Path/App/AreaPyImp.cpp index db6e0b5e54..959f1f8a8b 100644 --- a/src/Mod/Path/App/AreaPyImp.cpp +++ b/src/Mod/Path/App/AreaPyImp.cpp @@ -96,13 +96,9 @@ 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; diff --git a/src/Mod/Path/App/CommandPyImp.cpp b/src/Mod/Path/App/CommandPyImp.cpp index 88bd30fce5..e4c5f0cc79 100644 --- a/src/Mod/Path/App/CommandPyImp.cpp +++ b/src/Mod/Path/App/CommandPyImp.cpp @@ -90,13 +90,8 @@ int CommandPy::PyInit(PyObject* args, PyObject* kwd) Py_ssize_t pos = 0; while (parameters && PyDict_Next(parameters, &pos, &key, &value)) { std::string ckey; -#if PY_MAJOR_VERSION >= 3 if (PyUnicode_Check(key)) { ckey = PyUnicode_AsUTF8(key); -#else - if (PyString_Check(key)) { - ckey = PyString_AsString(key); -#endif } else { PyErr_SetString(PyExc_TypeError, "The dictionary can only contain string keys"); @@ -105,13 +100,8 @@ int CommandPy::PyInit(PyObject* args, PyObject* kwd) boost::to_upper(ckey); double cvalue; -#if PY_MAJOR_VERSION >= 3 if (PyObject_TypeCheck(value,&(PyLong_Type))) { cvalue = (double)PyLong_AsLong(value); -#else - if (PyObject_TypeCheck(value,&(PyInt_Type))) { - cvalue = (double)PyInt_AsLong(value); -#endif } else if (PyObject_TypeCheck(value, &(PyFloat_Type))) { cvalue = PyFloat_AsDouble(value); @@ -179,13 +169,8 @@ void CommandPy::setParameters(Py::Dict arg) Py_ssize_t pos = 0; while (PyDict_Next(dict_copy, &pos, &key, &value)) { std::string ckey; -#if PY_MAJOR_VERSION >= 3 if (PyUnicode_Check(key)) { ckey = PyUnicode_AsUTF8(key); -#else - if (PyString_Check(key)) { - ckey = PyString_AsString(key); -#endif } else { throw Py::TypeError("The dictionary can only contain string keys"); @@ -193,13 +178,8 @@ void CommandPy::setParameters(Py::Dict arg) boost::to_upper(ckey); double cvalue; -#if PY_MAJOR_VERSION >= 3 if (PyObject_TypeCheck(value,&(PyLong_Type))) { cvalue = (double)PyLong_AsLong(value); -#else - if (PyObject_TypeCheck(value,&(PyInt_Type))) { - cvalue = (double)PyInt_AsLong(value); -#endif } else if (PyObject_TypeCheck(value, &(PyFloat_Type))) { cvalue = PyFloat_AsDouble(value); @@ -217,11 +197,7 @@ void CommandPy::setParameters(Py::Dict arg) PyObject* CommandPy::toGCode(PyObject *args) { if (PyArg_ParseTuple(args, "")) { -#if PY_MAJOR_VERSION >= 3 return PyUnicode_FromString(getCommandPtr()->toGCode().c_str()); -#else - return PyString_FromString(getCommandPtr()->toGCode().c_str()); -#endif } throw Py::TypeError("This method accepts no argument"); } @@ -301,13 +277,8 @@ int CommandPy::setCustomAttributes(const char* attr, PyObject* obj) if (isalpha(satt[0])) { boost::to_upper(satt); double cvalue; -#if PY_MAJOR_VERSION >= 3 if (PyObject_TypeCheck(obj,&(PyLong_Type))) { cvalue = (double)PyLong_AsLong(obj); -#else - if (PyObject_TypeCheck(obj,&(PyInt_Type))) { - cvalue = (double)PyInt_AsLong(obj); -#endif } else if (PyObject_TypeCheck(obj,&(PyFloat_Type))) { cvalue = PyFloat_AsDouble(obj); } else { diff --git a/src/Mod/Path/App/ParamsHelper.h b/src/Mod/Path/App/ParamsHelper.h index 88c5d9947c..7f82f7fc44 100644 --- a/src/Mod/Path/App/ParamsHelper.h +++ b/src/Mod/Path/App/ParamsHelper.h @@ -860,13 +860,8 @@ #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) PyLong_FromLong(_v) +#define PARAM_CAST_PYOBJ_long(_v) PyLong_FromLong(_v) #define PARAM_CAST_PYOBJ_double(_v) PyFloat_FromDouble(_v) #define PARAM_CAST_PYOBJ_bool(_v) ((_v)?Py_True:Py_False) @@ -877,13 +872,9 @@ /** 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), \ @@ -931,17 +922,10 @@ #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 * diff --git a/src/Mod/Path/App/PathPyImp.cpp b/src/Mod/Path/App/PathPyImp.cpp index 263fccbb23..3a6e3e94bf 100644 --- a/src/Mod/Path/App/PathPyImp.cpp +++ b/src/Mod/Path/App/PathPyImp.cpp @@ -204,11 +204,7 @@ PyObject* PathPy::toGCode(PyObject * args) { if (PyArg_ParseTuple(args, "")) { std::string result = getToolpathPtr()->toGCode(); -#if PY_MAJOR_VERSION >= 3 return PyUnicode_FromString(result.c_str()); -#else - return PyString_FromString(result.c_str()); -#endif } throw Py::TypeError("This method accepts no argument"); } diff --git a/src/Mod/Path/App/ToolPyImp.cpp b/src/Mod/Path/App/ToolPyImp.cpp index 91d42245cb..cc10d6afd3 100644 --- a/src/Mod/Path/App/ToolPyImp.cpp +++ b/src/Mod/Path/App/ToolPyImp.cpp @@ -32,17 +32,10 @@ using namespace Path; -#if PY_MAJOR_VERSION >= 3 -# define PYSTRING_FROMSTRING(str) PyUnicode_FromString(str) -# define PYINT_TYPE PyLong_Type -# define PYINT_FROMLONG(l) PyLong_FromLong(l) -# define PYINT_ASLONG(o) PyLong_AsLong(o) -#else -# define PYSTRING_FROMSTRING(str) PyString_FromString(str) -# define PYINT_TYPE PyInt_Type -# define PYINT_FROMLONG(l) PyInt_FromLong(l) -# define PYINT_ASLONG(o) PyInt_AsLong(o) -#endif +#define PYSTRING_FROMSTRING(str) PyUnicode_FromString(str) +#define PYINT_TYPE PyLong_Type +#define PYINT_FROMLONG(l) PyLong_FromLong(l) +#define PYINT_ASLONG(o) PyLong_AsLong(o) // returns a string which represents the object e.g. when printed in python diff --git a/src/Mod/Path/App/TooltablePyImp.cpp b/src/Mod/Path/App/TooltablePyImp.cpp index b20fb539c3..92da20221e 100644 --- a/src/Mod/Path/App/TooltablePyImp.cpp +++ b/src/Mod/Path/App/TooltablePyImp.cpp @@ -33,17 +33,10 @@ using namespace Path; -#if PY_MAJOR_VERSION >= 3 -# define PYSTRING_FROMSTRING(str) PyUnicode_FromString(str) -# define PYINT_TYPE PyLong_Type -# define PYINT_FROMLONG(l) PyLong_FromLong(l) -# define PYINT_ASLONG(o) PyLong_AsLong(o) -#else -# define PYSTRING_FROMSTRING(str) PyString_FromString(str) -# define PYINT_TYPE PyInt_Type -# define PYINT_FROMLONG(l) PyInt_FromLong(l) -# define PYINT_ASLONG(o) PyInt_AsLong(o) -#endif +#define PYSTRING_FROMSTRING(str) PyUnicode_FromString(str) +#define PYINT_TYPE PyLong_Type +#define PYINT_FROMLONG(l) PyLong_FromLong(l) +#define PYINT_ASLONG(o) PyLong_AsLong(o) // returns a string which represents the object e.g. when printed in python std::string TooltablePy::representation(void) const