[Python-checkins] cpython: Issue #22082: Clear interned strings in slotdefs.

martin.v.loewis python-checkins at python.org
Sat Jul 26 16:44:20 CEST 2014


http://hg.python.org/cpython/rev/c55300337932
changeset:   91883:c55300337932
user:        Martin v. Löwis <martin at v.loewis.de>
date:        Sat Jul 26 16:44:07 2014 +0200
summary:
  Issue #22082: Clear interned strings in slotdefs.

files:
  Misc/NEWS            |   2 ++
  Objects/typeobject.c |  22 ++++++++++++++++++----
  2 files changed, 20 insertions(+), 4 deletions(-)


diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,8 @@
 Core and Builtins
 -----------------
 
+- Issue #22082: Clear interned strings in slotdefs.
+
 - Upgrade Unicode database to Unicode 7.0.0.
 
 - Issue #21897: Fix a crash with the f_locals attribute with closure
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -54,6 +54,9 @@
 static PyObject *
 slot_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
 
+static void
+clear_slotdefs();
+
 /*
  * finds the beginning of the docstring's introspection signature.
  * if present, returns a pointer pointing to the first '('.
@@ -177,6 +180,7 @@
 _PyType_Fini(void)
 {
     PyType_ClearCache();
+    clear_slotdefs();
 }
 
 void
@@ -6508,15 +6512,15 @@
     return 0;
 }
 
+static int slotdefs_initialized = 0;
 /* Initialize the slotdefs table by adding interned string objects for the
    names. */
 static void
 init_slotdefs(void)
 {
     slotdef *p;
-    static int initialized = 0;
-
-    if (initialized)
+
+    if (slotdefs_initialized)
         return;
     for (p = slotdefs; p->name; p++) {
         /* Slots must be ordered by their offset in the PyHeapTypeObject. */
@@ -6525,7 +6529,17 @@
         if (!p->name_strobj)
             Py_FatalError("Out of memory interning slotdef names");
     }
-    initialized = 1;
+    slotdefs_initialized = 1;
+}
+
+/* Undo init_slotdefs, releasing the interned strings. */
+static void clear_slotdefs()
+{
+    slotdef *p;
+    for (p = slotdefs; p->name; p++) {
+        Py_CLEAR(p->name_strobj);
+    }
+    slotdefs_initialized = 0;
 }
 
 /* Update the slots after assignment to a class (type) attribute. */

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list