From 7bb7dc84c8343d90e2ef48f2c8909d9ec8b229f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20V=C3=A1rady?= Date: Fri, 18 Oct 2024 17:33:56 +0200 Subject: [PATCH] filterx: propagate modified_in_place through refs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: László Várady --- lib/filterx/filterx-object.h | 24 +++++++++++++++++++++++- lib/filterx/filterx-ref.c | 18 +++++++++++++++++- lib/filterx/filterx-scope.c | 4 ++-- lib/filterx/object-json-array.c | 12 ++++++------ lib/filterx/object-json-object.c | 8 ++++---- 5 files changed, 52 insertions(+), 14 deletions(-) diff --git a/lib/filterx/filterx-object.h b/lib/filterx/filterx-object.h index a94445334..4ba32e902 100644 --- a/lib/filterx/filterx-object.h +++ b/lib/filterx/filterx-object.h @@ -55,6 +55,8 @@ struct _FilterXType gboolean (*len)(FilterXObject *self, guint64 *len); FilterXObject *(*add)(FilterXObject *self, FilterXObject *object); void (*make_readonly)(FilterXObject *self); + gboolean (*is_modified_in_place)(FilterXObject *self); + void (*set_modified_in_place)(FilterXObject *self, gboolean modified); void (*free_fn)(FilterXObject *self); }; @@ -83,7 +85,9 @@ struct _FilterXObject /* NOTE: * * modified_in_place -- set to TRUE in case the value in this - * FilterXObject was changed + * FilterXObject was changed. + * don't use it directly, use + * filterx_object_{is,set}_modified_in_place() * readonly -- marks the object as unmodifiable, * propagates to the inner elements lazily * @@ -296,4 +300,22 @@ filterx_object_add_object(FilterXObject *self, FilterXObject *object) return self->type->add(self, object); } +static inline gboolean +filterx_object_is_modified_in_place(FilterXObject *self) +{ + if (G_UNLIKELY(self->type->is_modified_in_place)) + return self->type->is_modified_in_place(self); + + return self->modified_in_place; +} + +static inline void +filterx_object_set_modified_in_place(FilterXObject *self, gboolean modified) +{ + if (G_UNLIKELY(self->type->set_modified_in_place)) + return self->type->set_modified_in_place(self, modified); + + self->modified_in_place = modified; +} + #endif diff --git a/lib/filterx/filterx-ref.c b/lib/filterx/filterx-ref.c index abf01ea48..08f7b8052 100644 --- a/lib/filterx/filterx-ref.c +++ b/lib/filterx/filterx-ref.c @@ -113,12 +113,26 @@ _filterx_ref_free(FilterXObject *s) filterx_object_free_method(s); } -void +static void _prohibit_readonly(FilterXObject *s) { g_assert_not_reached(); } +static gboolean +_is_modified_in_place(FilterXObject *s) +{ + FilterXRef *self = (FilterXRef *) s; + return filterx_object_is_modified_in_place(self->value); +} + +static void +_set_modified_in_place(FilterXObject *s, gboolean modified) +{ + FilterXRef *self = (FilterXRef *) s; + filterx_object_set_modified_in_place(self->value, modified); +} + /* readonly methods */ static FilterXObject * @@ -267,5 +281,7 @@ FILTERX_DEFINE_TYPE(ref, FILTERX_TYPE_NAME(object), .len = _filterx_ref_len, .add = _filterx_ref_add, .make_readonly = _prohibit_readonly, + .is_modified_in_place = _is_modified_in_place, + .set_modified_in_place = _set_modified_in_place, .free_fn = _filterx_ref_free, ); diff --git a/lib/filterx/filterx-scope.c b/lib/filterx/filterx-scope.c index 9a151f6f6..770e48498 100644 --- a/lib/filterx/filterx-scope.c +++ b/lib/filterx/filterx-scope.c @@ -234,7 +234,7 @@ filterx_scope_sync(FilterXScope *self, LogMessage *msg) log_msg_unset_value(msg, filterx_variable_get_nv_handle(v)); filterx_variable_unassign(v); } - else if (filterx_variable_is_assigned(v) || v->value->modified_in_place) + else if (filterx_variable_is_assigned(v) || filterx_object_is_modified_in_place(v->value)) { LogMessageValueType t; @@ -245,7 +245,7 @@ filterx_scope_sync(FilterXScope *self, LogMessage *msg) if (!filterx_object_marshal(v->value, buffer, &t)) g_assert_not_reached(); log_msg_set_value_with_type(msg, filterx_variable_get_nv_handle(v), buffer->str, buffer->len, t); - v->value->modified_in_place = FALSE; + filterx_object_set_modified_in_place(v->value, FALSE); filterx_variable_unassign(v); } else diff --git a/lib/filterx/object-json-array.c b/lib/filterx/object-json-array.c index d2476c697..3596461c1 100644 --- a/lib/filterx/object-json-array.c +++ b/lib/filterx/object-json-array.c @@ -167,11 +167,11 @@ _append(FilterXList *s, FilterXObject **new_value) return FALSE; } - self->super.super.modified_in_place = TRUE; + filterx_object_set_modified_in_place(&self->super.super, TRUE); FilterXObject *root_container = filterx_weakref_get(&self->root_container); if (root_container) { - root_container->modified_in_place = TRUE; + filterx_object_set_modified_in_place(root_container, TRUE); filterx_object_unref(root_container); } @@ -203,11 +203,11 @@ _set_subscript(FilterXList *s, guint64 index, FilterXObject **new_value) return FALSE; } - self->super.super.modified_in_place = TRUE; + filterx_object_set_modified_in_place(&self->super.super, TRUE); FilterXObject *root_container = filterx_weakref_get(&self->root_container); if (root_container) { - root_container->modified_in_place = TRUE; + filterx_object_set_modified_in_place(root_container, TRUE); filterx_object_unref(root_container); } @@ -228,11 +228,11 @@ _unset_index(FilterXList *s, guint64 index) if (json_object_array_del_idx(self->jso, index, 1) != 0) return FALSE; - self->super.super.modified_in_place = TRUE; + filterx_object_set_modified_in_place(&self->super.super, TRUE); FilterXObject *root_container = filterx_weakref_get(&self->root_container); if (root_container) { - root_container->modified_in_place = TRUE; + filterx_object_set_modified_in_place(root_container, TRUE); filterx_object_unref(root_container); } diff --git a/lib/filterx/object-json-object.c b/lib/filterx/object-json-object.c index d95ca476c..59837566e 100644 --- a/lib/filterx/object-json-object.c +++ b/lib/filterx/object-json-object.c @@ -149,11 +149,11 @@ _set_subscript(FilterXDict *s, FilterXObject *key, FilterXObject **new_value) return FALSE; } - self->super.super.modified_in_place = TRUE; + filterx_object_set_modified_in_place(&self->super.super, TRUE); FilterXObject *root_container = filterx_weakref_get(&self->root_container); if (root_container) { - root_container->modified_in_place = TRUE; + filterx_object_set_modified_in_place(root_container, TRUE); filterx_object_unref(root_container); } @@ -177,11 +177,11 @@ _unset_key(FilterXDict *s, FilterXObject *key) json_object_object_del(self->jso, key_str); - self->super.super.modified_in_place = TRUE; + filterx_object_set_modified_in_place(&self->super.super, TRUE); FilterXObject *root_container = filterx_weakref_get(&self->root_container); if (root_container) { - root_container->modified_in_place = TRUE; + filterx_object_set_modified_in_place(root_container, TRUE); filterx_object_unref(root_container); }