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 /include | |
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 'include')
-rw-r--r-- | include/serd/reader.h | 3 | ||||
-rw-r--r-- | include/serd/world.h | 29 |
2 files changed, 30 insertions, 2 deletions
diff --git a/include/serd/reader.h b/include/serd/reader.h index cc19a9b8..a2b2698d 100644 --- a/include/serd/reader.h +++ b/include/serd/reader.h @@ -31,8 +31,7 @@ typedef struct SerdReaderImpl SerdReader; SERD_API SerdReader* SERD_ALLOCATED serd_reader_new(SerdWorld* SERD_NONNULL world, SerdSyntax syntax, - const SerdSink* SERD_NONNULL sink, - size_t stack_size); + const SerdSink* SERD_NONNULL sink); /** Enable or disable strict parsing. diff --git a/include/serd/world.h b/include/serd/world.h index abf2999c..fe381628 100644 --- a/include/serd/world.h +++ b/include/serd/world.h @@ -7,6 +7,9 @@ #include "serd/attributes.h" #include "serd/error.h" #include "serd/node.h" +#include "serd/status.h" + +#include <stddef.h> SERD_BEGIN_DECLS @@ -19,6 +22,11 @@ SERD_BEGIN_DECLS /// Global library state typedef struct SerdWorldImpl SerdWorld; +/// Resource limits to control allocation +typedef struct { + size_t reader_stack_size; +} SerdLimits; + /** Create a new Serd World. @@ -33,6 +41,27 @@ SERD_API void serd_world_free(SerdWorld* SERD_NULLABLE world); /** + Return the current resource limits. + + These determine how much memory is allocated for reading and writing (where + the required stack space depends on the input data. The defaults use about + a megabyte and over 100 levels of nesting, which is more than enough for + most data. +*/ +SERD_API SerdLimits +serd_world_limits(const SerdWorld* SERD_NONNULL world); + +/** + Set the current resource limits. + + This updates the "current" limits, that is, those that will be used after + this call. It can be used to configure allocation sizes before calling some + other function like serd_reader_new() that uses the current limits. +*/ +SERD_API SerdStatus +serd_world_set_limits(SerdWorld* SERD_NONNULL world, SerdLimits limits); + +/** Return a unique blank node. The returned node is valid only until the next time serd_world_get_blank() |