mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-16 07:43:03 +00:00
(YYSTACK_REALLOC): Remove.
(YYSTACK_ALLOC): Resurrect this macro, with its old meaning. (YYSTACK_FREE, YYSTACK_GAP_MAX, YYSTACK_BYTES, YYSTACK_RELOCATE): New macros. (union yyalloc): New type. (__yy_memcpy): Last arg is size_t, not unsigned int, to remove an arbitrary restriction on hosts where size_t is wider than int. (yyparse): Don't dump core if alloca or malloc fails; instead, report a parser stack overflow. Allocate just one block of memory for all three stacks, instead of allocating three blocks; this typically is faster and reduces fragmentation. Do not limit the number of items in the stack to a value that fits in 'int', as this is an arbitrary limit on hosts with 64-bit size_t and 32-bit int.
This commit is contained in:
160
src/bison.simple
160
src/bison.simple
@@ -76,29 +76,56 @@
|
|||||||
# define YYSTACK_USE_ALLOCA 0
|
# define YYSTACK_USE_ALLOCA 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Realloc WHAT from SIZE to YYSTACKSIZE elements of TYPE.
|
|
||||||
If WHAT was malloc'ed (not the original automatic ARRAY), free it. */
|
|
||||||
#if YYSTACK_USE_ALLOCA
|
#if YYSTACK_USE_ALLOCA
|
||||||
# define YYSTACK_REALLOC(Type, What, Array) \
|
# define YYSTACK_ALLOC alloca
|
||||||
do { \
|
# define YYSTACK_FREE(Ptr) /* empty */
|
||||||
Type *old = What; \
|
|
||||||
What = (Type *) alloca (yystacksize * sizeof (Type)); \
|
|
||||||
__yy_memcpy ((char *) What, (char *) old, \
|
|
||||||
(size) * (unsigned int) sizeof (Type)); \
|
|
||||||
} while (0)
|
|
||||||
#else
|
#else
|
||||||
# define YYSTACK_REALLOC(Type, What, Array) \
|
# define YYSTACK_ALLOC malloc
|
||||||
do { \
|
# define YYSTACK_FREE(Ptr) free (Ptr)
|
||||||
Type *old = What; \
|
|
||||||
What = (Type *) malloc (yystacksize * sizeof (Type)); \
|
|
||||||
__yy_memcpy ((char *) What, (char *) old, \
|
|
||||||
(size) * (unsigned int) sizeof (Type)); \
|
|
||||||
yyfree_stacks = 1; \
|
|
||||||
if (old != Array) \
|
|
||||||
free (old); \
|
|
||||||
} while (0)
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* A type that is properly aligned for any stack member. */
|
||||||
|
union yyalloc
|
||||||
|
{
|
||||||
|
short yys;
|
||||||
|
YYSTYPE yyv;
|
||||||
|
#if YYLSP_NEEDED
|
||||||
|
YYLTYPE yyl;
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
/* The size of the maximum gap between one aligned stack and the next. */
|
||||||
|
#define YYSTACK_GAP_MAX (sizeof (union yyalloc) - 1)
|
||||||
|
|
||||||
|
/* The size of an array large to enough to hold all stacks, each with
|
||||||
|
N elements. */
|
||||||
|
#if YYLSP_NEEDED
|
||||||
|
# define YYSTACK_BYTES(N) \
|
||||||
|
((N) * (sizeof (short) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \
|
||||||
|
+ 2 * YYSTACK_GAP_MAX)
|
||||||
|
#else
|
||||||
|
# define YYSTACK_BYTES(N) \
|
||||||
|
((N) * (sizeof (short) + sizeof (YYSTYPE)) \
|
||||||
|
+ YYSTACK_GAP_MAX)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Relocate the TYPE STACK from its old location to the new one. The
|
||||||
|
local variables SIZE and YYSTACKSIZE give the old and new number of
|
||||||
|
elements in the stack, and YYPTR gives the new location of the
|
||||||
|
stack. Advance YYPTR to a properly aligned location for the next
|
||||||
|
stack. */
|
||||||
|
#define YYSTACK_RELOCATE(Type, Stack) \
|
||||||
|
do \
|
||||||
|
{ \
|
||||||
|
size_t yynewbytes; \
|
||||||
|
__yy_memcpy (yyptr, (char *) (Stack), size * sizeof (Type)); \
|
||||||
|
(Stack) = (Type *) yyptr; \
|
||||||
|
yynewbytes = yystacksize * sizeof (Type) + YYSTACK_GAP_MAX; \
|
||||||
|
yynewbytes -= yynewbytes % sizeof (union yyalloc); \
|
||||||
|
yyptr += yynewbytes; \
|
||||||
|
} \
|
||||||
|
while (0)
|
||||||
|
|
||||||
#define yyerrok (yyerrstatus = 0)
|
#define yyerrok (yyerrstatus = 0)
|
||||||
#define yyclearin (yychar = YYEMPTY)
|
#define yyclearin (yychar = YYEMPTY)
|
||||||
#define YYEMPTY -2
|
#define YYEMPTY -2
|
||||||
@@ -189,7 +216,12 @@ int yydebug;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
|
/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
|
||||||
if the built-in stack extension method is used). */
|
if the built-in stack extension method is used).
|
||||||
|
|
||||||
|
Do not make this value too large; the results are undefined if
|
||||||
|
SIZE_MAX < YYSTACK_BYTES (YYMAXDEPTH)
|
||||||
|
evaluated with infinite-precision integer arithmetic. */
|
||||||
|
|
||||||
#if YYMAXDEPTH == 0
|
#if YYMAXDEPTH == 0
|
||||||
# undef YYMAXDEPTH
|
# undef YYMAXDEPTH
|
||||||
#endif
|
#endif
|
||||||
@@ -198,11 +230,6 @@ int yydebug;
|
|||||||
# define YYMAXDEPTH 10000
|
# define YYMAXDEPTH 10000
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Define __yy_memcpy. Note that the size argument
|
|
||||||
should be passed with type unsigned int, because that is what the non-GCC
|
|
||||||
definitions require. With GCC, __builtin_memcpy takes an arg
|
|
||||||
of type size_t, but it can handle unsigned int. */
|
|
||||||
|
|
||||||
#if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
|
#if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
|
||||||
# define __yy_memcpy(To, From, Count) __builtin_memcpy (To, From, Count)
|
# define __yy_memcpy(To, From, Count) __builtin_memcpy (To, From, Count)
|
||||||
#else /* not GNU C or C++ */
|
#else /* not GNU C or C++ */
|
||||||
@@ -214,16 +241,16 @@ static void
|
|||||||
__yy_memcpy (to, from, count)
|
__yy_memcpy (to, from, count)
|
||||||
char *to;
|
char *to;
|
||||||
const char *from;
|
const char *from;
|
||||||
unsigned int count;
|
size_t count;
|
||||||
# else /* __cplusplus */
|
# else /* __cplusplus */
|
||||||
__yy_memcpy (char *to, const char *from, unsigned int count)
|
__yy_memcpy (char *to, const char *from, size_t count)
|
||||||
# endif
|
# endif
|
||||||
{
|
{
|
||||||
register const char *f = from;
|
register const char *f = from;
|
||||||
register char *t = to;
|
register char *t = to;
|
||||||
register int i = count;
|
register size_t i = count;
|
||||||
|
|
||||||
while (i-- > 0)
|
while (i-- != 0)
|
||||||
*t++ = *f++;
|
*t++ = *f++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -301,6 +328,7 @@ yyparse (YYPARSE_PARAM_ARG)
|
|||||||
|
|
||||||
register int yystate;
|
register int yystate;
|
||||||
register int yyn;
|
register int yyn;
|
||||||
|
int yyresult;
|
||||||
/* Number of tokens to shift before error messages enabled. */
|
/* Number of tokens to shift before error messages enabled. */
|
||||||
int yyerrstatus;
|
int yyerrstatus;
|
||||||
/* Lookahead token as an internal (translated) token number. */
|
/* Lookahead token as an internal (translated) token number. */
|
||||||
@@ -337,8 +365,7 @@ yyparse (YYPARSE_PARAM_ARG)
|
|||||||
# define YYPOPSTACK (yyvsp--, yyssp--)
|
# define YYPOPSTACK (yyvsp--, yyssp--)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int yystacksize = YYINITDEPTH;
|
size_t yystacksize = YYINITDEPTH;
|
||||||
int yyfree_stacks = 0;
|
|
||||||
|
|
||||||
|
|
||||||
/* The variables used to return semantic value and location from the
|
/* The variables used to return semantic value and location from the
|
||||||
@@ -386,7 +413,7 @@ yyparse (YYPARSE_PARAM_ARG)
|
|||||||
if (yyssp >= yyss + yystacksize - 1)
|
if (yyssp >= yyss + yystacksize - 1)
|
||||||
{
|
{
|
||||||
/* Get the current used size of the three stacks, in elements. */
|
/* Get the current used size of the three stacks, in elements. */
|
||||||
int size = yyssp - yyss + 1;
|
size_t size = yyssp - yyss + 1;
|
||||||
|
|
||||||
#ifdef yyoverflow
|
#ifdef yyoverflow
|
||||||
{
|
{
|
||||||
@@ -420,27 +447,25 @@ yyparse (YYPARSE_PARAM_ARG)
|
|||||||
#else /* no yyoverflow */
|
#else /* no yyoverflow */
|
||||||
/* Extend the stack our own way. */
|
/* Extend the stack our own way. */
|
||||||
if (yystacksize >= YYMAXDEPTH)
|
if (yystacksize >= YYMAXDEPTH)
|
||||||
{
|
goto yyoverflowlab;
|
||||||
yyerror ("parser stack overflow");
|
|
||||||
if (yyfree_stacks)
|
|
||||||
{
|
|
||||||
free (yyss);
|
|
||||||
free (yyvs);
|
|
||||||
# if YYLSP_NEEDED
|
|
||||||
free (yyls);
|
|
||||||
# endif
|
|
||||||
}
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
yystacksize *= 2;
|
yystacksize *= 2;
|
||||||
if (yystacksize > YYMAXDEPTH)
|
if (yystacksize > YYMAXDEPTH)
|
||||||
yystacksize = YYMAXDEPTH;
|
yystacksize = YYMAXDEPTH;
|
||||||
|
|
||||||
YYSTACK_REALLOC (short, yyss, yyssa);
|
{
|
||||||
YYSTACK_REALLOC (YYSTYPE, yyvs, yyvsa);
|
short *yyss1 = yyss;
|
||||||
|
char *yyptr = (char *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
|
||||||
|
if (! yyptr)
|
||||||
|
goto yyoverflowlab;
|
||||||
|
YYSTACK_RELOCATE (short, yyss);
|
||||||
|
YYSTACK_RELOCATE (YYSTYPE, yyvs);
|
||||||
# if YYLSP_NEEDED
|
# if YYLSP_NEEDED
|
||||||
YYSTACK_REALLOC (YYLTYPE, yyls, yylsa);
|
YYSTACK_RELOCATE (YYLTYPE, yyls);
|
||||||
# endif
|
# endif
|
||||||
|
# undef YYSTACK_RELOCATE
|
||||||
|
if (yyss1 != yyssa)
|
||||||
|
YYSTACK_FREE (yyss1);
|
||||||
|
}
|
||||||
#endif /* no yyoverflow */
|
#endif /* no yyoverflow */
|
||||||
|
|
||||||
yyssp = yyss + size - 1;
|
yyssp = yyss + size - 1;
|
||||||
@@ -449,7 +474,8 @@ yyparse (YYPARSE_PARAM_ARG)
|
|||||||
yylsp = yyls + size - 1;
|
yylsp = yyls + size - 1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
YYDPRINTF ((stderr, "Stack size increased to %d\n", yystacksize));
|
YYDPRINTF ((stderr, "Stack size increased to %lu\n",
|
||||||
|
(unsigned long int) yystacksize));
|
||||||
|
|
||||||
if (yyssp >= yyss + yystacksize - 1)
|
if (yyssp >= yyss + yystacksize - 1)
|
||||||
YYABORT;
|
YYABORT;
|
||||||
@@ -666,7 +692,7 @@ yyerrlab:
|
|||||||
|
|
||||||
if (yyn > YYFLAG && yyn < YYLAST)
|
if (yyn > YYFLAG && yyn < YYLAST)
|
||||||
{
|
{
|
||||||
int size = 0;
|
size_t size = 0;
|
||||||
char *msg;
|
char *msg;
|
||||||
int x, count;
|
int x, count;
|
||||||
|
|
||||||
@@ -816,28 +842,28 @@ yyerrhandle:
|
|||||||
| yyacceptlab -- YYACCEPT comes here. |
|
| yyacceptlab -- YYACCEPT comes here. |
|
||||||
`-------------------------------------*/
|
`-------------------------------------*/
|
||||||
yyacceptlab:
|
yyacceptlab:
|
||||||
if (yyfree_stacks)
|
yyresult = 0;
|
||||||
{
|
goto yyreturn;
|
||||||
free (yyss);
|
|
||||||
free (yyvs);
|
|
||||||
#if YYLSP_NEEDED
|
|
||||||
free (yyls);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
|
|
||||||
/*-----------------------------------.
|
/*-----------------------------------.
|
||||||
| yyabortlab -- YYABORT comes here. |
|
| yyabortlab -- YYABORT comes here. |
|
||||||
`-----------------------------------*/
|
`-----------------------------------*/
|
||||||
yyabortlab:
|
yyabortlab:
|
||||||
if (yyfree_stacks)
|
yyresult = 1;
|
||||||
{
|
goto yyreturn;
|
||||||
free (yyss);
|
|
||||||
free (yyvs);
|
/*---------------------------------------------.
|
||||||
#if YYLSP_NEEDED
|
| yyoverflowab -- parser overflow comes here. |
|
||||||
free (yyls);
|
`---------------------------------------------*/
|
||||||
|
yyoverflowlab:
|
||||||
|
yyerror ("parser stack overflow");
|
||||||
|
yyresult = 2;
|
||||||
|
/* Fall through. */
|
||||||
|
|
||||||
|
yyreturn:
|
||||||
|
#ifndef yyoverflow
|
||||||
|
if (yyss != yyssa)
|
||||||
|
YYSTACK_FREE (yyss);
|
||||||
#endif
|
#endif
|
||||||
}
|
return yyresult;
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user