[Python-Dev] Alternative implementation of string interning

Jack Jansen Jack.Jansen@cwi.nl
Tue, 2 Jul 2002 16:37:42 +0200


On Tuesday, July 2, 2002, at 03:57 , Oren Tirosh wrote:
>> Uhm... I'm confused: macimport stores a pointer to the object if it's
>> interned (the object in question is one of the strings in sys.path). It
>> didn't INCREF the object, and that wasn't needed up until now because
>> interned objects can never go away. However, if they can go away I 
>> would
>> think that storing a pointer would definitely call for an INCREF...
>
> Are you saying that this code is not following reference counting rules
> and got away with it only because interned strings are immortal?

I'm afraid so. Or, actually, "afraid so" sounds too apologetic:-): 
interned
strings were specifically defined to be immortal.

> I don't see how adding only an incref could be correct - there must be a
> corresponding decref somewhere.

No, there isn't, because this list of pointers is never cleared. Which 
was never
needed, because they were borrowed references.

Again, it isn't rocket science to fix this: _PyImport_Fini() will need 
to call
out to a new routine _PyMacImport_Fini() that DECREFs the stored 
pointers.
--
- Jack Jansen        <Jack.Jansen@oratrix.com>        
http://www.cwi.nl/~jack -
- If I can't dance I don't want to be part of your revolution -- Emma 
Goldman -