From 55fabac5bfcf0d160edb2afc2d9c58925541ca57 Mon Sep 17 00:00:00 2001 From: Szilard Parrag Date: Tue, 15 Oct 2024 17:35:27 +0200 Subject: [PATCH] lib/filterx: extract FilterXScope's variable validation logic Signed-off-by: Szilard Parrag --- lib/filterx/filterx-scope.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/filterx/filterx-scope.c b/lib/filterx/filterx-scope.c index 522c69378..09fd9aa8d 100644 --- a/lib/filterx/filterx-scope.c +++ b/lib/filterx/filterx-scope.c @@ -176,6 +176,15 @@ filterx_scope_map_variable_to_handle(const gchar *name, FilterXVariableType type return (FilterXVariableHandle) nv_handle | FILTERX_HANDLE_FLOATING_BIT; } +static gboolean +filterx_scope_validate_variable(FilterXScope *self, FilterXVariable *variable) +{ + if (filterx_variable_handle_is_floating(variable->handle) && + !variable->declared && variable->generation != self->generation) + return FALSE; + return TRUE; +} + FilterXVariable * filterx_scope_lookup_variable(FilterXScope *self, FilterXVariableHandle handle) { @@ -183,8 +192,7 @@ filterx_scope_lookup_variable(FilterXScope *self, FilterXVariableHandle handle) if (filterx_scope_lookup_variable_without_validation(self, handle, &v)) { - if (filterx_variable_handle_is_floating(handle) && - !v->declared && v->generation != self->generation) + if (!filterx_scope_validate_variable(self, v)) return NULL; return v; } @@ -265,8 +273,7 @@ filterx_scope_foreach_variable(FilterXScope *self, FilterXScopeForeachFunc func, if (!variable->value) continue; - if (filterx_variable_handle_is_floating(variable->handle) && - !variable->declared && variable->generation != self->generation) + if (!filterx_scope_validate_variable(self, variable)) continue; if (!func(variable, user_data))