* m4/malloc.m4 (_AC_FUNC_MALLOC_IF):
* m4/realloc.m4 (_AC_FUNC_REALLOC_IF):
Sync from bleeding-edge Autoconf.  All uses changed.
---
 ChangeLog     |  5 +++++
 m4/eealloc.m4 |  8 +++++---
 m4/malloc.m4  | 29 +++++++++++++++++++----------
 m4/realloc.m4 | 28 ++++++++++++++++++----------
 4 files changed, 47 insertions(+), 23 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 4e9bcd72d6..8484e2d261 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2024-10-29  Paul Eggert  <egg...@cs.ucla.edu>
 
+       malloc, realloc: sync from Autoconf master
+       * m4/malloc.m4 (_AC_FUNC_MALLOC_IF):
+       * m4/realloc.m4 (_AC_FUNC_REALLOC_IF):
+       Sync from bleeding-edge Autoconf.  All uses changed.
+
        malloc: fix recent doc bug for AIX 7.3
        * doc/posix-functions/malloc.texi: Undo previous change,
        as _LINUX_SOURCE_COMPAT no longer affects malloc on AIX 7.3.
diff --git a/m4/eealloc.m4 b/m4/eealloc.m4
index 2081ac9fb0..42ab030f38 100644
--- a/m4/eealloc.m4
+++ b/m4/eealloc.m4
@@ -1,5 +1,5 @@
 # eealloc.m4
-# serial 3
+# serial 4
 dnl Copyright (C) 2003, 2009-2024 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -16,7 +16,8 @@ AC_DEFUN([gl_EEMALLOC],
 [
   _AC_FUNC_MALLOC_IF(
     [gl_cv_func_malloc_0_nonnull=1],
-    [gl_cv_func_malloc_0_nonnull=0])
+    [gl_cv_func_malloc_0_nonnull=0],
+    [$gl_cross_guess_normal])
   AC_DEFINE_UNQUOTED([MALLOC_0_IS_NONNULL], [$gl_cv_func_malloc_0_nonnull],
     [If malloc(0) is != NULL, define this to 1.  Otherwise define this
      to 0.])
@@ -26,7 +27,8 @@ AC_DEFUN([gl_EEREALLOC],
 [
   _AC_FUNC_REALLOC_IF(
     [gl_cv_func_realloc_0_nonnull=1],
-    [gl_cv_func_realloc_0_nonnull=0])
+    [gl_cv_func_realloc_0_nonnull=0],
+    [$gl_cross_guess_normal])
   AC_DEFINE_UNQUOTED([REALLOC_0_IS_NONNULL], [$gl_cv_func_realloc_0_nonnull],
     [If realloc(NULL,0) is != NULL, define this to 1.  Otherwise define this
      to 0.])
diff --git a/m4/malloc.m4 b/m4/malloc.m4
index ff10e727ad..df3a492d40 100644
--- a/m4/malloc.m4
+++ b/m4/malloc.m4
@@ -1,13 +1,19 @@
 # malloc.m4
-# serial 35
+# serial 36
 dnl Copyright (C) 2007, 2009-2024 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.
 dnl This file is offered as-is, without any warranty.
 
-# This is adapted with modifications from upstream Autoconf here:
-# 
https://git.savannah.gnu.org/cgit/autoconf.git/tree/lib/autoconf/functions.m4?id=v2.70#n949
+m4_version_prereq([2.73], [], [
+# This is copied from upstream Autoconf here:
+# 
https://git.savannah.gnu.org/cgit/autoconf.git/tree/lib/autoconf/functions.m4?id=74df3c673320c06481f5c5b18ff7979a3034a9e5#n971
+# _AC_FUNC_MALLOC_IF(IF-WORKS, IF-NOT, UNKNOWN-ASSUME)
+# ----------------------------------------------------
+# If 'malloc (0, 0)' returns nonnull, run IF-WORKS, otherwise, IF-NOT.
+# If it is not known whether it works, assume the shell word UNKNOWN-ASSUME,
+# which should end in "yes" or in something else.
 AC_DEFUN([_AC_FUNC_MALLOC_IF],
 [
   AC_REQUIRE([AC_CANONICAL_HOST])dnl for cross-compiles
@@ -16,10 +22,11 @@ AC_DEFUN([_AC_FUNC_MALLOC_IF],
     [AC_RUN_IFELSE(
        [AC_LANG_PROGRAM(
           [[#include <stdlib.h>
-          ]],
-          [[void *p = malloc (0);
-            void * volatile vp = p;
-            int result = !vp;
+            /* Use pmalloc to test; 'volatile' prevents the compiler
+               from optimizing the malloc call away.  */
+            void *(*volatile pmalloc) (size_t) = malloc;]],
+          [[void *p = pmalloc (0);
+            int result = !p;
             free (p);
             return result;]])
        ],
@@ -31,13 +38,14 @@ AC_DEFUN([_AC_FUNC_MALLOC_IF],
           | gnu* | *-musl* | midipix* | midnightbsd* \
           | hpux* | solaris* | cygwin* | mingw* | windows* | msys* )
             ac_cv_func_malloc_0_nonnull="guessing yes" ;;
-          # If we don't know, obey --enable-cross-guesses.
-          *) ac_cv_func_malloc_0_nonnull="$gl_cross_guess_normal" ;;
+          # Guess as follows if we don't know.
+          *) ac_cv_func_malloc_0_nonnull=$3 ;;
         esac
        ])
     ])
   AS_CASE([$ac_cv_func_malloc_0_nonnull], [*yes], [$1], [$2])
 ])# _AC_FUNC_MALLOC_IF
+])
 
 # gl_FUNC_MALLOC_GNU
 # ------------------
@@ -53,7 +61,8 @@ AC_DEFUN([gl_FUNC_MALLOC_GNU],
 
   REPLACE_MALLOC_FOR_MALLOC_GNU="$REPLACE_MALLOC_FOR_MALLOC_POSIX"
   if test $REPLACE_MALLOC_FOR_MALLOC_GNU = 0; then
-    _AC_FUNC_MALLOC_IF([], [REPLACE_MALLOC_FOR_MALLOC_GNU=1])
+    _AC_FUNC_MALLOC_IF([], [REPLACE_MALLOC_FOR_MALLOC_GNU=1],
+      [$gl_cross_guess_normal])
   fi
 ])
 
diff --git a/m4/realloc.m4 b/m4/realloc.m4
index 8fd220e883..a48dc1cfe5 100644
--- a/m4/realloc.m4
+++ b/m4/realloc.m4
@@ -1,5 +1,5 @@
 # realloc.m4
-# serial 34
+# serial 35
 dnl Copyright (C) 2007, 2009-2024 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -18,8 +18,14 @@ AC_DEFUN([gl_FUNC_REALLOC_SANITIZED],
     [test -n "$gl_cv_func_realloc_sanitize" || gl_cv_func_realloc_sanitize=no])
 ])
 
-# This is adapted with modifications from upstream Autoconf here:
-# 
https://git.savannah.gnu.org/cgit/autoconf.git/tree/lib/autoconf/functions.m4?id=v2.70#n1455
+m4_version_prereq([2.73], [], [
+# This is copied from upstream Autoconf here:
+# 
https://git.savannah.gnu.org/cgit/autoconf.git/tree/lib/autoconf/functions.m4?id=74df3c673320c06481f5c5b18ff7979a3034a9e5#n1487
+# _AC_FUNC_REALLOC_IF(IF-WORKS, IF-NOT, UNKNOWN-ASSUME)
+# -----------------------------------------------------
+# If 'realloc (0, 0)' returns nonnull, run IF-WORKS, otherwise, IF-NOT.
+# If it is not known whether it works, assume the shell word UNKNOWN-ASSUME,
+# which should end in "yes" or in something else.
 AC_DEFUN([_AC_FUNC_REALLOC_IF],
 [
   AC_REQUIRE([AC_CANONICAL_HOST])dnl for cross-compiles
@@ -28,10 +34,11 @@ AC_DEFUN([_AC_FUNC_REALLOC_IF],
     [AC_RUN_IFELSE(
        [AC_LANG_PROGRAM(
           [[#include <stdlib.h>
-          ]],
-          [[void *p = realloc (0, 0);
-            void * volatile vp = p;
-            int result = !vp;
+            /* Use prealloc to test; 'volatile' prevents the compiler
+               from optimizing the realloc call away.  */
+            void *(*volatile prealloc) (void *, size_t) = realloc;]],
+          [[void *p = prealloc (0, 0);
+            int result = !p;
             free (p);
             return result;]])
        ],
@@ -43,13 +50,14 @@ AC_DEFUN([_AC_FUNC_REALLOC_IF],
           | gnu* | *-musl* | midipix* | midnightbsd* \
           | hpux* | solaris* | cygwin* | mingw* | windows* | msys* )
             ac_cv_func_realloc_0_nonnull="guessing yes" ;;
-          # If we don't know, obey --enable-cross-guesses.
-          *) ac_cv_func_realloc_0_nonnull="$gl_cross_guess_normal" ;;
+          # Guess as follows if we don't know.
+          *) ac_cv_func_realloc_0_nonnull=$3 ;;
         esac
        ])
     ])
   AS_CASE([$ac_cv_func_realloc_0_nonnull], [*yes], [$1], [$2])
-])# AC_FUNC_REALLOC
+])# _AC_FUNC_REALLOC_IF
+])
 
 # gl_FUNC_REALLOC_POSIX
 # ---------------------
-- 
2.43.0


Reply via email to