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..178dc4945b 100644 --- a/lib/filterx/expr-function.h +++ b/lib/filterx/expr-function.h @@ -33,10 +33,17 @@ #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); +static inline void +filterx_simple_function_free_args(FilterXObject *args[], gsize args_len) +{ + for (gsize i = 0; i < args_len; i++) + filterx_object_unref(args[i]); +} + typedef struct _FilterXFunction { FilterXExpr super; 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/lib/filterx/tests/test_builtin_functions.c b/lib/filterx/tests/test_builtin_functions.c index cdeb1f8e63..8fdcbf0044 100644 --- a/lib/filterx/tests/test_builtin_functions.c +++ b/lib/filterx/tests/test_builtin_functions.c @@ -47,7 +47,7 @@ #define TEST_BUILTIN_FUNCTION_NAME "TEST_BUILTIN_DUMMY_KEY" FilterXObject * -test_builtin_simple_dummy_function(FilterXExpr *s, GPtrArray *args) +test_builtin_simple_dummy_function(FilterXExpr *s, FilterXObject *args[], gsize args_len) { return filterx_string_new("test-builtin-functions", -1); } @@ -83,7 +83,7 @@ Test(builtin_functions, test_builtin_simple_functions_lookup) cr_assert(func != NULL); // check dummy function as result - FilterXObject *res = func(NULL, NULL); + FilterXObject *res = func(NULL, NULL, 0); cr_assert(res != NULL); cr_assert(filterx_object_is_type(res, &FILTERX_TYPE_NAME(string))); gsize len; diff --git a/lib/filterx/tests/test_expr_condition.c b/lib/filterx/tests/test_expr_condition.c index 26e3700e13..461553d00c 100644 --- a/lib/filterx/tests/test_expr_condition.c +++ b/lib/filterx/tests/test_expr_condition.c @@ -346,7 +346,7 @@ Test(expr_condition, test_condition_error_statement_must_return_null) } FilterXObject * -_dummy_func(FilterXExpr *s, GPtrArray *args) +_dummy_func(FilterXExpr *s, FilterXObject *args[], gsize args_len) { return filterx_string_new("foobar", -1); } diff --git a/lib/filterx/tests/test_expr_function.c b/lib/filterx/tests/test_expr_function.c index d48c67284f..43d2528e8d 100644 --- a/lib/filterx/tests/test_expr_function.c +++ b/lib/filterx/tests/test_expr_function.c @@ -44,13 +44,13 @@ #include "apphook.h" #include "scratch-buffers.h" -FilterXObject *test_dummy_function(FilterXExpr *s, GPtrArray *args) +FilterXObject *test_dummy_function(FilterXExpr *s, FilterXObject *args[], gsize args_len) { GString *repr = scratch_buffers_alloc(); GString *out = scratch_buffers_alloc(); - for (int i = 0; i < args->len; i++) + for (int i = 0; i < args_len; i++) { - FilterXObject *object = g_ptr_array_index(args, i); + FilterXObject *object = args[i]; cr_assert_not_null(object); cr_assert(filterx_object_repr(object, repr)); g_string_append(out, repr->str); diff --git a/lib/filterx/tests/test_object_boolean.c b/lib/filterx/tests/test_object_boolean.c index 110220892c..d0745ab57d 100644 --- a/lib/filterx/tests/test_object_boolean.c +++ b/lib/filterx/tests/test_object_boolean.c @@ -27,6 +27,7 @@ #include "filterx/object-null.h" #include "filterx/object-primitive.h" #include "filterx/filterx-object-istype.h" +#include "filterx/expr-function.h" #include "apphook.h" #include "scratch-buffers.h" @@ -64,60 +65,50 @@ Test(filterx_boolean, test_filterx_primitive_bool_is_truthy_if_true) Test(filterx_boolean, test_filterx_boolean_typecast_null_args) { - GPtrArray *args = NULL; - - FilterXObject *obj = filterx_typecast_boolean(NULL, args); + FilterXObject *obj = filterx_typecast_boolean(NULL, NULL, 0); cr_assert_null(obj); } Test(filterx_boolean, test_filterx_boolean_typecast_empty_args) { - GPtrArray *args = g_ptr_array_new_with_free_func((GDestroyNotify) filterx_object_unref); + FilterXObject *args[] = { NULL }; - FilterXObject *obj = filterx_typecast_boolean(NULL, args); + FilterXObject *obj = filterx_typecast_boolean(NULL, args, 0); cr_assert_null(obj); - - g_ptr_array_free(args, TRUE); } Test(filterx_boolean, test_filterx_boolean_typecast_null_arg) { - GPtrArray *args = g_ptr_array_new_with_free_func((GDestroyNotify) filterx_object_unref); - - g_ptr_array_add(args, NULL); + FilterXObject *args[] = { NULL }; - FilterXObject *obj = filterx_typecast_boolean(NULL, args); + FilterXObject *obj = filterx_typecast_boolean(NULL, args, G_N_ELEMENTS(args)); cr_assert_null(obj); - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); } Test(filterx_boolean, test_filterx_boolean_typecast_null_object_arg) { - GPtrArray *args = g_ptr_array_new_with_free_func((GDestroyNotify) filterx_object_unref); - FilterXObject *in = filterx_null_new(); - g_ptr_array_add(args, in); + FilterXObject *args[] = { filterx_null_new() }; - FilterXObject *obj = filterx_typecast_boolean(NULL, args); + FilterXObject *obj = filterx_typecast_boolean(NULL, args, G_N_ELEMENTS(args)); cr_assert_not_null(obj); cr_assert(filterx_object_is_type(obj, &FILTERX_TYPE_NAME(boolean))); cr_assert(!filterx_object_truthy(obj)); - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); filterx_object_unref(obj); } Test(filterx_boolean, test_filterx_boolean_typecast_from_boolean) { - GPtrArray *args = g_ptr_array_new_with_free_func((GDestroyNotify) filterx_object_unref); - FilterXObject *in = filterx_boolean_new(TRUE); - g_ptr_array_add(args, in); + FilterXObject *args[] = { filterx_boolean_new(TRUE) }; - FilterXObject *obj = filterx_typecast_boolean(NULL, args); - cr_assert_eq(in, obj); + FilterXObject *obj = filterx_typecast_boolean(NULL, args, G_N_ELEMENTS(args)); + cr_assert_eq(args[0], obj); - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); filterx_object_unref(obj); } diff --git a/lib/filterx/tests/test_object_bytes.c b/lib/filterx/tests/test_object_bytes.c index caf22217e1..3f08cd4d7b 100644 --- a/lib/filterx/tests/test_object_bytes.c +++ b/lib/filterx/tests/test_object_bytes.c @@ -24,74 +24,59 @@ #include "filterx/object-string.h" #include "filterx/object-null.h" #include "filterx/filterx-object-istype.h" +#include "filterx/expr-function.h" #include "apphook.h" #include "scratch-buffers.h" Test(filterx_bytes, test_filterx_bytes_typecast_null_args) { - GPtrArray *args = NULL; - - FilterXObject *obj = filterx_typecast_bytes(NULL, args); + FilterXObject *obj = filterx_typecast_bytes(NULL, NULL, 0); cr_assert_null(obj); } Test(filterx_bytes, test_filterx_bytes_typecast_empty_args) { - GPtrArray *args = g_ptr_array_new_with_free_func((GDestroyNotify) filterx_object_unref); - - FilterXObject *obj = filterx_typecast_bytes(NULL, args); + FilterXObject *args[] = { NULL }; + FilterXObject *obj = filterx_typecast_bytes(NULL, args, 0); cr_assert_null(obj); - - g_ptr_array_free(args, TRUE); } Test(filterx_bytes, test_filterx_bytes_typecast_null_arg) { - GPtrArray *args = g_ptr_array_new_with_free_func((GDestroyNotify) filterx_object_unref); - - g_ptr_array_add(args, NULL); + FilterXObject *args[] = { NULL }; - FilterXObject *obj = filterx_typecast_bytes(NULL, args); + FilterXObject *obj = filterx_typecast_bytes(NULL, args, G_N_ELEMENTS(args)); cr_assert_null(obj); - - g_ptr_array_free(args, TRUE); } Test(filterx_bytes, test_filterx_bytes_typecast_null_object_arg) { - GPtrArray *args = g_ptr_array_new_with_free_func((GDestroyNotify) filterx_object_unref); - FilterXObject *in = filterx_null_new(); - g_ptr_array_add(args, in); + FilterXObject *args[] = { filterx_null_new() }; - FilterXObject *obj = filterx_typecast_bytes(NULL, args); + FilterXObject *obj = filterx_typecast_bytes(NULL, args, G_N_ELEMENTS(args)); cr_assert_null(obj); - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); filterx_object_unref(obj); } Test(filterx_bytes, test_filterx_bytes_typecast_from_bytes) { - GPtrArray *args = g_ptr_array_new_with_free_func((GDestroyNotify) filterx_object_unref); - FilterXObject *in = filterx_bytes_new("byte \0sequence", 14); - g_ptr_array_add(args, in); - - FilterXObject *obj = filterx_typecast_bytes(NULL, args); + FilterXObject *args[] = { filterx_bytes_new("byte \0sequence", 14) }; + FilterXObject *obj = filterx_typecast_bytes(NULL, args, G_N_ELEMENTS(args)); - cr_assert_eq(in, obj); + cr_assert_eq(args[0], obj); - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); filterx_object_unref(obj); } Test(filterx_bytes, test_filterx_bytes_typecast_from_string) { - GPtrArray *args = g_ptr_array_new_with_free_func((GDestroyNotify) filterx_object_unref); - FilterXObject *in = filterx_string_new("string whatever", -1); - g_ptr_array_add(args, in); + FilterXObject *args[] = { filterx_string_new("string whatever", -1) }; - FilterXObject *obj = filterx_typecast_bytes(NULL, args); + FilterXObject *obj = filterx_typecast_bytes(NULL, args, G_N_ELEMENTS(args)); cr_assert_not_null(obj); cr_assert(filterx_object_is_type(obj, &FILTERX_TYPE_NAME(bytes))); @@ -100,17 +85,14 @@ Test(filterx_bytes, test_filterx_bytes_typecast_from_string) cr_assert(memcmp("string whatever", bytes, size) == 0); - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); filterx_object_unref(obj); } Test(filterx_bytes, test_filterx_bytes_typecast_from_protobuf) { - GPtrArray *args = g_ptr_array_new_with_free_func((GDestroyNotify) filterx_object_unref); - FilterXObject *in = filterx_protobuf_new("not a valid \0protobuf!", 22); - g_ptr_array_add(args, in); - - FilterXObject *obj = filterx_typecast_bytes(NULL, args); + FilterXObject *args[] = { filterx_protobuf_new("not a valid \0protobuf!", 22) }; + FilterXObject *obj = filterx_typecast_bytes(NULL, args, G_N_ELEMENTS(args)); cr_assert_not_null(obj); cr_assert(filterx_object_is_type(obj, &FILTERX_TYPE_NAME(bytes))); @@ -119,7 +101,7 @@ Test(filterx_bytes, test_filterx_bytes_typecast_from_protobuf) cr_assert(memcmp("not a valid \0protobuf!", bytes, size) == 0); - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); filterx_object_unref(obj); } diff --git a/lib/filterx/tests/test_object_datetime.c b/lib/filterx/tests/test_object_datetime.c index ed3472e89a..fcf54ef353 100644 --- a/lib/filterx/tests/test_object_datetime.c +++ b/lib/filterx/tests/test_object_datetime.c @@ -36,7 +36,6 @@ #include "filterx/filterx-private.h" #include "filterx/filterx-object-istype.h" - Test(filterx_datetime, test_filterx_object_datetime_marshals_to_the_stored_values) { UnixTime ut = { .ut_sec = 1701350398, .ut_usec = 123000, .ut_gmtoff = 3600 }; @@ -56,53 +55,41 @@ Test(filterx_datetime, test_filterx_object_datetime_maps_to_the_right_json_value Test(filterx_datetime, test_filterx_datetime_typecast_null_args) { - GPtrArray *args = NULL; - - FilterXObject *obj = filterx_typecast_datetime(NULL, args); + FilterXObject *obj = filterx_typecast_datetime(NULL, NULL, 0); cr_assert_null(obj); } Test(filterx_datetime, test_filterx_datetime_typecast_empty_args) { - GPtrArray *args = g_ptr_array_new_with_free_func((GDestroyNotify) filterx_object_unref); + FilterXObject *args[] = { NULL }; - FilterXObject *obj = filterx_typecast_datetime(NULL, args); + FilterXObject *obj = filterx_typecast_datetime(NULL, args, 0); cr_assert_null(obj); - - g_ptr_array_free(args, TRUE); } Test(filterx_datetime, test_filterx_datetime_typecast_null_arg) { - GPtrArray *args = g_ptr_array_new_with_free_func((GDestroyNotify) filterx_object_unref); - g_ptr_array_add(args, NULL); + FilterXObject *args[] = { NULL }; - FilterXObject *obj = filterx_typecast_datetime(NULL, args); + FilterXObject *obj = filterx_typecast_datetime(NULL, args, G_N_ELEMENTS(args)); cr_assert_null(obj); - - g_ptr_array_free(args, TRUE); } Test(filterx_datetime, test_filterx_datetime_typecast_null_object_arg) { - GPtrArray *args = g_ptr_array_new_with_free_func((GDestroyNotify) filterx_object_unref); - FilterXObject *in = filterx_null_new(); - g_ptr_array_add(args, in); + FilterXObject *args[] = { filterx_null_new() }; - FilterXObject *obj = filterx_typecast_datetime(NULL, args); + FilterXObject *obj = filterx_typecast_datetime(NULL, args, G_N_ELEMENTS(args)); cr_assert_null(obj); - - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); } Test(filterx_datetime, test_filterx_datetime_typecast_from_int) { // integer representation expected to be microsecond precision - GPtrArray *args = g_ptr_array_new_with_free_func((GDestroyNotify) filterx_object_unref); - FilterXObject *in = filterx_integer_new(1710762325395194); - g_ptr_array_add(args, in); + FilterXObject *args[] = { filterx_integer_new(1710762325395194) }; - FilterXObject *obj = filterx_typecast_datetime(NULL, args); + FilterXObject *obj = filterx_typecast_datetime(NULL, args, G_N_ELEMENTS(args)); cr_assert_not_null(obj); cr_assert(filterx_object_is_type(obj, &FILTERX_TYPE_NAME(datetime))); @@ -110,19 +97,16 @@ Test(filterx_datetime, test_filterx_datetime_typecast_from_int) UnixTime ut = filterx_datetime_get_value(obj); cr_assert(memcmp(&ut_expected, &ut, sizeof(UnixTime)) == 0); - - g_ptr_array_free(args, TRUE); filterx_object_unref(obj); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); } Test(filterx_datetime, test_filterx_datetime_typecast_from_double) { // double representation expected to be second precision - GPtrArray *args = g_ptr_array_new_with_free_func((GDestroyNotify) filterx_object_unref); - FilterXObject *in = filterx_double_new(1710762325.395194); - g_ptr_array_add(args, in); + FilterXObject *args[] = { filterx_double_new(1710762325.395194) }; - FilterXObject *obj = filterx_typecast_datetime(NULL, args); + FilterXObject *obj = filterx_typecast_datetime(NULL, args, G_N_ELEMENTS(args)); cr_assert_not_null(obj); cr_assert(filterx_object_is_type(obj, &FILTERX_TYPE_NAME(datetime))); @@ -131,18 +115,16 @@ Test(filterx_datetime, test_filterx_datetime_typecast_from_double) UnixTime ut = filterx_datetime_get_value(obj); cr_assert(memcmp(&ut_expected, &ut, sizeof(UnixTime)) == 0); - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); filterx_object_unref(obj); } Test(filterx_datetime, test_filterx_datetime_typecast_from_string) { // string representation expected to be rfc3339 standard - GPtrArray *args = g_ptr_array_new_with_free_func((GDestroyNotify) filterx_object_unref); - FilterXObject *in = filterx_string_new("2024-03-18T12:34:00Z", -1); - g_ptr_array_add(args, in); + FilterXObject *args[] = { filterx_string_new("2024-03-18T12:34:00Z", -1) }; - FilterXObject *obj = filterx_typecast_datetime(NULL, args); + FilterXObject *obj = filterx_typecast_datetime(NULL, args, G_N_ELEMENTS(args)); cr_assert_not_null(obj); cr_assert(filterx_object_is_type(obj, &FILTERX_TYPE_NAME(datetime))); @@ -151,23 +133,20 @@ Test(filterx_datetime, test_filterx_datetime_typecast_from_string) UnixTime ut = filterx_datetime_get_value(obj); cr_assert(memcmp(&ut_expected, &ut, sizeof(UnixTime)) == 0); - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); filterx_object_unref(obj); } Test(filterx_datetime, test_filterx_datetime_typecast_from_datetime) { UnixTime ut = { .ut_sec = 1701350398, .ut_usec = 123000, .ut_gmtoff = 3600 }; + FilterXObject *args[] = { filterx_datetime_new(&ut) }; - GPtrArray *args = g_ptr_array_new_with_free_func((GDestroyNotify) filterx_object_unref); - FilterXObject *in = filterx_datetime_new(&ut); - g_ptr_array_add(args, in); - - FilterXObject *obj = filterx_typecast_datetime(NULL, args); + FilterXObject *obj = filterx_typecast_datetime(NULL, args, G_N_ELEMENTS(args)); - cr_assert_eq(in, obj); + cr_assert_eq(args[0], obj); - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); filterx_object_unref(obj); } @@ -185,11 +164,9 @@ Test(filterx_datetime, test_filterx_datetime_repr_method) Test(filterx_datetime, test_filterx_datetime_repr) { - GPtrArray *args = g_ptr_array_new_with_free_func((GDestroyNotify) filterx_object_unref); - FilterXObject *in = filterx_string_new("2024-03-18T12:34:13+0900", -1); - g_ptr_array_add(args, in); + FilterXObject *args[] = { filterx_string_new("2024-03-18T12:34:13+0900", -1) }; - FilterXObject *obj = filterx_typecast_datetime(NULL, args); + FilterXObject *obj = filterx_typecast_datetime(NULL, args, G_N_ELEMENTS(args)); cr_assert_not_null(obj); cr_assert(filterx_object_is_type(obj, &FILTERX_TYPE_NAME(datetime))); @@ -200,27 +177,25 @@ Test(filterx_datetime, test_filterx_datetime_repr) cr_assert(filterx_object_repr_append(obj, repr)); cr_assert_str_eq("2024-03-18T12:34:13.000+09:002024-03-18T12:34:13.000+09:00", repr->str); - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); filterx_object_unref(obj); } Test(filterx_datetime, test_filterx_datetime_repr_isodate_Z) { const gchar *test_time_str = "2024-03-18T12:34:00Z"; - GPtrArray *args = g_ptr_array_new_with_free_func((GDestroyNotify) filterx_object_unref); - FilterXObject *in = filterx_string_new(test_time_str, -1); - g_ptr_array_add(args, in); + FilterXObject *args[] = { filterx_string_new(test_time_str, -1) }; - FilterXObject *obj = filterx_typecast_datetime(NULL, args); + FilterXObject *obj = filterx_typecast_datetime(NULL, args, G_N_ELEMENTS(args)); cr_assert_not_null(obj); cr_assert(filterx_object_is_type(obj, &FILTERX_TYPE_NAME(datetime))); GString *repr = scratch_buffers_alloc(); - cr_assert(filterx_object_repr(in, repr)); + cr_assert(filterx_object_repr(args[0], repr)); cr_assert_str_eq(test_time_str, repr->str); - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); filterx_object_unref(obj); } diff --git a/lib/filterx/tests/test_object_double.c b/lib/filterx/tests/test_object_double.c index c64ae940a4..3f9ddb4d3c 100644 --- a/lib/filterx/tests/test_object_double.c +++ b/lib/filterx/tests/test_object_double.c @@ -61,110 +61,91 @@ Test(filterx_double, test_filterx_primitive_double_is_truthy_if_nonzero) Test(filterx_double, test_filterx_double_typecast_null_args) { - GPtrArray *args = NULL; - - FilterXObject *obj = filterx_typecast_double(NULL, args); + FilterXObject *obj = filterx_typecast_double(NULL, NULL, 0); cr_assert_null(obj); } Test(filterx_double, test_filterx_double_typecast_empty_args) { - GPtrArray *args = g_ptr_array_new_with_free_func((GDestroyNotify) filterx_object_unref); - - FilterXObject *obj = filterx_typecast_double(NULL, args); + FilterXObject *args[] = { NULL }; + FilterXObject *obj = filterx_typecast_double(NULL, args, 0); cr_assert_null(obj); - - g_ptr_array_free(args, TRUE); } Test(filterx_double, test_filterx_double_typecast_null_arg) { - GPtrArray *args = g_ptr_array_new_with_free_func((GDestroyNotify) filterx_object_unref); + FilterXObject *args[] = { NULL }; - g_ptr_array_add(args, NULL); - - FilterXObject *obj = filterx_typecast_double(NULL, args); + FilterXObject *obj = filterx_typecast_double(NULL, args, G_N_ELEMENTS(args)); cr_assert_null(obj); - - g_ptr_array_free(args, TRUE); } Test(filterx_double, test_filterx_double_typecast_null_object_arg) { - GPtrArray *args = g_ptr_array_new_with_free_func((GDestroyNotify) filterx_object_unref); - FilterXObject *in = filterx_null_new(); - g_ptr_array_add(args, in); + FilterXObject *args[] = { filterx_null_new() }; - FilterXObject *obj = filterx_typecast_double(NULL, args); + FilterXObject *obj = filterx_typecast_double(NULL, args, G_N_ELEMENTS(args)); cr_assert_null(obj); - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); filterx_object_unref(obj); } Test(filterx_double, test_filterx_double_typecast_from_double) { - GPtrArray *args = g_ptr_array_new_with_free_func((GDestroyNotify) filterx_object_unref); - FilterXObject *in = filterx_double_new(3.14); - g_ptr_array_add(args, in); + FilterXObject *args[] = { filterx_double_new(3.14) }; - FilterXObject *obj = filterx_typecast_double(NULL, args); - cr_assert_eq(in, obj); + FilterXObject *obj = filterx_typecast_double(NULL, args, G_N_ELEMENTS(args)); + cr_assert_eq(args[0], obj); - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); filterx_object_unref(obj); } Test(filterx_double, test_filterx_double_typecast_from_integer) { - GPtrArray *args = g_ptr_array_new_with_free_func((GDestroyNotify) filterx_object_unref); - FilterXObject *in = filterx_integer_new(443); - g_ptr_array_add(args, in); + FilterXObject *args[] = { filterx_integer_new(443) }; - FilterXObject *obj = filterx_typecast_double(NULL, args); + FilterXObject *obj = filterx_typecast_double(NULL, args, G_N_ELEMENTS(args)); cr_assert_not_null(obj); cr_assert(filterx_object_is_type(obj, &FILTERX_TYPE_NAME(double))); GenericNumber gn = filterx_primitive_get_value(obj); cr_assert_float_eq(443.0, gn_as_double(&gn), 0.00001); - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); filterx_object_unref(obj); } Test(filterx_double, test_filterx_double_typecast_from_string) { - GPtrArray *args = g_ptr_array_new_with_free_func((GDestroyNotify) filterx_object_unref); - FilterXObject *in = filterx_string_new("443.117", -1); - g_ptr_array_add(args, in); + FilterXObject *args[] = { filterx_string_new("443.117", -1) }; - FilterXObject *obj = filterx_typecast_double(NULL, args); + FilterXObject *obj = filterx_typecast_double(NULL, args, G_N_ELEMENTS(args)); cr_assert_not_null(obj); cr_assert(filterx_object_is_type(obj, &FILTERX_TYPE_NAME(double))); GenericNumber gn = filterx_primitive_get_value(obj); cr_assert_float_eq(443.117, gn_as_double(&gn), 0.00001); - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); filterx_object_unref(obj); } Test(filterx_double, test_filterx_double_typecast_from_datetime) { - GPtrArray *args = g_ptr_array_new_with_free_func((GDestroyNotify) filterx_object_unref); UnixTime ut = { .ut_sec = 171, .ut_usec = 443221 }; - FilterXObject *in = filterx_datetime_new(&ut); - g_ptr_array_add(args, in); + FilterXObject *args[] = { filterx_datetime_new(&ut) }; - FilterXObject *obj = filterx_typecast_double(NULL, args); + FilterXObject *obj = filterx_typecast_double(NULL, args, G_N_ELEMENTS(args)); cr_assert_not_null(obj); cr_assert(filterx_object_is_type(obj, &FILTERX_TYPE_NAME(double))); GenericNumber gn = filterx_primitive_get_value(obj); cr_assert_float_eq(171.443221, gn_as_double(&gn), 0.00001); - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); filterx_object_unref(obj); } diff --git a/lib/filterx/tests/test_object_integer.c b/lib/filterx/tests/test_object_integer.c index 880cf813bc..b2cf247cff 100644 --- a/lib/filterx/tests/test_object_integer.c +++ b/lib/filterx/tests/test_object_integer.c @@ -63,67 +63,53 @@ Test(filterx_integer, test_filterx_primitive_int_is_truthy_if_nonzero) Test(filterx_integer, test_filterx_integer_typecast_null_args) { - GPtrArray *args = NULL; - - FilterXObject *obj = filterx_typecast_integer(NULL, args); + FilterXObject *obj = filterx_typecast_integer(NULL, NULL, 0); cr_assert_null(obj); } Test(filterx_integer, test_filterx_integer_typecast_empty_args) { - GPtrArray *args = g_ptr_array_new_with_free_func((GDestroyNotify) filterx_object_unref); + FilterXObject *args[] = { NULL }; - FilterXObject *obj = filterx_typecast_integer(NULL, args); + FilterXObject *obj = filterx_typecast_integer(NULL, args, 0); cr_assert_null(obj); - - g_ptr_array_free(args, TRUE); } Test(filterx_integer, test_filterx_integer_typecast_null_arg) { - GPtrArray *args = g_ptr_array_new_with_free_func((GDestroyNotify) filterx_object_unref); + FilterXObject *args[] = { NULL }; - g_ptr_array_add(args, NULL); - - FilterXObject *obj = filterx_typecast_integer(NULL, args); + FilterXObject *obj = filterx_typecast_integer(NULL, args, G_N_ELEMENTS(args)); cr_assert_null(obj); - - g_ptr_array_free(args, TRUE); } // null->int cast can might be result in 0 later Test(filterx_integer, test_filterx_integer_typecast_null_object_arg) { - GPtrArray *args = g_ptr_array_new_with_free_func((GDestroyNotify) filterx_object_unref); - FilterXObject *in = filterx_null_new(); - g_ptr_array_add(args, in); + FilterXObject *args[] = { filterx_null_new() }; - FilterXObject *obj = filterx_typecast_integer(NULL, args); + FilterXObject *obj = filterx_typecast_integer(NULL, args, G_N_ELEMENTS(args)); cr_assert_null(obj); - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); } Test(filterx_integer, test_filterx_integer_typecast_from_integer) { - GPtrArray *args = g_ptr_array_new_with_free_func((GDestroyNotify) filterx_object_unref); - FilterXObject *in = filterx_integer_new(443); - g_ptr_array_add(args, in); + FilterXObject *args[] = { filterx_integer_new(443) }; - FilterXObject *obj = filterx_typecast_integer(NULL, args); - cr_assert_eq(in, obj); + FilterXObject *obj = filterx_typecast_integer(NULL, args, G_N_ELEMENTS(args)); + cr_assert_eq(args[0], obj); - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); filterx_object_unref(obj); } Test(filterx_integer, test_filterx_integer_typecast_from_double) { - GPtrArray *args = g_ptr_array_new_with_free_func((GDestroyNotify) filterx_object_unref); - FilterXObject *in = filterx_double_new(171.443); - g_ptr_array_add(args, in); + FilterXObject *args[] = { filterx_double_new(171.443) }; - FilterXObject *obj = filterx_typecast_integer(NULL, args); + FilterXObject *obj = filterx_typecast_integer(NULL, args, G_N_ELEMENTS(args)); cr_assert_not_null(obj); cr_assert(filterx_object_is_type(obj, &FILTERX_TYPE_NAME(integer))); @@ -131,7 +117,7 @@ Test(filterx_integer, test_filterx_integer_typecast_from_double) cr_assert(gn_as_int64(&gn) == 171); - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); filterx_object_unref(obj); } @@ -139,11 +125,9 @@ Test(filterx_integer, test_filterx_integer_typecast_from_double) // ceil/floor helper functions or exact int(double) typecasts are possible solutions later Test(filterx_integer, test_filterx_integer_typecast_from_double_roundup) { - GPtrArray *args = g_ptr_array_new_with_free_func((GDestroyNotify) filterx_object_unref); - FilterXObject *in = filterx_double_new(171.743); - g_ptr_array_add(args, in); + FilterXObject *args[] = { filterx_double_new(171.743) }; - FilterXObject *obj = filterx_typecast_integer(NULL, args); + FilterXObject *obj = filterx_typecast_integer(NULL, args, G_N_ELEMENTS(args)); cr_assert_not_null(obj); cr_assert(filterx_object_is_type(obj, &FILTERX_TYPE_NAME(integer))); @@ -151,17 +135,15 @@ Test(filterx_integer, test_filterx_integer_typecast_from_double_roundup) cr_assert(gn_as_int64(&gn) == 172); - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); filterx_object_unref(obj); } Test(filterx_integer, test_filterx_integer_typecast_from_string) { - GPtrArray *args = g_ptr_array_new_with_free_func((GDestroyNotify) filterx_object_unref); - FilterXObject *in = filterx_string_new("443", -1); - g_ptr_array_add(args, in); + FilterXObject *args[] = { filterx_string_new("443", -1) }; - FilterXObject *obj = filterx_typecast_integer(NULL, args); + FilterXObject *obj = filterx_typecast_integer(NULL, args, G_N_ELEMENTS(args)); cr_assert_not_null(obj); cr_assert(filterx_object_is_type(obj, &FILTERX_TYPE_NAME(integer))); @@ -169,17 +151,15 @@ Test(filterx_integer, test_filterx_integer_typecast_from_string) cr_assert(gn_as_int64(&gn) == 443); - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); filterx_object_unref(obj); } Test(filterx_integer, test_filterx_integer_typecast_from_string_very_very_zero) { - GPtrArray *args = g_ptr_array_new_with_free_func((GDestroyNotify) filterx_object_unref); - FilterXObject *in = filterx_string_new("000", -1); - g_ptr_array_add(args, in); + FilterXObject *args[] = { filterx_string_new("000", -1) }; - FilterXObject *obj = filterx_typecast_integer(NULL, args); + FilterXObject *obj = filterx_typecast_integer(NULL, args, G_N_ELEMENTS(args)); cr_assert_not_null(obj); cr_assert(filterx_object_is_type(obj, &FILTERX_TYPE_NAME(integer))); @@ -187,31 +167,27 @@ Test(filterx_integer, test_filterx_integer_typecast_from_string_very_very_zero) cr_assert(gn_as_int64(&gn) == 0); - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); filterx_object_unref(obj); } Test(filterx_integer, test_filterx_integer_typecast_from_double_string) { - GPtrArray *args = g_ptr_array_new_with_free_func((GDestroyNotify) filterx_object_unref); - FilterXObject *in = filterx_string_new("443.117", -1); - g_ptr_array_add(args, in); + FilterXObject *args[] = { filterx_string_new("443.117", -1) }; - FilterXObject *obj = filterx_typecast_integer(NULL, args); + FilterXObject *obj = filterx_typecast_integer(NULL, args, G_N_ELEMENTS(args)); cr_assert_null(obj); - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); filterx_object_unref(obj); } Test(filterx_integer, test_filterx_integer_typecast_from_datetime) { - GPtrArray *args = g_ptr_array_new_with_free_func((GDestroyNotify) filterx_object_unref); UnixTime ut = { .ut_sec = 171, .ut_usec = 443221 }; - FilterXObject *in = filterx_datetime_new(&ut); - g_ptr_array_add(args, in); + FilterXObject *args[] = { filterx_datetime_new(&ut) }; - FilterXObject *obj = filterx_typecast_integer(NULL, args); + FilterXObject *obj = filterx_typecast_integer(NULL, args, G_N_ELEMENTS(args)); cr_assert_not_null(obj); cr_assert(filterx_object_is_type(obj, &FILTERX_TYPE_NAME(integer))); @@ -219,7 +195,7 @@ Test(filterx_integer, test_filterx_integer_typecast_from_datetime) cr_assert(gn_as_int64(&gn) == 171443221); - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); filterx_object_unref(obj); } diff --git a/lib/filterx/tests/test_object_json.c b/lib/filterx/tests/test_object_json.c index 84b0707928..e73171a6e8 100644 --- a/lib/filterx/tests/test_object_json.c +++ b/lib/filterx/tests/test_object_json.c @@ -70,12 +70,11 @@ static FilterXObject * _exec_func(FilterXSimpleFunctionProto func, FilterXObject *arg) { if (!arg) - return func(NULL, NULL); + return func(NULL, NULL, 0); - GPtrArray *args = g_ptr_array_new_with_free_func((GDestroyNotify) filterx_object_unref); - g_ptr_array_add(args, arg); - FilterXObject *result = func(NULL, args); - g_ptr_array_unref(args); + FilterXObject *args[] = { arg }; + FilterXObject *result = func(NULL, args, G_N_ELEMENTS(args)); + filterx_object_unref(arg); return result; } diff --git a/lib/filterx/tests/test_object_protobuf.c b/lib/filterx/tests/test_object_protobuf.c index b93cb15471..83c373d09f 100644 --- a/lib/filterx/tests/test_object_protobuf.c +++ b/lib/filterx/tests/test_object_protobuf.c @@ -24,59 +24,50 @@ #include "filterx/object-string.h" #include "filterx/object-null.h" #include "filterx/filterx-object-istype.h" +#include "filterx/expr-function.h" #include "apphook.h" #include "scratch-buffers.h" Test(filterx_protobuf, test_filterx_protobuf_typecast_null_args) { - GPtrArray *args = NULL; - - FilterXObject *obj = filterx_typecast_protobuf(NULL, args); + FilterXObject *obj = filterx_typecast_protobuf(NULL, NULL, 0); cr_assert_null(obj); } Test(filterx_protobuf, test_filterx_protobuf_typecast_empty_args) { - GPtrArray *args = g_ptr_array_new_with_free_func((GDestroyNotify) filterx_object_unref); + FilterXObject *args[] = { NULL }; - FilterXObject *obj = filterx_typecast_protobuf(NULL, args); + FilterXObject *obj = filterx_typecast_protobuf(NULL, args, 0); cr_assert_null(obj); - - g_ptr_array_free(args, TRUE); } Test(filterx_protobuf, test_filterx_protobuf_typecast_null_arg) { - GPtrArray *args = g_ptr_array_new_with_free_func((GDestroyNotify) filterx_object_unref); - - g_ptr_array_add(args, NULL); + FilterXObject *args[] = { NULL }; - FilterXObject *obj = filterx_typecast_protobuf(NULL, args); + FilterXObject *obj = filterx_typecast_protobuf(NULL, args, G_N_ELEMENTS(args)); cr_assert_null(obj); - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); } Test(filterx_protobuf, test_filterx_protobuf_typecast_null_object_arg) { - GPtrArray *args = g_ptr_array_new_with_free_func((GDestroyNotify) filterx_object_unref); - FilterXObject *in = filterx_null_new(); - g_ptr_array_add(args, in); + FilterXObject *args[] = { filterx_null_new() }; - FilterXObject *obj = filterx_typecast_protobuf(NULL, args); + FilterXObject *obj = filterx_typecast_protobuf(NULL, args, G_N_ELEMENTS(args)); cr_assert_null(obj); - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); } Test(filterx_protobuf, test_filterx_protobuf_typecast_from_bytes) { - GPtrArray *args = g_ptr_array_new_with_free_func((GDestroyNotify) filterx_object_unref); - FilterXObject *in = filterx_bytes_new("not valid \0protobuf!", 20); - g_ptr_array_add(args, in); + FilterXObject *args[] = { filterx_bytes_new("not valid \0protobuf!", 20) }; - FilterXObject *obj = filterx_typecast_protobuf(NULL, args); + FilterXObject *obj = filterx_typecast_protobuf(NULL, args, G_N_ELEMENTS(args)); cr_assert_not_null(obj); cr_assert(filterx_object_is_type(obj, &FILTERX_TYPE_NAME(protobuf))); @@ -85,20 +76,18 @@ Test(filterx_protobuf, test_filterx_protobuf_typecast_from_bytes) cr_assert(memcmp("not valid \0protobuf!", bytes, size) == 0); - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); filterx_object_unref(obj); } Test(filterx_protobuf, test_filterx_protobuf_typecast_from_protobuf) { - GPtrArray *args = g_ptr_array_new_with_free_func((GDestroyNotify) filterx_object_unref); - FilterXObject *in = filterx_protobuf_new("not valid \0protobuf!", 20); - g_ptr_array_add(args, in); + FilterXObject *args[] = { filterx_protobuf_new("not valid \0protobuf!", 20) }; - FilterXObject *obj = filterx_typecast_protobuf(NULL, args); - cr_assert_eq(in, obj); + FilterXObject *obj = filterx_typecast_protobuf(NULL, args, G_N_ELEMENTS(args)); + cr_assert_eq(args[0], obj); - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); filterx_object_unref(obj); } diff --git a/lib/filterx/tests/test_object_string.c b/lib/filterx/tests/test_object_string.c index 2b068cfda1..4a52c06ab7 100644 --- a/lib/filterx/tests/test_object_string.c +++ b/lib/filterx/tests/test_object_string.c @@ -26,6 +26,7 @@ #include "filterx/object-string.h" #include "filterx/object-null.h" #include "filterx/filterx-object-istype.h" +#include "filterx/expr-function.h" #include "apphook.h" #include "scratch-buffers.h" @@ -46,41 +47,31 @@ Test(filterx_string, test_filterx_object_string_maps_to_the_right_json_value) Test(filterx_string, test_filterx_string_typecast_null_args) { - GPtrArray *args = NULL; - - FilterXObject *obj = filterx_typecast_string(NULL, args); + FilterXObject *obj = filterx_typecast_string(NULL, NULL, 0); cr_assert_null(obj); } Test(filterx_string, test_filterx_string_typecast_empty_args) { - GPtrArray *args = g_ptr_array_new_with_free_func((GDestroyNotify) filterx_object_unref); + FilterXObject *args[] = { NULL }; - FilterXObject *obj = filterx_typecast_string(NULL, args); + FilterXObject *obj = filterx_typecast_string(NULL, args, 0); cr_assert_null(obj); - - g_ptr_array_free(args, TRUE); } Test(filterx_string, test_filterx_string_typecast_null_arg) { - GPtrArray *args = g_ptr_array_new_with_free_func((GDestroyNotify) filterx_object_unref); - - g_ptr_array_add(args, NULL); + FilterXObject *args[] = { NULL }; - FilterXObject *obj = filterx_typecast_string(NULL, args); + FilterXObject *obj = filterx_typecast_string(NULL, args, G_N_ELEMENTS(args)); cr_assert_null(obj); - - g_ptr_array_free(args, TRUE); } Test(filterx_string, test_filterx_string_typecast_null_object_arg) { - GPtrArray *args = g_ptr_array_new_with_free_func((GDestroyNotify) filterx_object_unref); - FilterXObject *in = filterx_null_new(); - g_ptr_array_add(args, in); + FilterXObject *args[] = { filterx_null_new() }; - FilterXObject *obj = filterx_typecast_string(NULL, args); + FilterXObject *obj = filterx_typecast_string(NULL, args, G_N_ELEMENTS(args)); cr_assert_not_null(obj); cr_assert(filterx_object_is_type(obj, &FILTERX_TYPE_NAME(string))); @@ -89,31 +80,27 @@ Test(filterx_string, test_filterx_string_typecast_null_object_arg) cr_assert(strcmp("null", str) == 0); - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); filterx_object_unref(obj); } Test(filterx_string, test_filterx_string_typecast_from_string) { - GPtrArray *args = g_ptr_array_new_with_free_func((GDestroyNotify) filterx_object_unref); - FilterXObject *in = filterx_string_new("foobar", -1); - g_ptr_array_add(args, in); + FilterXObject *args[] = { filterx_string_new("foobar", -1) }; - FilterXObject *obj = filterx_typecast_string(NULL, args); + FilterXObject *obj = filterx_typecast_string(NULL, args, G_N_ELEMENTS(args)); - cr_assert_eq(in, obj); + cr_assert_eq(args[0], obj); - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); filterx_object_unref(obj); } Test(filterx_string, test_filterx_string_typecast_from_bytes) { - GPtrArray *args = g_ptr_array_new_with_free_func((GDestroyNotify) filterx_object_unref); - FilterXObject *in = filterx_bytes_new("\x00\x1f byte \\sequence \x7f \xff", 21); - g_ptr_array_add(args, in); + FilterXObject *args[] = { filterx_bytes_new("\x00\x1f byte \\sequence \x7f \xff", 21) }; - FilterXObject *obj = filterx_typecast_string(NULL, args); + FilterXObject *obj = filterx_typecast_string(NULL, args, G_N_ELEMENTS(args)); cr_assert_not_null(obj); cr_assert(filterx_object_is_type(obj, &FILTERX_TYPE_NAME(string))); @@ -121,18 +108,15 @@ Test(filterx_string, test_filterx_string_typecast_from_bytes) const gchar *str = filterx_string_get_value_ref(obj, &size); cr_assert(memcmp("001f2062797465205c73657175656e6365207f20ff", str, size) == 0); - - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); filterx_object_unref(obj); } Test(filterx_string, test_filterx_string_typecast_from_protobuf) { - GPtrArray *args = g_ptr_array_new_with_free_func((GDestroyNotify) filterx_object_unref); - FilterXObject *in = filterx_protobuf_new("\xffnot a valid protobuf! \xd9", 23); - g_ptr_array_add(args, in); + FilterXObject *args[] = { filterx_protobuf_new("\xffnot a valid protobuf! \xd9", 23) }; - FilterXObject *obj = filterx_typecast_string(NULL, args); + FilterXObject *obj = filterx_typecast_string(NULL, args, G_N_ELEMENTS(args)); cr_assert_not_null(obj); cr_assert(filterx_object_is_type(obj, &FILTERX_TYPE_NAME(string))); @@ -140,8 +124,7 @@ Test(filterx_string, test_filterx_string_typecast_from_protobuf) const gchar *str = filterx_string_get_value_ref(obj, &size); cr_assert(memcmp("ff6e6f7420612076616c69642070726f746f6275662120d9", str, size) == 0); - - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); filterx_object_unref(obj); } 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/grpc/otel/tests/test-otel-filterx.cpp b/modules/grpc/otel/tests/test-otel-filterx.cpp index 8cf5890e47..d73032d2d0 100644 --- a/modules/grpc/otel/tests/test-otel-filterx.cpp +++ b/modules/grpc/otel/tests/test-otel-filterx.cpp @@ -171,55 +171,50 @@ Test(otel_filterx, logrecord_from_protobuf) attribute->mutable_value()->set_int_value(42); std::string serialized_log_record = log_record.SerializePartialAsString(); - GPtrArray *args = g_ptr_array_new_full(1, (GDestroyNotify) filterx_object_unref); - g_ptr_array_insert(args, 0, filterx_protobuf_new(serialized_log_record.c_str(), serialized_log_record.length())); - FilterXOtelLogRecord *filterx_otel_logrecord = (FilterXOtelLogRecord *) filterx_otel_logrecord_new_from_args(NULL, - args); + FilterXObject *args[] = { filterx_protobuf_new(serialized_log_record.c_str(), serialized_log_record.length()) }; + + FilterXOtelLogRecord *filterx_otel_logrecord = + (FilterXOtelLogRecord *) filterx_otel_logrecord_new_from_args(NULL, args, G_N_ELEMENTS(args)); + cr_assert(filterx_otel_logrecord); const LogRecord &log_record_from_filterx = filterx_otel_logrecord->cpp->get_value(); cr_assert(MessageDifferencer::Equals(log_record, log_record_from_filterx)); filterx_object_unref(&filterx_otel_logrecord->super.super); - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); } Test(otel_filterx, logrecord_from_protobuf_invalid_arg) { - GPtrArray *args = g_ptr_array_new_full(1, (GDestroyNotify) filterx_object_unref); - g_ptr_array_insert(args, 0, filterx_string_new("", 0)); + FilterXObject *args[] = { filterx_string_new("", 0) }; - FilterXOtelLogRecord *filterx_otel_logrecord = (FilterXOtelLogRecord *) filterx_otel_logrecord_new_from_args(NULL, - args); - cr_assert_not(filterx_otel_logrecord); + FilterXOtelLogRecord *filterx_otel_logrecord = + (FilterXOtelLogRecord *) filterx_otel_logrecord_new_from_args(NULL, args, G_N_ELEMENTS(args)); - g_ptr_array_free(args, TRUE); + cr_assert_not(filterx_otel_logrecord); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); } Test(otel_filterx, logrecord_from_protobuf_malformed_data) { - GPtrArray *args = g_ptr_array_new_full(1, (GDestroyNotify) filterx_object_unref); - g_ptr_array_insert(args, 0, filterx_protobuf_new("1234", 4)); + FilterXObject *args[] = { filterx_protobuf_new("1234", 4) }; FilterXOtelLogRecord *filterx_otel_logrecord = (FilterXOtelLogRecord *) filterx_otel_logrecord_new_from_args(NULL, - args); + args, G_N_ELEMENTS(args)); cr_assert_not(filterx_otel_logrecord); - - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); } Test(otel_filterx, logrecord_too_many_args) { - GPtrArray *args = g_ptr_array_new_full(2, (GDestroyNotify) filterx_object_unref); - g_ptr_array_insert(args, 0, filterx_string_new("foo", 3)); - g_ptr_array_insert(args, 1, filterx_protobuf_new("bar", 3)); + FilterXObject *args[] = { filterx_string_new("foo", 3), filterx_protobuf_new("bar", 3) }; FilterXOtelLogRecord *filterx_otel_logrecord = (FilterXOtelLogRecord *) filterx_otel_logrecord_new_from_args(NULL, - args); + args, G_N_ELEMENTS(args)); cr_assert_not(filterx_otel_logrecord); - - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); } Test(otel_filterx, logrecord_len_and_unset_and_is_key_set) @@ -324,51 +319,46 @@ Test(otel_filterx, resource_from_protobuf) attribute->mutable_value()->set_int_value(42); std::string serialized_resource = resource.SerializePartialAsString(); - GPtrArray *args = g_ptr_array_new_full(1, (GDestroyNotify) filterx_object_unref); - g_ptr_array_insert(args, 0, filterx_protobuf_new(serialized_resource.c_str(), serialized_resource.length())); + FilterXObject *args[] = { filterx_protobuf_new(serialized_resource.c_str(), serialized_resource.length()) }; - FilterXOtelResource *filterx_otel_resource = (FilterXOtelResource *) filterx_otel_resource_new_from_args(NULL, args); + FilterXOtelResource *filterx_otel_resource = (FilterXOtelResource *) filterx_otel_resource_new_from_args(NULL, args, G_N_ELEMENTS(args)); cr_assert(filterx_otel_resource); const opentelemetry::proto::resource::v1::Resource &resource_from_filterx = filterx_otel_resource->cpp->get_value(); cr_assert(MessageDifferencer::Equals(resource, resource_from_filterx)); filterx_object_unref(&filterx_otel_resource->super.super); - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); } Test(otel_filterx, resource_from_protobuf_invalid_arg) { - GPtrArray *args = g_ptr_array_new_full(1, (GDestroyNotify) filterx_object_unref); - g_ptr_array_insert(args, 0, filterx_string_new("", 0)); + FilterXObject *args[] = { filterx_string_new("", 0) }; - FilterXOtelResource *filterx_otel_resource = (FilterXOtelResource *) filterx_otel_resource_new_from_args(NULL, args); + FilterXOtelResource *filterx_otel_resource = (FilterXOtelResource *) filterx_otel_resource_new_from_args(NULL, args, G_N_ELEMENTS(args)); cr_assert_not(filterx_otel_resource); - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); } Test(otel_filterx, resource_from_protobuf_malformed_data) { - GPtrArray *args = g_ptr_array_new_full(1, (GDestroyNotify) filterx_object_unref); - g_ptr_array_insert(args, 0, filterx_protobuf_new("1234", 4)); + FilterXObject *args[] = { filterx_protobuf_new("1234", 4) }; - FilterXOtelResource *filterx_otel_resource = (FilterXOtelResource *) filterx_otel_resource_new_from_args(NULL, args); + FilterXOtelResource *filterx_otel_resource = (FilterXOtelResource *) filterx_otel_resource_new_from_args(NULL, args, G_N_ELEMENTS(args)); cr_assert_not(filterx_otel_resource); - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); } Test(otel_filterx, resource_too_many_args) { - GPtrArray *args = g_ptr_array_new_full(2, (GDestroyNotify) filterx_object_unref); - g_ptr_array_insert(args, 0, filterx_string_new("foo", 3)); - g_ptr_array_insert(args, 1, filterx_protobuf_new("bar", 3)); + FilterXObject *args[] = { filterx_string_new("foo", 3), filterx_protobuf_new("bar", 3) }; - FilterXOtelResource *filterx_otel_resource = (FilterXOtelResource *) filterx_otel_resource_new_from_args(NULL, args); + FilterXOtelResource *filterx_otel_resource = (FilterXOtelResource *) filterx_otel_resource_new_from_args(NULL, args, G_N_ELEMENTS(args)); cr_assert_not(filterx_otel_resource); - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); } Test(otel_filterx, resource_get_field) @@ -380,10 +370,9 @@ Test(otel_filterx, resource_get_field) attribute_1->mutable_value()->set_int_value(1337); std::string serialized_resource = resource.SerializePartialAsString(); - GPtrArray *args = g_ptr_array_new_full(1, (GDestroyNotify) filterx_object_unref); - g_ptr_array_insert(args, 0, filterx_protobuf_new(serialized_resource.c_str(), serialized_resource.length())); + FilterXObject *args[] = { filterx_protobuf_new(serialized_resource.c_str(), serialized_resource.length()) }; - FilterXObject *filterx_otel_resource = (FilterXObject *) filterx_otel_resource_new_from_args(NULL, args); + FilterXObject *filterx_otel_resource = (FilterXObject *) filterx_otel_resource_new_from_args(NULL, args, G_N_ELEMENTS(args)); cr_assert(filterx_otel_resource); _assert_filterx_integer_attribute(filterx_otel_resource, "dropped_attributes_count", 42); @@ -393,7 +382,7 @@ Test(otel_filterx, resource_get_field) cr_assert_not(filterx_invalid); filterx_object_unref(filterx_otel_resource); - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); } Test(otel_filterx, resource_set_field) @@ -409,10 +398,9 @@ Test(otel_filterx, resource_set_field) attribute_1->set_key("attribute_1"); attribute_1->mutable_value()->set_int_value(1337); std::string serialized_attributes = attributes.SerializePartialAsString(); - GPtrArray *attributes_kvlist_args = g_ptr_array_new_full(1, (GDestroyNotify) filterx_object_unref); - g_ptr_array_insert(attributes_kvlist_args, 0, filterx_protobuf_new(serialized_attributes.c_str(), - serialized_attributes.length())); - FilterXObject *filterx_kvlist = filterx_otel_kvlist_new_from_args(NULL, attributes_kvlist_args); + + FilterXObject *args[] = { filterx_protobuf_new(serialized_attributes.c_str(), serialized_attributes.length()) }; + FilterXObject *filterx_kvlist = filterx_otel_kvlist_new_from_args(NULL, args, G_N_ELEMENTS(args)); cr_assert(filterx_object_setattr_string(filterx_otel_resource, "attributes", &filterx_kvlist)); cr_assert_not(filterx_object_setattr_string(filterx_otel_resource, "invalid_attr", &filterx_integer)); @@ -428,7 +416,7 @@ Test(otel_filterx, resource_set_field) cr_assert_eq(resource.dropped_attributes_count(), 42); g_string_free(serialized, TRUE); - g_ptr_array_unref(attributes_kvlist_args); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); filterx_object_unref(filterx_kvlist); filterx_object_unref(filterx_integer); filterx_object_unref(filterx_otel_resource); @@ -504,51 +492,46 @@ Test(otel_filterx, scope_from_protobuf) attribute->mutable_value()->set_int_value(42); std::string serialized_scope = scope.SerializePartialAsString(); - GPtrArray *args = g_ptr_array_new_full(1, (GDestroyNotify) filterx_object_unref); - g_ptr_array_insert(args, 0, filterx_protobuf_new(serialized_scope.c_str(), serialized_scope.length())); + FilterXObject *args[] = { filterx_protobuf_new(serialized_scope.c_str(), serialized_scope.length()) }; - FilterXOtelScope *filterx_otel_scope = (FilterXOtelScope *) filterx_otel_scope_new_from_args(NULL, args); + FilterXOtelScope *filterx_otel_scope = (FilterXOtelScope *) filterx_otel_scope_new_from_args(NULL, args, G_N_ELEMENTS(args)); cr_assert(filterx_otel_scope); const opentelemetry::proto::common::v1::InstrumentationScope &scope_from_filterx = filterx_otel_scope->cpp->get_value(); cr_assert(MessageDifferencer::Equals(scope, scope_from_filterx)); filterx_object_unref(&filterx_otel_scope->super.super); - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); } Test(otel_filterx, scope_from_protobuf_invalid_arg) { - GPtrArray *args = g_ptr_array_new_full(1, (GDestroyNotify) filterx_object_unref); - g_ptr_array_insert(args, 0, filterx_string_new("", 0)); + FilterXObject *args[] = { filterx_string_new("", 0) }; - FilterXOtelScope *filterx_otel_scope = (FilterXOtelScope *) filterx_otel_scope_new_from_args(NULL, args); + FilterXOtelScope *filterx_otel_scope = (FilterXOtelScope *) filterx_otel_scope_new_from_args(NULL, args, G_N_ELEMENTS(args)); cr_assert_not(filterx_otel_scope); - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); } Test(otel_filterx, scope_from_protobuf_malformed_data) { - GPtrArray *args = g_ptr_array_new_full(1, (GDestroyNotify) filterx_object_unref); - g_ptr_array_insert(args, 0, filterx_protobuf_new("1234", 4)); + FilterXObject *args[] = { filterx_protobuf_new("1234", 4) }; - FilterXOtelScope *filterx_otel_scope = (FilterXOtelScope *) filterx_otel_scope_new_from_args(NULL, args); + FilterXOtelScope *filterx_otel_scope = (FilterXOtelScope *) filterx_otel_scope_new_from_args(NULL, args, G_N_ELEMENTS(args)); cr_assert_not(filterx_otel_scope); - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); } Test(otel_filterx, scope_too_many_args) { - GPtrArray *args = g_ptr_array_new_full(2, (GDestroyNotify) filterx_object_unref); - g_ptr_array_insert(args, 0, filterx_string_new("foo", 3)); - g_ptr_array_insert(args, 1, filterx_protobuf_new("bar", 3)); + FilterXObject *args[] = { filterx_string_new("foo", 3), filterx_protobuf_new("bar", 3) }; - FilterXOtelScope *filterx_otel_scope = (FilterXOtelScope *) filterx_otel_scope_new_from_args(NULL, args); + FilterXOtelScope *filterx_otel_scope = (FilterXOtelScope *) filterx_otel_scope_new_from_args(NULL, args, G_N_ELEMENTS(args)); cr_assert_not(filterx_otel_scope); - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); } Test(otel_filterx, scope_get_field) @@ -561,10 +544,9 @@ Test(otel_filterx, scope_get_field) attribute_1->mutable_value()->set_int_value(1337); std::string serialized_scope = scope.SerializePartialAsString(); - GPtrArray *args = g_ptr_array_new_full(1, (GDestroyNotify) filterx_object_unref); - g_ptr_array_insert(args, 0, filterx_protobuf_new(serialized_scope.c_str(), serialized_scope.length())); + FilterXObject *args[] = { filterx_protobuf_new(serialized_scope.c_str(), serialized_scope.length()) }; - FilterXObject *filterx_otel_scope = (FilterXObject *) filterx_otel_scope_new_from_args(NULL, args); + FilterXObject *filterx_otel_scope = (FilterXObject *) filterx_otel_scope_new_from_args(NULL, args, G_N_ELEMENTS(args)); cr_assert(filterx_otel_scope); _assert_filterx_integer_attribute(filterx_otel_scope, "dropped_attributes_count", 42); @@ -575,7 +557,7 @@ Test(otel_filterx, scope_get_field) cr_assert_not(filterx_invalid); filterx_object_unref(filterx_otel_scope); - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); } Test(otel_filterx, scope_set_field) @@ -594,10 +576,9 @@ Test(otel_filterx, scope_set_field) attribute_1->set_key("attribute_1"); attribute_1->mutable_value()->set_int_value(1337); std::string serialized_attributes = attributes.SerializePartialAsString(); - GPtrArray *attributes_kvlist_args = g_ptr_array_new_full(1, (GDestroyNotify) filterx_object_unref); - g_ptr_array_insert(attributes_kvlist_args, 0, filterx_protobuf_new(serialized_attributes.c_str(), - serialized_attributes.length())); - FilterXObject *filterx_kvlist = filterx_otel_kvlist_new_from_args(NULL, attributes_kvlist_args); + + FilterXObject *args[] = { filterx_protobuf_new(serialized_attributes.c_str(), serialized_attributes.length()) }; + FilterXObject *filterx_kvlist = filterx_otel_kvlist_new_from_args(NULL, args, G_N_ELEMENTS(args)); cr_assert(filterx_object_setattr_string(filterx_otel_scope, "attributes", &filterx_kvlist)); cr_assert_not(filterx_object_setattr_string(filterx_otel_scope, "invalid_attr", &filterx_integer)); @@ -614,7 +595,8 @@ Test(otel_filterx, scope_set_field) cr_assert_eq(scope.name().compare("foobar"), 0); g_string_free(serialized, TRUE); - g_ptr_array_unref(attributes_kvlist_args); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); + filterx_object_unref(filterx_kvlist); filterx_object_unref(filterx_string); filterx_object_unref(filterx_integer); @@ -645,50 +627,45 @@ Test(otel_filterx, kvlist_from_protobuf) element_2->mutable_value()->set_string_value("foobar"); std::string serialized_kvlist = kvlist.SerializePartialAsString(); - GPtrArray *args = g_ptr_array_new_full(1, (GDestroyNotify) filterx_object_unref); - g_ptr_array_insert(args, 0, filterx_protobuf_new(serialized_kvlist.c_str(), serialized_kvlist.length())); + FilterXObject *args[] = { filterx_protobuf_new(serialized_kvlist.c_str(), serialized_kvlist.length()) }; - FilterXOtelKVList *filterx_otel_kvlist = (FilterXOtelKVList *) filterx_otel_kvlist_new_from_args(NULL, args); + FilterXOtelKVList *filterx_otel_kvlist = (FilterXOtelKVList *) filterx_otel_kvlist_new_from_args(NULL, args, G_N_ELEMENTS(args)); cr_assert(filterx_otel_kvlist); _assert_repeated_kvs(filterx_otel_kvlist->cpp->get_value(), kvlist.values()); filterx_object_unref(&filterx_otel_kvlist->super.super); - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); } Test(otel_filterx, kvlist_from_protobuf_invalid_arg) { - GPtrArray *args = g_ptr_array_new_full(1, (GDestroyNotify) filterx_object_unref); - g_ptr_array_insert(args, 0, filterx_string_new("", 0)); + FilterXObject *args[] = { filterx_string_new("", 0) }; - FilterXOtelKVList *filterx_otel_kvlist = (FilterXOtelKVList *) filterx_otel_kvlist_new_from_args(NULL, args); + FilterXOtelKVList *filterx_otel_kvlist = (FilterXOtelKVList *) filterx_otel_kvlist_new_from_args(NULL, args, G_N_ELEMENTS(args)); cr_assert_not(filterx_otel_kvlist); - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); } Test(otel_filterx, kvlist_from_protobuf_malformed_data) { - GPtrArray *args = g_ptr_array_new_full(1, (GDestroyNotify) filterx_object_unref); - g_ptr_array_insert(args, 0, filterx_protobuf_new("1234", 4)); + FilterXObject *args[] = { filterx_protobuf_new("1234", 4) }; - FilterXOtelKVList *filterx_otel_kvlist = (FilterXOtelKVList *) filterx_otel_kvlist_new_from_args(NULL, args); + FilterXOtelKVList *filterx_otel_kvlist = (FilterXOtelKVList *) filterx_otel_kvlist_new_from_args(NULL, args, G_N_ELEMENTS(args)); cr_assert_not(filterx_otel_kvlist); - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); } Test(otel_filterx, kvlist_too_many_args) { - GPtrArray *args = g_ptr_array_new_full(2, (GDestroyNotify) filterx_object_unref); - g_ptr_array_insert(args, 0, filterx_string_new("foo", 3)); - g_ptr_array_insert(args, 1, filterx_protobuf_new("bar", 3)); + FilterXObject *args[] = { filterx_string_new("foo", 3), filterx_protobuf_new("bar", 3) }; - FilterXOtelKVList *filterx_otel_kvlist = (FilterXOtelKVList *) filterx_otel_kvlist_new_from_args(NULL, args); + FilterXOtelKVList *filterx_otel_kvlist = (FilterXOtelKVList *) filterx_otel_kvlist_new_from_args(NULL, args, G_N_ELEMENTS(args)); cr_assert_not(filterx_otel_kvlist); - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); } Test(otel_filterx, kvlist_get_subscript) @@ -713,10 +690,9 @@ Test(otel_filterx, kvlist_get_subscript) inner_array->add_values()->set_int_value(1000); std::string serialized_kvlist = kvlist.SerializePartialAsString(); - GPtrArray *args = g_ptr_array_new_full(1, (GDestroyNotify) filterx_object_unref); - g_ptr_array_insert(args, 0, filterx_protobuf_new(serialized_kvlist.c_str(), serialized_kvlist.length())); + FilterXObject *args[] = { filterx_protobuf_new(serialized_kvlist.c_str(), serialized_kvlist.length()) }; - FilterXObject *filterx_otel_kvlist = (FilterXObject *) filterx_otel_kvlist_new_from_args(NULL, args); + FilterXObject *filterx_otel_kvlist = (FilterXObject *) filterx_otel_kvlist_new_from_args(NULL, args, G_N_ELEMENTS(args)); cr_assert(filterx_otel_kvlist); FilterXObject *element_1_key = filterx_string_new("element_1_key", -1); @@ -733,7 +709,7 @@ Test(otel_filterx, kvlist_get_subscript) filterx_object_unref(element_3_key); filterx_object_unref(element_4_key); filterx_object_unref(filterx_otel_kvlist); - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); } Test(otel_filterx, kvlist_set_subscript) @@ -974,51 +950,46 @@ Test(otel_filterx, array_from_protobuf) element_2->set_string_value("foobar"); std::string serialized_array = array.SerializePartialAsString(); - GPtrArray *args = g_ptr_array_new_full(1, (GDestroyNotify) filterx_object_unref); - g_ptr_array_insert(args, 0, filterx_protobuf_new(serialized_array.c_str(), serialized_array.length())); + FilterXObject *args[] = { filterx_protobuf_new(serialized_array.c_str(), serialized_array.length()) }; - FilterXOtelArray *filterx_otel_array = (FilterXOtelArray *) filterx_otel_array_new_from_args(NULL, args); + FilterXOtelArray *filterx_otel_array = (FilterXOtelArray *) filterx_otel_array_new_from_args(NULL, args, G_N_ELEMENTS(args)); cr_assert(filterx_otel_array); const opentelemetry::proto::common::v1::ArrayValue &array_from_filterx = filterx_otel_array->cpp->get_value(); cr_assert(MessageDifferencer::Equals(array, array_from_filterx)); filterx_object_unref(&filterx_otel_array->super.super); - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); } Test(otel_filterx, array_from_protobuf_invalid_arg) { - GPtrArray *args = g_ptr_array_new_full(1, (GDestroyNotify) filterx_object_unref); - g_ptr_array_insert(args, 0, filterx_string_new("", 0)); + FilterXObject *args[] = { filterx_string_new("", 0) }; - FilterXOtelArray *filterx_otel_array = (FilterXOtelArray *) filterx_otel_array_new_from_args(NULL, args); + FilterXOtelArray *filterx_otel_array = (FilterXOtelArray *) filterx_otel_array_new_from_args(NULL, args, G_N_ELEMENTS(args)); cr_assert_not(filterx_otel_array); - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); } Test(otel_filterx, array_from_protobuf_malformed_data) { - GPtrArray *args = g_ptr_array_new_full(1, (GDestroyNotify) filterx_object_unref); - g_ptr_array_insert(args, 0, filterx_protobuf_new("1234", 4)); + FilterXObject *args[] = { filterx_protobuf_new("1234", 4) }; - FilterXOtelArray *filterx_otel_array = (FilterXOtelArray *) filterx_otel_array_new_from_args(NULL, args); + FilterXOtelArray *filterx_otel_array = (FilterXOtelArray *) filterx_otel_array_new_from_args(NULL, args, G_N_ELEMENTS(args)); cr_assert_not(filterx_otel_array); - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); } Test(otel_filterx, array_too_many_args) { - GPtrArray *args = g_ptr_array_new_full(2, (GDestroyNotify) filterx_object_unref); - g_ptr_array_insert(args, 0, filterx_string_new("foo", 3)); - g_ptr_array_insert(args, 1, filterx_protobuf_new("bar", 3)); + FilterXObject *args[] = { filterx_string_new("foo", 3), filterx_protobuf_new("bar", 3) }; - FilterXOtelArray *filterx_otel_array = (FilterXOtelArray *) filterx_otel_array_new_from_args(NULL, args); + FilterXOtelArray *filterx_otel_array = (FilterXOtelArray *) filterx_otel_array_new_from_args(NULL, args, G_N_ELEMENTS(args)); cr_assert_not(filterx_otel_array); - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); } Test(otel_filterx, array_get_subscript) @@ -1039,10 +1010,9 @@ Test(otel_filterx, array_get_subscript) inner_array->add_values()->set_int_value(1000); std::string serialized_array = array.SerializePartialAsString(); - GPtrArray *args = g_ptr_array_new_full(1, (GDestroyNotify) filterx_object_unref); - g_ptr_array_insert(args, 0, filterx_protobuf_new(serialized_array.c_str(), serialized_array.length())); + FilterXObject *args[] = { filterx_protobuf_new(serialized_array.c_str(), serialized_array.length()) }; - FilterXObject *filterx_otel_array = (FilterXObject *) filterx_otel_array_new_from_args(NULL, args); + FilterXObject *filterx_otel_array = (FilterXObject *) filterx_otel_array_new_from_args(NULL, args, G_N_ELEMENTS(args)); cr_assert(filterx_otel_array); FilterXObject *element_1_index = filterx_integer_new(0); @@ -1064,7 +1034,7 @@ Test(otel_filterx, array_get_subscript) filterx_object_unref(element_3_index); filterx_object_unref(element_4_index); filterx_object_unref(filterx_otel_array); - g_ptr_array_free(args, TRUE); + filterx_simple_function_free_args(args, G_N_ELEMENTS(args)); } Test(otel_filterx, array_set_subscript) 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); diff --git a/modules/json/tests/test_filterx_format_json.c b/modules/json/tests/test_filterx_format_json.c index d0a9fd8263..9417a0eacd 100644 --- a/modules/json/tests/test_filterx_format_json.c +++ b/modules/json/tests/test_filterx_format_json.c @@ -42,13 +42,12 @@ static FilterXObject * _exec_format_json_and_unref(FilterXObject *arg) { - GPtrArray *args = g_ptr_array_new_with_free_func((GDestroyNotify) filterx_object_unref); - g_ptr_array_add(args, arg); + FilterXObject *args[] = { arg }; - FilterXObject *result = filterx_format_json_call(NULL, args); + FilterXObject *result = filterx_format_json_call(NULL, args, G_N_ELEMENTS(args)); cr_assert(filterx_object_is_type(result, &FILTERX_TYPE_NAME(string))); - g_ptr_array_unref(args); + filterx_object_unref(arg); return result; }