[Python-Dev] Alternative implementation of interning

Guido van Rossum guido@python.org
Fri, 16 Aug 2002 15:08:58 -0400

[I wrote]
> Maybe we can add even detect the abusing cases by putting a test in
> PyString_InternInPlace() like this:
> if (s->ob_refcnt == 1) {
>     PyErr_Warn(PyExc_DeprecationWarning,
>                "interning won't keep your string alive");
>     PyErr_Clear(); /* In case the warning was an error, ignore it */
>     Py_INCREF(s); /* Make s immortal */
> }

I tried this, and alas it doesn't work; there are many legit places
where there's only one reference.  So we'll have to use more
traditional ways of tracking down C code that makes assumptions of
immortality so it can drop its own reference.  (Apart from
getclassname() I've seen none.)

--Guido van Rossum (home page: http://www.python.org/~guido/)