aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2023-12-02 01:20:48 -0500
committerDavid Robillard <d@drobilla.net>2023-12-02 18:49:07 -0500
commit930f28478ca2573b7f7baf29a57a03cfa95a841f (patch)
treeccd9fca0955c8c92e6f3d3cacd032024c1c3d4b7 /src
parent06bc73c6fdf986eb5d13943b497992a947661bb1 (diff)
downloadserd-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 'src')
-rw-r--r--src/reader.c4
-rw-r--r--src/serdi.c5
-rw-r--r--src/world.c19
-rw-r--r--src/world.h1
4 files changed, 25 insertions, 4 deletions
diff --git a/src/reader.c b/src/reader.c
index 61da89ff..4702131e 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -146,9 +146,9 @@ serd_reader_read_document(SerdReader* const reader)
SerdReader*
serd_reader_new(SerdWorld* const world,
const SerdSyntax syntax,
- const SerdSink* const sink,
- const size_t stack_size)
+ const SerdSink* const sink)
{
+ const size_t stack_size = world->limits.reader_stack_size;
if (stack_size < 3 * sizeof(SerdNode) + 192 + serd_node_align) {
return NULL;
}
diff --git a/src/serdi.c b/src/serdi.c
index 0610069d..105bda46 100644
--- a/src/serdi.c
+++ b/src/serdi.c
@@ -245,8 +245,11 @@ main(int argc, char** argv)
SerdWriter* const writer = serd_writer_new(
world, output_syntax, writer_flags, env, (SerdWriteFunc)fwrite, out_fd);
+ const SerdLimits limits = {stack_size};
+ serd_world_set_limits(world, limits);
+
SerdReader* const reader =
- serd_reader_new(world, input_syntax, serd_writer_sink(writer), stack_size);
+ serd_reader_new(world, input_syntax, serd_writer_sink(writer));
serd_reader_set_strict(reader, !lax);
if (quiet) {
diff --git a/src/world.c b/src/world.c
index 21cdffab..7fb5eea2 100644
--- a/src/world.c
+++ b/src/world.c
@@ -16,6 +16,7 @@
# include <fcntl.h>
#endif
+#include <assert.h>
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
@@ -102,7 +103,8 @@ serd_world_new(void)
return NULL;
}
- world->blank_node = blank_node;
+ world->limits.reader_stack_size = 1048576U;
+ world->blank_node = blank_node;
return world;
}
@@ -116,6 +118,21 @@ serd_world_free(SerdWorld* const world)
}
}
+SerdLimits
+serd_world_limits(const SerdWorld* const world)
+{
+ assert(world);
+ return world->limits;
+}
+
+SerdStatus
+serd_world_set_limits(SerdWorld* const world, const SerdLimits limits)
+{
+ assert(world);
+ world->limits = limits;
+ return SERD_SUCCESS;
+}
+
const SerdNode*
serd_world_get_blank(SerdWorld* const world)
{
diff --git a/src/world.h b/src/world.h
index b330d4e4..96252a7a 100644
--- a/src/world.h
+++ b/src/world.h
@@ -13,6 +13,7 @@
#include <stdio.h>
struct SerdWorldImpl {
+ SerdLimits limits;
SerdErrorFunc error_func;
void* error_handle;
uint32_t next_blank_id;