Blame m4/malloc.m4

Packit Service c30d13
# malloc.m4 serial 17
Packit Service c30d13
dnl Copyright (C) 2007, 2009-2018 Free Software Foundation, Inc.
Packit Service c30d13
dnl This file is free software; the Free Software Foundation
Packit Service c30d13
dnl gives unlimited permission to copy and/or distribute it,
Packit Service c30d13
dnl with or without modifications, as long as this notice is preserved.
Packit Service c30d13
Packit Service c30d13
m4_version_prereq([2.70], [] ,[
Packit Service c30d13
Packit Service c30d13
# This is adapted with modifications from upstream Autoconf here:
Packit Service c30d13
# https://git.savannah.gnu.org/cgit/autoconf.git/commit/?id=04be2b7a29d65d9a08e64e8e56e594c91749598c
Packit Service c30d13
AC_DEFUN([_AC_FUNC_MALLOC_IF],
Packit Service c30d13
[
Packit Service c30d13
  AC_REQUIRE([AC_HEADER_STDC])dnl
Packit Service c30d13
  AC_REQUIRE([AC_CANONICAL_HOST])dnl for cross-compiles
Packit Service c30d13
  AC_CHECK_HEADERS([stdlib.h])
Packit Service c30d13
  AC_CACHE_CHECK([for GNU libc compatible malloc],
Packit Service c30d13
    [ac_cv_func_malloc_0_nonnull],
Packit Service c30d13
    [AC_RUN_IFELSE(
Packit Service c30d13
       [AC_LANG_PROGRAM(
Packit Service c30d13
          [[#if defined STDC_HEADERS || defined HAVE_STDLIB_H
Packit Service c30d13
            # include <stdlib.h>
Packit Service c30d13
            #else
Packit Service c30d13
            char *malloc ();
Packit Service c30d13
            #endif
Packit Service c30d13
          ]],
Packit Service c30d13
          [[char *p = malloc (0);
Packit Service c30d13
            int result = !p;
Packit Service c30d13
            free (p);
Packit Service c30d13
            return result;]])
Packit Service c30d13
       ],
Packit Service c30d13
       [ac_cv_func_malloc_0_nonnull=yes],
Packit Service c30d13
       [ac_cv_func_malloc_0_nonnull=no],
Packit Service c30d13
       [case "$host_os" in
Packit Service c30d13
          # Guess yes on platforms where we know the result.
Packit Service c30d13
          *-gnu* | gnu* | freebsd* | netbsd* | openbsd* \
Packit Service c30d13
          | hpux* | solaris* | cygwin* | mingw*)
Packit Service c30d13
            ac_cv_func_malloc_0_nonnull=yes ;;
Packit Service c30d13
          # If we don't know, assume the worst.
Packit Service c30d13
          *) ac_cv_func_malloc_0_nonnull=no ;;
Packit Service c30d13
        esac
Packit Service c30d13
       ])
Packit Service c30d13
    ])
Packit Service c30d13
  AS_IF([test $ac_cv_func_malloc_0_nonnull = yes], [$1], [$2])
Packit Service c30d13
])# _AC_FUNC_MALLOC_IF
Packit Service c30d13
Packit Service c30d13
])
Packit Service c30d13
Packit Service c30d13
# gl_FUNC_MALLOC_GNU
Packit Service c30d13
# ------------------
Packit Service c30d13
# Test whether 'malloc (0)' is handled like in GNU libc, and replace malloc if
Packit Service c30d13
# it is not.
Packit Service c30d13
AC_DEFUN([gl_FUNC_MALLOC_GNU],
Packit Service c30d13
[
Packit Service c30d13
  AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
Packit Service c30d13
  dnl _AC_FUNC_MALLOC_IF is defined in Autoconf.
Packit Service c30d13
  _AC_FUNC_MALLOC_IF(
Packit Service c30d13
    [AC_DEFINE([HAVE_MALLOC_GNU], [1],
Packit Service c30d13
               [Define to 1 if your system has a GNU libc compatible 'malloc'
Packit Service c30d13
                function, and to 0 otherwise.])],
Packit Service c30d13
    [AC_DEFINE([HAVE_MALLOC_GNU], [0])
Packit Service c30d13
     REPLACE_MALLOC=1
Packit Service c30d13
    ])
Packit Service c30d13
])
Packit Service c30d13
Packit Service c30d13
# gl_FUNC_MALLOC_POSIX
Packit Service c30d13
# --------------------
Packit Service c30d13
# Test whether 'malloc' is POSIX compliant (sets errno to ENOMEM when it
Packit Service c30d13
# fails), and replace malloc if it is not.
Packit Service c30d13
AC_DEFUN([gl_FUNC_MALLOC_POSIX],
Packit Service c30d13
[
Packit Service c30d13
  AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
Packit Service c30d13
  AC_REQUIRE([gl_CHECK_MALLOC_POSIX])
Packit Service c30d13
  if test $gl_cv_func_malloc_posix = yes; then
Packit Service c30d13
    AC_DEFINE([HAVE_MALLOC_POSIX], [1],
Packit Service c30d13
      [Define if the 'malloc' function is POSIX compliant.])
Packit Service c30d13
  else
Packit Service c30d13
    REPLACE_MALLOC=1
Packit Service c30d13
  fi
Packit Service c30d13
])
Packit Service c30d13
Packit Service c30d13
# Test whether malloc, realloc, calloc are POSIX compliant,
Packit Service c30d13
# Set gl_cv_func_malloc_posix to yes or no accordingly.
Packit Service c30d13
AC_DEFUN([gl_CHECK_MALLOC_POSIX],
Packit Service c30d13
[
Packit Service c30d13
  AC_CACHE_CHECK([whether malloc, realloc, calloc are POSIX compliant],
Packit Service c30d13
    [gl_cv_func_malloc_posix],
Packit Service c30d13
    [
Packit Service c30d13
      dnl It is too dangerous to try to allocate a large amount of memory:
Packit Service c30d13
      dnl some systems go to their knees when you do that. So assume that
Packit Service c30d13
      dnl all Unix implementations of the function are POSIX compliant.
Packit Service c30d13
      AC_COMPILE_IFELSE(
Packit Service c30d13
        [AC_LANG_PROGRAM(
Packit Service c30d13
           [[]],
Packit Service c30d13
           [[#if defined _WIN32 && ! defined __CYGWIN__
Packit Service c30d13
             choke me
Packit Service c30d13
             #endif
Packit Service c30d13
            ]])],
Packit Service c30d13
        [gl_cv_func_malloc_posix=yes],
Packit Service c30d13
        [gl_cv_func_malloc_posix=no])
Packit Service c30d13
    ])
Packit Service c30d13
])