Annotation of embedaddon/libiconv/srcm4/malloc.m4, revision 1.1.1.2

1.1.1.2 ! misho       1: # malloc.m4 serial 19
        !             2: dnl Copyright (C) 2007, 2009-2019 Free Software Foundation, Inc.
1.1       misho       3: dnl This file is free software; the Free Software Foundation
                      4: dnl gives unlimited permission to copy and/or distribute it,
                      5: dnl with or without modifications, as long as this notice is preserved.
                      6: 
1.1.1.2 ! misho       7: m4_version_prereq([2.70], [] ,[
        !             8: 
        !             9: # This is adapted with modifications from upstream Autoconf here:
        !            10: # https://git.savannah.gnu.org/cgit/autoconf.git/commit/?id=04be2b7a29d65d9a08e64e8e56e594c91749598c
        !            11: AC_DEFUN([_AC_FUNC_MALLOC_IF],
        !            12: [
        !            13:   AC_REQUIRE([AC_HEADER_STDC])dnl
        !            14:   AC_REQUIRE([AC_CANONICAL_HOST])dnl for cross-compiles
        !            15:   AC_CHECK_HEADERS([stdlib.h])
        !            16:   AC_CACHE_CHECK([for GNU libc compatible malloc],
        !            17:     [ac_cv_func_malloc_0_nonnull],
        !            18:     [AC_RUN_IFELSE(
        !            19:        [AC_LANG_PROGRAM(
        !            20:           [[#if defined STDC_HEADERS || defined HAVE_STDLIB_H
        !            21:             # include <stdlib.h>
        !            22:             #else
        !            23:             char *malloc ();
        !            24:             #endif
        !            25:           ]],
        !            26:           [[char *p = malloc (0);
        !            27:             int result = !p;
        !            28:             free (p);
        !            29:             return result;]])
        !            30:        ],
        !            31:        [ac_cv_func_malloc_0_nonnull=yes],
        !            32:        [ac_cv_func_malloc_0_nonnull=no],
        !            33:        [case "$host_os" in
        !            34:           # Guess yes on platforms where we know the result.
        !            35:           *-gnu* | gnu* | *-musl* | freebsd* | netbsd* | openbsd* \
        !            36:           | hpux* | solaris* | cygwin* | mingw*)
        !            37:             ac_cv_func_malloc_0_nonnull="guessing yes" ;;
        !            38:           # If we don't know, assume the worst.
        !            39:           *) ac_cv_func_malloc_0_nonnull="guessing no" ;;
        !            40:         esac
        !            41:        ])
        !            42:     ])
        !            43:   case "$ac_cv_func_malloc_0_nonnull" in
        !            44:     *yes)
        !            45:       $1
        !            46:       ;;
        !            47:     *)
        !            48:       $2
        !            49:       ;;
        !            50:   esac
        !            51: ])# _AC_FUNC_MALLOC_IF
        !            52: 
        !            53: ])
        !            54: 
        !            55: # gl_FUNC_MALLOC_GNU
        !            56: # ------------------
        !            57: # Test whether 'malloc (0)' is handled like in GNU libc, and replace malloc if
        !            58: # it is not.
        !            59: AC_DEFUN([gl_FUNC_MALLOC_GNU],
        !            60: [
        !            61:   AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
        !            62:   dnl _AC_FUNC_MALLOC_IF is defined in Autoconf.
        !            63:   _AC_FUNC_MALLOC_IF(
        !            64:     [AC_DEFINE([HAVE_MALLOC_GNU], [1],
        !            65:                [Define to 1 if your system has a GNU libc compatible 'malloc'
        !            66:                 function, and to 0 otherwise.])],
        !            67:     [AC_DEFINE([HAVE_MALLOC_GNU], [0])
        !            68:      REPLACE_MALLOC=1
        !            69:     ])
        !            70: ])
        !            71: 
1.1       misho      72: # gl_FUNC_MALLOC_POSIX
                     73: # --------------------
                     74: # Test whether 'malloc' is POSIX compliant (sets errno to ENOMEM when it
                     75: # fails), and replace malloc if it is not.
                     76: AC_DEFUN([gl_FUNC_MALLOC_POSIX],
                     77: [
1.1.1.2 ! misho      78:   AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
1.1       misho      79:   AC_REQUIRE([gl_CHECK_MALLOC_POSIX])
                     80:   if test $gl_cv_func_malloc_posix = yes; then
                     81:     AC_DEFINE([HAVE_MALLOC_POSIX], [1],
                     82:       [Define if the 'malloc' function is POSIX compliant.])
                     83:   else
1.1.1.2 ! misho      84:     REPLACE_MALLOC=1
1.1       misho      85:   fi
                     86: ])
                     87: 
                     88: # Test whether malloc, realloc, calloc are POSIX compliant,
                     89: # Set gl_cv_func_malloc_posix to yes or no accordingly.
                     90: AC_DEFUN([gl_CHECK_MALLOC_POSIX],
                     91: [
                     92:   AC_CACHE_CHECK([whether malloc, realloc, calloc are POSIX compliant],
                     93:     [gl_cv_func_malloc_posix],
                     94:     [
                     95:       dnl It is too dangerous to try to allocate a large amount of memory:
                     96:       dnl some systems go to their knees when you do that. So assume that
                     97:       dnl all Unix implementations of the function are POSIX compliant.
1.1.1.2 ! misho      98:       AC_COMPILE_IFELSE(
        !            99:         [AC_LANG_PROGRAM(
        !           100:            [[]],
        !           101:            [[#if defined _WIN32 && ! defined __CYGWIN__
        !           102:              choke me
        !           103:              #endif
        !           104:             ]])],
        !           105:         [gl_cv_func_malloc_posix=yes],
        !           106:         [gl_cv_func_malloc_posix=no])
1.1       misho     107:     ])
                    108: ])

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>