[Python-Dev] Malloc interface (was: [Patches] Re: Garbage collection patches for Python (fwd)

Fredrik Lundh fredrik@pythonware.com
Mon, 14 Feb 2000 10:35:47 +0100


Vladimir Marangozov <marangoz@python.inrialpes.fr> wrote:
> > is XDEL simply a "if (p) free(p)" variant?
>=20
> Yes, see mymalloc.h.
>=20
> > 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.
>=20
> I'm aware of this, but I think Guido has included PyMem_XDEL for 2 =
reasons:
>=20
> a) it makes us foresee (and be explicit) that the pointer may be NULL
> b) if the pointer is NULL, the cost of the function call is avoided.

but if the pointer is not NULL, you end up with an
extra test.   and having read lots of python source
code lately, I'm pretty sure that's a far more common
case.

given this, and an ANSI compiler, XDEL is pretty meaning-
less.  and since Python 1.6 won't compile under a non-ANSI
compiler, I think we can require ANSI libraries too.

(if it's important to make that test inline, spell it out).

</F>