From: Paul Eggert Date: Fri, 21 Dec 2012 05:21:04 +0000 (-0800) Subject: AC_FUNC_ALLOCA: port to recent BSDs and remove obsolete AIX X-Git-Tag: v2.69b~182 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fd29dbd7d966f0fbde031a67955d77d50268c3d5;p=thirdparty%2Fautoconf.git AC_FUNC_ALLOCA: port to recent BSDs and remove obsolete AIX * doc/autoconf.texi (Particular Functions): Remove the AIX case from the recommended code, as the most recent version of the AIX compiler that IBM still supports (V10.1 as of this writing) has and thus longer needs this, and the old suggestion wasn't completely working anyway. Remove obsolete discussion of SVR3 libPW alloca and of SVR4 libucb alloca. * lib/autoconf/functions.m4 (AC_FUNC_ALLOCA): Rework to match documentation, including abovementioned AIX change. Inconsistency with documentation reported by Steven G. Johnson in . As this adds stdlib.h, it should also fix the problems on recent BSD platforms noted by Patrick Welche in http://lists.gnu.org/archive/html/autoconf-patches/2012-12/msg00009.html though the fix differs from NetBSD's current workaround. Also, don't bother checking for alloca if works, as the latter implies the former. --- diff --git a/doc/autoconf.texi b/doc/autoconf.texi index 3f0dbb41..c9c1677d 100644 --- a/doc/autoconf.texi +++ b/doc/autoconf.texi @@ -4858,15 +4858,11 @@ in some cases how they respond when given certain arguments. @prindex @code{alloca} @hdrindex{alloca.h} @c @caindex working_alloca_h -Check how to get @code{alloca}. Tries to get a builtin version by -checking for @file{alloca.h} or the predefined C preprocessor macros -@code{__GNUC__} and @code{_AIX}. If this macro finds @file{alloca.h}, -it defines @code{HAVE_ALLOCA_H}. - -If those attempts fail, it looks for the function in the standard C -library. If any of those methods succeed, it defines -@code{HAVE_ALLOCA}. Otherwise, it sets the output variable -@code{ALLOCA} to @samp{$@{LIBOBJDIR@}alloca.o} and defines +Check for the @code{alloca} function. Define @code{HAVE_ALLOCA_H} if +@file{alloca.h} defines a working @code{alloca}. If not, look for a +builtin alternative. If either method succeeds, define +@code{HAVE_ALLOCA}. Otherwise, set the output variable @code{ALLOCA} to +@samp{$@{LIBOBJDIR@}alloca.o} and define @code{C_ALLOCA} (so programs can periodically call @samp{alloca (0)} to garbage collect). This variable is separate from @code{LIBOBJS} so multiple programs can share the value of @code{ALLOCA} without needing @@ -4874,13 +4870,6 @@ to create an actual library, in case only some of them use the code in @code{LIBOBJS}. The @samp{$@{LIBOBJDIR@}} prefix serves the same purpose as in @code{LIBOBJS} (@pxref{AC_LIBOBJ vs LIBOBJS}). -This macro does not try to get @code{alloca} from the System V R3 -@file{libPW} or the System V R4 @file{libucb} because those libraries -contain some incompatible functions that cause trouble. Some versions -do not even contain @code{alloca} or contain a buggy version. If you -still want to use their @code{alloca}, use @code{ar} to extract -@file{alloca.o} from them instead of compiling @file{alloca.c}. - Source files that use @code{alloca} should start with a piece of code like the following, to declare it properly. @@ -4895,8 +4884,6 @@ like the following, to declare it properly. #elif !defined alloca # ifdef __GNUC__ # define alloca __builtin_alloca -# elif defined _AIX -# define alloca __alloca # elif defined _MSC_VER # include # define alloca _alloca diff --git a/lib/autoconf/functions.m4 b/lib/autoconf/functions.m4 index de7a6b86..db7be052 100644 --- a/lib/autoconf/functions.m4 +++ b/lib/autoconf/functions.m4 @@ -372,36 +372,36 @@ AC_CACHE_CHECK([for working alloca.h], ac_cv_working_alloca_h, [ac_cv_working_alloca_h=no])]) if test $ac_cv_working_alloca_h = yes; then AC_DEFINE(HAVE_ALLOCA_H, 1, - [Define to 1 if you have and it should be used - (not on Ultrix).]) + [Define to 1 if works.]) fi AC_CACHE_CHECK([for alloca], ac_cv_func_alloca_works, -[AC_LINK_IFELSE([AC_LANG_PROGRAM( -[[#ifdef __GNUC__ -# define alloca __builtin_alloca -#else -# ifdef _MSC_VER +[if test $ac_cv_working_alloca_h = yes; then + ac_cv_func_alloca_works=yes +else + AC_LINK_IFELSE([AC_LANG_PROGRAM( +[[#if defined STDC_HEADERS || defined HAVE_STDLIB_H +# include +#endif +#include +#ifndef alloca +# ifdef __GNUC__ +# define alloca __builtin_alloca +# elif defined _MSC_VER # include # define alloca _alloca # else -# ifdef HAVE_ALLOCA_H -# include -# else -# ifdef _AIX - #pragma alloca -# else -# ifndef alloca /* predefined by HP cc +Olibcalls */ -void *alloca (size_t); -# endif -# endif +# ifdef __cplusplus +extern "C" # endif +void *alloca (size_t); # endif #endif ]], [[char *p = (char *) alloca (1); if (p) return 0;]])], [ac_cv_func_alloca_works=yes], [ac_cv_func_alloca_works=no])]) +fi if test $ac_cv_func_alloca_works = yes; then AC_DEFINE(HAVE_ALLOCA, 1,