*alloc-gnu, eealloc: Avoid "guessing no" when cross-compiling to glibc.
authorBruno Haible <bruno@clisp.org>
Fri, 4 May 2012 02:23:44 +0000 (04:23 +0200)
committerBruno Haible <bruno@clisp.org>
Fri, 4 May 2012 02:23:58 +0000 (04:23 +0200)
* m4/malloc.m4 (_AC_FUNC_MALLOC_IF): Override in autoconf < 2.70.
* m4/realloc.m4 (_AC_FUNC_REALLOC_IF): Override in autoconf < 2.70.
* m4/calloc.m4 (_AC_FUNC_CALLOC_IF): Require AC_CANONICAL_HOST. When
cross-compiling, choose the first alternative on glibc systems.
* modules/eealloc (Files): Add m4/malloc.m4, m4/realloc.m4.

ChangeLog
m4/calloc.m4
m4/malloc.m4
m4/realloc.m4
modules/eealloc

index 2729eef..c1c5ac2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2012-05-03  Bruno Haible  <bruno@clisp.org>
 
+       *alloc-gnu, eealloc: Avoid "guessing no" when cross-compiling to glibc.
+       * m4/malloc.m4 (_AC_FUNC_MALLOC_IF): Override in autoconf < 2.70.
+       * m4/realloc.m4 (_AC_FUNC_REALLOC_IF): Override in autoconf < 2.70.
+       * m4/calloc.m4 (_AC_FUNC_CALLOC_IF): Require AC_CANONICAL_HOST. When
+       cross-compiling, choose the first alternative on glibc systems.
+       * modules/eealloc (Files): Add m4/malloc.m4, m4/realloc.m4.
+
+2012-05-03  Bruno Haible  <bruno@clisp.org>
+
        getgroups: Avoid "guessing no" when cross-compiling to glibc systems.
        * m4/getgroups.m4 (AC_FUNC_GETGROUPS): Override in autoconf < 2.70.
        (gl_FUNC_GETGROUPS): Adapt to change of ac_cv_func_getgroups_works.
index bc61168..00c5fe4 100644 (file)
@@ -1,4 +1,4 @@
-# calloc.m4 serial 14
+# calloc.m4 serial 15
 
 # Copyright (C) 2004-2012 Free Software Foundation, Inc.
 # This file is free software; the Free Software Foundation
@@ -18,6 +18,7 @@
 AC_DEFUN([_AC_FUNC_CALLOC_IF],
 [
   AC_REQUIRE([AC_TYPE_SIZE_T])dnl
+  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
   AC_CACHE_CHECK([for GNU libc compatible calloc],
     [ac_cv_func_calloc_0_nonnull],
     [AC_RUN_IFELSE(
@@ -32,8 +33,21 @@ AC_DEFUN([_AC_FUNC_CALLOC_IF],
           ]])],
        [ac_cv_func_calloc_0_nonnull=yes],
        [ac_cv_func_calloc_0_nonnull=no],
-       [ac_cv_func_calloc_0_nonnull=no])])
-  AS_IF([test $ac_cv_func_calloc_0_nonnull = yes], [$1], [$2])
+       [case "$host_os" in
+                  # Guess yes on glibc systems.
+          *-gnu*) ac_cv_func_calloc_0_nonnull="guessing yes" ;;
+                  # If we don't know, assume the worst.
+          *)      ac_cv_func_calloc_0_nonnull="guessing no" ;;
+        esac
+       ])])
+  case "$ac_cv_func_calloc_0_nonnull" in
+    *yes)
+      $1
+      ;;
+    *)
+      $2
+      ;;
+  esac
 ])# AC_FUNC_CALLOC
 
 
index d3c39f5..8fa48e9 100644 (file)
@@ -1,9 +1,47 @@
-# malloc.m4 serial 13
+# malloc.m4 serial 14
 dnl Copyright (C) 2007, 2009-2012 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
 dnl with or without modifications, as long as this notice is preserved.
 
+m4_version_prereq([2.70], [] ,[
+
+# This is taken from the following Autoconf patch:
+# http://git.savannah.gnu.org/gitweb/?p=autoconf.git;a=commitdiff;h=7fbb553727ed7e0e689a17594b58559ecf3ea6e9
+AC_DEFUN([_AC_FUNC_MALLOC_IF],
+[
+  AC_REQUIRE([AC_HEADER_STDC])dnl
+  AC_REQUIRE([AC_CANONICAL_HOST])dnl for cross-compiles
+  AC_CHECK_HEADERS([stdlib.h])
+  AC_CACHE_CHECK([for GNU libc compatible malloc],
+    [ac_cv_func_malloc_0_nonnull],
+    [AC_RUN_IFELSE(
+       [AC_LANG_PROGRAM(
+          [[#if defined STDC_HEADERS || defined HAVE_STDLIB_H
+            # include <stdlib.h>
+            #else
+            char *malloc ();
+            #endif
+          ]],
+          [[return ! malloc (0);]])
+       ],
+       [ac_cv_func_malloc_0_nonnull=yes],
+       [ac_cv_func_malloc_0_nonnull=no],
+       [case "$host_os" in
+          # Guess yes on platforms where we know the result.
+          *-gnu* | freebsd* | netbsd* | openbsd* \
+          | hpux* | solaris* | cygwin* | mingw*)
+            ac_cv_func_malloc_0_nonnull=yes ;;
+          # If we don't know, assume the worst.
+          *) ac_cv_func_malloc_0_nonnull=no ;;
+        esac
+       ])
+    ])
+  AS_IF([test $ac_cv_func_malloc_0_nonnull = yes], [$1], [$2])
+])# _AC_FUNC_MALLOC_IF
+
+])
+
 # gl_FUNC_MALLOC_GNU
 # ------------------
 # Test whether 'malloc (0)' is handled like in GNU libc, and replace malloc if
index 039ed19..954c2f0 100644 (file)
@@ -1,9 +1,47 @@
-# realloc.m4 serial 12
+# realloc.m4 serial 13
 dnl Copyright (C) 2007, 2009-2012 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
 dnl with or without modifications, as long as this notice is preserved.
 
+m4_version_prereq([2.70], [] ,[
+
+# This is taken from the following Autoconf patch:
+# http://git.savannah.gnu.org/gitweb/?p=autoconf.git;a=commitdiff;h=7fbb553727ed7e0e689a17594b58559ecf3ea6e9
+AC_DEFUN([_AC_FUNC_REALLOC_IF],
+[
+  AC_REQUIRE([AC_HEADER_STDC])dnl
+  AC_REQUIRE([AC_CANONICAL_HOST])dnl for cross-compiles
+  AC_CHECK_HEADERS([stdlib.h])
+  AC_CACHE_CHECK([for GNU libc compatible realloc],
+    [ac_cv_func_realloc_0_nonnull],
+    [AC_RUN_IFELSE(
+       [AC_LANG_PROGRAM(
+          [[#if defined STDC_HEADERS || defined HAVE_STDLIB_H
+            # include <stdlib.h>
+            #else
+            char *realloc ();
+            #endif
+          ]],
+          [[return ! realloc (0, 0);]])
+       ],
+       [ac_cv_func_realloc_0_nonnull=yes],
+       [ac_cv_func_realloc_0_nonnull=no],
+       [case "$host_os" in
+          # Guess yes on platforms where we know the result.
+          *-gnu* | freebsd* | netbsd* | openbsd* \
+          | hpux* | solaris* | cygwin* | mingw*)
+            ac_cv_func_realloc_0_nonnull=yes ;;
+          # If we don't know, assume the worst.
+          *) ac_cv_func_realloc_0_nonnull=no ;;
+        esac
+       ])
+    ])
+  AS_IF([test $ac_cv_func_realloc_0_nonnull = yes], [$1], [$2])
+])# AC_FUNC_REALLOC
+
+])
+
 # gl_FUNC_REALLOC_GNU
 # -------------------
 # Test whether 'realloc (0, 0)' is handled like in GNU libc, and replace
index 437cb4d..7e18d45 100644 (file)
@@ -4,6 +4,8 @@ Memory allocation with expensive empty allocations (glibc compatible).
 Files:
 lib/eealloc.h
 m4/eealloc.m4
+m4/malloc.m4
+m4/realloc.m4
 
 Depends-on: