From 85bb30495ee1c6f9f5d369238e7cf3b1caa8f09d Mon Sep 17 00:00:00 2001 From: looooo Date: Fri, 2 Jun 2017 11:56:38 +0200 Subject: [PATCH] py3: PyFindMethod -> GnericGetAttr issue 0000995 --- src/App/ApplicationPy.cpp | 5 +++++ src/App/ExtensionContainerPyImp.cpp | 17 +++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/App/ApplicationPy.cpp b/src/App/ApplicationPy.cpp index 70da7bbff5..af60d6d8f9 100644 --- a/src/App/ApplicationPy.cpp +++ b/src/App/ApplicationPy.cpp @@ -618,8 +618,13 @@ PyObject *Application::sSetLogLevel(PyObject * /*self*/, PyObject *args, PyObjec return NULL; PY_TRY{ int l; +#if PY_MAJOR_VERSION < 3 if (PyString_Check(pcObj)) { const char *pstr = PyString_AsString(pcObj); +#else + if (PyUnicode_Check(pcObj)) { + const char *pstr = PyUnicode_AsUTF8(pcObj); +#endif if(strcmp(pstr,"Log") == 0) l = FC_LOGLEVEL_LOG; else if(strcmp(pstr,"Warning") == 0) diff --git a/src/App/ExtensionContainerPyImp.cpp b/src/App/ExtensionContainerPyImp.cpp index 60b9797b80..9296cbdc71 100644 --- a/src/App/ExtensionContainerPyImp.cpp +++ b/src/App/ExtensionContainerPyImp.cpp @@ -122,11 +122,20 @@ PyObject *ExtensionContainerPy::getCustomAttributes(const char* attr) const // The PyTypeObject is shared by all instances of this type and therefore // we have to add new methods only once. PyObject* obj = (*it).second->getExtensionPyObject(); - PyMethodDef* meth = reinterpret_cast(obj->ob_type->tp_methods); - func = Py_FindMethod(meth, obj, attr); + PyObject *nameobj = PyUnicode_FromString(attr); + func = PyObject_GenericGetAttr(obj, nameobj); + Py_DECREF(nameobj); Py_DECREF(obj); - if (func) - break; + if (func && PyCFunction_Check(func)) { + PyCFunctionObject* cfunc = reinterpret_cast(func); + + // OK, that's what we wanted + if (cfunc->m_self == obj) + break; + // otherwise cleanup the result again + Py_DECREF(func); + func = 0; + } PyErr_Clear(); // clear the error set inside Py_FindMethod }