aboutsummaryrefslogtreecommitdiffstats
path: root/src/stack.h
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-11-17 21:01:59 +0100
committerDavid Robillard <d@drobilla.net>2022-01-13 23:04:27 -0500
commit41bbb6d138a8a05bd6bc9fbd3f94a551d9987197 (patch)
tree664c3416645512fbeb6f9c9b485f02ed512e42f0 /src/stack.h
parent4424a6f7781fcb9095618b2f2c846f3f99859b49 (diff)
downloadserd-41bbb6d138a8a05bd6bc9fbd3f94a551d9987197.tar.gz
serd-41bbb6d138a8a05bd6bc9fbd3f94a551d9987197.tar.bz2
serd-41bbb6d138a8a05bd6bc9fbd3f94a551d9987197.zip
Align nodes on the reader stack
Diffstat (limited to 'src/stack.h')
-rw-r--r--src/stack.h11
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;