From 020c6b59045f04b14a0898d2c373b6a09b39fe31 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Mon, 20 Apr 2020 13:59:10 -0700 Subject: libstage: return stage_t* from stage_replace() also from internal _stage_set_object() for better ergonomics --- src/stage.c | 12 ++++++------ src/stage.h | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/stage.c b/src/stage.c index 4d18486..13519b9 100644 --- a/src/stage.c +++ b/src/stage.c @@ -39,7 +39,7 @@ struct stage_t { /* minimally initialize a stage to carry an object */ -static void _stage_set_object(stage_t *stage, const char *name, const stage_ops_t *ops, void *object) +static stage_t * _stage_set_object(stage_t *stage, const char *name, const stage_ops_t *ops, void *object) { static stage_ops_t null_ops = {}; @@ -52,6 +52,8 @@ static void _stage_set_object(stage_t *stage, const char *name, const stage_ops_ strncpy(stage->name, name, sizeof(stage->name)); stage->ops = ops; stage->object = object; + + return stage; } @@ -68,9 +70,7 @@ static stage_t * _stage_new(const char *name, const stage_ops_t *ops, void *obje for (int i = 0; i < STAGE_LAYERS_MAX; i++) dll_init(&stage->layers[i]); - _stage_set_object(stage, name, ops, object); - - return stage; + return _stage_set_object(stage, name, ops, object); } @@ -115,14 +115,14 @@ stage_t * stage_new(const stage_conf_t *conf, const stage_ops_t *ops, void *obje /* replaces a given stage's object-related properties but otherwise keeping the existing state */ -void stage_replace(stage_t *stage, const char *name, const stage_ops_t *ops, void *object) +stage_t * stage_replace(stage_t *stage, const char *name, const stage_ops_t *ops, void *object) { assert(stage); if (stage->ops->free_func) stage->ops->free_func(stage, stage->object); - _stage_set_object(stage, name, ops, object); + return _stage_set_object(stage, name, ops, object); } diff --git a/src/stage.h b/src/stage.h index d1c8e69..ec0a72b 100644 --- a/src/stage.h +++ b/src/stage.h @@ -43,7 +43,7 @@ typedef struct stage_conf_t { } stage_conf_t; stage_t * stage_new(const stage_conf_t *conf, const stage_ops_t *ops, void *object); -void stage_replace(stage_t *stage, const char *name, const stage_ops_t *ops, void *object); +stage_t * stage_replace(stage_t *stage, const char *name, const stage_ops_t *ops, void *object); stage_t * stage_free(stage_t *stage); int stage_render(stage_t *stage, void *render_ctxt); -- cgit v1.2.3