[Python-Dev] Alternative implementation of string interning

Oren Tirosh oren-py-d@hishome.net
Tue, 2 Jul 2002 09:57:56 -0400


On Tue, Jul 02, 2002 at 03:25:20PM +0200, Jack Jansen wrote:
> 
> On Tuesday, Jul 2, 2002, at 12:37 Europe/Amsterdam, Oren Tirosh wrote:
> >>The macimport code relies on the ids remaining the same. But it is easy
> >>to fix (just add an incref). I'll also change it to use
> >>PyString_CheckInterned.
> >
> >No, an incref there would leak references.  Nothing needs to be changed.
> >
> 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 don't see how adding only an incref could be correct - there must be a
corresponding decref somewhere.

	Oren