From 8e17ac67aacb7302d46627960b9aa41de3a5ef5e Mon Sep 17 00:00:00 2001 From: John Millaway Date: Mon, 12 Aug 2002 19:36:58 +0000 Subject: [PATCH] Fixed type mismatch in printf. yylex_init now reports errors. --- flex.skl | 17 +++++++++++++++-- flex.texi | 13 ++++++++++++- gen.c | 4 ++-- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/flex.skl b/flex.skl index b34572f..668aec3 100644 --- a/flex.skl +++ b/flex.skl @@ -1903,6 +1903,10 @@ static int yy_init_globals YYFARGS0(void) yyin = (FILE *) 0; yyout = (FILE *) 0; #endif + + /* For future reference: Set errno on error, since we are called by + * yylex_init() + */ return 0; } @@ -1919,9 +1923,18 @@ int yylex_init( ptr_yy_globals ) yyscan_t* ptr_yy_globals; #endif { + if (ptr_yy_globals == NULL){ + errno = EINVAL; + return 1; + } + *ptr_yy_globals = (yyscan_t) yyalloc ( sizeof( struct yyguts_t ), NULL ); - yy_init_globals ( *ptr_yy_globals ); - return 0; + if (*ptr_yy_globals == NULL){ + errno = ENOMEM; + return 1; + } + + return yy_init_globals ( *ptr_yy_globals ); } #endif /* End YY_REENTRANT */ diff --git a/flex.texi b/flex.texi index 798f859..8559355 100644 --- a/flex.texi +++ b/flex.texi @@ -3754,6 +3754,17 @@ takes one argument, which is the value returned (via an argument) by @code{yylex_init}. Otherwise, it behaves the same as the non-reentrant version of @code{yylex}. +@code{yylex_init} returns 0 (zero) on success, or non-zero on failure, +in which case, errno is set to one of the following values: + +@itemize +@item ENOMEM +Memory allocation error. @xref{memory-management}. +@item EINVAL +Invalid argument. +@end itemize + + The function @code{yylex_destroy} should be called to free resources used by the scanner. After @code{yylex_destroy} is called, the contents of @code{yyscanner} should not be used. Of @@ -4340,7 +4351,7 @@ in braces are simply terminated at the end of the line. @chapter Memory Management @cindex memory management - +@anchor{memory-management} This chapter describes how flex handles dynamic memory, and how you can override the default behavior. diff --git a/gen.c b/gen.c index 31fa50e..ef03f99 100644 --- a/gen.c +++ b/gen.c @@ -1516,10 +1516,10 @@ void make_tables() else { indent_puts( - "fprintf( stderr, \"--accepting rule at line %d (\\\"%s\\\")\\n\"," ); + "fprintf( stderr, \"--accepting rule at line %ld (\\\"%s\\\")\\n\"," ); indent_puts( - " yy_rule_linenum[yy_act], yytext );" ); + " (long)yy_rule_linenum[yy_act], yytext );" ); } indent_down(); -- 2.40.0