Cleanup clear_static_tp_subclasses() (#106276)

Only iterate on the dictionary if Python is built with assertions:
subclass is only needed when Python is built with assertions.
This commit is contained in:
Victor Stinner 2023-06-30 12:39:55 +02:00 committed by GitHub
parent 80b3d8f337
commit 1a2652ceaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 0 deletions

View File

@ -5009,6 +5009,7 @@ clear_static_tp_subclasses(PyTypeObject *type)
going to leak. This mostly only affects embedding scenarios.
*/
#ifndef NDEBUG
// For now we just do a sanity check and then clear tp_subclasses.
Py_ssize_t i = 0;
PyObject *key, *ref; // borrowed ref
@ -5021,6 +5022,7 @@ clear_static_tp_subclasses(PyTypeObject *type)
assert(!(subclass->tp_flags & _Py_TPFLAGS_STATIC_BUILTIN));
Py_DECREF(subclass);
}
#endif
clear_tp_subclasses(type);
}