Allocates the stack if it does not exist. * Guarantees space for at least one push. */
| 2017 | * Guarantees space for at least one push. |
| 2018 | */ |
| 2019 | static void yyensure_buffer_stack (yyscan_t yyscanner) |
| 2020 | { |
| 2021 | yy_size_t num_to_alloc; |
| 2022 | struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; |
| 2023 | |
| 2024 | if (!yyg->yy_buffer_stack) { |
| 2025 | |
| 2026 | /* First allocation is just for 2 elements, since we don't know if this |
| 2027 | * scanner will even need a stack. We use 2 instead of 1 to avoid an |
| 2028 | * immediate realloc on the next call. |
| 2029 | */ |
| 2030 | num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */ |
| 2031 | yyg->yy_buffer_stack = (struct yy_buffer_state**)yyalloc |
| 2032 | (num_to_alloc * sizeof(struct yy_buffer_state*) |
| 2033 | , yyscanner); |
| 2034 | if ( ! yyg->yy_buffer_stack ) |
| 2035 | YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); |
| 2036 | |
| 2037 | memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*)); |
| 2038 | |
| 2039 | yyg->yy_buffer_stack_max = num_to_alloc; |
| 2040 | yyg->yy_buffer_stack_top = 0; |
| 2041 | return; |
| 2042 | } |
| 2043 | |
| 2044 | if (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1){ |
| 2045 | |
| 2046 | /* Increase the buffer to prepare for a possible push. */ |
| 2047 | yy_size_t grow_size = 8 /* arbitrary grow size */; |
| 2048 | |
| 2049 | num_to_alloc = yyg->yy_buffer_stack_max + grow_size; |
| 2050 | yyg->yy_buffer_stack = (struct yy_buffer_state**)yyrealloc |
| 2051 | (yyg->yy_buffer_stack, |
| 2052 | num_to_alloc * sizeof(struct yy_buffer_state*) |
| 2053 | , yyscanner); |
| 2054 | if ( ! yyg->yy_buffer_stack ) |
| 2055 | YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); |
| 2056 | |
| 2057 | /* zero only the new slots.*/ |
| 2058 | memset(yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, 0, grow_size * sizeof(struct yy_buffer_state*)); |
| 2059 | yyg->yy_buffer_stack_max = num_to_alloc; |
| 2060 | } |
| 2061 | } |
| 2062 | |
| 2063 | /** Setup the input buffer state to scan directly from a user-specified character buffer. |
| 2064 | * @param base the character buffer |
no test coverage detected