Mercurial > cpython-lru_cache-weakref
diff Objects/stringobject.c @ 5935:d77d3b8e86b2 legacy-trunk
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.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Tue, 05 Aug 1997 02:15:12 +0000 |
| parents | 5fb30413b93b |
| children | 82cd2baa4136 |
line wrap: on
line diff
--- a/Objects/stringobject.c Tue Aug 05 02:11:41 1997 +0000 +++ b/Objects/stringobject.c Tue Aug 05 02:15:12 1997 +0000 @@ -1043,8 +1043,6 @@ interned = PyDict_New(); if (interned == NULL) return; - /* Force slow lookups: */ - PyDict_SetItem(interned, Py_None, Py_None); } if ((t = PyDict_GetItem(interned, (PyObject *)s)) != NULL) { Py_INCREF(t); @@ -1078,10 +1076,6 @@ PyString_Fini() { int i; -#ifdef INTERN_STRINGS - Py_XDECREF(interned); - interned = NULL; -#endif for (i = 0; i < UCHAR_MAX + 1; i++) { Py_XDECREF(characters[i]); characters[i] = NULL; @@ -1090,4 +1084,20 @@ Py_XDECREF(nullstring); nullstring = NULL; #endif +#ifdef INTERN_STRINGS + if (interned) { + int pos, changed; + PyObject *key, *value; + do { + changed = 0; + pos = 0; + while (PyDict_Next(interned, &pos, &key, &value)) { + if (key->ob_refcnt == 2 && key == value) { + PyDict_DelItem(interned, key); + changed = 1; + } + } + } while (changed); + } +#endif }
