diff options
author | David Robillard <d@drobilla.net> | 2011-04-24 00:49:35 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2011-04-24 00:49:35 +0000 |
commit | 0b04f70d827a850ca5e779819095766194cd0e94 (patch) | |
tree | ef44ac656c1f2a8f4687fe6ef5bdb594c30c156d /src/reader.c | |
parent | 2824ef300111f198132de215b57376587851cbd7 (diff) | |
download | serd-0b04f70d827a850ca5e779819095766194cd0e94.tar.gz serd-0b04f70d827a850ca5e779819095766194cd0e94.tar.bz2 serd-0b04f70d827a850ca5e779819095766194cd0e94.zip |
Fix reader memory stack use and verify read_object fully clears its stack.
Make abbreviation in writer not assume equivalent nodes have equivalent addresses (abbreviate more than on input if triples are sorted correctly, e.g. abbrevate ntriples)
git-svn-id: http://svn.drobilla.net/serd/trunk@149 490d8e77-9747-427b-9fa3-0b8f29cee8a0
Diffstat (limited to 'src/reader.c')
-rw-r--r-- | src/reader.c | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/src/reader.c b/src/reader.c index a237bbf2..0f250a0c 100644 --- a/src/reader.c +++ b/src/reader.c @@ -204,21 +204,12 @@ stack_is_top_string(SerdReader reader, Ref ref) } #endif -static inline intptr_t -pad_size(intptr_t size) -{ - return (size + 7) & (~7); -} - // Make a new string from a non-UTF-8 C string (internal use only) static Ref push_string(SerdReader reader, const char* c_str, size_t n_bytes) { - // Align strings to 64-bits (assuming malloc/realloc are aligned to 64-bits) - const size_t stack_size = pad_size((intptr_t)reader->stack.size); - const size_t pad = stack_size - reader->stack.size; - uint8_t* mem = serd_stack_push( - &reader->stack, pad + sizeof(SerdString) + n_bytes) + pad; + uint8_t* mem = serd_stack_push(&reader->stack, + sizeof(SerdString) + n_bytes); SerdString* const str = (SerdString*)mem; str->n_bytes = n_bytes; str->n_chars = n_bytes - 1; @@ -278,7 +269,7 @@ pop_string(SerdReader reader, Ref ref) --reader->n_allocs; #endif SerdString* str = deref(reader, ref); - serd_stack_pop(&reader->stack, pad_size(sizeof(SerdString) + str->n_bytes)); + serd_stack_pop(&reader->stack, sizeof(SerdString) + str->n_bytes); } } @@ -1061,6 +1052,10 @@ read_object(SerdReader reader, ReadContext ctx) static const char* const XSD_BOOLEAN = NS_XSD "boolean"; static const size_t XSD_BOOLEAN_LEN = 40; +#ifndef NDEBUG + const size_t orig_stack_size = reader->stack.size; +#endif + uint8_t pre[6]; bool ret = false; bool emit = (ctx.subject != 0); @@ -1118,6 +1113,9 @@ except: pop_string(reader, o.lang); pop_string(reader, o.datatype); pop_string(reader, o.value); +#ifndef NDEBUG + assert(reader->stack.size == orig_stack_size); +#endif return ret; } |