diff options
Diffstat (limited to 'src/world.c')
-rw-r--r-- | src/world.c | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/src/world.c b/src/world.c index f5ab2f19..2c563f15 100644 --- a/src/world.c +++ b/src/world.c @@ -4,6 +4,7 @@ #include "world.h" #include "log.h" +#include "memory.h" #include "node.h" #include "serd/node.h" @@ -13,23 +14,26 @@ #include <assert.h> #include <stdio.h> -#include <stdlib.h> #include <string.h> SerdWorld* -serd_world_new(void) +serd_world_new(SerdAllocator* const allocator) { - SerdWorld* world = (SerdWorld*)calloc(1, sizeof(SerdWorld)); - SerdNode* blank_node = serd_new_blank(serd_string("b00000000000")); + SerdAllocator* const actual = + allocator ? allocator : serd_default_allocator(); + + SerdWorld* world = (SerdWorld*)serd_acalloc(actual, 1, sizeof(SerdWorld)); + SerdNode* blank_node = serd_new_blank(actual, serd_string("b00000000000")); if (!world || !blank_node) { - serd_node_free(blank_node); - free(world); + serd_node_free(actual, blank_node); + serd_afree(actual, world); return NULL; } world->limits.reader_stack_size = 1048576U; world->limits.writer_max_depth = 128U; + world->allocator = actual; world->blank_node = blank_node; serd_log_init(&world->log); @@ -41,8 +45,8 @@ void serd_world_free(SerdWorld* const world) { if (world) { - serd_node_free(world->blank_node); - free(world); + serd_node_free(world->allocator, world->blank_node); + serd_afree(world->allocator, world); } } @@ -78,3 +82,11 @@ serd_world_get_blank(SerdWorld* const world) #undef BLANK_CHARS } + +SerdAllocator* +serd_world_allocator(const SerdWorld* const world) +{ + assert(world); + assert(world->allocator); + return world->allocator; +} |