diff options
-rw-r--r-- | src/writer.c | 62 |
1 files changed, 30 insertions, 32 deletions
diff --git a/src/writer.c b/src/writer.c index 8fb2cb50..a3d9d8e8 100644 --- a/src/writer.c +++ b/src/writer.c @@ -154,7 +154,11 @@ free_context(SerdWriter* writer) } static SerdStatus -push_context(SerdWriter* writer, const WriteContext new_context) +push_context(SerdWriter* const writer, + const ContextType type, + const SerdNode* const g, + const SerdNode* const s, + const SerdNode* const p) { WriteContext* top = (WriteContext*)serd_stack_push(&writer->anon_stack, sizeof(WriteContext)); @@ -163,7 +167,11 @@ push_context(SerdWriter* writer, const WriteContext new_context) return SERD_ERR_OVERFLOW; } - *top = writer->context; + *top = writer->context; + + const WriteContext new_context = { + type, serd_node_copy(g), serd_node_copy(s), serd_node_copy(p), false}; + writer->context = new_context; return SERD_SUCCESS; } @@ -941,44 +949,34 @@ serd_writer_write_statement(SerdWriter* const writer, write_node(writer, object, SERD_OBJECT, flags); } - // Push context for anonymous or list subject if necessary - if (flags & (SERD_ANON_S | SERD_LIST_S)) { - const bool is_list = (flags & SERD_LIST_S); - - const WriteContext ctx = {is_list ? CTX_LIST : CTX_BLANK, - serd_node_copy(graph), - serd_node_copy(subject), - is_list ? NULL : serd_node_copy(predicate), - false}; - if ((st = push_context(writer, ctx))) { - return st; + // Push context for list or anonymous subject if necessary + if (!st) { + if (flags & SERD_ANON_S) { + st = push_context(writer, CTX_BLANK, graph, subject, predicate); + } else if (flags & SERD_LIST_S) { + st = push_context(writer, CTX_LIST, graph, subject, NULL); } } - // Push context for anonymous or list object if necessary - if (flags & (SERD_ANON_O | SERD_LIST_O)) { - const bool is_list = (flags & SERD_LIST_O); - - const WriteContext ctx = {is_list ? CTX_LIST : CTX_BLANK, - serd_node_copy(graph), - serd_node_copy(object), - NULL, - false}; - if ((st = push_context(writer, ctx))) { - serd_node_free(ctx.graph); - serd_node_free(ctx.subject); - return st; + // Push context for list or anonymous object if necessary + if (!st) { + if (flags & SERD_ANON_O) { + st = push_context(writer, CTX_BLANK, graph, object, NULL); + } else if (flags & SERD_LIST_O) { + st = push_context(writer, CTX_LIST, graph, object, NULL); } } - if (!(flags & (SERD_ANON_S | SERD_LIST_S | SERD_ANON_O | SERD_LIST_O))) { - // Update current context to this statement - serd_node_set(&writer->context.graph, graph); - serd_node_set(&writer->context.subject, subject); - serd_node_set(&writer->context.predicate, predicate); + // Update current context to this statement if this isn't a new context + if (!st) { + if (!(flags & (SERD_ANON_S | SERD_LIST_S | SERD_ANON_O | SERD_LIST_O))) { + serd_node_set(&writer->context.graph, graph); + serd_node_set(&writer->context.subject, subject); + serd_node_set(&writer->context.predicate, predicate); + } } - return SERD_SUCCESS; + return st; } static SerdStatus |