aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/serd/serd.h12
-rw-r--r--src/reader.c28
-rw-r--r--src/reader.h1
-rw-r--r--test/test_reader_writer.c59
4 files changed, 30 insertions, 70 deletions
diff --git a/include/serd/serd.h b/include/serd/serd.h
index 21f6b7b1..c7dc4a17 100644
--- a/include/serd/serd.h
+++ b/include/serd/serd.h
@@ -1091,18 +1091,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 3be28a53..76b28295 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -118,17 +118,12 @@ push_node(SerdReader* reader,
SerdStatus
emit_statement(SerdReader* reader, ReadContext ctx, SerdNode* o)
{
- SerdNode* graph = ctx.graph;
- if (!graph && reader->default_graph) {
- graph = reader->default_graph;
- }
-
/* Zero the pad of the object node on the top of the stack. Lower nodes
(subject and predicate) were already zeroed by subsequent pushes. */
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;
@@ -162,13 +157,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;
me->rdf_first = push_node(me, SERD_URI, NS_RDF "first", 48);
me->rdf_rest = push_node(me, SERD_URI, NS_RDF "rest", 47);
@@ -191,7 +185,6 @@ serd_reader_free(SerdReader* reader)
}
serd_reader_finish(reader);
- serd_node_free(reader->default_graph);
#ifdef SERD_STACK_CHECK
free(reader->allocs);
@@ -216,13 +209,6 @@ serd_reader_add_blank_prefix(SerdReader* reader, const char* prefix)
}
}
-void
-serd_reader_set_default_graph(SerdReader* reader, const SerdNode* graph)
-{
- serd_node_free(reader->default_graph);
- reader->default_graph = serd_node_copy(graph);
-}
-
static SerdStatus
skip_bom(SerdReader* me)
{
diff --git a/src/reader.h b/src/reader.h
index ce377fd3..6e9ac513 100644
--- a/src/reader.h
+++ b/src/reader.h
@@ -57,7 +57,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 43b820db..8742289a 100644
--- a/test/test_reader_writer.c
+++ b/test/test_reader_writer.c
@@ -25,11 +25,6 @@
#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 +37,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;
}
@@ -79,11 +74,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);
@@ -106,37 +101,36 @@ 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);
}
@@ -160,10 +154,10 @@ test_get_blank(void)
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 +171,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);
}
@@ -291,17 +284,15 @@ 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);
SerdReader* reader = serd_reader_new(world, SERD_TURTLE, sink, 4096);
assert(reader);
assert(sink);
serd_sink_set_statement_func(sink, test_sink);
- SerdNode* g = serd_new_uri(SERD_STATIC_STRING("http://example.org/"));
- serd_reader_set_default_graph(reader, g);
serd_reader_add_blank_prefix(reader, "tmp");
#if defined(__GNUC__)
@@ -313,17 +304,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