diff options
Diffstat (limited to 'gl/m4/calloc.m4')
| -rw-r--r-- | gl/m4/calloc.m4 | 73 |
1 files changed, 35 insertions, 38 deletions
diff --git a/gl/m4/calloc.m4 b/gl/m4/calloc.m4 index 550cf5cc..ac7d08d4 100644 --- a/gl/m4/calloc.m4 +++ b/gl/m4/calloc.m4 | |||
| @@ -1,9 +1,10 @@ | |||
| 1 | # calloc.m4 | 1 | # calloc.m4 |
| 2 | # serial 31 | 2 | # serial 36 |
| 3 | dnl Copyright (C) 2004-2024 Free Software Foundation, Inc. | 3 | dnl Copyright (C) 2004-2025 Free Software Foundation, Inc. |
| 4 | dnl This file is free software; the Free Software Foundation | 4 | dnl This file is free software; the Free Software Foundation |
| 5 | dnl gives unlimited permission to copy and/or distribute it, | 5 | dnl gives unlimited permission to copy and/or distribute it, |
| 6 | dnl with or without modifications, as long as this notice is preserved. | 6 | dnl with or without modifications, as long as this notice is preserved. |
| 7 | dnl This file is offered as-is, without any warranty. | ||
| 7 | 8 | ||
| 8 | # Written by Jim Meyering. | 9 | # Written by Jim Meyering. |
| 9 | 10 | ||
| @@ -12,42 +13,35 @@ dnl with or without modifications, as long as this notice is preserved. | |||
| 12 | # If so, define HAVE_CALLOC. Otherwise, define calloc to rpl_calloc | 13 | # If so, define HAVE_CALLOC. Otherwise, define calloc to rpl_calloc |
| 13 | # and arrange to use a calloc wrapper function that does work in that case. | 14 | # and arrange to use a calloc wrapper function that does work in that case. |
| 14 | 15 | ||
| 15 | # _AC_FUNC_CALLOC_IF([IF-WORKS], [IF-NOT]) | 16 | # gl_FUNC_CALLOC_IF([IF-WORKS], [IF-NOT]) |
| 16 | # ------------------------------------- | 17 | # --------------------------------------- |
| 17 | # If calloc is compatible with GNU calloc, run IF-WORKS, otherwise, IF-NOT. | 18 | # If calloc is compatible with GNU calloc, run IF-WORKS, otherwise, IF-NOT. |
| 18 | AC_DEFUN([_AC_FUNC_CALLOC_IF], | 19 | AC_DEFUN([gl_FUNC_CALLOC_IF], |
| 19 | [ | 20 | [ |
| 20 | AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles | 21 | AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles |
| 21 | AC_CACHE_CHECK([whether calloc (0, n) and calloc (n, 0) return nonnull], | 22 | AC_CACHE_CHECK([whether calloc (0, n) and calloc (n, 0) return nonnull], |
| 22 | [ac_cv_func_calloc_0_nonnull], | 23 | [gl_cv_func_calloc_0_nonnull], |
| 23 | [if test $cross_compiling != yes; then | 24 | [AC_RUN_IFELSE( |
| 24 | ac_cv_func_calloc_0_nonnull=yes | 25 | [AC_LANG_PROGRAM( |
| 25 | AC_RUN_IFELSE( | 26 | [[#include <stdlib.h> |
| 26 | [AC_LANG_PROGRAM( | 27 | /* Use pcalloc to test; "volatile" prevents the compiler |
| 27 | [AC_INCLUDES_DEFAULT], | 28 | from optimizing the calloc call away. */ |
| 28 | [[int result = 0; | 29 | void *(*volatile pcalloc) (size_t, size_t) = calloc;]], |
| 29 | char * volatile p = calloc (0, 0); | 30 | [[void *p = pcalloc (0, 0); |
| 30 | if (!p) | 31 | int result = !p; |
| 31 | result |= 1; | 32 | free (p); |
| 32 | free (p); | 33 | return result;]])], |
| 33 | return result; | 34 | [gl_cv_func_calloc_0_nonnull=yes], |
| 34 | ]])], | 35 | [gl_cv_func_calloc_0_nonnull=no], |
| 35 | [], | 36 | [AS_CASE([$host_os], |
| 36 | [ac_cv_func_calloc_0_nonnull=no]) | 37 | [# Guess yes on platforms where we know the result. |
| 37 | else | 38 | *-gnu* | freebsd* | netbsd* | openbsd* | bitrig* \ |
| 38 | case "$host_os" in | 39 | | gnu* | *-musl* | midipix* | midnightbsd* \ |
| 39 | # Guess yes on glibc systems. | 40 | | hpux* | solaris* | cygwin* | mingw* | windows* | msys*], |
| 40 | *-gnu* | gnu*) ac_cv_func_calloc_0_nonnull="guessing yes" ;; | 41 | [gl_cv_func_calloc_0_nonnull="guessing yes"], |
| 41 | # Guess yes on musl systems. | 42 | [# If we don't know, obey --enable-cross-guesses. |
| 42 | *-musl* | midipix*) ac_cv_func_calloc_0_nonnull="guessing yes" ;; | 43 | gl_cv_func_calloc_0_nonnull="$gl_cross_guess_normal"])])]) |
| 43 | # Guess yes on native Windows. | 44 | AS_CASE([$gl_cv_func_calloc_0_nonnull], [*yes], [$1], [$2]) |
| 44 | mingw* | windows*) ac_cv_func_calloc_0_nonnull="guessing yes" ;; | ||
| 45 | # If we don't know, obey --enable-cross-guesses. | ||
| 46 | *) ac_cv_func_calloc_0_nonnull="$gl_cross_guess_normal" ;; | ||
| 47 | esac | ||
| 48 | fi | ||
| 49 | ]) | ||
| 50 | AS_CASE([$ac_cv_func_calloc_0_nonnull], [*yes], [$1], [$2]) | ||
| 51 | ]) | 45 | ]) |
| 52 | 46 | ||
| 53 | 47 | ||
| @@ -58,9 +52,14 @@ AC_DEFUN([gl_FUNC_CALLOC_GNU], | |||
| 58 | [ | 52 | [ |
| 59 | AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) | 53 | AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) |
| 60 | AC_REQUIRE([gl_FUNC_CALLOC_POSIX]) | 54 | AC_REQUIRE([gl_FUNC_CALLOC_POSIX]) |
| 55 | |||
| 56 | dnl Through the dependency on module extensions-aix, _LINUX_SOURCE_COMPAT | ||
| 57 | dnl gets defined already before this macro gets invoked. This helps | ||
| 58 | dnl if !(__VEC__ || __AIXVEC), and doesn't hurt otherwise. | ||
| 59 | |||
| 61 | REPLACE_CALLOC_FOR_CALLOC_GNU="$REPLACE_CALLOC_FOR_CALLOC_POSIX" | 60 | REPLACE_CALLOC_FOR_CALLOC_GNU="$REPLACE_CALLOC_FOR_CALLOC_POSIX" |
| 62 | if test $REPLACE_CALLOC_FOR_CALLOC_GNU = 0; then | 61 | if test $REPLACE_CALLOC_FOR_CALLOC_GNU = 0; then |
| 63 | _AC_FUNC_CALLOC_IF([], [REPLACE_CALLOC_FOR_CALLOC_GNU=1]) | 62 | gl_FUNC_CALLOC_IF([], [REPLACE_CALLOC_FOR_CALLOC_GNU=1]) |
| 64 | fi | 63 | fi |
| 65 | ])# gl_FUNC_CALLOC_GNU | 64 | ])# gl_FUNC_CALLOC_GNU |
| 66 | 65 | ||
| @@ -73,9 +72,7 @@ AC_DEFUN([gl_FUNC_CALLOC_POSIX], | |||
| 73 | [ | 72 | [ |
| 74 | AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) | 73 | AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) |
| 75 | AC_REQUIRE([gl_FUNC_MALLOC_POSIX]) | 74 | AC_REQUIRE([gl_FUNC_MALLOC_POSIX]) |
| 76 | if test $REPLACE_MALLOC_FOR_MALLOC_POSIX = 1; then | 75 | REPLACE_CALLOC_FOR_CALLOC_POSIX=$REPLACE_MALLOC_FOR_MALLOC_POSIX |
| 77 | REPLACE_CALLOC_FOR_CALLOC_POSIX=1 | ||
| 78 | fi | ||
| 79 | dnl Although in theory we should also test for size_t overflow, | 76 | dnl Although in theory we should also test for size_t overflow, |
| 80 | dnl in practice testing for ptrdiff_t overflow suffices | 77 | dnl in practice testing for ptrdiff_t overflow suffices |
| 81 | dnl since PTRDIFF_MAX <= SIZE_MAX on all known Gnulib porting targets. | 78 | dnl since PTRDIFF_MAX <= SIZE_MAX on all known Gnulib porting targets. |
