Skip to content

Commit

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

// Last check is id in the parent
{
PyObject *res = PyDict_GetItem(Py_TYPE(type)->tp_dict, attr_name);
if (res)
{
Py_INCREF(res);
return res;
}
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;
}
}
}

return NULL;
Expand Down

0 comments on commit ce35bba

Please sign in to comment.