diff options
Diffstat (limited to 'gl/m4/malloc.m4')
| -rw-r--r-- | gl/m4/malloc.m4 | 79 |
1 files changed, 68 insertions, 11 deletions
diff --git a/gl/m4/malloc.m4 b/gl/m4/malloc.m4 index 910ac922..4b24a0b1 100644 --- a/gl/m4/malloc.m4 +++ b/gl/m4/malloc.m4 | |||
| @@ -1,25 +1,78 @@ | |||
| 1 | # malloc.m4 serial 9 | 1 | # malloc.m4 serial 14 |
| 2 | dnl Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc. | 2 | dnl Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc. |
| 3 | dnl This file is free software; the Free Software Foundation | 3 | dnl This file is free software; the Free Software Foundation |
| 4 | dnl gives unlimited permission to copy and/or distribute it, | 4 | dnl gives unlimited permission to copy and/or distribute it, |
| 5 | dnl with or without modifications, as long as this notice is preserved. | 5 | dnl with or without modifications, as long as this notice is preserved. |
| 6 | 6 | ||
| 7 | m4_version_prereq([2.70], [] ,[ | ||
| 8 | |||
| 9 | # This is taken from the following Autoconf patch: | ||
| 10 | # http://git.savannah.gnu.org/gitweb/?p=autoconf.git;a=commitdiff;h=7fbb553727ed7e0e689a17594b58559ecf3ea6e9 | ||
| 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 | [[return ! malloc (0);]]) | ||
| 27 | ], | ||
| 28 | [ac_cv_func_malloc_0_nonnull=yes], | ||
| 29 | [ac_cv_func_malloc_0_nonnull=no], | ||
| 30 | [case "$host_os" in | ||
| 31 | # Guess yes on platforms where we know the result. | ||
| 32 | *-gnu* | freebsd* | netbsd* | openbsd* \ | ||
| 33 | | hpux* | solaris* | cygwin* | mingw*) | ||
| 34 | ac_cv_func_malloc_0_nonnull=yes ;; | ||
| 35 | # If we don't know, assume the worst. | ||
| 36 | *) ac_cv_func_malloc_0_nonnull=no ;; | ||
| 37 | esac | ||
| 38 | ]) | ||
| 39 | ]) | ||
| 40 | AS_IF([test $ac_cv_func_malloc_0_nonnull = yes], [$1], [$2]) | ||
| 41 | ])# _AC_FUNC_MALLOC_IF | ||
| 42 | |||
| 43 | ]) | ||
| 44 | |||
| 45 | # gl_FUNC_MALLOC_GNU | ||
| 46 | # ------------------ | ||
| 47 | # Test whether 'malloc (0)' is handled like in GNU libc, and replace malloc if | ||
| 48 | # it is not. | ||
| 49 | AC_DEFUN([gl_FUNC_MALLOC_GNU], | ||
| 50 | [ | ||
| 51 | AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) | ||
| 52 | dnl _AC_FUNC_MALLOC_IF is defined in Autoconf. | ||
| 53 | _AC_FUNC_MALLOC_IF( | ||
| 54 | [AC_DEFINE([HAVE_MALLOC_GNU], [1], | ||
| 55 | [Define to 1 if your system has a GNU libc compatible 'malloc' | ||
| 56 | function, and to 0 otherwise.])], | ||
| 57 | [AC_DEFINE([HAVE_MALLOC_GNU], [0]) | ||
| 58 | REPLACE_MALLOC=1 | ||
| 59 | ]) | ||
| 60 | ]) | ||
| 61 | |||
| 7 | # gl_FUNC_MALLOC_POSIX | 62 | # gl_FUNC_MALLOC_POSIX |
| 8 | # -------------------- | 63 | # -------------------- |
| 9 | # Test whether 'malloc' is POSIX compliant (sets errno to ENOMEM when it | 64 | # Test whether 'malloc' is POSIX compliant (sets errno to ENOMEM when it |
| 10 | # fails), and replace malloc if it is not. | 65 | # fails), and replace malloc if it is not. |
| 11 | AC_DEFUN([gl_FUNC_MALLOC_POSIX], | 66 | AC_DEFUN([gl_FUNC_MALLOC_POSIX], |
| 12 | [ | 67 | [ |
| 68 | AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) | ||
| 13 | AC_REQUIRE([gl_CHECK_MALLOC_POSIX]) | 69 | AC_REQUIRE([gl_CHECK_MALLOC_POSIX]) |
| 14 | if test $gl_cv_func_malloc_posix = yes; then | 70 | if test $gl_cv_func_malloc_posix = yes; then |
| 15 | HAVE_MALLOC_POSIX=1 | ||
| 16 | AC_DEFINE([HAVE_MALLOC_POSIX], [1], | 71 | AC_DEFINE([HAVE_MALLOC_POSIX], [1], |
| 17 | [Define if the 'malloc' function is POSIX compliant.]) | 72 | [Define if the 'malloc' function is POSIX compliant.]) |
| 18 | else | 73 | else |
| 19 | AC_LIBOBJ([malloc]) | 74 | REPLACE_MALLOC=1 |
| 20 | HAVE_MALLOC_POSIX=0 | ||
| 21 | fi | 75 | fi |
| 22 | AC_SUBST([HAVE_MALLOC_POSIX]) | ||
| 23 | ]) | 76 | ]) |
| 24 | 77 | ||
| 25 | # Test whether malloc, realloc, calloc are POSIX compliant, | 78 | # Test whether malloc, realloc, calloc are POSIX compliant, |
| @@ -32,10 +85,14 @@ AC_DEFUN([gl_CHECK_MALLOC_POSIX], | |||
| 32 | dnl It is too dangerous to try to allocate a large amount of memory: | 85 | dnl It is too dangerous to try to allocate a large amount of memory: |
| 33 | dnl some systems go to their knees when you do that. So assume that | 86 | dnl some systems go to their knees when you do that. So assume that |
| 34 | dnl all Unix implementations of the function are POSIX compliant. | 87 | dnl all Unix implementations of the function are POSIX compliant. |
| 35 | AC_TRY_COMPILE([], | 88 | AC_COMPILE_IFELSE( |
| 36 | [#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ | 89 | [AC_LANG_PROGRAM( |
| 37 | choke me | 90 | [[]], |
| 38 | #endif | 91 | [[#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ |
| 39 | ], [gl_cv_func_malloc_posix=yes], [gl_cv_func_malloc_posix=no]) | 92 | choke me |
| 93 | #endif | ||
| 94 | ]])], | ||
| 95 | [gl_cv_func_malloc_posix=yes], | ||
| 96 | [gl_cv_func_malloc_posix=no]) | ||
| 40 | ]) | 97 | ]) |
| 41 | ]) | 98 | ]) |
