]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
* lib/autoconf/functions.m4 (AC_FUNC_REALLOC, _AC_FUNC_REALLOC)
authorAkim Demaille <akim@epita.fr>
Wed, 17 Jul 2002 08:09:42 +0000 (08:09 +0000)
committerAkim Demaille <akim@epita.fr>
Wed, 17 Jul 2002 08:09:42 +0000 (08:09 +0000)
(_AC_FUNC_MALLOC): New.
(AC_FUNC_MALLOC): Use the latter.
Define HAVE_MALLOC to 0 if broken.
* doc/autoconf.texi (Particular Functions): Adjust.

ChangeLog
NEWS
doc/autoconf.texi
lib/autoconf/functions.m4
lib/autoscan/functions

index 6a08211bb6925e7db5931ebcd59844bd136210d5..c6bb9a94238d05f924142ecd9065e0887118ce7d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2002-07-17  Akim Demaille  <akim@epita.fr>
+
+       * lib/autoconf/functions.m4 (AC_FUNC_REALLOC, _AC_FUNC_REALLOC)
+       (_AC_FUNC_MALLOC): New.
+       (AC_FUNC_MALLOC): Use the latter.
+       Define HAVE_MALLOC to 0 if broken.
+       * doc/autoconf.texi (Particular Functions): Adjust.
+
 2002-07-16  Akim Demaille  <akim@epita.fr>
 
        * lib/autoconf/c.m4 (AC_C_BACKSLASH_A): New.
diff --git a/NEWS b/NEWS
index cac2aec52009f90107ffda44e979c27474937743..983080320d88d68ee05445cc36fe3377013619e2 100644 (file)
--- a/NEWS
+++ b/NEWS
 
   AC_C_BACKSLASH_A, AC_CONFIG_LIBOBJ_DIR, AC_GNU_SOURCE,
   AC_PROG_EGREP, AC_PROG_FGREP, AC_REPLACE_FNMATCH,
-  AC_FUNC_FNMATCH_GNU, AC_TYPE_MBSTATE_T.
+  AC_FUNC_FNMATCH_GNU, AC_FUNC_REALLOC, AC_TYPE_MBSTATE_T.
 
 - AC_FUNC_GETLOADAVG
   looks for getloadavg.c in the CONFIG_LIBOBJ_DIR.
 
+- AC_FUNC_MALLOC
+   Now defines HAVE_MALLOC to 0 if `malloc' does not work, and asks
+   for an AC_LIBOBJ replacement.
+
 ** Bug fixes
 
 - Spurious complaints from `m4_bmatch' about invalid regular
index 691cec2eed4ca318ea787f30e98b3c6525e37376..70acf26e5cce293f4ce0f68d7dbdaafdd8c8f3cf 100644 (file)
@@ -3737,10 +3737,40 @@ If @code{lstat} behaves properly, define
 
 @defmac AC_FUNC_MALLOC
 @acindex FUNC_MALLOC
+@cvindex HAVE_MALLOC
+@cvindex malloc
 @c @fuindex malloc
 @prindex @code{malloc}
 If the @code{malloc} works correctly (@samp{malloc (0)} returns a valid
-pointer), define @code{HAVE_MALLOC}.
+pointer), define @code{HAVE_MALLOC} to 1.  Otherwise define
+@code{HAVE_MALLOC} to 0, ask for an @code{AC_LIBOBJ} replacement for
+@samp{malloc}, and define @code{malloc} to @code{rpl_malloc} so that the
+native @code{malloc} is not used in the main project.
+
+Typically, the replacement file @file{malloc.c} should look like (note
+the @samp{#undef malloc}:
+
+@verbatim
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+#undef malloc
+
+#include <sys/types.h>
+
+char *malloc ();
+
+/* Allocate an N-byte block of memory from the heap.
+   If N is zero, allocate a 1-byte block.  */
+
+char *
+rpl_malloc (size_t n)
+{
+  if (n == 0)
+    n = 1;
+  return malloc (n);
+}
+@end verbatim
 @end defmac
 
 @defmac AC_FUNC_MEMCMP
@@ -3782,6 +3812,20 @@ If the obstacks are found, define @code{HAVE_OBSTACK}, else require an
 @code{AC_LIBOBJ} replacement for @samp{obstack}.
 @end defmac
 
+@defmac AC_FUNC_REALLOC
+@acindex FUNC_REALLOC
+@cvindex HAVE_REALLOC
+@cvindex realloc
+@c @fuindex realloc
+@prindex @code{realloc}
+If the @code{realloc} works correctly (@samp{realloc (0, 0)} returns a
+valid pointer), define @code{HAVE_REALLOC} to 1.  Otherwise define
+@code{HAVE_REALLOC} to 0, ask for an @code{AC_LIBOBJ} replacement for
+@samp{realloc}, and define @code{realloc} to @code{rpl_realloc} so that
+the native @code{realloc} is not used in the main project.  See
+@code{AC_FUNC_MALLOC} for details.
+@end defmac
+
 @defmac AC_FUNC_SELECT_ARGTYPES
 @acindex FUNC_SELECT_ARGTYPES
 @cvindex SELECT_TYPE_ARG1
index 1f02ff2cbc9df08d7dafa3adb9e153834fb44bb8..c0aec9dff63ca10edcd6e2e84911264794bcbed8 100644 (file)
@@ -714,10 +714,10 @@ fi
 ])
 
 
-# AC_FUNC_MALLOC
-# --------------
-# Is `malloc (0)' properly handled?
-AC_DEFUN([AC_FUNC_MALLOC],
+# _AC_FUNC_MALLOC_IF(IF-WORKS, IF-NOT)
+# ------------------------------------
+# If `malloc (0)' properly handled, run IF-WORKS, otherwise, IF-NOT.
+AC_DEFUN([_AC_FUNC_MALLOC_IF],
 [AC_REQUIRE([AC_HEADER_STDC])dnl
 AC_CHECK_HEADERS(stdlib.h)
 AC_CACHE_CHECK([for working malloc], ac_cv_func_malloc_works,
@@ -733,10 +733,23 @@ char *malloc ();
                [ac_cv_func_malloc_works=yes],
                [ac_cv_func_malloc_works=no],
                [ac_cv_func_malloc_works=no])])
-if test $ac_cv_func_malloc_works = yes; then
-  AC_DEFINE(HAVE_MALLOC, 1,
-            [Define to 1 if your system has a working `malloc' function.])
-fi
+AS_IF([test $ac_cv_func_malloc_works = yes], [$1], [$2])
+])# AC_FUNC_MALLOC
+
+
+# AC_FUNC_MALLOC
+# --------------
+# Report whether `malloc (0)' properly handled, and replace malloc if
+# needed.
+AC_DEFUN([AC_FUNC_MALLOC],
+[_AC_FUNC_MALLOC_IF(
+  [AC_DEFINE([HAVE_MALLOC], 1,
+             [Define to 1 if your system has a working `malloc' function,
+              and to 0 otherwise.])],
+  [AC_DEFINE([HAVE_MALLOC], 0)
+   AC_LIBOBJ(malloc)
+   AC_DEFINE([malloc], [rpl_malloc],
+      [Define to rpl_malloc if the replacement function should be used.])])
 ])# AC_FUNC_MALLOC
 
 
@@ -1115,6 +1128,46 @@ fi
 AU_ALIAS([AM_FUNC_OBSTACK], [AC_FUNC_OBSTACK])
 
 
+
+# _AC_FUNC_REALLOC_IF(IF-WORKS, IF-NOT)
+# -------------------------------------
+# If `realloc (0, 0)' properly handled, run IF-WORKS, otherwise, IF-NOT.
+AC_DEFUN([_AC_FUNC_REALLOC_IF],
+[AC_REQUIRE([AC_HEADER_STDC])dnl
+AC_CHECK_HEADERS(stdlib.h)
+AC_CACHE_CHECK([for working realloc], ac_cv_func_realloc_works,
+[AC_RUN_IFELSE(
+[AC_LANG_PROGRAM(
+[[#if STDC_HEADERS || HAVE_STDLIB_H
+# include <stdlib.h>
+#else
+char *realloc ();
+#endif
+]],
+                 [exit (realloc (0, 0) ? 0 : 1);])],
+               [ac_cv_func_realloc_works=yes],
+               [ac_cv_func_realloc_works=no],
+               [ac_cv_func_realloc_works=no])])
+AS_IF([test $ac_cv_func_realloc_works = yes], [$1], [$2])
+])# AC_FUNC_REALLOC
+
+
+# AC_FUNC_REALLOC
+# ---------------
+# Report whether `realloc (0, 0)' properly handled, and replace realloc if
+# needed.
+AC_DEFUN([AC_FUNC_REALLOC],
+[_AC_FUNC_REALLOC_IF(
+  [AC_DEFINE([HAVE_REALLOC], 1,
+             [Define to 1 if your system has a working `realloc' function,
+              and to 0 otherwise.])],
+  [AC_DEFINE([HAVE_REALLOC], 0)
+   AC_LIBOBJ([realloc])
+   AC_DEFINE([realloc], [rpl_realloc],
+      [Define to rpl_realloc if the replacement function should be used.])])
+])# AC_FUNC_REALLOC
+
+
 # AC_FUNC_SELECT_ARGTYPES
 # -----------------------
 # Determine the correct type to be passed to each of the `select'
index 8f555f2c45d9a5c2824b16d3922868391ec6e64d..dc64a1e66accd7ca9d7721866522f480dc6f8bde 100644 (file)
@@ -1,5 +1,5 @@
 # functions -- autoscan's mapping from functions to Autoconf macros
-# Copyright 1992, 1993, 1994, 1996, 1999, 2000, 2001, 2002
+# Copyright (C) 1992, 1993, 1994, 1996, 1999, 2000, 2001, 2002
 # Free Software Foundation, Inc.
 
 # This program is free software; you can redistribute it and/or modify
@@ -51,6 +51,7 @@ minor         AC_HEADER_MAJOR
 mktime         AC_FUNC_MKTIME
 mmap           AC_FUNC_MMAP
 obstack_init   AC_FUNC_OBSTACK
+realloc                AC_FUNC_REALLOC
 rindex         AC_HEADER_STDC
 setpgrp                AC_FUNC_SETPGRP
 setvbuf                AC_FUNC_SETVBUF_REVERSED