PyAPI: use _PyObject_LookupAttr

Unlike PyObject_GetAttr, this avoids setting the attribute error
only to clear it - under some conditions.
This commit is contained in:
2019-02-04 23:35:23 +11:00
parent 6b2a91efff
commit ff2dd59d4a

View File

@@ -8253,11 +8253,9 @@ static PyObject *pyrna_register_class(PyObject *UNUSED(self), PyObject *py_class
return NULL; return NULL;
/* call classed register method () */ /* call classed register method () */
py_cls_meth = PyObject_GetAttr(py_class, bpy_intern_str_register); switch (_PyObject_LookupAttr(py_class, bpy_intern_str_register, &py_cls_meth)) {
if (py_cls_meth == NULL) { case 1:
PyErr_Clear(); {
}
else {
PyObject *ret = PyObject_CallObject(py_cls_meth, NULL); PyObject *ret = PyObject_CallObject(py_cls_meth, NULL);
if (ret) { if (ret) {
Py_DECREF(ret); Py_DECREF(ret);
@@ -8265,6 +8263,12 @@ static PyObject *pyrna_register_class(PyObject *UNUSED(self), PyObject *py_class
else { else {
return NULL; return NULL;
} }
break;
}
case -1:
{
return NULL;
}
} }
Py_RETURN_NONE; Py_RETURN_NONE;
@@ -8353,11 +8357,9 @@ static PyObject *pyrna_unregister_class(PyObject *UNUSED(self), PyObject *py_cla
} }
/* call classed unregister method */ /* call classed unregister method */
py_cls_meth = PyObject_GetAttr(py_class, bpy_intern_str_unregister); switch (_PyObject_LookupAttr(py_class, bpy_intern_str_unregister, &py_cls_meth)) {
if (py_cls_meth == NULL) { case 1:
PyErr_Clear(); {
}
else {
PyObject *ret = PyObject_CallObject(py_cls_meth, NULL); PyObject *ret = PyObject_CallObject(py_cls_meth, NULL);
if (ret) { if (ret) {
Py_DECREF(ret); Py_DECREF(ret);
@@ -8365,6 +8367,12 @@ static PyObject *pyrna_unregister_class(PyObject *UNUSED(self), PyObject *py_cla
else { else {
return NULL; return NULL;
} }
break;
}
case -1:
{
return NULL;
}
} }
/* should happen all the time but very slow */ /* should happen all the time but very slow */