diff options
author | David Robillard <d@drobilla.net> | 2012-02-21 19:45:52 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2012-02-21 19:45:52 +0000 |
commit | 1663e3e9940db8be898a1e00e5b6833cd8a22c3f (patch) | |
tree | c2c112cc8386e78767b57af7f4a5b72d33dedc11 | |
parent | 6d82fc9ff3264f3a327934920c125f1fb8e7eae5 (diff) | |
download | serd-1663e3e9940db8be898a1e00e5b6833cd8a22c3f.tar.gz serd-1663e3e9940db8be898a1e00e5b6833cd8a22c3f.tar.bz2 serd-1663e3e9940db8be898a1e00e5b6833cd8a22c3f.zip |
Add prefix to generated node IDs as well, to avoid clashing when reading multiple documents into one model.
git-svn-id: http://svn.drobilla.net/serd/trunk@324 490d8e77-9747-427b-9fa3-0b8f29cee8a0
-rw-r--r-- | src/reader.c | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/reader.c b/src/reader.c index 05dcdfca..c0cb522a 100644 --- a/src/reader.c +++ b/src/reader.c @@ -30,8 +30,6 @@ #define TRY_THROW(exp) if (!(exp)) goto except; #define TRY_RET(exp) if (!(exp)) return 0; -#define MAX_ID_SIZE (5 + 10 + 1) /* "genid" + UINT32_MAX + \0 */ - #ifdef SERD_STACK_CHECK # define SERD_STACK_ASSERT_TOP(reader, ref) \ assert(ref == reader->allocs[reader->n_allocs - 1]); @@ -966,16 +964,23 @@ read_nodeID(SerdReader* reader) static void set_blank_id(SerdReader* reader, Ref ref, size_t buf_size) { - SerdNode* node = deref(reader, ref); + SerdNode* node = deref(reader, ref); + const char* prefix = reader->bprefix ? (const char*)reader->bprefix : ""; node->n_bytes = node->n_chars = snprintf( - (char*)node->buf, buf_size, "genid%u", reader->next_id++); + (char*)node->buf, buf_size, "%sgenid%u", prefix, reader->next_id++); +} + +static size_t +genid_size(SerdReader* reader) +{ + return reader->bprefix_len + 5 + 10 + 1; // + "genid" + UINT32_MAX + \0 } static Ref blank_id(SerdReader* reader) { - Ref ref = push_node_padded(reader, MAX_ID_SIZE, SERD_BLANK, "", 0); - set_blank_id(reader, ref, MAX_ID_SIZE); + Ref ref = push_node_padded(reader, genid_size(reader), SERD_BLANK, "", 0); + set_blank_id(reader, ref, genid_size(reader)); return ref; } @@ -1172,7 +1177,7 @@ read_collection(SerdReader* reader, ReadContext ctx, Ref* dest) /* The order of node allocation here is necessarily not in stack order, so we create two nodes and recycle them throughout. */ - Ref n1 = push_node_padded(reader, MAX_ID_SIZE, SERD_BLANK, "", 0); + Ref n1 = push_node_padded(reader, genid_size(reader), SERD_BLANK, "", 0); Ref n2 = 0; Ref node = n1; Ref rest = 0; @@ -1191,7 +1196,7 @@ read_collection(SerdReader* reader, ReadContext ctx, Ref* dest) if (!rest) { rest = n2 = blank_id(reader); // First pass, push a new node } else { - set_blank_id(reader, rest, MAX_ID_SIZE); + set_blank_id(reader, rest, genid_size(reader)); } } |