* m4/malloc.m4 (gl_FUNC_MALLOC_0_NONNULL):
New macro, split out from gl_FUNC_MALLOC_GNU.
(gl_FUNC_MALLOC_GNU): Require it.
---
 ChangeLog    |  7 +++++++
 m4/malloc.m4 | 37 ++++++++++++++++++++++++++-----------
 2 files changed, 33 insertions(+), 11 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 59a665308c..16b28b3f65 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2024-11-05  Paul Eggert  <egg...@cs.ucla.edu>
+
+       malloc: refactor to help replace eealloc
+       * m4/malloc.m4 (gl_FUNC_MALLOC_0_NONNULL):
+       New macro, split out from gl_FUNC_MALLOC_GNU.
+       (gl_FUNC_MALLOC_GNU): Require it.
+
 2024-11-06  Bruno Haible  <br...@clisp.org>
 
        aligned_alloc tests: Fix compilation error on mingw (regr. 2024-11-04).
diff --git a/m4/malloc.m4 b/m4/malloc.m4
index 622a16f70b..a854ade93b 100644
--- a/m4/malloc.m4
+++ b/m4/malloc.m4
@@ -1,5 +1,5 @@
 # malloc.m4
-# serial 42
+# serial 43
 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,
@@ -7,6 +7,11 @@ dnl with or without modifications, as long as this notice is 
preserved.
 dnl This file is offered as-is, without any warranty.
 
 m4_version_prereq([2.73], [], [
+# Modules that use this macro directly or indirectly should depend
+# on extensions-aix, so that _LINUX_SOURCE_COMPAT gets defined
+# before this macro gets invoked.  This helps on AIX 7.2 and earlier
+# if !(__VEC__ || __AIXVEC), and doesn't hurt otherwise.
+#
 # This is copied from upstream Autoconf here:
 # 
https://git.savannah.gnu.org/cgit/autoconf.git/tree/lib/autoconf/functions.m4?id=1f38316f6af7bf63e5e7dd187ff6456e07ad743e#n971
 # _AC_FUNC_MALLOC_IF(IF-WORKS, IF-NOT[, UNKNOWN-ASSUME])
@@ -43,6 +48,21 @@ AC_DEFUN([_AC_FUNC_MALLOC_IF],
 ])# _AC_FUNC_MALLOC_IF
 ])
 
+# gl_FUNC_MALLOC_0_NONNULL
+# ------------------------
+# If 'malloc (0)' returns nonnull define HAVE_MALLOC_0_NONNULL.
+# Also, set ac_cv_func_malloc_0_nonnull to a string that ends in
+# "yes", otherwise set it to something else.  If unknown whether
+# malloc (0) works, guess as normal for cross-builds.
+AC_DEFUN([gl_FUNC_MALLOC_0_NONNULL],
+[
+  _AC_FUNC_MALLOC_IF(
+    [AC_DEFINE([HAVE_MALLOC_0_NONNULL], [1],
+       [Define to 1 if malloc (0) returns nonnull.])],
+    [],
+    ["$gl_cross_guess_normal"])
+])
+
 # gl_FUNC_MALLOC_GNU
 # ------------------
 # Test whether malloc (0) is compatible with GNU libc.
@@ -55,17 +75,12 @@ AC_DEFUN([gl_FUNC_MALLOC_GNU],
 [
   AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
   AC_REQUIRE([gl_FUNC_MALLOC_POSIX])
+  AC_REQUIRE([gl_FUNC_MALLOC_0_NONNULL])
 
-  dnl Through the dependency on module extensions-aix, _LINUX_SOURCE_COMPAT
-  dnl gets defined already before this macro gets invoked.  This helps
-  dnl if !(__VEC__ || __AIXVEC), and doesn't hurt otherwise.
-
-  _AC_FUNC_MALLOC_IF(
-    [AC_DEFINE([HAVE_MALLOC_0_NONNULL], [1],
-       [Define to 1 if malloc (0) returns nonnull.])
-     REPLACE_MALLOC_FOR_MALLOC_GNU=$REPLACE_MALLOC_FOR_MALLOC_POSIX],
-    [REPLACE_MALLOC_FOR_MALLOC_GNU=1],
-    ["$gl_cross_guess_normal"])
+  AS_CASE([$ac_cv_func_malloc_0_nonnull],
+    [*yes],
+      [REPLACE_MALLOC_FOR_MALLOC_GNU=$REPLACE_MALLOC_FOR_MALLOC_POSIX],
+    [REPLACE_MALLOC_FOR_MALLOC_GNU=1])
 ])
 
 # gl_FUNC_MALLOC_PTRDIFF
-- 
2.43.0


Reply via email to