Remove dependency of hash and xalloc modules on the malloc and realloc
authorPaul Eggert <eggert@cs.ucla.edu>
Tue, 1 Jun 2004 03:49:45 +0000 (03:49 +0000)
committerPaul Eggert <eggert@cs.ucla.edu>
Tue, 1 Jun 2004 03:49:45 +0000 (03:49 +0000)
modules.

ChangeLog
lib/ChangeLog
lib/xmalloc.c
m4/ChangeLog
m4/xalloc.m4
modules/hash
modules/xalloc

index 2c7c0aea8856509c0b9e77afa7290a5644da4d6d..ed3b455f304644f908997e68a922270df2b6b2bb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2004-05-30  Paul Eggert  <eggert@cs.ucla.edu>
 
+       * modules/hash (Depends-on): Remove malloc, realloc.
+       * modules/xalloc (Depends-on): Likewise.
+
        * README: Mention that the 'free' module works around the
        problem with 'free (0)'.
        Mention LIA-1 and C99.
index a894cc13c46e40fe95fc961dc3328eb54e5d5d26..9752f1e76396db7516c5963708103d94ff3b2acc 100644 (file)
@@ -1,3 +1,10 @@
+2004-05-30  Paul Eggert  <eggert@cs.ucla.edu>
+
+       * xmalloc.c (HAVE_MALLOC, HAVE_REALLOC): Do not require these
+       macros to be defined.
+       (xnmalloc_inline, xnrealloc_inline, xcalloc): Do not die if
+       the allocator returns NULL because the requested size is zero.
+
 2004-05-20  Paul Eggert  <eggert@cs.ucla.edu>
 
        * malloc/obstack.c (_obstack) [defined _LIBC]: Bring back this
index 181006b43dbc69e40a1d6d5f167093074fe751b9..cc7501974d9771a802e5ca3afd3ac0c841bdb499 100644 (file)
@@ -1,7 +1,7 @@
 /* xmalloc.c -- malloc with out of memory checking
 
    Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2003,
-   1999, 2000, 2002, 2003 Free Software Foundation, Inc.
+   1999, 2000, 2002, 2003, 2004 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
 # define SIZE_MAX ((size_t) -1)
 #endif
 
-#ifndef HAVE_MALLOC
-"you must run the autoconf test for a GNU libc compatible malloc"
-#endif
-
-#ifndef HAVE_REALLOC
-"you must run the autoconf test for a GNU libc compatible realloc"
-#endif
-
 /* If non NULL, call this function when memory is exhausted. */
 void (*xalloc_fail_func) (void) = 0;
 
@@ -71,7 +63,7 @@ static inline void *
 xnmalloc_inline (size_t n, size_t s)
 {
   void *p;
-  if (xalloc_oversized (n, s) || ! (p = malloc (n * s)))
+  if (xalloc_oversized (n, s) || (! (p = malloc (n * s)) && n != 0))
     xalloc_die ();
   return p;
 }
@@ -96,7 +88,7 @@ xmalloc (size_t n)
 static inline void *
 xnrealloc_inline (void *p, size_t n, size_t s)
 {
-  if (xalloc_oversized (n, s) || ! (p = realloc (p, n * s)))
+  if (xalloc_oversized (n, s) || (! (p = realloc (p, n * s)) && n != 0))
     xalloc_die ();
   return p;
 }
@@ -239,7 +231,7 @@ xcalloc (size_t n, size_t s)
   void *p;
   /* Test for overflow, since some calloc implementations don't have
      proper overflow checks.  */
-  if (xalloc_oversized (n, s) || ! (p = calloc (n, s)))
+  if (xalloc_oversized (n, s) || (! (p = calloc (n, s)) && n != 0))
     xalloc_die ();
   return p;
 }
index 02d81a2765df6713136020335ac07e33c3cf95aa..909ba98990e562ab28b42662fa2bd6ba57f32247 100644 (file)
@@ -1,3 +1,8 @@
+2004-05-30  Paul Eggert  <eggert@cs.ucla.edu>
+
+       * xalloc.m4 (gl_PREREQ_XMALLOC): Do not require AC_FUNC_MALLOC
+       or AC_FUNC_REALLOC.
+
 2004-05-20  Andreas Schwab  <schwab@suse.de>
 
        * free.m4: Replace free if it not known to work, not the other
index f3d37900749d11ecc1be922691d75ba7a4472661..4d9383509fe9676de348882ece27fb3baee38d0c 100644 (file)
@@ -1,4 +1,4 @@
-# xalloc.m4 serial 8
+# xalloc.m4 serial 9
 dnl Copyright (C) 2002-2004 Free Software Foundation, Inc.
 dnl This file is free software, distributed under the terms of the GNU
 dnl General Public License.  As a special exception to the GNU General
@@ -21,8 +21,6 @@ AC_DEFUN([gl_PREREQ_XALLOC], [
 # Prerequisites of lib/xmalloc.c.
 AC_DEFUN([gl_PREREQ_XMALLOC], [
   AC_REQUIRE([AC_C_INLINE])
-  AC_REQUIRE([AC_FUNC_MALLOC])
-  AC_REQUIRE([AC_FUNC_REALLOC])
   :
 ])
 
index 6f353dc23038c878e39bceb7205eed745e5b59ee..60810045305f00e9662f23e40d48dc778156496f 100644 (file)
@@ -7,8 +7,6 @@ lib/hash.c
 m4/hash.m4
 
 Depends-on:
-malloc
-realloc
 stdbool
 
 configure.ac:
index e92d5332fc294453d7d33d63d52be4b8891a985b..5d93aa3988d0181a4820fdecfb5d5faedfd77d65 100644 (file)
@@ -8,8 +8,6 @@ lib/xstrdup.c
 m4/xalloc.m4
 
 Depends-on:
-malloc
-realloc
 error
 gettext
 exitfail