Allocates the stack if it does not exist. * Guarantees space for at least one push. */
| 4531 | * Guarantees space for at least one push. |
| 4532 | */ |
| 4533 | static void yyensure_buffer_stack (yyscan_t yyscanner) |
| 4534 | { |
| 4535 | yy_size_t num_to_alloc; |
| 4536 | struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; |
| 4537 | |
| 4538 | if (!yyg->yy_buffer_stack) { |
| 4539 | |
| 4540 | /* First allocation is just for 2 elements, since we don't know if this |
| 4541 | * scanner will even need a stack. We use 2 instead of 1 to avoid an |
| 4542 | * immediate realloc on the next call. |
| 4543 | */ |
| 4544 | num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */ |
| 4545 | yyg->yy_buffer_stack = (struct yy_buffer_state**)yyalloc |
| 4546 | (num_to_alloc * sizeof(struct yy_buffer_state*) |
| 4547 | , yyscanner); |
| 4548 | if ( ! yyg->yy_buffer_stack ) |
| 4549 | YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); |
| 4550 | |
| 4551 | memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*)); |
| 4552 | |
| 4553 | yyg->yy_buffer_stack_max = num_to_alloc; |
| 4554 | yyg->yy_buffer_stack_top = 0; |
| 4555 | return; |
| 4556 | } |
| 4557 | |
| 4558 | if (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1){ |
| 4559 | |
| 4560 | /* Increase the buffer to prepare for a possible push. */ |
| 4561 | yy_size_t grow_size = 8 /* arbitrary grow size */; |
| 4562 | |
| 4563 | num_to_alloc = yyg->yy_buffer_stack_max + grow_size; |
| 4564 | yyg->yy_buffer_stack = (struct yy_buffer_state**)yyrealloc |
| 4565 | (yyg->yy_buffer_stack, |
| 4566 | num_to_alloc * sizeof(struct yy_buffer_state*) |
| 4567 | , yyscanner); |
| 4568 | if ( ! yyg->yy_buffer_stack ) |
| 4569 | YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); |
| 4570 | |
| 4571 | /* zero only the new slots.*/ |
| 4572 | memset(yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, 0, grow_size * sizeof(struct yy_buffer_state*)); |
| 4573 | yyg->yy_buffer_stack_max = num_to_alloc; |
| 4574 | } |
| 4575 | } |
| 4576 | |
| 4577 | /** Setup the input buffer state to scan directly from a user-specified character buffer. |
| 4578 | * @param base the character buffer |
no test coverage detected