aboutsummaryrefslogtreecommitdiffstats
path: root/src/reader.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-05-12 22:44:36 +0200
committerDavid Robillard <d@drobilla.net>2018-12-31 11:37:47 -0500
commitb44992069f4892769b055d5dd1df7cc5d856080c (patch)
treec43466fe776a74134b4c06028dd4fe22607a3d20 /src/reader.c
parent869e805270479fbce0e5f517890b6458398d781a (diff)
downloadserd-b44992069f4892769b055d5dd1df7cc5d856080c.tar.gz
serd-b44992069f4892769b055d5dd1df7cc5d856080c.tar.bz2
serd-b44992069f4892769b055d5dd1df7cc5d856080c.zip
Simplify stack management by popping in bulk at higher levels
Since all memory used by the reader is POD in the stack, there is no benefit to forcing code to explicitly pop everything pushed to the stack, since any function can record an offset and pop back down to it regardless of what its callers pushed if it knows that it does not need those items.
Diffstat (limited to 'src/reader.c')
-rw-r--r--src/reader.c27
1 files changed, 8 insertions, 19 deletions
diff --git a/src/reader.c b/src/reader.c
index 6e784eea..e6629305 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -74,6 +74,13 @@ SerdNode*
push_node_padded(SerdReader* reader, size_t maxlen,
SerdType type, const char* str, size_t n_bytes)
{
+ // Push a null byte to ensure the previous node was null terminated
+ char* terminator = (char*)serd_stack_push(&reader->stack, 1);
+ if (!terminator) {
+ return NULL;
+ }
+ *terminator = 0;
+
void* mem = serd_stack_push_aligned(
&reader->stack, sizeof(SerdNode) + maxlen + 1, sizeof(SerdNode));
@@ -93,7 +100,7 @@ push_node_padded(SerdReader* reader, size_t maxlen,
#ifdef SERD_STACK_CHECK
reader->allocs = realloc(
reader->allocs, sizeof(reader->allocs) * (++reader->n_allocs));
- reader->allocs[reader->n_allocs - 1] = (mem - reader->stack.buf);
+ reader->allocs[reader->n_allocs - 1] = node;
#endif
return node;
}
@@ -104,21 +111,6 @@ push_node(SerdReader* reader, SerdType type, const char* str, size_t n_bytes)
return push_node_padded(reader, n_bytes, type, str, n_bytes);
}
-SerdNode*
-pop_node(SerdReader* reader, const SerdNode* node)
-{
- if (node && node != reader->rdf_first && node != reader->rdf_rest
- && node != reader->rdf_nil) {
-#ifdef SERD_STACK_CHECK
- SERD_STACK_ASSERT_TOP(reader, node);
- --reader->n_allocs;
-#endif
- char* const top = reader->stack.buf + reader->stack.size;
- serd_stack_pop_aligned(&reader->stack, top - (char*)node);
- }
- return NULL;
-}
-
bool
emit_statement(SerdReader* reader, ReadContext ctx, SerdNode* o)
{
@@ -190,9 +182,6 @@ serd_reader_set_strict(SerdReader* reader, bool strict)
void
serd_reader_free(SerdReader* reader)
{
- pop_node(reader, reader->rdf_nil);
- pop_node(reader, reader->rdf_rest);
- pop_node(reader, reader->rdf_first);
serd_node_free(reader->default_graph);
#ifdef SERD_STACK_CHECK