From eab63f4d16533532355729b34762daa28a69fce1 Mon Sep 17 00:00:00 2001 From: John Millaway Date: Wed, 10 Jul 2002 00:04:36 +0000 Subject: [PATCH] Fixed prefix issue with get/set debug functions. Fixed prefix issues with memory functions. --- flex.skl | 52 ++++++++++++++++++------------------- flex.texi | 14 ++++++---- main.c | 11 ++++++++ scan.l | 6 ++--- tests/test-mem-nr/scanner.l | 8 +++--- tests/test-mem-r/scanner.l | 8 +++--- 6 files changed, 57 insertions(+), 42 deletions(-) diff --git a/flex.skl b/flex.skl index 68dae7d..4b0bdf9 100644 --- a/flex.skl +++ b/flex.skl @@ -339,9 +339,9 @@ YY_BUFFER_STATE yy_scan_bytes YY_PROTO(( yyconst char *bytes, int len YY_LAST_AR %* %c -void *yy_flex_alloc YY_PROTO(( yy_size_t YY_LAST_ARG )); -void *yy_flex_realloc YY_PROTO(( void *, yy_size_t YY_LAST_ARG )); -void yy_flex_free YY_PROTO(( void * YY_LAST_ARG )); +void *yyalloc YY_PROTO(( yy_size_t YY_LAST_ARG )); +void *yyrealloc YY_PROTO(( void *, yy_size_t YY_LAST_ARG )); +void yyfree YY_PROTO(( void * YY_LAST_ARG )); %e #define yy_new_buffer yy_create_buffer @@ -953,7 +953,7 @@ yyFlexLexer::yyFlexLexer( FLEX_STD istream* arg_yyin, FLEX_STD ostream* arg_yyou yyFlexLexer::~yyFlexLexer() { delete [] yy_state_buf; - yy_flex_free( yy_start_stack YY_CALL_LAST_ARG ); + yyfree( yy_start_stack YY_CALL_LAST_ARG ); yy_delete_buffer( yy_current_buffer YY_CALL_LAST_ARG); } @@ -1097,7 +1097,7 @@ int yyFlexLexer::yy_get_next_buffer() b->yy_ch_buf = (char *) /* Include room in for 2 EOB chars. */ - yy_flex_realloc( (void *) b->yy_ch_buf, + yyrealloc( (void *) b->yy_ch_buf, b->yy_buf_size + 2 YY_CALL_LAST_ARG ); } else @@ -1435,7 +1435,7 @@ YY_BUFFER_STATE yyFlexLexer::yy_create_buffer( FLEX_STD istream* file, int size { YY_BUFFER_STATE b; - b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) YY_CALL_LAST_ARG ); + b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) YY_CALL_LAST_ARG ); if ( ! b ) YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); @@ -1444,7 +1444,7 @@ YY_BUFFER_STATE yyFlexLexer::yy_create_buffer( FLEX_STD istream* file, int size /* yy_ch_buf has to be 2 characters longer than the size given because * we need to put in 2 end-of-buffer characters. */ - b->yy_ch_buf = (char *) yy_flex_alloc( b->yy_buf_size + 2 YY_CALL_LAST_ARG ); + b->yy_ch_buf = (char *) yyalloc( b->yy_buf_size + 2 YY_CALL_LAST_ARG ); if ( ! b->yy_ch_buf ) YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); @@ -1475,9 +1475,9 @@ void yyFlexLexer::yy_delete_buffer( YY_BUFFER_STATE b ) YY_G(yy_current_buffer) = (YY_BUFFER_STATE) 0; if ( b->yy_is_our_buffer ) - yy_flex_free( (void *) b->yy_ch_buf YY_CALL_LAST_ARG ); + yyfree( (void *) b->yy_ch_buf YY_CALL_LAST_ARG ); - yy_flex_free( (void *) b YY_CALL_LAST_ARG ); + yyfree( (void *) b YY_CALL_LAST_ARG ); } @@ -1588,7 +1588,7 @@ YY_DECL_LAST_ARG /* They forgot to leave room for the EOB's. */ return 0; - b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) YY_CALL_LAST_ARG ); + b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) YY_CALL_LAST_ARG ); if ( ! b ) YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); @@ -1648,7 +1648,7 @@ int len; /* Get memory for full buffer, including space for trailing EOB's. */ n = len + 2; - buf = (char *) yy_flex_alloc( n YY_CALL_LAST_ARG ); + buf = (char *) yyalloc( n YY_CALL_LAST_ARG ); if ( ! buf ) YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); @@ -1693,10 +1693,10 @@ void yyFlexLexer::yy_push_state( int new_state ) new_size = YY_G(yy_start_stack_depth) * sizeof( int ); if ( ! YY_G(yy_start_stack) ) - YY_G(yy_start_stack) = (int *) yy_flex_alloc( new_size YY_CALL_LAST_ARG ); + YY_G(yy_start_stack) = (int *) yyalloc( new_size YY_CALL_LAST_ARG ); else - YY_G(yy_start_stack) = (int *) yy_flex_realloc( + YY_G(yy_start_stack) = (int *) yyrealloc( (void *) YY_G(yy_start_stack), new_size YY_CALL_LAST_ARG ); if ( ! YY_G(yy_start_stack) ) @@ -2040,7 +2040,7 @@ int yylex_init( ptr_yy_globals ) yyscan_t* ptr_yy_globals; #endif { - *ptr_yy_globals = (yyscan_t) yy_flex_alloc ( sizeof( struct yy_globals_t ), NULL ); + *ptr_yy_globals = (yyscan_t) yyalloc ( sizeof( struct yy_globals_t ), NULL ); yy_init_globals ( *ptr_yy_globals ); return 0; } @@ -2063,14 +2063,14 @@ int yylex_destroy( YY_ONLY_ARG ) #if defined(YY_STACK_USED) || defined(YY_REENTRANT) /* Destroy the start condition stack. */ if (YY_G(yy_start_stack) ){ - yy_flex_free( YY_G(yy_start_stack) YY_CALL_LAST_ARG ); + yyfree( YY_G(yy_start_stack) YY_CALL_LAST_ARG ); YY_G(yy_start_stack) = NULL; } #endif #ifdef YY_REENTRANT /* Destroy the main struct (reentrant only). */ - yy_flex_free ( yy_globals YY_CALL_LAST_ARG ); + yyfree ( yy_globals YY_CALL_LAST_ARG ); #endif return 0; } @@ -2112,13 +2112,13 @@ YY_DECL_LAST_ARG } #endif -/* You may override yy_flex_alloc by defining YY_NO_FLEX_ALLOC and linking to +/* You may override yyalloc by defining YY_NO_FLEX_ALLOC and linking to * your own version */ #ifndef YY_NO_FLEX_ALLOC #ifdef YY_USE_PROTOS -void *yy_flex_alloc( yy_size_t size YY_LAST_ARG ) +void *yyalloc( yy_size_t size YY_LAST_ARG ) #else -void *yy_flex_alloc( size YY_LAST_ARG ) +void *yyalloc( size YY_LAST_ARG ) yy_size_t size; YY_DECL_LAST_ARG #endif @@ -2127,13 +2127,13 @@ YY_DECL_LAST_ARG } #endif -/* You may override yy_flex_realloc by defining YY_NO_FLEX_REALLOC and linking +/* You may override yyrealloc by defining YY_NO_FLEX_REALLOC and linking * to your own version. */ #ifndef YY_NO_FLEX_REALLOC #ifdef YY_USE_PROTOS -void *yy_flex_realloc( void *ptr, yy_size_t size YY_LAST_ARG ) +void *yyrealloc( void *ptr, yy_size_t size YY_LAST_ARG ) #else -void *yy_flex_realloc( ptr, size YY_LAST_ARG ) +void *yyrealloc( ptr, size YY_LAST_ARG ) void *ptr; yy_size_t size; YY_DECL_LAST_ARG @@ -2150,18 +2150,18 @@ YY_DECL_LAST_ARG } #endif -/* You may override yy_flex_free by defining YY_NO_FLEX_FREE and linking to +/* You may override yyfree by defining YY_NO_FLEX_FREE and linking to * your own version.*/ #ifndef YY_NO_FLEX_FREE #ifdef YY_USE_PROTOS -void yy_flex_free( void *ptr YY_LAST_ARG ) +void yyfree( void *ptr YY_LAST_ARG ) #else -void yy_flex_free( ptr YY_LAST_ARG ) +void yyfree( ptr YY_LAST_ARG ) void *ptr; YY_DECL_LAST_ARG #endif { - free( (char *) ptr ); /* see yy_flex_realloc() for (char *) cast */ + free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ } #endif diff --git a/flex.texi b/flex.texi index 915ff26..9bb5528 100644 --- a/flex.texi +++ b/flex.texi @@ -2564,6 +2564,9 @@ the names affected: yyrestart yytext yywrap + yyalloc + yyrealloc + yyfree @end verbatim @end example @@ -3856,6 +3859,8 @@ The following Functions are available in a reentrant scanner: @findex yyset_lineno @findex yyget_debug @findex yyset_debug +@findex yyget_extra +@findex yyset_extra @example @verbatim @@ -4159,10 +4164,9 @@ in braces are simply terminated at the end of the line. @chapter Memory Management @cindex memory management -@cindex alloc, overriding -@cindex malloc, overriding -@cindex realloc, overriding -@cindex free, overriding +@cindex yyalloc, overriding +@cindex yyrealloc, overriding +@cindex yyfree, overriding @cindex yytext, memory for This chapter describes how flex handles dynamic memory, and how you can @@ -4227,7 +4231,7 @@ yylex_destroy(). @node Overriding The Default Memory Management @section Overriding The Default Memory Management -TODO -- Describe how to override yy_flex_(alloc,free,realloc), +TODO -- Describe how to override yy(alloc,free,realloc), YY_READ_BUF_SIZE, YY_BUF_SIZE, YY_START_STACK_INCR, and anything else that crops up. diff --git a/main.c b/main.c index 834378a..9e99844 100644 --- a/main.c +++ b/main.c @@ -382,6 +382,9 @@ void check_options() GEN_PREFIX( "get_text" ); GEN_PREFIX( "get_lineno" ); GEN_PREFIX( "set_lineno" ); + GEN_PREFIX( "alloc" ); + GEN_PREFIX( "realloc" ); + GEN_PREFIX( "free" ); outn( "#ifdef YY_REENTRANT_BISON_PURE" ); GEN_PREFIX( "get_lval" ); @@ -582,6 +585,9 @@ int exit_status; fprintf(header_out,"#undef YY_MORE_ADJ\n"); fprintf(header_out,"#undef YY_NEED_STRLEN\n"); fprintf(header_out,"#undef YY_NEW_FILE\n"); + fprintf(header_out,"#undef YY_NO_FLEX_ALLOC\n"); + fprintf(header_out,"#undef YY_NO_FLEX_REALLOC\n"); + fprintf(header_out,"#undef YY_NO_FLEX_FREE\n"); fprintf(header_out,"#undef YY_NO_GET_DEBUG\n"); fprintf(header_out,"#undef YY_NO_GET_EXTRA\n"); fprintf(header_out,"#undef YY_NO_GET_IN\n"); @@ -647,6 +653,8 @@ int exit_status; fprintf(header_out,"#undef yy_switch_to_buffer\n"); fprintf(header_out,"#undef yyconst\n"); fprintf(header_out,"#undef yyextra\n"); + fprintf(header_out,"#undef yyget_debug\n"); + fprintf(header_out,"#undef yyset_debug\n"); fprintf(header_out,"#undef yyget_extra\n"); fprintf(header_out,"#undef yyget_in\n"); fprintf(header_out,"#undef yyget_leng\n"); @@ -677,6 +685,9 @@ int exit_status; fprintf(header_out,"#undef yytext\n"); fprintf(header_out,"#undef yytext_ptr\n"); fprintf(header_out,"#undef yywrap\n"); + fprintf(header_out,"#undef yyalloc\n"); + fprintf(header_out,"#undef yyrealloc\n"); + fprintf(header_out,"#undef yyfree\n"); /* undef any of the auto-generated symbols. */ for(i=0; i < defs_buf.nelts; i++) diff --git a/scan.l b/scan.l index f8c6c8a..df8a919 100644 --- a/scan.l +++ b/scan.l @@ -286,9 +286,9 @@ LEXOPT [aceknopr] yy_scan_bytes ACTION_IFDEF("YY_NO_SCAN_BYTES", ! option_sense); yy_scan_string ACTION_IFDEF("YY_NO_SCAN_STRING", ! option_sense); - yy_flex_alloc ACTION_IFDEF("YY_NO_FLEX_ALLOC", ! option_sense); - yy_flex_realloc ACTION_IFDEF("YY_NO_FLEX_REALLOC", ! option_sense); - yy_flex_free ACTION_IFDEF("YY_NO_FLEX_FREE", ! option_sense); + yyalloc ACTION_IFDEF("YY_NO_FLEX_ALLOC", ! option_sense); + yyrealloc ACTION_IFDEF("YY_NO_FLEX_REALLOC", ! option_sense); + yyfree ACTION_IFDEF("YY_NO_FLEX_FREE", ! option_sense); yyget_debug ACTION_IFDEF("YY_NO_GET_DEBUG", ! option_sense); yyset_debug ACTION_IFDEF("YY_NO_SET_DEBUG", ! option_sense); diff --git a/tests/test-mem-nr/scanner.l b/tests/test-mem-nr/scanner.l index 8031ba6..75a29c9 100644 --- a/tests/test-mem-nr/scanner.l +++ b/tests/test-mem-nr/scanner.l @@ -39,7 +39,7 @@ %option 8bit outfile="scanner.c" prefix="test" %option nounput nomain noyywrap %option warn stack nodefault -%option noyy_flex_alloc noyy_flex_realloc noyy_flex_free +%option noyyalloc noyyrealloc noyyfree %x parens @@ -82,7 +82,7 @@ static void dump_mem(FILE* fp){ fprintf(fp,"}\n"); } -void * yy_flex_alloc(size_t n YY_LAST_ARG) +void * yyalloc(size_t n YY_LAST_ARG) { void * p; struct memsz * old; @@ -112,7 +112,7 @@ void * yy_flex_alloc(size_t n YY_LAST_ARG) return p; } -void * yy_flex_realloc(void* p, size_t n YY_LAST_ARG) +void * yyrealloc(void* p, size_t n YY_LAST_ARG) { int i; for (i=0; i < arrsz; i++) @@ -133,7 +133,7 @@ void * yy_flex_realloc(void* p, size_t n YY_LAST_ARG) exit(1); } -void yy_flex_free(void* p YY_LAST_ARG) +void yyfree(void* p YY_LAST_ARG) { int i; for (i=0; i < arrsz; i++) diff --git a/tests/test-mem-r/scanner.l b/tests/test-mem-r/scanner.l index d4ba2e1..10acd9a 100644 --- a/tests/test-mem-r/scanner.l +++ b/tests/test-mem-r/scanner.l @@ -39,7 +39,7 @@ %option 8bit outfile="scanner.c" prefix="test" %option nounput nomain noyywrap %option warn stack nodefault reentrant -%option noyy_flex_alloc noyy_flex_realloc noyy_flex_free +%option noyyalloc noyyrealloc noyyfree %x parens @@ -82,7 +82,7 @@ static void dump_mem(FILE* fp){ fprintf(fp,"}\n"); } -void * yy_flex_alloc(size_t n YY_LAST_ARG) +void * yyalloc(size_t n YY_LAST_ARG) { void * p; struct memsz * old; @@ -112,7 +112,7 @@ void * yy_flex_alloc(size_t n YY_LAST_ARG) return p; } -void * yy_flex_realloc(void* p, size_t n YY_LAST_ARG) +void * yyrealloc(void* p, size_t n YY_LAST_ARG) { int i; for (i=0; i < arrsz; i++) @@ -133,7 +133,7 @@ void * yy_flex_realloc(void* p, size_t n YY_LAST_ARG) exit(1); } -void yy_flex_free(void* p YY_LAST_ARG) +void yyfree(void* p YY_LAST_ARG) { int i; for (i=0; i < arrsz; i++) -- 2.40.0