Skip to content
Prev Previous commit
Next Next commit
more paranoid
  • Loading branch information
JelleZijlstra committed Jul 25, 2025
commit 250f3e9935d8188c27dcd91e6cb61293166475c9
13 changes: 11 additions & 2 deletions Python/sysmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2666,13 +2666,22 @@ sys__clear_type_descriptors(PyObject *module, PyObject *type)
return NULL;
}
PyObject *dict = _PyType_GetDict(typeobj);
if (PyDict_PopString(dict, "__dict__", NULL) < 0) {
PyObject *dunder_dict = NULL;
if (PyDict_PopString(dict, "__dict__", &dunder_dict) < 0) {
Comment thread
JelleZijlstra marked this conversation as resolved.
Outdated
return NULL;
}
if (PyDict_PopString(dict, "__weakref__", NULL) < 0) {
PyObject *dunder_weakref = NULL;
if (PyDict_PopString(dict, "__weakref__", &dunder_weakref) < 0) {
Comment thread
JelleZijlstra marked this conversation as resolved.
Outdated
PyType_Modified(typeobj);
Py_XDECREF(dunder_dict);
return NULL;
}
PyType_Modified(typeobj);
Comment thread
JelleZijlstra marked this conversation as resolved.
// We try to hold onto a reference to these until after we call
// PyType_Modified(), in case their deallocation triggers somer user code
// that tries to do something to the type.
Py_XDECREF(dunder_dict);
Py_XDECREF(dunder_weakref);
Py_RETURN_NONE;
}

Expand Down