diff options
author | David Robillard <d@drobilla.net> | 2018-11-17 21:01:59 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2022-01-13 23:04:27 -0500 |
commit | 41bbb6d138a8a05bd6bc9fbd3f94a551d9987197 (patch) | |
tree | 664c3416645512fbeb6f9c9b485f02ed512e42f0 | |
parent | 4424a6f7781fcb9095618b2f2c846f3f99859b49 (diff) | |
download | serd-41bbb6d138a8a05bd6bc9fbd3f94a551d9987197.tar.gz serd-41bbb6d138a8a05bd6bc9fbd3f94a551d9987197.tar.bz2 serd-41bbb6d138a8a05bd6bc9fbd3f94a551d9987197.zip |
Align nodes on the reader stack
-rw-r--r-- | src/reader.c | 4 | ||||
-rw-r--r-- | src/stack.h | 11 | ||||
-rw-r--r-- | test/test_overflow.c | 4 |
3 files changed, 12 insertions, 7 deletions
diff --git a/src/reader.c b/src/reader.c index 73e92d40..09e90076 100644 --- a/src/reader.c +++ b/src/reader.c @@ -188,7 +188,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); @@ -217,7 +217,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 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; diff --git a/test/test_overflow.c b/test/test_overflow.c index 8395a13b..936187a9 100644 --- a/test/test_overflow.c +++ b/test/test_overflow.c @@ -84,12 +84,14 @@ static void test_turtle_overflow(void) { static const char* const test_strings[] = { + "<http://example.org/s> <http://example.org/p> :%99 .", "<http://example.org/s> <http://example.org/p> <http://example.org/> .", "<http://example.org/s> <http://example.org/p> " "<thisisanabsurdlylongurischeme://because/testing/> .", + "<http://example.org/s> <http://example.org/p> eg:foo .", "<http://example.org/s> <http://example.org/p> 1234 .", "<http://example.org/s> <http://example.org/p> (1 2 3 4) .", - "<http://example.org/s> <http://example.org/p> ((((((((42)))))))) .", + "<http://example.org/s> <http://example.org/p> (((((((42))))))) .", "<http://example.org/s> <http://example.org/p> \"literal\" .", "<http://example.org/s> <http://example.org/p> _:blank .", "<http://example.org/s> <http://example.org/p> true .", |