From 84a34fcd489187279e54201e9b56e049b5048892 Mon Sep 17 00:00:00 2001 From: TazyFoundSoup Date: Mon, 30 Mar 2026 13:48:56 +1100 Subject: feat(common): Create ff_ctx initialiser --- src/common.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/common.c b/src/common.c index ad7be7b..c0bf478 100644 --- a/src/common.c +++ b/src/common.c @@ -1,5 +1,41 @@ +#include #include +#ifdef USE_HOSTED +#include +#endif + + +// Initializes a new tinyff context. +ff_ctx* ff_init(ff_allocator* allocator) +{ + +#ifdef USE_HOSTED + ff_allocator default_alloc = { malloc, free, calloc }; + if (!allocator) allocator = &default_alloc; +#else + if (!allocator) return NULL; +#endif + + ff_ctx* ctx = allocator->ff_alloc(sizeof(ff_ctx)); + + if (!ctx) return NULL; + + ctx->ff_debug_enabled = FF_DISABLE; + ctx->ff_debug_stream = NULL; + + ctx->allocator = *allocator; + + return ctx; +} + +void ff_cleanup(ff_ctx *ctx) { + if (!ctx) return; + ff_dprintf(ctx, "goodbye from tinyff ;]"); + ctx->allocator.ff_free(ctx); + +} + // Endian functions moved to header because C's acting up again // Anyway, while you're here, lets have a talk. // Listen, life isnt easy. but listen, storms make stronger sailors. -- cgit v1.2.3