aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-01-23 18:10:50 +0000
committerDavid Robillard <d@drobilla.net>2011-01-23 18:10:50 +0000
commiteaec2a93dcc9f7de5ed2d98fa3427c6f9c2ba878 (patch)
treeb274528955394c9f1650bd51f32e34bd2ed8da41
parentbdae0a9015cb399e11525d4296c1a910d038e3dc (diff)
downloadserd-eaec2a93dcc9f7de5ed2d98fa3427c6f9c2ba878.tar.gz
serd-eaec2a93dcc9f7de5ed2d98fa3427c6f9c2ba878.tar.bz2
serd-eaec2a93dcc9f7de5ed2d98fa3427c6f9c2ba878.zip
Gracefully handle failure to emit statement.
Add test cases for 5 and 6-byte UTF-* characters and undefined namespaces. git-svn-id: http://svn.drobilla.net/serd/trunk@48 490d8e77-9747-427b-9fa3-0b8f29cee8a0
-rw-r--r--src/reader.c29
-rw-r--r--src/writer.c4
-rw-r--r--tests/UTF-8.ttl7
-rw-r--r--tests/bad-ns.ttl1
4 files changed, 25 insertions, 16 deletions
diff --git a/src/reader.c b/src/reader.c
index 08511045..0dfdbedc 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -269,17 +269,18 @@ pop_string(SerdReader reader, Ref ref)
}
}
-static inline void
+static inline bool
emit_statement(SerdReader reader,
const Node* g, const Node* s, const Node* p, const Node* o)
{
assert(s->value && p->value && o->value);
- reader->statement_sink(reader->handle,
- g ? deref(reader, g->value) : NULL, g ? g->type : 0,
- deref(reader, s->value), s->type,
- deref(reader, p->value), p->type,
- deref(reader, o->value), o->type,
- deref(reader, o->datatype), deref(reader, o->lang));
+ return reader->statement_sink(
+ reader->handle,
+ g ? deref(reader, g->value) : NULL, g ? g->type : 0,
+ deref(reader, s->value), s->type,
+ deref(reader, p->value), p->type,
+ deref(reader, o->value), o->type,
+ deref(reader, o->datatype), deref(reader, o->lang));
}
static bool read_collection(SerdReader reader, ReadContext ctx, Node* dest);
@@ -985,13 +986,13 @@ read_blank(SerdReader reader, ReadContext ctx, Node* dest)
eat_byte(reader, ']');
*dest = make_node(SERD_BLANK_ID, blank_id(reader), 0, 0);
if (ctx.subject) {
- emit_statement(reader, ctx.graph, ctx.subject, ctx.predicate, dest);
+ TRY_RET(emit_statement(reader, ctx.graph, ctx.subject, ctx.predicate, dest));
}
return true;
}
*dest = make_node(SERD_ANON_BEGIN, blank_id(reader), 0, 0);
if (ctx.subject) {
- emit_statement(reader, ctx.graph, ctx.subject, ctx.predicate, dest);
+ TRY_RET(emit_statement(reader, ctx.graph, ctx.subject, ctx.predicate, dest));
dest->type = SERD_ANON;
}
ctx.subject = dest;
@@ -1005,7 +1006,7 @@ read_blank(SerdReader reader, ReadContext ctx, Node* dest)
case '(':
if (read_collection(reader, ctx, dest)) {
if (ctx.subject) {
- emit_statement(reader, ctx.graph, ctx.subject, ctx.predicate, dest);
+ TRY_RET(emit_statement(reader, ctx.graph, ctx.subject, ctx.predicate, dest));
}
return true;
}
@@ -1085,7 +1086,7 @@ read_object(SerdReader reader, ReadContext ctx)
if (ret && emit) {
assert(o.value);
- emit_statement(reader, ctx.graph, ctx.subject, ctx.predicate, &o);
+ ret = emit_statement(reader, ctx.graph, ctx.subject, ctx.predicate, &o);
}
except:
@@ -1158,12 +1159,12 @@ read_collection_rec(SerdReader reader, ReadContext ctx)
read_ws_star(reader);
if (peek_byte(reader) == ')') {
eat_byte(reader, ')');
- emit_statement(reader, NULL, ctx.subject,
- &reader->rdf_rest, &reader->rdf_nil);
+ TRY_RET(emit_statement(reader, NULL, ctx.subject,
+ &reader->rdf_rest, &reader->rdf_nil));
return false;
} else {
const Node rest = make_node(SERD_BLANK_ID, blank_id(reader), 0, 0);
- emit_statement(reader, ctx.graph, ctx.subject, &reader->rdf_rest, &rest);
+ TRY_RET(emit_statement(reader, ctx.graph, ctx.subject, &reader->rdf_rest, &rest));
ctx.subject = &rest;
ctx.predicate = &reader->rdf_first;
if (read_object(reader, ctx)) {
diff --git a/src/writer.c b/src/writer.c
index b58d4f3e..48f4adc1 100644
--- a/src/writer.c
+++ b/src/writer.c
@@ -258,7 +258,9 @@ serd_writer_write_statement(
writer->sink(" ", 1, writer->stream);
write_node(writer, predicate_type, predicate, NULL, NULL);
writer->sink(" ", 1, writer->stream);
- write_node(writer, object_type, object, object_datatype, object_lang);
+ if (!write_node(writer, object_type, object, object_datatype, object_lang)) {
+ return false;
+ }
writer->sink(" .\n", 3, writer->stream);
return true;
case SERD_TURTLE:
diff --git a/tests/UTF-8.ttl b/tests/UTF-8.ttl
index 4aa347e8..66be456e 100644
--- a/tests/UTF-8.ttl
+++ b/tests/UTF-8.ttl
@@ -212,4 +212,9 @@ Box drawing alignment tests: █
║└─╥─┘║ │╚═╤═╝│ │╘═╪═╛│ │╙─╀─╜│ ┃└─╂─┘┃ ░░▒▒▓▓██ ┊ ┆ ╎ ╏ ┇ ┋ ▏
╚══╩══╝ └──┴──┘ ╰──┴──╯ ╰──┴──╯ ┗━━┻━━┛ ▗▄▖▛▀▜ └╌╌┘ ╎ ┗╍╍┛ ┋ ▁▂▃▄▅▆▇█
▝▀▘▙▄▟
-""" . \ No newline at end of file
+""" .
+<> rdfs:comment """
+ 5 byte character: \U3FFFFFF
+ 6 byte character: \U7FFFFFFF
+""" .
+
diff --git a/tests/bad-ns.ttl b/tests/bad-ns.ttl
new file mode 100644
index 00000000..4410573e
--- /dev/null
+++ b/tests/bad-ns.ttl
@@ -0,0 +1 @@
+<> a badprefix:Thing . \ No newline at end of file