From 48dbf2c191cd60b64354849d8e0a8fe4a7d613f2 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Fri, 10 Jan 2003 21:06:49 +0000 Subject: [PATCH] Make it possibly to simply write: #include . --- ChangeLog | 5 +++++ lib/ChangeLog | 8 +++++++ lib/alloca_.h | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/getdate.y | 7 +++--- lib/makepath.c | 16 ++------------ lib/setenv.c | 33 ++--------------------------- lib/userspec.c | 16 ++------------ m4/ChangeLog | 4 ++++ m4/alloca.m4 | 15 +++++++++++-- modules/alloca | 41 ++++++++++------------------------- 10 files changed, 117 insertions(+), 95 deletions(-) create mode 100644 lib/alloca_.h diff --git a/ChangeLog b/ChangeLog index ecaf5ecd7..40a94a881 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2003-01-10 Bruno Haible + + * modules/alloca: Change Makefile.am requirements. Simplify Include + requirements. Add lib/alloca_.h to file list. + 2003-01-09 Bruno Haible * modules/stdbool: Change configure.ac, Makefile.am requirements. diff --git a/lib/ChangeLog b/lib/ChangeLog index 710cb16d0..91e10214d 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,11 @@ +2003-01-10 Bruno Haible + + * alloca_.h: New file. + * getdate.y: Unconditionally include alloca.h. + * makepath.c: Likewise. + * setenv.c: Likewise. + * userspec.c: Likewise. + 2003-01-09 Bruno Haible * stdbool.h.in: New file. diff --git a/lib/alloca_.h b/lib/alloca_.h new file mode 100644 index 000000000..c6e44d288 --- /dev/null +++ b/lib/alloca_.h @@ -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 +# define alloca _alloca +# else +# if HAVE_ALLOCA_H +# include +# 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 */ diff --git a/lib/getdate.y b/lib/getdate.y index 1b5148b41..3c4a04000 100644 --- a/lib/getdate.y +++ b/lib/getdate.y @@ -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 @@ -27,11 +27,10 @@ #ifdef HAVE_CONFIG_H # include -# ifdef HAVE_ALLOCA_H -# include -# endif #endif +#include + /* 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 diff --git a/lib/makepath.c b/lib/makepath.c index d4eaadeec..0d1a1ef26 100644 --- a/lib/makepath.c +++ b/lib/makepath.c @@ -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 @@ -21,19 +21,7 @@ # include #endif -#if __GNUC__ -# define alloca __builtin_alloca -#else -# if HAVE_ALLOCA_H -# include -# else -# ifdef _AIX - # pragma alloca -# else -char *alloca (); -# endif -# endif -#endif +#include #include #include diff --git a/lib/setenv.c b/lib/setenv.c index 57e6dd9e6..fdbf35434 100644 --- a/lib/setenv.c +++ b/lib/setenv.c @@ -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 @@ -20,36 +20,7 @@ # include #endif -#ifdef __GNUC__ -# ifndef alloca -# define alloca __builtin_alloca -# endif -#else -# ifdef _MSC_VER -# include -# define alloca _alloca -# else -# if HAVE_ALLOCA_H -# include -# 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 #include #if !_LIBC diff --git a/lib/userspec.c b/lib/userspec.c index 9def456ad..88b43a131 100644 --- a/lib/userspec.c +++ b/lib/userspec.c @@ -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 @@ -21,19 +21,7 @@ # include #endif -#ifdef __GNUC__ -# define alloca __builtin_alloca -#else -# if HAVE_ALLOCA_H -# include -# else -# ifdef _AIX - # pragma alloca -# else -char *alloca (); -# endif -# endif -#endif +#include #include #include diff --git a/m4/ChangeLog b/m4/ChangeLog index af00c93d8..168512b0a 100644 --- a/m4/ChangeLog +++ b/m4/ChangeLog @@ -1,3 +1,7 @@ +2003-01-10 Bruno Haible + + * alloca.m4 (gl_FUNC_ALLOCA): Also define ALLOCA_H. + 2003-01-09 Bruno Haible * stdbool.m4 (AM_STDBOOL_H): New macro. diff --git a/m4/alloca.m4 b/m4/alloca.m4 index fa026fc15..6dc0760fa 100644 --- a/m4/alloca.m4 +++ b/m4/alloca.m4 @@ -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. diff --git a/modules/alloca b/modules/alloca index 4d32288ce..42a0583fa 100644 --- a/modules/alloca +++ b/modules/alloca @@ -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 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 -# define alloca _alloca -# else -# if HAVE_ALLOCA_H -# include -# 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 -- 2.11.0