[Python-Dev] survey of extension module memory managment

Martin v. Loewis martin@v.loewis.de
19 Mar 2002 08:11:54 +0100


Neil Schemenauer <nas@python.ca> writes:

> I randomly grabbed a bunch of extension modules by searching the
> python.org topic guides and by using Parnassus.  I looked at 20
> different packages.  12 of them implemented an extension type.  12 of
> them use the memory management API incorrectly and will break if
> pymalloc is enabled.   That's worse than I thought.

It's actually better than you thought. Using PyObject_NEW is the 1.5.2
way to spell "allocate and initialize object"; it is the rename2.h
name for NEWOBJ.

Your review shows that using PyObject_New and PyObject_Del is not
common, I'd now question that there actually is real-world code that
uses them incorrectly. So here is my theory:

If PyObject_NEW becomes malloc, and PyObject_New becomes pymalloc,
nothing would break.

Regards,
Martin