diff options
Diffstat (limited to 'include/serd')
-rw-r--r-- | include/serd/attributes.h | 3 | ||||
-rw-r--r-- | include/serd/reader.h | 16 | ||||
-rw-r--r-- | include/serd/serd.h | 1 | ||||
-rw-r--r-- | include/serd/world.h | 51 | ||||
-rw-r--r-- | include/serd/writer.h | 16 |
5 files changed, 61 insertions, 26 deletions
diff --git a/include/serd/attributes.h b/include/serd/attributes.h index 4e0d68e2..59063153 100644 --- a/include/serd/attributes.h +++ b/include/serd/attributes.h @@ -76,6 +76,9 @@ /// A const function in the public API that is pure and only reads parameters #define SERD_CONST_API SERD_API SERD_CONST_FUNC +/// A malloc function in the public API that returns allocated memory +#define SERD_MALLOC_API SERD_API SERD_MALLOC_FUNC + /** @} */ diff --git a/include/serd/reader.h b/include/serd/reader.h index e67717d7..26641801 100644 --- a/include/serd/reader.h +++ b/include/serd/reader.h @@ -5,12 +5,12 @@ #define SERD_READER_H #include "serd/attributes.h" -#include "serd/error.h" #include "serd/node.h" #include "serd/sink.h" #include "serd/status.h" #include "serd/stream.h" #include "serd/syntax.h" +#include "serd/world.h" #include <stdbool.h> #include <stddef.h> @@ -29,7 +29,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); @@ -44,17 +45,6 @@ SERD_API 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 diff --git a/include/serd/serd.h b/include/serd/serd.h index 03243c76..eb33d329 100644 --- a/include/serd/serd.h +++ b/include/serd/serd.h @@ -20,6 +20,7 @@ #include "serd/attributes.h" #include "serd/version.h" +#include "serd/world.h" /** @} diff --git a/include/serd/world.h b/include/serd/world.h new file mode 100644 index 00000000..22ae57ed --- /dev/null +++ b/include/serd/world.h @@ -0,0 +1,51 @@ +// Copyright 2011-2022 David Robillard <d@drobilla.net> +// SPDX-License-Identifier: ISC + +#ifndef SERD_WORLD_H +#define SERD_WORLD_H + +#include "serd/attributes.h" +#include "serd/error.h" + +SERD_BEGIN_DECLS + +/** + @defgroup serd_world World + @ingroup serd_library + @{ +*/ + +/// Global library state +typedef struct SerdWorldImpl SerdWorld; + +/** + 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); + +/** + @} +*/ + +SERD_END_DECLS + +#endif // SERD_WORLD_H diff --git a/include/serd/writer.h b/include/serd/writer.h index 5f1d0535..77ecac80 100644 --- a/include/serd/writer.h +++ b/include/serd/writer.h @@ -6,12 +6,12 @@ #include "serd/attributes.h" #include "serd/env.h" -#include "serd/error.h" #include "serd/node.h" #include "serd/sink.h" #include "serd/status.h" #include "serd/stream.h" #include "serd/syntax.h" +#include "serd/world.h" #include <stdint.h> @@ -47,7 +47,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, @@ -62,17 +63,6 @@ SERD_CONST_API const SerdSink* SERD_NONNULL serd_writer_sink(SerdWriter* SERD_NONNULL writer); /** - 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 |