40 if (item_size == 0 || chunk_size == 0 || stack == NULL)
47 s->
items = malloc(item_size * chunk_size);
48 if (s->
items == NULL) {
92 if (stack == NULL || item == NULL)
102 void *temp = realloc(stack->
items,
135 memcpy(item, (uint8_t *) stack->
items +
156 return (uint8_t *) stack->
items +
164 void (*printer)(
void *item));
167 void (*printer)(
void *item))
171 if (stack == NULL || printer == NULL)
175 printf(
"%s %d: ", prefix != NULL ? prefix :
"", i);
parserutils_error parserutils_stack_create(size_t item_size, size_t chunk_size, parserutils_stack **stack)
Create a stack.
void * parserutils_stack_get_current(parserutils_stack *stack)
Retrieve a pointer to the current item on the stack.
parserutils_error parserutils_stack_pop(parserutils_stack *stack, void *item)
Pop an item off a stack.
void parserutils_stack_dump(parserutils_stack *stack, const char *prefix, void(*printer)(void *item))
parserutils_error parserutils_stack_push(parserutils_stack *stack, const void *item)
Push an item onto the stack.
parserutils_error parserutils_stack_destroy(parserutils_stack *stack)
Destroy a stack instance.
void * items
Items in stack.
size_t item_size
Size of an item in the stack.
size_t items_allocated
Number of slots allocated.
size_t chunk_size
Size of a stack chunk.
int32_t current_item
Index of current item.