diff options
Diffstat (limited to 'gnulib-m4/calloc.m4')
-rw-r--r-- | gnulib-m4/calloc.m4 | 68 |
1 files changed, 30 insertions, 38 deletions
diff --git a/gnulib-m4/calloc.m4 b/gnulib-m4/calloc.m4 index c69ce414..ac7d08d4 100644 --- a/gnulib-m4/calloc.m4 +++ b/gnulib-m4/calloc.m4 @@ -1,9 +1,10 @@ # calloc.m4 -# serial 34 -dnl Copyright (C) 2004-2024 Free Software Foundation, Inc. +# serial 36 +dnl Copyright (C) 2004-2025 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. # Written by Jim Meyering. @@ -12,42 +13,35 @@ dnl with or without modifications, as long as this notice is preserved. # If so, define HAVE_CALLOC. Otherwise, define calloc to rpl_calloc # and arrange to use a calloc wrapper function that does work in that case. -# _AC_FUNC_CALLOC_IF([IF-WORKS], [IF-NOT]) -# ------------------------------------- +# gl_FUNC_CALLOC_IF([IF-WORKS], [IF-NOT]) +# --------------------------------------- # If calloc is compatible with GNU calloc, run IF-WORKS, otherwise, IF-NOT. -AC_DEFUN([_AC_FUNC_CALLOC_IF], +AC_DEFUN([gl_FUNC_CALLOC_IF], [ 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 - ac_cv_func_calloc_0_nonnull=yes - AC_RUN_IFELSE( - [AC_LANG_PROGRAM( - [AC_INCLUDES_DEFAULT], - [[int result = 0; - char * volatile p = calloc (0, 0); - if (!p) - result |= 1; - free (p); - return result; - ]])], - [], - [ac_cv_func_calloc_0_nonnull=no]) - else - case "$host_os" in - # Guess yes on glibc systems. - *-gnu* | gnu*) ac_cv_func_calloc_0_nonnull="guessing yes" ;; - # Guess yes on musl systems. - *-musl* | midipix*) ac_cv_func_calloc_0_nonnull="guessing yes" ;; - # Guess yes on native Windows. - mingw* | windows*) ac_cv_func_calloc_0_nonnull="guessing yes" ;; - # If we don't know, obey --enable-cross-guesses. - *) ac_cv_func_calloc_0_nonnull="$gl_cross_guess_normal" ;; - esac - fi - ]) - AS_CASE([$ac_cv_func_calloc_0_nonnull], [*yes], [$1], [$2]) + [gl_cv_func_calloc_0_nonnull], + [AC_RUN_IFELSE( + [AC_LANG_PROGRAM( + [[#include <stdlib.h> + /* Use pcalloc to test; "volatile" prevents the compiler + from optimizing the calloc call away. */ + void *(*volatile pcalloc) (size_t, size_t) = calloc;]], + [[void *p = pcalloc (0, 0); + int result = !p; + free (p); + return result;]])], + [gl_cv_func_calloc_0_nonnull=yes], + [gl_cv_func_calloc_0_nonnull=no], + [AS_CASE([$host_os], + [# Guess yes on platforms where we know the result. + *-gnu* | freebsd* | netbsd* | openbsd* | bitrig* \ + | gnu* | *-musl* | midipix* | midnightbsd* \ + | hpux* | solaris* | cygwin* | mingw* | windows* | msys*], + [gl_cv_func_calloc_0_nonnull="guessing yes"], + [# If we don't know, obey --enable-cross-guesses. + gl_cv_func_calloc_0_nonnull="$gl_cross_guess_normal"])])]) + AS_CASE([$gl_cv_func_calloc_0_nonnull], [*yes], [$1], [$2]) ]) @@ -65,7 +59,7 @@ AC_DEFUN([gl_FUNC_CALLOC_GNU], REPLACE_CALLOC_FOR_CALLOC_GNU="$REPLACE_CALLOC_FOR_CALLOC_POSIX" if test $REPLACE_CALLOC_FOR_CALLOC_GNU = 0; then - _AC_FUNC_CALLOC_IF([], [REPLACE_CALLOC_FOR_CALLOC_GNU=1]) + gl_FUNC_CALLOC_IF([], [REPLACE_CALLOC_FOR_CALLOC_GNU=1]) fi ])# gl_FUNC_CALLOC_GNU @@ -78,9 +72,7 @@ AC_DEFUN([gl_FUNC_CALLOC_POSIX], [ AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) AC_REQUIRE([gl_FUNC_MALLOC_POSIX]) - if test $REPLACE_MALLOC_FOR_MALLOC_POSIX = 1; then - REPLACE_CALLOC_FOR_CALLOC_POSIX=1 - fi + REPLACE_CALLOC_FOR_CALLOC_POSIX=$REPLACE_MALLOC_FOR_MALLOC_POSIX dnl Although in theory we should also test for size_t overflow, dnl in practice testing for ptrdiff_t overflow suffices dnl since PTRDIFF_MAX <= SIZE_MAX on all known Gnulib porting targets. |