Re: Building Python 0.9.7b for IBM/AIX-6000 with GL support

Guido.van.Rossum@cwi.nl
Mon, 21 Dec 1992 22:22:07 +0100

>Most of the python/demo/sgi/gl programs appear to work except for nurbs,
>which gives this error message:
>
>> $ python nurbs.py
>> MemoryError
>> Stack backtrace (innermost last):
>> File "nurbs.py", line 171
>> main()
>> File "nurbs.py", line 77
>> make_lights()
>> File "nurbs.py", line 152
>> lmdef(DEFLMODEL,1,[])

By sheer coincidence I ran into this myself the other day. God knows
how long it has been there waiting until I tried those old demos
again!

The cause is simple: the empty list [] is being copied to a malloc'ed
array of floats which causes a call to malloc(0). This returns NULL on
some systems, and of course the check for malloc errors takes that as
an error return. This can happen in other situations too.

As a temporary measure (though this is a waste of some memory), I
added 1 to the malloc and realloc arguments in the definitions of NEW
and RENEW in [my]malloc.h (the file's name changed at I don't know
which release):

/* XXX Always allocate one extra byte, since some malloc's return NULL
XXX for malloc(0) or realloc(p, 0). */
#define NEW(type, n) ( (type *) malloc(1 + (n) * sizeof(type)) )
#define RESIZE(p, type, n) \
if ((p) == NULL) \
(p) = (type *) malloc(1 + (n) * sizeof(type)); \
else \
(p) = (type *) realloc((ANY *)(p), 1 + (n) * sizeof(type))

Eventually I'll probably use a less wasteful fix (Python is a really
heavy malloc user and every byte counts!).

I wonder -- will I really have to use a configure script like the GNU
software uses? I'd much rather write portable code that doesn't need
to be configured, but I hate it if it gets wasteful that way...

--Guido van Rossum, CWI, Amsterdam <guido@cwi.nl>
"The man from the cat-detector van."