py3: PyFindMethod -> GnericGetAttr

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

View File

@@ -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)

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
}