diff options
author | David Robillard <d@drobilla.net> | 2021-07-11 20:47:51 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2022-01-13 23:03:46 -0500 |
commit | 71c950bb749c3581ab389edfff9771cb06242e29 (patch) | |
tree | a1437913131978133e48b21078d900859ce30c43 /include | |
parent | 30f3e6fc2c1e24c429d5d0b7100dc449ade6703f (diff) | |
download | serd-71c950bb749c3581ab389edfff9771cb06242e29.tar.gz serd-71c950bb749c3581ab389edfff9771cb06242e29.tar.bz2 serd-71c950bb749c3581ab389edfff9771cb06242e29.zip |
Add SerdWorld for shared library state
Diffstat (limited to 'include')
-rw-r--r-- | include/serd/serd.h | 104 |
1 files changed, 62 insertions, 42 deletions
diff --git a/include/serd/serd.h b/include/serd/serd.h index f09d5e39..778ccc03 100644 --- a/include/serd/serd.h +++ b/include/serd/serd.h @@ -37,9 +37,11 @@ #ifdef __GNUC__ # define SERD_PURE_FUNC __attribute__((pure)) # define SERD_CONST_FUNC __attribute__((const)) +# define SERD_MALLOC_FUNC __attribute__((malloc)) #else # define SERD_PURE_FUNC # define SERD_CONST_FUNC +# define SERD_MALLOC_FUNC #endif #if defined(__clang__) && __clang_major__ >= 7 @@ -60,6 +62,10 @@ SERD_API \ SERD_CONST_FUNC +#define SERD_MALLOC_API \ + SERD_API \ + SERD_MALLOC_FUNC + #ifdef __cplusplus extern "C" { # if defined(__GNUC__) @@ -821,24 +827,12 @@ serd_node_equals(const SerdNode* SERD_NULLABLE a, /** @} - @defgroup serd_event Event Handlers + @defgroup serd_world World @{ */ -/// Flags indicating inline abbreviation information for a statement -typedef enum { - SERD_EMPTY_S = 1u << 1u, ///< Empty blank node subject - SERD_EMPTY_O = 1u << 2u, ///< Empty blank node object - SERD_ANON_S_BEGIN = 1u << 3u, ///< Start of anonymous subject - SERD_ANON_O_BEGIN = 1u << 4u, ///< Start of anonymous object - SERD_ANON_CONT = 1u << 5u, ///< Continuation of anonymous node - SERD_LIST_S_BEGIN = 1u << 6u, ///< Start of list subject - SERD_LIST_O_BEGIN = 1u << 7u, ///< Start of list object - SERD_LIST_CONT = 1u << 8u ///< Continuation of list -} SerdStatementFlag; - -/// Bitwise OR of SerdStatementFlag values -typedef uint32_t SerdStatementFlags; +/// Global library state +typedef struct SerdWorldImpl SerdWorld; /// An error description typedef struct { @@ -860,7 +854,55 @@ typedef SerdStatus (*SerdErrorFunc)(void* SERD_NULLABLE handle, const SerdError* SERD_NONNULL error); /** - Sink function for base URI changes. + Create a new Serd World. + + It is safe to use multiple worlds in one process, though no objects can be + shared between worlds. +*/ +SERD_MALLOC_API +SerdWorld* SERD_ALLOCATED +serd_world_new(void); + +/// Free `world` +SERD_API +void +serd_world_free(SerdWorld* SERD_NULLABLE world); + +/** + Set a function to be called when errors occur. + + The `error_func` will be called with `handle` as its first argument. If + no error function is set, errors are printed to stderr. +*/ +SERD_API +void +serd_world_set_error_func(SerdWorld* SERD_NONNULL world, + SerdErrorFunc SERD_NULLABLE error_func, + void* SERD_NULLABLE handle); + +/** + @} + @defgroup serd_event Event Handlers + @{ +*/ + +/// Flags indicating inline abbreviation information for a statement +typedef enum { + SERD_EMPTY_S = 1u << 1u, ///< Empty blank node subject + SERD_EMPTY_O = 1u << 2u, ///< Empty blank node object + SERD_ANON_S_BEGIN = 1u << 3u, ///< Start of anonymous subject + SERD_ANON_O_BEGIN = 1u << 4u, ///< Start of anonymous object + SERD_ANON_CONT = 1u << 5u, ///< Continuation of anonymous node + SERD_LIST_S_BEGIN = 1u << 6u, ///< Start of list subject + SERD_LIST_O_BEGIN = 1u << 7u, ///< Start of list object + SERD_LIST_CONT = 1u << 8u ///< Continuation of list +} SerdStatementFlag; + +/// Bitwise OR of SerdStatementFlag values +typedef uint32_t SerdStatementFlags; + +/** + Sink function for base URI changes Called whenever the base URI of the serialisation changes. */ @@ -1074,7 +1116,8 @@ typedef struct SerdReaderImpl SerdReader; /// Create a new RDF reader SERD_API SerdReader* SERD_ALLOCATED -serd_reader_new(SerdSyntax syntax, +serd_reader_new(SerdWorld* SERD_NONNULL world, + SerdSyntax syntax, const SerdSink* SERD_NONNULL sink, size_t stack_size); @@ -1090,18 +1133,6 @@ void serd_reader_set_strict(SerdReader* SERD_NONNULL reader, bool strict); /** - Set a function to be called when errors occur during reading. - - The `error_func` will be called with `handle` as its first argument. If - no error function is set, errors are printed to stderr in GCC style. -*/ -SERD_API -void -serd_reader_set_error_sink(SerdReader* SERD_NONNULL reader, - SerdErrorFunc SERD_NULLABLE error_func, - void* SERD_NULLABLE error_handle); - -/** Set a prefix to be added to all blank node identifiers. This is useful when multiple files are to be parsed into the same output (a @@ -1226,7 +1257,8 @@ typedef uint32_t SerdWriterFlags; /// Create a new RDF writer SERD_API SerdWriter* SERD_ALLOCATED -serd_writer_new(SerdSyntax syntax, +serd_writer_new(SerdWorld* SERD_NONNULL world, + SerdSyntax syntax, SerdWriterFlags flags, SerdEnv* SERD_NONNULL env, SerdWriteFunc SERD_NONNULL ssink, @@ -1268,18 +1300,6 @@ char* SERD_NONNULL serd_buffer_sink_finish(SerdBuffer* SERD_NONNULL stream); /** - Set a function to be called when errors occur during writing. - - The `error_func` will be called with `handle` as its first argument. If - no error function is set, errors are printed to stderr. -*/ -SERD_API -void -serd_writer_set_error_sink(SerdWriter* SERD_NONNULL writer, - SerdErrorFunc SERD_NONNULL error_func, - void* SERD_NULLABLE error_handle); - -/** Set a prefix to be removed from matching blank node identifiers. This is the counterpart to serd_reader_add_blank_prefix() which can be used |