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/rtv/rtv.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'src/modules/rtv') diff --git a/src/modules/rtv/rtv.c b/src/modules/rtv/rtv.c index 742b2bc..06dfd90 100644 --- a/src/modules/rtv/rtv.c +++ b/src/modules/rtv/rtv.c @@ -25,7 +25,7 @@ typedef struct rtv_channel_t { const til_module_t *module; void *module_ctxt; - void *module_setup; + til_setup_t *module_setup; time_t last_on_time, cumulative_time; char *settings; txt_t *caption; @@ -51,6 +51,7 @@ typedef struct rtv_context_t { } rtv_context_t; typedef struct rtv_setup_t { + til_setup_t til_setup; unsigned duration; unsigned context_duration; unsigned snow_duration; @@ -60,11 +61,11 @@ typedef struct rtv_setup_t { } rtv_setup_t; static void setup_next_channel(rtv_context_t *ctxt, unsigned ticks); -static void * rtv_create_context(unsigned ticks, unsigned num_cpus, void *setup); +static void * rtv_create_context(unsigned ticks, unsigned num_cpus, til_setup_t *setup); static void rtv_destroy_context(void *context); static void rtv_prepare_frame(void *context, unsigned ticks, unsigned n_cpus, til_fb_fragment_t *fragment, til_fragmenter_t *res_fragmenter); static void rtv_finish_frame(void *context, unsigned ticks, til_fb_fragment_t *fragment); -static int rtv_setup(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, void **res_setup); +static int rtv_setup(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, til_setup_t **res_setup); static rtv_setup_t rtv_default_setup = { .duration = RTV_DURATION_SECS, @@ -203,7 +204,7 @@ static int rtv_should_skip_module(const rtv_setup_t *setup, const til_module_t * } -static void * rtv_create_context(unsigned ticks, unsigned num_cpus, void *setup) +static void * rtv_create_context(unsigned ticks, unsigned num_cpus, til_setup_t *setup) { rtv_context_t *ctxt; const til_module_t **modules; @@ -211,13 +212,13 @@ static void * rtv_create_context(unsigned ticks, unsigned num_cpus, void *setup) static til_module_t none_module = {}; if (!setup) - setup = &rtv_default_setup; + setup = &rtv_default_setup.til_setup; til_get_modules(&modules, &n_modules); /* how many modules are in the setup? */ for (size_t i = 0; i < n_modules; i++) { - if (!rtv_should_skip_module(setup, modules[i])) + if (!rtv_should_skip_module((rtv_setup_t *)setup, modules[i])) n_channels++; } @@ -238,7 +239,7 @@ static void * rtv_create_context(unsigned ticks, unsigned num_cpus, void *setup) } for (size_t i = 0; i < n_modules; i++) { - if (!rtv_should_skip_module(setup, modules[i])) + if (!rtv_should_skip_module((rtv_setup_t *)setup, modules[i])) ctxt->channels[ctxt->n_channels++].module = modules[i]; } @@ -298,7 +299,7 @@ static void rtv_finish_frame(void *context, unsigned ticks, til_fb_fragment_t *f } -static int rtv_setup(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, void **res_setup) +static int rtv_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 *channels; const char *duration; @@ -393,7 +394,8 @@ static int rtv_setup(const til_settings_t *settings, til_setting_t **res_setting if (res_setup) { rtv_setup_t *setup; - setup = calloc(1, sizeof(*setup) + sizeof(setup->channels[0])); + /* FIXME: rtv_setup_t.snow_module needs freeing, so we need a bespoke free_func */ + setup = til_setup_new(sizeof(*setup) + sizeof(setup->channels[0]), (void(*)(til_setup_t *))free); if (!setup) return -ENOMEM; @@ -446,7 +448,7 @@ static int rtv_setup(const til_settings_t *settings, til_setting_t **res_setting sscanf(caption_duration, "%u", &setup->caption_duration); sscanf(snow_duration, "%u", &setup->snow_duration); - *res_setup = setup; + *res_setup = &setup->til_setup; } return 0; -- cgit v1.2.3