py3: ported Path to python3
This commit is contained in:
@@ -363,11 +363,19 @@ int TooltablePy::PyInit(PyObject* args, PyObject* /*kwd*/)
|
||||
PyObject *key, *value;
|
||||
Py_ssize_t pos = 0;
|
||||
while (PyDict_Next(pcObj, &pos, &key, &value)) {
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
if ( !PyObject_TypeCheck(key,&(PyLong_Type)) || !PyObject_TypeCheck(value,&(Path::ToolPy::Type)) ) {
|
||||
#else
|
||||
if ( !PyObject_TypeCheck(key,&(PyInt_Type)) || !PyObject_TypeCheck(value,&(Path::ToolPy::Type)) ) {
|
||||
#endif
|
||||
PyErr_SetString(PyExc_TypeError, "The dictionary can only contain int:tool pairs");
|
||||
return -1;
|
||||
}
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
int ckey = (int)PyLong_AsLong(key);
|
||||
#else
|
||||
int ckey = (int)PyInt_AsLong(key);
|
||||
#endif
|
||||
Path::Tool &tool = *static_cast<Path::ToolPy*>(value)->getToolPtr();
|
||||
getTooltablePtr()->setTool(tool,ckey);
|
||||
}
|
||||
@@ -397,7 +405,11 @@ Py::Dict TooltablePy::getTools(void) const
|
||||
PyObject *dict = PyDict_New();
|
||||
for(std::map<int,Path::Tool*>::iterator i = getTooltablePtr()->Tools.begin(); i != getTooltablePtr()->Tools.end(); ++i) {
|
||||
PyObject *tool = new Path::ToolPy(i->second);
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
PyDict_SetItem(dict,PyLong_FromLong(i->first),tool);
|
||||
#else
|
||||
PyDict_SetItem(dict,PyInt_FromLong(i->first),tool);
|
||||
#endif
|
||||
}
|
||||
return Py::Dict(dict);
|
||||
}
|
||||
@@ -409,8 +421,13 @@ void TooltablePy::setTools(Py::Dict arg)
|
||||
PyObject *key, *value;
|
||||
Py_ssize_t pos = 0;
|
||||
while (PyDict_Next(dict_copy, &pos, &key, &value)) {
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
if ( PyObject_TypeCheck(key,&(PyLong_Type)) && (PyObject_TypeCheck(value,&(Path::ToolPy::Type))) ) {
|
||||
int ckey = (int)PyLong_AsLong(key);
|
||||
#else
|
||||
if ( PyObject_TypeCheck(key,&(PyInt_Type)) && (PyObject_TypeCheck(value,&(Path::ToolPy::Type))) ) {
|
||||
int ckey = (int)PyInt_AsLong(key);
|
||||
#endif
|
||||
Path::Tool &tool = *static_cast<Path::ToolPy*>(value)->getToolPtr();
|
||||
getTooltablePtr()->setTool(tool,ckey);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user