libcbor 0.12.0
libcbor is a C library for parsing and generating CBOR, the general-purpose schema-less binary data format.
Loading...
Searching...
No Matches
stack.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2014-2020 Pavel Kalvoda <me@pavelkalvoda.com>
3 *
4 * libcbor is free software; you can redistribute it and/or modify
5 * it under the terms of the MIT license. See LICENSE for details.
6 */
7
8#include "stack.h"
9
11 return (struct _cbor_stack){.top = NULL, .size = 0};
12}
13
14void _cbor_stack_pop(struct _cbor_stack* stack) {
15 struct _cbor_stack_record* top = stack->top;
16 stack->top = stack->top->lower;
17 _cbor_free(top);
18 stack->size--;
19}
20
23 size_t subitems) {
24 if (stack->size == CBOR_MAX_STACK_SIZE) return NULL;
25 struct _cbor_stack_record* new_top =
26 _cbor_malloc(sizeof(struct _cbor_stack_record));
27 if (new_top == NULL) return NULL;
28
29 *new_top = (struct _cbor_stack_record){stack->top, item, subitems};
30 stack->top = new_top;
31 stack->size++;
32 return new_top;
33}
_cbor_malloc_t _cbor_malloc
Definition allocators.c:10
_cbor_free_t _cbor_free
Definition allocators.c:12
void _cbor_stack_pop(struct _cbor_stack *stack)
Definition stack.c:14
struct _cbor_stack _cbor_stack_init(void)
Definition stack.c:10
struct _cbor_stack_record * _cbor_stack_push(struct _cbor_stack *stack, cbor_item_t *item, size_t subitems)
Definition stack.c:21
Simple stack record for the parser.
Definition stack.h:18
cbor_item_t * item
Item under construction.
Definition stack.h:22
size_t subitems
How many outstanding subitems are expected.
Definition stack.h:31
struct _cbor_stack_record * lower
Pointer to the parent stack frame.
Definition stack.h:20
Stack handle - contents and size.
Definition stack.h:35
struct _cbor_stack_record * top
Definition stack.h:36
size_t size
Definition stack.h:37
The item handle.
Definition data.h:171