Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 971a7aa

Browse files
committed
Change the Fini function to only remove otherwise unreferenced strings
from the interned table. There are references in hard-to-find static variables all over the interpreter, and it's not worth trying to get rid of all those; but "uninterning" isn't fair either and may cause subtle failures later -- so we have to keep them in the interned table. Also get rid of no-longer-needed insert of None in interned dict.
1 parent 1f39c5c commit 971a7aa

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

Objects/stringobject.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,8 +1043,6 @@ PyString_InternInPlace(p)
10431043
interned = PyDict_New();
10441044
if (interned == NULL)
10451045
return;
1046-
/* Force slow lookups: */
1047-
PyDict_SetItem(interned, Py_None, Py_None);
10481046
}
10491047
if ((t = PyDict_GetItem(interned, (PyObject *)s)) != NULL) {
10501048
Py_INCREF(t);
@@ -1078,10 +1076,6 @@ void
10781076
PyString_Fini()
10791077
{
10801078
int i;
1081-
#ifdef INTERN_STRINGS
1082-
Py_XDECREF(interned);
1083-
interned = NULL;
1084-
#endif
10851079
for (i = 0; i < UCHAR_MAX + 1; i++) {
10861080
Py_XDECREF(characters[i]);
10871081
characters[i] = NULL;
@@ -1090,4 +1084,20 @@ PyString_Fini()
10901084
Py_XDECREF(nullstring);
10911085
nullstring = NULL;
10921086
#endif
1087+
#ifdef INTERN_STRINGS
1088+
if (interned) {
1089+
int pos, changed;
1090+
PyObject *key, *value;
1091+
do {
1092+
changed = 0;
1093+
pos = 0;
1094+
while (PyDict_Next(interned, &pos, &key, &value)) {
1095+
if (key->ob_refcnt == 2 && key == value) {
1096+
PyDict_DelItem(interned, key);
1097+
changed = 1;
1098+
}
1099+
}
1100+
} while (changed);
1101+
}
1102+
#endif
10931103
}

0 commit comments

Comments
 (0)