diff options
author | David Robillard <d@drobilla.net> | 2023-09-10 15:06:42 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2023-12-02 18:49:08 -0500 |
commit | 248a874d7425749d29cf900a1c3783c624ea8d8c (patch) | |
tree | aed59f5a484a815cd254506866e98a947858904d /src/sink.c | |
parent | 0bd10132c6707353dba80bd89cf0102ee7ca4e34 (diff) | |
download | serd-248a874d7425749d29cf900a1c3783c624ea8d8c.tar.gz serd-248a874d7425749d29cf900a1c3783c624ea8d8c.tar.bz2 serd-248a874d7425749d29cf900a1c3783c624ea8d8c.zip |
Add support for custom allocators
This makes it explicit in the API where memory is allocated, and allows the
user to provide a custom allocator to avoid the use of the default system
allocator for whatever reason.
Diffstat (limited to 'src/sink.c')
-rw-r--r-- | src/sink.c | 21 |
1 files changed, 13 insertions, 8 deletions
@@ -3,6 +3,7 @@ #include "sink.h" +#include "memory.h" #include "statement.h" #include "serd/node.h" @@ -14,15 +15,19 @@ #include <stdlib.h> SerdSink* -serd_sink_new(void* const handle, - SerdEventFunc event_func, - SerdFreeFunc free_handle) +serd_sink_new(SerdAllocator* const allocator, + void* const handle, + SerdEventFunc event_func, + SerdFreeFunc free_handle) { - SerdSink* sink = (SerdSink*)calloc(1, sizeof(SerdSink)); + SerdSink* sink = (SerdSink*)serd_acalloc(allocator, 1, sizeof(SerdSink)); - sink->handle = handle; - sink->on_event = event_func; - sink->free_handle = free_handle; + if (sink) { + sink->allocator = allocator; + sink->handle = handle; + sink->on_event = event_func; + sink->free_handle = free_handle; + } return sink; } @@ -35,7 +40,7 @@ serd_sink_free(SerdSink* sink) sink->free_handle(sink->handle); } - free(sink); + serd_afree(sink->allocator, sink); } } |