aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2022-12-19 17:55:02 -0500
committerDavid Robillard <d@drobilla.net>2023-12-02 18:49:08 -0500
commit0f9816d67bc67a396607291f845ca2a33c2285a7 (patch)
treeb31fd1b344305dc984a2109084fa183573a0ae43
parent258ea2ff59bbd2127ea446cf4b9676ad3d7fe53d (diff)
downloadserd-0f9816d67bc67a396607291f845ca2a33c2285a7.tar.gz
serd-0f9816d67bc67a396607291f845ca2a33c2285a7.tar.bz2
serd-0f9816d67bc67a396607291f845ca2a33c2285a7.zip
Use ZixAllocator directly
-rw-r--r--doc/conf.py.in2
-rw-r--r--include/serd/buffer.h8
-rw-r--r--include/serd/caret.h10
-rw-r--r--include/serd/cursor.h8
-rw-r--r--include/serd/describe.h4
-rw-r--r--include/serd/env.h6
-rw-r--r--include/serd/memory.h128
-rw-r--r--include/serd/model.h10
-rw-r--r--include/serd/node.h10
-rw-r--r--include/serd/node_syntax.h16
-rw-r--r--include/serd/nodes.h4
-rw-r--r--include/serd/serd.h1
-rw-r--r--include/serd/sink.h10
-rw-r--r--include/serd/statement.h8
-rw-r--r--include/serd/uri.h11
-rw-r--r--include/serd/world.h6
-rw-r--r--meson.build2
-rw-r--r--src/block_dumper.c4
-rw-r--r--src/block_dumper.h4
-rw-r--r--src/buffer.c5
-rw-r--r--src/byte_source.c18
-rw-r--r--src/byte_source.h6
-rw-r--r--src/canon.c8
-rw-r--r--src/caret.c18
-rw-r--r--src/cursor.c11
-rw-r--r--src/describe.c7
-rw-r--r--src/env.c32
-rw-r--r--src/filter.c25
-rw-r--r--src/memory.c17
-rw-r--r--src/memory.h97
-rw-r--r--src/model.c19
-rw-r--r--src/model.h4
-rw-r--r--src/node.c29
-rw-r--r--src/node.h10
-rw-r--r--src/node_syntax.c18
-rw-r--r--src/nodes.c44
-rw-r--r--src/reader.c2
-rw-r--r--src/sink.c14
-rw-r--r--src/sink.h10
-rw-r--r--src/stack.h13
-rw-r--r--src/statement.c23
-rw-r--r--src/string.c8
-rw-r--r--src/uri.c19
-rw-r--r--src/world.c20
-rw-r--r--src/world.h4
-rw-r--r--src/writer.c5
-rw-r--r--test/failing_allocator.c37
-rw-r--r--test/failing_allocator.h8
-rw-r--r--test/test_caret.c4
-rw-r--r--test/test_free_null.c2
-rw-r--r--test/test_model.c36
-rw-r--r--test/test_node_syntax.c10
-rw-r--r--test/test_nodes.c44
-rw-r--r--test/test_overflow.c11
-rw-r--r--test/test_reader_writer.c3
-rw-r--r--test/test_statement.c18
-rw-r--r--test/test_terse_write.c14
-rw-r--r--test/test_uri.c20
-rw-r--r--test/test_writer.c14
-rw-r--r--tools/console.c9
-rw-r--r--tools/console.h10
-rw-r--r--tools/serd-filter.c14
62 files changed, 373 insertions, 619 deletions
diff --git a/doc/conf.py.in b/doc/conf.py.in
index b72d0882..24dede6f 100644
--- a/doc/conf.py.in
+++ b/doc/conf.py.in
@@ -27,7 +27,6 @@ except ModuleNotFoundError:
# Ignore everything opaque or external for nitpicky mode
_opaque = [
"FILE",
- "SerdAllocatorImpl",
"SerdCaretImpl",
"SerdCursorImpl",
"SerdEnvImpl",
@@ -39,6 +38,7 @@ _opaque = [
"SerdStatementImpl",
"SerdWorldImpl",
"SerdWriterImpl",
+ "ZixAllocator",
"ZixStringView",
"int16_t",
"int32_t",
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);
/**
diff --git a/meson.build b/meson.build
index fe582fd5..e58436a2 100644
--- a/meson.build
+++ b/meson.build
@@ -139,7 +139,6 @@ c_headers = files(
'include/serd/input_stream.h',
'include/serd/inserter.h',
'include/serd/log.h',
- 'include/serd/memory.h',
'include/serd/model.h',
'include/serd/node.h',
'include/serd/node_syntax.h',
@@ -175,7 +174,6 @@ sources = files(
'src/input_stream.c',
'src/inserter.c',
'src/log.c',
- 'src/memory.c',
'src/model.c',
'src/node.c',
'src/node_syntax.c',
diff --git a/src/block_dumper.c b/src/block_dumper.c
index 21a10fcc..837b37e9 100644
--- a/src/block_dumper.c
+++ b/src/block_dumper.c
@@ -6,6 +6,8 @@
#include "memory.h"
#include "system.h"
+#include "zix/allocator.h"
+
#include <stddef.h>
SerdStatus
@@ -53,5 +55,5 @@ serd_block_dumper_flush(SerdBlockDumper* const dumper)
void
serd_block_dumper_close(SerdBlockDumper* const dumper)
{
- serd_aaligned_free(dumper->allocator, dumper->buf);
+ zix_aligned_free(dumper->allocator, dumper->buf);
}
diff --git a/src/block_dumper.h b/src/block_dumper.h
index e5a2c318..038f0a82 100644
--- a/src/block_dumper.h
+++ b/src/block_dumper.h
@@ -4,17 +4,17 @@
#ifndef SERD_SRC_BLOCK_DUMPER_H
#define SERD_SRC_BLOCK_DUMPER_H
-#include "serd/memory.h"
#include "serd/output_stream.h"
#include "serd/status.h"
#include "serd/world.h"
+#include "zix/allocator.h"
#include "zix/attributes.h"
#include <stddef.h>
#include <string.h>
typedef struct {
- SerdAllocator* ZIX_NONNULL allocator; ///< Buffer allocator
+ ZixAllocator* ZIX_NONNULL allocator; ///< Buffer allocator
SerdOutputStream* ZIX_ALLOCATED out; ///< Output stream to write to
char* ZIX_ALLOCATED buf; ///< Local buffer if needed
diff --git a/src/buffer.c b/src/buffer.c
index c16a0ad6..64510d43 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -1,9 +1,8 @@
// Copyright 2011-2021 David Robillard <d@drobilla.net>
// SPDX-License-Identifier: ISC
-#include "memory.h"
-
#include "serd/buffer.h"
+#include "zix/allocator.h"
#include <assert.h>
#include <stddef.h>
@@ -22,7 +21,7 @@ serd_buffer_write(const void* const buf,
const size_t n_bytes = size * nmemb;
char* const new_buf =
- (char*)serd_arealloc(buffer->allocator, buffer->buf, buffer->len + n_bytes);
+ (char*)zix_realloc(buffer->allocator, buffer->buf, buffer->len + n_bytes);
if (new_buf) {
memcpy(new_buf + buffer->len, buf, n_bytes);
diff --git a/src/byte_source.c b/src/byte_source.c
index 249c0dde..6ec2084a 100644
--- a/src/byte_source.c
+++ b/src/byte_source.c
@@ -3,10 +3,10 @@
#include "byte_source.h"
-#include "memory.h"
#include "system.h"
#include "serd/node.h"
+#include "zix/allocator.h"
#include <assert.h>
#include <stdbool.h>
@@ -39,11 +39,11 @@ serd_byte_source_page(SerdByteSource* const source)
}
static void
-serd_byte_source_init_buffer(SerdAllocator* const allocator,
+serd_byte_source_init_buffer(ZixAllocator* const allocator,
SerdByteSource* const source)
{
if (source->block_size > 1) {
- source->block = (uint8_t*)serd_aaligned_alloc(
+ source->block = (uint8_t*)zix_aligned_alloc(
allocator, SERD_PAGE_SIZE, source->block_size);
if ((source->read_buf = source->block)) {
@@ -55,7 +55,7 @@ serd_byte_source_init_buffer(SerdAllocator* const allocator,
}
SerdByteSource*
-serd_byte_source_new_input(SerdAllocator* const allocator,
+serd_byte_source_new_input(ZixAllocator* const allocator,
SerdInputStream* const input,
const SerdNode* const name,
const size_t block_size)
@@ -73,7 +73,7 @@ serd_byte_source_new_input(SerdAllocator* const allocator,
}
SerdByteSource* source =
- (SerdByteSource*)serd_acalloc(allocator, 1, sizeof(SerdByteSource));
+ (SerdByteSource*)zix_calloc(allocator, 1, sizeof(SerdByteSource));
if (!source) {
serd_node_free(allocator, source_name);
@@ -91,7 +91,7 @@ serd_byte_source_new_input(SerdAllocator* const allocator,
serd_byte_source_init_buffer(allocator, source);
if (block_size > 1 && !source->block) {
serd_node_free(allocator, source_name);
- serd_afree(allocator, source);
+ zix_free(allocator, source);
return NULL;
}
@@ -99,16 +99,16 @@ serd_byte_source_new_input(SerdAllocator* const allocator,
}
void
-serd_byte_source_free(SerdAllocator* const allocator,
+serd_byte_source_free(ZixAllocator* const allocator,
SerdByteSource* const source)
{
if (source) {
if (source->block_size > 1) {
- serd_aaligned_free(allocator, source->block);
+ zix_aligned_free(allocator, source->block);
}
serd_node_free(allocator, source->name);
- serd_afree(allocator, source);
+ zix_free(allocator, source);
}
}
diff --git a/src/byte_source.h b/src/byte_source.h
index ba63e794..ced36b82 100644
--- a/src/byte_source.h
+++ b/src/byte_source.h
@@ -8,9 +8,9 @@
#include "serd/caret.h"
#include "serd/input_stream.h"
-#include "serd/memory.h"
#include "serd/node.h"
#include "serd/status.h"
+#include "zix/allocator.h"
#include "zix/attributes.h"
#include <assert.h>
@@ -33,13 +33,13 @@ typedef struct {
} SerdByteSource;
SerdByteSource*
-serd_byte_source_new_input(SerdAllocator* allocator,
+serd_byte_source_new_input(ZixAllocator* allocator,
SerdInputStream* input,
const SerdNode* name,
size_t block_size);
void
-serd_byte_source_free(SerdAllocator* allocator, SerdByteSource* source);
+serd_byte_source_free(ZixAllocator* allocator, SerdByteSource* source);
SerdStatus
serd_byte_source_prepare(SerdByteSource* source);
diff --git a/src/canon.c b/src/canon.c
index 2ef28e07..718b1a83 100644
--- a/src/canon.c
+++ b/src/canon.c
@@ -13,12 +13,12 @@
#include "serd/caret.h"
#include "serd/event.h"
#include "serd/log.h"
-#include "serd/memory.h"
#include "serd/node.h"
#include "serd/sink.h"
#include "serd/statement.h"
#include "serd/status.h"
#include "serd/world.h"
+#include "zix/allocator.h"
#include "zix/attributes.h"
#include "zix/string_view.h"
@@ -34,7 +34,7 @@ typedef struct {
} SerdCanonData;
static ExessResult
-build_typed(SerdAllocator* const ZIX_NONNULL allocator,
+build_typed(ZixAllocator* const ZIX_NONNULL allocator,
SerdNode** const out,
const SerdNode* const ZIX_NONNULL node,
const SerdNode* const ZIX_NONNULL datatype)
@@ -91,7 +91,7 @@ build_typed(SerdAllocator* const ZIX_NONNULL allocator,
}
static ExessResult
-build_tagged(SerdAllocator* const ZIX_NONNULL allocator,
+build_tagged(ZixAllocator* const ZIX_NONNULL allocator,
SerdNode** const out,
const SerdNode* const ZIX_NONNULL node,
const SerdNode* const ZIX_NONNULL language)
@@ -129,7 +129,7 @@ serd_canon_on_statement(SerdCanonData* const data,
const SerdStatementFlags flags,
const SerdStatement* const statement)
{
- SerdAllocator* const allocator = serd_world_allocator(data->world);
+ ZixAllocator* const allocator = serd_world_allocator(data->world);
const SerdNode* const object = serd_statement_object(statement);
const SerdNode* const datatype = serd_node_datatype(object);
const SerdNode* const language = serd_node_language(object);
diff --git a/src/caret.c b/src/caret.c
index 2d7e9a8e..e7ff58fa 100644
--- a/src/caret.c
+++ b/src/caret.c
@@ -3,10 +3,8 @@
#include "caret.h"
-#include "memory.h"
-
#include "serd/caret.h"
-#include "serd/memory.h"
+#include "zix/allocator.h"
#include <assert.h>
#include <stdbool.h>
@@ -14,15 +12,14 @@
#include <string.h>
SerdCaret*
-serd_caret_new(SerdAllocator* const allocator,
+serd_caret_new(ZixAllocator* const allocator,
const SerdNode* const document,
const unsigned line,
const unsigned column)
{
assert(document);
- SerdCaret* const caret =
- (SerdCaret*)serd_amalloc(allocator, sizeof(SerdCaret));
+ SerdCaret* const caret = (SerdCaret*)zix_malloc(allocator, sizeof(SerdCaret));
if (caret) {
caret->document = document;
@@ -34,14 +31,13 @@ serd_caret_new(SerdAllocator* const allocator,
}
SerdCaret*
-serd_caret_copy(SerdAllocator* const allocator, const SerdCaret* const caret)
+serd_caret_copy(ZixAllocator* const allocator, const SerdCaret* const caret)
{
if (!caret) {
return NULL;
}
- SerdCaret* const copy =
- (SerdCaret*)serd_amalloc(allocator, sizeof(SerdCaret));
+ SerdCaret* const copy = (SerdCaret*)zix_malloc(allocator, sizeof(SerdCaret));
if (copy) {
memcpy(copy, caret, sizeof(SerdCaret));
@@ -51,9 +47,9 @@ serd_caret_copy(SerdAllocator* const allocator, const SerdCaret* const caret)
}
void
-serd_caret_free(SerdAllocator* const allocator, SerdCaret* const caret)
+serd_caret_free(ZixAllocator* const allocator, SerdCaret* const caret)
{
- serd_afree(allocator, caret);
+ zix_free(allocator, caret);
}
bool
diff --git a/src/cursor.c b/src/cursor.c
index d6a86d19..b3183ae9 100644
--- a/src/cursor.c
+++ b/src/cursor.c
@@ -3,14 +3,13 @@
#include "cursor.h"
-#include "memory.h"
#include "model.h"
#include "node.h"
#include "statement.h"
#include "serd/log.h"
-#include "serd/memory.h"
#include "serd/statement.h"
+#include "zix/allocator.h"
#include "zix/attributes.h"
#include "zix/btree.h"
#include "zix/status.h"
@@ -122,14 +121,14 @@ serd_cursor_make(const SerdModel* const model,
}
SerdCursor*
-serd_cursor_copy(SerdAllocator* const allocator, const SerdCursor* const cursor)
+serd_cursor_copy(ZixAllocator* const allocator, const SerdCursor* const cursor)
{
if (!cursor) {
return NULL;
}
SerdCursor* const copy =
- (SerdCursor* const)serd_amalloc(allocator, sizeof(SerdCursor));
+ (SerdCursor* const)zix_malloc(allocator, sizeof(SerdCursor));
if (copy) {
memcpy(copy, cursor, sizeof(SerdCursor));
@@ -218,7 +217,7 @@ serd_cursor_equals(const SerdCursor* const lhs, const SerdCursor* const rhs)
}
void
-serd_cursor_free(SerdAllocator* const allocator, SerdCursor* const cursor)
+serd_cursor_free(ZixAllocator* const allocator, SerdCursor* const cursor)
{
- serd_afree(allocator, cursor);
+ zix_free(allocator, cursor);
}
diff --git a/src/describe.c b/src/describe.c
index a7012cf9..41d5b67a 100644
--- a/src/describe.c
+++ b/src/describe.c
@@ -11,7 +11,6 @@
#include "serd/cursor.h"
#include "serd/describe.h"
-#include "serd/memory.h"
#include "serd/model.h"
#include "serd/node.h"
#include "serd/sink.h"
@@ -31,7 +30,7 @@
typedef enum { NAMED, ANON_S, ANON_O, LIST_S, LIST_O } NodeStyle;
typedef struct {
- SerdAllocator* allocator; // Allocator for auxiliary structures
+ ZixAllocator* allocator; // Allocator for auxiliary structures
const SerdModel* model; // Model to read from
const SerdSink* sink; // Sink to write description to
ZixHash* list_subjects; // Nodes written in the current list or null
@@ -286,7 +285,7 @@ write_range_statement(const DescribeContext* const ctx,
}
SerdStatus
-serd_describe_range(SerdAllocator* const allocator,
+serd_describe_range(ZixAllocator* const allocator,
const SerdCursor* const range,
const SerdSink* sink,
const SerdDescribeFlags flags)
@@ -300,7 +299,7 @@ serd_describe_range(SerdAllocator* const allocator,
SerdCursor copy = *range;
ZixHash* const list_subjects =
- zix_hash_new((ZixAllocator*)allocator, identity, ptr_hash, ptr_equals);
+ zix_hash_new(allocator, identity, ptr_hash, ptr_equals);
SerdStatus st = SERD_BAD_ALLOC;
if (list_subjects) {
diff --git a/src/env.c b/src/env.c
index d17910f9..a63f2126 100644
--- a/src/env.c
+++ b/src/env.c
@@ -4,7 +4,6 @@
#include "serd/env.h"
#include "env.h"
-#include "memory.h"
#include "node.h"
#include "serd/node.h"
@@ -25,7 +24,7 @@ typedef struct {
} SerdPrefix;
struct SerdEnvImpl {
- SerdAllocator* allocator;
+ ZixAllocator* allocator;
SerdNodes* nodes;
SerdPrefix* prefixes;
size_t n_prefixes;
@@ -34,22 +33,21 @@ struct SerdEnvImpl {
};
SerdEnv*
-serd_env_new(SerdAllocator* const allocator, const ZixStringView base_uri)
+serd_env_new(ZixAllocator* const allocator, const ZixStringView base_uri)
{
- SerdEnv* env =
- (SerdEnv*)serd_acalloc(allocator, 1, sizeof(struct SerdEnvImpl));
+ SerdEnv* env = (SerdEnv*)zix_calloc(allocator, 1, sizeof(struct SerdEnvImpl));
if (env) {
env->allocator = allocator;
if (!(env->nodes = serd_nodes_new(allocator))) {
- serd_afree(allocator, env);
+ zix_free(allocator, env);
return NULL;
}
if (base_uri.length) {
if (serd_env_set_base_uri(env, base_uri)) {
serd_nodes_free(env->nodes);
- serd_afree(allocator, env);
+ zix_free(allocator, env);
return NULL;
}
}
@@ -59,13 +57,13 @@ serd_env_new(SerdAllocator* const allocator, const ZixStringView base_uri)
}
SerdEnv*
-serd_env_copy(SerdAllocator* const allocator, const SerdEnv* const env)
+serd_env_copy(ZixAllocator* const allocator, const SerdEnv* const env)
{
if (!env) {
return NULL;
}
- SerdEnv* const copy = (SerdEnv*)serd_acalloc(allocator, 1, sizeof(SerdEnv));
+ SerdEnv* const copy = (SerdEnv*)zix_calloc(allocator, 1, sizeof(SerdEnv));
if (copy) {
copy->allocator = allocator;
copy->n_prefixes = env->n_prefixes;
@@ -73,7 +71,7 @@ serd_env_copy(SerdAllocator* const allocator, const SerdEnv* const env)
// Allocate structure and set base URI
const SerdNode* const base = serd_env_base_uri(env);
if (!(copy->nodes = serd_nodes_new(allocator)) ||
- !(copy->prefixes = (SerdPrefix*)serd_acalloc(
+ !(copy->prefixes = (SerdPrefix*)zix_calloc(
allocator, copy->n_prefixes, sizeof(SerdPrefix))) ||
(base && serd_env_set_base_uri(copy, serd_node_string_view(base)))) {
serd_env_free(copy);
@@ -98,9 +96,9 @@ void
serd_env_free(SerdEnv* const env)
{
if (env) {
- serd_afree(env->allocator, env->prefixes);
+ zix_free(env->allocator, env->prefixes);
serd_nodes_free(env->nodes);
- serd_afree(env->allocator, env);
+ zix_free(env->allocator, env);
}
}
@@ -187,7 +185,7 @@ serd_env_set_base_path(SerdEnv* const env, const ZixStringView path)
const char path_last = path.data[path.length - 1];
if (path_last == '/' || path_last == '\\') {
char* const base_path =
- (char*)serd_acalloc(env->allocator, real_path_len + 2, 1);
+ (char*)zix_calloc(env->allocator, real_path_len + 2, 1);
memcpy(base_path, real_path, real_path_len + 1);
base_path[real_path_len] = path_last;
@@ -195,7 +193,7 @@ serd_env_set_base_path(SerdEnv* const env, const ZixStringView path)
base_node = serd_node_new(
NULL, serd_a_file_uri(zix_string(base_path), zix_empty_string()));
- serd_afree(env->allocator, base_path);
+ zix_free(env->allocator, base_path);
} else {
base_node = serd_node_new(
NULL, serd_a_file_uri(zix_string(real_path), zix_empty_string()));
@@ -259,9 +257,9 @@ serd_env_add(SerdEnv* const env,
}
SerdPrefix* const new_prefixes =
- (SerdPrefix*)serd_arealloc(env->allocator,
- env->prefixes,
- (env->n_prefixes + 1) * sizeof(SerdPrefix));
+ (SerdPrefix*)zix_realloc(env->allocator,
+ env->prefixes,
+ (env->n_prefixes + 1) * sizeof(SerdPrefix));
if (!new_prefixes) {
return SERD_BAD_ALLOC;
diff --git a/src/filter.c b/src/filter.c
index 581a7b72..dc6ef152 100644
--- a/src/filter.c
+++ b/src/filter.c
@@ -3,13 +3,12 @@
#include "serd/filter.h"
+#include "sink.h"
+
#include "serd/event.h"
-#include "serd/memory.h"
#include "serd/statement.h"
#include "serd/status.h"
-
-#include "memory.h"
-#include "sink.h"
+#include "zix/allocator.h"
#include <assert.h>
#include <stdbool.h>
@@ -29,13 +28,13 @@ free_data(void* const handle)
{
if (handle) {
SerdFilterData* const data = (SerdFilterData*)handle;
- SerdAllocator* const allocator = data->target->allocator;
+ ZixAllocator* const allocator = data->target->allocator;
serd_node_free(allocator, data->subject);
serd_node_free(allocator, data->predicate);
serd_node_free(allocator, data->object);
serd_node_free(allocator, data->graph);
- serd_afree(allocator, data);
+ zix_free(allocator, data);
}
}
@@ -77,9 +76,9 @@ serd_filter_new(const SerdWorld* const world,
assert(world);
assert(target);
- SerdAllocator* const allocator = serd_world_allocator(world);
+ ZixAllocator* const alloc = serd_world_allocator(world);
SerdFilterData* const data =
- (SerdFilterData*)serd_wcalloc(world, 1, sizeof(SerdFilterData));
+ (SerdFilterData*)zix_calloc(alloc, 1, sizeof(SerdFilterData));
if (!data) {
return NULL;
@@ -89,35 +88,35 @@ serd_filter_new(const SerdWorld* const world,
data->inclusive = inclusive;
if (subject && serd_node_type(subject) != SERD_VARIABLE) {
- if (!(data->subject = serd_node_copy(allocator, subject))) {
+ if (!(data->subject = serd_node_copy(alloc, subject))) {
free_data(data);
return NULL;
}
}
if (predicate && serd_node_type(predicate) != SERD_VARIABLE) {
- if (!(data->predicate = serd_node_copy(allocator, predicate))) {
+ if (!(data->predicate = serd_node_copy(alloc, predicate))) {
free_data(data);
return NULL;
}
}
if (object && serd_node_type(object) != SERD_VARIABLE) {
- if (!(data->object = serd_node_copy(allocator, object))) {
+ if (!(data->object = serd_node_copy(alloc, object))) {
free_data(data);
return NULL;
}
}
if (graph && serd_node_type(graph) != SERD_VARIABLE) {
- if (!(data->graph = serd_node_copy(allocator, graph))) {
+ if (!(data->graph = serd_node_copy(alloc, graph))) {
free_data(data);
return NULL;
}
}
SerdSink* const sink =
- serd_sink_new(allocator, data, serd_filter_on_event, free_data);
+ serd_sink_new(alloc, data, serd_filter_on_event, free_data);
if (!sink) {
free_data(data);
diff --git a/src/memory.c b/src/memory.c
deleted file mode 100644
index 74694c14..00000000
--- a/src/memory.c
+++ /dev/null
@@ -1,17 +0,0 @@
-// Copyright 2011-2021 David Robillard <d@drobilla.net>
-// SPDX-License-Identifier: ISC
-
-#include "memory.h"
-
-#include "serd/memory.h"
-#include "zix/allocator.h"
-
-SerdAllocator*
-serd_default_allocator(void)
-{
- /* Note that SerdAllocator is intentionally the same as ZixAllocator. It
- only exists to avoid exposing the zix API in the public serd API, which
- I'm not sure would be appropriate. */
-
- return (SerdAllocator*)zix_default_allocator();
-}
diff --git a/src/memory.h b/src/memory.h
index 80c60724..ace3abce 100644
--- a/src/memory.h
+++ b/src/memory.h
@@ -4,99 +4,18 @@
#ifndef SERD_SRC_MEMORY_H
#define SERD_SRC_MEMORY_H
-#include "serd/memory.h"
#include "serd/world.h"
+#include "zix/allocator.h"
#include <stddef.h>
#include <string.h>
-// Allocator convenience wrappers that fall back to the default for NULL
-
-/// Convenience wrapper that defers to malloc() if allocator is null
-static inline void*
-serd_amalloc(SerdAllocator* const allocator, const size_t size)
-{
- SerdAllocator* const actual =
- allocator ? allocator : serd_default_allocator();
-
- return actual->malloc(actual, size);
-}
-
-/// Convenience wrapper that defers to calloc() if allocator is null
-static inline void*
-serd_acalloc(SerdAllocator* const allocator,
- const size_t nmemb,
- const size_t size)
-{
- SerdAllocator* const actual =
- allocator ? allocator : serd_default_allocator();
-
- return actual->calloc(actual, nmemb, size);
-}
-
-/// Convenience wrapper that defers to realloc() if allocator is null
-static inline void*
-serd_arealloc(SerdAllocator* const allocator,
- void* const ptr,
- const size_t size)
-{
- SerdAllocator* const actual =
- allocator ? allocator : serd_default_allocator();
-
- return actual->realloc(actual, ptr, size);
-}
-
-/// Convenience wrapper that defers to free() if allocator is null
-static inline void
-serd_afree(SerdAllocator* const allocator, void* const ptr)
-{
- SerdAllocator* const actual =
- allocator ? allocator : serd_default_allocator();
-
- actual->free(actual, ptr);
-}
-
-/// Convenience wrapper that defers to the system allocator if allocator is null
-static inline void*
-serd_aaligned_alloc(SerdAllocator* const allocator,
- const size_t alignment,
- const size_t size)
-{
- SerdAllocator* const actual =
- allocator ? allocator : serd_default_allocator();
-
- return actual->aligned_alloc(actual, alignment, size);
-}
-
-/// Convenience wrapper for serd_aaligned_alloc that zeros memory
-static inline void*
-serd_aaligned_calloc(SerdAllocator* const allocator,
- const size_t alignment,
- const size_t size)
-{
- void* const ptr = serd_aaligned_alloc(allocator, alignment, size);
- if (ptr) {
- memset(ptr, 0, size);
- }
- return ptr;
-}
-
-/// Convenience wrapper that defers to the system allocator if allocator is null
-static inline void
-serd_aaligned_free(SerdAllocator* const allocator, void* const ptr)
-{
- SerdAllocator* const actual =
- allocator ? allocator : serd_default_allocator();
-
- actual->aligned_free(actual, ptr);
-}
-
-// World convenience wrappers
+// Allocator convenience wrappers that use the world allocator
static inline void*
serd_wmalloc(const SerdWorld* const world, const size_t size)
{
- return serd_amalloc(serd_world_allocator(world), size);
+ return zix_malloc(serd_world_allocator(world), size);
}
static inline void*
@@ -104,19 +23,19 @@ serd_wcalloc(const SerdWorld* const world,
const size_t nmemb,
const size_t size)
{
- return serd_acalloc(serd_world_allocator(world), nmemb, size);
+ return zix_calloc(serd_world_allocator(world), nmemb, size);
}
static inline void*
serd_wrealloc(const SerdWorld* const world, void* const ptr, const size_t size)
{
- return serd_arealloc(serd_world_allocator(world), ptr, size);
+ return zix_realloc(serd_world_allocator(world), ptr, size);
}
static inline void
serd_wfree(const SerdWorld* const world, void* const ptr)
{
- serd_afree(serd_world_allocator(world), ptr);
+ zix_free(serd_world_allocator(world), ptr);
}
static inline void*
@@ -124,13 +43,13 @@ serd_waligned_alloc(const SerdWorld* const world,
const size_t alignment,
const size_t size)
{
- return serd_aaligned_alloc(serd_world_allocator(world), alignment, size);
+ return zix_aligned_alloc(serd_world_allocator(world), alignment, size);
}
static inline void
serd_waligned_free(const SerdWorld* const world, void* const ptr)
{
- serd_aaligned_free(serd_world_allocator(world), ptr);
+ zix_aligned_free(serd_world_allocator(world), ptr);
}
#endif // SERD_SRC_MEMORY_H
diff --git a/src/model.c b/src/model.c
index 89b37d83..fd1b0f92 100644
--- a/src/model.c
+++ b/src/model.c
@@ -77,8 +77,7 @@ serd_model_add_index(SerdModel* const model, const SerdStatementOrder order)
const ZixBTreeCompareFunc comparator =
serd_model_index_comparator(model, order);
- model->indices[order] =
- zix_btree_new((ZixAllocator*)model->allocator, comparator, ordering);
+ model->indices[order] = zix_btree_new(model->allocator, comparator, ordering);
if (!model->indices[order]) {
return SERD_BAD_ALLOC;
@@ -117,7 +116,7 @@ serd_model_drop_index(SerdModel* const model, const SerdStatementOrder order)
}
static SerdModel*
-serd_model_new_with_allocator(SerdAllocator* const allocator,
+serd_model_new_with_allocator(ZixAllocator* const allocator,
SerdWorld* const world,
const SerdStatementOrder default_order,
const SerdModelFlags flags)
@@ -130,7 +129,7 @@ serd_model_new_with_allocator(SerdAllocator* const allocator,
}
SerdModel* model =
- (SerdModel*)serd_acalloc(allocator, 1, sizeof(struct SerdModelImpl));
+ (SerdModel*)zix_calloc(allocator, 1, sizeof(struct SerdModelImpl));
if (!model) {
serd_nodes_free(nodes);
@@ -220,7 +219,7 @@ make_begin_cursor(const SerdModel* const model, const SerdStatementOrder order)
}
SerdModel*
-serd_model_copy(SerdAllocator* const allocator, const SerdModel* const model)
+serd_model_copy(ZixAllocator* const allocator, const SerdModel* const model)
{
assert(model);
@@ -280,7 +279,7 @@ serd_model_drop_statement(SerdModel* const model,
}
typedef struct {
- SerdAllocator* allocator;
+ ZixAllocator* allocator;
} DestroyContext;
static void
@@ -355,7 +354,7 @@ serd_model_empty(const SerdModel* const model)
}
SerdCursor*
-serd_model_begin_ordered(SerdAllocator* const allocator,
+serd_model_begin_ordered(ZixAllocator* const allocator,
const SerdModel* const model,
const SerdStatementOrder order)
{
@@ -367,7 +366,7 @@ serd_model_begin_ordered(SerdAllocator* const allocator,
}
SerdCursor*
-serd_model_begin(SerdAllocator* const allocator, const SerdModel* const model)
+serd_model_begin(ZixAllocator* const allocator, const SerdModel* const model)
{
assert(model);
return serd_model_begin_ordered(allocator, model, model->default_order);
@@ -551,7 +550,7 @@ serd_model_search(const SerdModel* const model,
}
SerdCursor*
-serd_model_find(SerdAllocator* const allocator,
+serd_model_find(ZixAllocator* const allocator,
const SerdModel* const model,
const SerdNode* const s,
const SerdNode* const p,
@@ -647,7 +646,7 @@ serd_model_intern_caret(SerdModel* const model, const SerdCaret* const caret)
}
SerdCaret* const copy =
- (SerdCaret*)serd_acalloc(model->allocator, 1, sizeof(SerdCaret));
+ (SerdCaret*)zix_calloc(model->allocator, 1, sizeof(SerdCaret));
if (copy) {
copy->document = serd_nodes_intern(model->nodes, caret->document);
diff --git a/src/model.h b/src/model.h
index a67ba087..f0a54aaa 100644
--- a/src/model.h
+++ b/src/model.h
@@ -7,16 +7,16 @@
#include "cursor.h"
#include "serd/cursor.h"
-#include "serd/memory.h"
#include "serd/model.h"
#include "serd/nodes.h"
#include "serd/world.h"
+#include "zix/allocator.h"
#include "zix/btree.h"
#include <stddef.h>
struct SerdModelImpl {
- SerdAllocator* allocator; ///< Allocator for everything in this model
+ ZixAllocator* allocator; ///< Allocator for everything in this model
SerdWorld* world; ///< World this model is a part of
SerdNodes* nodes; ///< Interned nodes in this model
ZixBTree* indices[12]; ///< Trees of SerdStatement pointers
diff --git a/src/node.c b/src/node.c
index f38cdb78..c89f20fd 100644
--- a/src/node.c
+++ b/src/node.c
@@ -3,7 +3,6 @@
#include "node.h"
-#include "memory.h"
#include "namespaces.h"
#include "string_utils.h"
@@ -13,6 +12,7 @@
#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"
@@ -180,17 +180,21 @@ serd_node_total_size(const SerdNode* const node)
}
SerdNode*
-serd_node_malloc(SerdAllocator* const allocator, const size_t size)
+serd_node_malloc(ZixAllocator* const allocator, const size_t size)
{
- SerdNode* const node = (SerdNode*)serd_aaligned_calloc(
+ SerdNode* const node = (SerdNode*)zix_aligned_alloc(
allocator, serd_node_align, serd_node_pad_size(size));
+ if (node) {
+ memset(node, 0, size);
+ }
+
assert((uintptr_t)node % serd_node_align == 0U);
return node;
}
SerdNode*
-serd_node_try_malloc(SerdAllocator* const allocator, const SerdWriteResult r)
+serd_node_try_malloc(ZixAllocator* const allocator, const SerdWriteResult r)
{
return (r.status && r.status != SERD_OVERFLOW)
? NULL
@@ -198,7 +202,7 @@ serd_node_try_malloc(SerdAllocator* const allocator, const SerdWriteResult r)
}
SerdStatus
-serd_node_set(SerdAllocator* const allocator,
+serd_node_set(ZixAllocator* const allocator,
SerdNode** const dst,
const SerdNode* const src)
{
@@ -207,9 +211,8 @@ serd_node_set(SerdAllocator* const allocator,
const size_t size = serd_node_total_size(src);
if (!*dst || serd_node_total_size(*dst) < size) {
- serd_aaligned_free(allocator, *dst);
- if (!(*dst = (SerdNode*)serd_aaligned_calloc(
- allocator, serd_node_align, size))) {
+ zix_aligned_free(allocator, *dst);
+ if (!(*dst = serd_node_malloc(allocator, size))) {
return SERD_BAD_ALLOC;
}
}
@@ -599,7 +602,7 @@ serd_node_construct_uri(const size_t buf_size,
}
SerdNode*
-serd_node_new(SerdAllocator* const allocator, const SerdNodeArgs args)
+serd_node_new(ZixAllocator* const allocator, const SerdNodeArgs args)
{
SerdWriteResult r = serd_node_construct(0, NULL, args);
if (r.status != SERD_OVERFLOW) {
@@ -729,7 +732,7 @@ serd_node_decode(const SerdNode* const node,
}
SerdNode*
-serd_node_copy(SerdAllocator* const allocator, const SerdNode* node)
+serd_node_copy(ZixAllocator* const allocator, const SerdNode* node)
{
if (!node) {
return NULL;
@@ -737,7 +740,7 @@ serd_node_copy(SerdAllocator* const allocator, const SerdNode* node)
const size_t size = serd_node_total_size(node);
SerdNode* copy =
- (SerdNode*)serd_aaligned_alloc(allocator, serd_node_align, size);
+ (SerdNode*)zix_aligned_alloc(allocator, serd_node_align, size);
if (copy) {
memcpy(copy, node, size);
@@ -996,9 +999,9 @@ serd_node_flags(const SerdNode* const node)
}
void
-serd_node_free(SerdAllocator* const allocator, SerdNode* const node)
+serd_node_free(ZixAllocator* const allocator, SerdNode* const node)
{
- serd_aaligned_free(allocator, node);
+ zix_aligned_free(allocator, node);
}
#undef MUST_SUCCEED
diff --git a/src/node.h b/src/node.h
index 0dd15d0c..4c7afe2b 100644
--- a/src/node.h
+++ b/src/node.h
@@ -4,10 +4,10 @@
#ifndef SERD_SRC_NODE_H
#define SERD_SRC_NODE_H
-#include "serd/memory.h"
#include "serd/node.h"
#include "serd/status.h"
#include "serd/write_result.h"
+#include "zix/allocator.h"
#include "zix/attributes.h"
#include <assert.h>
@@ -87,14 +87,14 @@ serd_node_pattern_match(const SerdNode* ZIX_NULLABLE a,
}
ZIX_MALLOC_FUNC SerdNode* ZIX_ALLOCATED
-serd_node_malloc(SerdAllocator* ZIX_NULLABLE allocator, size_t size);
+serd_node_malloc(ZixAllocator* ZIX_NULLABLE allocator, size_t size);
ZIX_MALLOC_FUNC SerdNode* ZIX_ALLOCATED
-serd_node_try_malloc(SerdAllocator* ZIX_NULLABLE allocator,
- SerdWriteResult result);
+serd_node_try_malloc(ZixAllocator* ZIX_NULLABLE allocator,
+ SerdWriteResult result);
SerdStatus
-serd_node_set(SerdAllocator* ZIX_NULLABLE allocator,
+serd_node_set(ZixAllocator* ZIX_NULLABLE allocator,
SerdNode* ZIX_NONNULL* ZIX_NONNULL dst,
const SerdNode* ZIX_NONNULL src);
diff --git a/src/node_syntax.c b/src/node_syntax.c
index a66c6e22..5fe0ae44 100644
--- a/src/node_syntax.c
+++ b/src/node_syntax.c
@@ -8,7 +8,6 @@
#include "serd/env.h"
#include "serd/event.h"
#include "serd/input_stream.h"
-#include "serd/memory.h"
#include "serd/node.h"
#include "serd/node_syntax.h"
#include "serd/output_stream.h"
@@ -19,6 +18,7 @@
#include "serd/syntax.h"
#include "serd/world.h"
#include "serd/writer.h"
+#include "zix/allocator.h"
#include "zix/string_view.h"
#include <assert.h>
@@ -26,8 +26,8 @@
#include <string.h>
typedef struct {
- SerdAllocator* allocator;
- SerdNode* object;
+ ZixAllocator* allocator;
+ SerdNode* object;
} NodeSyntaxContext;
static SerdStatus
@@ -54,7 +54,7 @@ serd_node_from_syntax_in(SerdWorld* const world,
static const char* const prelude =
"_:s <http://www.w3.org/2000/01/rdf-schema#object>";
- SerdAllocator* const alloc = serd_world_allocator(world);
+ ZixAllocator* const alloc = serd_world_allocator(world);
const size_t str_len = strlen(str);
const size_t doc_len = strlen(prelude) + str_len + 5;
@@ -96,10 +96,10 @@ serd_node_from_syntax_in(SerdWorld* const world,
}
SerdNode*
-serd_node_from_syntax(SerdAllocator* const allocator,
- const char* const str,
- const SerdSyntax syntax,
- SerdEnv* const env)
+serd_node_from_syntax(ZixAllocator* const allocator,
+ const char* const str,
+ const SerdSyntax syntax,
+ SerdEnv* const env)
{
assert(str);
@@ -161,7 +161,7 @@ serd_node_to_syntax_in(SerdWorld* const world,
}
char*
-serd_node_to_syntax(SerdAllocator* const allocator,
+serd_node_to_syntax(ZixAllocator* const allocator,
const SerdNode* const node,
const SerdSyntax syntax,
const SerdEnv* const env)
diff --git a/src/nodes.c b/src/nodes.c
index 22ee3146..e353b9aa 100644
--- a/src/nodes.c
+++ b/src/nodes.c
@@ -3,7 +3,6 @@
#include "nodes.h"
-#include "memory.h"
#include "node.h"
#include "node_spec.h"
@@ -12,7 +11,6 @@
#define ZIX_HASH_RECORD_TYPE NodesEntry
#define ZIX_HASH_SEARCH_DATA_TYPE NodeSpec
-#include "serd/memory.h"
#include "serd/nodes.h"
#include "serd/write_result.h"
#include "zix/allocator.h"
@@ -76,16 +74,16 @@ typedef struct {
with an extra header) rather than node pointers directly.
*/
typedef struct {
- SerdAllocator base; ///< Implementation of SerdAllocator (base "class")
- SerdAllocator* real; ///< Underlying "real" memory allocator
+ ZixAllocator base; ///< Implementation of ZixAllocator (base "class")
+ ZixAllocator* real; ///< Underlying "real" memory allocator
} SerdNodesEntryAllocator;
ZIX_MALLOC_FUNC static void*
-serd_nodes_entry_aligned_alloc(SerdAllocator* const allocator,
- const size_t alignment,
- const size_t size)
+serd_nodes_entry_aligned_alloc(ZixAllocator* const allocator,
+ const size_t alignment,
+ const size_t size)
{
- SerdAllocator* const real = ((SerdNodesEntryAllocator*)allocator)->real;
+ ZixAllocator* const real = ((SerdNodesEntryAllocator*)allocator)->real;
void* const ptr =
real->aligned_alloc(real, alignment, serd_node_align + size);
@@ -94,9 +92,9 @@ serd_nodes_entry_aligned_alloc(SerdAllocator* const allocator,
}
static void
-serd_nodes_entry_aligned_free(SerdAllocator* const allocator, void* const ptr)
+serd_nodes_entry_aligned_free(ZixAllocator* const allocator, void* const ptr)
{
- SerdAllocator* const real = ((SerdNodesEntryAllocator*)allocator)->real;
+ ZixAllocator* const real = ((SerdNodesEntryAllocator*)allocator)->real;
if (ptr) {
real->aligned_free(real, (((uint8_t*)ptr) - serd_node_align));
@@ -104,7 +102,7 @@ serd_nodes_entry_aligned_free(SerdAllocator* const allocator, void* const ptr)
}
static SerdNodesEntryAllocator
-serd_nodes_entry_allocator(SerdAllocator* const real)
+serd_nodes_entry_allocator(ZixAllocator* const real)
{
const SerdNodesEntryAllocator entry_allocator = {
{
@@ -115,7 +113,7 @@ serd_nodes_entry_allocator(SerdAllocator* const real)
serd_nodes_entry_aligned_alloc,
serd_nodes_entry_aligned_free,
},
- real ? real : serd_default_allocator(),
+ real ? real : zix_default_allocator(),
};
return entry_allocator;
@@ -228,21 +226,21 @@ nodes_equal(const SerdNode* const a, const SerdNode* const b)
static void
free_entry(SerdNodes* const nodes, NodesEntry* const entry)
{
- serd_aaligned_free(&nodes->allocator.base, &entry->node);
+ zix_aligned_free(&nodes->allocator.base, &entry->node);
}
SerdNodes*
-serd_nodes_new(SerdAllocator* const allocator)
+serd_nodes_new(ZixAllocator* const allocator)
{
SerdNodes* const nodes =
- (SerdNodes*)serd_acalloc(allocator, 1, sizeof(SerdNodes));
+ (SerdNodes*)zix_calloc(allocator, 1, sizeof(SerdNodes));
if (nodes) {
nodes->allocator = serd_nodes_entry_allocator(allocator);
- if (!(nodes->hash = zix_hash_new(
- (ZixAllocator*)allocator, nodes_key, nodes_hash, nodes_equal))) {
- serd_afree(allocator, nodes);
+ if (!(nodes->hash =
+ zix_hash_new(allocator, nodes_key, nodes_hash, nodes_equal))) {
+ zix_free(allocator, nodes);
return NULL;
}
}
@@ -261,7 +259,7 @@ serd_nodes_free(SerdNodes* nodes)
}
zix_hash_free(nodes->hash);
- serd_afree(nodes->allocator.real, nodes);
+ zix_free(nodes->allocator.real, nodes);
}
}
@@ -399,8 +397,8 @@ serd_nodes_token(SerdNodes* const nodes,
}
// Otherwise, allocate and manage a new one
- SerdAllocator* const alloc = &nodes->allocator.base;
- SerdNode* const node = serd_node_new(alloc, serd_a_token(type, string));
+ ZixAllocator* const alloc = &nodes->allocator.base;
+ SerdNode* const node = serd_node_new(alloc, serd_a_token(type, string));
return serd_nodes_manage_entry_node_at(nodes, node, plan);
}
@@ -428,8 +426,8 @@ serd_nodes_literal(SerdNodes* const nodes,
}
// Otherwise, allocate and manage a new one
- SerdAllocator* const alloc = &nodes->allocator.base;
- SerdNode* const node =
+ ZixAllocator* const alloc = &nodes->allocator.base;
+ SerdNode* const node =
serd_node_new(alloc, serd_a_literal(string, flags, meta));
return serd_nodes_manage_entry_node_at(nodes, node, plan);
diff --git a/src/reader.c b/src/reader.c
index ce87a6f0..85db9b0b 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -305,7 +305,7 @@ serd_reader_free(SerdReader* const reader)
serd_reader_finish(reader);
}
- serd_aaligned_free(reader->world->allocator, reader->stack.buf);
+ serd_stack_free(reader->world->allocator, &reader->stack);
serd_wfree(reader->world, reader);
}
diff --git a/src/sink.c b/src/sink.c
index 48ada0c5..61636048 100644
--- a/src/sink.c
+++ b/src/sink.c
@@ -3,24 +3,24 @@
#include "sink.h"
-#include "memory.h"
#include "statement.h"
#include "serd/node.h"
#include "serd/sink.h"
#include "serd/statement.h"
#include "serd/status.h"
+#include "zix/allocator.h"
#include <assert.h>
#include <stdlib.h>
SerdSink*
-serd_sink_new(SerdAllocator* const allocator,
- void* const handle,
- SerdEventFunc event_func,
- SerdFreeFunc free_handle)
+serd_sink_new(ZixAllocator* const allocator,
+ void* const handle,
+ SerdEventFunc event_func,
+ SerdFreeFunc free_handle)
{
- SerdSink* sink = (SerdSink*)serd_acalloc(allocator, 1, sizeof(SerdSink));
+ SerdSink* sink = (SerdSink*)zix_calloc(allocator, 1, sizeof(SerdSink));
if (sink) {
sink->allocator = allocator;
@@ -40,7 +40,7 @@ serd_sink_free(SerdSink* sink)
sink->free_handle(sink->handle);
}
- serd_afree(sink->allocator, sink);
+ zix_free(sink->allocator, sink);
}
}
diff --git a/src/sink.h b/src/sink.h
index baed246e..d6a12b3b 100644
--- a/src/sink.h
+++ b/src/sink.h
@@ -5,17 +5,17 @@
#define SERD_SRC_SINK_H
#include "serd/event.h"
-#include "serd/memory.h"
#include "serd/sink.h"
+#include "zix/allocator.h"
/**
An interface that receives a stream of RDF data.
*/
struct SerdSinkImpl {
- SerdAllocator* allocator;
- void* handle;
- SerdFreeFunc free_handle;
- SerdEventFunc on_event;
+ ZixAllocator* allocator;
+ void* handle;
+ SerdFreeFunc free_handle;
+ SerdEventFunc on_event;
};
#endif // SERD_SRC_SINK_H
diff --git a/src/stack.h b/src/stack.h
index 40e8065d..94e091a1 100644
--- a/src/stack.h
+++ b/src/stack.h
@@ -19,21 +19,26 @@ typedef struct {
} SerdStack;
static inline SerdStack
-serd_stack_new(SerdAllocator* const allocator, size_t size, size_t align)
+serd_stack_new(ZixAllocator* const allocator, size_t size, size_t align)
{
const size_t aligned_size = (size + (align - 1)) / align * align;
SerdStack stack;
- stack.buf = (char*)serd_aaligned_calloc(allocator, align, aligned_size);
+ stack.buf = (char*)zix_aligned_alloc(allocator, align, aligned_size);
stack.buf_size = size;
stack.size = align; // 0 is reserved for null
+
+ if (stack.buf) {
+ memset(stack.buf, 0, size);
+ }
+
return stack;
}
static inline void
-serd_stack_free(SerdAllocator* const allocator, SerdStack* stack)
+serd_stack_free(ZixAllocator* const allocator, SerdStack* stack)
{
- serd_aaligned_free(allocator, stack->buf);
+ zix_aligned_free(allocator, stack->buf);
stack->buf = NULL;
stack->buf_size = 0;
stack->size = 0;
diff --git a/src/statement.c b/src/statement.c
index 5ea14910..45c10459 100644
--- a/src/statement.c
+++ b/src/statement.c
@@ -4,11 +4,10 @@
#include "statement.h"
#include "caret.h"
-#include "memory.h"
#include "node.h"
-#include "serd/memory.h"
#include "serd/statement.h"
+#include "zix/allocator.h"
#include <assert.h>
#include <stdbool.h>
@@ -36,7 +35,7 @@ serd_statement_is_valid(const SerdNode* const subject,
}
SerdStatement*
-serd_statement_new(SerdAllocator* const allocator,
+serd_statement_new(ZixAllocator* const allocator,
const SerdNode* const s,
const SerdNode* const p,
const SerdNode* const o,
@@ -52,7 +51,7 @@ serd_statement_new(SerdAllocator* const allocator,
}
SerdStatement* statement =
- (SerdStatement*)serd_amalloc(allocator, sizeof(SerdStatement));
+ (SerdStatement*)zix_malloc(allocator, sizeof(SerdStatement));
if (statement) {
statement->nodes[0] = s;
@@ -63,7 +62,7 @@ serd_statement_new(SerdAllocator* const allocator,
if (caret) {
if (!(statement->caret = serd_caret_copy(allocator, caret))) {
- serd_afree(allocator, statement);
+ zix_free(allocator, statement);
return NULL;
}
}
@@ -73,7 +72,7 @@ serd_statement_new(SerdAllocator* const allocator,
}
SerdStatement*
-serd_statement_copy(SerdAllocator* const allocator,
+serd_statement_copy(ZixAllocator* const allocator,
const SerdStatement* const statement)
{
if (!statement) {
@@ -81,15 +80,15 @@ serd_statement_copy(SerdAllocator* const allocator,
}
SerdStatement* copy =
- (SerdStatement*)serd_amalloc(allocator, sizeof(SerdStatement));
+ (SerdStatement*)zix_malloc(allocator, sizeof(SerdStatement));
if (copy) {
memcpy(copy, statement, sizeof(SerdStatement));
if (statement->caret) {
if (!(copy->caret =
- (SerdCaret*)serd_amalloc(allocator, sizeof(SerdCaret)))) {
- serd_afree(allocator, copy);
+ (SerdCaret*)zix_malloc(allocator, sizeof(SerdCaret)))) {
+ zix_free(allocator, copy);
return NULL;
}
@@ -101,12 +100,12 @@ serd_statement_copy(SerdAllocator* const allocator,
}
void
-serd_statement_free(SerdAllocator* const allocator,
+serd_statement_free(ZixAllocator* const allocator,
SerdStatement* const statement)
{
if (statement) {
- serd_afree(allocator, statement->caret);
- serd_afree(allocator, statement);
+ zix_free(allocator, statement->caret);
+ zix_free(allocator, statement);
}
}
diff --git a/src/string.c b/src/string.c
index ac964705..89c4abaa 100644
--- a/src/string.c
+++ b/src/string.c
@@ -1,21 +1,13 @@
// Copyright 2011-2021 David Robillard <d@drobilla.net>
// SPDX-License-Identifier: ISC
-#include "memory.h"
#include "string_utils.h"
-#include "serd/memory.h"
#include "serd/status.h"
#include "serd/string.h"
#include <stddef.h>
-void
-serd_free(SerdAllocator* const allocator, void* const ptr)
-{
- serd_afree(allocator, ptr);
-}
-
const char*
serd_strerror(const SerdStatus status)
{
diff --git a/src/uri.c b/src/uri.c
index 53574600..9dc09fe6 100644
--- a/src/uri.c
+++ b/src/uri.c
@@ -1,15 +1,14 @@
// Copyright 2011-2023 David Robillard <d@drobilla.net>
// SPDX-License-Identifier: ISC
-#include "memory.h"
#include "string_utils.h"
#include "uri_utils.h"
#include "serd/buffer.h"
-#include "serd/memory.h"
#include "serd/status.h"
#include "serd/stream.h"
#include "serd/uri.h"
+#include "zix/allocator.h"
#include "zix/string_view.h"
#include <assert.h>
@@ -26,9 +25,9 @@ write_file_uri_char(const char c, void* const stream)
}
static char*
-parse_hostname(SerdAllocator* const allocator,
- const char* const authority,
- char** const hostname)
+parse_hostname(ZixAllocator* const allocator,
+ const char* const authority,
+ char** const hostname)
{
char* const path = strchr(authority, '/');
if (!path) {
@@ -37,7 +36,7 @@ parse_hostname(SerdAllocator* const allocator,
if (hostname) {
const size_t len = (size_t)(path - authority);
- if (!(*hostname = (char*)serd_acalloc(allocator, len + 1, 1))) {
+ if (!(*hostname = (char*)zix_calloc(allocator, len + 1, 1))) {
return NULL;
}
@@ -48,9 +47,9 @@ parse_hostname(SerdAllocator* const allocator,
}
char*
-serd_parse_file_uri(SerdAllocator* const allocator,
- const char* const uri,
- char** const hostname)
+serd_parse_file_uri(ZixAllocator* const allocator,
+ const char* const uri,
+ char** const hostname)
{
assert(uri);
@@ -95,7 +94,7 @@ serd_parse_file_uri(SerdAllocator* const allocator,
}
if (st || serd_buffer_close(&buffer)) {
- serd_free(allocator, buffer.buf);
+ zix_free(allocator, buffer.buf);
return NULL;
}
diff --git a/src/world.c b/src/world.c
index b4fe4ebc..b160fc4e 100644
--- a/src/world.c
+++ b/src/world.c
@@ -4,13 +4,13 @@
#include "world.h"
#include "log.h"
-#include "memory.h"
#include "namespaces.h"
#include "node.h"
#include "serd/node.h"
#include "serd/status.h"
#include "serd/world.h"
+#include "zix/allocator.h"
#include "zix/string_view.h"
#include <assert.h>
@@ -18,19 +18,15 @@
#include <string.h>
SerdWorld*
-serd_world_new(SerdAllocator* const allocator)
+serd_world_new(ZixAllocator* const allocator)
{
- SerdAllocator* const actual =
- allocator ? allocator : serd_default_allocator();
-
- SerdWorld* const world =
- (SerdWorld*)serd_acalloc(actual, 1, sizeof(SerdWorld));
+ ZixAllocator* const actual = allocator ? allocator : zix_default_allocator();
+ SerdWorld* const world = (SerdWorld*)zix_calloc(actual, 1, sizeof(SerdWorld));
SerdNodes* const nodes = serd_nodes_new(actual);
-
if (!world || !nodes) {
serd_nodes_free(nodes);
- serd_afree(actual, world);
+ zix_free(actual, world);
return NULL;
}
@@ -57,7 +53,7 @@ serd_world_new(SerdAllocator* const allocator)
!(world->xsd_decimal = serd_nodes_get(nodes, serd_a_uri(xsd_decimal))) ||
!(world->xsd_integer = serd_nodes_get(nodes, serd_a_uri(xsd_integer)))) {
serd_nodes_free(nodes);
- serd_afree(actual, world);
+ zix_free(actual, world);
return NULL;
}
@@ -72,7 +68,7 @@ serd_world_free(SerdWorld* const world)
{
if (world) {
serd_nodes_free(world->nodes);
- serd_afree(world->allocator, world);
+ zix_free(world->allocator, world);
}
}
@@ -109,7 +105,7 @@ serd_world_get_blank(SerdWorld* const world)
#undef BLANK_CHARS
}
-SerdAllocator*
+ZixAllocator*
serd_world_allocator(const SerdWorld* const world)
{
assert(world);
diff --git a/src/world.h b/src/world.h
index 8033dcec..67dd7916 100644
--- a/src/world.h
+++ b/src/world.h
@@ -7,15 +7,15 @@
#include "log.h"
#include "node.h"
-#include "serd/memory.h"
#include "serd/node.h"
#include "serd/nodes.h"
#include "serd/world.h"
+#include "zix/allocator.h"
#include <stdint.h>
struct SerdWorldImpl {
- SerdAllocator* allocator;
+ ZixAllocator* allocator;
SerdLog log;
SerdLimits limits;
SerdNodes* nodes;
diff --git a/src/writer.c b/src/writer.c
index b87df07a..fd52a123 100644
--- a/src/writer.c
+++ b/src/writer.c
@@ -19,8 +19,6 @@
#include "serd/env.h"
#include "serd/event.h"
#include "serd/log.h"
-#include "serd/memory.h"
-#include "serd/node.h"
#include "serd/output_stream.h"
#include "serd/sink.h"
#include "serd/statement.h"
@@ -28,6 +26,7 @@
#include "serd/syntax.h"
#include "serd/uri.h"
#include "serd/world.h"
+#include "zix/allocator.h"
#include "zix/string_view.h"
#include <assert.h>
@@ -1406,7 +1405,7 @@ serd_writer_set_root_uri(SerdWriter* writer, const ZixStringView uri)
{
assert(writer);
- SerdAllocator* const allocator = writer->world->allocator;
+ ZixAllocator* const allocator = writer->world->allocator;
serd_node_free(allocator, writer->root_node);
writer->root_node = NULL;
diff --git a/test/failing_allocator.c b/test/failing_allocator.c
index 89c19bad..869cd15d 100644
--- a/test/failing_allocator.c
+++ b/test/failing_allocator.c
@@ -3,6 +3,7 @@
#include "failing_allocator.h"
+#include "zix/allocator.h"
#include "zix/attributes.h"
#include <stdbool.h>
@@ -23,63 +24,63 @@ attempt(SerdFailingAllocator* const allocator)
}
ZIX_MALLOC_FUNC static void*
-serd_failing_malloc(SerdAllocator* const allocator, const size_t size)
+serd_failing_malloc(ZixAllocator* const allocator, const size_t size)
{
SerdFailingAllocator* const state = (SerdFailingAllocator*)allocator;
- SerdAllocator* const base = serd_default_allocator();
+ ZixAllocator* const base = zix_default_allocator();
return attempt(state) ? base->malloc(base, size) : NULL;
}
ZIX_MALLOC_FUNC static void*
-serd_failing_calloc(SerdAllocator* const allocator,
- const size_t nmemb,
- const size_t size)
+serd_failing_calloc(ZixAllocator* const allocator,
+ const size_t nmemb,
+ const size_t size)
{
SerdFailingAllocator* const state = (SerdFailingAllocator*)allocator;
- SerdAllocator* const base = serd_default_allocator();
+ ZixAllocator* const base = zix_default_allocator();
return attempt(state) ? base->calloc(base, nmemb, size) : NULL;
}
static void*
-serd_failing_realloc(SerdAllocator* const allocator,
- void* const ptr,
- const size_t size)
+serd_failing_realloc(ZixAllocator* const allocator,
+ void* const ptr,
+ const size_t size)
{
SerdFailingAllocator* const state = (SerdFailingAllocator*)allocator;
- SerdAllocator* const base = serd_default_allocator();
+ ZixAllocator* const base = zix_default_allocator();
return attempt(state) ? base->realloc(base, ptr, size) : NULL;
}
static void
-serd_failing_free(SerdAllocator* const allocator, void* const ptr)
+serd_failing_free(ZixAllocator* const allocator, void* const ptr)
{
(void)allocator;
- SerdAllocator* const base = serd_default_allocator();
+ ZixAllocator* const base = zix_default_allocator();
base->free(base, ptr);
}
ZIX_MALLOC_FUNC static void*
-serd_failing_aligned_alloc(SerdAllocator* const allocator,
- const size_t alignment,
- const size_t size)
+serd_failing_aligned_alloc(ZixAllocator* const allocator,
+ const size_t alignment,
+ const size_t size)
{
SerdFailingAllocator* const state = (SerdFailingAllocator*)allocator;
- SerdAllocator* const base = serd_default_allocator();
+ ZixAllocator* const base = zix_default_allocator();
return attempt(state) ? base->aligned_alloc(base, alignment, size) : NULL;
}
static void
-serd_failing_aligned_free(SerdAllocator* const allocator, void* const ptr)
+serd_failing_aligned_free(ZixAllocator* const allocator, void* const ptr)
{
(void)allocator;
- SerdAllocator* const base = serd_default_allocator();
+ ZixAllocator* const base = zix_default_allocator();
base->aligned_free(base, ptr);
}
diff --git a/test/failing_allocator.h b/test/failing_allocator.h
index 7bc514bb..16ed0bec 100644
--- a/test/failing_allocator.h
+++ b/test/failing_allocator.h
@@ -4,15 +4,15 @@
#ifndef SERD_TEST_FAILING_ALLOCATOR_H
#define SERD_TEST_FAILING_ALLOCATOR_H
-#include "serd/serd.h"
+#include "zix/allocator.h"
#include <stddef.h>
/// An allocator that fails after some number of successes for testing
typedef struct {
- SerdAllocator base; ///< Base allocator instance
- size_t n_allocations; ///< Number of attempted allocations
- size_t n_remaining; ///< Number of remaining successful allocations
+ ZixAllocator base; ///< Base allocator instance
+ size_t n_allocations; ///< Number of attempted allocations
+ size_t n_remaining; ///< Number of remaining successful allocations
} SerdFailingAllocator;
SerdFailingAllocator
diff --git a/test/test_caret.c b/test/test_caret.c
index 379f80eb..98b1af67 100644
--- a/test/test_caret.c
+++ b/test/test_caret.c
@@ -6,9 +6,9 @@
#include "failing_allocator.h"
#include "serd/caret.h"
-#include "serd/memory.h"
#include "serd/node.h"
#include "serd/nodes.h"
+#include "zix/allocator.h"
#include <assert.h>
#include <stddef.h>
@@ -17,7 +17,7 @@
static int
test_caret(void)
{
- SerdAllocator* const allocator = serd_default_allocator();
+ ZixAllocator* const allocator = zix_default_allocator();
SerdNodes* const nodes = serd_nodes_new(allocator);
const SerdNode* const node = serd_nodes_get(nodes, serd_a_string("node"));
diff --git a/test/test_free_null.c b/test/test_free_null.c
index 89846c7f..c9f76c2c 100644
--- a/test/test_free_null.c
+++ b/test/test_free_null.c
@@ -6,7 +6,6 @@
#include "serd/caret.h"
#include "serd/cursor.h"
#include "serd/env.h"
-#include "serd/memory.h"
#include "serd/model.h"
#include "serd/node.h"
#include "serd/nodes.h"
@@ -21,7 +20,6 @@
int
main(void)
{
- serd_free(NULL, NULL);
serd_node_free(NULL, NULL);
serd_world_free(NULL);
serd_env_free(NULL);
diff --git a/test/test_model.c b/test/test_model.c
index 2e3a7847..f1a8d5cb 100644
--- a/test/test_model.c
+++ b/test/test_model.c
@@ -12,7 +12,6 @@
#include "serd/env.h"
#include "serd/inserter.h"
#include "serd/log.h"
-#include "serd/memory.h"
#include "serd/model.h"
#include "serd/node.h"
#include "serd/nodes.h"
@@ -23,6 +22,7 @@
#include "serd/syntax.h"
#include "serd/world.h"
#include "serd/writer.h"
+#include "zix/allocator.h"
#include "zix/attributes.h"
#include "zix/string_view.h"
@@ -156,8 +156,8 @@ test_read(SerdWorld* world,
const SerdNode* g,
const unsigned n_quads)
{
- SerdAllocator* const allocator = serd_default_allocator();
- SerdNodes* const nodes = serd_nodes_new(allocator);
+ ZixAllocator* const allocator = zix_default_allocator();
+ SerdNodes* const nodes = serd_nodes_new(allocator);
SerdCursor* cursor = serd_model_begin(NULL, model);
const SerdStatement* prev = NULL;
@@ -604,10 +604,10 @@ test_inserter(SerdWorld* world, const unsigned n_quads)
{
(void)n_quads;
- SerdAllocator* const allocator = serd_default_allocator();
- SerdNodes* const nodes = serd_nodes_new(allocator);
- SerdModel* const model = serd_model_new(world, SERD_ORDER_SPO, 0U);
- SerdSink* const inserter = serd_inserter_new(model, NULL);
+ ZixAllocator* const allocator = zix_default_allocator();
+ SerdNodes* const nodes = serd_nodes_new(allocator);
+ SerdModel* const model = serd_model_new(world, SERD_ORDER_SPO, 0U);
+ SerdSink* const inserter = serd_inserter_new(model, NULL);
const SerdNode* const s =
serd_nodes_get(nodes, serd_a_uri_string("http://example.org/s"));
@@ -673,7 +673,7 @@ test_add_erase(SerdWorld* world, const unsigned n_quads)
{
(void)n_quads;
- SerdAllocator* const allocator = serd_default_allocator();
+ ZixAllocator* const allocator = zix_default_allocator();
SerdNodes* const nodes = serd_nodes_new(allocator);
SerdModel* const model = serd_model_new(world, SERD_ORDER_SPO, 0U);
@@ -713,8 +713,8 @@ test_add_bad_statement(SerdWorld* world, const unsigned n_quads)
{
(void)n_quads;
- SerdAllocator* const allocator = serd_world_allocator(world);
- SerdNodes* const nodes = serd_nodes_new(allocator);
+ ZixAllocator* const allocator = serd_world_allocator(world);
+ SerdNodes* const nodes = serd_nodes_new(allocator);
const SerdNode* s = serd_nodes_get(nodes, serd_a_uri_string("urn:s"));
const SerdNode* p = serd_nodes_get(nodes, serd_a_uri_string("urn:p"));
@@ -1089,7 +1089,7 @@ test_write_flat_range(SerdWorld* world, const unsigned n_quads)
{
(void)n_quads;
- SerdAllocator* const alloc = serd_world_allocator(world);
+ ZixAllocator* const alloc = serd_world_allocator(world);
SerdModel* model = serd_model_new(world, SERD_ORDER_SPO, SERD_STORE_GRAPHS);
SerdNodes* nodes = serd_nodes_new(alloc);
@@ -1136,7 +1136,7 @@ test_write_flat_range(SerdWorld* world, const unsigned n_quads)
assert(str);
assert(!strcmp(str, expected));
- serd_free(NULL, buffer.buf);
+ zix_free(NULL, buffer.buf);
serd_writer_free(writer);
serd_model_free(model);
serd_env_free(env);
@@ -1149,7 +1149,7 @@ test_write_bad_list(SerdWorld* world, const unsigned n_quads)
{
(void)n_quads;
- SerdAllocator* const alloc = serd_world_allocator(world);
+ ZixAllocator* const alloc = serd_world_allocator(world);
SerdModel* model = serd_model_new(world, SERD_ORDER_SPO, SERD_STORE_GRAPHS);
SerdNodes* nodes = serd_nodes_new(alloc);
@@ -1212,7 +1212,7 @@ test_write_bad_list(SerdWorld* world, const unsigned n_quads)
assert(str);
assert(!strcmp(str, expected));
- serd_free(NULL, buffer.buf);
+ zix_free(NULL, buffer.buf);
serd_writer_free(writer);
serd_close_output(&out);
serd_model_free(model);
@@ -1226,7 +1226,7 @@ test_write_infinite_list(SerdWorld* world, const unsigned n_quads)
{
(void)n_quads;
- SerdAllocator* const alloc = serd_world_allocator(world);
+ ZixAllocator* const alloc = serd_world_allocator(world);
SerdModel* model = serd_model_new(world, SERD_ORDER_SPO, SERD_STORE_GRAPHS);
SerdNodes* nodes = serd_nodes_new(alloc);
@@ -1284,7 +1284,7 @@ test_write_infinite_list(SerdWorld* world, const unsigned n_quads)
assert(str);
assert(!strcmp(str, expected));
- serd_free(NULL, buffer.buf);
+ zix_free(NULL, buffer.buf);
serd_writer_free(writer);
serd_close_output(&out);
serd_model_free(model);
@@ -1317,7 +1317,7 @@ test_write_error_in_list_subject(SerdWorld* world, const unsigned n_quads)
{
(void)n_quads;
- SerdAllocator* const alloc = serd_world_allocator(world);
+ ZixAllocator* const alloc = serd_world_allocator(world);
serd_set_log_func(world, expected_error, NULL);
@@ -1377,7 +1377,7 @@ test_write_error_in_list_object(SerdWorld* world, const unsigned n_quads)
{
(void)n_quads;
- SerdAllocator* const alloc = serd_world_allocator(world);
+ ZixAllocator* const alloc = serd_world_allocator(world);
serd_set_log_func(world, expected_error, NULL);
diff --git a/test/test_node_syntax.c b/test/test_node_syntax.c
index 5e106a94..ce556669 100644
--- a/test/test_node_syntax.c
+++ b/test/test_node_syntax.c
@@ -6,12 +6,12 @@
#include "failing_allocator.h"
#include "serd/env.h"
-#include "serd/memory.h"
#include "serd/node.h"
#include "serd/node_syntax.h"
#include "serd/nodes.h"
#include "serd/syntax.h"
#include "serd/value.h"
+#include "zix/allocator.h"
#include "zix/string_view.h"
#include <assert.h>
@@ -50,11 +50,11 @@ test_failed_alloc(void)
assert(!s || !c);
serd_node_free(&allocator.base, c);
- serd_free(&allocator.base, s);
+ zix_free(&allocator.base, s);
}
serd_node_free(&allocator.base, copy);
- serd_free(&allocator.base, str);
+ zix_free(&allocator.base, str);
serd_node_free(&allocator.base, node);
}
@@ -72,7 +72,7 @@ check(const SerdSyntax syntax,
const bool success = !strcmp(str, expected) && serd_node_equals(copy, node);
serd_node_free(NULL, copy);
- serd_free(NULL, str);
+ zix_free(NULL, str);
serd_env_free(env);
return success;
}
@@ -162,7 +162,7 @@ test_ntriples(void)
serd_node_free(NULL, copy);
serd_env_free(env);
- serd_free(NULL, str);
+ zix_free(NULL, str);
}
assert(check(SERD_NTRIPLES,
diff --git a/test/test_nodes.c b/test/test_nodes.c
index b220f6d7..974ee062 100644
--- a/test/test_nodes.c
+++ b/test/test_nodes.c
@@ -5,11 +5,11 @@
#include "failing_allocator.h"
-#include "serd/memory.h"
#include "serd/node.h"
#include "serd/nodes.h"
#include "serd/uri.h"
#include "serd/value.h"
+#include "zix/allocator.h"
#include "zix/string_view.h"
#include <assert.h>
@@ -75,7 +75,7 @@ test_intern_failed_alloc(void)
static void
test_intern(void)
{
- SerdAllocator* const allocator = serd_default_allocator();
+ ZixAllocator* const allocator = zix_default_allocator();
SerdNodes* nodes = serd_nodes_new(allocator);
SerdNode* node = serd_node_new(NULL, serd_a_string("node"));
@@ -101,7 +101,7 @@ test_string(void)
{
static const ZixStringView string = ZIX_STATIC_STRING("string");
- SerdAllocator* const allocator = serd_default_allocator();
+ ZixAllocator* const allocator = zix_default_allocator();
SerdNodes* const nodes = serd_nodes_new(allocator);
const SerdNode* const node =
@@ -133,7 +133,7 @@ test_string(void)
static void
test_invalid_literal(void)
{
- SerdAllocator* const allocator = serd_default_allocator();
+ ZixAllocator* const allocator = zix_default_allocator();
SerdNodes* const nodes = serd_nodes_new(allocator);
@@ -161,7 +161,7 @@ test_plain_literal(void)
static const ZixStringView string = ZIX_STATIC_STRING("string");
static const ZixStringView language = ZIX_STATIC_STRING("en");
- SerdAllocator* const allocator = serd_default_allocator();
+ ZixAllocator* const allocator = zix_default_allocator();
SerdNodes* const nodes = serd_nodes_new(allocator);
const SerdNode* const node =
@@ -214,7 +214,7 @@ test_typed_literal(void)
static const ZixStringView string = ZIX_STATIC_STRING("string");
static const ZixStringView datatype = ZIX_STATIC_STRING(NS_EG "Type");
- SerdAllocator* const allocator = serd_default_allocator();
+ ZixAllocator* const allocator = zix_default_allocator();
SerdNodes* const nodes = serd_nodes_new(allocator);
const SerdNode* const node =
@@ -246,7 +246,7 @@ test_typed_literal(void)
static void
test_boolean(void)
{
- SerdAllocator* const allocator = serd_default_allocator();
+ ZixAllocator* const allocator = zix_default_allocator();
SerdNodes* const nodes = serd_nodes_new(allocator);
@@ -285,8 +285,8 @@ test_boolean(void)
static void
test_decimal(void)
{
- SerdAllocator* const allocator = serd_default_allocator();
- SerdNodes* const nodes = serd_nodes_new(allocator);
+ ZixAllocator* const allocator = zix_default_allocator();
+ SerdNodes* const nodes = serd_nodes_new(allocator);
const SerdNode* const a = serd_nodes_get(nodes, serd_a_decimal(-12.3456789));
const SerdNode* const b = serd_nodes_get(nodes, serd_a_decimal(-12.3456789));
@@ -306,7 +306,7 @@ test_decimal(void)
static void
test_double(void)
{
- SerdAllocator* const allocator = serd_default_allocator();
+ ZixAllocator* const allocator = zix_default_allocator();
SerdNodes* const nodes = serd_nodes_new(allocator);
@@ -327,7 +327,7 @@ test_double(void)
static void
test_float(void)
{
- SerdAllocator* const allocator = serd_default_allocator();
+ ZixAllocator* const allocator = zix_default_allocator();
SerdNodes* const nodes = serd_nodes_new(allocator);
@@ -348,8 +348,8 @@ test_float(void)
static void
test_integer(void)
{
- SerdAllocator* const allocator = serd_default_allocator();
- SerdNodes* const nodes = serd_nodes_new(allocator);
+ ZixAllocator* const allocator = zix_default_allocator();
+ SerdNodes* const nodes = serd_nodes_new(allocator);
const SerdNode* const a = serd_nodes_get(nodes, serd_a_integer(-1234567890));
const SerdNode* const b = serd_nodes_get(nodes, serd_a_integer(-1234567890));
@@ -371,7 +371,7 @@ test_base64(void)
{
static const char data[] = {'f', 'o', 'o', 'b', 'a', 'r'};
- SerdAllocator* const allocator = serd_default_allocator();
+ ZixAllocator* const allocator = zix_default_allocator();
SerdNodes* const nodes = serd_nodes_new(allocator);
@@ -398,8 +398,8 @@ test_uri(void)
{
static const ZixStringView string = ZIX_STATIC_STRING("http://example.org/");
- SerdAllocator* const allocator = serd_default_allocator();
- SerdNodes* const nodes = serd_nodes_new(allocator);
+ ZixAllocator* const allocator = zix_default_allocator();
+ SerdNodes* const nodes = serd_nodes_new(allocator);
const SerdNode* const node = serd_nodes_get(nodes, serd_a_uri(string));
@@ -419,7 +419,7 @@ test_parsed_uri(void)
{
static const ZixStringView string = ZIX_STATIC_STRING("http://example.org/");
- SerdAllocator* const allocator = serd_default_allocator();
+ ZixAllocator* const allocator = zix_default_allocator();
SerdNodes* const nodes = serd_nodes_new(allocator);
const SerdURIView uri = serd_parse_uri(string.data);
@@ -448,7 +448,7 @@ test_parsed_uri(void)
static void
test_file_uri(void)
{
- SerdAllocator* const allocator = serd_default_allocator();
+ ZixAllocator* const allocator = zix_default_allocator();
static const ZixStringView local_string =
ZIX_STATIC_STRING("file:///d/f.txt");
@@ -497,7 +497,7 @@ test_blank(void)
{
static const ZixStringView string = ZIX_STATIC_STRING("b42");
- SerdAllocator* const allocator = serd_default_allocator();
+ ZixAllocator* const allocator = zix_default_allocator();
SerdNodes* const nodes = serd_nodes_new(allocator);
const SerdNode* const node = serd_nodes_get(nodes, serd_a_blank(string));
@@ -516,8 +516,8 @@ test_blank(void)
static void
test_deref(void)
{
- SerdAllocator* const allocator = serd_default_allocator();
- SerdNodes* nodes = serd_nodes_new(allocator);
+ ZixAllocator* const allocator = zix_default_allocator();
+ SerdNodes* nodes = serd_nodes_new(allocator);
const SerdNode* original = serd_nodes_get(nodes, serd_a_string("node"));
const SerdNode* another = serd_nodes_get(nodes, serd_a_string("node"));
@@ -558,7 +558,7 @@ test_deref(void)
static void
test_get(void)
{
- SerdAllocator* const allocator = serd_default_allocator();
+ ZixAllocator* const allocator = zix_default_allocator();
SerdNodes* nodes = serd_nodes_new(allocator);
SerdNode* node = serd_node_new(NULL, serd_a_string("node"));
diff --git a/test/test_overflow.c b/test/test_overflow.c
index f2ff184b..39fbd00d 100644
--- a/test/test_overflow.c
+++ b/test/test_overflow.c
@@ -4,6 +4,7 @@
#undef NDEBUG
#include "serd/serd.h"
+#include "zix/allocator.h"
#include "zix/string_view.h"
#include <assert.h>
@@ -23,11 +24,11 @@ test_size(SerdWorld* const world,
limits.reader_stack_size = stack_size;
serd_world_set_limits(world, limits);
- SerdNodes* const nodes = serd_world_nodes(world);
- SerdAllocator* const alloc = serd_world_allocator(world);
- SerdSink* const sink = serd_sink_new(alloc, NULL, NULL, NULL);
- SerdEnv* const env = serd_env_new(alloc, zix_empty_string());
- SerdReader* const reader = serd_reader_new(world, syntax, flags, env, sink);
+ SerdNodes* const nodes = serd_world_nodes(world);
+ ZixAllocator* const alloc = serd_world_allocator(world);
+ SerdSink* const sink = serd_sink_new(alloc, NULL, NULL, NULL);
+ SerdEnv* const env = serd_env_new(alloc, zix_empty_string());
+ SerdReader* const reader = serd_reader_new(world, syntax, flags, env, sink);
if (!reader) {
return SERD_BAD_STACK;
}
diff --git a/test/test_reader_writer.c b/test/test_reader_writer.c
index 1858d570..0237cb6c 100644
--- a/test/test_reader_writer.c
+++ b/test/test_reader_writer.c
@@ -7,7 +7,6 @@
#include "serd/env.h"
#include "serd/event.h"
#include "serd/input_stream.h"
-#include "serd/memory.h"
#include "serd/node.h"
#include "serd/nodes.h"
#include "serd/output_stream.h"
@@ -233,7 +232,7 @@ test_writer(const char* const path)
char* const out = (char*)buffer.buf;
assert(out);
assert(!strcmp(out, "@base <http://example.org/base> .\n"));
- serd_free(NULL, buffer.buf);
+ zix_free(NULL, buffer.buf);
serd_env_free(env);
serd_world_free(world);
diff --git a/test/test_statement.c b/test/test_statement.c
index e960002f..3cad95bb 100644
--- a/test/test_statement.c
+++ b/test/test_statement.c
@@ -6,10 +6,10 @@
#include "failing_allocator.h"
#include "serd/caret.h"
-#include "serd/memory.h"
#include "serd/node.h"
#include "serd/nodes.h"
#include "serd/statement.h"
+#include "zix/allocator.h"
#include <assert.h>
#include <stddef.h>
@@ -20,7 +20,7 @@
static void
test_new(void)
{
- SerdAllocator* const allocator = serd_default_allocator();
+ ZixAllocator* const allocator = zix_default_allocator();
assert(!serd_statement_copy(allocator, NULL));
@@ -49,7 +49,7 @@ test_copy(void)
{
assert(!serd_statement_copy(NULL, NULL));
- SerdAllocator* const allocator = serd_default_allocator();
+ ZixAllocator* const allocator = zix_default_allocator();
assert(!serd_statement_copy(allocator, NULL));
@@ -80,7 +80,7 @@ test_copy_with_caret(void)
{
assert(!serd_statement_copy(NULL, NULL));
- SerdAllocator* const allocator = serd_default_allocator();
+ ZixAllocator* const allocator = zix_default_allocator();
assert(!serd_statement_copy(allocator, NULL));
@@ -115,14 +115,14 @@ test_copy_with_caret(void)
static void
test_free(void)
{
- serd_statement_free(serd_default_allocator(), NULL);
+ serd_statement_free(zix_default_allocator(), NULL);
serd_statement_free(NULL, NULL);
}
static void
test_fields(void)
{
- SerdAllocator* const allocator = serd_default_allocator();
+ ZixAllocator* const allocator = zix_default_allocator();
SerdNodes* const nodes = serd_nodes_new(allocator);
@@ -194,7 +194,7 @@ test_fields(void)
static void
test_failed_alloc(void)
{
- SerdNodes* const nodes = serd_nodes_new(serd_default_allocator());
+ SerdNodes* const nodes = serd_nodes_new(zix_default_allocator());
const SerdNode* const f = serd_nodes_get(nodes, serd_a_string("file"));
const SerdNode* const s = serd_nodes_get(nodes, serd_a_uri_string(NS_EG "s"));
@@ -202,7 +202,7 @@ test_failed_alloc(void)
const SerdNode* const o = serd_nodes_get(nodes, serd_a_uri_string(NS_EG "o"));
const SerdNode* const g = serd_nodes_get(nodes, serd_a_uri_string(NS_EG "g"));
- SerdCaret* const caret = serd_caret_new(serd_default_allocator(), f, 1, 1);
+ SerdCaret* const caret = serd_caret_new(zix_default_allocator(), f, 1, 1);
SerdFailingAllocator allocator = serd_failing_allocator();
@@ -233,7 +233,7 @@ test_failed_alloc(void)
serd_statement_free(&allocator.base, copy);
serd_statement_free(&allocator.base, statement);
- serd_caret_free(serd_default_allocator(), caret);
+ serd_caret_free(zix_default_allocator(), caret);
serd_nodes_free(nodes);
}
diff --git a/test/test_terse_write.c b/test/test_terse_write.c
index 0c55eb9d..c6a14d7d 100644
--- a/test/test_terse_write.c
+++ b/test/test_terse_write.c
@@ -5,7 +5,6 @@
#include "serd/buffer.h"
#include "serd/env.h"
-#include "serd/memory.h"
#include "serd/node.h"
#include "serd/nodes.h"
#include "serd/output_stream.h"
@@ -14,6 +13,7 @@
#include "serd/syntax.h"
#include "serd/world.h"
#include "serd/writer.h"
+#include "zix/allocator.h"
#include "zix/string_view.h"
#include <assert.h>
@@ -40,11 +40,11 @@ check_output(SerdWriter* writer, SerdBuffer* buffer, const char* expected)
static int
test(void)
{
- SerdWorld* world = serd_world_new(NULL);
- SerdAllocator* alloc = serd_world_allocator(world);
- SerdBuffer buffer = {NULL, NULL, 0};
- SerdEnv* env = serd_env_new(alloc, zix_empty_string());
- SerdNodes* nodes = serd_nodes_new(alloc);
+ SerdWorld* world = serd_world_new(NULL);
+ ZixAllocator* alloc = serd_world_allocator(world);
+ SerdBuffer buffer = {NULL, NULL, 0};
+ SerdEnv* env = serd_env_new(alloc, zix_empty_string());
+ SerdNodes* nodes = serd_nodes_new(alloc);
const SerdNode* b1 = serd_nodes_get(nodes, serd_a_blank_string("b1"));
const SerdNode* l1 = serd_nodes_get(nodes, serd_a_blank_string("l1"));
@@ -102,7 +102,7 @@ test(void)
serd_writer_free(writer);
serd_close_output(&output);
- serd_free(NULL, buffer.buf);
+ zix_free(NULL, buffer.buf);
serd_nodes_free(nodes);
serd_env_free(env);
serd_world_free(world);
diff --git a/test/test_uri.c b/test/test_uri.c
index bf4fa0f3..9c832bc1 100644
--- a/test/test_uri.c
+++ b/test/test_uri.c
@@ -5,10 +5,10 @@
#include "failing_allocator.h"
-#include "serd/memory.h"
#include "serd/node.h"
#include "serd/nodes.h"
#include "serd/uri.h"
+#include "zix/allocator.h"
#include "zix/string_view.h"
#include <assert.h>
@@ -29,8 +29,8 @@ test_file_uri_failed_alloc(void)
assert(!strcmp(path, "/path/spacey dir/100%.ttl"));
assert(!strcmp(hostname, "host"));
- serd_free(&allocator.base, path);
- serd_free(&allocator.base, hostname);
+ zix_free(&allocator.base, path);
+ zix_free(&allocator.base, hostname);
// Test that each allocation failing is handled gracefully
const size_t n_allocs = allocator.n_allocations;
@@ -40,8 +40,8 @@ test_file_uri_failed_alloc(void)
path = serd_parse_file_uri(&allocator.base, string, &hostname);
assert(!path || !hostname);
- serd_free(&allocator.base, path);
- serd_free(&allocator.base, hostname);
+ zix_free(&allocator.base, path);
+ zix_free(&allocator.base, hostname);
}
}
@@ -90,8 +90,8 @@ test_file_uri(const char* const hostname,
assert(!hostname || !strcmp(hostname, out_hostname));
assert(!strcmp(out_path, expected_path));
- serd_free(NULL, out_path);
- serd_free(NULL, out_hostname);
+ zix_free(NULL, out_path);
+ zix_free(NULL, out_hostname);
serd_nodes_free(nodes);
}
@@ -148,17 +148,17 @@ test_uri_parsing(void)
// Check that NULL hostname doesn't crash
char* out_path = serd_parse_file_uri(NULL, "file://me/path", NULL);
assert(!strcmp(out_path, "/path"));
- serd_free(NULL, out_path);
+ zix_free(NULL, out_path);
// Invalid first escape character
out_path = serd_parse_file_uri(NULL, "file:///foo/%0Xbar", NULL);
assert(!strcmp(out_path, "/foo/bar"));
- serd_free(NULL, out_path);
+ zix_free(NULL, out_path);
// Invalid second escape character
out_path = serd_parse_file_uri(NULL, "file:///foo/%X0bar", NULL);
assert(!strcmp(out_path, "/foo/bar"));
- serd_free(NULL, out_path);
+ zix_free(NULL, out_path);
}
static void
diff --git a/test/test_writer.c b/test/test_writer.c
index 17790527..fce67f8f 100644
--- a/test/test_writer.c
+++ b/test/test_writer.c
@@ -8,7 +8,6 @@
#include "serd/buffer.h"
#include "serd/env.h"
#include "serd/event.h"
-#include "serd/memory.h"
#include "serd/node.h"
#include "serd/nodes.h"
#include "serd/output_stream.h"
@@ -18,6 +17,7 @@
#include "serd/syntax.h"
#include "serd/world.h"
#include "serd/writer.h"
+#include "zix/allocator.h"
#include "zix/string_view.h"
#include <assert.h>
@@ -126,7 +126,7 @@ test_write_failed_alloc(void)
serd_close_output(&output);
serd_env_free(env);
serd_buffer_close(&buffer);
- serd_free(NULL, buffer.buf);
+ zix_free(NULL, buffer.buf);
serd_world_free(world);
}
@@ -152,7 +152,7 @@ test_write_bad_event(void)
char* const out = (char*)buffer.buf;
assert(out);
assert(!strcmp(out, ""));
- serd_free(NULL, buffer.buf);
+ zix_free(NULL, buffer.buf);
serd_writer_free(writer);
serd_env_free(env);
@@ -199,7 +199,7 @@ test_write_long_literal(void)
"\t<http://example.org/p> \"\"\"hello \"\"\\\"world\"\"\\\"!\"\"\" .\n";
assert(!strcmp(out, expected));
- serd_free(NULL, buffer.buf);
+ zix_free(NULL, buffer.buf);
serd_world_free(world);
}
@@ -429,7 +429,7 @@ test_write_empty_syntax(void)
char* const out = (char*)buffer.buf;
assert(out);
assert(strlen(out) == 0);
- serd_free(NULL, buffer.buf);
+ zix_free(NULL, buffer.buf);
serd_writer_free(writer);
serd_close_output(&output);
@@ -477,7 +477,7 @@ check_pname_escape(const char* const lname, const char* const expected)
char* const out = (char*)buffer.buf;
assert(!strcmp(out, expected));
- serd_free(NULL, buffer.buf);
+ zix_free(NULL, buffer.buf);
serd_world_free(world);
}
@@ -543,7 +543,7 @@ test_write_bad_uri(void)
serd_writer_free(writer);
serd_close_output(&output);
- serd_free(NULL, buffer.buf);
+ zix_free(NULL, buffer.buf);
serd_env_free(env);
serd_world_free(world);
}
diff --git a/tools/console.c b/tools/console.c
index 53e86389..057656d5 100644
--- a/tools/console.c
+++ b/tools/console.c
@@ -10,6 +10,7 @@
#include "serd/syntax.h"
#include "serd/uri.h"
#include "serd/version.h"
+#include "zix/allocator.h"
#include "zix/attributes.h"
#include "zix/string_view.h"
@@ -392,10 +393,10 @@ serd_parse_common_option(OptionIter* const iter, SerdCommonOptions* const opts)
}
SerdEnv*
-serd_create_env(SerdAllocator* const allocator,
- const char* const program,
- const char* const base_string,
- const char* const out_filename)
+serd_create_env(ZixAllocator* const allocator,
+ const char* const program,
+ const char* const base_string,
+ const char* const out_filename)
{
if (serd_uri_string_has_scheme(base_string)) {
return serd_env_new(allocator, zix_string(base_string));
diff --git a/tools/console.h b/tools/console.h
index 7e59862d..75755360 100644
--- a/tools/console.h
+++ b/tools/console.h
@@ -7,7 +7,6 @@
#include "serd/env.h"
#include "serd/input_stream.h"
#include "serd/log.h"
-#include "serd/memory.h"
#include "serd/output_stream.h"
#include "serd/reader.h"
#include "serd/sink.h"
@@ -15,6 +14,7 @@
#include "serd/syntax.h"
#include "serd/world.h"
#include "serd/writer.h"
+#include "zix/allocator.h"
#include "zix/string_view.h"
#include <stdbool.h>
@@ -108,10 +108,10 @@ SerdStatus
serd_parse_common_option(OptionIter* iter, SerdCommonOptions* opts);
SerdEnv*
-serd_create_env(SerdAllocator* allocator,
- const char* program,
- const char* base_string,
- const char* out_filename);
+serd_create_env(ZixAllocator* allocator,
+ const char* program,
+ const char* base_string,
+ const char* out_filename);
SerdInputStream
serd_open_tool_input(const char* filename);
diff --git a/tools/serd-filter.c b/tools/serd-filter.c
index 464a727e..5c7211b3 100644
--- a/tools/serd-filter.c
+++ b/tools/serd-filter.c
@@ -9,7 +9,6 @@
#include "serd/filter.h"
#include "serd/input_stream.h"
#include "serd/log.h"
-#include "serd/memory.h"
#include "serd/node.h"
#include "serd/nodes.h"
#include "serd/reader.h"
@@ -19,6 +18,7 @@
#include "serd/syntax.h"
#include "serd/world.h"
#include "serd/writer.h"
+#include "zix/allocator.h"
#include "zix/string_view.h"
#include <stdarg.h>
@@ -49,8 +49,8 @@ typedef struct {
// Context for the pattern event callback
typedef struct {
- SerdAllocator* allocator;
- FilterPattern pattern;
+ ZixAllocator* allocator;
+ FilterPattern pattern;
} PatternEventContext;
// Handler for events read from a pattern
@@ -58,7 +58,7 @@ static SerdStatus
on_pattern_event(void* const handle, const SerdEvent* const event)
{
PatternEventContext* const ctx = (PatternEventContext*)handle;
- SerdAllocator* const allocator = ctx->allocator;
+ ZixAllocator* const allocator = ctx->allocator;
if (event->type == SERD_STATEMENT) {
FilterPattern* const pat = &ctx->pattern;
@@ -83,9 +83,9 @@ parse_pattern(SerdWorld* const world,
SerdInputStream* const in,
const bool inclusive)
{
- SerdAllocator* const allocator = serd_world_allocator(world);
- SerdEnv* const env = serd_env_new(allocator, zix_empty_string());
- PatternEventContext ctx = {allocator, {NULL, NULL, NULL, NULL}};
+ ZixAllocator* const allocator = serd_world_allocator(world);
+ SerdEnv* const env = serd_env_new(allocator, zix_empty_string());
+ PatternEventContext ctx = {allocator, {NULL, NULL, NULL, NULL}};
SerdSink* in_sink = serd_sink_new(allocator, &ctx, on_pattern_event, NULL);
SerdReader* reader =