Skip to content

Commit

Permalink
fix: Use PyType_GetDict instead of NULL check
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher-Chianelli committed Oct 3, 2023
1 parent ce35bba commit 92b285a
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions native/python/pyjp_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,26 +174,22 @@ PyObject* PyJP_GetAttrDescriptor(PyTypeObject *type, PyObject *attr_name)
for (Py_ssize_t i = 0; i < n; ++i)
{
PyTypeObject *type2 = (PyTypeObject*) PyTuple_GetItem(mro, i);
if (type2->tp_dict != NULL) {
PyObject *res = PyDict_GetItem(type2->tp_dict, attr_name);
if (res)
{
Py_INCREF(res);
return res;
}
}
PyObject *res = PyDict_GetItem(PyType_GetDict(type2), attr_name);
if (res)
{
Py_INCREF(res);
return res;
}
}

// Last check is id in the parent
{
if (Py_TYPE(type)->tp_dict != NULL) {
PyObject *res = PyDict_GetItem(Py_TYPE(type)->tp_dict, attr_name);
if (res)
{
Py_INCREF(res);
return res;
}
}
PyObject *res = PyDict_GetItem(PyType_GetDict(Py_TYPE(type)), attr_name);
if (res)
{
Py_INCREF(res);
return res;
}
}

return NULL;
Expand Down

0 comments on commit 92b285a

Please sign in to comment.