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 ++++++----- src/modules/compose/compose.c | 21 +++++++++++++-------- src/modules/drizzle/drizzle.c | 11 ++++++----- src/modules/flui2d/flui2d.c | 17 +++++++++-------- src/modules/julia/julia.c | 2 +- src/modules/meta2d/meta2d.c | 2 +- src/modules/montage/montage.c | 6 +++--- src/modules/pixbounce/pixbounce.c | 2 +- src/modules/plasma/plasma.c | 2 +- src/modules/plato/plato.c | 2 +- src/modules/ray/ray.c | 2 +- src/modules/roto/roto.c | 2 +- src/modules/rtv/rtv.c | 22 ++++++++++++---------- src/modules/snow/snow.c | 2 +- src/modules/sparkler/sparkler.c | 11 ++++++----- src/modules/spiro/spiro.c | 2 +- src/modules/stars/stars.c | 11 ++++++----- src/modules/submit/submit.c | 11 ++++++----- src/modules/swab/swab.c | 2 +- src/modules/swarm/swarm.c | 11 ++++++----- 20 files changed, 83 insertions(+), 69 deletions(-) (limited to 'src/modules') 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; diff --git a/src/modules/compose/compose.c b/src/modules/compose/compose.c index 180df44..0fa1204 100644 --- a/src/modules/compose/compose.c +++ b/src/modules/compose/compose.c @@ -37,14 +37,15 @@ typedef struct compose_context_t { } compose_context_t; typedef struct compose_setup_t { + til_setup_t til_setup; size_t n_layers; char *layers[]; } compose_setup_t; -static void * compose_create_context(unsigned ticks, unsigned num_cpus, void *setup); +static void * compose_create_context(unsigned ticks, unsigned num_cpus, til_setup_t *setup); static void compose_destroy_context(void *context); static void compose_prepare_frame(void *context, unsigned ticks, unsigned n_cpus, til_fb_fragment_t *fragment, til_fragmenter_t *res_fragmenter); -static int compose_setup(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, void **res_setup); +static int compose_setup(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, til_setup_t **res_setup); static compose_setup_t compose_default_setup = { .layers = { "drizzle", "stars", "spiro", "plato", NULL }, @@ -61,13 +62,13 @@ til_module_t compose_module = { }; -static void * compose_create_context(unsigned ticks, unsigned num_cpus, void *setup) +static void * compose_create_context(unsigned ticks, unsigned num_cpus, til_setup_t *setup) { compose_context_t *ctxt; size_t n; if (!setup) - setup = &compose_default_setup; + setup = &compose_default_setup.til_setup; for (n = 0; ((compose_setup_t *)setup)->layers[n]; n++); @@ -79,7 +80,7 @@ static void * compose_create_context(unsigned ticks, unsigned num_cpus, void *se for (int i = 0; i < n; i++) { const til_module_t *layer_module; - void *layer_setup = NULL; + til_setup_t *layer_setup = NULL; layer_module = til_lookup_module(((compose_setup_t *)setup)->layers[i]); (void) til_module_randomize_setup(layer_module, &layer_setup, NULL); @@ -117,7 +118,7 @@ static void compose_prepare_frame(void *context, unsigned ticks, unsigned n_cpus } -static int compose_setup(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, void **res_setup) +static int compose_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 *layers; int r; @@ -137,7 +138,7 @@ static int compose_setup(const til_settings_t *settings, til_setting_t **res_set /* turn layers colon-separated list into a null-terminated array of strings */ if (res_setup) { - compose_setup_t *setup = NULL; + compose_setup_t *setup; const til_module_t **modules; size_t n_modules; char *toklayers, *layer; @@ -153,6 +154,10 @@ static int compose_setup(const til_settings_t *settings, til_setting_t **res_set if (!layer) return -EINVAL; + setup = til_setup_new(sizeof(*setup), (void(*)(til_setup_t *))free); + if (!setup) + return -ENOMEM; + do { compose_setup_t *new; size_t i; @@ -184,7 +189,7 @@ static int compose_setup(const til_settings_t *settings, til_setting_t **res_set setup = new; } while (layer = strtok(NULL, ":")); - *res_setup = setup; + *res_setup = &setup->til_setup; } return 0; diff --git a/src/modules/drizzle/drizzle.c b/src/modules/drizzle/drizzle.c index d3d3c3e..2fa3b75 100644 --- a/src/modules/drizzle/drizzle.c +++ b/src/modules/drizzle/drizzle.c @@ -36,6 +36,7 @@ typedef struct v2f_t { } v2f_t; typedef struct drizzle_setup_t { + til_setup_t til_setup; float viscosity; } drizzle_setup_t; @@ -72,12 +73,12 @@ static inline uint32_t color_to_uint32(v3f_t color) { } -static void * drizzle_create_context(unsigned ticks, unsigned num_cpus, void *setup) +static void * drizzle_create_context(unsigned ticks, unsigned num_cpus, til_setup_t *setup) { drizzle_context_t *ctxt; if (!setup) - setup = &drizzle_default_setup; + setup = &drizzle_default_setup.til_setup; ctxt = calloc(1, sizeof(drizzle_context_t)); if (!ctxt) @@ -165,7 +166,7 @@ static void drizzle_render_fragment(void *context, unsigned ticks, unsigned cpu, } -static int drizzle_setup(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, void **res_setup) +static int drizzle_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 *viscosity; const char *values[] = { @@ -195,13 +196,13 @@ static int drizzle_setup(const til_settings_t *settings, til_setting_t **res_set if (res_setup) { drizzle_setup_t *setup; - setup = calloc(1, sizeof(*setup)); + setup = til_setup_new(sizeof(*setup), (void(*)(til_setup_t *))free); if (!setup) return -ENOMEM; sscanf(viscosity, "%f", &setup->viscosity); - *res_setup = setup; + *res_setup = &setup->til_setup; } return 0; diff --git a/src/modules/flui2d/flui2d.c b/src/modules/flui2d/flui2d.c index d5b3b72..1c2715d 100644 --- a/src/modules/flui2d/flui2d.c +++ b/src/modules/flui2d/flui2d.c @@ -181,9 +181,10 @@ typedef struct flui2d_context_t { } flui2d_context_t; typedef struct flui2d_setup_t { - float viscosity; - float diffusion; - float decay; + til_setup_t til_setup; + float viscosity; + float diffusion; + float decay; } flui2d_setup_t; static flui2d_setup_t flui2d_default_setup = { @@ -193,12 +194,12 @@ static flui2d_setup_t flui2d_default_setup = { }; -static void * flui2d_create_context(unsigned ticks, unsigned num_cpus, void *setup) +static void * flui2d_create_context(unsigned ticks, unsigned num_cpus, til_setup_t *setup) { flui2d_context_t *ctxt; if (!setup) - setup = &flui2d_default_setup; + setup = &flui2d_default_setup.til_setup; ctxt = calloc(1, sizeof(flui2d_context_t)); if (!ctxt) @@ -294,7 +295,7 @@ static void flui2d_render_fragment(void *context, unsigned ticks, unsigned cpu, /* Settings hooks for configurable variables */ -static int flui2d_setup(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, void **res_setup) +static int flui2d_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 *viscosity; const char *diffusion; @@ -368,7 +369,7 @@ static int flui2d_setup(const til_settings_t *settings, til_setting_t **res_sett if (res_setup) { flui2d_setup_t *setup; - setup = calloc(1, sizeof(*setup)); + setup = til_setup_new(sizeof(*setup), (void(*)(til_setup_t *))free); if (!setup) return -ENOMEM; @@ -383,7 +384,7 @@ static int flui2d_setup(const til_settings_t *settings, til_setting_t **res_sett return -EINVAL; } - *res_setup = setup; + *res_setup = &setup->til_setup; } return 0; diff --git a/src/modules/julia/julia.c b/src/modules/julia/julia.c index dfe6726..fb3bdae 100644 --- a/src/modules/julia/julia.c +++ b/src/modules/julia/julia.c @@ -66,7 +66,7 @@ static uint32_t colors[] = { }; -static void * julia_create_context(unsigned ticks, unsigned num_cpus, void *setup) +static void * julia_create_context(unsigned ticks, unsigned num_cpus, til_setup_t *setup) { return calloc(1, sizeof(julia_context_t)); } diff --git a/src/modules/meta2d/meta2d.c b/src/modules/meta2d/meta2d.c index 4e8024b..8edff42 100644 --- a/src/modules/meta2d/meta2d.c +++ b/src/modules/meta2d/meta2d.c @@ -66,7 +66,7 @@ static inline uint32_t color_to_uint32(v3f_t color) { } -static void * meta2d_create_context(unsigned ticks, unsigned num_cpus, void *setup) +static void * meta2d_create_context(unsigned ticks, unsigned num_cpus, til_setup_t *setup) { meta2d_context_t *ctxt; diff --git a/src/modules/montage/montage.c b/src/modules/montage/montage.c index 15c1354..268d7db 100644 --- a/src/modules/montage/montage.c +++ b/src/modules/montage/montage.c @@ -16,7 +16,7 @@ typedef struct montage_context_t { } montage_context_t; static void setup_next_module(montage_context_t *ctxt); -static void * montage_create_context(unsigned ticks, unsigned num_cpus, void *setup); +static void * montage_create_context(unsigned ticks, unsigned num_cpus, til_setup_t *setup); static void montage_destroy_context(void *context); static void montage_prepare_frame(void *context, unsigned ticks, unsigned n_cpus, til_fb_fragment_t *fragment, til_fragmenter_t *res_fragmenter); static void montage_render_fragment(void *context, unsigned ticks, unsigned cpu, til_fb_fragment_t *fragment); @@ -32,7 +32,7 @@ til_module_t montage_module = { }; -static void * montage_create_context(unsigned ticks, unsigned num_cpus, void *setup) +static void * montage_create_context(unsigned ticks, unsigned num_cpus, til_setup_t *setup) { const til_module_t **modules, *rtv_module, *compose_module; size_t n_modules; @@ -88,7 +88,7 @@ static void * montage_create_context(unsigned ticks, unsigned num_cpus, void *se for (size_t i = 0; i < ctxt->n_modules; i++) { const til_module_t *module = ctxt->modules[i]; - void *setup = NULL; + til_setup_t *setup = NULL; (void) til_module_randomize_setup(module, &setup, NULL); diff --git a/src/modules/pixbounce/pixbounce.c b/src/modules/pixbounce/pixbounce.c index ff2d990..5f54644 100644 --- a/src/modules/pixbounce/pixbounce.c +++ b/src/modules/pixbounce/pixbounce.c @@ -109,7 +109,7 @@ static int pick_pix(int num_pics, int last_pic) return pix_num; } -static void * pixbounce_create_context(unsigned ticks, unsigned num_cpus, void *setup) +static void * pixbounce_create_context(unsigned ticks, unsigned num_cpus, til_setup_t *setup) { pixbounce_context_t *ctxt; diff --git a/src/modules/plasma/plasma.c b/src/modules/plasma/plasma.c index c6380ef..81540c5 100644 --- a/src/modules/plasma/plasma.c +++ b/src/modules/plasma/plasma.c @@ -52,7 +52,7 @@ static void init_plasma(int32_t *costab, int32_t *sintab) } -static void * plasma_create_context(unsigned ticks, unsigned num_cpus, void *setup) +static void * plasma_create_context(unsigned ticks, unsigned num_cpus, til_setup_t *setup) { static int initialized; diff --git a/src/modules/plato/plato.c b/src/modules/plato/plato.c index 5942d93..bc38f2d 100644 --- a/src/modules/plato/plato.c +++ b/src/modules/plato/plato.c @@ -609,7 +609,7 @@ static void draw_polyhedron(const polyhedron_t *polyhedron, m4f_t *transform, ti } -static void * plato_create_context(unsigned ticks, unsigned num_cpus, void *setup) +static void * plato_create_context(unsigned ticks, unsigned num_cpus, til_setup_t *setup) { plato_context_t *ctxt; diff --git a/src/modules/ray/ray.c b/src/modules/ray/ray.c index 79e14ce..49d3371 100644 --- a/src/modules/ray/ray.c +++ b/src/modules/ray/ray.c @@ -130,7 +130,7 @@ typedef struct ray_context_t { } ray_context_t; -static void * ray_create_context(unsigned ticks, unsigned num_cpus, void *setup) +static void * ray_create_context(unsigned ticks, unsigned num_cpus, til_setup_t *setup) { return calloc(1, sizeof(ray_context_t)); } diff --git a/src/modules/roto/roto.c b/src/modules/roto/roto.c index ac66987..5409970 100644 --- a/src/modules/roto/roto.c +++ b/src/modules/roto/roto.c @@ -32,7 +32,7 @@ static int32_t costab[FIXED_TRIG_LUT_SIZE], sintab[FIXED_TRIG_LUT_SIZE]; static uint8_t texture[256][256]; static color_t palette[2]; -static void * roto_create_context(unsigned ticks, unsigned num_cpus, void *setup) +static void * roto_create_context(unsigned ticks, unsigned num_cpus, til_setup_t *setup) { return calloc(1, sizeof(roto_context_t)); } 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; diff --git a/src/modules/snow/snow.c b/src/modules/snow/snow.c index f61f2e9..cd364a0 100644 --- a/src/modules/snow/snow.c +++ b/src/modules/snow/snow.c @@ -20,7 +20,7 @@ typedef struct snow_context_t { } snow_context_t; -static void * snow_create_context(unsigned ticks, unsigned n_cpus, void *setup) +static void * snow_create_context(unsigned ticks, unsigned n_cpus, til_setup_t *setup) { snow_context_t *ctxt; diff --git a/src/modules/sparkler/sparkler.c b/src/modules/sparkler/sparkler.c index ec706b9..62abfe5 100644 --- a/src/modules/sparkler/sparkler.c +++ b/src/modules/sparkler/sparkler.c @@ -17,6 +17,7 @@ #define INIT_PARTS 100 typedef struct sparkler_setup_t { + til_setup_t til_setup; unsigned show_bsp_leafs:1; unsigned show_bsp_matches:1; unsigned show_bsp_matches_affected_only:1; @@ -33,12 +34,12 @@ extern particle_ops_t simple_ops; static sparkler_setup_t sparkler_default_setup; -static void * sparkler_create_context(unsigned ticks, unsigned num_cpus, void *setup) +static void * sparkler_create_context(unsigned ticks, unsigned num_cpus, til_setup_t *setup) { sparkler_context_t *ctxt; if (!setup) - setup = &sparkler_default_setup; + setup = &sparkler_default_setup.til_setup; ctxt = calloc(1, sizeof(sparkler_context_t)); if (!ctxt) @@ -108,7 +109,7 @@ static void sparkler_render_fragment(void *context, unsigned ticks, unsigned cpu /* Settings hooks for configurable variables */ -static int sparkler_setup(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, void **res_setup) +static int sparkler_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 *show_bsp_leafs; const char *show_bsp_leafs_min_depth; @@ -192,7 +193,7 @@ static int sparkler_setup(const til_settings_t *settings, til_setting_t **res_se if (res_setup) { sparkler_setup_t *setup; - setup = calloc(1, sizeof(*setup)); + setup = til_setup_new(sizeof(*setup), (void(*)(til_setup_t *))free); if (!setup) return -ENOMEM; @@ -209,7 +210,7 @@ static int sparkler_setup(const til_settings_t *settings, til_setting_t **res_se setup->show_bsp_matches_affected_only = 1; } - *res_setup = setup; + *res_setup = &setup->til_setup; } return 0; diff --git a/src/modules/spiro/spiro.c b/src/modules/spiro/spiro.c index 546dc60..bf93b27 100644 --- a/src/modules/spiro/spiro.c +++ b/src/modules/spiro/spiro.c @@ -29,7 +29,7 @@ typedef struct spiro_context_t { } spiro_context_t; -static void * spiro_create_context(unsigned ticks, unsigned num_cpus, void *setup) +static void * spiro_create_context(unsigned ticks, unsigned num_cpus, til_setup_t *setup) { spiro_context_t *ctxt; float z; diff --git a/src/modules/stars/stars.c b/src/modules/stars/stars.c index d7093fe..150602a 100644 --- a/src/modules/stars/stars.c +++ b/src/modules/stars/stars.c @@ -35,6 +35,7 @@ typedef struct stars_context_t { } stars_context_t; typedef struct stars_setup_t { + til_setup_t til_setup; float rot_adj; } stars_setup_t; @@ -48,14 +49,14 @@ float get_random_unit_coord() { } -static void * stars_create_context(unsigned ticks, unsigned num_cpus, void *setup) +static void * stars_create_context(unsigned ticks, unsigned num_cpus, til_setup_t *setup) { stars_context_t *ctxt; float z; struct points* p_ptr = NULL; if (!setup) - setup = &stars_default_setup; + setup = &stars_default_setup.til_setup; ctxt = malloc(sizeof(stars_context_t)); if (!ctxt) @@ -211,7 +212,7 @@ static void stars_render_fragment(void *context, unsigned ticks, unsigned cpu, t ctxt->offset_y = tmp_y; } -int stars_setup(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, void **res_setup) +int stars_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 *rot_adj; const char *rot_adj_values[] = { @@ -243,13 +244,13 @@ int stars_setup(const til_settings_t *settings, til_setting_t **res_setting, con if (res_setup) { stars_setup_t *setup; - setup = calloc(1, sizeof(*setup)); + setup = til_setup_new(sizeof(*setup), (void(*)(til_setup_t *))free); if (!setup) return -ENOMEM; sscanf(rot_adj, "%f", &setup->rot_adj); - *res_setup = setup; + *res_setup = &setup->til_setup; } return 0; diff --git a/src/modules/submit/submit.c b/src/modules/submit/submit.c index e1f6008..f8e2ff0 100644 --- a/src/modules/submit/submit.c +++ b/src/modules/submit/submit.c @@ -58,6 +58,7 @@ typedef struct submit_context_t { } submit_context_t; typedef struct submit_setup_t { + til_setup_t til_setup; unsigned bilerp:1; } submit_setup_t; @@ -264,12 +265,12 @@ static void setup_grid(submit_context_t *ctxt) } -static void * submit_create_context(unsigned ticks, unsigned num_cpus, void *setup) +static void * submit_create_context(unsigned ticks, unsigned num_cpus, til_setup_t *setup) { submit_context_t *ctxt; if (!setup) - setup = &submit_default_setup; + setup = &submit_default_setup.til_setup; ctxt = calloc(1, sizeof(submit_context_t)); if (!ctxt) @@ -329,7 +330,7 @@ static void submit_render_fragment(void *context, unsigned ticks, unsigned cpu, } -static int submit_setup(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, void **res_setup) +static int submit_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 *values[] = { "off", @@ -357,14 +358,14 @@ static int submit_setup(const til_settings_t *settings, til_setting_t **res_sett if (res_setup) { submit_setup_t *setup; - setup = calloc(1, sizeof(*setup)); + setup = til_setup_new(sizeof(*setup), (void(*)(til_setup_t *))free); if (!setup) return -ENOMEM; if (!strcasecmp(bilerp, "on")) setup->bilerp = 1; - *res_setup = setup; + *res_setup = &setup->til_setup; } return 0; diff --git a/src/modules/swab/swab.c b/src/modules/swab/swab.c index b64ca2b..a635e4d 100644 --- a/src/modules/swab/swab.c +++ b/src/modules/swab/swab.c @@ -65,7 +65,7 @@ static inline uint32_t color_to_uint32(color_t color) { } -static void * swab_create_context(unsigned ticks, unsigned num_cpus, void *setup) +static void * swab_create_context(unsigned ticks, unsigned num_cpus, til_setup_t *setup) { swab_context_t *ctxt; diff --git a/src/modules/swarm/swarm.c b/src/modules/swarm/swarm.c index e708082..0d70568 100644 --- a/src/modules/swarm/swarm.c +++ b/src/modules/swarm/swarm.c @@ -48,6 +48,7 @@ typedef enum swarm_draw_style_t { } swarm_draw_style_t; typedef struct swarm_setup_t { + til_setup_t til_setup; swarm_draw_style_t draw_style; } swarm_setup_t; @@ -178,12 +179,12 @@ static inline uint32_t color_to_uint32(v3f_t color) { } -static void * swarm_create_context(unsigned ticks, unsigned num_cpus, void *setup) +static void * swarm_create_context(unsigned ticks, unsigned num_cpus, til_setup_t *setup) { swarm_context_t *ctxt; if (!setup) - setup = &swarm_default_setup; + setup = &swarm_default_setup.til_setup; ctxt = calloc(1, sizeof(swarm_context_t) + sizeof(*(ctxt->boids)) * SWARM_SIZE); if (!ctxt) @@ -421,7 +422,7 @@ static void swarm_render_fragment(void *context, unsigned ticks, unsigned cpu, t } -static int swarm_setup(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, void **res_setup) +static int swarm_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 *styles[] = { "points", @@ -448,7 +449,7 @@ static int swarm_setup(const til_settings_t *settings, til_setting_t **res_setti if (res_setup) { swarm_setup_t *setup; - setup = calloc(1, sizeof(*setup)); + setup = til_setup_new(sizeof(*setup), (void(*)(til_setup_t *))free); if (!setup) return -ENOMEM; @@ -457,7 +458,7 @@ static int swarm_setup(const til_settings_t *settings, til_setting_t **res_setti setup->draw_style = i; } - *res_setup = setup; + *res_setup = &setup->til_setup; } return 0; -- cgit v1.2.3