diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/serd/buffer.h | 8 | ||||
-rw-r--r-- | include/serd/caret.h | 10 | ||||
-rw-r--r-- | include/serd/cursor.h | 8 | ||||
-rw-r--r-- | include/serd/describe.h | 4 | ||||
-rw-r--r-- | include/serd/env.h | 6 | ||||
-rw-r--r-- | include/serd/memory.h | 128 | ||||
-rw-r--r-- | include/serd/model.h | 10 | ||||
-rw-r--r-- | include/serd/node.h | 10 | ||||
-rw-r--r-- | include/serd/node_syntax.h | 16 | ||||
-rw-r--r-- | include/serd/nodes.h | 4 | ||||
-rw-r--r-- | include/serd/serd.h | 1 | ||||
-rw-r--r-- | include/serd/sink.h | 10 | ||||
-rw-r--r-- | include/serd/statement.h | 8 | ||||
-rw-r--r-- | include/serd/uri.h | 11 | ||||
-rw-r--r-- | include/serd/world.h | 6 |
15 files changed, 56 insertions, 184 deletions
diff --git a/include/serd/buffer.h b/include/serd/buffer.h index a56188e7..b37d5882 100644 --- a/include/serd/buffer.h +++ b/include/serd/buffer.h @@ -5,7 +5,7 @@ #define SERD_BUFFER_H #include "serd/attributes.h" -#include "serd/memory.h" +#include "zix/allocator.h" #include "zix/attributes.h" #include <stddef.h> @@ -26,9 +26,9 @@ SERD_BEGIN_DECLS /// A dynamically resizable mutable buffer in memory typedef struct { - SerdAllocator* ZIX_NULLABLE allocator; ///< Allocator for buf - void* ZIX_NULLABLE buf; ///< Buffer - size_t len; ///< Size of buffer in bytes + ZixAllocator* ZIX_NULLABLE allocator; ///< Allocator for buf + void* ZIX_NULLABLE buf; ///< Buffer + size_t len; ///< Size of buffer in bytes } SerdBuffer; /** diff --git a/include/serd/caret.h b/include/serd/caret.h index 54df0932..a3d20a56 100644 --- a/include/serd/caret.h +++ b/include/serd/caret.h @@ -5,8 +5,8 @@ #define SERD_CARET_H #include "serd/attributes.h" -#include "serd/memory.h" #include "serd/node.h" +#include "zix/allocator.h" #include "zix/attributes.h" #include <stdbool.h> @@ -37,20 +37,20 @@ typedef struct SerdCaretImpl SerdCaret; @return A new caret that must be freed with serd_caret_free() */ SERD_API SerdCaret* ZIX_ALLOCATED -serd_caret_new(SerdAllocator* ZIX_NULLABLE allocator, +serd_caret_new(ZixAllocator* ZIX_NULLABLE allocator, const SerdNode* ZIX_NONNULL document, unsigned line, unsigned column); /// Return a copy of `caret` SERD_API SerdCaret* ZIX_ALLOCATED -serd_caret_copy(SerdAllocator* ZIX_NULLABLE allocator, +serd_caret_copy(ZixAllocator* ZIX_NULLABLE allocator, const SerdCaret* ZIX_NULLABLE caret); /// Free `caret` SERD_API void -serd_caret_free(SerdAllocator* ZIX_NULLABLE allocator, - SerdCaret* ZIX_NULLABLE caret); +serd_caret_free(ZixAllocator* ZIX_NULLABLE allocator, + SerdCaret* ZIX_NULLABLE caret); /// Return true iff `lhs` is equal to `rhs` SERD_PURE_API bool diff --git a/include/serd/cursor.h b/include/serd/cursor.h index eba88ca7..752c1d84 100644 --- a/include/serd/cursor.h +++ b/include/serd/cursor.h @@ -5,9 +5,9 @@ #define SERD_CURSOR_H #include "serd/attributes.h" -#include "serd/memory.h" #include "serd/statement.h" #include "serd/status.h" +#include "zix/allocator.h" #include "zix/attributes.h" #include <stdbool.h> @@ -30,7 +30,7 @@ typedef struct SerdCursorImpl SerdCursor; /// Return a new copy of `cursor` SERD_API SerdCursor* ZIX_ALLOCATED -serd_cursor_copy(SerdAllocator* ZIX_NULLABLE allocator, +serd_cursor_copy(ZixAllocator* ZIX_NULLABLE allocator, const SerdCursor* ZIX_NULLABLE cursor); /// Return the statement pointed to by `cursor` @@ -71,8 +71,8 @@ serd_cursor_equals(const SerdCursor* ZIX_NULLABLE lhs, /// Free `cursor` SERD_API void -serd_cursor_free(SerdAllocator* ZIX_NULLABLE allocator, - SerdCursor* ZIX_NULLABLE cursor); +serd_cursor_free(ZixAllocator* ZIX_NULLABLE allocator, + SerdCursor* ZIX_NULLABLE cursor); /** @} diff --git a/include/serd/describe.h b/include/serd/describe.h index c571aeae..cc78d417 100644 --- a/include/serd/describe.h +++ b/include/serd/describe.h @@ -6,9 +6,9 @@ #include "serd/attributes.h" #include "serd/cursor.h" -#include "serd/memory.h" #include "serd/sink.h" #include "serd/status.h" +#include "zix/allocator.h" #include "zix/attributes.h" #include <stdint.h> @@ -43,7 +43,7 @@ typedef uint32_t SerdDescribeFlags; ugly output for Turtle or Trig. */ SERD_API SerdStatus -serd_describe_range(SerdAllocator* ZIX_NULLABLE allocator, +serd_describe_range(ZixAllocator* ZIX_NULLABLE allocator, const SerdCursor* ZIX_NULLABLE range, const SerdSink* ZIX_NONNULL sink, SerdDescribeFlags flags); diff --git a/include/serd/env.h b/include/serd/env.h index fdcc2190..9ec2ef6a 100644 --- a/include/serd/env.h +++ b/include/serd/env.h @@ -5,10 +5,10 @@ #define SERD_ENV_H #include "serd/attributes.h" -#include "serd/memory.h" #include "serd/node.h" #include "serd/sink.h" #include "serd/status.h" +#include "zix/allocator.h" #include "zix/attributes.h" #include "zix/string_view.h" @@ -27,11 +27,11 @@ typedef struct SerdEnvImpl SerdEnv; /// Create a new environment SERD_API SerdEnv* ZIX_ALLOCATED -serd_env_new(SerdAllocator* ZIX_NULLABLE allocator, ZixStringView base_uri); +serd_env_new(ZixAllocator* ZIX_NULLABLE allocator, ZixStringView base_uri); /// Copy an environment SERD_API SerdEnv* ZIX_ALLOCATED -serd_env_copy(SerdAllocator* ZIX_NULLABLE allocator, +serd_env_copy(ZixAllocator* ZIX_NULLABLE allocator, const SerdEnv* ZIX_NULLABLE env); /// Return true iff `a` is equal to `b` diff --git a/include/serd/memory.h b/include/serd/memory.h deleted file mode 100644 index 4a653349..00000000 --- a/include/serd/memory.h +++ /dev/null @@ -1,128 +0,0 @@ -// Copyright 2011-2022 David Robillard <d@drobilla.net> -// SPDX-License-Identifier: ISC - -#ifndef SERD_MEMORY_H -#define SERD_MEMORY_H - -#include "serd/attributes.h" -#include "zix/attributes.h" - -#include <stddef.h> - -SERD_BEGIN_DECLS - -/** - @defgroup serd_allocator Allocator - @ingroup serd_memory - @{ -*/ - -/** - A memory allocator. - - This object-like structure provides an interface like the standard C - functions malloc(), calloc(), realloc(), free(), and aligned_alloc(). It - contains function pointers that differ from their standard counterparts by - taking a context parameter (a pointer to this struct), which allows the user - to implement custom stateful allocators. -*/ -typedef struct SerdAllocatorImpl SerdAllocator; - -/** - General malloc-like memory allocation function. - - This works like the standard C malloc(), except has an additional handle - parameter for implementing stateful allocators without static data. -*/ -typedef void* ZIX_ALLOCATED (*SerdAllocatorMallocFunc)( // - SerdAllocator* ZIX_NULLABLE allocator, - size_t size); - -/** - General calloc-like memory allocation function. - - This works like the standard C calloc(), except has an additional handle - parameter for implementing stateful allocators without static data. -*/ -typedef void* ZIX_ALLOCATED (*SerdAllocatorCallocFunc)( // - SerdAllocator* ZIX_NULLABLE allocator, - size_t nmemb, - size_t size); - -/** - General realloc-like memory reallocation function. - - This works like the standard C remalloc(), except has an additional handle - parameter for implementing stateful allocators without static data. -*/ -typedef void* ZIX_ALLOCATED (*SerdAllocatorReallocFunc)( // - SerdAllocator* ZIX_NULLABLE allocator, - void* ZIX_NULLABLE ptr, - size_t size); - -/** - General free-like memory deallocation function. - - This works like the standard C remalloc(), except has an additional handle - parameter for implementing stateful allocators without static data. -*/ -typedef void (*SerdAllocatorFreeFunc)( // - SerdAllocator* ZIX_NULLABLE allocator, - void* ZIX_NULLABLE ptr); - -/** - General aligned_alloc-like memory deallocation function. - - This works like the standard C aligned_alloc(), except has an additional - handle parameter for implementing stateful allocators without static data. -*/ -typedef void* ZIX_ALLOCATED (*SerdAllocatorAlignedAllocFunc)( // - SerdAllocator* ZIX_NULLABLE allocator, - size_t alignment, - size_t size); - -/** - General aligned memory deallocation function. - - This works like the standard C free(), but must be used to free memory - allocated with the aligned_alloc() method of the allocator. This allows - portability to systems (like Windows) that can not use the same free function - in these cases. -*/ -typedef void (*SerdAllocatorAlignedFreeFunc)( // - SerdAllocator* ZIX_NULLABLE allocator, - void* ZIX_NULLABLE ptr); - -/// Definition of SerdAllocator -struct SerdAllocatorImpl { - SerdAllocatorMallocFunc ZIX_ALLOCATED malloc; - SerdAllocatorCallocFunc ZIX_ALLOCATED calloc; - SerdAllocatorReallocFunc ZIX_ALLOCATED realloc; - SerdAllocatorFreeFunc ZIX_ALLOCATED free; - SerdAllocatorAlignedAllocFunc ZIX_ALLOCATED aligned_alloc; - SerdAllocatorAlignedFreeFunc ZIX_ALLOCATED aligned_free; -}; - -/// Return the default allocator which simply uses the system allocator -SERD_CONST_API SerdAllocator* ZIX_NONNULL -serd_default_allocator(void); - -/** - Free memory allocated by Serd. - - This function exists because some systems require memory allocated by a - library to be freed by code in the same library. It is otherwise equivalent - to the standard C free() function. - - This may be used to free memory allocated using serd_default_allocator(). -*/ -SERD_API void -serd_free(SerdAllocator* ZIX_NULLABLE allocator, void* ZIX_NULLABLE ptr); - -/** - @} -*/ - -SERD_END_DECLS - -#endif // SERD_MEMORY_H diff --git a/include/serd/model.h b/include/serd/model.h index 24055c9d..fd2620f6 100644 --- a/include/serd/model.h +++ b/include/serd/model.h @@ -7,12 +7,12 @@ #include "serd/attributes.h" #include "serd/caret.h" #include "serd/cursor.h" -#include "serd/memory.h" #include "serd/node.h" #include "serd/nodes.h" #include "serd/statement.h" #include "serd/status.h" #include "serd/world.h" +#include "zix/allocator.h" #include "zix/attributes.h" #include <stdbool.h> @@ -83,7 +83,7 @@ serd_model_new(SerdWorld* ZIX_NONNULL world, /// Return a deep copy of `model` SERD_API SerdModel* ZIX_ALLOCATED -serd_model_copy(SerdAllocator* ZIX_NULLABLE allocator, +serd_model_copy(ZixAllocator* ZIX_NULLABLE allocator, const SerdModel* ZIX_NONNULL model); /// Return true iff `a` is equal to `b`, ignoring statement cursor metadata @@ -145,7 +145,7 @@ serd_model_empty(const SerdModel* ZIX_NONNULL model); @param model The model that the returned cursor points to. */ SERD_API SerdCursor* ZIX_ALLOCATED -serd_model_begin(SerdAllocator* ZIX_NULLABLE allocator, +serd_model_begin(ZixAllocator* ZIX_NULLABLE allocator, const SerdModel* ZIX_NONNULL model); /** @@ -165,7 +165,7 @@ serd_model_end(const SerdModel* ZIX_NONNULL model); @param order The statement order that the returned cursor advances through. */ SERD_API SerdCursor* ZIX_ALLOCATED -serd_model_begin_ordered(SerdAllocator* ZIX_NULLABLE allocator, +serd_model_begin_ordered(ZixAllocator* ZIX_NULLABLE allocator, const SerdModel* ZIX_NONNULL model, SerdStatementOrder order); @@ -181,7 +181,7 @@ serd_model_begin_ordered(SerdAllocator* ZIX_NULLABLE allocator, @return A cursor pointing at the first match, or the end. */ SERD_API SerdCursor* ZIX_NULLABLE -serd_model_find(SerdAllocator* ZIX_NULLABLE allocator, +serd_model_find(ZixAllocator* ZIX_NULLABLE allocator, const SerdModel* ZIX_NONNULL model, const SerdNode* ZIX_NULLABLE s, const SerdNode* ZIX_NULLABLE p, diff --git a/include/serd/node.h b/include/serd/node.h index 31caad88..941be5d1 100644 --- a/include/serd/node.h +++ b/include/serd/node.h @@ -5,10 +5,10 @@ #define SERD_NODE_H #include "serd/attributes.h" -#include "serd/memory.h" #include "serd/uri.h" #include "serd/value.h" #include "serd/write_result.h" +#include "zix/allocator.h" #include "zix/attributes.h" #include "zix/string_view.h" @@ -428,7 +428,7 @@ serd_node_construct(size_t buf_size, void* ZIX_NULLABLE buf, SerdNodeArgs args); null. */ SERD_API SerdNode* ZIX_ALLOCATED -serd_node_new(SerdAllocator* ZIX_NULLABLE allocator, SerdNodeArgs args); +serd_node_new(ZixAllocator* ZIX_NULLABLE allocator, SerdNodeArgs args); /** Return a deep copy of `node`. @@ -437,15 +437,15 @@ serd_node_new(SerdAllocator* ZIX_NULLABLE allocator, SerdNodeArgs args); @param node The node to copyl */ SERD_API SerdNode* ZIX_ALLOCATED -serd_node_copy(SerdAllocator* ZIX_NULLABLE allocator, +serd_node_copy(ZixAllocator* ZIX_NULLABLE allocator, const SerdNode* ZIX_NULLABLE node); /** Free any data owned by `node`. */ SERD_API void -serd_node_free(SerdAllocator* ZIX_NULLABLE allocator, - SerdNode* ZIX_NULLABLE node); +serd_node_free(ZixAllocator* ZIX_NULLABLE allocator, + SerdNode* ZIX_NULLABLE node); /** @} diff --git a/include/serd/node_syntax.h b/include/serd/node_syntax.h index 7529c954..2567be03 100644 --- a/include/serd/node_syntax.h +++ b/include/serd/node_syntax.h @@ -6,9 +6,9 @@ #include "serd/attributes.h" #include "serd/env.h" -#include "serd/memory.h" #include "serd/node.h" #include "serd/syntax.h" +#include "zix/allocator.h" #include "zix/attributes.h" SERD_BEGIN_DECLS @@ -43,10 +43,10 @@ SERD_BEGIN_DECLS using the world allocator. */ SERD_API SerdNode* ZIX_ALLOCATED -serd_node_from_syntax(SerdAllocator* ZIX_NULLABLE allocator, - const char* ZIX_NONNULL str, - SerdSyntax syntax, - SerdEnv* ZIX_NULLABLE env); +serd_node_from_syntax(ZixAllocator* ZIX_NULLABLE allocator, + const char* ZIX_NONNULL str, + SerdSyntax syntax, + SerdEnv* ZIX_NULLABLE env); /** Return a string representation of `node` in `syntax`. @@ -66,11 +66,11 @@ serd_node_from_syntax(SerdAllocator* ZIX_NULLABLE allocator, @param env Environment for the output string. This can be used to abbreviate things nicely by setting namespace prefixes. - @return A newly allocated string that must be freed with serd_free() using - the world allocator. + @return A newly allocated string that must be freed with zix_free() using + the same `allocator`. */ SERD_API char* ZIX_ALLOCATED -serd_node_to_syntax(SerdAllocator* ZIX_NULLABLE allocator, +serd_node_to_syntax(ZixAllocator* ZIX_NULLABLE allocator, const SerdNode* ZIX_NONNULL node, SerdSyntax syntax, const SerdEnv* ZIX_NULLABLE env); diff --git a/include/serd/nodes.h b/include/serd/nodes.h index c23fe024..d466c326 100644 --- a/include/serd/nodes.h +++ b/include/serd/nodes.h @@ -5,8 +5,8 @@ #define SERD_NODES_H #include "serd/attributes.h" -#include "serd/memory.h" #include "serd/node.h" +#include "zix/allocator.h" #include "zix/attributes.h" #include <stddef.h> @@ -24,7 +24,7 @@ typedef struct SerdNodesImpl SerdNodes; /// Create a new node set SERD_API SerdNodes* ZIX_ALLOCATED -serd_nodes_new(SerdAllocator* ZIX_NULLABLE allocator); +serd_nodes_new(ZixAllocator* ZIX_NULLABLE allocator); /** Free `nodes` and all nodes that are stored in it. diff --git a/include/serd/serd.h b/include/serd/serd.h index 2814ed00..6ddf2c79 100644 --- a/include/serd/serd.h +++ b/include/serd/serd.h @@ -38,7 +38,6 @@ */ #include "serd/buffer.h" -#include "serd/memory.h" /** @} diff --git a/include/serd/sink.h b/include/serd/sink.h index e34ce941..a0e7eee5 100644 --- a/include/serd/sink.h +++ b/include/serd/sink.h @@ -6,10 +6,10 @@ #include "serd/attributes.h" #include "serd/event.h" -#include "serd/memory.h" #include "serd/node.h" #include "serd/statement.h" #include "serd/status.h" +#include "zix/allocator.h" #include "zix/attributes.h" SERD_BEGIN_DECLS @@ -72,10 +72,10 @@ typedef void (*SerdFreeFunc)(void* ZIX_NULLABLE ptr); @param free_handle Free function to call on handle in serd_sink_free(). */ SERD_API SerdSink* ZIX_ALLOCATED -serd_sink_new(SerdAllocator* ZIX_NULLABLE allocator, - void* ZIX_NULLABLE handle, - SerdEventFunc ZIX_NULLABLE event_func, - SerdFreeFunc ZIX_NULLABLE free_handle); +serd_sink_new(ZixAllocator* ZIX_NULLABLE allocator, + void* ZIX_NULLABLE handle, + SerdEventFunc ZIX_NULLABLE event_func, + SerdFreeFunc ZIX_NULLABLE free_handle); /// Free `sink` SERD_API void diff --git a/include/serd/statement.h b/include/serd/statement.h index 03d7ae6d..afdffae9 100644 --- a/include/serd/statement.h +++ b/include/serd/statement.h @@ -6,8 +6,8 @@ #include "serd/attributes.h" #include "serd/caret.h" -#include "serd/memory.h" #include "serd/node.h" +#include "zix/allocator.h" #include "zix/attributes.h" #include <stdbool.h> @@ -65,7 +65,7 @@ typedef struct SerdStatementImpl SerdStatement; @return A new statement that must be freed with serd_statement_free() */ SERD_API SerdStatement* ZIX_ALLOCATED -serd_statement_new(SerdAllocator* ZIX_NULLABLE allocator, +serd_statement_new(ZixAllocator* ZIX_NULLABLE allocator, const SerdNode* ZIX_NONNULL s, const SerdNode* ZIX_NONNULL p, const SerdNode* ZIX_NONNULL o, @@ -74,12 +74,12 @@ serd_statement_new(SerdAllocator* ZIX_NULLABLE allocator, /// Return a copy of `statement` SERD_API SerdStatement* ZIX_ALLOCATED -serd_statement_copy(SerdAllocator* ZIX_NULLABLE allocator, +serd_statement_copy(ZixAllocator* ZIX_NULLABLE allocator, const SerdStatement* ZIX_NULLABLE statement); /// Free `statement` SERD_API void -serd_statement_free(SerdAllocator* ZIX_NULLABLE allocator, +serd_statement_free(ZixAllocator* ZIX_NULLABLE allocator, SerdStatement* ZIX_NULLABLE statement); /// Return the given node of the statement diff --git a/include/serd/uri.h b/include/serd/uri.h index efdf68aa..ef00351c 100644 --- a/include/serd/uri.h +++ b/include/serd/uri.h @@ -5,8 +5,8 @@ #define SERD_URI_H #include "serd/attributes.h" -#include "serd/memory.h" #include "serd/stream.h" +#include "zix/allocator.h" #include "zix/attributes.h" #include "zix/string_view.h" @@ -54,16 +54,17 @@ static const SerdURIView SERD_URI_NULL = /** Get the unescaped path and hostname from a file URI. - The returned path and `*hostname` must be freed with serd_free(). + Both the returned path and `*hostname` must be freed with zix_free() using + the same allocator. @param allocator Allocator for the returned string. @param uri A file URI. - @param hostname If non-NULL, set to the hostname, if present. + @param hostname If non-NULL, set to the newly allocated hostname, if present. - @return A newly allocated path string that must be freed with serd_free(). + @return A newly allocated path string. */ SERD_API char* ZIX_ALLOCATED -serd_parse_file_uri(SerdAllocator* ZIX_NULLABLE allocator, +serd_parse_file_uri(ZixAllocator* ZIX_NULLABLE allocator, const char* ZIX_NONNULL uri, char* ZIX_NONNULL* ZIX_NULLABLE hostname); diff --git a/include/serd/world.h b/include/serd/world.h index fb0930aa..a5dfe183 100644 --- a/include/serd/world.h +++ b/include/serd/world.h @@ -5,10 +5,10 @@ #define SERD_WORLD_H #include "serd/attributes.h" -#include "serd/memory.h" #include "serd/node.h" #include "serd/nodes.h" #include "serd/status.h" +#include "zix/allocator.h" #include "zix/attributes.h" #include <stddef.h> @@ -37,14 +37,14 @@ typedef struct { shared between worlds. */ SERD_MALLOC_API SerdWorld* ZIX_ALLOCATED -serd_world_new(SerdAllocator* ZIX_NULLABLE allocator); +serd_world_new(ZixAllocator* ZIX_NULLABLE allocator); /// Free `world` SERD_API void serd_world_free(SerdWorld* ZIX_NULLABLE world); /// Return the allocator used by `world` -SERD_PURE_API SerdAllocator* ZIX_NONNULL +SERD_PURE_API ZixAllocator* ZIX_NONNULL serd_world_allocator(const SerdWorld* ZIX_NONNULL world); /** |