[Python-bugs-list] apply(): throws MemoryError when sending an {} as the keyword list (PR#85)

guido@CNRI.Reston.VA.US guido@CNRI.Reston.VA.US
Fri, 24 Sep 1999 10:46:04 -0400 (EDT)


> 	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/)