[Python-Dev] unicode/string asymmetries

Martin v. Loewis martin@v.loewis.de
Thu, 10 Jan 2002 08:17:30 +0100


> > I think format specifiers that require explicit memory management are
> > so difficult to use that they must be avoided. I'd be in favour of
> > extending the argtuple type to include additional slots for objects
> > that go away when the tuple goes away.
> 
> I don't understand that last comment.

I was suggesting that the tuple passed to C API should not be of <type
'tuple'>, but of <type 'argtuple'>, which should have a method
add_object(o), which puts a reference to o into the tuple. Then,
whenever you want to return memory to the user, you create a string
object whose contents is that memory, and you put a reference to the
string into the argument tuple. 

The author of the C function then does not need to worry about memory
management: the memory will be deallocated when the argument tuple is
released.

Unfortunately, that approach cannot be used for the existing
conversion codes that return memory, since it is the extension's job
to release the memory; changing that would break extensions which do
properly release memory.

Regards,
Martin