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
@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
@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
])
-# 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,
[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
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'
# 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
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