diff options
author | David Robillard <d@drobilla.net> | 2021-10-27 14:15:31 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2022-01-28 21:57:24 -0500 |
commit | 30487c277ac5d4be5786733ca7b98adb4c810ae9 (patch) | |
tree | f1b00a7725d74a594fcd91de2aea924485356528 /src/cursor.c | |
parent | 56cceb103dc633d6af957472945e792187a5dd4e (diff) | |
download | serd-30487c277ac5d4be5786733ca7b98adb4c810ae9.tar.gz serd-30487c277ac5d4be5786733ca7b98adb4c810ae9.tar.bz2 serd-30487c277ac5d4be5786733ca7b98adb4c810ae9.zip |
Add custom allocator support
Diffstat (limited to 'src/cursor.c')
-rw-r--r-- | src/cursor.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/cursor.c b/src/cursor.c index 1a94142e..e3d7e35f 100644 --- a/src/cursor.c +++ b/src/cursor.c @@ -16,6 +16,7 @@ #include "cursor.h" +#include "memory.h" #include "model.h" #include "node.h" @@ -25,7 +26,6 @@ #include <assert.h> #include <stdbool.h> -#include <stdlib.h> #include <string.h> static inline bool @@ -132,14 +132,19 @@ serd_cursor_make(const SerdModel* const model, } SerdCursor* -serd_cursor_copy(const SerdCursor* const cursor) +serd_cursor_copy(SerdAllocator* const allocator, const SerdCursor* const cursor) { if (!cursor) { return NULL; } - SerdCursor* const copy = (SerdCursor* const)malloc(sizeof(SerdCursor)); - memcpy(copy, cursor, sizeof(SerdCursor)); + SerdCursor* const copy = + (SerdCursor* const)serd_amalloc(allocator, sizeof(SerdCursor)); + + if (copy) { + memcpy(copy, cursor, sizeof(SerdCursor)); + } + return copy; } @@ -223,5 +228,7 @@ serd_cursor_equals(const SerdCursor* const lhs, const SerdCursor* const rhs) void serd_cursor_free(SerdCursor* const cursor) { - free(cursor); + if (cursor) { + serd_afree(cursor->model->allocator, cursor); + } } |