check if layout-demand-handler exists every time it is called

This commit is contained in:
Leon Henrik Plickat
2023-12-29 11:38:26 +01:00
parent 098f15860c
commit 2e409596cf

View File

@@ -56,12 +56,33 @@ static bool scm2uint(uint32_t *x, SCM s)
return true; 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) static void *call_layout_demand_handler (void *data)
{ {
struct Layout_demand_parameters *params = (struct Layout_demand_parameters *)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 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->view_count),
scm_from_uint32(params->width), scm_from_uint32(params->width),
scm_from_uint32(params->height) scm_from_uint32(params->height)
@@ -320,14 +341,8 @@ static void *load_script (void *data)
scm_primitive_load_path(scm_from_utf8_string(path)); scm_primitive_load_path(scm_from_utf8_string(path));
/* Check if the handler has been defined. */ /* Check if the handler has been defined. */
SCM variable = scm_module_variable( SCM layout_demand_handler = scm_c_get_variable("layout-demand-handler");
scm_current_module(), if ( scm_is_false(layout_demand_handler) == 1 )
scm_string_to_symbol(
scm_from_utf8_string("layout-demand-handler")
)
);
if ( scm_is_false(variable) == 1 )
{ {
ret = EXIT_FAILURE; ret = EXIT_FAILURE;
loop = false; loop = false;