Allocates the stack if it does not exist. * Guarantees space for at least one push. */
| 4098 | * Guarantees space for at least one push. |
| 4099 | */ |
| 4100 | static void yyensure_buffer_stack (yyscan_t yyscanner) |
| 4101 | { |
| 4102 | yy_size_t num_to_alloc; |
| 4103 | struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; |
| 4104 | |
| 4105 | if (!yyg->yy_buffer_stack) { |
| 4106 | |
| 4107 | /* First allocation is just for 2 elements, since we don't know if this |
| 4108 | * scanner will even need a stack. We use 2 instead of 1 to avoid an |
| 4109 | * immediate realloc on the next call. |
| 4110 | */ |
| 4111 | num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */ |
| 4112 | yyg->yy_buffer_stack = (struct yy_buffer_state**)yyalloc |
| 4113 | (num_to_alloc * sizeof(struct yy_buffer_state*) |
| 4114 | , yyscanner); |
| 4115 | if ( ! yyg->yy_buffer_stack ) |
| 4116 | YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); |
| 4117 | |
| 4118 | memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*)); |
| 4119 | |
| 4120 | yyg->yy_buffer_stack_max = num_to_alloc; |
| 4121 | yyg->yy_buffer_stack_top = 0; |
| 4122 | return; |
| 4123 | } |
| 4124 | |
| 4125 | if (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1){ |
| 4126 | |
| 4127 | /* Increase the buffer to prepare for a possible push. */ |
| 4128 | yy_size_t grow_size = 8 /* arbitrary grow size */; |
| 4129 | |
| 4130 | num_to_alloc = yyg->yy_buffer_stack_max + grow_size; |
| 4131 | yyg->yy_buffer_stack = (struct yy_buffer_state**)yyrealloc |
| 4132 | (yyg->yy_buffer_stack, |
| 4133 | num_to_alloc * sizeof(struct yy_buffer_state*) |
| 4134 | , yyscanner); |
| 4135 | if ( ! yyg->yy_buffer_stack ) |
| 4136 | YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); |
| 4137 | |
| 4138 | /* zero only the new slots.*/ |
| 4139 | memset(yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, 0, grow_size * sizeof(struct yy_buffer_state*)); |
| 4140 | yyg->yy_buffer_stack_max = num_to_alloc; |
| 4141 | } |
| 4142 | } |
| 4143 | |
| 4144 | /** Setup the input buffer state to scan directly from a user-specified character buffer. |
| 4145 | * @param base the character buffer |
no test coverage detected