yysyntax_error: avoid duplicate lookahead collection.

Except when memory reallocation is required, this change
eliminates the need to invoke yysyntax_error twice and thus to
repeat the collection of lookaheads.  It also prepares for
future extensions that will make those repetitions more
expensive and that will require additional memory management in
yysyntax_error.  Finally, it fixes an obscure bug already
exercised in the test suite.
* data/yacc.c (yysyntax_error): Add arguments for message
buffer variables stored in the parser.  Instead of size, return
status similar to yyparse status but indicating success of
message creation.  Other than the actual reallocation of the
message buffer, import and clean up memory management code
from...
(yyparse, yypush_parse): ... here.
* tests/regression.at (%error-verbose overflow): No longer an
expected failure.
(cherry picked from commit 45319f1365)

Conflicts:

	src/parse-gram.c
	src/parse-gram.h
This commit is contained in:
Joel E. Denny
2009-09-23 17:54:04 -04:00
parent d88cf11791
commit 69a2ab11cf
5 changed files with 295 additions and 271 deletions

View File

@@ -1358,16 +1358,13 @@ AT_CLEANUP
# Imagine the case where YYSTACK_ALLOC_MAXIMUM = YYSIZE_MAXIMUM and an
# invocation of yysyntax_error has caused yymsg_alloc to grow to exactly
# YYSTACK_ALLOC_MAXIMUM (perhaps because the normal doubling of size had
# to be clipped to YYSTACK_ALLOC_MAXIMUM). Now imagine a subsequent
# invocation of yysyntax_error that overflows during its size
# calculation and thus returns YYSIZE_MAXIMUM to yyparse. Then, yyparse
# will invoke yyerror using the old contents of yymsg. This bug needs
# to be fixed.
# to be clipped to YYSTACK_ALLOC_MAXIMUM). In an old version of yacc.c,
# a subsequent invocation of yysyntax_error that overflows during its
# size calculation would return YYSIZE_MAXIMUM to yyparse. Then,
# yyparse would invoke yyerror using the old contents of yymsg.
AT_SETUP([[%error-verbose overflow]])
AT_XFAIL_IF([[:]])
AT_DATA_GRAMMAR([input.y],
[[%code {
#include <stdio.h>