Navigation Menu

Skip to content

Commit

Permalink
Path: remove some more deprecated Py2 code
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Apr 26, 2021
1 parent 322e027 commit b84dcf9
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 79 deletions.
6 changes: 1 addition & 5 deletions src/Mod/Path/App/AreaPyImp.cpp
Expand Up @@ -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;
Expand Down
29 changes: 0 additions & 29 deletions src/Mod/Path/App/CommandPyImp.cpp
Expand Up @@ -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");
Expand All @@ -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);
Expand Down Expand Up @@ -179,27 +169,17 @@ 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");
}

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);
Expand All @@ -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");
}
Expand Down Expand Up @@ -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 {
Expand Down
22 changes: 3 additions & 19 deletions src/Mod/Path/App/ParamsHelper.h
Expand Up @@ -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)
Expand All @@ -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), \
Expand Down Expand Up @@ -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
*
Expand Down
4 changes: 0 additions & 4 deletions src/Mod/Path/App/PathPyImp.cpp
Expand Up @@ -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");
}
Expand Down
15 changes: 4 additions & 11 deletions src/Mod/Path/App/ToolPyImp.cpp
Expand Up @@ -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
Expand Down
15 changes: 4 additions & 11 deletions src/Mod/Path/App/TooltablePyImp.cpp
Expand Up @@ -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
Expand Down

0 comments on commit b84dcf9

Please sign in to comment.