]> Savannah Git Hosting - gnulib.git/commitdiff
malloc: refactor to help replace eealloc
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 6 Nov 2024 06:00:01 +0000 (22:00 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 6 Nov 2024 06:51:14 +0000 (22:51 -0800)
* m4/malloc.m4 (gl_FUNC_MALLOC_0_NONNULL):
New macro, split out from gl_FUNC_MALLOC_GNU.
(gl_FUNC_MALLOC_GNU): Require it.

ChangeLog
m4/malloc.m4

index 59a665308cb12f622522bce7f5ff35d7ee4c6a71..16b28b3f65efeb15ad18be794521431ee39726cc 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2024-11-05  Paul Eggert  <eggert@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  <bruno@clisp.org>
 
        aligned_alloc tests: Fix compilation error on mingw (regr. 2024-11-04).
index 622a16f70b3861e7f947048e76f83915f799fed0..a854ade93b37dcef1862d172d626e68c3ebbd64e 100644 (file)
@@ -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