From 2e409596cf4f6dbcb5849fbd9994249badd9be1e Mon Sep 17 00:00:00 2001 From: Leon Henrik Plickat Date: Fri, 29 Dec 2023 11:38:26 +0100 Subject: [PATCH] check if layout-demand-handler exists every time it is called --- riverguile.c | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/riverguile.c b/riverguile.c index 0871188..2081e05 100644 --- a/riverguile.c +++ b/riverguile.c @@ -56,12 +56,33 @@ static bool scm2uint(uint32_t *x, SCM s) return true; } +/** + * Try to find a variable named 'name' and returns it, otherwise #f is returned. + */ +static SCM scm_c_get_variable (const char *name) +{ + return scm_module_variable( + scm_current_module(), + scm_string_to_symbol( + scm_from_utf8_string(name) + ) + ); +} + static void *call_layout_demand_handler (void *data) { struct Layout_demand_parameters *params = (struct Layout_demand_parameters *)data; + SCM layout_demand_handler = scm_c_get_variable("layout-demand-handler"); + if ( scm_is_false(layout_demand_handler) == 1 ) + { + ret = EXIT_FAILURE; + loop = false; + return (void *)"ERROR: layout-demand-handler no longer exists.\n"; + } + SCM call_result = scm_call_3( - scm_variable_ref(scm_c_lookup("layout-demand-handler")), + scm_variable_ref(layout_demand_handler), scm_from_uint32(params->view_count), scm_from_uint32(params->width), scm_from_uint32(params->height) @@ -320,14 +341,8 @@ static void *load_script (void *data) scm_primitive_load_path(scm_from_utf8_string(path)); /* Check if the handler has been defined. */ - SCM variable = scm_module_variable( - scm_current_module(), - scm_string_to_symbol( - scm_from_utf8_string("layout-demand-handler") - ) - ); - - if ( scm_is_false(variable) == 1 ) + SCM layout_demand_handler = scm_c_get_variable("layout-demand-handler"); + if ( scm_is_false(layout_demand_handler) == 1 ) { ret = EXIT_FAILURE; loop = false;