Allocates the stack if it does not exist. * Guarantees space for at least one push. */
| 2076 | * Guarantees space for at least one push. |
| 2077 | */ |
| 2078 | static void yyensure_buffer_stack (yyscan_t yyscanner) |
| 2079 | { |
| 2080 | yy_size_t num_to_alloc; |
| 2081 | struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; |
| 2082 | |
| 2083 | if (!yyg->yy_buffer_stack) { |
| 2084 | |
| 2085 | /* First allocation is just for 2 elements, since we don't know if this |
| 2086 | * scanner will even need a stack. We use 2 instead of 1 to avoid an |
| 2087 | * immediate realloc on the next call. |
| 2088 | */ |
| 2089 | num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */ |
| 2090 | yyg->yy_buffer_stack = (struct yy_buffer_state**)yyalloc |
| 2091 | (num_to_alloc * sizeof(struct yy_buffer_state*) |
| 2092 | , yyscanner); |
| 2093 | if ( ! yyg->yy_buffer_stack ) |
| 2094 | YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); |
| 2095 | |
| 2096 | memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*)); |
| 2097 | |
| 2098 | yyg->yy_buffer_stack_max = num_to_alloc; |
| 2099 | yyg->yy_buffer_stack_top = 0; |
| 2100 | return; |
| 2101 | } |
| 2102 | |
| 2103 | if (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1){ |
| 2104 | |
| 2105 | /* Increase the buffer to prepare for a possible push. */ |
| 2106 | yy_size_t grow_size = 8 /* arbitrary grow size */; |
| 2107 | |
| 2108 | num_to_alloc = yyg->yy_buffer_stack_max + grow_size; |
| 2109 | yyg->yy_buffer_stack = (struct yy_buffer_state**)yyrealloc |
| 2110 | (yyg->yy_buffer_stack, |
| 2111 | num_to_alloc * sizeof(struct yy_buffer_state*) |
| 2112 | , yyscanner); |
| 2113 | if ( ! yyg->yy_buffer_stack ) |
| 2114 | YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); |
| 2115 | |
| 2116 | /* zero only the new slots.*/ |
| 2117 | memset(yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, 0, grow_size * sizeof(struct yy_buffer_state*)); |
| 2118 | yyg->yy_buffer_stack_max = num_to_alloc; |
| 2119 | } |
| 2120 | } |
| 2121 | |
| 2122 | /** Setup the input buffer state to scan directly from a user-specified character buffer. |
| 2123 | * @param base the character buffer |
no test coverage detected
searching dependent graphs…