summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2022-04-01 18:22:11 -0700
committerVito Caputo <vcaputo@pengaru.com>2022-04-01 18:22:11 -0700
commit4351afc62b3dd1c7fb7f0bc563dae22ee0ec73d9 (patch)
treef604cb82ccf97d71ec4a6fede21c20eb9aa57e9b
parent6b8790a22c38e0d5419eb5a4dac5e30f684ae473 (diff)
til_settings: make res_{desc,setting} optional
The til_settings_get_and_describe_value() helper (and the calling setup methods in the modules) can be useful in independently spitting out a baked setup instance from a fully resolved til_settings_t which has already gone through the whole rigamarole of getting populated and described. Normally when this all happens in one place with the setup instance then either immediately fed to create_context(), or stowed somewhere for future use, it's not a problem to always require the res_desc,res_setting parameters. But especially in GUI scenarios (glimmer) the whole populate and describe phase of til_settings_t can very easily be done in a separate place from the convenient place to produce a setup out of it. So when the caller /knows/ the setup is finished and a subsequent call with the same til_settings_t would produce a res_setup immediately, the caller should be able to omit res_setting and res_desc as they're of no use now. This is all kind of crufty, but it's nice to have all this happening in a single setup method to help keep the res_setup phase from diverging/becoming out of sync with the populate+describe phase. Will live with it for now. Frontends get written far less than modules, so the API cruft from the frontend perspective is relatively benign. It's still relatively sane and ergonomic from the module writer's perspective.
-rw-r--r--src/til_settings.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/til_settings.c b/src/til_settings.c
index 8aa172b..35bb85c 100644
--- a/src/til_settings.c
+++ b/src/til_settings.c
@@ -188,13 +188,14 @@ int til_settings_get_and_describe_value(const til_settings_t *settings, const ti
assert(settings);
assert(desc);
assert(res_value);
- assert(res_setting);
- assert(res_desc);
value = til_settings_get_value(settings, desc->key, &setting);
if (!value || !setting->desc) {
int r;
+ assert(res_setting);
+ assert(res_desc);
+
r = til_setting_desc_clone(desc, res_desc);
if (r < 0)
return r;
@@ -206,8 +207,10 @@ int til_settings_get_and_describe_value(const til_settings_t *settings, const ti
}
*res_value = value;
- *res_setting = setting;
- *res_desc = NULL;
+ if (res_setting)
+ *res_setting = setting;
+ if (res_desc)
+ *res_desc = NULL;
return 0;
}
© All Rights Reserved