[Python-checkins] Cleanup clear_static_tp_subclasses() (#106276)

vstinner webhook-mailer at python.org
Fri Jun 30 06:39:59 EDT 2023


https://github.com/python/cpython/commit/1a2652ceaa55190a0b860abd1448095eafbdf238
commit: 1a2652ceaa55190a0b860abd1448095eafbdf238
branch: main
author: Victor Stinner <vstinner at python.org>
committer: vstinner <vstinner at python.org>
date: 2023-06-30T10:39:55Z
summary:

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.

files:
M Objects/typeobject.c

diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index cc389bc3d6fa..e67945db9af3 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -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);
 }



More information about the Python-checkins mailing list