aboutsummaryrefslogtreecommitdiffstats
path: root/src/reader.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2012-02-21 04:29:25 +0000
committerDavid Robillard <d@drobilla.net>2012-02-21 04:29:25 +0000
commit30aa350f3ed2a494640db31a44d6ceb24911dce5 (patch)
tree35197922a3f405fa504caa749a2cb9f63800a52f /src/reader.c
parent5121ecc53618dcca1510eb2af85ea57699cff071 (diff)
downloadserd-30aa350f3ed2a494640db31a44d6ceb24911dce5.tar.gz
serd-30aa350f3ed2a494640db31a44d6ceb24911dce5.tar.bz2
serd-30aa350f3ed2a494640db31a44d6ceb24911dce5.zip
Report read error if both "genid" and "docid" IDs are found in the same document, to prevent silent merging of distinct blank nodes.
git-svn-id: http://svn.drobilla.net/serd/trunk@320 490d8e77-9747-427b-9fa3-0b8f29cee8a0
Diffstat (limited to 'src/reader.c')
-rw-r--r--src/reader.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/reader.c b/src/reader.c
index 0a6b3467..05dcdfca 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -81,6 +81,7 @@ struct SerdReaderImpl {
int32_t read_head; ///< Offset into read_buf
bool from_file; ///< True iff reading from @ref fd
bool eof;
+ bool seen_genid;
#ifdef SERD_STACK_CHECK
Ref* allocs; ///< Stack of push offsets
size_t n_allocs; ///< Number of stack pushes
@@ -948,11 +949,16 @@ read_nodeID(SerdReader* reader)
if (!read_name(reader, ref)) {
return error(reader, "illegal character at start of name\n");
}
- SerdNode* const node = deref(reader, ref);
- if (reader->syntax == SERD_TURTLE
- && !strncmp((const char*)node->buf, "genid", 5)) {
- // Replace "genid" nodes with "docid" to prevent clashing
- memcpy((uint8_t*)node + sizeof(SerdNode), "docid", 5);
+ if (reader->syntax == SERD_TURTLE) {
+ const char* const buf = (const char*)deref(reader, ref)->buf;
+ if (!strncmp(buf, "genid", 5)) {
+ memcpy((char*)buf, "docid", 5); // Prevent clash
+ reader->seen_genid = true;
+ } else if (reader->seen_genid && !strncmp(buf, "docid", 5)) {
+ error(reader, "found both `genid' and `docid' blank IDs\n");
+ error(reader, "resolve this with a blank ID prefix\n");
+ return pop_node(reader, ref);
+ }
}
return ref;
}
@@ -983,8 +989,7 @@ read_blank(SerdReader* reader, ReadContext ctx, bool subject, Ref* dest)
const SerdStatementFlags old_flags = *ctx.flags;
switch (peek_byte(reader)) {
case '_':
- *dest = read_nodeID(reader);
- return true;
+ return (*dest = read_nodeID(reader));
case '[':
eat_byte_safe(reader, '[');
const bool empty = peek_delim(reader, ']');
@@ -1354,6 +1359,7 @@ serd_reader_new(SerdSyntax syntax,
me->read_buf = 0;
me->read_head = 0;
me->eof = false;
+ me->seen_genid = false;
#ifdef SERD_STACK_CHECK
me->allocs = 0;
me->n_allocs = 0;