aboutsummaryrefslogtreecommitdiffstats
path: root/src/node.c
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 /src/node.c
parent258ea2ff59bbd2127ea446cf4b9676ad3d7fe53d (diff)
downloadserd-0f9816d67bc67a396607291f845ca2a33c2285a7.tar.gz
serd-0f9816d67bc67a396607291f845ca2a33c2285a7.tar.bz2
serd-0f9816d67bc67a396607291f845ca2a33c2285a7.zip
Use ZixAllocator directly
Diffstat (limited to 'src/node.c')
-rw-r--r--src/node.c29
1 files changed, 16 insertions, 13 deletions
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