aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/reader.c4
-rw-r--r--src/stack.h19
2 files changed, 10 insertions, 13 deletions
diff --git a/src/reader.c b/src/reader.c
index e819d472..5ff2cbd9 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -173,7 +173,7 @@ serd_reader_new(SerdWorld* const world,
me->world = world;
me->sink = sink;
- me->stack = serd_stack_new(stack_size);
+ me->stack = serd_stack_new(stack_size, serd_node_align);
me->syntax = syntax;
me->next_id = 1;
me->strict = !(flags & SERD_READ_LAX);
@@ -202,7 +202,7 @@ serd_reader_free(SerdReader* const reader)
serd_reader_finish(reader);
- free(reader->stack.buf);
+ serd_free_aligned(reader->stack.buf);
free(reader->bprefix);
free(reader);
}
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 <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. */
-#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;