Make it possibly to simply write: #include <alloca.h>.
authorBruno Haible <bruno@clisp.org>
Fri, 10 Jan 2003 21:06:49 +0000 (21:06 +0000)
committerBruno Haible <bruno@clisp.org>
Fri, 10 Jan 2003 21:06:49 +0000 (21:06 +0000)
ChangeLog
lib/ChangeLog
lib/alloca_.h [new file with mode: 0644]
lib/getdate.y
lib/makepath.c
lib/setenv.c
lib/userspec.c
m4/ChangeLog
m4/alloca.m4
modules/alloca

index ecaf5ec..40a94a8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2003-01-10  Bruno Haible  <bruno@clisp.org>
+
+       * modules/alloca: Change Makefile.am requirements. Simplify Include
+       requirements. Add lib/alloca_.h to file list.
+
 2003-01-09  Bruno Haible  <bruno@clisp.org>
 
        * modules/stdbool: Change configure.ac, Makefile.am requirements.
index 710cb16..91e1021 100644 (file)
@@ -1,3 +1,11 @@
+2003-01-10  Bruno Haible  <bruno@clisp.org>
+
+       * alloca_.h: New file.
+       * getdate.y: Unconditionally include alloca.h.
+       * makepath.c: Likewise.
+       * setenv.c: Likewise.
+       * userspec.c: Likewise.
+
 2003-01-09  Bruno Haible  <bruno@clisp.org>
 
        * stdbool.h.in: New file.
diff --git a/lib/alloca_.h b/lib/alloca_.h
new file mode 100644 (file)
index 0000000..c6e44d2
--- /dev/null
@@ -0,0 +1,67 @@
+/* Memory allocation on the stack.
+   Copyright (C) 1995, 1999, 2001-2003 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 2, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+
+/* When this file is included, it may be preceded only by preprocessor
+   declarations.  Thanks to AIX 3.  Therefore we include it right after
+   "config.h", not later.  */
+
+#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.
+   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.
+ */
+
+#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
+#endif
+
+#endif /* _ALLOCA_H */
index 1b5148b..3c4a040 100644 (file)
@@ -1,6 +1,6 @@
 %{
 /* Parse a string into an internal time stamp.
-   Copyright (C) 1999, 2000, 2002 Free Software Foundation, Inc.
+   Copyright (C) 1999, 2000, 2002, 2003 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
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
-# ifdef HAVE_ALLOCA_H
-#  include <alloca.h>
-# endif
 #endif
 
+#include <alloca.h>
+
 /* Since the code of getdate.y is not included in the Emacs executable
    itself, there is no need to #define static in this file.  Even if
    the code were included in the Emacs executable, it probably
index d4eaade..0d1a1ef 100644 (file)
@@ -1,5 +1,5 @@
 /* makepath.c -- Ensure that a directory path exists.
-   Copyright (C) 1990, 1997, 1998, 1999, 2000, 2002 Free Software Foundation, Inc.
+   Copyright (C) 1990, 1997-1999, 2000, 2002-2003 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
 # include <config.h>
 #endif
 
-#if __GNUC__
-# define alloca __builtin_alloca
-#else
-# if HAVE_ALLOCA_H
-#  include <alloca.h>
-# else
-#  ifdef _AIX
- #  pragma alloca
-#  else
-char *alloca ();
-#  endif
-# endif
-#endif
+#include <alloca.h>
 
 #include <stdio.h>
 #include <sys/types.h>
index 57e6dd9..fdbf354 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1992,1995-1999,2000-2002 Free Software Foundation, Inc.
+/* Copyright (C) 1992,1995-1999,2000-2003 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
 # include <config.h>
 #endif
 
-#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 */
-void *alloca ();
-#     endif /* not __cplusplus */
-#    else /* not __hpux */
-#     ifndef alloca
-char *alloca ();
-#     endif
-#    endif /* __hpux */
-#   endif
-#  endif
-# endif
-#endif
+#include <alloca.h>
 
 #include <errno.h>
 #if !_LIBC
index 9def456..88b43a1 100644 (file)
@@ -1,5 +1,5 @@
 /* userspec.c -- Parse a user and group string.
-   Copyright (C) 1989-1992, 1997, 1998, 2000, 2002 Free Software Foundation, Inc.
+   Copyright (C) 1989-1992, 1997-1998, 2000, 2002-2003 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
 # include <config.h>
 #endif
 
-#ifdef __GNUC__
-# define alloca __builtin_alloca
-#else
-# if HAVE_ALLOCA_H
-#  include <alloca.h>
-# else
-#  ifdef _AIX
- #  pragma alloca
-#  else
-char *alloca ();
-#  endif
-# endif
-#endif
+#include <alloca.h>
 
 #include <stdio.h>
 #include <sys/types.h>
index af00c93..168512b 100644 (file)
@@ -1,3 +1,7 @@
+2003-01-10  Bruno Haible  <bruno@clisp.org>
+
+       * alloca.m4 (gl_FUNC_ALLOCA): Also define ALLOCA_H.
+
 2003-01-09  Bruno Haible  <bruno@clisp.org>
 
        * stdbool.m4 (AM_STDBOOL_H): New macro.
index fa026fc..6dc0760 100644 (file)
@@ -1,5 +1,5 @@
-# alloca.m4 serial 1
-dnl Copyright (C) 2002 Free Software Foundation, Inc.
+# alloca.m4 serial 2
+dnl Copyright (C) 2002-2003 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
@@ -12,6 +12,17 @@ AC_DEFUN([gl_FUNC_ALLOCA],
   if test $ac_cv_func_alloca_works = no; then
     gl_PREREQ_ALLOCA
   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
+#endif
+    ],
+    ALLOCA_H=alloca.h,
+    ALLOCA_H=)
+  AC_SUBST([ALLOCA_H])
 ])
 
 # Prerequisites of lib/alloca.c.
index 4d32288..42a0583 100644 (file)
@@ -1,6 +1,8 @@
 Description:
+Memory allocation on the stack.
 
 Files:
+lib/alloca_.h
 lib/alloca.c
 m4/alloca.m4
 
@@ -11,36 +13,15 @@ configure.ac:
 gl_FUNC_ALLOCA
 
 Makefile.am:
+EXTRA_DIST += alloca_.h
+
+# The following is needed in order to create an <alloca.h> when the system
+# doesn't have one that works with the given compiler.
+all-local: @ALLOCA_H@
+alloca.h: alloca_.h
+       cp $(srcdir)/alloca_.h alloca.h
+MOSTLYCLEANFILES += alloca.h
 
 Include:
-#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 */
-void *alloca ();
-#     endif /* not __cplusplus */
-#    else /* not __hpux */
-#     ifndef alloca
-char *alloca ();
-#     endif
-#    endif /* __hpux */
-#   endif
-#  endif
-# endif
-#endif
+#include <alloca.h>