aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/serd/serd.h12
-rw-r--r--src/reader.c29
-rw-r--r--src/reader.h1
-rw-r--r--test/test_reader_writer.c60
4 files changed, 30 insertions, 72 deletions
diff --git a/include/serd/serd.h b/include/serd/serd.h
index 778ccc03..a04f1c8f 100644
--- a/include/serd/serd.h
+++ b/include/serd/serd.h
@@ -1146,18 +1146,6 @@ void
serd_reader_add_blank_prefix(SerdReader* SERD_NONNULL reader,
const char* SERD_NULLABLE prefix);
-/**
- Set the URI of the default graph.
-
- If this is set, the reader will emit quads with the graph set to the given
- node for any statements that are not in a named graph (which is currently
- all of them since Serd currently does not support any graph syntaxes).
-*/
-SERD_API
-void
-serd_reader_set_default_graph(SerdReader* SERD_NONNULL reader,
- const SerdNode* SERD_NULLABLE graph);
-
/// Prepare to read from the file at a local file `uri`
SERD_API
SerdStatus
diff --git a/src/reader.c b/src/reader.c
index 2bcd0969..2cdf18c6 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -120,11 +120,6 @@ emit_statement(SerdReader* const reader,
const ReadContext ctx,
SerdNode* const o)
{
- SerdNode* graph = ctx.graph;
- if (!graph && reader->default_graph) {
- graph = reader->default_graph;
- }
-
if (reader->stack.size + (2 * sizeof(SerdNode)) > reader->stack.buf_size) {
return SERD_ERR_OVERFLOW;
}
@@ -134,7 +129,7 @@ emit_statement(SerdReader* const reader,
serd_node_zero_pad(o);
const SerdStatus st = serd_sink_write(
- reader->sink, *ctx.flags, ctx.subject, ctx.predicate, o, graph);
+ reader->sink, *ctx.flags, ctx.subject, ctx.predicate, o, ctx.graph);
*ctx.flags &= SERD_ANON_CONT | SERD_LIST_CONT; // Preserve only cont flags
return st;
@@ -172,13 +167,12 @@ serd_reader_new(SerdWorld* const world,
SerdReader* me = (SerdReader*)calloc(1, sizeof(SerdReader));
- me->world = world;
- me->sink = sink;
- me->default_graph = NULL;
- me->stack = serd_stack_new(stack_size);
- me->syntax = syntax;
- me->next_id = 1;
- me->strict = true;
+ me->world = world;
+ me->sink = sink;
+ me->stack = serd_stack_new(stack_size);
+ me->syntax = syntax;
+ me->next_id = 1;
+ me->strict = true;
// Reserve a bit of space at the end of the stack to zero pad nodes
me->stack.buf_size -= serd_node_align;
@@ -209,7 +203,6 @@ serd_reader_free(SerdReader* const reader)
}
serd_reader_finish(reader);
- serd_node_free(reader->default_graph);
free(reader->stack.buf);
free(reader->bprefix);
@@ -231,14 +224,6 @@ serd_reader_add_blank_prefix(SerdReader* const reader, const char* const prefix)
}
}
-void
-serd_reader_set_default_graph(SerdReader* const reader,
- const SerdNode* const graph)
-{
- serd_node_free(reader->default_graph);
- reader->default_graph = serd_node_copy(graph);
-}
-
static SerdStatus
skip_bom(SerdReader* const me)
{
diff --git a/src/reader.h b/src/reader.h
index 39ab4628..d9391ac8 100644
--- a/src/reader.h
+++ b/src/reader.h
@@ -50,7 +50,6 @@ struct SerdReaderImpl {
SerdNode* rdf_first;
SerdNode* rdf_rest;
SerdNode* rdf_nil;
- SerdNode* default_graph;
SerdByteSource source;
SerdStack stack;
SerdSyntax syntax;
diff --git a/test/test_reader_writer.c b/test/test_reader_writer.c
index c71c377a..b741c1ae 100644
--- a/test/test_reader_writer.c
+++ b/test/test_reader_writer.c
@@ -22,14 +22,8 @@
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
-#include <stdlib.h>
#include <string.h>
-typedef struct {
- int n_statements;
- const SerdNode* graph;
-} ReaderTest;
-
static SerdStatus
test_sink(void* handle,
SerdStatementFlags flags,
@@ -42,10 +36,10 @@ test_sink(void* handle,
(void)subject;
(void)predicate;
(void)object;
+ (void)graph;
+
+ ++*(size_t*)handle;
- ReaderTest* rt = (ReaderTest*)handle;
- ++rt->n_statements;
- rt->graph = graph;
return SERD_SUCCESS;
}
@@ -96,11 +90,11 @@ eof_test_error(void* stream)
static void
test_read_chunks(void)
{
- SerdWorld* world = serd_world_new();
- ReaderTest* const rt = (ReaderTest*)calloc(1, sizeof(ReaderTest));
- FILE* const f = tmpfile();
- static const char null = 0;
- SerdSink* sink = serd_sink_new(rt, NULL);
+ SerdWorld* world = serd_world_new();
+ size_t n_statements = 0;
+ FILE* const f = tmpfile();
+ static const char null = 0;
+ SerdSink* sink = serd_sink_new(&n_statements, NULL);
SerdReader* reader = serd_reader_new(world, SERD_TURTLE, sink, 4096);
assert(reader);
@@ -123,47 +117,46 @@ test_read_chunks(void)
// Read prefix
st = serd_reader_read_chunk(reader);
assert(st == SERD_SUCCESS);
- assert(rt->n_statements == 0);
+ assert(n_statements == 0);
// Read first statement
st = serd_reader_read_chunk(reader);
assert(st == SERD_SUCCESS);
- assert(rt->n_statements == 1);
+ assert(n_statements == 1);
// Read terminator
st = serd_reader_read_chunk(reader);
assert(st == SERD_FAILURE);
- assert(rt->n_statements == 1);
+ assert(n_statements == 1);
// Read second statement (after null terminator)
st = serd_reader_read_chunk(reader);
assert(st == SERD_SUCCESS);
- assert(rt->n_statements == 2);
+ assert(n_statements == 2);
// Read terminator
st = serd_reader_read_chunk(reader);
assert(st == SERD_FAILURE);
- assert(rt->n_statements == 2);
+ assert(n_statements == 2);
// EOF
st = serd_reader_read_chunk(reader);
assert(st == SERD_FAILURE);
- assert(rt->n_statements == 2);
+ assert(n_statements == 2);
serd_reader_free(reader);
serd_sink_free(sink);
fclose(f);
- free(rt);
serd_world_free(world);
}
static void
test_read_string(void)
{
- SerdWorld* world = serd_world_new();
- ReaderTest* rt = (ReaderTest*)calloc(1, sizeof(ReaderTest));
- SerdSink* sink = serd_sink_new(rt, NULL);
- SerdReader* reader = serd_reader_new(world, SERD_TURTLE, sink, 4096);
+ SerdWorld* world = serd_world_new();
+ size_t n_statements = 0;
+ SerdSink* sink = serd_sink_new(&n_statements, NULL);
+ SerdReader* reader = serd_reader_new(world, SERD_TURTLE, sink, 4096);
assert(reader);
assert(sink);
@@ -177,12 +170,11 @@ test_read_string(void)
"<http://example.org/o> ."));
assert(!serd_reader_read_document(reader));
- assert(rt->n_statements == 1);
+ assert(n_statements == 1);
assert(!serd_reader_finish(reader));
serd_reader_free(reader);
serd_sink_free(sink);
- free(rt);
serd_world_free(world);
}
@@ -290,9 +282,9 @@ test_writer(const char* const path)
static void
test_reader(const char* path)
{
- SerdWorld* world = serd_world_new();
- ReaderTest rt = {0, NULL};
- SerdSink* const sink = serd_sink_new(&rt, NULL);
+ SerdWorld* world = serd_world_new();
+ size_t n_statements = 0;
+ SerdSink* const sink = serd_sink_new(&n_statements, NULL);
assert(sink);
serd_sink_set_statement_func(sink, test_sink);
@@ -302,8 +294,6 @@ test_reader(const char* path)
SerdReader* reader = serd_reader_new(world, SERD_TURTLE, sink, 4096);
assert(reader);
- SerdNode* g = serd_new_uri(SERD_STRING("http://example.org/"));
- serd_reader_set_default_graph(reader, g);
serd_reader_add_blank_prefix(reader, "tmp");
#if defined(__GNUC__)
@@ -315,17 +305,13 @@ test_reader(const char* path)
# pragma GCC diagnostic pop
#endif
- serd_node_free(g);
-
assert(serd_reader_start_file(reader, "http://notafile", false));
assert(serd_reader_start_file(reader, "file://invalid", false));
assert(serd_reader_start_file(reader, "file:///nonexistant", false));
assert(!serd_reader_start_file(reader, path, true));
assert(!serd_reader_read_document(reader));
- assert(rt.n_statements == 6);
- assert(rt.graph && serd_node_string(rt.graph) &&
- !strcmp(serd_node_string(rt.graph), "http://example.org/"));
+ assert(n_statements == 6);
serd_reader_finish(reader);
// A read of a big page hits EOF then fails to read chunks immediately