From: Bruno Haible Date: Fri, 4 May 2012 02:23:44 +0000 (+0200) Subject: *alloc-gnu, eealloc: Avoid "guessing no" when cross-compiling to glibc. X-Git-Tag: v0.1~711 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=98f7f8fde92f6f3f583cabc1168305a9ce542bbe;p=gnulib.git *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. --- diff --git a/ChangeLog b/ChangeLog index 2729eef88..c1c5ac29f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,14 @@ 2012-05-03 Bruno Haible + *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 + 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. diff --git a/m4/calloc.m4 b/m4/calloc.m4 index bc61168c3..00c5fe43c 100644 --- a/m4/calloc.m4 +++ b/m4/calloc.m4 @@ -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 diff --git a/m4/malloc.m4 b/m4/malloc.m4 index d3c39f5d9..8fa48e93b 100644 --- a/m4/malloc.m4 +++ b/m4/malloc.m4 @@ -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 + #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 diff --git a/m4/realloc.m4 b/m4/realloc.m4 index 039ed192a..954c2f0e5 100644 --- a/m4/realloc.m4 +++ b/m4/realloc.m4 @@ -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 + #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 diff --git a/modules/eealloc b/modules/eealloc index 437cb4ddf..7e18d45a9 100644 --- a/modules/eealloc +++ b/modules/eealloc @@ -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: