About Xalloc()/Xfree() function used in liblbxutil library.

Bernardo Innocenti bernie at codewiz.org
Wed Sep 19 06:33:25 PDT 2007

Joerg Sonnenberger wrote:

> On Mon, Sep 17, 2007 at 02:01:21PM +0900, Tadashi Koike wrote:
>> On this research, I understood that Xalloc()/Xfree() are same as
>> malloc()/free() except that an memory allocation size be specified
>> as ZERO  by caller. But sorry I couldn't understand a difference of
>> behavior on failure.
> malloc(0) can implement one of two behaviours according to POSIX:
> (a) It can return NULL.
> (b) It can return a unique pointer.
> It is up to the implementation which one it does. A bunch of code in X11
> depends on the second behaviour and the easiest way to force that is to
> turn malloc(0) into malloc(1). That is precisely what this code does.

Autoconf has a much cleaner way to deal with this problem.

If we check for malloc with AC_FUNC_MALLOC, it automatically
replaces it with the appropriate wrapper code.

It may be worthwhile to migrate to this mechanism, if only
to make X code look more like ordinary ANSI C to newcomers.

   //  Bernardo Innocenti - http://www.codewiz.org/
 \X/ One Laptop Per Child - http://www.laptop.org/

More information about the xorg mailing list