[Python-bugs-list] [Bug #110712] MALLOC_ZERO_RETURNS_NULL problem

noreply@sourceforge.net noreply@sourceforge.net
Thu, 7 Sep 2000 14:21:07 -0700


Bug #110712, was updated on 2000-Jul-31 14:30
Here is a current snapshot of the bug.

Project: Python
Category: None
Status: Open
Resolution: None
Bug Group: Platform-specific
Priority: 5
Summary: MALLOC_ZERO_RETURNS_NULL problem

Details: Jitterbug-Id: 86
Submitted-By: Sean Dunn <sdunn@digitalanvil.com>
Date: Fri, 24 Sep 1999 14:44:22 -0500
Version: None
OS: None

The use of

    #define MALLOC_ZERO_RETURNS_NULL 1

at the top of mymalloc.h worked fine...
By curiousity.. I just tried compiling the following:

/*testmalloc.c*/
#include <stdio.h>
main()
{
    int *fp;
    int *sp;

    fp = (int*)malloc(0);
    sp = (int*)malloc(sizeof(int));
    printf("fp: %x\nsp: %x\n", fp, sp);
}
/**/

First, I just compiled normally:

> cc -o testmalloc testmalloc.c
> ./testmalloc
fp: 10015010
sp: 10015020

Then I compiled with the -lmalloc flag (libmalloc is the SGI high performance
memory library - which seems to be the default used after running the
configure script)

> cc -o testmalloc testmalloc.c
> ./testmalloc
fp: 0
sp: 10015048

So...  It looks like without libmalloc, we're actually getting memory when we
"shouldn't" - but from reading your source code it seems like that's the way
it is usually made to work (weird).  When compiling with libmalloc, the
returned 0 is triggering the MemError flag.

At ceval.c:2467, should it even get to this point if the passed in kwargs ==
{}?  It does a PyDict_Size of it, which returns 0 (which seems correct) but kw
isn't NULL.  It seems like at this point that it should be..

Sean


Guido van Rossum wrote:

> >       The builtin function apply() seems to barf on empty dictionaries
> >       when passed as the keyword list.  See the following output:
>
> > >>> apply(func, (1,), {})
> > Traceback (innermost last):
> >   File "<stdin>", line 1, in ?
> > MemoryError
> > >>>
>
> > The variable 'kwargs' in this case is {}.  The actual exception is thrown
> > at line 2467 of Python/ceval.c:
> >
> >       if (kw != NULL) {
> >               int pos, i;
> >               nk = PyDict_Size(kw);
> >
> > /* 2467 */    k = PyMem_NEW(PyObject *, 2*nk);
> > /* nk, the PyDict_Size (the size of ma_used) is 0 */
> >
> >               if (k == NULL) {
> >                       PyErr_NoMemory();
> >                       Py_DECREF(arg);
> >                       return NULL;
> >               }
> >               pos = i = 0;
> >               while (PyDict_Next(kw, &pos, &k[i], &k[i+1]))
> >                       i += 2;
> >               nk = i/2;
> >               /* XXX This is broken if the caller deletes dict items! */
> >       }
>
> Thanks very much for your detailed analysis!  The cause is probably
> that somehow the configure script doesn't compute the correct value
> for MALLOC_ZERO_RETURNS_NULL.  I don't know why; the test seems simple
> enough.  (Maybe you inherited a config.cache file from a previous Irix
> version?)  To work around this in the build, if "make clobber" and
> rerunning configure don't do the trick, add
>
>     #define MALLOC_ZERO_RETURNS_NULL 1
>
> to the top of Include/mymalloc.h.
>
> Please let me know if rerunning configure makes the bug go away; this
> will decides the classification of your bug report.
>
> --Guido van Rossum (home page: http://www.python.org/~guido/)





====================================================================
Audit trail:
Fri Sep 24 16:15:04 1999	guido	changed notes
Fri Sep 24 16:15:04 1999	guido	moved from incoming to platformbug

For detailed info, follow this link:
http://sourceforge.net/bugs/?func=detailbug&bug_id=110712&group_id=5470