From 2d43bf2b5c301ca1e4766b5048650ca1e29e38c0 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 17 Nov 2018 21:01:59 +0100 Subject: Align nodes on the reader stack --- src/stack.h | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'src/stack.h') diff --git a/src/stack.h b/src/stack.h index cdf2b0f6..20bd561b 100644 --- a/src/stack.h +++ b/src/stack.h @@ -4,15 +4,13 @@ #ifndef SERD_SRC_STACK_H #define SERD_SRC_STACK_H +#include "system.h" + #include #include #include -#include #include -/** An offset to start the stack at. Note 0 is reserved for NULL. */ -#define SERD_STACK_BOTTOM sizeof(void*) - /** A dynamic stack in memory. */ typedef struct { char* buf; ///< Stack memory @@ -20,23 +18,22 @@ typedef struct { size_t size; ///< Conceptual size of stack in buf } SerdStack; -/** An offset to start the stack at. Note 0 is reserved for NULL. */ -#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; + stack.size = align; // 0 is reserved for null return 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; -- cgit v1.2.1