Skip to content

Commit

Permalink
Issue python#22082: Clear interned strings in slotdefs.
Browse files Browse the repository at this point in the history
  • Loading branch information
loewis committed Jul 26, 2014
1 parent 5b56150 commit 996b671
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Misc/NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Release date: TBA
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
Expand Down
20 changes: 17 additions & 3 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ _Py_IDENTIFIER(builtins);
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 '('.
Expand Down Expand Up @@ -177,6 +180,7 @@ void
_PyType_Fini(void)
{
PyType_ClearCache();
clear_slotdefs();
}

void
Expand Down Expand Up @@ -6508,15 +6512,15 @@ update_slots_callback(PyTypeObject *type, void *data)
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. */
Expand All @@ -6525,7 +6529,17 @@ init_slotdefs(void)
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. */
Expand Down

0 comments on commit 996b671

Please sign in to comment.