[comp.windows.x] MALLOC_0_RETURNS_NULL

PAYNE@latlog.UUCP (06/17/88)

Is there any reason why this exists and why it is not defined?

Having spent two days tracking this down it is very frustrating to find
that this non-standard behaviour is the reason. Is this feature documented
anywhere? If it is not (and I couldn't find it) it certainly ought to be?

Julian Payne, European Silicon Structures (ES2)
(payne@latlog.uucp)

RWS@ZERMATT.LCS.MIT.EDU (Robert Scheifler) (06/17/88)

    Date: Fri, 17 Jun 88 06:46:55 -0100
    From: mcvax!latlog!PAYNE@uunet.uu.net

    Is there any reason why this exists and why it is not defined?

It exists because not all systems work the same way for malloc(0).
Handling NULL incurs an expense on all mallocs, and since V11R2 has
primarily been installed on BSD based systems rather than SVID compliant
systems, it was turned off by default.  (Also, it was put in at the last
minute before R1 shipped, and hadn't been tested, and was mostly
forgotten about since.)

    Having spent two days tracking this down it is very frustrating to find
    that this non-standard behaviour is the reason.

Unfortunately, there is more than one "standard" here.  You won't find
this behavior documented in most BSD based documentation.

    Is this feature documented anywhere?

Probably not.

    If it is not (and I couldn't find it) it certainly ought to be?

Yup.

dshr@SUN.COM (David Rosenthal) (06/17/88)

At the time we made X11R1, SVID called for malloc(0) to return 0.

I believe that we have convinced AT&T that this is less than desirable,
and that the SVID has (or will be) changed.

	David.

ado@VAX.BBN.COM (Buz Owen) (06/21/88)

Maybe this idea will be of some value to someone...  MALLOC_0_RETURNS_NULL
sounds like a compile time option that could probably be checked at startup
time, by calling malloc(0) and looking at the result, assuming it did not bomb.
There are probably are other configuration options that could be similarly
checked.  A suite of such checks could be written, probably pretty easily, and
included in some program run by make when the system is compiled, and/or in the
startup of some appropriate program, maybe the x server.  Any false assumption
would produce a helpful message about the incorrect option.