Mike Klaas schrieb:
cause problems for other users of the interned string. I agree with the reasoning, but propose a different solution: when interning an instance of a string subtype, PyString_InternInPlace could simply intern a copy.
Interning currently requires an external reference to prevent garbage collection (I believe). What will hold a reference to the string copy?
For PyString_InternInPlace, the caller will receive a reference; the original object passed in is decref'ed. A typical caller of PyString_InternInPlace will just store the reference in some global/static variable. builtin_intern will return it to the caller, which then needs to store it. This was always the case with intern(); the usage pattern is foo = intern(foo) as intern may return a different object (e.g. if the string was already interned). Regards, Martin