MCPcopy Create free account
hub / github.com/AMReX-Codes/amrex / yyensure_buffer_stack

Function yyensure_buffer_stack

Src/Base/Parser/amrex_parser.lex.nolint.H:1921–1962  ·  view source on GitHub ↗

Allocates the stack if it does not exist. * Guarantees space for at least one push. */

Source from the content-addressed store, hash-verified

1919 * Guarantees space for at least one push.
1920 */
1921static void yyensure_buffer_stack (void)
1922{
1923 yy_size_t num_to_alloc;
1924
1925 if (!(yy_buffer_stack)) {
1926
1927 /* First allocation is just for 2 elements, since we don't know if this
1928 * scanner will even need a stack. We use 2 instead of 1 to avoid an
1929 * immediate realloc on the next call.
1930 */
1931 num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */
1932 (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc
1933 (num_to_alloc * sizeof(struct yy_buffer_state*)
1934 );
1935 if ( ! (yy_buffer_stack) )
1936 YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
1937
1938 memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*));
1939
1940 (yy_buffer_stack_max) = num_to_alloc;
1941 (yy_buffer_stack_top) = 0;
1942 return;
1943 }
1944
1945 if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){
1946
1947 /* Increase the buffer to prepare for a possible push. */
1948 yy_size_t grow_size = 8 /* arbitrary grow size */;
1949
1950 num_to_alloc = (yy_buffer_stack_max) + grow_size;
1951 (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc
1952 ((yy_buffer_stack),
1953 num_to_alloc * sizeof(struct yy_buffer_state*)
1954 );
1955 if ( ! (yy_buffer_stack) )
1956 YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
1957
1958 /* zero only the new slots.*/
1959 memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*));
1960 (yy_buffer_stack_max) = num_to_alloc;
1961 }
1962}
1963
1964/** Setup the input buffer state to scan directly from a user-specified character buffer.
1965 * @param base the character buffer

Callers 4

yyrestartFunction · 0.70
yy_switch_to_bufferFunction · 0.70
yypush_buffer_stateFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected