Hi Jim, The bug Richard Lloyd reported was caused by the use of the "old" idioms for function replacement, which don't allow a "#undef" for reverting to the system's original definition. But such a "#undef" is needed when lib/setenv.c is compiled as part of the relocwrapper programs.
As indicated in <http://lists.gnu.org/archive/html/bug-gnulib/2010-06/msg00145.html> most of the AC_FUNC_* macros that require replacement code will soon defer to gnulib. Here we have the same situation for AC_FUNC_MALLOC and AC_FUNC_REALLOC. Here are 3 patches to drop the uses of AC_FUNC_MALLOC and AC_FUNC_REALLOC. In this proposal instead we would use _AC_FUNC_MALLOC_IF and _AC_FUNC_REALLOC_IF, which are defined in Autoconf but undocumented. I'm not sure which is better: using these undocumented macros, or copying their code from Autoconf? (For calloc, gnulib already has its own copy of _AC_FUNC_CALLOC_IF.) OK to apply? 2010-06-20 Bruno Haible <br...@clisp.org> Use modern idiom for malloc() replacement. * modules/malloc (configure.ac): Invoke gl_FUNC_MALLOC_GNU instead of AC_FUNC_MALLOC. * m4/malloc.m4 (gl_FUNC_MALLOC_GNU): New macro, mostly copied from Autoconf's AC_FUNC_MALLOC. (gl_FUNC_MALLOC_POSIX): Rely on gl_STDLIB_H_DEFAULTS to initialize HAVE_MALLOC_POSIX. Invoke gl_REPLACE_MALLOC. (gl_REPLACE_MALLOC): New macro. --- modules/malloc.orig Mon Jun 21 02:22:12 2010 +++ modules/malloc Mon Jun 21 01:55:48 2010 @@ -13,7 +13,7 @@ malloc-posix configure.ac: -AC_FUNC_MALLOC +gl_FUNC_MALLOC_GNU AC_DEFINE([GNULIB_MALLOC_GNU], 1, [Define to indicate the 'malloc' module.]) Makefile.am: --- m4/malloc.m4.orig Mon Jun 21 02:22:12 2010 +++ m4/malloc.m4 Mon Jun 21 02:17:16 2010 @@ -1,25 +1,40 @@ -# malloc.m4 serial 9 +# malloc.m4 serial 10 dnl Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. +# gl_FUNC_MALLOC_GNU +# ------------------ +# Test whether 'malloc (0)' is handled like in GNU libc, and replace malloc if +# it is not. +AC_DEFUN([gl_FUNC_MALLOC_GNU], +[ + AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) + dnl _AC_FUNC_MALLOC_IF is defined in Autoconf. + _AC_FUNC_MALLOC_IF( + [AC_DEFINE([HAVE_MALLOC], [1], + [Define to 1 if your system has a GNU libc compatible 'malloc' + function, and to 0 otherwise.])], + [AC_DEFINE([HAVE_MALLOC], [0]) + gl_REPLACE_MALLOC + ]) +]) + # gl_FUNC_MALLOC_POSIX # -------------------- # Test whether 'malloc' is POSIX compliant (sets errno to ENOMEM when it # fails), and replace malloc if it is not. AC_DEFUN([gl_FUNC_MALLOC_POSIX], [ + AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) AC_REQUIRE([gl_CHECK_MALLOC_POSIX]) if test $gl_cv_func_malloc_posix = yes; then - HAVE_MALLOC_POSIX=1 AC_DEFINE([HAVE_MALLOC_POSIX], [1], [Define if the 'malloc' function is POSIX compliant.]) else - AC_LIBOBJ([malloc]) - HAVE_MALLOC_POSIX=0 + gl_REPLACE_MALLOC fi - AC_SUBST([HAVE_MALLOC_POSIX]) ]) # Test whether malloc, realloc, calloc are POSIX compliant, @@ -39,3 +54,9 @@ ], [gl_cv_func_malloc_posix=yes], [gl_cv_func_malloc_posix=no]) ]) ]) + +AC_DEFUN([gl_REPLACE_MALLOC], +[ + AC_LIBOBJ([malloc]) + HAVE_MALLOC_POSIX=0 +]) 2010-06-20 Bruno Haible <br...@clisp.org> Use modern idiom for realloc() replacement. * modules/realloc (configure.ac): Invoke gl_FUNC_REALLOC_GNU instead of AC_FUNC_REALLOC. * m4/realloc.m4 (gl_FUNC_REALLOC_GNU): New macro, mostly copied from Autoconf's AC_FUNC_REALLOC. (gl_FUNC_REALLOC_POSIX): Rely on gl_STDLIB_H_DEFAULTS to initialize HAVE_REALLOC_POSIX. Invoke gl_REPLACE_REALLOC. (gl_REPLACE_REALLOC): New macro. --- modules/realloc.orig Mon Jun 21 02:25:25 2010 +++ modules/realloc Mon Jun 21 01:56:09 2010 @@ -13,7 +13,7 @@ realloc-posix configure.ac: -AC_FUNC_REALLOC +gl_FUNC_REALLOC_GNU AC_DEFINE([GNULIB_REALLOC_GNU], 1, [Define to indicate the 'realloc' module.]) Makefile.am: --- m4/realloc.m4.orig Mon Jun 21 02:25:25 2010 +++ m4/realloc.m4 Mon Jun 21 02:16:56 2010 @@ -1,23 +1,44 @@ -# realloc.m4 serial 9 +# realloc.m4 serial 10 dnl Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. +# gl_FUNC_REALLOC_GNU +# ------------------- +# Test whether 'realloc (0, 0)' is handled like in GNU libc, and replace +# realloc if it is not. +AC_DEFUN([gl_FUNC_REALLOC_GNU], +[ + AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) + dnl _AC_FUNC_REALLOC_IF is defined in Autoconf. + _AC_FUNC_REALLOC_IF( + [AC_DEFINE([HAVE_REALLOC], [1], + [Define to 1 if your system has a GNU libc compatible 'realloc' + function, and to 0 otherwise.])], + [AC_DEFINE([HAVE_REALLOC], [0]) + gl_REPLACE_REALLOC + ]) +])# gl_FUNC_REALLOC_GNU + # gl_FUNC_REALLOC_POSIX # --------------------- # Test whether 'realloc' is POSIX compliant (sets errno to ENOMEM when it # fails), and replace realloc if it is not. AC_DEFUN([gl_FUNC_REALLOC_POSIX], [ + AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) AC_REQUIRE([gl_CHECK_MALLOC_POSIX]) if test $gl_cv_func_malloc_posix = yes; then - HAVE_REALLOC_POSIX=1 AC_DEFINE([HAVE_REALLOC_POSIX], [1], [Define if the 'realloc' function is POSIX compliant.]) else - AC_LIBOBJ([realloc]) - HAVE_REALLOC_POSIX=0 + gl_REPLACE_REALLOC fi - AC_SUBST([HAVE_REALLOC_POSIX]) +]) + +AC_DEFUN([gl_REPLACE_REALLOC], +[ + AC_LIBOBJ([realloc]) + HAVE_REALLOC_POSIX=0 ]) 2010-06-20 Bruno Haible <br...@clisp.org> Use modern idiom for calloc() replacement. * modules/calloc (configure.ac): Invoke gl_FUNC_CALLOC_GNU instead of AC_FUNC_CALLOC. * m4/calloc.m4 (gl_FUNC_CALLOC_GNU): Renamed from AC_FUNC_CALLOC. Require gl_STDLIB_H_DEFAULTS. Invoke gl_REPLACE_CALLOC. (gl_FUNC_CALLOC_POSIX): Rely on gl_STDLIB_H_DEFAULTS to initialize HAVE_CALLOC_POSIX. Invoke gl_REPLACE_CALLOC. (gl_REPLACE_CALLOC): New macro. --- modules/calloc.orig Mon Jun 21 02:26:56 2010 +++ modules/calloc Mon Jun 21 01:56:09 2010 @@ -9,7 +9,7 @@ calloc-posix configure.ac: -AC_FUNC_CALLOC +gl_FUNC_CALLOC_GNU Makefile.am: --- m4/calloc.m4.orig Mon Jun 21 02:26:56 2010 +++ m4/calloc.m4 Mon Jun 21 02:17:21 2010 @@ -1,4 +1,4 @@ -# calloc.m4 serial 9 +# calloc.m4 serial 10 # Copyright (C) 2004-2010 Free Software Foundation, Inc. # This file is free software; the Free Software Foundation @@ -27,20 +27,21 @@ ])# AC_FUNC_CALLOC -# AC_FUNC_CALLOC -# --------------- +# gl_FUNC_CALLOC_GNU +# ------------------ # Report whether `calloc (0, 0)' is properly handled, and replace calloc if # needed. -AC_DEFUN([AC_FUNC_CALLOC], -[_AC_FUNC_CALLOC_IF( - [AC_DEFINE([HAVE_CALLOC], [1], - [Define to 1 if your system has a GNU libc compatible `calloc' - function, and to 0 otherwise.])], - [AC_DEFINE([HAVE_CALLOC], [0]) - AC_LIBOBJ([calloc]) - AC_DEFINE([calloc], [rpl_calloc], - [Define to rpl_calloc if the replacement function should be used.])]) -])# AC_FUNC_CALLOC +AC_DEFUN([gl_FUNC_CALLOC_GNU], +[ + AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) + _AC_FUNC_CALLOC_IF( + [AC_DEFINE([HAVE_CALLOC], [1], + [Define to 1 if your system has a GNU libc compatible `calloc' + function, and to 0 otherwise.])], + [AC_DEFINE([HAVE_CALLOC], [0]) + gl_REPLACE_CALLOC + ]) +])# gl_FUNC_CALLOC_GNU # gl_FUNC_CALLOC_POSIX @@ -49,14 +50,18 @@ # fails), and replace calloc if it is not. AC_DEFUN([gl_FUNC_CALLOC_POSIX], [ + AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) AC_REQUIRE([gl_CHECK_MALLOC_POSIX]) if test $gl_cv_func_malloc_posix = yes; then - HAVE_CALLOC_POSIX=1 AC_DEFINE([HAVE_CALLOC_POSIX], [1], [Define if the 'calloc' function is POSIX compliant.]) else - AC_LIBOBJ([calloc]) - HAVE_CALLOC_POSIX=0 + gl_REPLACE_CALLOC fi - AC_SUBST([HAVE_CALLOC_POSIX]) +]) + +AC_DEFUN([gl_REPLACE_CALLOC], +[ + AC_LIBOBJ([calloc]) + HAVE_CALLOC_POSIX=0 ])