[Python-Dev] Malloc interface (was: [Patches] Re: Garbage collection patches for Python (fwd)
Fredrik Lundh
fredrik@pythonware.com
Thu, 10 Feb 2000 15:38:35 +0100
Vladimir Marangozov wrote:
> The goal is to remove Python's dependency on the standard POSIX =
interface
> (malloc/realloc/free) so that we can cleanly and easily plug in the =
future
> a "proprietary" mem manager, other than the one in the C library.
(hmm. I've been forced to use interfaces like this a lot, but
never ever stumbled upon a situation where we couldn't just
tweak malloc/free to mean what we wanted, either by relinking
or via the preprocessor. I'm sceptical, in other words...)
> For this purpose, the Python core should be patched and "cleaned" to =
use
> one or more of the following APIs:
>=20
> 1) PyMem_MALLOC 2) PyMem_NEW =20
> PyMem_REALLOC =3D=3D> PyMem_RESIZE
> PyMem_FREE PyMem_DEL
> PyMem_XDEL
is XDEL simply a "if (p) free(p)" variant?
if so, don't forget that ANSI C requires that free() does the right
thing if handled a NULL pointer. since Python 1.6 will be ANSI C,
it's probably better to force users of broken platforms to work
around bugs in PyMem_FREE, rather than expose two different
alternatives. I'm pretty sure there are standard macros for auto-
conf that tests for this.
in other words,=20
> > ! if (md->off_num) free(md->off_num);=20
> > ! if (md->offset_top) free(md->offset_top);=20
> > ! if (md->r1) free(md->r1);=20
> > ! if (md->r2) free(md->r2);=20
> > ! if (md->eptr) free((char *)md->eptr);=20
> > ! if (md->ecode) free((char *)md->ecode);
would become:
> > ! PyMem_FREE(md->off_num);=20
> > ! PyMem_FREE(md->offset_top);=20
> > ! PyMem_FREE(md->r1);=20
> > ! PyMem_FREE(md->r2);=20
> > ! PyMem_FREE(md->eptr);=20
> > ! PyMem_FREE(md->ecode);
</F>