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

Vladimir Marangozov Vladimir.Marangozov@inrialpes.fr
Mon, 14 Feb 2000 11:18:27 +0100 (CET)


Fredrik Lundh wrote:
> 
> Vladimir Marangozov <marangoz@python.inrialpes.fr> wrote:
> > > is XDEL simply a "if (p) free(p)" variant?
> > 
> > Yes, see mymalloc.h.
> > 
> > > 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.
> > 
> > I'm aware of this, but I think Guido has included PyMem_XDEL for 2 reasons:
> > 
> > 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.

PyMem_XDEL is very rare in the distribution...

> 
> 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.

Okay, so you can use PyMem_DEL directly.

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

PyMem_XDEL spells it out, but the choice is to the programmer.

If your point is to remove it, or to rename it to PyMem_DEL in
the distribution, well, Guido has to speak up (but I doubt he'll
remove it, for backwards compatibility reasons -- 3rd party extensions
may have used it).

-- 
       Vladimir MARANGOZOV          | Vladimir.Marangozov@inrialpes.fr
http://sirac.inrialpes.fr/~marangoz | tel:(+33-4)76615277 fax:76615252