From 79da5dfa0fb837f97b1f1d71377a83efa90c8081 Mon Sep 17 00:00:00 2001 From: Joseph Langley Date: Fri, 2 Jul 2021 18:46:52 -0400 Subject: fix(skel): Init state buffer correctly State buffer initialization in cpp-flex.skl got lost during a rebase. Added it back in from c99-flex.skl and made improvements suggested by smcpeak. --- src/c99-flex.skl | 37 ++++++++++++++----------------------- src/cpp-flex.skl | 23 ++++++++++++----------- src/go-flex.skl | 37 ++++++++++++++----------------------- 3 files changed, 40 insertions(+), 57 deletions(-) diff --git a/src/c99-flex.skl b/src/c99-flex.skl index 18af12b..317c038 100644 --- a/src/c99-flex.skl +++ b/src/c99-flex.skl @@ -2020,29 +2020,6 @@ m4_ifdef( [[]], m4_ifdef([[YY_USER_INIT]], [[YY_USER_INIT]]) -m4_ifdef( [[M4_MODE_USES_REJECT]], -[[ - /* Create the reject buffer large enough to save one state per allowed character. */ - if ( yyscanner->yy_state_buf == NULL ) { - if( yy_current_buffer(yyscanner) == NULL ) { - yyscanner->yy_state_buf = (yy_state_type *)yyalloc((YY_STATE_BUF_SIZE * sizeof(yy_state_type)), yyscanner); - } - else { - yyscanner->yy_state_buf = (yy_state_type *)yyalloc(((yy_current_buffer(yyscanner)->yy_buf_size + YY_STATE_BUF_EXTRA_SPACE) * sizeof(yy_state_type)), yyscanner); - } - } - - if ( yyscanner->yy_state_buf == NULL ) { - yypanic( "out of dynamic memory in yylex()", yyscanner ); - } - else if ( yy_current_buffer(yyscanner) == NULL ) { - yyscanner->yy_state_buf_max = YY_STATE_BUF_SIZE; - } - else { - yyscanner->yy_state_buf_max = (yy_current_buffer(yyscanner)->yy_buf_size + YY_STATE_BUF_EXTRA_SPACE); - } -]]) - if ( yyscanner->yy_start == 0 ) { yyscanner->yy_start = 1; /* first start state */ } @@ -2057,6 +2034,20 @@ m4_ifdef( [[M4_MODE_USES_REJECT]], yyscanner->yy_buffer_stack[yyscanner->yy_buffer_stack_top] = yy_create_buffer( yyscanner->yyin_r, YY_BUF_SIZE, yyscanner); } + +m4_ifdef( [[M4_MODE_USES_REJECT]], +[[ + /* Create the reject buffer large enough to save one state per allowed character. + * If the reject buffer already exists, keep using it. + */ + if ( yyscanner->yy_state_buf == NULL ) { + yyscanner->yy_state_buf = (yy_state_type *)yyalloc(((yy_current_buffer(yyscanner)->yy_buf_size + YY_STATE_BUF_EXTRA_SPACE) * sizeof(yy_state_type)), yyscanner); + if ( yyscanner->yy_state_buf == NULL ) { + yypanic( "out of dynamic memory in yylex()", yyscanner ); + } + yyscanner->yy_state_buf_max = (yy_current_buffer(yyscanner)->yy_buf_size + YY_STATE_BUF_EXTRA_SPACE); + } +]]) yy_load_buffer_state( yyscanner ); } diff --git a/src/cpp-flex.skl b/src/cpp-flex.skl index fe9344f..10738ba 100644 --- a/src/cpp-flex.skl +++ b/src/cpp-flex.skl @@ -1880,17 +1880,6 @@ m4_ifdef( [[]], YY_USER_INIT; #endif -m4_ifdef( [[M4_MODE_USES_REJECT]], -[[ - /* Create the reject buffer large enough to save one state per allowed character. */ - if ( ! YY_G(yy_state_buf) ) { - YY_G(yy_state_buf) = (yy_state_type *)yyalloc(YY_STATE_BUF_SIZE M4_YY_CALL_LAST_ARG); - } - if ( ! YY_G(yy_state_buf) ) { - YY_FATAL_ERROR( "out of dynamic memory in yylex()" ); - } -]]) - if ( ! YY_G(yy_start) ) { YY_G(yy_start) = 1; /* first start state */ } @@ -1915,6 +1904,18 @@ m4_ifdef([[M4_MODE_CXX_ONLY]], [[ YY_CURRENT_BUFFER_LVALUE = yy_create_buffer( yyin, YY_BUF_SIZE M4_YY_CALL_LAST_ARG); } + +m4_ifdef( [[M4_MODE_USES_REJECT]], +[[ + /* Create the reject buffer large enough to save one state per allowed character. */ + if ( ! YY_G(yy_state_buf) ) { + YY_G(yy_state_buf) = (yy_state_type *)yyalloc( ((YY_CURRENT_BUFFER_LVALUE->yy_buf_size + YY_STATE_BUF_EXTRA_SPACE) * sizeof(yy_state_type)) M4_YY_CALL_LAST_ARG); + if ( ! YY_G(yy_state_buf) ) { + YY_FATAL_ERROR( "out of dynamic memory in yylex()" ); + } + YY_G(yy_state_buf_max) = (YY_CURRENT_BUFFER_LVALUE->yy_buf_size + YY_STATE_BUF_EXTRA_SPACE); + } +]]) yy_load_buffer_state( M4_YY_CALL_ONLY_ARG ); } diff --git a/src/go-flex.skl b/src/go-flex.skl index f05bb51..53f0b90 100644 --- a/src/go-flex.skl +++ b/src/go-flex.skl @@ -1871,29 +1871,6 @@ m4_ifdef([[]], m4_ifdef([[YY_USER_INIT]], [[YY_USER_INIT]]) -m4_ifdef([[M4_MODE_USES_REJECT]], -[[ - /* Create the reject buffer large enough to save one state per allowed character. */ - if (yyscanner->yyStateBuf == NULL) { - if (yy_current_buffer(yyscanner) == NULL) { - yyscanner->yyStateBuf = (yyStateType *)yyalloc((YY_STATE_BUF_SIZE * sizeof(yyStateType)), yyscanner); - } - else { - yyscanner->yyStateBuf = (yyStateType *)yyalloc((yy_current_buffer(yyscanner)->yyInputBufSize + YY_STATE_BUF_EXTRA_SPACE) * sizeof(yyStateType), yyscanner); - } - } - - if ( yyscanner->yyStateBuf == NULL ) { - yypanic( "out of dynamic memory in yylex()", yyscanner ); - } - else if ( yy_current_buffer(yyscanner) == NULL ) { - yyscanner->yyStateBufMax = YY_STATE_BUF_SIZE; - } - else { - yyscanner->yyStateBufMax = (yy_current_buffer(yyscanner)->yyInputBufSize + YY_STATE_BUF_EXTRA_SPACE); - } -]]) - if (yyscanner->yyStart == 0) { yyscanner->yyStart = 1; /* first start state */ } @@ -1909,6 +1886,20 @@ m4_ifdef([[M4_MODE_USES_REJECT]], yy_create_buffer(yyscanner->yyin, flexInputBufferSize, yyscanner); } +m4_ifdef([[M4_MODE_USES_REJECT]], +[[ + /* Create the reject buffer large enough to save one state per allowed character. + * If the reject buffer already exists, keep using it. + */ + if (yyscanner->yyStateBuf == NULL) { + yyscanner->yyStateBuf = (yyStateType *)yyalloc((yy_current_buffer(yyscanner)->yyInputBufSize + YY_STATE_BUF_EXTRA_SPACE) * sizeof(yyStateType), yyscanner); + if ( yyscanner->yyStateBuf == NULL ) { + yypanic( "out of dynamic memory in yylex()", yyscanner ); + } + yyscanner->yyStateBufMax = (yy_current_buffer(yyscanner)->yyInputBufSize + YY_STATE_BUF_EXTRA_SPACE); + } +]]) + yy_load_buffer_state(yyscanner); } -- cgit v1.2.1