py3: PyFindMethod -> GnericGetAttr

issue 0000995
This commit is contained in:
looooo
2017-06-02 11:56:38 +02:00
committed by wmayer
parent 6ad7dc1217
commit 85bb30495e
2 changed files with 18 additions and 4 deletions

View File

@@ -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<PyMethodDef*>(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<PyCFunctionObject*>(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
}