[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: yacc.c: Extracting yysyntax_error
From: |
Paul Eggert |
Subject: |
Re: yacc.c: Extracting yysyntax_error |
Date: |
Tue, 20 Sep 2005 16:13:24 -0700 |
User-agent: |
Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux) |
Akim Demaille <address@hidden> writes:
> So what is exactly the point of striving for alloca? alloca is a
> great tool to simplify the deallocation, but that's not our case.
I'm not sure, but I'd guess the original motivation was:
1. Performance: alloca is faster than malloc/free.
2. Avoid memory leaks when a C signal handler does a setjmp out of a
parser. Traditionally this has been useful for programs that
read and parse input interactively, and that trap signals and use
longjmp in signal handers.
3. Name space cleanness: If you assume GCC, you can get alloca
without reserving any user-visible symbols, thus allowing users
to use any names they like in their own code (e.g., "static int
free;").
I agree that (1) is not that important these days.
As for (2), how are C++ programs supposed to prevent memory leaks in
such situations? Does lalr1.cc handle this correctly? (glr.c
doesn't, not that I'm tempted to modify it to handle this....)
POSIX is fuzzy about whether (3) is required, which means it isn't
required (and therefore the POSIX yacc spec has a big hole).
Solaris 10 yacc isn't name-space clean: it generates a y.tab.c that
includes <stdlib.h>, <string.h>. On the other hand Solaris 10 yacc is
not a good model since it includes <values.h>, a nonstandard file.
Hence the output of Solaris 10 yacc won't compile on (say) OpenBSD.
Ouch! We don't want to head down that path, as many GNU source
distributions ship the output of Bison and are intended to be compiled
on many platforms.
At the very least I suppose (3) should be documented better in
bison.texinfo. Also, in reviewing gnulib <alloca_.h> I noticed that
there are some easy ports for Bison to other (non-GNU) compilers that
support alloca, and we might as well add them. So I installed the
following:
2005-09-20 Paul Eggert <address@hidden>
* data/yacc.c (YYSIZE_T): Reindent to make it clearer. This
doesn't affect behavior.
(YYSTACK_ALLOC) [YYSTACK_USE_ALLOCA]: Improve support for
Solaris, AIX, MSC.
(_STDLIB_H): Renamed from YYINCLUDED_STDLIB_H. All uses changed.
This works a bit better with glibc, if user code has already included
stdlib.h.
* doc/bison.texinfo (Bison Parser): Document that users can't
arbitrarily use malloc and free for other purposes. Document
that <alloca.h> and <malloc.h> might be included.
(Table of Symbols): Under YYSTACK_USE_ALLOCA, Don't claim that the
user must declare alloca.
--- data/yacc.c 20 Sep 2005 06:06:42 -0000 1.105
+++ data/yacc.c 20 Sep 2005 23:08:03 -0000 1.107
@@ -219,18 +219,17 @@ typedef struct YYLTYPE
/* Line __line__ of yacc.c. */
b4_syncline(address@hidden@], address@hidden@])[
-#if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__)
-# define YYSIZE_T __SIZE_TYPE__
-#endif
-#if ! defined (YYSIZE_T) && defined (size_t)
-# define YYSIZE_T size_t
-#endif
-#if ! defined (YYSIZE_T) && (defined (__STDC__) || defined (__cplusplus))
-# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
-# define YYSIZE_T size_t
-#endif
-#if ! defined (YYSIZE_T)
-# define YYSIZE_T unsigned int
+#ifndef YYSIZE_T
+# if defined (__SIZE_TYPE__)
+# define YYSIZE_T __SIZE_TYPE__
+# elif defined (size_t)
+# define YYSIZE_T size_t
+# elif ! defined (YYSIZE_T) && (defined (__STDC__) || defined (__cplusplus))
+# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
+# define YYSIZE_T size_t
+# else
+# define YYSIZE_T unsigned int
+# endif
#endif
#define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
@@ -255,11 +254,20 @@ b4_syncline(address@hidden@], address@hidden@])[
# if YYSTACK_USE_ALLOCA
# ifdef __GNUC__
# define YYSTACK_ALLOC __builtin_alloca
+# elif defined (__BUILTIN_VA_ARG_INCR)
+# include <alloca.h> /* INFRINGES ON USER NAME SPACE */
+# elif defined (_AIX)
+# define YYSTACK_ALLOC __alloca
+# elif defined (_MSC_VER)
+# include <malloc.h> /* INFRINGES ON USER NAME SPACE */
+# define alloca _alloca
# else
# define YYSTACK_ALLOC alloca
-# if defined (__STDC__) || defined (__cplusplus)
+# if ! defined (_STDLIB_H) && (defined (__STDC__) || defined (__cplusplus))
# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
-# define YYINCLUDED_STDLIB_H
+# ifndef _STDLIB_H
+# define _STDLIB_H 1
+# endif
# endif
# endif
# endif
@@ -286,14 +294,14 @@ extern "C" {
# endif
# ifndef YYMALLOC
# define YYMALLOC malloc
-# if (! defined (malloc) && ! defined (YYINCLUDED_STDLIB_H) \
+# if (! defined (malloc) && ! defined (_STDLIB_H) \
&& (defined (__STDC__) || defined (__cplusplus)))
void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
# endif
# endif
# ifndef YYFREE
# define YYFREE free
-# if (! defined (free) && ! defined (YYINCLUDED_STDLIB_H) \
+# if (! defined (free) && ! defined (_STDLIB_H) \
&& (defined (__STDC__) || defined (__cplusplus)))
void free (void *); /* INFRINGES ON USER NAME SPACE */
# endif
--- doc/bison.texinfo 20 Sep 2005 06:01:50 -0000 1.160
+++ doc/bison.texinfo 20 Sep 2005 23:06:10 -0000 1.161
@@ -1197,11 +1197,13 @@ function @code{yyerror} and the parser f
This also includes numerous identifiers used for internal purposes.
Therefore, you should avoid using C identifiers starting with @samp{yy}
or @samp{YY} in the Bison grammar file except for the ones defined in
-this manual.
+this manual. Also, you should avoid using the C identifiers
address@hidden and @samp{free} for anything other than their usual
+meanings.
In some cases the Bison parser file includes system headers, and in
those cases your code should respect the identifiers reserved by those
-headers. On some address@hidden hosts, @code{<alloca.h>},
+headers. On some address@hidden hosts, @code{<alloca.h>}, @code{<malloc.h>},
@code{<stddef.h>}, and @code{<stdlib.h>} are included as needed to
declare memory allocators and related types. @code{<libintl.h>} is
included if message translation is in use
@@ -8127,10 +8129,7 @@ the parser will use @code{malloc} to ext
reserved for future Bison extensions. If not defined,
@code{YYSTACK_USE_ALLOCA} defaults to 0.
-If you define @code{YYSTACK_USE_ALLOCA} to 1, it is your
-responsibility to make sure that @code{alloca} is visible, e.g., by
-using @acronym{GCC} or by including @code{<stdlib.h>}. Furthermore,
-in the all-too-common case where your code may run on a host with a
+In the all-too-common case where your code may run on a host with a
limited stack and with unreliable stack-overflow checking, you should
set @code{YYMAXDEPTH} to a value that cannot possibly result in
unchecked stack overflow on any of your target hosts when
- Re: yacc.c: Extracting yysyntax_error, Paul Eggert, 2005/09/20
- Re: yacc.c: Extracting yysyntax_error, Akim Demaille, 2005/09/20
- Re: yacc.c: Extracting yysyntax_error,
Paul Eggert <=
- Re: yacc.c: Extracting yysyntax_error, Hans Aberg, 2005/09/21
- Re: yacc.c: Extracting yysyntax_error, Akim Demaille, 2005/09/21
- Re: yacc.c: Extracting yysyntax_error, Hans Aberg, 2005/09/21
- Re: yacc.c: Extracting yysyntax_error, Paul Eggert, 2005/09/21
- Re: yacc.c: Extracting yysyntax_error, Hans Aberg, 2005/09/21
- Re: yacc.c: Extracting yysyntax_error, Hans Aberg, 2005/09/22
- Re: yacc.c: Extracting yysyntax_error, Paul Eggert, 2005/09/21