Skip to content

Commit

Permalink
Merge pull request #360 from axoflow/filterx-scope-fix-followups
Browse files Browse the repository at this point in the history
Filterx: scope-sync followups for cloning
  • Loading branch information
MrAnno authored Oct 31, 2024
2 parents 7bc4bdb + 8ee9fbb commit a967442
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions lib/filterx/filterx-scope.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,23 @@ filterx_scope_is_dirty(FilterXScope *self)
return self->dirty;
}

static gboolean
_validate_variable(FilterXScope *self, FilterXVariable *variable)
{
if (filterx_variable_is_floating(variable) &&
!filterx_variable_is_declared(variable) &&
!filterx_variable_is_same_generation(variable, self->generation))
return FALSE;
return TRUE;
}

FilterXVariable *
filterx_scope_lookup_variable(FilterXScope *self, FilterXVariableHandle handle)
{
FilterXVariable *v;

if (_lookup_variable(self, handle, &v))
{
if (filterx_variable_handle_is_floating(handle) &&
!filterx_variable_is_declared(v) &&
!filterx_variable_is_same_generation(v, self->generation))
return NULL;
if (!filterx_variable_handle_is_floating(handle) && v->generation == 0 && self->syncable)
return NULL;
return v;
}
if (_lookup_variable(self, handle, &v) && _validate_variable(self, v))
return v;
return NULL;
}

Expand Down Expand Up @@ -185,9 +187,7 @@ filterx_scope_foreach_variable(FilterXScope *self, FilterXScopeForeachFunc func,
if (!variable->value)
continue;

if (filterx_variable_is_floating(variable) &&
!filterx_variable_is_declared(variable) &&
!filterx_variable_is_same_generation(variable, self->generation))
if (!_validate_variable(self, variable))
continue;

if (!func(variable, user_data))
Expand Down Expand Up @@ -316,7 +316,7 @@ filterx_scope_clone(FilterXScope *other)
if (other->variables->len > 0)
self->dirty = other->dirty;
self->syncable = other->syncable;
self->log_msg_has_changes = other->log_msg_has_changes;

msg_trace("Filterx clone finished",
evt_tag_printf("scope", "%p", self),
evt_tag_printf("other", "%p", other),
Expand Down Expand Up @@ -377,12 +377,15 @@ filterx_scope_invalidate_log_msg_cache(FilterXScope *self)
{
g_assert(filterx_scope_has_log_msg_changes(self));

for (gint i = 0; i < self->variables->len; i++)
gint i = 0;
while (i < self->variables->len)
{
FilterXVariable *v = &g_array_index(self->variables, FilterXVariable, i);

if (!filterx_variable_is_floating(v) && self->syncable)
v->generation = 0;
g_array_remove_index(self->variables, i);
else
i++;
}

filterx_scope_clear_log_msg_has_changes(self);
Expand Down

0 comments on commit a967442

Please sign in to comment.