#include "Python.h"
#include "pycore_call.h"
#include "pycore_code.h" // CO_FAST_FREE
-#include "pycore_symtable.h" // _Py_Mangle()
#include "pycore_dict.h" // _PyDict_KeysSize()
+#include "pycore_frame.h" // _PyInterpreterFrame
#include "pycore_initconfig.h" // _PyStatus_OK()
+#include "pycore_long.h" // _PyLong_IsNegative()
#include "pycore_memoryobject.h" // _PyMemoryView_FromBufferProc()
#include "pycore_moduleobject.h" // _PyModule_GetDef()
#include "pycore_object.h" // _PyType_HasFeature()
-#include "pycore_long.h" // _PyLong_IsNegative()
#include "pycore_pyerrors.h" // _PyErr_Occurred()
#include "pycore_pystate.h" // _PyThreadState_GET()
+#include "pycore_symtable.h" // _Py_Mangle()
#include "pycore_typeobject.h" // struct type_cache
#include "pycore_unionobject.h" // _Py_union_type_or
-#include "pycore_frame.h" // _PyInterpreterFrame
+#include "pycore_weakref.h" // _PyWeakref_GET_REF()
#include "opcode.h" // MAKE_CELL
#include "structmember.h" // PyMemberDef
static inline PyTypeObject *
type_from_ref(PyObject *ref)
{
- assert(PyWeakref_CheckRef(ref));
- PyObject *obj = PyWeakref_GET_OBJECT(ref); // borrowed ref
- assert(obj != NULL);
- if (obj == Py_None) {
+ PyObject *obj = _PyWeakref_GET_REF(ref);
+ if (obj == NULL) {
return NULL;
}
- assert(PyType_Check(obj));
return _PyType_CAST(obj);
}
Py_ssize_t i = 0;
PyObject *ref; // borrowed ref
while (PyDict_Next(subclasses, &i, NULL, &ref)) {
- PyTypeObject *subclass = type_from_ref(ref); // borrowed
+ PyTypeObject *subclass = type_from_ref(ref);
if (subclass == NULL) {
continue;
}
if (PyList_Append(list, _PyObject_CAST(subclass)) < 0) {
Py_DECREF(list);
+ Py_DECREF(subclass);
return NULL;
}
+ Py_DECREF(subclass);
}
return list;
}
Py_ssize_t i = 0;
PyObject *ref;
while (PyDict_Next(subclasses, &i, NULL, &ref)) {
- PyTypeObject *subclass = type_from_ref(ref); // borrowed
+ PyTypeObject *subclass = type_from_ref(ref);
if (subclass == NULL) {
continue;
}
PyType_Modified(subclass);
+ Py_DECREF(subclass);
}
}
Py_ssize_t i = 0;
PyObject *key, *ref; // borrowed ref
while (PyDict_Next(subclasses, &i, &key, &ref)) {
- PyTypeObject *subclass = type_from_ref(ref); // borrowed
+ PyTypeObject *subclass = type_from_ref(ref);
if (subclass == NULL) {
continue;
}
// All static builtin subtypes should have been finalized already.
assert(!(subclass->tp_flags & _Py_TPFLAGS_STATIC_BUILTIN));
+ Py_DECREF(subclass);
}
clear_tp_subclasses(type);
PyObject *subclasses = lookup_tp_subclasses(base);
if (subclasses != NULL) {
while (PyDict_Next(subclasses, &i, &key, &ref)) {
- PyTypeObject *subclass = type_from_ref(ref); // borrowed
+ PyTypeObject *subclass = type_from_ref(ref);
+ if (subclass == NULL) {
+ continue;
+ }
if (subclass == type) {
+ Py_DECREF(subclass);
return Py_NewRef(key);
}
+ Py_DECREF(subclass);
}
}
/* It wasn't found. */
Py_ssize_t i = 0;
PyObject *ref;
while (PyDict_Next(subclasses, &i, NULL, &ref)) {
- PyTypeObject *subclass = type_from_ref(ref); // borrowed
+ PyTypeObject *subclass = type_from_ref(ref);
if (subclass == NULL) {
continue;
}
if (dict != NULL && PyDict_Check(dict)) {
int r = PyDict_Contains(dict, attr_name);
if (r < 0) {
+ Py_DECREF(subclass);
return -1;
}
if (r > 0) {
+ Py_DECREF(subclass);
continue;
}
}
if (update_subclasses(subclass, attr_name, callback, data) < 0) {
+ Py_DECREF(subclass);
return -1;
}
+ Py_DECREF(subclass);
}
return 0;
}