From 5e647dee95763d8f628bdc771a32c5d33c51d78a Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Thu, 19 Jan 2023 21:00:40 -0800 Subject: til: pass module to .context_create()/til_module_context_new() Let's make it so til_module_context_t as returned from til_module_context_new() can immediately be freed via til_module_context_free(). Previously it was only after the context propagated out to til_module_context_create() that it could be freed that way, as that was where the module member was being assigned. With this change, and wiring up the module pointer into til_module_t.create_context() as well for convenient providing to til_module_context_new(), til_module_t.create_context() error paths can easily cleanup via `return til_module_context_free()` But this does require the til_module_t.destroy_context() be able to safely handle partially constructed contexts, since the mid-create failure freeing won't necessarily have all the members initialized. There will probably be some NULL derefs to fix up, but at least the contexts are zero-initialized @ new. --- src/modules/blinds/blinds.c | 4 ++-- src/modules/checkers/checkers.c | 4 ++-- src/modules/compose/compose.c | 6 +++--- src/modules/drizzle/drizzle.c | 4 ++-- src/modules/flui2d/flui2d.c | 4 ++-- src/modules/julia/julia.c | 4 ++-- src/modules/meta2d/meta2d.c | 4 ++-- src/modules/moire/moire.c | 4 ++-- src/modules/montage/montage.c | 6 +++--- src/modules/pixbounce/pixbounce.c | 4 ++-- src/modules/plasma/plasma.c | 4 ++-- src/modules/plato/plato.c | 4 ++-- src/modules/ray/ray.c | 4 ++-- src/modules/roto/roto.c | 4 ++-- src/modules/rtv/rtv.c | 6 +++--- src/modules/shapes/shapes.c | 4 ++-- src/modules/snow/snow.c | 4 ++-- src/modules/sparkler/sparkler.c | 4 ++-- src/modules/spiro/spiro.c | 4 ++-- src/modules/stars/stars.c | 4 ++-- src/modules/strobe/strobe.c | 4 ++-- src/modules/submit/submit.c | 4 ++-- src/modules/swab/swab.c | 4 ++-- src/modules/swarm/swarm.c | 4 ++-- src/modules/voronoi/voronoi.c | 4 ++-- src/til.c | 11 +++-------- src/til.h | 9 +++++---- src/til_module_context.c | 11 ++++++++--- src/til_module_context.h | 2 +- 29 files changed, 70 insertions(+), 69 deletions(-) (limited to 'src') diff --git a/src/modules/blinds/blinds.c b/src/modules/blinds/blinds.c index b0aebdb..a2cf181 100644 --- a/src/modules/blinds/blinds.c +++ b/src/modules/blinds/blinds.c @@ -37,14 +37,14 @@ static blinds_setup_t blinds_default_setup = { }; -static til_module_context_t * blinds_create_context(til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) +static til_module_context_t * blinds_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) { blinds_context_t *ctxt; if (!setup) setup = &blinds_default_setup.til_setup; - ctxt = til_module_context_new(stream, sizeof(blinds_context_t), seed, ticks, n_cpus, path); + ctxt = til_module_context_new(module, sizeof(blinds_context_t), stream, seed, ticks, n_cpus, path); if (!ctxt) return NULL; diff --git a/src/modules/checkers/checkers.c b/src/modules/checkers/checkers.c index c4a419f..bd651d5 100644 --- a/src/modules/checkers/checkers.c +++ b/src/modules/checkers/checkers.c @@ -79,7 +79,7 @@ static checkers_setup_t checkers_default_setup = { }; -static til_module_context_t * checkers_create_context(til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) +static til_module_context_t * checkers_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) { size_t size = sizeof(checkers_context_t); checkers_context_t *ctxt; @@ -90,7 +90,7 @@ static til_module_context_t * checkers_create_context(til_stream_t *stream, unsi if (((checkers_setup_t *)setup)->fill_module) size += sizeof(til_module_context_t *) * n_cpus; - ctxt = til_module_context_new(stream, size, ticks, seed, n_cpus, path); + ctxt = til_module_context_new(module, size, stream, ticks, seed, n_cpus, path); if (!ctxt) return NULL; diff --git a/src/modules/compose/compose.c b/src/modules/compose/compose.c index 38ea539..954f0d3 100644 --- a/src/modules/compose/compose.c +++ b/src/modules/compose/compose.c @@ -47,7 +47,7 @@ typedef struct compose_setup_t { char *layers[]; } compose_setup_t; -static til_module_context_t * compose_create_context(til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup); +static til_module_context_t * compose_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup); static void compose_destroy_context(til_module_context_t *context); static void compose_render_fragment(til_module_context_t *context, til_stream_t *stream, unsigned ticks, unsigned cpu, til_fb_fragment_t **fragment_ptr); 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); @@ -67,7 +67,7 @@ til_module_t compose_module = { }; -static til_module_context_t * compose_create_context(til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) +static til_module_context_t * compose_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) { compose_context_t *ctxt; size_t n; @@ -77,7 +77,7 @@ static til_module_context_t * compose_create_context(til_stream_t *stream, unsig for (n = 0; ((compose_setup_t *)setup)->layers[n]; n++); - ctxt = til_module_context_new(stream, sizeof(compose_context_t) + n * sizeof(compose_layer_t), seed, ticks, n_cpus, path); + ctxt = til_module_context_new(module, sizeof(compose_context_t) + n * sizeof(compose_layer_t), stream, seed, ticks, n_cpus, path); if (!ctxt) return NULL; diff --git a/src/modules/drizzle/drizzle.c b/src/modules/drizzle/drizzle.c index 307e0d3..56eaf83 100644 --- a/src/modules/drizzle/drizzle.c +++ b/src/modules/drizzle/drizzle.c @@ -85,14 +85,14 @@ static inline uint32_t color_to_uint32(v3f_t color) { } -static til_module_context_t * drizzle_create_context(til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) +static til_module_context_t * drizzle_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) { drizzle_context_t *ctxt; if (!setup) setup = &drizzle_default_setup.til_setup; - ctxt = til_module_context_new(stream, sizeof(drizzle_context_t), seed, ticks, n_cpus, path); + ctxt = til_module_context_new(module, sizeof(drizzle_context_t), stream, seed, ticks, n_cpus, path); if (!ctxt) return NULL; diff --git a/src/modules/flui2d/flui2d.c b/src/modules/flui2d/flui2d.c index 9ae3e94..bbebcc6 100644 --- a/src/modules/flui2d/flui2d.c +++ b/src/modules/flui2d/flui2d.c @@ -245,7 +245,7 @@ static void gamma_init(float gamma) } -static til_module_context_t * flui2d_create_context(til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) +static til_module_context_t * flui2d_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) { static int initialized; flui2d_context_t *ctxt; @@ -253,7 +253,7 @@ static til_module_context_t * flui2d_create_context(til_stream_t *stream, unsign if (!setup) setup = &flui2d_default_setup.til_setup; - ctxt = til_module_context_new(stream, sizeof(flui2d_context_t), seed, ticks, n_cpus, path); + ctxt = til_module_context_new(module, sizeof(flui2d_context_t), stream, seed, ticks, n_cpus, path); if (!ctxt) return NULL; diff --git a/src/modules/julia/julia.c b/src/modules/julia/julia.c index 65a15b6..c01059c 100644 --- a/src/modules/julia/julia.c +++ b/src/modules/julia/julia.c @@ -67,11 +67,11 @@ static uint32_t colors[] = { }; -static til_module_context_t * julia_create_context(til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) +static til_module_context_t * julia_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) { julia_context_t *ctxt; - ctxt = til_module_context_new(stream, sizeof(julia_context_t), seed, ticks, n_cpus, path); + ctxt = til_module_context_new(module, sizeof(julia_context_t), stream, seed, ticks, n_cpus, path); if (!ctxt) return NULL; diff --git a/src/modules/meta2d/meta2d.c b/src/modules/meta2d/meta2d.c index 6d9d307..891b355 100644 --- a/src/modules/meta2d/meta2d.c +++ b/src/modules/meta2d/meta2d.c @@ -67,11 +67,11 @@ static inline uint32_t color_to_uint32(v3f_t color) { } -static til_module_context_t * meta2d_create_context(til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) +static til_module_context_t * meta2d_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) { meta2d_context_t *ctxt; - ctxt = til_module_context_new(stream, sizeof(meta2d_context_t), seed, ticks, n_cpus, path); + ctxt = til_module_context_new(module, sizeof(meta2d_context_t), stream, seed, ticks, n_cpus, path); if (!ctxt) return NULL; diff --git a/src/modules/moire/moire.c b/src/modules/moire/moire.c index b010cdd..736a3bf 100644 --- a/src/modules/moire/moire.c +++ b/src/modules/moire/moire.c @@ -47,14 +47,14 @@ static moire_setup_t moire_default_setup = { }; -static til_module_context_t * moire_create_context(til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) +static til_module_context_t * moire_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) { moire_context_t *ctxt; if (!setup) setup = &moire_default_setup.til_setup; - ctxt = til_module_context_new(stream, sizeof(moire_context_t) + ((moire_setup_t *)setup)->n_centers * sizeof(moire_center_t), seed, ticks, n_cpus, path); + ctxt = til_module_context_new(module, sizeof(moire_context_t) + ((moire_setup_t *)setup)->n_centers * sizeof(moire_center_t), stream, seed, ticks, n_cpus, path); if (!ctxt) return NULL; diff --git a/src/modules/montage/montage.c b/src/modules/montage/montage.c index 9315e79..2d4314a 100644 --- a/src/modules/montage/montage.c +++ b/src/modules/montage/montage.c @@ -16,7 +16,7 @@ typedef struct montage_context_t { size_t n_modules; } montage_context_t; -static til_module_context_t * montage_create_context(til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup); +static til_module_context_t * montage_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup); static void montage_destroy_context(til_module_context_t *context); static void montage_prepare_frame(til_module_context_t *context, til_stream_t *stream, unsigned ticks, til_fb_fragment_t **fragment_ptr, til_frame_plan_t *res_frame_plan); static void montage_render_fragment(til_module_context_t *context, til_stream_t *stream, unsigned ticks, unsigned cpu, til_fb_fragment_t **fragment_ptr); @@ -32,13 +32,13 @@ til_module_t montage_module = { }; -static til_module_context_t * montage_create_context(til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) +static til_module_context_t * montage_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) { const til_module_t **modules, *rtv_module, *compose_module; size_t n_modules; montage_context_t *ctxt; - ctxt = til_module_context_new(stream, sizeof(montage_context_t), seed, ticks, n_cpus, path); + ctxt = til_module_context_new(module, sizeof(montage_context_t), stream, seed, ticks, n_cpus, path); if (!ctxt) return NULL; diff --git a/src/modules/pixbounce/pixbounce.c b/src/modules/pixbounce/pixbounce.c index 8a26be2..7fa7f34 100644 --- a/src/modules/pixbounce/pixbounce.c +++ b/src/modules/pixbounce/pixbounce.c @@ -240,11 +240,11 @@ static uint32_t pick_color(unsigned *seedp) return makergb(rand_r(seedp)%256, rand_r(seedp)%256, rand_r(seedp)%256, 1); } -static til_module_context_t * pixbounce_create_context(til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) +static til_module_context_t * pixbounce_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) { pixbounce_context_t *ctxt; - ctxt = til_module_context_new(stream, sizeof(pixbounce_context_t), seed, ticks, n_cpus, path); + ctxt = til_module_context_new(module, sizeof(pixbounce_context_t), stream, seed, ticks, n_cpus, path); if (!ctxt) return NULL; diff --git a/src/modules/plasma/plasma.c b/src/modules/plasma/plasma.c index c42efd2..e6d71dd 100644 --- a/src/modules/plasma/plasma.c +++ b/src/modules/plasma/plasma.c @@ -53,7 +53,7 @@ static void init_plasma(int32_t *costab, int32_t *sintab) } -static til_module_context_t * plasma_create_context(til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) +static til_module_context_t * plasma_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) { static int initialized; plasma_context_t *ctxt; @@ -64,7 +64,7 @@ static til_module_context_t * plasma_create_context(til_stream_t *stream, unsign init_plasma(costab, sintab); } - ctxt = til_module_context_new(stream, sizeof(plasma_context_t), seed, ticks, n_cpus, path); + ctxt = til_module_context_new(module, sizeof(plasma_context_t), stream, seed, ticks, n_cpus, path); if (!ctxt) return NULL; diff --git a/src/modules/plato/plato.c b/src/modules/plato/plato.c index 4334eda..c8977bf 100644 --- a/src/modules/plato/plato.c +++ b/src/modules/plato/plato.c @@ -630,11 +630,11 @@ static void draw_polyhedron(const polyhedron_t *polyhedron, m4f_t *transform, ti } -static til_module_context_t * plato_create_context(til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) +static til_module_context_t * plato_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) { plato_context_t *ctxt; - ctxt = til_module_context_new(stream, sizeof(plato_context_t), seed, ticks, n_cpus, path); + ctxt = til_module_context_new(module, sizeof(plato_context_t), stream, seed, ticks, n_cpus, path); if (!ctxt) return NULL; diff --git a/src/modules/ray/ray.c b/src/modules/ray/ray.c index 0017da3..36532bf 100644 --- a/src/modules/ray/ray.c +++ b/src/modules/ray/ray.c @@ -132,11 +132,11 @@ typedef struct ray_context_t { } ray_context_t; -static til_module_context_t * ray_create_context(til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) +static til_module_context_t * ray_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) { ray_context_t *ctxt; - ctxt = til_module_context_new(stream, sizeof(ray_context_t), seed, ticks, n_cpus, path); + ctxt = til_module_context_new(module, sizeof(ray_context_t), stream, seed, ticks, n_cpus, path); if (!ctxt) return NULL; diff --git a/src/modules/roto/roto.c b/src/modules/roto/roto.c index 1b20e2e..3883ce5 100644 --- a/src/modules/roto/roto.c +++ b/src/modules/roto/roto.c @@ -62,7 +62,7 @@ static void init_roto(uint8_t texture[256][256], int32_t *costab, int32_t *sinta } -static til_module_context_t * roto_create_context(til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) +static til_module_context_t * roto_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) { static int initialized; roto_context_t *ctxt; @@ -73,7 +73,7 @@ static til_module_context_t * roto_create_context(til_stream_t *stream, unsigned init_roto(texture, costab, sintab); } - ctxt = til_module_context_new(stream, sizeof(roto_context_t), seed, ticks, n_cpus, path); + ctxt = til_module_context_new(module, sizeof(roto_context_t), stream, seed, ticks, n_cpus, path); if (!ctxt) return NULL; diff --git a/src/modules/rtv/rtv.c b/src/modules/rtv/rtv.c index 19f823b..661afc9 100644 --- a/src/modules/rtv/rtv.c +++ b/src/modules/rtv/rtv.c @@ -61,7 +61,7 @@ typedef struct rtv_setup_t { } rtv_setup_t; static void setup_next_channel(rtv_context_t *ctxt, unsigned ticks); -static til_module_context_t * rtv_create_context(til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup); +static til_module_context_t * rtv_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup); static void rtv_destroy_context(til_module_context_t *context); static void rtv_render_fragment(til_module_context_t *context, til_stream_t *stream, unsigned ticks, unsigned cpu, til_fb_fragment_t **fragment_ptr); static void rtv_finish_frame(til_module_context_t *context, til_stream_t *stream, unsigned ticks, til_fb_fragment_t **fragment_ptr); @@ -220,7 +220,7 @@ static int rtv_should_skip_module(const rtv_setup_t *setup, const til_module_t * } -static til_module_context_t * rtv_create_context(til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) +static til_module_context_t * rtv_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) { rtv_context_t *ctxt; const til_module_t **modules; @@ -237,7 +237,7 @@ static til_module_context_t * rtv_create_context(til_stream_t *stream, unsigned n_channels++; } - ctxt = til_module_context_new(stream, sizeof(rtv_context_t) + n_channels * sizeof(rtv_channel_t), seed, ticks, n_cpus, path); + ctxt = til_module_context_new(module, sizeof(rtv_context_t) + n_channels * sizeof(rtv_channel_t), stream, seed, ticks, n_cpus, path); if (!ctxt) return NULL; diff --git a/src/modules/shapes/shapes.c b/src/modules/shapes/shapes.c index 1be9f03..5073002 100644 --- a/src/modules/shapes/shapes.c +++ b/src/modules/shapes/shapes.c @@ -98,14 +98,14 @@ static shapes_setup_t shapes_default_setup = { }; -static til_module_context_t * shapes_create_context(til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) +static til_module_context_t * shapes_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) { shapes_context_t *ctxt; if (!setup) setup = &shapes_default_setup.til_setup; - ctxt = til_module_context_new(stream, sizeof(shapes_context_t), seed, ticks, n_cpus, path); + ctxt = til_module_context_new(module, sizeof(shapes_context_t), stream, seed, ticks, n_cpus, path); if (!ctxt) return NULL; diff --git a/src/modules/snow/snow.c b/src/modules/snow/snow.c index bcf1cc4..8ba0929 100644 --- a/src/modules/snow/snow.c +++ b/src/modules/snow/snow.c @@ -22,11 +22,11 @@ typedef struct snow_context_t { } snow_context_t; -static til_module_context_t * snow_create_context(til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) +static til_module_context_t * snow_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) { snow_context_t *ctxt; - ctxt = til_module_context_new(stream, sizeof(snow_context_t) + n_cpus * sizeof(snow_seed_t), seed, ticks, n_cpus, path); + ctxt = til_module_context_new(module, sizeof(snow_context_t) + n_cpus * sizeof(snow_seed_t), stream, seed, ticks, n_cpus, path); if (!ctxt) return NULL; diff --git a/src/modules/sparkler/sparkler.c b/src/modules/sparkler/sparkler.c index afe4f0f..6b27813 100644 --- a/src/modules/sparkler/sparkler.c +++ b/src/modules/sparkler/sparkler.c @@ -35,14 +35,14 @@ extern particle_ops_t simple_ops; static sparkler_setup_t sparkler_default_setup; -static til_module_context_t * sparkler_create_context(til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) +static til_module_context_t * sparkler_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) { sparkler_context_t *ctxt; if (!setup) setup = &sparkler_default_setup.til_setup; - ctxt = til_module_context_new(stream, sizeof(sparkler_context_t), seed, ticks, n_cpus, path); + ctxt = til_module_context_new(module, sizeof(sparkler_context_t), stream, seed, ticks, n_cpus, path); if (!ctxt) return NULL; diff --git a/src/modules/spiro/spiro.c b/src/modules/spiro/spiro.c index ab11aab..5c9b447 100644 --- a/src/modules/spiro/spiro.c +++ b/src/modules/spiro/spiro.c @@ -31,12 +31,12 @@ typedef struct spiro_context_t { } spiro_context_t; -static til_module_context_t * spiro_create_context(til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) +static til_module_context_t * spiro_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) { spiro_context_t *ctxt; float z; - ctxt = til_module_context_new(stream, sizeof(spiro_context_t), seed, ticks, n_cpus, path); + ctxt = til_module_context_new(module, sizeof(spiro_context_t), stream, seed, ticks, n_cpus, path); if (!ctxt) return NULL; diff --git a/src/modules/stars/stars.c b/src/modules/stars/stars.c index 26f2913..e2c9a21 100644 --- a/src/modules/stars/stars.c +++ b/src/modules/stars/stars.c @@ -70,7 +70,7 @@ float get_random_unit_coord(unsigned *seed) { } -static til_module_context_t * stars_create_context(til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) +static til_module_context_t * stars_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) { stars_context_t *ctxt; float z; @@ -79,7 +79,7 @@ static til_module_context_t * stars_create_context(til_stream_t *stream, unsigne if (!setup) setup = &stars_default_setup.til_setup; - ctxt = til_module_context_new(stream, sizeof(stars_context_t), seed, ticks, n_cpus, path); + ctxt = til_module_context_new(module, sizeof(stars_context_t), stream, seed, ticks, n_cpus, path); if (!ctxt) return NULL; diff --git a/src/modules/strobe/strobe.c b/src/modules/strobe/strobe.c index 5410ffb..7d0acbf 100644 --- a/src/modules/strobe/strobe.c +++ b/src/modules/strobe/strobe.c @@ -40,14 +40,14 @@ static strobe_setup_t strobe_default_setup = { }; -static til_module_context_t * strobe_create_context(til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) +static til_module_context_t * strobe_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) { strobe_context_t *ctxt; if (!setup) setup = &strobe_default_setup.til_setup; - ctxt = til_module_context_new(stream, sizeof(strobe_context_t), seed, ticks, n_cpus, path); + ctxt = til_module_context_new(module, sizeof(strobe_context_t), stream, seed, ticks, n_cpus, path); if (!ctxt) return NULL; diff --git a/src/modules/submit/submit.c b/src/modules/submit/submit.c index b3c7220..69e67f0 100644 --- a/src/modules/submit/submit.c +++ b/src/modules/submit/submit.c @@ -267,14 +267,14 @@ static void setup_grid(submit_context_t *ctxt) } -static til_module_context_t * submit_create_context(til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) +static til_module_context_t * submit_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) { submit_context_t *ctxt; if (!setup) setup = &submit_default_setup.til_setup; - ctxt = til_module_context_new(stream, sizeof(submit_context_t), seed, ticks, n_cpus, path); + ctxt = til_module_context_new(module, sizeof(submit_context_t), stream, seed, ticks, n_cpus, path); if (!ctxt) return NULL; diff --git a/src/modules/swab/swab.c b/src/modules/swab/swab.c index 0465de7..a94c8f5 100644 --- a/src/modules/swab/swab.c +++ b/src/modules/swab/swab.c @@ -66,11 +66,11 @@ static inline uint32_t color_to_uint32(color_t color) { } -static til_module_context_t * swab_create_context(til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) +static til_module_context_t * swab_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) { swab_context_t *ctxt; - ctxt = til_module_context_new(stream, sizeof(swab_context_t), seed, ticks, n_cpus, path); + ctxt = til_module_context_new(module, sizeof(swab_context_t), stream, seed, ticks, n_cpus, path); if (!ctxt) return NULL; diff --git a/src/modules/swarm/swarm.c b/src/modules/swarm/swarm.c index 5a58210..e1b9640 100644 --- a/src/modules/swarm/swarm.c +++ b/src/modules/swarm/swarm.c @@ -181,14 +181,14 @@ static inline uint32_t color_to_uint32(v3f_t color) { } -static til_module_context_t * swarm_create_context(til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) +static til_module_context_t * swarm_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) { swarm_context_t *ctxt; if (!setup) setup = &swarm_default_setup.til_setup; - ctxt = til_module_context_new(stream, sizeof(swarm_context_t) + sizeof(*(ctxt->boids)) * SWARM_SIZE, seed, ticks, n_cpus, path); + ctxt = til_module_context_new(module, sizeof(swarm_context_t) + sizeof(*(ctxt->boids)) * SWARM_SIZE, stream, seed, ticks, n_cpus, path); if (!ctxt) return NULL; diff --git a/src/modules/voronoi/voronoi.c b/src/modules/voronoi/voronoi.c index 647871b..c258165 100644 --- a/src/modules/voronoi/voronoi.c +++ b/src/modules/voronoi/voronoi.c @@ -80,14 +80,14 @@ static void voronoi_randomize(voronoi_context_t *ctxt) } -static til_module_context_t * voronoi_create_context(til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) +static til_module_context_t * voronoi_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) { voronoi_context_t *ctxt; if (!setup) setup = &voronoi_default_setup.til_setup; - ctxt = til_module_context_new(stream, sizeof(voronoi_context_t) + ((voronoi_setup_t *)setup)->n_cells * sizeof(voronoi_cell_t), seed, ticks, n_cpus, path); + ctxt = til_module_context_new(module, sizeof(voronoi_context_t) + ((voronoi_setup_t *)setup)->n_cells * sizeof(voronoi_cell_t), stream, seed, ticks, n_cpus, path); if (!ctxt) return NULL; diff --git a/src/til.c b/src/til.c index c00f6a3..038070b 100644 --- a/src/til.c +++ b/src/til.c @@ -248,17 +248,12 @@ int til_module_create_context(const til_module_t *module, til_stream_t *stream, n_cpus = til_threads_num_threads(til_threads); if (!module->create_context) - context = til_module_context_new(stream, sizeof(til_module_context_t), seed, ticks, n_cpus, path); + context = til_module_context_new(module, sizeof(til_module_context_t), stream, seed, ticks, n_cpus, path); else - context = module->create_context(stream, seed, ticks, n_cpus, path, setup); - - if (!context) { - free(path); + context = module->create_context(module, stream, seed, ticks, n_cpus, path, setup); + if (!context) return -ENOMEM; - } - - context->module = module; *res_context = context; diff --git a/src/til.h b/src/til.h index b074158..64cdd8a 100644 --- a/src/til.h +++ b/src/til.h @@ -15,17 +15,18 @@ typedef struct til_frame_plan_t { til_fragmenter_t fragmenter; /* fragmenter to use in rendering the frame */ } til_frame_plan_t; +typedef struct til_module_t til_module_t; +typedef struct til_knob_t til_knob_t; typedef struct til_settings_t settings; typedef struct til_setting_desc_t til_setting_desc_t; -typedef struct til_knob_t til_knob_t; typedef struct til_stream_t til_stream_t; #define TIL_MODULE_OVERLAYABLE 1u /* module is appropriate for overlay use */ #define TIL_MODULE_HERMETIC 2u /* module doesn't work readily with other modules / requires manual settings */ #define TIL_MODULE_EXPERIMENTAL 4u /* module is buggy / unfinished */ -typedef struct til_module_t { - til_module_context_t * (*create_context)(til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup); +struct til_module_t { + til_module_context_t * (*create_context)(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup); void (*destroy_context)(til_module_context_t *context); /* destroy gets stream in context, but the render-related functions should always use the passed-in stream so it can potentially change */ void (*prepare_frame)(til_module_context_t *context, til_stream_t *stream, unsigned ticks, til_fb_fragment_t **fragment_ptr, til_frame_plan_t *res_frame_plan); void (*render_fragment)(til_module_context_t *context, til_stream_t *stream, unsigned ticks, unsigned cpu, til_fb_fragment_t **fragment_ptr); @@ -36,7 +37,7 @@ typedef struct til_module_t { char *description; char *author; unsigned flags; -} til_module_t; +}; int til_init(void); void til_quiesce(void); diff --git a/src/til_module_context.c b/src/til_module_context.c index 58de3d5..e065f0d 100644 --- a/src/til_module_context.c +++ b/src/til_module_context.c @@ -26,20 +26,25 @@ * as the callers are generally using it in place of calloc(), and assign it to a * container struct of some other type but having an embedded til_module_context_t. * - * path must not be NULL, and the context takes ownership of the path; it's freed @ context_free(). + * path must not be NULL, and the context always takes ownership of the path; it's freed @ context_free(). */ -void * til_module_context_new(til_stream_t *stream, size_t size, unsigned seed, unsigned ticks, unsigned n_cpus, char *path) +void * til_module_context_new(const til_module_t *module, size_t size, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path) { til_module_context_t *module_context; + assert(module); assert(size >= sizeof(til_module_context_t)); assert(n_cpus > 0); assert(path); /* modules must be able to key things like taps off their context's path */ module_context = calloc(1, size); - if (!module_context) + if (!module_context) { + free(path); + return NULL; + } + module_context->module = module; module_context->stream = stream; module_context->seed = seed; module_context->ticks = ticks; diff --git a/src/til_module_context.h b/src/til_module_context.h index 6f4339b..a11b876 100644 --- a/src/til_module_context.h +++ b/src/til_module_context.h @@ -17,7 +17,7 @@ struct til_module_context_t { uint32_t path_hash; }; -void * til_module_context_new(til_stream_t *stream, size_t size, unsigned seed, unsigned ticks, unsigned n_cpus, char *path); +void * til_module_context_new(const til_module_t *module, size_t size, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path); void * til_module_context_free(til_module_context_t *module_context); #endif -- cgit v1.2.3