diff --git a/lib/filterx/expr-compound.c b/lib/filterx/expr-compound.c index 9a0bc144a..b324894c6 100644 --- a/lib/filterx/expr-compound.c +++ b/lib/filterx/expr-compound.c @@ -129,6 +129,42 @@ _eval(FilterXExpr *s) return result; } +static gboolean +_init(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXCompoundExpr *self = (FilterXCompoundExpr *) s; + + for (gint i = 0; i < self->exprs->len; i++) + { + FilterXExpr *expr = g_ptr_array_index(self->exprs, i); + if (!filterx_expr_init(expr, cfg)) + { + for (gint j = 0; j < i; j++) + { + expr = g_ptr_array_index(self->exprs, j); + filterx_expr_deinit(expr, cfg); + } + return FALSE; + } + } + + return filterx_expr_init_method(s, cfg); +} + +static void +_deinit(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXCompoundExpr *self = (FilterXCompoundExpr *) s; + + for (gint i = 0; i < self->exprs->len; i++) + { + FilterXExpr *expr = g_ptr_array_index(self->exprs, i); + filterx_expr_deinit(expr, cfg); + } + + filterx_expr_deinit_method(s, cfg); +} + static void _free(FilterXExpr *s) { @@ -165,6 +201,8 @@ filterx_compound_expr_new(gboolean return_value_of_last_expr) filterx_expr_init_instance(&self->super); self->super.eval = _eval; + self->super.init = _init; + self->super.deinit = _deinit; self->super.free_fn = _free; self->exprs = g_ptr_array_new_with_free_func((GDestroyNotify) filterx_expr_unref); self->return_value_of_last_expr = return_value_of_last_expr; diff --git a/lib/filterx/expr-condition.c b/lib/filterx/expr-condition.c index 1e9f8392c..8473a49c8 100644 --- a/lib/filterx/expr-condition.c +++ b/lib/filterx/expr-condition.c @@ -35,6 +35,42 @@ struct _FilterXConditional FilterXExpr *false_branch; }; +static gboolean +_init(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXConditional *self = (FilterXConditional *) s; + + if (!filterx_expr_init(self->condition, cfg)) + return FALSE; + + if (!filterx_expr_init(self->true_branch, cfg)) + { + filterx_expr_deinit(self->condition, cfg); + return FALSE; + } + + if (!filterx_expr_init(self->false_branch, cfg)) + { + filterx_expr_deinit(self->condition, cfg); + filterx_expr_deinit(self->true_branch, cfg); + return FALSE; + } + + return filterx_expr_init_method(s, cfg); +} + + +static void +_deinit(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXConditional *self = (FilterXConditional *) s; + + filterx_expr_deinit(self->condition, cfg); + filterx_expr_deinit(self->true_branch, cfg); + filterx_expr_deinit(self->false_branch, cfg); + filterx_expr_deinit_method(s, cfg); +} + static void _free(FilterXExpr *s) { @@ -119,6 +155,8 @@ filterx_conditional_new(FilterXExpr *condition) FilterXConditional *self = g_new0(FilterXConditional, 1); filterx_expr_init_instance(&self->super); self->super.eval = _eval; + self->super.init = _init; + self->super.deinit = _deinit; self->super.free_fn = _free; self->super.suppress_from_trace = TRUE; self->condition = condition; diff --git a/lib/filterx/expr-function.c b/lib/filterx/expr-function.c index e5a05adcc..408051995 100644 --- a/lib/filterx/expr-function.c +++ b/lib/filterx/expr-function.c @@ -133,6 +133,42 @@ _simple_eval(FilterXExpr *s) return res; } +static gboolean +_simple_init(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXSimpleFunction *self = (FilterXSimpleFunction *) s; + + for (guint64 i = 0; i < self->args->len; i++) + { + FilterXExpr *arg = g_ptr_array_index(self->args, i); + if (!filterx_expr_init(arg, cfg)) + { + for (gint j = 0; j < i; j++) + { + arg = g_ptr_array_index(self->args, j); + filterx_expr_deinit(arg, cfg); + } + return FALSE; + } + } + + return filterx_function_init_method(&self->super, cfg); +} + +static void +_simple_deinit(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXSimpleFunction *self = (FilterXSimpleFunction *) s; + + for (guint64 i = 0; i < self->args->len; i++) + { + FilterXExpr *arg = g_ptr_array_index(self->args, i); + filterx_expr_deinit(arg, cfg); + } + + filterx_function_deinit_method(&self->super, cfg); +} + static void _simple_free(FilterXExpr *s) { @@ -169,6 +205,8 @@ filterx_simple_function_new(const gchar *function_name, FilterXFunctionArgs *arg filterx_function_init_instance(&self->super, function_name); self->super.super.eval = _simple_eval; + self->super.super.init = _simple_init; + self->super.super.deinit = _simple_deinit; self->super.super.free_fn = _simple_free; self->function_proto = function_proto; @@ -186,6 +224,18 @@ filterx_simple_function_new(const gchar *function_name, FilterXFunctionArgs *arg return NULL; } +gboolean +filterx_function_init_method(FilterXFunction *s, GlobalConfig *cfg) +{ + return filterx_expr_init_method(&s->super, cfg); +} + +void +filterx_function_deinit_method(FilterXFunction *s, GlobalConfig *cfg) +{ + filterx_expr_deinit_method(&s->super, cfg); +} + void filterx_function_free_method(FilterXFunction *s) { @@ -208,6 +258,18 @@ filterx_function_init_instance(FilterXFunction *s, const gchar *function_name) s->super.free_fn = _function_free; } +gboolean +filterx_generator_function_init_method(FilterXGeneratorFunction *s, GlobalConfig *cfg) +{ + return filterx_generator_init_method(&s->super.super, cfg); +} + +void +filterx_generator_function_deinit_method(FilterXGeneratorFunction *s, GlobalConfig *cfg) +{ + filterx_generator_deinit_method(&s->super.super, cfg); +} + void filterx_generator_function_free_method(FilterXGeneratorFunction *s) { diff --git a/lib/filterx/expr-function.h b/lib/filterx/expr-function.h index 076bc73fa..819e0b736 100644 --- a/lib/filterx/expr-function.h +++ b/lib/filterx/expr-function.h @@ -69,7 +69,11 @@ enum FilterXFunctionError }; void filterx_function_init_instance(FilterXFunction *s, const gchar *function_name); +gboolean filterx_function_init_method(FilterXFunction *s, GlobalConfig *cfg); +void filterx_function_deinit_method(FilterXFunction *s, GlobalConfig *cfg); void filterx_function_free_method(FilterXFunction *s); +gboolean filterx_generator_function_init_method(FilterXGeneratorFunction *s, GlobalConfig *cfg); +void filterx_generator_function_deinit_method(FilterXGeneratorFunction *s, GlobalConfig *cfg); void filterx_generator_function_init_instance(FilterXGeneratorFunction *s, const gchar *function_name); void filterx_generator_function_free_method(FilterXGeneratorFunction *s); diff --git a/lib/filterx/expr-generator.c b/lib/filterx/expr-generator.c index b39f0b293..378c989a5 100644 --- a/lib/filterx/expr-generator.c +++ b/lib/filterx/expr-generator.c @@ -59,10 +59,32 @@ void filterx_generator_init_instance(FilterXExpr *s) { filterx_expr_init_instance(s); + s->init = filterx_generator_init_method; + s->deinit = filterx_generator_deinit_method; s->eval = _eval; s->ignore_falsy_result = TRUE; } +gboolean +filterx_generator_init_method(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXExprGenerator *self = (FilterXExprGenerator *) s; + + if (!filterx_expr_init(self->fillable, cfg)) + return FALSE; + + return filterx_expr_init_method(s, cfg); +} + +void +filterx_generator_deinit_method(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXExprGenerator *self = (FilterXExprGenerator *) s; + + filterx_expr_deinit(self->fillable, cfg); + filterx_expr_deinit_method(s, cfg); +} + void filterx_generator_free_method(FilterXExpr *s) { @@ -87,6 +109,26 @@ _create_container_eval(FilterXExpr *s) return self->generator->create_container(self->generator, self->fillable_parent); } +static gboolean +_create_container_init(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXExprGeneratorCreateContainer *self = (FilterXExprGeneratorCreateContainer *) s; + + if (!filterx_expr_init(self->fillable_parent, cfg)) + return FALSE; + + return filterx_expr_init_method(s, cfg); +} + +static void +_create_container_deinit(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXExprGeneratorCreateContainer *self = (FilterXExprGeneratorCreateContainer *) s; + + filterx_expr_deinit(self->fillable_parent, cfg); + filterx_expr_deinit_method(s, cfg); +} + static void _create_container_free(FilterXExpr *s) { @@ -130,6 +172,8 @@ filterx_generator_create_container_new(FilterXExpr *g, FilterXExpr *fillable_par filterx_expr_init_instance(&self->super); self->generator = (FilterXExprGenerator *) g; self->fillable_parent = fillable_parent; + self->super.init = _create_container_init; + self->super.deinit = _create_container_deinit; self->super.eval = _create_container_eval; self->super.free_fn = _create_container_free; diff --git a/lib/filterx/expr-generator.h b/lib/filterx/expr-generator.h index 72688dfec..f3026c448 100644 --- a/lib/filterx/expr-generator.h +++ b/lib/filterx/expr-generator.h @@ -37,6 +37,8 @@ struct FilterXExprGenerator_ void filterx_generator_set_fillable(FilterXExpr *s, FilterXExpr *fillable); void filterx_generator_init_instance(FilterXExpr *s); +gboolean filterx_generator_init_method(FilterXExpr *s, GlobalConfig *cfg); +void filterx_generator_deinit_method(FilterXExpr *s, GlobalConfig *cfg); void filterx_generator_free_method(FilterXExpr *s); gboolean filterx_expr_is_generator(FilterXExpr *s); diff --git a/lib/filterx/expr-get-subscript.c b/lib/filterx/expr-get-subscript.c index 69dc2a4df..6ccee3c26 100644 --- a/lib/filterx/expr-get-subscript.c +++ b/lib/filterx/expr-get-subscript.c @@ -103,6 +103,33 @@ _unset(FilterXExpr *s) return result; } +static gboolean +_init(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXGetSubscript *self = (FilterXGetSubscript *) s; + + if (!filterx_expr_init(self->operand, cfg)) + return FALSE; + + if (!filterx_expr_init(self->key, cfg)) + { + filterx_expr_deinit(self->operand, cfg); + return FALSE; + } + + return filterx_expr_init_method(s, cfg); +} + +static void +_deinit(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXGetSubscript *self = (FilterXGetSubscript *) s; + + filterx_expr_deinit(self->operand, cfg); + filterx_expr_deinit(self->key, cfg); + filterx_expr_deinit_method(s, cfg); +} + static void _free(FilterXExpr *s) { @@ -122,6 +149,8 @@ filterx_get_subscript_new(FilterXExpr *operand, FilterXExpr *key) self->super.eval = _eval; self->super.is_set = _isset; self->super.unset = _unset; + self->super.init = _init; + self->super.deinit = _deinit; self->super.free_fn = _free; self->operand = operand; self->key = key; diff --git a/lib/filterx/expr-getattr.c b/lib/filterx/expr-getattr.c index ada4d74ff..781e64cfc 100644 --- a/lib/filterx/expr-getattr.c +++ b/lib/filterx/expr-getattr.c @@ -90,6 +90,25 @@ _isset(FilterXExpr *s) return result; } +static gboolean +_init(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXGetAttr *self = (FilterXGetAttr *) s; + + if (!filterx_expr_init(self->operand, cfg)) + return FALSE; + + return filterx_expr_init_method(s, cfg); +} + +static void +_deinit(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXGetAttr *self = (FilterXGetAttr *) s; + + filterx_expr_deinit(self->operand, cfg); + filterx_expr_deinit_method(s, cfg); +} static void _free(FilterXExpr *s) @@ -110,6 +129,8 @@ filterx_getattr_new(FilterXExpr *operand, FilterXString *attr_name) self->super.eval = _eval; self->super.unset = _unset; self->super.is_set = _isset; + self->super.init = _init; + self->super.deinit = _deinit; self->super.free_fn = _free; self->operand = operand; diff --git a/lib/filterx/expr-literal-generator.c b/lib/filterx/expr-literal-generator.c index 61eea5da5..e11d25901 100644 --- a/lib/filterx/expr-literal-generator.c +++ b/lib/filterx/expr-literal-generator.c @@ -44,6 +44,28 @@ filterx_literal_generator_elem_new(FilterXExpr *key, FilterXExpr *value, gboolea return self; } +static gboolean +_literal_generator_elem_init(FilterXLiteralGeneratorElem *self, GlobalConfig *cfg) +{ + if (!filterx_expr_init(self->key, cfg)) + return FALSE; + + if (!filterx_expr_init(self->value, cfg)) + { + filterx_expr_deinit(self->key, cfg); + return FALSE; + } + + return TRUE; +} + +static void +_literal_generator_elem_deinit(FilterXLiteralGeneratorElem *self, GlobalConfig *cfg) +{ + filterx_expr_deinit(self->key, cfg); + filterx_expr_deinit(self->value, cfg); +} + static void _literal_generator_elem_free(FilterXLiteralGeneratorElem *self) { @@ -118,6 +140,43 @@ _literal_generator_generate(FilterXExprGenerator *s, FilterXObject *fillable) return _eval_elements(fillable, self->elements); } +static gboolean +_literal_generator_init(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXExprLiteralGenerator *self = (FilterXExprLiteralGenerator *) s; + + for (GList *link = self->elements; link; link = link->next) + { + FilterXLiteralGeneratorElem *elem = (FilterXLiteralGeneratorElem *) link->data; + + if (!_literal_generator_elem_init(elem, cfg)) + { + for (GList *deinit_link = self->elements; deinit_link != link; deinit_link = deinit_link->next) + { + elem = (FilterXLiteralGeneratorElem *) deinit_link->data; + _literal_generator_elem_deinit(elem, cfg); + } + return FALSE; + } + } + + return filterx_generator_init_method(s, cfg); +} + +static void +_literal_generator_deinit(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXExprLiteralGenerator *self = (FilterXExprLiteralGenerator *) s; + + for (GList *link = self->elements; link; link = link->next) + { + FilterXLiteralGeneratorElem *elem = (FilterXLiteralGeneratorElem *) link->data; + _literal_generator_elem_deinit(elem, cfg); + } + + filterx_generator_deinit_method(s, cfg); +} + void _literal_generator_free(FilterXExpr *s) { @@ -132,6 +191,8 @@ _literal_generator_init_instance(FilterXExprLiteralGenerator *self) { filterx_generator_init_instance(&self->super.super); self->super.generate = _literal_generator_generate; + self->super.super.init = _literal_generator_init; + self->super.super.deinit = _literal_generator_deinit; self->super.super.free_fn = _literal_generator_free; } diff --git a/lib/filterx/expr-plus-generator.c b/lib/filterx/expr-plus-generator.c index f9fda257f..a0677ab65 100644 --- a/lib/filterx/expr-plus-generator.c +++ b/lib/filterx/expr-plus-generator.c @@ -100,6 +100,31 @@ _expr_plus_generator_create_container(FilterXExprGenerator *s, FilterXExpr *fill return generator->create_container(generator, fillable_parent); } +static gboolean +_expr_plus_generator_init(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXOperatorPlusGenerator *self = (FilterXOperatorPlusGenerator *) s; + + if (!filterx_expr_init(self->lhs, cfg)) + return FALSE; + + if (!filterx_expr_init(self->rhs, cfg)) + { + filterx_expr_deinit(self->lhs, cfg); + return FALSE; + } + return filterx_generator_init_method(s, cfg); +} + +static void +_expr_plus_generator_deinit(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXOperatorPlusGenerator *self = (FilterXOperatorPlusGenerator *) s; + filterx_expr_deinit(self->lhs, cfg); + filterx_expr_deinit(self->rhs, cfg); + filterx_generator_deinit_method(s, cfg); +} + static void _expr_plus_generator_free(FilterXExpr *s) { @@ -117,6 +142,8 @@ filterx_operator_plus_generator_new(FilterXExpr *lhs, FilterXExpr *rhs) self->lhs = lhs; self->rhs = rhs; self->super.generate = _expr_plus_generator_generate; + self->super.super.init = _expr_plus_generator_init; + self->super.super.deinit = _expr_plus_generator_deinit; self->super.super.free_fn = _expr_plus_generator_free; self->super.create_container = _expr_plus_generator_create_container; diff --git a/lib/filterx/expr-regexp.c b/lib/filterx/expr-regexp.c index 821956bca..cb8df99ca 100644 --- a/lib/filterx/expr-regexp.c +++ b/lib/filterx/expr-regexp.c @@ -315,6 +315,26 @@ _regexp_match_eval(FilterXExpr *s) return result; } +static gboolean +_regexp_match_init(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXExprRegexpMatch *self = (FilterXExprRegexpMatch *) s; + + if (!filterx_expr_init(self->lhs, cfg)) + return FALSE; + + return filterx_expr_init_method(s, cfg); +} + +static void +_regexp_match_deinit(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXExprRegexpMatch *self = (FilterXExprRegexpMatch *) s; + + filterx_expr_deinit(self->lhs, cfg); + filterx_expr_deinit_method(s, cfg); +} + static void _regexp_match_free(FilterXExpr *s) { @@ -334,6 +354,8 @@ filterx_expr_regexp_match_new(FilterXExpr *lhs, const gchar *pattern) filterx_expr_init_instance(&self->super); self->super.eval = _regexp_match_eval; + self->super.init = _regexp_match_init; + self->super.deinit = _regexp_match_deinit; self->super.free_fn = _regexp_match_free; self->lhs = lhs; @@ -403,6 +425,26 @@ _regexp_search_generator_create_container(FilterXExprGenerator *s, FilterXExpr * return filterx_generator_create_list_container(s, fillable_parent); } +static gboolean +_regexp_search_generator_init(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXExprRegexpSearchGenerator *self = (FilterXExprRegexpSearchGenerator *) s; + + if (!filterx_expr_init(self->lhs, cfg)) + return FALSE; + + return filterx_generator_init_method(s, cfg); +} + +static void +_regexp_search_generator_deinit(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXExprRegexpSearchGenerator *self = (FilterXExprRegexpSearchGenerator *) s; + + filterx_expr_deinit(self->lhs, cfg); + filterx_generator_deinit_method(s, cfg); +} + static void _regexp_search_generator_free(FilterXExpr *s) { @@ -454,6 +496,8 @@ filterx_generator_function_regexp_search_new(FilterXFunctionArgs *args, GError * filterx_generator_function_init_instance(&self->super, "regexp_search"); self->super.super.generate = _regexp_search_generator_generate; + self->super.super.super.init = _regexp_search_generator_init; + self->super.super.super.deinit = _regexp_search_generator_deinit; self->super.super.super.free_fn = _regexp_search_generator_free; self->super.super.create_container = _regexp_search_generator_create_container; @@ -677,6 +721,25 @@ _extract_subst_args(FilterXFuncRegexpSubst *self, FilterXFunctionArgs *args, GEr return TRUE; } +static gboolean +_subst_init(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXFuncRegexpSubst *self = (FilterXFuncRegexpSubst *) s; + + if (!filterx_expr_init(self->string_expr, cfg)) + return FALSE; + + return filterx_function_init_method(&self->super, cfg); +} + +static void +_subst_deinit(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXFuncRegexpSubst *self = (FilterXFuncRegexpSubst *) s; + filterx_expr_deinit(self->string_expr, cfg); + filterx_function_deinit_method(&self->super, cfg); +} + static void _subst_free(FilterXExpr *s) { @@ -701,6 +764,8 @@ filterx_function_regexp_subst_new(FilterXFunctionArgs *args, GError **error) FilterXFuncRegexpSubst *self = g_new0(FilterXFuncRegexpSubst, 1); filterx_function_init_instance(&self->super, "regexp_subst"); self->super.super.eval = _subst_eval; + self->super.super.init = _subst_init; + self->super.super.deinit = _subst_deinit; self->super.super.free_fn = _subst_free; _opts_init(&self->opts); diff --git a/lib/filterx/expr-set-subscript.c b/lib/filterx/expr-set-subscript.c index 3901d164c..aabecd849 100644 --- a/lib/filterx/expr-set-subscript.c +++ b/lib/filterx/expr-set-subscript.c @@ -93,6 +93,41 @@ _eval(FilterXExpr *s) return result; } +static gboolean +_init(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXSetSubscript *self = (FilterXSetSubscript *) s; + + if (!filterx_expr_init(self->object, cfg)) + return FALSE; + + if (!filterx_expr_init(self->new_value, cfg)) + { + filterx_expr_deinit(self->object, cfg); + return FALSE; + } + + if (!filterx_expr_init(self->key, cfg)) + { + filterx_expr_deinit(self->object, cfg); + filterx_expr_deinit(self->new_value, cfg); + return FALSE; + } + + return filterx_expr_init_method(s, cfg); +} + +static void +_deinit(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXSetSubscript *self = (FilterXSetSubscript *) s; + + filterx_expr_deinit(self->object, cfg); + filterx_expr_deinit(self->new_value, cfg); + filterx_expr_deinit(self->key, cfg); + filterx_expr_deinit_method(s, cfg); +} + static void _free(FilterXExpr *s) { @@ -111,6 +146,8 @@ filterx_set_subscript_new(FilterXExpr *object, FilterXExpr *key, FilterXExpr *ne filterx_expr_init_instance(&self->super); self->super.eval = _eval; + self->super.init = _init; + self->super.deinit = _deinit; self->super.free_fn = _free; self->object = object; self->key = key; diff --git a/lib/filterx/expr-setattr.c b/lib/filterx/expr-setattr.c index bd5084292..63ca21847 100644 --- a/lib/filterx/expr-setattr.c +++ b/lib/filterx/expr-setattr.c @@ -80,6 +80,33 @@ _eval(FilterXExpr *s) return result; } +static gboolean +_init(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXSetAttr *self = (FilterXSetAttr *) s; + + if (!filterx_expr_init(self->object, cfg)) + return FALSE; + + if (!filterx_expr_init(self->new_value, cfg)) + { + filterx_expr_deinit(self->object, cfg); + return FALSE; + } + + return filterx_expr_init_method(s, cfg); +} + +static void +_deinit(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXSetAttr *self = (FilterXSetAttr *) s; + + filterx_expr_deinit(self->object, cfg); + filterx_expr_deinit(self->new_value, cfg); + filterx_expr_deinit_method(s, cfg); +} + static void _free(FilterXExpr *s) { @@ -99,6 +126,8 @@ filterx_setattr_new(FilterXExpr *object, FilterXString *attr_name, FilterXExpr * filterx_expr_init_instance(&self->super); self->super.eval = _eval; + self->super.init = _init; + self->super.deinit = _deinit; self->super.free_fn = _free; self->object = object; diff --git a/lib/filterx/expr-unset.c b/lib/filterx/expr-unset.c index 1fb242942..b3dfa97a5 100644 --- a/lib/filterx/expr-unset.c +++ b/lib/filterx/expr-unset.c @@ -46,6 +46,42 @@ _eval(FilterXExpr *s) return filterx_boolean_new(TRUE); } +static gboolean +_init(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXExprUnset *self = (FilterXExprUnset *) s; + + for (guint i = 0; i < self->exprs->len; i++) + { + FilterXExpr *expr = (FilterXExpr *) g_ptr_array_index(self->exprs, i); + if (!filterx_expr_init(expr, cfg)) + { + for (guint j = 0; j < i; j++) + { + expr = g_ptr_array_index(self->exprs, i); + filterx_expr_deinit(expr, cfg); + } + return FALSE; + } + } + + return filterx_function_init_method(&self->super, cfg); +} + +static void +_deinit(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXExprUnset *self = (FilterXExprUnset *) s; + + for (guint i = 0; i < self->exprs->len; i++) + { + FilterXExpr *expr = (FilterXExpr *) g_ptr_array_index(self->exprs, i); + filterx_expr_deinit(expr, cfg); + } + + filterx_function_deinit_method(&self->super, cfg); +} + static void _free(FilterXExpr *s) { @@ -62,6 +98,8 @@ filterx_function_unset_new(FilterXFunctionArgs *args, GError **error) filterx_function_init_instance(&self->super, "unset"); self->super.super.eval = _eval; + self->super.super.init = _init; + self->super.super.deinit = _deinit; self->super.super.free_fn = _free; self->exprs = g_ptr_array_new_full(filterx_function_args_len(args), (GDestroyNotify) filterx_expr_unref); diff --git a/lib/filterx/filterx-expr.c b/lib/filterx/filterx-expr.c index 771e3910c..de7280921 100644 --- a/lib/filterx/filterx-expr.c +++ b/lib/filterx/filterx-expr.c @@ -58,6 +58,17 @@ filterx_expr_format_location_tag(FilterXExpr *self) return evt_tag_str("expr", "n/a"); } +gboolean +filterx_expr_init_method(FilterXExpr *self, GlobalConfig *cfg) +{ + return TRUE; +} + +void +filterx_expr_deinit_method(FilterXExpr *self, GlobalConfig *cfg) +{ +} + void filterx_expr_free_method(FilterXExpr *self) { @@ -68,6 +79,8 @@ void filterx_expr_init_instance(FilterXExpr *self) { self->ref_cnt = 1; + self->init = filterx_expr_init_method; + self->deinit = filterx_expr_deinit_method; self->free_fn = filterx_expr_free_method; } @@ -106,6 +119,26 @@ filterx_expr_unref(FilterXExpr *self) } } +gboolean +filterx_unary_op_init_method(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXUnaryOp *self = (FilterXUnaryOp *) s; + + if (!filterx_expr_init(self->operand, cfg)) + return FALSE; + + return filterx_expr_init_method(s, cfg); +} + +void +filterx_unary_op_deinit_method(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXUnaryOp *self = (FilterXUnaryOp *) s; + + filterx_expr_deinit(self->operand, cfg); + filterx_expr_deinit_method(s, cfg); +} + void filterx_unary_op_free_method(FilterXExpr *s) { @@ -119,6 +152,8 @@ void filterx_unary_op_init_instance(FilterXUnaryOp *self, FilterXExpr *operand) { filterx_expr_init_instance(&self->super); + self->super.init = filterx_unary_op_init_method; + self->super.deinit = filterx_unary_op_deinit_method; self->super.free_fn = filterx_unary_op_free_method; self->operand = operand; } @@ -133,10 +168,36 @@ filterx_binary_op_free_method(FilterXExpr *s) filterx_expr_free_method(s); } +gboolean +filterx_binary_op_init_method(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXBinaryOp *self = (FilterXBinaryOp *) s; + + if (!filterx_expr_init(self->lhs, cfg)) + return FALSE; + + if (!filterx_expr_init(self->rhs, cfg)) + return FALSE; + + return filterx_expr_init_method(s, cfg); +} + +void +filterx_binary_op_deinit_method(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXBinaryOp *self = (FilterXBinaryOp *) s; + + filterx_expr_deinit(self->lhs, cfg); + filterx_expr_deinit(self->rhs, cfg); + filterx_expr_deinit_method(s, cfg); +} + void filterx_binary_op_init_instance(FilterXBinaryOp *self, FilterXExpr *lhs, FilterXExpr *rhs) { filterx_expr_init_instance(&self->super); + self->super.init = filterx_binary_op_init_method; + self->super.deinit = filterx_binary_op_deinit_method; self->super.free_fn = filterx_binary_op_free_method; g_assert(lhs); g_assert(rhs); diff --git a/lib/filterx/filterx-expr.h b/lib/filterx/filterx-expr.h index 11912667c..d889c0aaa 100644 --- a/lib/filterx/filterx-expr.h +++ b/lib/filterx/filterx-expr.h @@ -49,7 +49,12 @@ struct _FilterXExpr /* unset the expression */ gboolean (*unset)(FilterXExpr *self); + gboolean (*init)(FilterXExpr *self, GlobalConfig *cfg); + void (*deinit)(FilterXExpr *self, GlobalConfig *cfg); void (*free_fn)(FilterXExpr *self); + + gboolean inited; + CFG_LTYPE lloc; gchar *expr_text; }; @@ -145,14 +150,45 @@ void filterx_expr_init_instance(FilterXExpr *self); FilterXExpr *filterx_expr_new(void); FilterXExpr *filterx_expr_ref(FilterXExpr *self); void filterx_expr_unref(FilterXExpr *self); +gboolean filterx_expr_init_method(FilterXExpr *self, GlobalConfig *cfg); +void filterx_expr_deinit_method(FilterXExpr *self, GlobalConfig *cfg); void filterx_expr_free_method(FilterXExpr *self); +static inline gboolean +filterx_expr_init(FilterXExpr *self, GlobalConfig *cfg) +{ + if (!self || self->inited) + return TRUE; + + if (!self->init || self->init(self, cfg)) + { + self->inited = TRUE; + return TRUE; + } + + return FALSE; +} + +static inline void +filterx_expr_deinit(FilterXExpr *self, GlobalConfig *cfg) +{ + if (!self || !self->inited) + return; + + if (self->deinit) + self->deinit(self, cfg); + + self->inited = FALSE; +} + typedef struct _FilterXUnaryOp { FilterXExpr super; FilterXExpr *operand; } FilterXUnaryOp; +gboolean filterx_unary_op_init_method(FilterXExpr *s, GlobalConfig *cfg); +void filterx_unary_op_deinit_method(FilterXExpr *s, GlobalConfig *cfg); void filterx_unary_op_free_method(FilterXExpr *s); void filterx_unary_op_init_instance(FilterXUnaryOp *self, FilterXExpr *operand); @@ -162,6 +198,8 @@ typedef struct _FilterXBinaryOp FilterXExpr *lhs, *rhs; } FilterXBinaryOp; +gboolean filterx_binary_op_init_method(FilterXExpr *s, GlobalConfig *cfg); +void filterx_binary_op_deinit_method(FilterXExpr *s, GlobalConfig *cfg); void filterx_binary_op_free_method(FilterXExpr *s); void filterx_binary_op_init_instance(FilterXBinaryOp *self, FilterXExpr *lhs, FilterXExpr *rhs); diff --git a/lib/filterx/filterx-metrics-labels.c b/lib/filterx/filterx-metrics-labels.c index 979f644cf..44b1844d8 100644 --- a/lib/filterx/filterx-metrics-labels.c +++ b/lib/filterx/filterx-metrics-labels.c @@ -98,6 +98,18 @@ _label_cmp(gconstpointer a, gconstpointer b) return strcmp(lhs->name, rhs->name); } +static gboolean +_label_init(FilterXMetricsLabel *self, GlobalConfig *cfg) +{ + return filterx_expr_init(self->value.expr, cfg); +} + +static void +_label_deinit(FilterXMetricsLabel *self, GlobalConfig *cfg) +{ + filterx_expr_deinit(self->value.expr, cfg); +} + static void _label_free(FilterXMetricsLabel *self) { @@ -286,6 +298,48 @@ filterx_metrics_labels_format(FilterXMetricsLabels *self, StatsClusterLabel **la return TRUE; } +gboolean +filterx_metrics_labels_init(FilterXMetricsLabels *self, GlobalConfig *cfg) +{ + if (!filterx_expr_init(self->expr, cfg)) + return FALSE; + + if (self->literal_labels) + { + for (guint i = 0; i < self->literal_labels->len; i++) + { + FilterXMetricsLabel *label = g_ptr_array_index(self->literal_labels, i); + if (!_label_init(label, cfg)) + { + for (guint j = 0; j < i; j++) + { + label = g_ptr_array_index(self->literal_labels, j); + _label_deinit(label, cfg); + } + filterx_expr_deinit(self->expr, cfg); + return FALSE; + } + } + } + + return TRUE; +} + +void +filterx_metrics_labels_deinit(FilterXMetricsLabels *self, GlobalConfig *cfg) +{ + filterx_expr_deinit(self->expr, cfg); + + if (self->literal_labels) + { + for (guint i = 0; i < self->literal_labels->len; i++) + { + FilterXMetricsLabel *label = g_ptr_array_index(self->literal_labels, i); + _label_deinit(label, cfg); + } + } +} + void filterx_metrics_labels_free(FilterXMetricsLabels *self) { diff --git a/lib/filterx/filterx-metrics-labels.h b/lib/filterx/filterx-metrics-labels.h index d17cfdcfa..cbb5903b9 100644 --- a/lib/filterx/filterx-metrics-labels.h +++ b/lib/filterx/filterx-metrics-labels.h @@ -30,6 +30,8 @@ typedef struct _FilterXMetricsLabels FilterXMetricsLabels; FilterXMetricsLabels *filterx_metrics_labels_new(FilterXExpr *labels); +gboolean filterx_metrics_labels_init(FilterXMetricsLabels *self, GlobalConfig *cfg); +void filterx_metrics_labels_deinit(FilterXMetricsLabels *self, GlobalConfig *cfg); void filterx_metrics_labels_free(FilterXMetricsLabels *self); gboolean filterx_metrics_labels_format(FilterXMetricsLabels *self, StatsClusterLabel **labels, gsize *len); diff --git a/lib/filterx/filterx-metrics.c b/lib/filterx/filterx-metrics.c index c7bf1d27c..65b376c88 100644 --- a/lib/filterx/filterx-metrics.c +++ b/lib/filterx/filterx-metrics.c @@ -33,7 +33,6 @@ #include "stats/stats-registry.h" #include "metrics/dyn-metrics-cache.h" #include "scratch-buffers.h" -#include "atomic.h" struct _FilterXMetrics { @@ -46,7 +45,6 @@ struct _FilterXMetrics FilterXMetricsLabels *labels; gint level; - GAtomicCounter is_optimized; StatsCluster *const_cluster; }; @@ -110,9 +108,6 @@ _optimize(FilterXMetrics *self) { stats_lock(); - if (g_atomic_counter_get(&self->is_optimized)) - goto exit; - if (!self->key.str || !filterx_metrics_labels_is_const(self->labels)) goto exit; @@ -136,7 +131,6 @@ _optimize(FilterXMetrics *self) self->key.str = NULL; exit: - g_atomic_counter_set(&self->is_optimized, TRUE); stats_unlock(); } @@ -149,13 +143,6 @@ filterx_metrics_get_stats_counter(FilterXMetrics *self, StatsCounterItem **count return TRUE; } - /* - * We need to delay the optimization to the first get() call, - * as we don't have stats options when FilterXExprs are being created. - */ - if (!g_atomic_counter_get(&self->is_optimized)) - _optimize(self); - if (_is_const(self)) { *counter = stats_cluster_single_get_counter(self->const_cluster); @@ -179,6 +166,30 @@ filterx_metrics_get_stats_counter(FilterXMetrics *self, StatsCounterItem **count return success; } +gboolean +filterx_metrics_init(FilterXMetrics *self, GlobalConfig *cfg) +{ + if (!filterx_expr_init(self->key.expr, cfg)) + return FALSE; + + if (!filterx_metrics_labels_init(self->labels, cfg)) + { + filterx_expr_deinit(self->key.expr, cfg); + return FALSE; + } + + _optimize(self); + + return TRUE; +} + +void +filterx_metrics_deinit(FilterXMetrics *self, GlobalConfig *cfg) +{ + filterx_expr_deinit(self->key.expr, cfg); + filterx_metrics_labels_deinit(self->labels, cfg); +} + void filterx_metrics_free(FilterXMetrics *self) { @@ -243,8 +254,6 @@ filterx_metrics_new(gint level, FilterXExpr *key, FilterXExpr *labels) if (!_init_labels(self, labels)) goto error; - g_atomic_counter_set(&self->is_optimized, FALSE); - return self; error: diff --git a/lib/filterx/filterx-metrics.h b/lib/filterx/filterx-metrics.h index 567885d77..d850d0f22 100644 --- a/lib/filterx/filterx-metrics.h +++ b/lib/filterx/filterx-metrics.h @@ -34,6 +34,8 @@ gboolean filterx_metrics_is_enabled(FilterXMetrics *self); gboolean filterx_metrics_get_stats_counter(FilterXMetrics *self, StatsCounterItem **counter); FilterXMetrics *filterx_metrics_new(gint level, FilterXExpr *key, FilterXExpr *labels); +gboolean filterx_metrics_init(FilterXMetrics *self, GlobalConfig *cfg); +void filterx_metrics_deinit(FilterXMetrics *self, GlobalConfig *cfg); void filterx_metrics_free(FilterXMetrics *self); #endif diff --git a/lib/filterx/filterx-pipe.c b/lib/filterx/filterx-pipe.c index cc4ccea9e..1f2142edb 100644 --- a/lib/filterx/filterx-pipe.c +++ b/lib/filterx/filterx-pipe.c @@ -41,9 +41,21 @@ log_filterx_pipe_init(LogPipe *s) if (!self->name) self->name = cfg_tree_get_rule_name(&cfg->tree, ENC_FILTER, s->expr_node); + if (!filterx_expr_init(self->block, cfg)) + return FALSE; + return TRUE; } +static gboolean +log_filterx_pipe_deinit(LogPipe *s) +{ + LogFilterXPipe *self = (LogFilterXPipe *) s; + GlobalConfig *cfg = log_pipe_get_config(s); + + filterx_expr_deinit(self->block, cfg); + return TRUE; +} static void log_filterx_pipe_queue(LogPipe *s, LogMessage *msg, const LogPathOptions *path_options) @@ -127,6 +139,7 @@ log_filterx_pipe_new(FilterXExpr *block, GlobalConfig *cfg) log_pipe_init_instance(&self->super, cfg); self->super.flags = (self->super.flags | PIF_CONFIG_RELATED); self->super.init = log_filterx_pipe_init; + self->super.deinit = log_filterx_pipe_deinit; self->super.queue = log_filterx_pipe_queue; self->super.free_fn = log_filterx_pipe_free; self->super.clone = log_filterx_pipe_clone; diff --git a/lib/filterx/func-flatten.c b/lib/filterx/func-flatten.c index bcda2ec8f..4b8b79511 100644 --- a/lib/filterx/func-flatten.c +++ b/lib/filterx/func-flatten.c @@ -208,6 +208,26 @@ _eval(FilterXExpr *s) return result ? filterx_boolean_new(TRUE) : NULL; } +static gboolean +_init(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXFunctionFlatten *self = (FilterXFunctionFlatten *) s; + + if (!filterx_expr_init(self->dict_expr, cfg)) + return FALSE; + + return filterx_function_init_method(&self->super, cfg); +} + +static void +_deinit(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXFunctionFlatten *self = (FilterXFunctionFlatten *) s; + + filterx_expr_deinit(self->dict_expr, cfg); + filterx_function_deinit_method(&self->super, cfg); +} + static void _free(FilterXExpr *s) { @@ -262,6 +282,8 @@ filterx_function_flatten_new(FilterXFunctionArgs *args, GError **error) FilterXFunctionFlatten *self = g_new0(FilterXFunctionFlatten, 1); filterx_function_init_instance(&self->super, "flatten"); self->super.super.eval = _eval; + self->super.super.init = _init; + self->super.super.deinit = _deinit; self->super.super.free_fn = _free; if (!_extract_args(self, args, error)) diff --git a/lib/filterx/func-istype.c b/lib/filterx/func-istype.c index fce1fc0d9..898dd4d11 100644 --- a/lib/filterx/func-istype.c +++ b/lib/filterx/func-istype.c @@ -59,6 +59,25 @@ _eval(FilterXExpr *s) return filterx_boolean_new(result); } +static gboolean +_init(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXFunctionIsType *self = (FilterXFunctionIsType *) s; + + if (!filterx_expr_init(self->object_expr, cfg)) + return FALSE; + + return filterx_function_init_method(&self->super, cfg); +} + +static void +_deinit(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXFunctionIsType *self = (FilterXFunctionIsType *) s; + filterx_expr_deinit(self->object_expr, cfg); + filterx_function_deinit_method(&self->super, cfg); +} + static void _free(FilterXExpr *s) { @@ -130,6 +149,8 @@ filterx_function_istype_new(FilterXFunctionArgs *args, GError **error) FilterXFunctionIsType *self = g_new0(FilterXFunctionIsType, 1); filterx_function_init_instance(&self->super, "istype"); self->super.super.eval = _eval; + self->super.super.init = _init; + self->super.super.deinit = _deinit; self->super.super.free_fn = _free; if (!_extract_args(self, args, error) || diff --git a/lib/filterx/func-str.c b/lib/filterx/func-str.c index 217473a76..7d2b55d30 100644 --- a/lib/filterx/func-str.c +++ b/lib/filterx/func-str.c @@ -217,6 +217,33 @@ _expr_affix_init_needle(FilterXExprAffix *self) return TRUE; } +static gboolean +_expr_affix_init(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXExprAffix *self = (FilterXExprAffix *) s; + + if (!filterx_expr_init(self->haystack, cfg)) + return FALSE; + + if (!filterx_expr_init(self->needle.expr, cfg)) + { + filterx_expr_deinit(self->haystack, cfg); + return FALSE; + } + + return filterx_function_init_method(&self->super, cfg); +} + +static void +_expr_affix_deinit(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXExprAffix *self = (FilterXExprAffix *) s; + + filterx_expr_deinit(self->haystack, cfg); + filterx_expr_deinit(self->needle.expr, cfg); + filterx_function_deinit_method(&self->super, cfg); +} + static void _expr_affix_free(FilterXExpr *s) { @@ -376,6 +403,8 @@ _function_affix_new(FilterXFunctionArgs *args, filterx_function_init_instance(&self->super, affix_name); self->super.super.eval = _expr_affix_eval; + self->super.super.init = _expr_affix_init; + self->super.super.deinit = _expr_affix_deinit; self->super.super.free_fn = _expr_affix_free; self->needle.cached_strings = g_ptr_array_new_with_free_func((GDestroyNotify) _string_with_cache_free); diff --git a/lib/filterx/func-unset-empties.c b/lib/filterx/func-unset-empties.c index 0ad388e3d..9ac534d60 100644 --- a/lib/filterx/func-unset-empties.c +++ b/lib/filterx/func-unset-empties.c @@ -248,6 +248,26 @@ _eval(FilterXExpr *s) return success ? filterx_boolean_new(TRUE) : NULL; } +static gboolean +_init(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXFunctionUnsetEmpties *self = (FilterXFunctionUnsetEmpties *) s; + + if (!filterx_expr_init_method(self->object_expr, cfg)) + return FALSE; + + return filterx_function_init_method(&self->super, cfg); +} + +static void +_deinit(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXFunctionUnsetEmpties *self = (FilterXFunctionUnsetEmpties *) s; + + filterx_expr_deinit(self->object_expr, cfg); + filterx_function_deinit_method(&self->super, cfg); +} + static void _free(FilterXExpr *s) { @@ -486,6 +506,8 @@ filterx_function_unset_empties_new(FilterXFunctionArgs *args, GError **error) FilterXFunctionUnsetEmpties *self = g_new0(FilterXFunctionUnsetEmpties, 1); filterx_function_init_instance(&self->super, "unset_empties"); self->super.super.eval = _eval; + self->super.super.init = _init; + self->super.super.deinit = _deinit; self->super.super.free_fn = _free; reset_flags(&self->flags, ALL_FLAG_SET(FilterXFunctionUnsetEmptiesFlags)); diff --git a/modules/cef/event-format-parser.c b/modules/cef/event-format-parser.c index 3d19c5900..1ecbb7f52 100644 --- a/modules/cef/event-format-parser.c +++ b/modules/cef/event-format-parser.c @@ -279,6 +279,25 @@ _generate(FilterXExprGenerator *s, FilterXObject *fillable) return ok; } +static gboolean +_init(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXFunctionEventFormatParser *self = (FilterXFunctionEventFormatParser *) s; + + if (!filterx_expr_init(self->msg, cfg)) + return FALSE; + + return filterx_generator_init_method(s, cfg); +} + +static void +_deinit(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXFunctionEventFormatParser *self = (FilterXFunctionEventFormatParser *) s; + filterx_expr_deinit(self->msg, cfg); + filterx_generator_deinit_method(s, cfg); +} + static void _free(FilterXExpr *s) { @@ -383,6 +402,8 @@ filterx_function_parser_init_instance(FilterXFunctionEventFormatParser *self, co filterx_generator_function_init_instance(&self->super, fn_name); self->super.super.generate = _generate; self->super.super.create_container = filterx_generator_create_dict_container; + self->super.super.super.init = _init; + self->super.super.super.deinit = _deinit; self->super.super.super.free_fn = _free; _set_config(self, cfg); diff --git a/modules/csvparser/filterx-func-format-csv.c b/modules/csvparser/filterx-func-format-csv.c index ac4ecd848..6f47b0998 100644 --- a/modules/csvparser/filterx-func-format-csv.c +++ b/modules/csvparser/filterx-func-format-csv.c @@ -164,6 +164,33 @@ _eval(FilterXExpr *s) return success ? filterx_string_new(formatted->str, formatted->len) : NULL; } +static gboolean +_init(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXFunctionFormatCSV *self = (FilterXFunctionFormatCSV *) s; + + if (!filterx_expr_init(self->input, cfg)) + return FALSE; + + if (!filterx_expr_init(self->columns, cfg)) + { + filterx_expr_deinit(self->input, cfg); + return FALSE; + } + + return filterx_function_init_method(&self->super, cfg); +} + +static void +_deinit(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXFunctionFormatCSV *self = (FilterXFunctionFormatCSV *) s; + + filterx_expr_deinit(self->input, cfg); + filterx_expr_deinit(self->columns, cfg); + filterx_function_deinit_method(&self->super, cfg); +} + static void _free(FilterXExpr *s) { @@ -271,6 +298,8 @@ filterx_function_format_csv_new(FilterXFunctionArgs *args, GError **error) filterx_function_init_instance(&self->super, "format_csv"); self->super.super.eval = _eval; + self->super.super.init = _init; + self->super.super.deinit = _deinit; self->super.super.free_fn = _free; self->delimiter = ','; self->default_value = filterx_string_new("", -1); diff --git a/modules/csvparser/filterx-func-parse-csv.c b/modules/csvparser/filterx-func-parse-csv.c index 95049124f..c0bd0a28c 100644 --- a/modules/csvparser/filterx-func-parse-csv.c +++ b/modules/csvparser/filterx-func-parse-csv.c @@ -282,6 +282,40 @@ _generate(FilterXExprGenerator *s, FilterXObject *fillable) return ok; } +static gboolean +_init(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXFunctionParseCSV *self = (FilterXFunctionParseCSV *) s; + + if (!filterx_expr_init(self->msg, cfg)) + return FALSE; + + if (!filterx_expr_init(self->columns.expr, cfg)) + { + filterx_expr_deinit(self->msg, cfg); + return FALSE; + } + + if (!filterx_expr_init(self->string_delimiters, cfg)) + { + filterx_expr_deinit(self->msg, cfg); + filterx_expr_deinit(self->columns.expr, cfg); + return FALSE; + } + + return filterx_generator_function_init_method(&self->super, cfg); +} + +static void +_deinit(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXFunctionParseCSV *self = (FilterXFunctionParseCSV *) s; + filterx_expr_deinit(self->msg, cfg); + filterx_expr_deinit(self->columns.expr, cfg); + filterx_expr_deinit(self->string_delimiters, cfg); + filterx_generator_function_deinit_method(&self->super, cfg); +} + static void _free(FilterXExpr *s) { @@ -505,6 +539,8 @@ filterx_function_parse_csv_new(FilterXFunctionArgs *args, GError **error) filterx_generator_function_init_instance(&self->super, "parse_csv"); self->super.super.generate = _generate; self->super.super.create_container = _create_container; + self->super.super.super.init = _init; + self->super.super.super.deinit = _deinit; self->super.super.super.free_fn = _free; csv_scanner_options_set_delimiters(&self->options, ","); csv_scanner_options_set_quote_pairs(&self->options, "\"\"''"); diff --git a/modules/kvformat/filterx-func-format-kv.c b/modules/kvformat/filterx-func-format-kv.c index 478d2ef1a..3e340afda 100644 --- a/modules/kvformat/filterx-func-format-kv.c +++ b/modules/kvformat/filterx-func-format-kv.c @@ -116,6 +116,26 @@ _eval(FilterXExpr *s) return success ? filterx_string_new(formatted->str, formatted->len) : NULL; } +static gboolean +_init(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXFunctionFormatKV *self = (FilterXFunctionFormatKV *) s; + + if (!filterx_expr_init(self->kvs, cfg)) + return FALSE; + + return filterx_function_init_method(&self->super, cfg); +} + +static void +_deinit(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXFunctionFormatKV *self = (FilterXFunctionFormatKV *) s; + + filterx_expr_deinit(self->kvs, cfg); + filterx_function_deinit_method(&self->super, cfg); +} + static void _free(FilterXExpr *s) { @@ -218,6 +238,8 @@ filterx_function_format_kv_new(FilterXFunctionArgs *args, GError **error) filterx_function_init_instance(&self->super, "format_kv"); self->super.super.eval = _eval; + self->super.super.init = _init; + self->super.super.deinit = _deinit; self->super.super.free_fn = _free; self->value_separator = '='; self->pair_separator = g_strdup(", "); diff --git a/modules/kvformat/filterx-func-parse-kv.c b/modules/kvformat/filterx-func-parse-kv.c index 6b040e04b..5e8887408 100644 --- a/modules/kvformat/filterx-func-parse-kv.c +++ b/modules/kvformat/filterx-func-parse-kv.c @@ -145,6 +145,25 @@ _generate(FilterXExprGenerator *s, FilterXObject *fillable) return result; } +static gboolean +_init(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXFunctionParseKV *self = (FilterXFunctionParseKV *) s; + + if (!filterx_expr_init(self->msg, cfg)) + return FALSE; + + return filterx_generator_function_init_method(&self->super, cfg); +} + +static void +_deinit(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXFunctionParseKV *self = (FilterXFunctionParseKV *) s; + filterx_expr_deinit(self->msg, cfg); + filterx_generator_function_deinit_method(&self->super, cfg); +} + static void _free(FilterXExpr *s) { @@ -255,6 +274,8 @@ filterx_function_parse_kv_new(FilterXFunctionArgs *args, GError **error) filterx_generator_function_init_instance(&self->super, "parse_kv"); self->super.super.generate = _generate; self->super.super.create_container = filterx_generator_create_dict_container; + self->super.super.super.init = _init; + self->super.super.super.deinit = _deinit; self->super.super.super.free_fn = _free; self->value_separator = '='; self->pair_separator = g_strdup(", "); diff --git a/modules/metrics-probe/filterx/func-update-metric.c b/modules/metrics-probe/filterx/func-update-metric.c index 4e9dea846..bcdc5e0e8 100644 --- a/modules/metrics-probe/filterx/func-update-metric.c +++ b/modules/metrics-probe/filterx/func-update-metric.c @@ -94,6 +94,32 @@ _eval(FilterXExpr *s) return filterx_boolean_new(TRUE); } +static gboolean +_init(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXFunctionUpdateMetric *self = (FilterXFunctionUpdateMetric *) s; + + if (!filterx_expr_init(self->increment.expr, cfg)) + return FALSE; + + if (!filterx_metrics_init(self->metrics, cfg)) + { + filterx_expr_deinit(self->increment.expr, cfg); + return FALSE; + } + + return filterx_function_init_method(&self->super, cfg); +} + +static void +_deinit(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXFunctionUpdateMetric *self = (FilterXFunctionUpdateMetric *) s; + filterx_expr_deinit(self->increment.expr, cfg); + filterx_metrics_deinit(self->metrics, cfg); + filterx_function_deinit_method(&self->super, cfg); +} + static void _free(FilterXExpr *s) { @@ -201,6 +227,8 @@ filterx_function_update_metric_new(FilterXFunctionArgs *args, GError **error) filterx_function_init_instance(&self->super, "update_metric"); self->super.super.eval = _eval; + self->super.super.init = _init; + self->super.super.deinit = _deinit; self->super.super.free_fn = _free; if (!_extract_args(self, args, error) || diff --git a/modules/metrics-probe/tests/test_filterx_func_update_metric.c b/modules/metrics-probe/tests/test_filterx_func_update_metric.c index 3d8525ad8..f0f538a43 100644 --- a/modules/metrics-probe/tests/test_filterx_func_update_metric.c +++ b/modules/metrics-probe/tests/test_filterx_func_update_metric.c @@ -95,6 +95,7 @@ Test(filterx_func_update_metric, key_and_labels) _add_label(labels, "test_label_1", "foo"); _add_label(labels, "test_label_2", "bar"); FilterXExpr *func = _create_func(key, labels, NULL, NULL); + cr_assert(filterx_expr_init(func, configuration)); StatsClusterLabel expected_labels[] = { @@ -115,6 +116,7 @@ Test(filterx_func_update_metric, key_and_labels) G_N_ELEMENTS(expected_labels), 2); + filterx_expr_deinit(func, configuration); filterx_expr_unref(func); } @@ -122,6 +124,7 @@ Test(filterx_func_update_metric, increment) { FilterXExpr *key = filterx_literal_new(filterx_string_new("test_key", -1)); FilterXExpr *func = _create_func(key, NULL, filterx_non_literal_new(filterx_integer_new(42)), NULL); + cr_assert(filterx_expr_init(func, configuration)); StatsClusterLabel expected_labels[] = {}; @@ -137,6 +140,7 @@ Test(filterx_func_update_metric, increment) G_N_ELEMENTS(expected_labels), 84); + filterx_expr_deinit(func, configuration); filterx_expr_unref(func); } @@ -149,7 +153,9 @@ Test(filterx_func_update_metric, level) cr_assert(cfg_init(configuration)); func = _create_func(filterx_literal_new(filterx_string_new("test_key", -1)), NULL, NULL, filterx_literal_new(filterx_integer_new(2))); + cr_assert(filterx_expr_init(func, configuration)); cr_assert(_eval(func)); + filterx_expr_deinit(func, configuration); filterx_expr_unref(func); cr_assert_not(metrics_probe_test_stats_cluster_exists("test_key", expected_labels, G_N_ELEMENTS(expected_labels))); cr_assert(cfg_deinit(configuration)); @@ -158,7 +164,9 @@ Test(filterx_func_update_metric, level) cr_assert(cfg_init(configuration)); func = _create_func(filterx_literal_new(filterx_string_new("test_key", -1)), NULL, NULL, filterx_literal_new(filterx_integer_new(2))); + cr_assert(filterx_expr_init(func, configuration)); cr_assert(_eval(func)); + filterx_expr_deinit(func, configuration); filterx_expr_unref(func); cr_assert_not(metrics_probe_test_stats_cluster_exists("test_key", expected_labels, G_N_ELEMENTS(expected_labels))); cr_assert(cfg_deinit(configuration)); @@ -167,7 +175,9 @@ Test(filterx_func_update_metric, level) cr_assert(cfg_init(configuration)); func = _create_func(filterx_literal_new(filterx_string_new("test_key", -1)), NULL, NULL, filterx_literal_new(filterx_integer_new(2))); + cr_assert(filterx_expr_init(func, configuration)); cr_assert(_eval(func)); + filterx_expr_deinit(func, configuration); filterx_expr_unref(func); metrics_probe_test_assert_counter_value("test_key", expected_labels, diff --git a/modules/xml/filterx-parse-xml.c b/modules/xml/filterx-parse-xml.c index 56db99cca..ef6376d37 100644 --- a/modules/xml/filterx-parse-xml.c +++ b/modules/xml/filterx-parse-xml.c @@ -710,6 +710,26 @@ _extract_args(FilterXGeneratorFunctionParseXml *self, FilterXFunctionArgs *args, return TRUE; } +static gboolean +_init(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXGeneratorFunctionParseXml *self = (FilterXGeneratorFunctionParseXml *) s; + + if (!filterx_expr_init(self->xml_expr, cfg)) + return FALSE; + + return filterx_generator_function_init_method(&self->super, cfg); +} + +static void +_deinit(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXGeneratorFunctionParseXml *self = (FilterXGeneratorFunctionParseXml *) s; + + filterx_expr_deinit(self->xml_expr, cfg); + filterx_generator_function_deinit_method(&self->super, cfg); +} + static void _free(FilterXExpr *s) { @@ -727,6 +747,8 @@ filterx_generator_function_parse_xml_new(FilterXFunctionArgs *args, GError **err filterx_generator_function_init_instance(&self->super, "parse_xml"); self->super.super.generate = _generate; self->super.super.create_container = filterx_generator_create_dict_container; + self->super.super.super.init = _init; + self->super.super.super.deinit = _deinit; self->super.super.super.free_fn = _free; self->create_state = _state_new;