diff --git a/lib/filterx/expr-function.c b/lib/filterx/expr-function.c index 013bcf7e07..89da1b6c8f 100644 --- a/lib/filterx/expr-function.c +++ b/lib/filterx/expr-function.c @@ -88,49 +88,43 @@ _get_arg_object(FilterXSimpleFunction *self, guint64 index) return filterx_expr_eval(expr); } -static GPtrArray * -_simple_function_eval_args(FilterXSimpleFunction *self) +static gboolean +_simple_function_eval_args(FilterXSimpleFunction *self, FilterXObject **args, gsize *args_len) { - GPtrArray *res = g_ptr_array_new_full(self->args->len, (GDestroyNotify) filterx_object_unref); - - for (guint64 i = 0; i < self->args->len; i++) + gsize n = *args_len; + for (gsize i = 0; i < n; i++) { - FilterXObject *obj = _get_arg_object(self, i); - if (obj == NULL) - goto error; - - g_ptr_array_add(res, obj); + if ((args[i] = _get_arg_object(self, i)) == NULL) + { + *args_len = i; + return FALSE; + } } + *args_len = n; + return TRUE; +} - return res; - -error: - g_ptr_array_free(res, TRUE); - return NULL; +static void +_simple_function_free_args(FilterXObject *args[], gsize args_len) +{ + for (gsize i = 0; i < args_len; i++) + filterx_object_unref(args[i]); } static FilterXObject * _simple_eval(FilterXExpr *s) { FilterXSimpleFunction *self = (FilterXSimpleFunction *) s; + gsize args_len = self->args->len; + FilterXObject *args[self->args->len]; + FilterXObject *res = NULL; - GPtrArray *args = NULL; - - if (self->args->len) + if (_simple_function_eval_args(self, args, &args_len)) { - args = _simple_function_eval_args(self); - if (!args) - return NULL; + res = self->function_proto(s, args, args_len); } - FilterXSimpleFunctionProto f = self->function_proto; - - g_assert(f != NULL); - FilterXObject *res = f(s, args); - - if (args != NULL) - g_ptr_array_free(args, TRUE); - + _simple_function_free_args(args, args_len); return res; } diff --git a/lib/filterx/expr-function.h b/lib/filterx/expr-function.h index 0c1085f2a1..513f0a86f5 100644 --- a/lib/filterx/expr-function.h +++ b/lib/filterx/expr-function.h @@ -33,7 +33,7 @@ #include "generic-number.h" #include "plugin.h" -typedef FilterXObject *(*FilterXSimpleFunctionProto)(FilterXExpr *s, GPtrArray *); +typedef FilterXObject *(*FilterXSimpleFunctionProto)(FilterXExpr *s, FilterXObject *args[], gsize args_len); void filterx_simple_function_argument_error(FilterXExpr *s, gchar *error_info, gboolean free_info); diff --git a/lib/filterx/filterx-globals.c b/lib/filterx/filterx-globals.c index 67c977128f..eb6b7176ff 100644 --- a/lib/filterx/filterx-globals.c +++ b/lib/filterx/filterx-globals.c @@ -277,14 +277,13 @@ filterx_global_deinit(void) } FilterXObject * -filterx_typecast_get_arg(FilterXExpr *s, GPtrArray *args) +filterx_typecast_get_arg(FilterXExpr *s, FilterXObject *args[], gsize args_len) { - if (args == NULL || args->len != 1) + if (args == NULL || args_len != 1) { filterx_simple_function_argument_error(s, "Requires exactly one argument", FALSE); return NULL; } - FilterXObject *object = g_ptr_array_index(args, 0); - return object; + return args[0]; } diff --git a/lib/filterx/filterx-globals.h b/lib/filterx/filterx-globals.h index 7b2bd312e7..b75feb734e 100644 --- a/lib/filterx/filterx-globals.h +++ b/lib/filterx/filterx-globals.h @@ -44,6 +44,6 @@ FilterXType *filterx_type_lookup(const gchar *type_name); gboolean filterx_type_register(const gchar *type_name, FilterXType *fxtype); // Helpers -FilterXObject *filterx_typecast_get_arg(FilterXExpr *s, GPtrArray *args); +FilterXObject *filterx_typecast_get_arg(FilterXExpr *s, FilterXObject *args[], gsize args_len); #endif diff --git a/lib/filterx/func-len.c b/lib/filterx/func-len.c index cceb82552d..5aba571681 100644 --- a/lib/filterx/func-len.c +++ b/lib/filterx/func-len.c @@ -28,15 +28,15 @@ #define FILTERX_FUNC_LEN_USAGE "Usage: len(object)" FilterXObject * -filterx_simple_function_len(FilterXExpr *s, GPtrArray *args) +filterx_simple_function_len(FilterXExpr *s, FilterXObject *args[], gsize args_len) { - if (args == NULL || args->len != 1) + if (args == NULL || args_len != 1) { filterx_simple_function_argument_error(s, "Requires exactly one argument", FALSE); return NULL; } - FilterXObject *object = g_ptr_array_index(args, 0); + FilterXObject *object = args[0]; guint64 len; gboolean success = filterx_object_len(object, &len); diff --git a/lib/filterx/func-len.h b/lib/filterx/func-len.h index d93909f3ca..ae748c7e80 100644 --- a/lib/filterx/func-len.h +++ b/lib/filterx/func-len.h @@ -26,6 +26,6 @@ #include "filterx/expr-function.h" -FilterXObject *filterx_simple_function_len(FilterXExpr *s, GPtrArray *args); +FilterXObject *filterx_simple_function_len(FilterXExpr *s, FilterXObject *args[], gsize args_len); #endif diff --git a/lib/filterx/func-sdata.c b/lib/filterx/func-sdata.c index 9e390f8747..5505545bbf 100644 --- a/lib/filterx/func-sdata.c +++ b/lib/filterx/func-sdata.c @@ -118,9 +118,9 @@ filterx_function_is_sdata_from_enterprise_new(FilterXFunctionArgs *args, GError FilterXObject * -filterx_simple_function_has_sdata(FilterXExpr *s, GPtrArray *args) +filterx_simple_function_has_sdata(FilterXExpr *s, FilterXObject *args[], gsize args_len) { - if (args && args->len != 0) + if (args && args_len != 0) { filterx_simple_function_argument_error(s, "Incorrect number of arguments", FALSE); return NULL; diff --git a/lib/filterx/func-sdata.h b/lib/filterx/func-sdata.h index a8aec2c161..c457426322 100644 --- a/lib/filterx/func-sdata.h +++ b/lib/filterx/func-sdata.h @@ -28,7 +28,7 @@ #include "filterx/expr-function.h" FilterXExpr *filterx_function_is_sdata_from_enterprise_new(FilterXFunctionArgs *args, GError **error); -FilterXObject *filterx_simple_function_has_sdata(FilterXExpr *s, GPtrArray *args); +FilterXObject *filterx_simple_function_has_sdata(FilterXExpr *s, FilterXObject *args[], gsize args_len); FilterXExpr *filterx_generator_function_get_sdata_new(FilterXFunctionArgs *args, GError **error); typedef struct FilterXGenFuncGetSdata_ { diff --git a/lib/filterx/func-str-transform.c b/lib/filterx/func-str-transform.c index 6e2a64b84f..fe452791c6 100644 --- a/lib/filterx/func-str-transform.c +++ b/lib/filterx/func-str-transform.c @@ -28,9 +28,9 @@ #include "filterx/filterx-eval.h" static const gchar * -_extract_str_arg(FilterXExpr *s, GPtrArray *args, gssize *len) +_extract_str_arg(FilterXExpr *s, FilterXObject *args[], gsize args_len, gssize *len) { - if (args == NULL || args->len != 1) + if (args == NULL || args_len != 1) { filterx_simple_function_argument_error(s, "Requires exactly one argument", FALSE); return NULL; @@ -38,7 +38,7 @@ _extract_str_arg(FilterXExpr *s, GPtrArray *args, gssize *len) const gchar *str; gsize inner_len; - FilterXObject *object = g_ptr_array_index(args, 0); + FilterXObject *object = args[0]; if (!filterx_object_extract_string_ref(object, &str, &inner_len)) { @@ -51,10 +51,10 @@ _extract_str_arg(FilterXExpr *s, GPtrArray *args, gssize *len) } FilterXObject * -filterx_simple_function_lower(FilterXExpr *s, GPtrArray *args) +filterx_simple_function_lower(FilterXExpr *s, FilterXObject *args[], gsize args_len) { gssize len; - const gchar *str = _extract_str_arg(s, args, &len); + const gchar *str = _extract_str_arg(s, args, args_len, &len); if (!str) return NULL; @@ -66,10 +66,10 @@ filterx_simple_function_lower(FilterXExpr *s, GPtrArray *args) } FilterXObject * -filterx_simple_function_upper(FilterXExpr *s, GPtrArray *args) +filterx_simple_function_upper(FilterXExpr *s, FilterXObject *args[], gsize args_len) { gssize len; - const gchar *str = _extract_str_arg(s, args, &len); + const gchar *str = _extract_str_arg(s, args, args_len, &len); if (!str) return NULL; diff --git a/lib/filterx/func-str-transform.h b/lib/filterx/func-str-transform.h index b3d329576c..dbcccdfb1e 100644 --- a/lib/filterx/func-str-transform.h +++ b/lib/filterx/func-str-transform.h @@ -27,7 +27,7 @@ #include "filterx/expr-function.h" -FilterXObject *filterx_simple_function_lower(FilterXExpr *s, GPtrArray *args); -FilterXObject *filterx_simple_function_upper(FilterXExpr *s, GPtrArray *args); +FilterXObject *filterx_simple_function_lower(FilterXExpr *s, FilterXObject *args[], gsize args_len); +FilterXObject *filterx_simple_function_upper(FilterXExpr *s, FilterXObject *args[], gsize args_len); #endif diff --git a/lib/filterx/func-vars.c b/lib/filterx/func-vars.c index 4251a36140..f78286882c 100644 --- a/lib/filterx/func-vars.c +++ b/lib/filterx/func-vars.c @@ -64,9 +64,9 @@ _add_to_dict(FilterXVariable *variable, gpointer user_data) } FilterXObject * -filterx_simple_function_vars(FilterXExpr *s, GPtrArray *args) +filterx_simple_function_vars(FilterXExpr *s, FilterXObject *args[], gsize args_len) { - if (args && args->len != 0) + if (args && args_len != 0) { filterx_simple_function_argument_error(s, "Incorrect number of arguments", FALSE); return NULL; @@ -150,15 +150,15 @@ _load_from_dict(FilterXObject *key, FilterXObject *value, gpointer user_data) } FilterXObject * -filterx_simple_function_load_vars(FilterXExpr *s, GPtrArray *args) +filterx_simple_function_load_vars(FilterXExpr *s, FilterXObject *args[], gsize args_len) { - if (!args || args->len != 1) + if (!args || args_len != 1) { filterx_simple_function_argument_error(s, "Incorrect number of arguments", FALSE); return NULL; } - FilterXObject *vars = g_ptr_array_index(args, 0); + FilterXObject *vars = args[0]; FilterXObject *vars_unwrapped = filterx_ref_unwrap_ro(vars); FilterXObject *vars_unmarshalled = NULL; diff --git a/lib/filterx/func-vars.h b/lib/filterx/func-vars.h index 88d0161efe..63f57c5607 100644 --- a/lib/filterx/func-vars.h +++ b/lib/filterx/func-vars.h @@ -26,7 +26,7 @@ #include "filterx/expr-function.h" -FilterXObject *filterx_simple_function_vars(FilterXExpr *s, GPtrArray *args); -FilterXObject *filterx_simple_function_load_vars(FilterXExpr *s, GPtrArray *args); +FilterXObject *filterx_simple_function_vars(FilterXExpr *s, FilterXObject *args[], gsize args_len); +FilterXObject *filterx_simple_function_load_vars(FilterXExpr *s, FilterXObject *args[], gsize args_len); #endif diff --git a/lib/filterx/object-datetime.c b/lib/filterx/object-datetime.c index 51517b5835..8e4f373818 100644 --- a/lib/filterx/object-datetime.c +++ b/lib/filterx/object-datetime.c @@ -121,9 +121,9 @@ filterx_datetime_get_value(FilterXObject *s) FilterXObject * -filterx_typecast_datetime(FilterXExpr *s, GPtrArray *args) +filterx_typecast_datetime(FilterXExpr *s, FilterXObject *args[], gsize args_len) { - FilterXObject *object = filterx_typecast_get_arg(s, args); + FilterXObject *object = filterx_typecast_get_arg(s, args, args_len); if (!object) return NULL; @@ -147,13 +147,13 @@ filterx_typecast_datetime(FilterXExpr *s, GPtrArray *args) return filterx_datetime_new(&ut); } - return filterx_typecast_datetime_isodate(s, args); + return filterx_typecast_datetime_isodate(s, args, args_len); } FilterXObject * -filterx_typecast_datetime_isodate(FilterXExpr *s, GPtrArray *args) +filterx_typecast_datetime_isodate(FilterXExpr *s, FilterXObject *args[], gsize args_len) { - FilterXObject *object = filterx_typecast_get_arg(s, args); + FilterXObject *object = filterx_typecast_get_arg(s, args, args_len); if (!object) return NULL; diff --git a/lib/filterx/object-datetime.h b/lib/filterx/object-datetime.h index 17e4be1359..d31a0e7fce 100644 --- a/lib/filterx/object-datetime.h +++ b/lib/filterx/object-datetime.h @@ -34,8 +34,8 @@ FILTERX_DECLARE_TYPE(datetime); FilterXObject *filterx_datetime_new(const UnixTime *ut); UnixTime filterx_datetime_get_value(FilterXObject *s); -FilterXObject *filterx_typecast_datetime(FilterXExpr *s, GPtrArray *args); -FilterXObject *filterx_typecast_datetime_isodate(FilterXExpr *, GPtrArray *args); +FilterXObject *filterx_typecast_datetime(FilterXExpr *s, FilterXObject *args[], gsize args_len); +FilterXObject *filterx_typecast_datetime_isodate(FilterXExpr *, FilterXObject *args[], gsize args_len); FilterXExpr *filterx_function_strptime_new(FilterXFunctionArgs *args, GError **error); FilterXExpr *filterx_function_strftime_new(FilterXFunctionArgs *args, GError **error); diff --git a/lib/filterx/object-json-array.c b/lib/filterx/object-json-array.c index 3596461c1c..aa83e12ad7 100644 --- a/lib/filterx/object-json-array.c +++ b/lib/filterx/object-json-array.c @@ -316,18 +316,18 @@ filterx_json_array_new_from_syslog_ng_list(const gchar *repr, gssize repr_len) } FilterXObject * -filterx_json_array_new_from_args(FilterXExpr *s, GPtrArray *args) +filterx_json_array_new_from_args(FilterXExpr *s, FilterXObject *args[], gsize args_len) { - if (!args || args->len == 0) + if (!args || args_len == 0) return filterx_json_array_new_empty(); - if (args->len != 1) + if (args_len != 1) { filterx_simple_function_argument_error(s, "Requires zero or one argument", FALSE); return NULL; } - FilterXObject *arg = (FilterXObject *) g_ptr_array_index(args, 0); + FilterXObject *arg = args[0]; FilterXObject *json_arr = filterx_ref_unwrap_ro(arg); if (filterx_object_is_type(json_arr, &FILTERX_TYPE_NAME(json_array))) diff --git a/lib/filterx/object-json.c b/lib/filterx/object-json.c index 7fe7125e82..0bd6d10884 100644 --- a/lib/filterx/object-json.c +++ b/lib/filterx/object-json.c @@ -186,18 +186,18 @@ filterx_json_new_from_repr(const gchar *repr, gssize repr_len) } FilterXObject * -filterx_json_new_from_args(FilterXExpr *s, GPtrArray *args) +filterx_json_new_from_args(FilterXExpr *s, FilterXObject *args[], gsize args_len) { - if (!args || args->len == 0) + if (!args || args_len == 0) return filterx_json_object_new_empty(); - if (args->len != 1) + if (args_len != 1) { filterx_eval_push_error("Too many arguments", s, NULL); return NULL; } - FilterXObject *arg = (FilterXObject *) g_ptr_array_index(args, 0); + FilterXObject *arg = args[0]; FilterXObject *arg_unwrapped = filterx_ref_unwrap_ro(arg); if (filterx_object_is_type(arg_unwrapped, &FILTERX_TYPE_NAME(json_array)) || diff --git a/lib/filterx/object-json.h b/lib/filterx/object-json.h index 22116b7ce0..3dc79718f4 100644 --- a/lib/filterx/object-json.h +++ b/lib/filterx/object-json.h @@ -41,8 +41,8 @@ FilterXObject *filterx_json_array_new_from_syslog_ng_list(const gchar *repr, gss FilterXObject *filterx_json_object_new_empty(void); FilterXObject *filterx_json_array_new_empty(void); -FilterXObject *filterx_json_new_from_args(FilterXExpr *s, GPtrArray *args); -FilterXObject *filterx_json_array_new_from_args(FilterXExpr *s, GPtrArray *args); +FilterXObject *filterx_json_new_from_args(FilterXExpr *s, FilterXObject *args[], gsize args_len); +FilterXObject *filterx_json_array_new_from_args(FilterXExpr *s, FilterXObject *args[], gsize args_len); FilterXObject *filterx_json_new_from_object(struct json_object *object); diff --git a/lib/filterx/object-metrics-labels.c b/lib/filterx/object-metrics-labels.c index dc40d53f0d..5bd0a3a11d 100644 --- a/lib/filterx/object-metrics-labels.c +++ b/lib/filterx/object-metrics-labels.c @@ -293,9 +293,9 @@ filterx_object_metrics_labels_new(guint reserved_size) } FilterXObject * -filterx_simple_function_metrics_labels(FilterXExpr *s, GPtrArray *args) +filterx_simple_function_metrics_labels(FilterXExpr *s, FilterXObject *args[], gsize args_len) { - if (args && args->len) + if (args && args_len) { filterx_simple_function_argument_error(s, "unexpected argument.", FALSE); return NULL; @@ -305,16 +305,16 @@ filterx_simple_function_metrics_labels(FilterXExpr *s, GPtrArray *args) } static FilterXObject * -_dedup_extract_obj_arg(FilterXExpr *s, GPtrArray *args) +_dedup_extract_obj_arg(FilterXExpr *s, FilterXObject *args[], gsize args_len) { - if (!args || args->len != 1) + if (!args || args_len != 1) { filterx_simple_function_argument_error(s, "unexpected number of arguments. " DEDUP_METRICS_LABELS_USAGE, FALSE); return NULL; } - FilterXObject *obj = g_ptr_array_index(args, 0); + FilterXObject *obj = args[0]; FilterXObject *typed_obj = filterx_ref_unwrap_ro(obj); if (!filterx_object_is_type(typed_obj, &FILTERX_TYPE_NAME(metrics_labels))) { @@ -327,9 +327,9 @@ _dedup_extract_obj_arg(FilterXExpr *s, GPtrArray *args) } FilterXObject * -filterx_simple_function_dedup_metrics_labels(FilterXExpr *s, GPtrArray *args) +filterx_simple_function_dedup_metrics_labels(FilterXExpr *s, FilterXObject *args[], gsize args_len) { - FilterXObject *obj = _dedup_extract_obj_arg(s, args); + FilterXObject *obj = _dedup_extract_obj_arg(s, args, args_len); if (!obj) return NULL; diff --git a/lib/filterx/object-metrics-labels.h b/lib/filterx/object-metrics-labels.h index ffdfbd1687..a7a3622cd9 100644 --- a/lib/filterx/object-metrics-labels.h +++ b/lib/filterx/object-metrics-labels.h @@ -32,7 +32,7 @@ FILTERX_DECLARE_TYPE(metrics_labels); FilterXObject *filterx_object_metrics_labels_new(guint reserved_size); StatsClusterLabel *filterx_object_metrics_labels_get_value_ref(FilterXObject *s, gsize *len); -FilterXObject *filterx_simple_function_metrics_labels(FilterXExpr *s, GPtrArray *args); -FilterXObject *filterx_simple_function_dedup_metrics_labels(FilterXExpr *s, GPtrArray *args); +FilterXObject *filterx_simple_function_metrics_labels(FilterXExpr *s, FilterXObject *args[], gsize args_len); +FilterXObject *filterx_simple_function_dedup_metrics_labels(FilterXExpr *s, FilterXObject *args[], gsize args_len); #endif diff --git a/lib/filterx/object-primitive.c b/lib/filterx/object-primitive.c index c0e7030264..ebb894b651 100644 --- a/lib/filterx/object-primitive.c +++ b/lib/filterx/object-primitive.c @@ -268,9 +268,9 @@ filterx_primitive_get_value(FilterXObject *s) } FilterXObject * -filterx_typecast_boolean(FilterXExpr *s, GPtrArray *args) +filterx_typecast_boolean(FilterXExpr *s, FilterXObject *args[], gsize args_len) { - FilterXObject *object = filterx_typecast_get_arg(s, args); + FilterXObject *object = filterx_typecast_get_arg(s, args, args_len); if (!object) return NULL; @@ -284,9 +284,9 @@ filterx_typecast_boolean(FilterXExpr *s, GPtrArray *args) } FilterXObject * -filterx_typecast_integer(FilterXExpr *s, GPtrArray *args) +filterx_typecast_integer(FilterXExpr *s, FilterXObject *args[], gsize args_len) { - FilterXObject *object = filterx_typecast_get_arg(s, args); + FilterXObject *object = filterx_typecast_get_arg(s, args, args_len); if (!object) return NULL; @@ -320,9 +320,9 @@ filterx_typecast_integer(FilterXExpr *s, GPtrArray *args) } FilterXObject * -filterx_typecast_double(FilterXExpr *s, GPtrArray *args) +filterx_typecast_double(FilterXExpr *s, FilterXObject *args[], gsize args_len) { - FilterXObject *object = filterx_typecast_get_arg(s, args); + FilterXObject *object = filterx_typecast_get_arg(s, args, args_len); if (!object) return NULL; diff --git a/lib/filterx/object-primitive.h b/lib/filterx/object-primitive.h index 41898b8811..955207e061 100644 --- a/lib/filterx/object-primitive.h +++ b/lib/filterx/object-primitive.h @@ -50,9 +50,9 @@ FilterXObject *filterx_boolean_new(gboolean value); FilterXObject *filterx_enum_new(GlobalConfig *cfg, const gchar *namespace_name, const gchar *enum_name); GenericNumber filterx_primitive_get_value(FilterXObject *s); -FilterXObject *filterx_typecast_boolean(FilterXExpr *s, GPtrArray *args); -FilterXObject *filterx_typecast_integer(FilterXExpr *s, GPtrArray *args); -FilterXObject *filterx_typecast_double(FilterXExpr *s, GPtrArray *args); +FilterXObject *filterx_typecast_boolean(FilterXExpr *s, FilterXObject *args[], gsize args_len); +FilterXObject *filterx_typecast_integer(FilterXExpr *s, FilterXObject *args[], gsize args_len); +FilterXObject *filterx_typecast_double(FilterXExpr *s, FilterXObject *args[], gsize args_len); gboolean bool_repr(gboolean bool_val, GString *repr); gboolean double_repr(double val, GString *repr); diff --git a/lib/filterx/object-string.c b/lib/filterx/object-string.c index 23439fc87b..baf45a10fb 100644 --- a/lib/filterx/object-string.c +++ b/lib/filterx/object-string.c @@ -264,9 +264,9 @@ filterx_protobuf_new(const gchar *mem, gssize mem_len) } FilterXObject * -filterx_typecast_string(FilterXExpr *s, GPtrArray *args) +filterx_typecast_string(FilterXExpr *s, FilterXObject *args[], gsize args_len) { - FilterXObject *object = filterx_typecast_get_arg(s, args); + FilterXObject *object = filterx_typecast_get_arg(s, args, args_len); if (!object) return NULL; @@ -287,9 +287,9 @@ filterx_typecast_string(FilterXExpr *s, GPtrArray *args) } FilterXObject * -filterx_typecast_bytes(FilterXExpr *s, GPtrArray *args) +filterx_typecast_bytes(FilterXExpr *s, FilterXObject *args[], gsize args_len) { - FilterXObject *object = filterx_typecast_get_arg(s, args); + FilterXObject *object = filterx_typecast_get_arg(s, args, args_len); if (!object) return NULL; @@ -311,9 +311,9 @@ filterx_typecast_bytes(FilterXExpr *s, GPtrArray *args) } FilterXObject * -filterx_typecast_protobuf(FilterXExpr *s, GPtrArray *args) +filterx_typecast_protobuf(FilterXExpr *s, FilterXObject *args[], gsize args_len) { - FilterXObject *object = filterx_typecast_get_arg(s, args); + FilterXObject *object = filterx_typecast_get_arg(s, args, args_len); if (!object) return NULL; diff --git a/lib/filterx/object-string.h b/lib/filterx/object-string.h index ea2b4b0d70..736ede0cfb 100644 --- a/lib/filterx/object-string.h +++ b/lib/filterx/object-string.h @@ -34,9 +34,9 @@ FILTERX_DECLARE_TYPE(protobuf); const gchar *filterx_string_get_value_ref(FilterXObject *s, gsize *length); const gchar *filterx_bytes_get_value_ref(FilterXObject *s, gsize *length); const gchar *filterx_protobuf_get_value_ref(FilterXObject *s, gsize *length); -FilterXObject *filterx_typecast_string(FilterXExpr *s, GPtrArray *args); -FilterXObject *filterx_typecast_bytes(FilterXExpr *s, GPtrArray *args); -FilterXObject *filterx_typecast_protobuf(FilterXExpr *s, GPtrArray *args); +FilterXObject *filterx_typecast_string(FilterXExpr *s, FilterXObject *args[], gsize args_len); +FilterXObject *filterx_typecast_bytes(FilterXExpr *s, FilterXObject *args[], gsize args_len); +FilterXObject *filterx_typecast_protobuf(FilterXExpr *s, FilterXObject *args[], gsize args_len); FilterXObject *filterx_string_new(const gchar *str, gssize str_len); FilterXObject *filterx_bytes_new(const gchar *str, gssize str_len); diff --git a/modules/examples/filterx/example-filterx-func/example-filterx-func-plugin.c b/modules/examples/filterx/example-filterx-func/example-filterx-func-plugin.c index a3367c99f3..f26c3dd5ac 100644 --- a/modules/examples/filterx/example-filterx-func/example-filterx-func-plugin.c +++ b/modules/examples/filterx/example-filterx-func/example-filterx-func-plugin.c @@ -29,27 +29,27 @@ #include "filterx/object-primitive.h" static FilterXObject * -echo(FilterXExpr *s, GPtrArray *args) +echo(FilterXExpr *s, FilterXObject *args[], gsize args_len) { GString *buf = scratch_buffers_alloc(); LogMessageValueType t; if (args == NULL || - args->len < 1) + args_len < 1) { return NULL; } - for (int i = 0; i < args->len; i++) + for (int i = 0; i < args_len; i++) { - if (!filterx_object_marshal(args->pdata[i], buf, &t)) + if (!filterx_object_marshal(args[i], buf, &t)) goto exit; msg_debug("FILTERX EXAMPLE ECHO", evt_tag_str("value", buf->str), evt_tag_str("type", log_msg_value_type_to_str(t))); } - if (args->len > 0) - return filterx_object_ref(args->pdata[0]); + if (args_len > 0) + return filterx_object_ref(args[0]); exit: return filterx_boolean_new(FALSE); } diff --git a/modules/grpc/otel/filterx/object-otel-array.cpp b/modules/grpc/otel/filterx/object-otel-array.cpp index 333f40f21a..9334802e0b 100644 --- a/modules/grpc/otel/filterx/object-otel-array.cpp +++ b/modules/grpc/otel/filterx/object-otel-array.cpp @@ -249,20 +249,20 @@ _filterx_otel_array_clone(FilterXObject *s) } FilterXObject * -filterx_otel_array_new_from_args(FilterXExpr *s, GPtrArray *args) +filterx_otel_array_new_from_args(FilterXExpr *s, FilterXObject *args[], gsize args_len) { FilterXOtelArray *self = g_new0(FilterXOtelArray, 1); _init_instance(self); try { - if (!args || args->len == 0) + if (!args || args_len == 0) { self->cpp = new Array(self); } - else if (args->len == 1) + else if (args_len == 1) { - FilterXObject *arg = (FilterXObject *) g_ptr_array_index(args, 0); + FilterXObject *arg = args[0]; FilterXObject *list_arg = filterx_ref_unwrap_ro(arg); if (filterx_object_is_type(list_arg, &FILTERX_TYPE_NAME(list))) diff --git a/modules/grpc/otel/filterx/object-otel-kvlist.cpp b/modules/grpc/otel/filterx/object-otel-kvlist.cpp index 1794143954..956d1f6f3a 100644 --- a/modules/grpc/otel/filterx/object-otel-kvlist.cpp +++ b/modules/grpc/otel/filterx/object-otel-kvlist.cpp @@ -364,20 +364,20 @@ _filterx_otel_kvlist_clone(FilterXObject *s) } FilterXObject * -filterx_otel_kvlist_new_from_args(FilterXExpr *s, GPtrArray *args) +filterx_otel_kvlist_new_from_args(FilterXExpr *s, FilterXObject *args[], gsize args_len) { FilterXOtelKVList *self = g_new0(FilterXOtelKVList, 1); _init_instance(self); try { - if (!args || args->len == 0) + if (!args || args_len == 0) { self->cpp = new KVList(self); } - else if (args->len == 1) + else if (args_len == 1) { - FilterXObject *arg = (FilterXObject *) g_ptr_array_index(args, 0); + FilterXObject *arg = args[0]; FilterXObject *dict_arg = filterx_ref_unwrap_ro(arg); if (filterx_object_is_type(dict_arg, &FILTERX_TYPE_NAME(dict))) { diff --git a/modules/grpc/otel/filterx/object-otel-logrecord.cpp b/modules/grpc/otel/filterx/object-otel-logrecord.cpp index 596ea515fe..f021cbf9f3 100644 --- a/modules/grpc/otel/filterx/object-otel-logrecord.cpp +++ b/modules/grpc/otel/filterx/object-otel-logrecord.cpp @@ -281,20 +281,20 @@ _filterx_otel_logrecord_clone(FilterXObject *s) } FilterXObject * -filterx_otel_logrecord_new_from_args(FilterXExpr *s, GPtrArray *args) +filterx_otel_logrecord_new_from_args(FilterXExpr *s, FilterXObject *args[], gsize args_len) { FilterXOtelLogRecord *self = g_new0(FilterXOtelLogRecord, 1); _init_instance(self); try { - if (!args || args->len == 0) + if (!args || args_len == 0) { self->cpp = new LogRecord(self); } - else if (args->len == 1) + else if (args_len == 1) { - FilterXObject *arg = (FilterXObject *) g_ptr_array_index(args, 0); + FilterXObject *arg = args[0]; FilterXObject *dict_arg = filterx_ref_unwrap_ro(arg); if (filterx_object_is_type(dict_arg, &FILTERX_TYPE_NAME(dict))) { diff --git a/modules/grpc/otel/filterx/object-otel-resource.cpp b/modules/grpc/otel/filterx/object-otel-resource.cpp index 475b32e314..f725939fd3 100644 --- a/modules/grpc/otel/filterx/object-otel-resource.cpp +++ b/modules/grpc/otel/filterx/object-otel-resource.cpp @@ -267,20 +267,20 @@ _filterx_otel_resource_clone(FilterXObject *s) } FilterXObject * -filterx_otel_resource_new_from_args(FilterXExpr *s, GPtrArray *args) +filterx_otel_resource_new_from_args(FilterXExpr *s, FilterXObject *args[], gsize args_len) { FilterXOtelResource *self = g_new0(FilterXOtelResource, 1); _init_instance(self); try { - if (!args || args->len == 0) + if (!args || args_len == 0) { self->cpp = new Resource(self); } - else if (args->len == 1) + else if (args_len == 1) { - FilterXObject *arg = (FilterXObject *) g_ptr_array_index(args, 0); + FilterXObject *arg = args[0]; FilterXObject *dict_arg = filterx_ref_unwrap_ro(arg); if (filterx_object_is_type(dict_arg, &FILTERX_TYPE_NAME(dict))) { diff --git a/modules/grpc/otel/filterx/object-otel-scope.cpp b/modules/grpc/otel/filterx/object-otel-scope.cpp index ead2c40c10..c6b2703d57 100644 --- a/modules/grpc/otel/filterx/object-otel-scope.cpp +++ b/modules/grpc/otel/filterx/object-otel-scope.cpp @@ -267,20 +267,20 @@ _filterx_otel_scope_clone(FilterXObject *s) } FilterXObject * -filterx_otel_scope_new_from_args(FilterXExpr *s, GPtrArray *args) +filterx_otel_scope_new_from_args(FilterXExpr *s, FilterXObject *args[], gsize args_len) { FilterXOtelScope *self = g_new0(FilterXOtelScope, 1); _init_instance(self); try { - if (!args || args->len == 0) + if (!args || args_len == 0) { self->cpp = new Scope(self); } - else if (args->len == 1) + else if (args_len == 1) { - FilterXObject *arg = (FilterXObject *) g_ptr_array_index(args, 0); + FilterXObject *arg = args[0]; FilterXObject *dict_arg = filterx_ref_unwrap_ro(arg); if (filterx_object_is_type(dict_arg, &FILTERX_TYPE_NAME(dict))) { diff --git a/modules/grpc/otel/filterx/object-otel.h b/modules/grpc/otel/filterx/object-otel.h index 313787410b..c5da73077b 100644 --- a/modules/grpc/otel/filterx/object-otel.h +++ b/modules/grpc/otel/filterx/object-otel.h @@ -36,40 +36,40 @@ FILTERX_SIMPLE_FUNCTION_DECLARE(otel_kvlist); FILTERX_SIMPLE_FUNCTION_DECLARE(otel_array); -FilterXObject *filterx_otel_logrecord_new_from_args(FilterXExpr *s, GPtrArray *args); -FilterXObject *filterx_otel_resource_new_from_args(FilterXExpr *s, GPtrArray *args); -FilterXObject *filterx_otel_scope_new_from_args(FilterXExpr *s, GPtrArray *args); -FilterXObject *filterx_otel_kvlist_new_from_args(FilterXExpr *s, GPtrArray *args); -FilterXObject *filterx_otel_array_new_from_args(FilterXExpr *s, GPtrArray *args); +FilterXObject *filterx_otel_logrecord_new_from_args(FilterXExpr *s, FilterXObject *args[], gsize args_len); +FilterXObject *filterx_otel_resource_new_from_args(FilterXExpr *s, FilterXObject *args[], gsize args_len); +FilterXObject *filterx_otel_scope_new_from_args(FilterXExpr *s, FilterXObject *args[], gsize args_len); +FilterXObject *filterx_otel_kvlist_new_from_args(FilterXExpr *s, FilterXObject *args[], gsize args_len); +FilterXObject *filterx_otel_array_new_from_args(FilterXExpr *s, FilterXObject *args[], gsize args_len); static inline FilterXObject * filterx_otel_logrecord_new(void) { - return filterx_otel_logrecord_new_from_args(NULL, NULL); + return filterx_otel_logrecord_new_from_args(NULL, NULL, 0); } static inline FilterXObject * filterx_otel_resource_new(void) { - return filterx_otel_resource_new_from_args(NULL, NULL); + return filterx_otel_resource_new_from_args(NULL, NULL, 0); } static inline FilterXObject * filterx_otel_scope_new(void) { - return filterx_otel_scope_new_from_args(NULL, NULL); + return filterx_otel_scope_new_from_args(NULL, NULL, 0); } static inline FilterXObject * filterx_otel_kvlist_new(void) { - return filterx_otel_kvlist_new_from_args(NULL, NULL); + return filterx_otel_kvlist_new_from_args(NULL, NULL, 0); } static inline FilterXObject * filterx_otel_array_new(void) { - return filterx_otel_array_new_from_args(NULL, NULL); + return filterx_otel_array_new_from_args(NULL, NULL, 0); } gpointer grpc_otel_filterx_enum_construct(Plugin *self); diff --git a/modules/json/filterx-format-json.c b/modules/json/filterx-format-json.c index 79051e561a..4af6ab0cd8 100644 --- a/modules/json/filterx-format-json.c +++ b/modules/json/filterx-format-json.c @@ -297,16 +297,16 @@ _format_json(FilterXObject *arg) } FilterXObject * -filterx_format_json_call(FilterXExpr *s, GPtrArray *args) +filterx_format_json_call(FilterXExpr *s, FilterXObject *args[], gsize args_len) { - if (!args || args->len != 1) + if (!args || args_len != 1) { msg_error("FilterX: format_json(): Invalid number of arguments. " "Usage: format_json($data)"); return NULL; } - FilterXObject *arg = (FilterXObject *) g_ptr_array_index(args, 0); + FilterXObject *arg = args[0]; return _format_json(arg); } diff --git a/modules/json/filterx-format-json.h b/modules/json/filterx-format-json.h index 0e495b61c3..e598163f8c 100644 --- a/modules/json/filterx-format-json.h +++ b/modules/json/filterx-format-json.h @@ -24,7 +24,7 @@ #include "filterx/filterx-object.h" #include "filterx/expr-function.h" -FilterXObject *filterx_format_json_call(FilterXExpr *s, GPtrArray *args); +FilterXObject *filterx_format_json_call(FilterXExpr *s, FilterXObject *args[], gsize args_len); FILTERX_SIMPLE_FUNCTION_DECLARE(format_json);