bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Fix malloc, calloc, realloc


From: Bruno Haible
Subject: Re: Fix malloc, calloc, realloc
Date: Sun, 29 Aug 2010 21:19:17 +0200
User-agent: KMail/1.9.9

Hello Ralf,

> Please note that the last patch from my series (or an equivalent fix
> which is acceptable to Bruno) is still needed for things to work on AIX.

Oh, that wasn't clear to me, after you had retracted parts of your statements.

Your patch is a little bit overkill, however, for situations where the
replacement is needed for malloc-posix (like on mingw) and no 'malloc-gnu'
module has been asked for. I'm applying this instead:


2010-08-29  Ralf Wildenhues <address@hidden>
            Bruno Haible  <address@hidden>

        Make the module 'malloc-gnu' work again on AIX and OSF/1.
        * m4/malloc.m4 (gl_FUNC_MALLOC_GNU): Define HAVE_MALLOC_GNU instead of
        HAVE_MALLOC.
        * lib/malloc.c (NEED_MALLOC_GNU): Enable behaviour also when
        GNULIB_MALLOC_GNU && !HAVE_MALLOC_GNU.
        * modules/malloc-gnu (configure.ac): Use gl_MODULE_INDICATOR.

diff --git a/lib/malloc.c b/lib/malloc.c
index f236f37..8f849b4 100644
--- a/lib/malloc.c
+++ b/lib/malloc.c
@@ -21,8 +21,11 @@
 #include <config.h>
 /* Only the AC_FUNC_MALLOC macro defines 'malloc' already in config.h.  */
 #ifdef malloc
-# define NEED_MALLOC_GNU
+# define NEED_MALLOC_GNU 1
 # undef malloc
+/* Whereas the gnulib module 'malloc-gnu' defines HAVE_MALLOC_GNU.  */
+#elif GNULIB_MALLOC_GNU && !HAVE_MALLOC_GNU
+# define NEED_MALLOC_GNU 1
 #endif
 
 /* Specification.  */
@@ -41,7 +44,7 @@ rpl_malloc (size_t n)
 {
   void *result;
 
-#ifdef NEED_MALLOC_GNU
+#if NEED_MALLOC_GNU
   if (n == 0)
     n = 1;
 #endif
diff --git a/m4/malloc.m4 b/m4/malloc.m4
index 56fd25e..7a74925 100644
--- a/m4/malloc.m4
+++ b/m4/malloc.m4
@@ -1,4 +1,4 @@
-# malloc.m4 serial 11
+# malloc.m4 serial 12
 dnl Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -13,10 +13,10 @@ AC_DEFUN([gl_FUNC_MALLOC_GNU],
   AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
   dnl _AC_FUNC_MALLOC_IF is defined in Autoconf.
   _AC_FUNC_MALLOC_IF(
-    [AC_DEFINE([HAVE_MALLOC], [1],
+    [AC_DEFINE([HAVE_MALLOC_GNU], [1],
                [Define to 1 if your system has a GNU libc compatible 'malloc'
                 function, and to 0 otherwise.])],
-    [AC_DEFINE([HAVE_MALLOC], [0])
+    [AC_DEFINE([HAVE_MALLOC_GNU], [0])
      gl_REPLACE_MALLOC
     ])
 ])
diff --git a/modules/malloc-gnu b/modules/malloc-gnu
index eb6ab6a..7cb21b8 100644
--- a/modules/malloc-gnu
+++ b/modules/malloc-gnu
@@ -14,7 +14,7 @@ malloc-posix
 
 configure.ac:
 gl_FUNC_MALLOC_GNU
-AC_DEFINE([GNULIB_MALLOC_GNU], 1, [Define to indicate the 'malloc' module.])
+gl_MODULE_INDICATOR([malloc-gnu])
 
 Makefile.am:
 


2010-08-29  Ralf Wildenhues <address@hidden>
            Bruno Haible  <address@hidden>

        Make the module 'calloc-gnu' work again on AIX and OSF/1.
        * m4/calloc.m4 (gl_FUNC_CALLOC_GNU): Define HAVE_CALLOC_GNU instead of
        HAVE_CALLOC.
        * lib/xmalloc.c: Update accordingly.
        * lib/calloc.c (NEED_CALLOC_GNU): Enable also when
        GNULIB_CALLOC_GNU && !HAVE_CALLOC_GNU.
        * modules/calloc-gnu (configure.ac): Invoke gl_MODULE_INDICATOR.

diff --git a/lib/calloc.c b/lib/calloc.c
index d28e158..22451e4 100644
--- a/lib/calloc.c
+++ b/lib/calloc.c
@@ -20,8 +20,11 @@
 #include <config.h>
 /* Only the AC_FUNC_CALLOC macro defines 'calloc' already in config.h.  */
 #ifdef calloc
-# define NEED_CALLOC_GNU
+# define NEED_CALLOC_GNU 1
 # undef calloc
+/* Whereas the gnulib module 'calloc-gnu' defines HAVE_CALLOC_GNU.  */
+#elif GNULIB_CALLOC_GNU && !HAVE_CALLOC_GNU
+# define NEED_CALLOC_GNU 1
 #endif
 
 /* Specification.  */
@@ -40,7 +43,7 @@ rpl_calloc (size_t n, size_t s)
 {
   void *result;
 
-#ifdef NEED_CALLOC_GNU
+#if NEED_CALLOC_GNU
   if (n == 0 || s == 0)
     {
       n = 1;
diff --git a/lib/xmalloc.c b/lib/xmalloc.c
index ecce529..f06d44f 100644
--- a/lib/xmalloc.c
+++ b/lib/xmalloc.c
@@ -30,8 +30,8 @@
 
 /* 1 if calloc is known to be compatible with GNU calloc.  This
    matters if we are not also using the calloc module, which defines
-   HAVE_CALLOC and supports the GNU API even on non-GNU platforms.  */
-#if defined HAVE_CALLOC || defined __GLIBC__
+   HAVE_CALLOC_GNU and supports the GNU API even on non-GNU platforms.  */
+#if defined HAVE_CALLOC_GNU || defined __GLIBC__
 enum { HAVE_GNU_CALLOC = 1 };
 #else
 enum { HAVE_GNU_CALLOC = 0 };
diff --git a/m4/calloc.m4 b/m4/calloc.m4
index e62da1e..7a58967 100644
--- a/m4/calloc.m4
+++ b/m4/calloc.m4
@@ -1,4 +1,4 @@
-# calloc.m4 serial 10
+# calloc.m4 serial 11
 
 # Copyright (C) 2004-2010 Free Software Foundation, Inc.
 # This file is free software; the Free Software Foundation
@@ -35,10 +35,10 @@ AC_DEFUN([gl_FUNC_CALLOC_GNU],
 [
   AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
   _AC_FUNC_CALLOC_IF(
-    [AC_DEFINE([HAVE_CALLOC], [1],
+    [AC_DEFINE([HAVE_CALLOC_GNU], [1],
                [Define to 1 if your system has a GNU libc compatible `calloc'
                 function, and to 0 otherwise.])],
-    [AC_DEFINE([HAVE_CALLOC], [0])
+    [AC_DEFINE([HAVE_CALLOC_GNU], [0])
      gl_REPLACE_CALLOC
     ])
 ])# gl_FUNC_CALLOC_GNU
diff --git a/modules/calloc-gnu b/modules/calloc-gnu
index 07378b4..734d973 100644
--- a/modules/calloc-gnu
+++ b/modules/calloc-gnu
@@ -10,6 +10,7 @@ calloc-posix
 
 configure.ac:
 gl_FUNC_CALLOC_GNU
+gl_MODULE_INDICATOR([calloc-gnu])
 
 Makefile.am:
 


2010-08-29  Ralf Wildenhues <address@hidden>
            Bruno Haible  <address@hidden>

        Make the module 'realloc-gnu' work again on AIX and OSF/1.
        * m4/realloc.m4 (gl_FUNC_REALLOC_GNU): Define HAVE_REALLOC_GNU instead
        of HAVE_REALLOC.
        * lib/realloc.c (NEED_REALLOC_GNU): Enable behaviour also when
        GNULIB_REALLOC_GNU && !HAVE_REALLOC_GNU.
        (SYSTEM_MALLOC_GLIBC_COMPATIBLE): Adjust definition.
        * modules/realloc-gnu (configure.ac): Use gl_MODULE_INDICATOR.

diff --git a/lib/realloc.c b/lib/realloc.c
index 36aeecc..053208f 100644
--- a/lib/realloc.c
+++ b/lib/realloc.c
@@ -23,11 +23,14 @@
 /* Only the AC_FUNC_REALLOC macro defines 'realloc' already in config.h.  */
 #ifdef realloc
 # define NEED_REALLOC_GNU 1
+/* Whereas the gnulib module 'realloc-gnu' defines HAVE_REALLOC_GNU.  */
+#elif GNULIB_REALLOC_GNU && !HAVE_REALLOC_GNU
+# define NEED_REALLOC_GNU 1
 #endif
 
 /* Infer the properties of the system's malloc function.
-   Only the AC_FUNC_MALLOC macro defines 'malloc' already in config.h.  */
-#if GNULIB_MALLOC_GNU && !defined malloc
+   The gnulib module 'malloc-gnu' defines HAVE_MALLOC_GNU.  */
+#if GNULIB_MALLOC_GNU && HAVE_MALLOC_GNU
 # define SYSTEM_MALLOC_GLIBC_COMPATIBLE 1
 #endif
 
diff --git a/m4/realloc.m4 b/m4/realloc.m4
index 3e97b1d..01c1234 100644
--- a/m4/realloc.m4
+++ b/m4/realloc.m4
@@ -1,4 +1,4 @@
-# realloc.m4 serial 10
+# realloc.m4 serial 11
 dnl Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -13,10 +13,10 @@ AC_DEFUN([gl_FUNC_REALLOC_GNU],
   AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
   dnl _AC_FUNC_REALLOC_IF is defined in Autoconf.
   _AC_FUNC_REALLOC_IF(
-    [AC_DEFINE([HAVE_REALLOC], [1],
+    [AC_DEFINE([HAVE_REALLOC_GNU], [1],
                [Define to 1 if your system has a GNU libc compatible 'realloc'
                 function, and to 0 otherwise.])],
-    [AC_DEFINE([HAVE_REALLOC], [0])
+    [AC_DEFINE([HAVE_REALLOC_GNU], [0])
      gl_REPLACE_REALLOC
     ])
 ])# gl_FUNC_REALLOC_GNU
diff --git a/modules/realloc-gnu b/modules/realloc-gnu
index d4f2167..f059976 100644
--- a/modules/realloc-gnu
+++ b/modules/realloc-gnu
@@ -14,7 +14,7 @@ realloc-posix
 
 configure.ac:
 gl_FUNC_REALLOC_GNU
-AC_DEFINE([GNULIB_REALLOC_GNU], 1, [Define to indicate the 'realloc' module.])
+gl_MODULE_INDICATOR([realloc-gnu])
 
 Makefile.am:
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]