From 9f9f9eaa096e6be8c1613014868e919d6991b188 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Sun, 24 Apr 2022 19:24:47 -0700 Subject: *: s/void */til_setup_t */ This brings something resembling an actual type to the private objects returrned in *res_setup. Internally libtil/rototiller wants this to be a til_setup_t, and it's up to the private users of what's returned in *res_setup to embed this appropriately and either use container_of() or casting when simply embedded at the start to go between til_setup_t and their private containing struct. Everywhere *res_setup was previously allocated using calloc() is now using til_setup_new() with a free_func, which til_setup_new() will initialize appropriately. There's still some remaining work to do with the supplied free_func in some modules, where free() isn't quite appropriate. Setup freeing isn't actually being performed yet, but this sets the foundation for that to happen in a subsequent commit that cleans up the setup leaks. Many modules use a static default setup for when no setup has been provided. In those cases, the free_func would be NULL, which til_setup_new() refuses to do. When setup freeing actually starts happening, it'll simply skip freeing when til_setup_t.free_func is NULL. --- src/modules/checkers/checkers.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/modules/checkers/checkers.c') diff --git a/src/modules/checkers/checkers.c b/src/modules/checkers/checkers.c index a88f17c..2b626e7 100644 --- a/src/modules/checkers/checkers.c +++ b/src/modules/checkers/checkers.c @@ -41,6 +41,7 @@ typedef enum checkers_dynamics_t { } checkers_dynamics_t; typedef struct checkers_setup_t { + til_setup_t til_setup; unsigned size; checkers_pattern_t pattern; checkers_dynamics_t dynamics; @@ -60,12 +61,12 @@ static checkers_setup_t checkers_default_setup = { }; -static void * checkers_create_context(unsigned ticks, unsigned num_cpus, void *setup) +static void * checkers_create_context(unsigned ticks, unsigned num_cpus, til_setup_t *setup) { checkers_context_t *ctxt; if (!setup) - setup = &checkers_default_setup; + setup = &checkers_default_setup.til_setup; ctxt = calloc(1, sizeof(checkers_context_t)); if (!ctxt) @@ -150,7 +151,7 @@ static void checkers_render_fragment(void *context, unsigned ticks, unsigned cpu } -static int checkers_setup(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, void **res_setup) +static int checkers_setup(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, til_setup_t **res_setup) { const char *size; const char *pattern; @@ -252,7 +253,7 @@ static int checkers_setup(const til_settings_t *settings, til_setting_t **res_se if (res_setup) { checkers_setup_t *setup; - setup = calloc(1, sizeof(*setup)); + setup = til_setup_new(sizeof(*setup), (void(*)(til_setup_t *))free); if (!setup) return -ENOMEM; @@ -283,7 +284,7 @@ static int checkers_setup(const til_settings_t *settings, til_setting_t **res_se if (setup->dynamics != CHECKERS_DYNAMICS_ODD && setup->dynamics != CHECKERS_DYNAMICS_EVEN) sscanf(dynamics_rate, "%f", &setup->rate); - *res_setup = setup; + *res_setup = &setup->til_setup; } return 0; -- cgit v1.2.3