changeset 5063:1aecdc8063ba

alloca cleanup: always include <alloca.h>.
author Paul Eggert <eggert@cs.ucla.edu>
date Mon, 17 May 2004 05:41:42 +0000
parents aa119e787246
children 3d7c85c0bae6
files ChangeLog lib/ChangeLog lib/alloca.c lib/alloca_.h lib/fnmatch.c lib/regex.c m4/ChangeLog m4/alloca.m4 modules/getdate modules/setenv
diffstat 10 files changed, 80 insertions(+), 76 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2004-05-16  Paul Eggert  <eggert@cs.ucla.edu>
+
+	* modules/getdate: Depend on alloca.
+	* modules/setenv: Likewise.
+
 2004-05-04  Derek Price  <derek@ximbiot.com>
 
 	* modules/argp: Remove dependency on alloca.
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -1,3 +1,16 @@
+2004-05-16  Paul Eggert  <eggert@cs.ucla.edu>
+	    Derek Price  <derek@ximbiot.com>
+
+	* alloca.c: Include <alloca.h>, to get our interface.
+	* alloca_.h: Use __alloca on AIX, so that we don't have to
+	include <alloca.h> first.  Use C89 prototype for alloca; this
+	requires including <stddef.h> for size_t.  Use extern "C" if C++.
+	Use #elif for simplicity, since we can assume C89 now.
+	Don't try to source the system alloca.h since it will not be found
+	and to prevent recursively including its replacement.
+	* fnmatch.c: Include <alloca.h> instead of opencoding.
+	* lib/regex.c: Likewise.
+
 2004-05-16  Derek Price  <derek@ximbiot.com>
 	    Paul Eggert  <eggert@cs.ucla.edu>
 
@@ -5,11 +18,11 @@
 	arguments, and meaning of delim2 (now uses EOF, not 0, to indicate
 	no delimiter).
 	
-	* lib/getline.c: Don't include stddef.h or stdio.h, since our
+	* getline.c: Don't include stddef.h or stdio.h, since our
 	interface does that.
 	(getline): Always use getdelim, so that we don't have two
 	copies of this code.
-	* lib/getndelim2.c: Include <limits.h>, <inttypes.h>, <stdint.h>
+	* getndelim2.c: Include <limits.h>, <inttypes.h>, <stdint.h>
 	if available.
 	(PTRDIFF_MAX, SIZE_MAX, SSIZE_MAX): Define if not defined.
 	(GETNDELIM2_MAXIMUM): New macro.
@@ -17,15 +30,15 @@
 	instead of the old practice of delim2==0.  All callers changed.
 	Return -1 on overflow, instead of returning junk.
 	Do not set *linesize unless allocation succeeds.
-	* lib/getndelim2.h: Do not include stddef.h; no longer needed, now
+	* getndelim2.h: Do not include stddef.h; no longer needed, now
 	that we include sys/types.h.
-	* lib/getnline.h: Likewise.
-	* lib/getndelim2.h (GETNLINE_NO_LIMIT): New macro.
+	* getnline.h: Likewise.
+	* getndelim2.h (GETNLINE_NO_LIMIT): New macro.
 	(getndelim2): Reorder arguments.
-	* lib/getnline.c (getnline, getndelim):
+	* getnline.c (getnline, getndelim):
 	Don't discard the NMAX argument.
 	(getnline): Invoke getndelim, to avoid code duplication.
-	* lib/getnline.h (GETNLINE_NO_LIMIT): New macro, used instead
+	* getnline.h (GETNLINE_NO_LIMIT): New macro, used instead
 	of (size_t) -1 by callers of the getnline family.
 
 2004-05-13  Paul Eggert  <eggert@cs.ucla.edu>
--- a/lib/alloca.c
+++ b/lib/alloca.c
@@ -25,6 +25,8 @@
 # include <config.h>
 #endif
 
+#include <alloca.h>
+
 #include <string.h>
 #include <stdlib.h>
 
--- a/lib/alloca_.h
+++ b/lib/alloca_.h
@@ -1,5 +1,7 @@
 /* Memory allocation on the stack.
-   Copyright (C) 1995, 1999, 2001-2003 Free Software Foundation, Inc.
+
+   Copyright (C) 1995, 1999, 2001, 2002, 2003, 2004 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
@@ -23,8 +25,8 @@
 #ifndef _ALLOCA_H
 # define _ALLOCA_H
 
-/* alloca(N) returns a pointer (void* or char*) to N bytes of memory
-   allocated on the stack, and which will last until the function returns.
+/* 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
@@ -34,35 +36,19 @@
        request, the program just crashes.
  */
 
-# ifdef __GNUC__
-#  ifndef alloca
-#   define alloca __builtin_alloca
-#  endif
-# else
-#  ifdef _MSC_VER
-#   include <malloc.h>
-#   define alloca _alloca
-#  else
-#   if HAVE_ALLOCA_H
-#    include <alloca.h>
-#   else
-#    ifdef _AIX
- #    pragma alloca
-#    else
-#     ifdef __hpux /* This section must match that of bison generated files. */
-#      ifdef __cplusplus
-extern "C" void *alloca (unsigned int);
-#      else /* not __cplusplus */
-extern void *alloca ();
-#      endif /* not __cplusplus */
-#     else /* not __hpux */
-#      ifndef alloca
-extern char *alloca ();
-#      endif
-#     endif /* __hpux */
-#    endif
-#   endif
-#  endif
+#ifdef __GNUC__
+# define alloca __builtin_alloca
+#elif defined _AIX
+# define alloca __alloca 
+#elif defined _MSC_VER
+# include <malloc.h>
+# define alloca _alloca
+#else
+# include <stddef.h>
+# ifdef  __cplusplus
+extern "C"
 # endif
+void *alloca (size_t);
+#endif
 
 #endif /* _ALLOCA_H */
--- a/lib/fnmatch.c
+++ b/lib/fnmatch.c
@@ -24,29 +24,13 @@
 # define _GNU_SOURCE	1
 #endif
 
-#ifdef __GNUC__
-# define alloca __builtin_alloca
-# define HAVE_ALLOCA 1
-#else
-# if defined HAVE_ALLOCA_H || defined _LIBC
-#  include <alloca.h>
-# else
-#  ifdef _AIX
- #  pragma alloca
-#  else
-#   ifndef alloca
-char *alloca ();
-#   endif
-#  endif
-# endif
-#endif
-
 #if ! defined __builtin_expect && __GNUC__ < 3
 # define __builtin_expect(expr, expected) (expr)
 #endif
 
 #include <fnmatch.h>
 
+#include <alloca.h>
 #include <assert.h>
 #include <ctype.h>
 #include <errno.h>
--- a/lib/regex.c
+++ b/lib/regex.c
@@ -4,7 +4,7 @@
    internationalization features.)
 
    Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
-   2002, 2003 Free Software Foundation, Inc.
+   2002, 2003, 2004 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
@@ -275,13 +275,7 @@
 #  ifndef alloca
 
 /* Make alloca work the best possible way.  */
-#   ifdef __GNUC__
-#    define alloca __builtin_alloca
-#   else /* not __GNUC__ */
-#    if HAVE_ALLOCA_H
-#     include <alloca.h>
-#    endif /* HAVE_ALLOCA_H */
-#   endif /* not __GNUC__ */
+#   include <alloca.h>
 
 #  endif /* not alloca */
 
--- a/m4/ChangeLog
+++ b/m4/ChangeLog
@@ -1,8 +1,16 @@
+2004-05-16  Paul Eggert  <eggert@cs.ucla.edu>
+
+	* alloca.m4 (gl_FUNC_ALLOCA): Define HAVE_ALLOCA_H always,
+	for backward compatibility with older code.  We need our own
+	alloca.h if _AIX is defined.  Define HAVE_ALLOCA if we discover
+	it under some other name, and our alloca.h will define it.
+
 2004-05-13  Paul Eggert  <eggert@cs.ucla.edu>
 
-	* gettime.m4 (gl_GETTIME): Require gl_TIMESPEC.  Check for gettimeofday.
-	* settime.m4 (gl_SETTIME): Require gl_TIMESPEC.  Check for settimeofday,
-	stime.
+	* gettime.m4 (gl_GETTIME): Require gl_TIMESPEC.
+	Check for gettimeofday.
+	* settime.m4 (gl_SETTIME): Require gl_TIMESPEC.
+	Check for settimeofday, stime.
 	
 2004-04-20  Paul Eggert  <eggert@twinsun.com>
 
--- a/m4/alloca.m4
+++ b/m4/alloca.m4
@@ -1,5 +1,5 @@
-# alloca.m4 serial 3
-dnl Copyright (C) 2002-2003 Free Software Foundation, Inc.
+# alloca.m4 serial 4
+dnl Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
 dnl This file is free software, distributed under the terms of the GNU
 dnl General Public License.  As a special exception to the GNU General
 dnl Public License, this file may be distributed as part of a program
@@ -18,15 +18,25 @@
   fi
 
   # Define an additional variable used in the Makefile substitution.
-
-  AC_EGREP_CPP([Need own alloca], [
-#if defined __GNUC__ || defined _MSC_VER || !HAVE_ALLOCA_H
-  Need own alloca
+  if test $ac_cv_working_alloca_h = yes; then
+    AC_EGREP_CPP([Need own alloca], [
+#if defined __GNUC__ || defined _AIX || defined _MSC_VER
+	Need own alloca
 #endif
-    ],
-    ALLOCA_H=alloca.h,
-    ALLOCA_H=)
+      ],
+      [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],
+      [ALLOCA_H=])
+  else
+    ALLOCA_H=alloca.h
+  fi
   AC_SUBST([ALLOCA_H])
+
+  AC_DEFINE(HAVE_ALLOCA_H, 1,
+    [Define HAVE_ALLOCA_H for backward compatibility with older code
+     that includes <alloca.h> only if HAVE_ALLOCA_H is defined.])
 ])
 
 # Prerequisites of lib/alloca.c.
--- a/modules/getdate
+++ b/modules/getdate
@@ -13,6 +13,7 @@
 stdbool
 gettime
 mktime
+alloca
 unlocked-io
 
 configure.ac:
--- a/modules/setenv
+++ b/modules/setenv
@@ -10,6 +10,7 @@
 
 Depends-on:
 allocsa
+alloca
 
 configure.ac:
 gt_FUNC_SETENV