From 30487c277ac5d4be5786733ca7b98adb4c810ae9 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 27 Oct 2021 14:15:31 -0400 Subject: Add custom allocator support --- src/caret.c | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) (limited to 'src/caret.c') diff --git a/src/caret.c b/src/caret.c index b6911468..67abbadb 100644 --- a/src/caret.c +++ b/src/caret.c @@ -16,40 +16,54 @@ #include "caret.h" +#include "memory.h" + #include #include #include #include SerdCaret* -serd_caret_new(const SerdNode* name, unsigned line, unsigned col) +serd_caret_new(SerdAllocator* const allocator, + const SerdNode* const name, + const unsigned line, + const unsigned col) { assert(name); - SerdCaret* caret = (SerdCaret*)malloc(sizeof(SerdCaret)); + SerdCaret* const caret = + (SerdCaret*)serd_amalloc(allocator, sizeof(SerdCaret)); + + if (caret) { + caret->file = name; + caret->line = line; + caret->col = col; + } - caret->file = name; - caret->line = line; - caret->col = col; return caret; } SerdCaret* -serd_caret_copy(const SerdCaret* caret) +serd_caret_copy(SerdAllocator* const allocator, const SerdCaret* caret) { if (!caret) { return NULL; } - SerdCaret* copy = (SerdCaret*)malloc(sizeof(SerdCaret)); - memcpy(copy, caret, sizeof(SerdCaret)); + SerdCaret* const copy = + (SerdCaret*)serd_amalloc(allocator, sizeof(SerdCaret)); + + if (copy) { + memcpy(copy, caret, sizeof(SerdCaret)); + } + return copy; } void -serd_caret_free(SerdCaret* caret) +serd_caret_free(SerdAllocator* const allocator, SerdCaret* caret) { - free(caret); + serd_afree(allocator, caret); } bool -- cgit v1.2.1