diff options
author | Guido van Rossum <guido@python.org> | 1997-08-05 02:15:12 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1997-08-05 02:15:12 (GMT) |
commit | 971a7aaeac7b9c817ca68f11701b97bbd9aa54ab (patch) | |
tree | 3bd28d65c1111b2c3093fbc84131ca9542d519f8 | |
parent | 1f39c5c666ce8ede33b989aa816ed947affd1f7b (diff) | |
download | cpython-971a7aaeac7b9c817ca68f11701b97bbd9aa54ab.zip cpython-971a7aaeac7b9c817ca68f11701b97bbd9aa54ab.tar.gz cpython-971a7aaeac7b9c817ca68f11701b97bbd9aa54ab.tar.bz2 |
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.
-rw-r--r-- | Objects/stringobject.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/Objects/stringobject.c b/Objects/stringobject.c index 40dfc9e..cb37038 100644 --- a/Objects/stringobject.c +++ b/Objects/stringobject.c @@ -1043,8 +1043,6 @@ PyString_InternInPlace(p) 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 @@ void 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 @@ PyString_Fini() 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 } |