diff options
Diffstat (limited to 'src/stack.h')
-rw-r--r-- | src/stack.h | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/stack.h b/src/stack.h index 074d43b0..f94730c3 100644 --- a/src/stack.h +++ b/src/stack.h @@ -17,10 +17,11 @@ #ifndef SERD_STACK_H #define SERD_STACK_H +#include "system.h" + #include <assert.h> #include <stdbool.h> #include <stddef.h> -#include <stdlib.h> #include <string.h> /** An offset to start the stack at. Note 0 is reserved for NULL. */ @@ -37,10 +38,12 @@ typedef struct { #define SERD_STACK_BOTTOM sizeof(void*) static inline SerdStack -serd_stack_new(size_t size) +serd_stack_new(size_t size, size_t align) { + const size_t aligned_size = (size + (align - 1)) / align * align; + SerdStack stack; - stack.buf = (char*)calloc(size, 1); + stack.buf = (char*)serd_calloc_aligned(align, aligned_size); stack.buf_size = size; stack.size = SERD_STACK_BOTTOM; return stack; @@ -61,7 +64,7 @@ serd_stack_is_empty(const SerdStack* stack) static inline void serd_stack_free(SerdStack* stack) { - free(stack->buf); + serd_free_aligned(stack->buf); stack->buf = NULL; stack->buf_size = 0; stack->size = 0; |