diff options
-rw-r--r-- | ChangeLog | 10 | ||||
-rw-r--r-- | Makefile.in | 1 | ||||
-rw-r--r-- | configure.in | 34 | ||||
-rw-r--r-- | lib/alloca.in.h | 56 | ||||
-rw-r--r-- | lib/gnulib.mk | 25 | ||||
-rw-r--r-- | m4/alloca.m4 | 121 | ||||
-rw-r--r-- | m4/gl-comp.m4 | 4 |
7 files changed, 226 insertions, 25 deletions
@@ -1,3 +1,13 @@ +2011-06-21 Paul Eggert <eggert@cs.ucla.edu> + + Use gnulib's alloca-opt module. + * .bzrignore: Add lib/alloca.h. + * Makefile.in (GNULIB_MODULES): Add alloca-opt. + * configure.in (AC_FUNC_ALLOCA): Remove almost all the alloca stuff, + as gnulib now does that for us. Put alloca check after gl_INIT. + * lib/gnulib.mk, m4/gl-comp.m4: Regenerate. + * lib/alloca.in.h, m4/alloca.m4: New files, from gnulib. + 2011-06-21 Leo Liu <sdl.web@gmail.com> * m4/sha256.m4: diff --git a/Makefile.in b/Makefile.in index 4fe51076ae..40d7610439 100644 --- a/Makefile.in +++ b/Makefile.in @@ -332,6 +332,7 @@ DOS_gnulib_comp.m4 = gl-comp.m4 # $(gnulib_srcdir) (relative to $(srcdir) and should have build tools # as per $(gnulib_srcdir)/DEPENDENCIES. GNULIB_MODULES = \ + alloca-opt \ careadlinkat crypto/md5 crypto/sha1 crypto/sha256 crypto/sha512 dtoastr \ filemode getloadavg getopt-gnu ignore-value intprops lstat mktime readlink \ socklen stdarg stdio strftime strtoumax symlink sys_stat diff --git a/configure.in b/configure.in index 0135b9f1bf..e4d2e2e96c 100644 --- a/configure.in +++ b/configure.in @@ -990,7 +990,7 @@ AC_SYS_LARGEFILE ## If user specified a crt-dir, use that unconditionally. if test "X$CRT_DIR" = "X"; then - + case "$canonical" in x86_64-*-linux-gnu* | s390x-*-linux-gnu*) ## On x86-64 and s390x GNU/Linux distributions, the standard library @@ -2565,15 +2565,6 @@ if test $emacs_cv_netdb_declares_h_errno = yes; then AC_DEFINE(HAVE_H_ERRNO, 1, [Define to 1 if netdb.h declares h_errno.]) fi -AC_FUNC_ALLOCA - -dnl src/alloca.c has been removed. Could also check if $ALLOCA is set? -dnl FIXME is there an autoconf test that does the right thing, without -dnl needing to call A_M_E afterwards? -if test x"$ac_cv_func_alloca_works" != xyes; then - AC_MSG_ERROR( [a system implementation of alloca is required] ) -fi - # fmod, logb, and frexp are found in -lm on most systems. # On HPUX 9.01, -lm does not contain logb, so check for sqrt. AC_CHECK_LIB(m, sqrt) @@ -2687,6 +2678,14 @@ gl_ASSERT_NO_GNULIB_POSIXCHECK gl_ASSERT_NO_GNULIB_TESTS gl_INIT +# Check for alloca. +dnl src/alloca.c has been removed. Could also check if $ALLOCA is set? +dnl FIXME is there an autoconf test that does the right thing, without +dnl needing to call A_M_E afterwards? +if test x"$ac_cv_func_alloca_works" != xyes; then + AC_MSG_ERROR( [a system implementation of alloca is required] ) +fi + # UNIX98 PTYs. AC_CHECK_FUNCS(grantpt) @@ -3534,20 +3533,7 @@ AH_BOTTOM([ #include <string.h> #include <stdlib.h> - -#ifdef HAVE_ALLOCA_H -# include <alloca.h> -#elif defined __GNUC__ -# define alloca __builtin_alloca -#elif defined _AIX -# define alloca __alloca -#else -# include <stddef.h> -# ifdef __cplusplus -extern "C" -# endif -void *alloca (size_t); -#endif +#include <alloca.h> #ifndef HAVE_STRCHR #define strchr(a, b) index (a, b) diff --git a/lib/alloca.in.h b/lib/alloca.in.h new file mode 100644 index 0000000000..5b69c6c81a --- /dev/null +++ b/lib/alloca.in.h @@ -0,0 +1,56 @@ +/* Memory allocation on the stack. + + Copyright (C) 1995, 1999, 2001-2004, 2006-2011 Free Software Foundation, + Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +/* Avoid using the symbol _ALLOCA_H here, as Bison assumes _ALLOCA_H + means there is a real alloca function. */ +#ifndef _GL_ALLOCA_H +#define _GL_ALLOCA_H + +/* alloca (N) returns a pointer to N bytes of memory + allocated on the stack, which will last until the function returns. + Use of alloca should be avoided: + - inside arguments of function calls - undefined behaviour, + - in inline functions - the allocation may actually last until the + calling function returns, + - for huge N (say, N >= 65536) - you never know how large (or small) + the stack is, and when the stack cannot fulfill the memory allocation + request, the program just crashes. + */ + +#ifndef alloca +# ifdef __GNUC__ +# define alloca __builtin_alloca +# elif defined _AIX +# define alloca __alloca +# elif defined _MSC_VER +# include <malloc.h> +# define alloca _alloca +# elif defined __DECC && defined __VMS +# define alloca __ALLOCA +# else +# include <stddef.h> +# ifdef __cplusplus +extern "C" +# endif +void *alloca (size_t); +# endif +#endif + +#endif /* _GL_ALLOCA_H */ diff --git a/lib/gnulib.mk b/lib/gnulib.mk index 5987138faf..0fd7f520ac 100644 --- a/lib/gnulib.mk +++ b/lib/gnulib.mk @@ -9,7 +9,7 @@ # the same distribution terms as the rest of that program. # # Generated by gnulib-tool. -# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=. --makefile-name=gnulib.mk --conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files careadlinkat crypto/md5 crypto/sha1 crypto/sha256 crypto/sha512 dtoastr filemode getloadavg getopt-gnu ignore-value intprops lstat mktime readlink socklen stdarg stdio strftime strtoumax symlink sys_stat +# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=. --makefile-name=gnulib.mk --conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files alloca-opt careadlinkat crypto/md5 crypto/sha1 crypto/sha256 crypto/sha512 dtoastr filemode getloadavg getopt-gnu ignore-value intprops lstat mktime readlink socklen stdarg stdio strftime strtoumax symlink sys_stat MOSTLYCLEANFILES += core *.stackdump @@ -21,6 +21,29 @@ libgnu_a_LIBADD = $(gl_LIBOBJS) libgnu_a_DEPENDENCIES = $(gl_LIBOBJS) EXTRA_libgnu_a_SOURCES = +## begin gnulib module alloca-opt + +BUILT_SOURCES += $(ALLOCA_H) + +# We need the following in order to create <alloca.h> when the system +# doesn't have one that works with the given compiler. +if GL_GENERATE_ALLOCA_H +alloca.h: alloca.in.h $(top_builddir)/config.status + $(AM_V_GEN)rm -f $@-t $@ && \ + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ + cat $(srcdir)/alloca.in.h; \ + } > $@-t && \ + mv -f $@-t $@ +else +alloca.h: $(top_builddir)/config.status + rm -f $@ +endif +MOSTLYCLEANFILES += alloca.h alloca.h-t + +EXTRA_DIST += alloca.in.h + +## end gnulib module alloca-opt + ## begin gnulib module allocator libgnu_a_SOURCES += allocator.c diff --git a/m4/alloca.m4 b/m4/alloca.m4 new file mode 100644 index 0000000000..891fc8bc36 --- /dev/null +++ b/m4/alloca.m4 @@ -0,0 +1,121 @@ +# alloca.m4 serial 12 +dnl Copyright (C) 2002-2004, 2006-2007, 2009-2011 Free Software Foundation, +dnl 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. + +AC_DEFUN([gl_FUNC_ALLOCA], +[ + AC_REQUIRE([AC_FUNC_ALLOCA]) + if test $ac_cv_func_alloca_works = no; then + gl_PREREQ_ALLOCA + fi + + # Define an additional variable used in the Makefile substitution. + if test $ac_cv_working_alloca_h = yes; then + AC_CACHE_CHECK([for alloca as a compiler built-in], [gl_cv_rpl_alloca], [ + AC_EGREP_CPP([Need own alloca], [ +#if defined __GNUC__ || defined _AIX || defined _MSC_VER + Need own alloca +#endif + ], [gl_cv_rpl_alloca=yes], [gl_cv_rpl_alloca=no]) + ]) + if test $gl_cv_rpl_alloca = yes; then + dnl OK, alloca can be implemented through a compiler built-in. + AC_DEFINE([HAVE_ALLOCA], [1], + [Define to 1 if you have 'alloca' after including <alloca.h>, + a header that may be supplied by this distribution.]) + ALLOCA_H=alloca.h + else + dnl alloca exists as a library function, i.e. it is slow and probably + dnl a memory leak. Don't define HAVE_ALLOCA in this case. + ALLOCA_H= + fi + else + ALLOCA_H=alloca.h + fi + AC_SUBST([ALLOCA_H]) + AM_CONDITIONAL([GL_GENERATE_ALLOCA_H], [test -n "$ALLOCA_H"]) +]) + +# Prerequisites of lib/alloca.c. +# STACK_DIRECTION is already handled by AC_FUNC_ALLOCA. +AC_DEFUN([gl_PREREQ_ALLOCA], [:]) + +# This works around a bug in autoconf <= 2.68. +# See <http://lists.gnu.org/archive/html/bug-gnulib/2011-06/msg00277.html>. + +m4_version_prereq([2.69], [] ,[ + +# This is taken from the following Autoconf patch: +# http://git.savannah.gnu.org/cgit/autoconf.git/commit/?id=6cd9f12520b0d6f76d3230d7565feba1ecf29497 + +# _AC_LIBOBJ_ALLOCA +# ----------------- +# Set up the LIBOBJ replacement of `alloca'. Well, not exactly +# AC_LIBOBJ since we actually set the output variable `ALLOCA'. +# Nevertheless, for Automake, AC_LIBSOURCES it. +m4_define([_AC_LIBOBJ_ALLOCA], +[# The SVR3 libPW and SVR4 libucb both contain incompatible functions +# that cause trouble. Some versions do not even contain alloca or +# contain a buggy version. If you still want to use their alloca, +# use ar to extract alloca.o from them instead of compiling alloca.c. +AC_LIBSOURCES(alloca.c) +AC_SUBST([ALLOCA], [\${LIBOBJDIR}alloca.$ac_objext])dnl +AC_DEFINE(C_ALLOCA, 1, [Define to 1 if using `alloca.c'.]) + +AC_CACHE_CHECK(whether `alloca.c' needs Cray hooks, ac_cv_os_cray, +[AC_EGREP_CPP(webecray, +[#if defined CRAY && ! defined CRAY2 +webecray +#else +wenotbecray +#endif +], ac_cv_os_cray=yes, ac_cv_os_cray=no)]) +if test $ac_cv_os_cray = yes; then + for ac_func in _getb67 GETB67 getb67; do + AC_CHECK_FUNC($ac_func, + [AC_DEFINE_UNQUOTED(CRAY_STACKSEG_END, $ac_func, + [Define to one of `_getb67', `GETB67', + `getb67' for Cray-2 and Cray-YMP + systems. This function is required for + `alloca.c' support on those systems.]) + break]) + done +fi + +AC_CACHE_CHECK([stack direction for C alloca], + [ac_cv_c_stack_direction], +[AC_RUN_IFELSE([AC_LANG_SOURCE( +[AC_INCLUDES_DEFAULT +int +find_stack_direction (int *addr, int depth) +{ + int dir, dummy = 0; + if (! addr) + addr = &dummy; + *addr = addr < &dummy ? 1 : addr == &dummy ? 0 : -1; + dir = depth ? find_stack_direction (addr, depth - 1) : 0; + return dir + dummy; +} + +int +main (int argc, char **argv) +{ + return find_stack_direction (0, argc + !argv + 20) < 0; +}])], + [ac_cv_c_stack_direction=1], + [ac_cv_c_stack_direction=-1], + [ac_cv_c_stack_direction=0])]) +AH_VERBATIM([STACK_DIRECTION], +[/* If using the C implementation of alloca, define if you know the + direction of stack growth for your system; otherwise it will be + automatically deduced at runtime. + STACK_DIRECTION > 0 => grows toward higher addresses + STACK_DIRECTION < 0 => grows toward lower addresses + STACK_DIRECTION = 0 => direction of growth unknown */ +@%:@undef STACK_DIRECTION])dnl +AC_DEFINE_UNQUOTED(STACK_DIRECTION, $ac_cv_c_stack_direction) +])# _AC_LIBOBJ_ALLOCA +]) diff --git a/m4/gl-comp.m4 b/m4/gl-comp.m4 index 64a7874c4c..24141a2639 100644 --- a/m4/gl-comp.m4 +++ b/m4/gl-comp.m4 @@ -26,6 +26,7 @@ AC_DEFUN([gl_EARLY], m4_pattern_allow([^gl_LIBOBJS$])dnl a variable m4_pattern_allow([^gl_LTLIBOBJS$])dnl a variable AC_REQUIRE([AC_PROG_RANLIB]) + # Code from module alloca-opt: # Code from module allocator: # Code from module arg-nonnull: # Code from module c++defs: @@ -94,6 +95,7 @@ AC_DEFUN([gl_INIT], m4_pushdef([gl_LIBSOURCES_DIR], []) gl_COMMON gl_source_base='lib' +gl_FUNC_ALLOCA AC_CHECK_FUNCS_ONCE([readlinkat]) gl_MD5 gl_SHA1 @@ -392,6 +394,7 @@ AC_DEFUN([gl_FILE_LIST], [ build-aux/arg-nonnull.h build-aux/c++defs.h build-aux/warn-on-use.h + lib/alloca.in.h lib/allocator.c lib/allocator.h lib/careadlinkat.c @@ -445,6 +448,7 @@ AC_DEFUN([gl_FILE_LIST], [ lib/unistd.in.h lib/verify.h m4/00gnulib.m4 + m4/alloca.m4 m4/c-strtod.m4 m4/extensions.m4 m4/filemode.m4 |