diff options
author | David Robillard <d@drobilla.net> | 2023-12-02 01:20:48 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2023-12-02 18:49:07 -0500 |
commit | 930f28478ca2573b7f7baf29a57a03cfa95a841f (patch) | |
tree | ccd9fca0955c8c92e6f3d3cacd032024c1c3d4b7 /test/test_reader_writer.c | |
parent | 06bc73c6fdf986eb5d13943b497992a947661bb1 (diff) | |
download | serd-930f28478ca2573b7f7baf29a57a03cfa95a841f.tar.gz serd-930f28478ca2573b7f7baf29a57a03cfa95a841f.tar.bz2 serd-930f28478ca2573b7f7baf29a57a03cfa95a841f.zip |
Add a set of limits to the world
The idea here is to remove the burden of passing things around like stack
sizes (where most users don't care and will be happy with a reasonably large
default) and keeping the call sites to things like serd_reader_new() clean.
The cost is a bit more state, so it's both more powerful and more potentially
flaky, since changing the limits has action at a distance that isn't clear from
the call site. I think it's worth it for the cleaner API in the common case,
and the much better forward compatibility.
Diffstat (limited to 'test/test_reader_writer.c')
-rw-r--r-- | test/test_reader_writer.c | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/test/test_reader_writer.c b/test/test_reader_writer.c index 3cacd4be..fd9c0d28 100644 --- a/test/test_reader_writer.c +++ b/test/test_reader_writer.c @@ -162,7 +162,7 @@ test_read_nquads_chunks(const char* const path) SerdSink* const sink = serd_sink_new(&rt, test_sink, NULL); assert(sink); - SerdReader* const reader = serd_reader_new(world, SERD_NQUADS, sink, 4096); + SerdReader* const reader = serd_reader_new(world, SERD_NQUADS, sink); assert(reader); SerdStatus st = serd_reader_start_stream( @@ -241,7 +241,7 @@ test_read_turtle_chunks(const char* const path) SerdSink* sink = serd_sink_new(&rt, test_sink, NULL); assert(sink); - SerdReader* reader = serd_reader_new(world, SERD_TURTLE, sink, 4096); + SerdReader* reader = serd_reader_new(world, SERD_TURTLE, sink); assert(reader); SerdStatus st = serd_reader_start_stream( @@ -321,7 +321,7 @@ test_read_string(void) SerdSink* sink = serd_sink_new(&rt, test_sink, NULL); assert(sink); - SerdReader* reader = serd_reader_new(world, SERD_TURTLE, sink, 4096); + SerdReader* reader = serd_reader_new(world, SERD_TURTLE, sink); assert(reader); // Test reading a string that ends exactly at the end of input (no newline) @@ -386,8 +386,8 @@ test_write_errors(void) SerdWriter* const writer = serd_writer_new(world, syntax, 0U, env, faulty_sink, &ctx); - const SerdSink* const sink = serd_writer_sink(writer); - SerdReader* const reader = serd_reader_new(world, SERD_TRIG, sink, 4096U); + const SerdSink* const sink = serd_writer_sink(writer); + SerdReader* const reader = serd_reader_new(world, SERD_TRIG, sink); SerdStatus st = serd_reader_start_string(reader, doc_string, NULL); assert(!st); @@ -513,9 +513,15 @@ test_reader(const char* path) assert(sink); // Test that too little stack space fails gracefully - assert(!serd_reader_new(world, SERD_TURTLE, sink, 32)); - - SerdReader* reader = serd_reader_new(world, SERD_TURTLE, sink, 4096); + const SerdLimits old_limits = serd_world_limits(world); + SerdLimits limits = old_limits; + limits.reader_stack_size = 32U; + serd_world_set_limits(world, limits); + assert(!serd_reader_new(world, SERD_TURTLE, sink)); + + // Restore original limits and successfully create reader + serd_world_set_limits(world, old_limits); + SerdReader* reader = serd_reader_new(world, SERD_TURTLE, sink); assert(reader); assert(serd_reader_read_chunk(reader) == SERD_FAILURE); |