On 4/18/21 5:13 AM, Bruno Haible wrote:

* m4/realloc.m4 (_AC_FUNC_REALLOC_IF):
Don’t start with a newline.

This is not very robust. We usually don't care about newlines or useless
indentation in the generated configure.ac any more.

Yes, I made that change only because I ran into some shell syntax error and the change fixed it. I don't recall what the error was and can't reproduce it now, so the attached first patch reverts that change.

If we run into further problems in this area, though, perhaps the patch should go back in. Autoconf (which _AC_FUNC_REALLOC_IF is taken from) does care about leading newlines, and even if we have a different API in Gnulib surely it's better to stick to the Autoconf API in Autoconf-replacing macros.

  if test $REPLACE_REALLOC = 0; then
    _AC_FUNC_REALLOC_IF([], [REPLACE_REALLOC=1])
  fi

I confess I don't like the style as much: it makes the shell code a bit less readable, at least to me. But it appears that this style isn't needed anyway.

I noticed some other incompatibilities with Autoconf _AC_FUNC_REALLOC_IF etc. and fixed them too in the attached first patch.

The second patch switches from AS_IF to AS_CASE as that's cleaner in the Gnulib version.
From c08e261c39ef3840b1cb1ae7c04c669c469cd91d Mon Sep 17 00:00:00 2001
From: Paul Eggert <egg...@cs.ucla.edu>
Date: Sun, 18 Apr 2021 11:23:24 -0700
Subject: [PATCH 1/2] malloc-gnu, etc.: sync better with Autoconf
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* m4/calloc.m4 (_AC_FUNC_CALLOC_IF):
* m4/malloc.m4 (_AC_FUNC_MALLOC_IF):
* m4/realloc.m4 (_AC_FUNC_REALLOC_IF):
Avoid some unnecessary differences from Autoconf’s versions.
Separate our platforms into a different line so that it’s easier
to diff.  Use AS_IF in case the args use AC_REQUIRE.
However, don’t bother with omitting the first newline, as
omitting the newline is not Gnulib style and the difference
doesn’t seem to matter here.
---
 ChangeLog     | 13 +++++++++++++
 m4/calloc.m4  | 15 +++++----------
 m4/malloc.m4  | 24 ++++++++++--------------
 m4/realloc.m4 | 24 ++++++++++--------------
 4 files changed, 38 insertions(+), 38 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 38311496b..fa630a758 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2021-04-18  Paul Eggert  <egg...@cs.ucla.edu>
+
+	malloc-gnu, etc.: sync better with Autoconf
+	* m4/calloc.m4 (_AC_FUNC_CALLOC_IF):
+	* m4/malloc.m4 (_AC_FUNC_MALLOC_IF):
+	* m4/realloc.m4 (_AC_FUNC_REALLOC_IF):
+	Avoid some unnecessary differences from Autoconf’s versions.
+	Separate our platforms into a different line so that it’s easier
+	to diff.  Use AS_IF in case the args use AC_REQUIRE.
+	However, don’t bother with omitting the first newline, as
+	omitting the newline is not Gnulib style and the difference
+	doesn’t seem to matter here.
+
 2021-04-18  Bruno Haible  <br...@clisp.org>
 
 	malloc-posix, realloc-posix, calloc-posix: Document affected platforms.
diff --git a/m4/calloc.m4 b/m4/calloc.m4
index 143f3bc3f..776979d25 100644
--- a/m4/calloc.m4
+++ b/m4/calloc.m4
@@ -1,4 +1,4 @@
-# calloc.m4 serial 24
+# calloc.m4 serial 25
 
 # Copyright (C) 2004-2021 Free Software Foundation, Inc.
 # This file is free software; the Free Software Foundation
@@ -16,7 +16,8 @@
 # -------------------------------------
 # If calloc is compatible with GNU calloc, run IF-WORKS, otherwise, IF-NOT.
 AC_DEFUN([_AC_FUNC_CALLOC_IF],
-[ AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+[
+  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
   AC_CACHE_CHECK([whether calloc (0, n) and calloc (n, 0) return nonnull],
     [ac_cv_func_calloc_0_nonnull],
     [if test $cross_compiling != yes; then
@@ -46,14 +47,8 @@ AC_DEFUN([_AC_FUNC_CALLOC_IF],
        esac
      fi
     ])
-  case "$ac_cv_func_calloc_0_nonnull" in
-    *yes)
-      $1
-      ;;
-    *)
-      $2
-      ;;
-  esac
+  AS_IF([case $ac_cv_func_calloc_0_nonnull in *yes) :;; *) false;; esac],
+    [$1], [$2])
 ])
 
 
diff --git a/m4/malloc.m4 b/m4/malloc.m4
index 503da2cf8..9734dab05 100644
--- a/m4/malloc.m4
+++ b/m4/malloc.m4
@@ -1,20 +1,21 @@
-# malloc.m4 serial 23
+# malloc.m4 serial 24
 dnl Copyright (C) 2007, 2009-2021 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.
 
 # This is adapted with modifications from upstream Autoconf here:
-# https://git.savannah.gnu.org/cgit/autoconf.git/commit/?id=04be2b7a29d65d9a08e64e8e56e594c91749598c
+# https://git.savannah.gnu.org/cgit/autoconf.git/tree/lib/autoconf/functions.m4?id=v2.70#n949
 AC_DEFUN([_AC_FUNC_MALLOC_IF],
-[ AC_REQUIRE([AC_CANONICAL_HOST])dnl for cross-compiles
+[
+  AC_REQUIRE([AC_CANONICAL_HOST])dnl for cross-compiles
   AC_CACHE_CHECK([whether malloc (0) returns nonnull],
     [ac_cv_func_malloc_0_nonnull],
     [AC_RUN_IFELSE(
        [AC_LANG_PROGRAM(
           [[#include <stdlib.h>
           ]],
-          [[char *p = malloc (0);
+          [[void *p = malloc (0);
             int result = !p;
             free (p);
             return result;]])
@@ -23,22 +24,17 @@ AC_DEFUN([_AC_FUNC_MALLOC_IF],
        [ac_cv_func_malloc_0_nonnull=no],
        [case "$host_os" in
           # Guess yes on platforms where we know the result.
-          *-gnu* | gnu* | *-musl* | freebsd* | midnightbsd* | netbsd* | openbsd* \
-          | hpux* | solaris* | cygwin* | mingw*)
+          *-gnu* | freebsd* | netbsd* | openbsd* | bitrig* \
+          | gnu* | *-musl* | midnightbsd* \
+          | hpux* | solaris* | cygwin* | mingw* | 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" ;;
         esac
        ])
     ])
-  case "$ac_cv_func_malloc_0_nonnull" in
-    *yes)
-      $1
-      ;;
-    *)
-      $2
-      ;;
-  esac
+  AS_IF([case $ac_cv_func_malloc_0_nonnull in *yes) :;; *) false;; esac],
+    [$1], [$2])
 ])# _AC_FUNC_MALLOC_IF
 
 # gl_FUNC_MALLOC_GNU
diff --git a/m4/realloc.m4 b/m4/realloc.m4
index 4939516a0..cde906192 100644
--- a/m4/realloc.m4
+++ b/m4/realloc.m4
@@ -1,20 +1,21 @@
-# realloc.m4 serial 21
+# realloc.m4 serial 22
 dnl Copyright (C) 2007, 2009-2021 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.
 
 # This is adapted with modifications from upstream Autoconf here:
-# https://git.savannah.gnu.org/cgit/autoconf.git/commit/?id=04be2b7a29d65d9a08e64e8e56e594c91749598c
+# https://git.savannah.gnu.org/cgit/autoconf.git/tree/lib/autoconf/functions.m4?id=v2.70#n1455
 AC_DEFUN([_AC_FUNC_REALLOC_IF],
-[ AC_REQUIRE([AC_CANONICAL_HOST])dnl for cross-compiles
+[
+  AC_REQUIRE([AC_CANONICAL_HOST])dnl for cross-compiles
   AC_CACHE_CHECK([whether realloc (0, 0) returns nonnull],
     [ac_cv_func_realloc_0_nonnull],
     [AC_RUN_IFELSE(
        [AC_LANG_PROGRAM(
           [[#include <stdlib.h>
           ]],
-          [[char *p = realloc (0, 0);
+          [[void *p = realloc (0, 0);
             int result = !p;
             free (p);
             return result;]])
@@ -23,22 +24,17 @@ AC_DEFUN([_AC_FUNC_REALLOC_IF],
        [ac_cv_func_realloc_0_nonnull=no],
        [case "$host_os" in
           # Guess yes on platforms where we know the result.
-          *-gnu* | gnu* | *-musl* | freebsd* | midnightbsd* | netbsd* | openbsd* \
-          | hpux* | solaris* | cygwin* | mingw*)
+          *-gnu* | freebsd* | netbsd* | openbsd* | bitrig* \
+          | gnu* | *-musl* | midnightbsd* \
+          | hpux* | solaris* | cygwin* | mingw* | 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" ;;
         esac
        ])
     ])
-  case "$ac_cv_func_realloc_0_nonnull" in
-    *yes)
-      $1
-      ;;
-    *)
-      $2
-      ;;
-  esac
+  AS_IF([case $ac_cv_func_realloc_0_nonnull in *yes) :;; *) false;; esac],
+    [$1], [$2])
 ])# AC_FUNC_REALLOC
 
 # gl_FUNC_REALLOC_GNU
-- 
2.27.0

From 6a9be1acc3445f09d7dd875a14271bbb7cb05c0c Mon Sep 17 00:00:00 2001
From: Paul Eggert <egg...@cs.ucla.edu>
Date: Sun, 18 Apr 2021 11:31:02 -0700
Subject: [PATCH 2/2] malloc-gnu, etc.: prefer AS_CASE to woolly AS_IF

* m4/calloc.m4 (_AC_FUNC_CALLOC_IF):
* m4/malloc.m4 (_AC_FUNC_MALLOC_IF):
* m4/realloc.m4 (_AC_FUNC_REALLOC_IF): Use AS_CASE.
---
 ChangeLog     | 5 +++++
 m4/calloc.m4  | 3 +--
 m4/malloc.m4  | 3 +--
 m4/realloc.m4 | 3 +--
 4 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index fa630a758..dd491f07b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2021-04-18  Paul Eggert  <egg...@cs.ucla.edu>
 
+	malloc-gnu, etc.: prefer AS_CASE to woolly AS_IF
+	* m4/calloc.m4 (_AC_FUNC_CALLOC_IF):
+	* m4/malloc.m4 (_AC_FUNC_MALLOC_IF):
+	* m4/realloc.m4 (_AC_FUNC_REALLOC_IF): Use AS_CASE.
+
 	malloc-gnu, etc.: sync better with Autoconf
 	* m4/calloc.m4 (_AC_FUNC_CALLOC_IF):
 	* m4/malloc.m4 (_AC_FUNC_MALLOC_IF):
diff --git a/m4/calloc.m4 b/m4/calloc.m4
index 776979d25..2f0abee03 100644
--- a/m4/calloc.m4
+++ b/m4/calloc.m4
@@ -47,8 +47,7 @@ AC_DEFUN([_AC_FUNC_CALLOC_IF],
        esac
      fi
     ])
-  AS_IF([case $ac_cv_func_calloc_0_nonnull in *yes) :;; *) false;; esac],
-    [$1], [$2])
+  AS_CASE([$ac_cv_func_calloc_0_nonnull], [*yes], [$1], [$2])
 ])
 
 
diff --git a/m4/malloc.m4 b/m4/malloc.m4
index 9734dab05..c09006df5 100644
--- a/m4/malloc.m4
+++ b/m4/malloc.m4
@@ -33,8 +33,7 @@ AC_DEFUN([_AC_FUNC_MALLOC_IF],
         esac
        ])
     ])
-  AS_IF([case $ac_cv_func_malloc_0_nonnull in *yes) :;; *) false;; esac],
-    [$1], [$2])
+  AS_CASE([$ac_cv_func_malloc_0_nonnull], [*yes], [$1], [$2])
 ])# _AC_FUNC_MALLOC_IF
 
 # gl_FUNC_MALLOC_GNU
diff --git a/m4/realloc.m4 b/m4/realloc.m4
index cde906192..8eb6b199f 100644
--- a/m4/realloc.m4
+++ b/m4/realloc.m4
@@ -33,8 +33,7 @@ AC_DEFUN([_AC_FUNC_REALLOC_IF],
         esac
        ])
     ])
-  AS_IF([case $ac_cv_func_realloc_0_nonnull in *yes) :;; *) false;; esac],
-    [$1], [$2])
+  AS_CASE([$ac_cv_func_realloc_0_nonnull], [*yes], [$1], [$2])
 ])# AC_FUNC_REALLOC
 
 # gl_FUNC_REALLOC_GNU
-- 
2.27.0

Reply via email to