summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsodabrew <sodabrew>2007-05-31 06:21:57 +0000
committersodabrew <sodabrew>2007-05-31 06:21:57 +0000
commit462334f4fe2a71903e84dd85aefc9c717d219939 (patch)
treee193764bd785ca94a517fafd9d02b485c42eacc1
parentf47fa3dca272a3ddb6af146bdaa8ccc9c3efac28 (diff)
downloadflex-462334f4fe2a71903e84dd85aefc9c717d219939.tar.gz
Changes to resolve SF bugs 1568325 and 1563589.
-rw-r--r--configure.in1
-rw-r--r--flex.skl65
-rw-r--r--gen.c24
-rw-r--r--main.c1
4 files changed, 75 insertions, 16 deletions
diff --git a/configure.in b/configure.in
index 62ff25a..cfcaf74 100644
--- a/configure.in
+++ b/configure.in
@@ -144,6 +144,7 @@ tests/test-pthread/Makefile
tests/test-string-nr/Makefile
tests/test-string-r/Makefile
tests/test-yyextra/Makefile
+tests/test-alloc-extra/Makefile
tests/test-lineno-nr/Makefile
tests/test-lineno-r/Makefile
tests/test-linedir-r/Makefile
diff --git a/flex.skl b/flex.skl
index a6976c1..b7511c5 100644
--- a/flex.skl
+++ b/flex.skl
@@ -132,6 +132,7 @@ m4preproc_define(`M4_GEN_PREFIX',
M4_GEN_PREFIX(`lex')
M4_GEN_PREFIX(`restart')
M4_GEN_PREFIX(`lex_init')
+ M4_GEN_PREFIX(`lex_init_extra')
M4_GEN_PREFIX(`lex_destroy')
M4_GEN_PREFIX(`get_debug')
M4_GEN_PREFIX(`set_debug')
@@ -820,6 +821,12 @@ m4_ifdef( [[M4_YY_USES_REJECT]],
yy_state_type *yy_state_ptr;
char *yy_full_match;
int yy_lp;
+
+ /* These are only needed for trailing context rules,
+ * but there's no conditional variable for that yet. */
+ int yy_looking_for_trail_begin;
+ int yy_full_lp;
+ int *yy_full_state;
]])
m4_ifdef( [[M4_YY_TEXT_IS_ARRAY]],
@@ -1456,6 +1463,8 @@ do_action: /* This label is used only to access EOF actions. */
%if-c++-only
%not-for-header
+/* The contents of this function are C++ specific, so the YY_G macro is not used.
+ */
yyFlexLexer::yyFlexLexer( std::istream* arg_yyin, std::ostream* arg_yyout )
{
yyin = arg_yyin;
@@ -1476,9 +1485,9 @@ yyFlexLexer::yyFlexLexer( std::istream* arg_yyin, std::ostream* arg_yyout )
yy_start_stack_ptr = yy_start_stack_depth = 0;
yy_start_stack = NULL;
- YY_G(yy_buffer_stack) = 0;
- YY_G(yy_buffer_stack_top) = 0;
- YY_G(yy_buffer_stack_max) = 0;
+ yy_buffer_stack = 0;
+ yy_buffer_stack_top = 0;
+ yy_buffer_stack_max = 0;
m4_ifdef( [[M4_YY_USES_REJECT]],
@@ -1490,6 +1499,8 @@ m4_ifdef( [[M4_YY_USES_REJECT]],
]])
}
+/* The contents of this function are C++ specific, so the YY_G macro is not used.
+ */
yyFlexLexer::~yyFlexLexer()
{
delete [] yy_state_buf;
@@ -1498,6 +1509,8 @@ yyFlexLexer::~yyFlexLexer()
yyfree( yy_buffer_stack M4_YY_CALL_LAST_ARG );
}
+/* The contents of this function are C++ specific, so the YY_G macro is not used.
+ */
void yyFlexLexer::switch_streams( std::istream* new_in, std::ostream* new_out )
{
if ( new_in )
@@ -2759,7 +2772,51 @@ int yylex_init(yyscan_t* ptr_yy_globals)
return yy_init_globals ( *ptr_yy_globals );
}
-%endif
+
+/* yylex_init_extra has the same functionality as yylex_init, but follows the
+ * convention of taking the scanner as the last argument. Note however, that
+ * this is a *pointer* to a scanner, as it will be allocated by this call (and
+ * is the reason, too, why this function also must handle its own declaration).
+ * The user defined value in the first argument will be available to yyalloc in
+ * the yyextra field.
+ */
+m4_ifdef( [[M4_YY_NO_ANSI_FUNC_DEFS]],
+[[
+int yylex_init_extra( yy_user_defined, ptr_yy_globals )
+ YY_EXTRA_TYPE yy_user_defined;
+ yyscan_t* ptr_yy_globals;
+]],
+[[
+int yylex_init_extra( YY_EXTRA_TYPE yy_user_defined, yyscan_t* ptr_yy_globals )
+]])
+{
+ struct yyguts_t dummy_yyguts;
+
+ yyset_extra (yy_user_defined, &dummy_yyguts);
+
+ if (ptr_yy_globals == NULL){
+ errno = EINVAL;
+ return 1;
+ }
+
+ *ptr_yy_globals = (yyscan_t) yyalloc ( sizeof( struct yyguts_t ), &dummy_yyguts );
+
+ if (*ptr_yy_globals == NULL){
+ errno = ENOMEM;
+ return 1;
+ }
+
+ /* By setting to 0xAA, we expose bugs in
+ yy_init_globals. Leave at 0x00 for releases. */
+ memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t));
+
+ yyset_extra (yy_user_defined, *ptr_yy_globals);
+
+ return yy_init_globals ( *ptr_yy_globals );
+}
+
+%endif if-c-only
+
%if-c-only
static int yy_init_globals YYFARGS0(void)
diff --git a/gen.c b/gen.c
index aac39af..848e2c5 100644
--- a/gen.c
+++ b/gen.c
@@ -525,15 +525,15 @@ void gen_find_action ()
if (variable_trailing_context_rules) {
indent_puts
("if ( yy_act & YY_TRAILING_HEAD_MASK ||");
- indent_puts (" yy_looking_for_trail_begin )");
+ indent_puts (" YY_G(yy_looking_for_trail_begin) )");
indent_up ();
indent_puts ("{");
indent_puts
- ("if ( yy_act == yy_looking_for_trail_begin )");
+ ("if ( yy_act == YY_G(yy_looking_for_trail_begin) )");
indent_up ();
indent_puts ("{");
- indent_puts ("yy_looking_for_trail_begin = 0;");
+ indent_puts ("YY_G(yy_looking_for_trail_begin) = 0;");
indent_puts ("yy_act &= ~YY_TRAILING_HEAD_MASK;");
indent_puts ("break;");
indent_puts ("}");
@@ -547,9 +547,9 @@ void gen_find_action ()
indent_up ();
indent_puts ("{");
indent_puts
- ("yy_looking_for_trail_begin = yy_act & ~YY_TRAILING_MASK;");
+ ("YY_G(yy_looking_for_trail_begin) = yy_act & ~YY_TRAILING_MASK;");
indent_puts
- ("yy_looking_for_trail_begin |= YY_TRAILING_HEAD_MASK;");
+ ("YY_G(yy_looking_for_trail_begin) |= YY_TRAILING_HEAD_MASK;");
if (real_reject) {
/* Remember matched text in case we back up
@@ -558,8 +558,8 @@ void gen_find_action ()
indent_puts
("YY_G(yy_full_match) = yy_cp;");
indent_puts
- ("yy_full_state = YY_G(yy_state_ptr);");
- indent_puts ("yy_full_lp = YY_G(yy_lp);");
+ ("YY_G(yy_full_state) = YY_G(yy_state_ptr);");
+ indent_puts ("YY_G(yy_full_lp) = YY_G(yy_lp);");
}
indent_puts ("}");
@@ -570,8 +570,8 @@ void gen_find_action ()
indent_puts ("{");
indent_puts ("YY_G(yy_full_match) = yy_cp;");
indent_puts
- ("yy_full_state = YY_G(yy_state_ptr);");
- indent_puts ("yy_full_lp = YY_G(yy_lp);");
+ ("YY_G(yy_full_state) = YY_G(yy_state_ptr);");
+ indent_puts ("YY_G(yy_full_lp) = YY_G(yy_lp);");
indent_puts ("break;");
indent_puts ("}");
indent_down ();
@@ -1764,7 +1764,7 @@ void make_tables ()
}
if (variable_trailing_context_rules) {
- if (!C_plus_plus) {
+ if (!C_plus_plus && !reentrant) {
outn ("static int yy_looking_for_trail_begin = 0;");
outn ("static int yy_full_lp;");
outn ("static int *yy_full_state;");
@@ -1782,8 +1782,8 @@ void make_tables ()
outn ("yy_cp = YY_G(yy_full_match); /* restore poss. backed-over text */ \\");
if (variable_trailing_context_rules) {
- outn ("YY_G(yy_lp) = yy_full_lp; /* restore orig. accepting pos. */ \\");
- outn ("YY_G(yy_state_ptr) = yy_full_state; /* restore orig. state */ \\");
+ outn ("YY_G(yy_lp) = YY_G(yy_full_lp); /* restore orig. accepting pos. */ \\");
+ outn ("YY_G(yy_state_ptr) = YY_G(yy_full_state); /* restore orig. state */ \\");
outn ("yy_current_state = *YY_G(yy_state_ptr); /* restore curr. state */ \\");
}
diff --git a/main.c b/main.c
index 5fae7ab..90fcc02 100644
--- a/main.c
+++ b/main.c
@@ -641,6 +641,7 @@ void flexend (exit_status)
"yylex",
"yylex_destroy",
"yylex_init",
+ "yylex_init_extra",
"yylineno",
"yylloc",
"yylval",