From: Simon Marchi Date: Tue, 17 Oct 2023 18:52:38 +0000 (-0400) Subject: common: introduce bt_g_array_index X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=d50d46f31cc000f03601eeaf8a0806a0c183c1d0 common: introduce bt_g_array_index Introduce bt_g_array_index, a wrapper to g_array_index, that adds a check that the specified index does not go past the end of the array. Use BT_ASSERT_DBG, so that it's enabled only in builds with debug mode enabled. The difficulty is that g_array_index is expected to yield an lvalue, since some call sites take the address of what it yields, or assign to it. The way I found to make it work is to add a statement expression that has no effect, and put the BT_ASSERT_DBG in it. Change-Id: I280c0657ec6f1cadd01328eec79da5cefada5c31 Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/10905 Reviewed-by: Philippe Proulx Tested-by: jenkins --- diff --git a/src/common/macros.h b/src/common/macros.h index 533cb9fb..ad4218c4 100644 --- a/src/common/macros.h +++ b/src/common/macros.h @@ -52,6 +52,10 @@ extern "C" { _ref; \ }) +/* Wrapper for g_array_index that adds bound checking. */ +#define bt_g_array_index(a, t, i) \ + g_array_index((a), t, ({ BT_ASSERT_DBG((i) < (a)->len); (i); })) + /* * Copied from: * : diff --git a/src/ctf-writer/field-path.c b/src/ctf-writer/field-path.c index 2d71d79f..7689a6d8 100644 --- a/src/ctf-writer/field-path.c +++ b/src/ctf-writer/field-path.c @@ -147,7 +147,7 @@ int bt_ctf_field_path_get_index(const struct bt_ctf_field_path *field_path, goto end; } - ret = g_array_index(field_path->indexes, int, index); + ret = bt_g_array_index(field_path->indexes, int, index); end: return ret; diff --git a/src/ctf-writer/field-types.c b/src/ctf-writer/field-types.c index 50f943c3..a2986abf 100644 --- a/src/ctf-writer/field-types.c +++ b/src/ctf-writer/field-types.c @@ -516,7 +516,7 @@ int add_structure_variant_member(GArray *members, if (is_variant) { struct bt_ctf_field_type_common_variant_choice *choice = - &g_array_index(members, + &bt_g_array_index(members, struct bt_ctf_field_type_common_variant_choice, members->len - 1); @@ -528,7 +528,7 @@ int add_structure_variant_member(GArray *members, BT_ASSERT_DBG(choice->ranges); } else { struct bt_ctf_field_type_common_structure_field *field = - &g_array_index(members, + &bt_g_array_index(members, struct bt_ctf_field_type_common_structure_field, members->len - 1); @@ -2190,7 +2190,7 @@ int64_t bt_ctf_field_type_common_variant_find_choice_index( for (range_i = 0; range_i < choice->ranges->len; range_i++) { struct bt_ctf_field_type_common_variant_choice_range *range = - &g_array_index( + &bt_g_array_index( choice->ranges, struct bt_ctf_field_type_common_variant_choice_range, range_i); diff --git a/src/ctf-writer/field-types.h b/src/ctf-writer/field-types.h index fa6b96a4..064108ce 100644 --- a/src/ctf-writer/field-types.h +++ b/src/ctf-writer/field-types.h @@ -33,11 +33,11 @@ BT_CTF_ASSERT_PRE_HOT((_ft), (_name), ": ft-addr=%p", (_ft)) #define BT_CTF_FIELD_TYPE_COMMON_STRUCTURE_FIELD_AT_INDEX(_ft, _index) \ - (&g_array_index(((struct bt_ctf_field_type_common_structure *) (_ft))->fields, \ + (&bt_g_array_index(((struct bt_ctf_field_type_common_structure *) (_ft))->fields, \ struct bt_ctf_field_type_common_structure_field, (_index))) #define BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(_ft, _index) \ - (&g_array_index(((struct bt_ctf_field_type_common_variant *) (_ft))->choices, \ + (&bt_g_array_index(((struct bt_ctf_field_type_common_variant *) (_ft))->choices, \ struct bt_ctf_field_type_common_variant_choice, (_index))) struct bt_ctf_field_common; diff --git a/src/ctf-writer/fields.c b/src/ctf-writer/fields.c index 3d6e3523..e05bcbcb 100644 --- a/src/ctf-writer/fields.c +++ b/src/ctf-writer/fields.c @@ -163,7 +163,7 @@ int bt_ctf_field_common_string_initialize(struct bt_ctf_field_common *field, } g_array_set_size(string->buf, 1); - g_array_index(string->buf, char, 0) = '\0'; + bt_g_array_index(string->buf, char, 0) = '\0'; BT_LOGD("Initialized common string field object: addr=%p, ft-addr=%p", field, type); diff --git a/src/ctf-writer/resolve.c b/src/ctf-writer/resolve.c index 33896051..2ceaba33 100644 --- a/src/ctf-writer/resolve.c +++ b/src/ctf-writer/resolve.c @@ -541,7 +541,7 @@ int relative_ptokens_to_field_path(GList *ptokens, } for (i = 0; i < tail_field_path_len; i++) { - int index = g_array_index( + int index = bt_g_array_index( tail_field_path->indexes, int, i); @@ -709,7 +709,7 @@ struct bt_ctf_field_type_common *field_path_to_field_type( for (i = 0; i < field_path->indexes->len; i++) { struct bt_ctf_field_type_common *child_type; int child_index = - g_array_index(field_path->indexes, int, i); + bt_g_array_index(field_path->indexes, int, i); /* Get child field type */ child_type = bt_ctf_field_type_common_borrow_field_at_index(type, @@ -827,9 +827,9 @@ int get_field_paths_lca_index(struct bt_ctf_field_path *field_path1, break; } - target_index = g_array_index(field_path1->indexes, int, + target_index = bt_g_array_index(field_path1->indexes, int, lca_index); - ctx_index = g_array_index(field_path2->indexes, int, + ctx_index = bt_g_array_index(field_path2->indexes, int, lca_index); if (target_index != ctx_index) { @@ -910,9 +910,9 @@ int validate_target_field_path(struct bt_ctf_field_path *target_field_path, * Make sure the target field path is located before the * context field path. */ - target_index = g_array_index(target_field_path->indexes, + target_index = bt_g_array_index(target_field_path->indexes, int, lca_index); - ctx_index = g_array_index(ctx_field_path->indexes, + ctx_index = bt_g_array_index(ctx_field_path->indexes, int, lca_index); if (target_index >= ctx_index) { diff --git a/src/lib/graph/component-class.c b/src/lib/graph/component-class.c index 516c31f1..ae3e6871 100644 --- a/src/lib/graph/component-class.c +++ b/src/lib/graph/component-class.c @@ -39,7 +39,7 @@ void destroy_component_class(struct bt_object *obj) if (class->destroy_listeners) { for (i = class->destroy_listeners->len - 1; i >= 0; i--) { struct bt_component_class_destroy_listener *listener = - &g_array_index(class->destroy_listeners, + &bt_g_array_index(class->destroy_listeners, struct bt_component_class_destroy_listener, i); diff --git a/src/lib/graph/component.c b/src/lib/graph/component.c index e73a1c7a..b5f4d28d 100644 --- a/src/lib/graph/component.c +++ b/src/lib/graph/component.c @@ -133,7 +133,7 @@ void destroy_component(struct bt_object *obj) for (i = component->destroy_listeners->len - 1; i >= 0; i--) { struct bt_component_destroy_listener *listener = - &g_array_index(component->destroy_listeners, + &bt_g_array_index(component->destroy_listeners, struct bt_component_destroy_listener, i); listener->func(component, listener->data); @@ -610,7 +610,7 @@ void bt_component_remove_destroy_listener(struct bt_component *component, for (i = 0; i < component->destroy_listeners->len; i++) { struct bt_component_destroy_listener *listener = - &g_array_index(component->destroy_listeners, + &bt_g_array_index(component->destroy_listeners, struct bt_component_destroy_listener, i); if (listener->func == func && listener->data == data) { diff --git a/src/lib/graph/graph.c b/src/lib/graph/graph.c index d0776249..08d8846d 100644 --- a/src/lib/graph/graph.c +++ b/src/lib/graph/graph.c @@ -929,7 +929,7 @@ enum bt_graph_listener_func_status bt_graph_notify_port_added( for (i = 0; i < listeners->len; i++) { struct bt_graph_listener_port_added *listener = - &g_array_index(listeners, + &bt_g_array_index(listeners, struct bt_graph_listener_port_added, i); diff --git a/src/lib/integer-range-set.h b/src/lib/integer-range-set.h index 69e51993..c53a7849 100644 --- a/src/lib/integer-range-set.h +++ b/src/lib/integer-range-set.h @@ -17,7 +17,7 @@ #include "object.h" #define BT_INTEGER_RANGE_SET_RANGE_AT_INDEX(_rs, _index) \ - (&g_array_index((_rs)->ranges, struct bt_integer_range, (_index))) + (&bt_g_array_index((_rs)->ranges, struct bt_integer_range, (_index))) struct bt_integer_range { union { diff --git a/src/lib/plugin/plugin-so.c b/src/lib/plugin/plugin-so.c index 65ec447d..6cb14080 100644 --- a/src/lib/plugin/plugin-so.c +++ b/src/lib/plugin/plugin-so.c @@ -460,7 +460,7 @@ int bt_plugin_so_init(struct bt_plugin *plugin, /* Find the corresponding component class descriptor entry */ for (i = 0; i < comp_class_full_descriptors->len; i++) { struct comp_class_full_descriptor *cc_full_descr = - &g_array_index(comp_class_full_descriptors, + &bt_g_array_index(comp_class_full_descriptors, struct comp_class_full_descriptor, i); if (cur_cc_descr_attr->comp_class_descriptor != @@ -751,7 +751,7 @@ int bt_plugin_so_init(struct bt_plugin *plugin, /* Add described component classes to plugin */ for (i = 0; i < comp_class_full_descriptors->len; i++) { struct comp_class_full_descriptor *cc_full_descr = - &g_array_index(comp_class_full_descriptors, + &bt_g_array_index(comp_class_full_descriptors, struct comp_class_full_descriptor, i); struct bt_component_class *comp_class = NULL; struct bt_component_class_source *src_comp_class = NULL; diff --git a/src/lib/trace-ir/field-class.h b/src/lib/trace-ir/field-class.h index 29c4f72a..159614a2 100644 --- a/src/lib/trace-ir/field-class.h +++ b/src/lib/trace-ir/field-class.h @@ -20,11 +20,11 @@ #include #define BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(_fc, _index) \ - (&g_array_index(((struct bt_field_class_enumeration *) (_fc))->mappings, \ + (&bt_g_array_index(((struct bt_field_class_enumeration *) (_fc))->mappings, \ struct bt_field_class_enumeration_mapping, (_index))) #define BT_FIELD_CLASS_ENUM_MAPPING_RANGE_AT_INDEX(_mapping, _index) \ - (&g_array_index((_mapping)->ranges, \ + (&bt_g_array_index((_mapping)->ranges, \ struct bt_field_class_enumeration_mapping_range, (_index))) struct bt_field_class { diff --git a/src/lib/trace-ir/field-path.h b/src/lib/trace-ir/field-path.h index fb07e11c..79e9d8f1 100644 --- a/src/lib/trace-ir/field-path.h +++ b/src/lib/trace-ir/field-path.h @@ -37,7 +37,7 @@ struct bt_field_path_item *bt_field_path_borrow_item_by_index_inline( { BT_ASSERT_DBG(field_path); BT_ASSERT_DBG(index < field_path->items->len); - return &g_array_index(field_path->items, struct bt_field_path_item, + return &bt_g_array_index(field_path->items, struct bt_field_path_item, index); } diff --git a/src/lib/trace-ir/field.c b/src/lib/trace-ir/field.c index 41ea5f64..d1906c5f 100644 --- a/src/lib/trace-ir/field.c +++ b/src/lib/trace-ir/field.c @@ -389,7 +389,7 @@ struct bt_field *create_string_field(struct bt_field_class *fc) } g_array_set_size(string_field->buf, 1); - g_array_index(string_field->buf, char, 0) = '\0'; + bt_g_array_index(string_field->buf, char, 0) = '\0'; BT_LIB_LOGD("Created string field object: %!+f", string_field); end: @@ -875,7 +875,7 @@ void clear_string_field(struct bt_field *field) BT_ASSERT_DBG(field); string_field->length = 0; - g_array_index(string_field->buf, char, 0) = '\0'; + bt_g_array_index(string_field->buf, char, 0) = '\0'; bt_field_set_single(field, true); } diff --git a/src/lib/trace-ir/trace-class.c b/src/lib/trace-ir/trace-class.c index 9f7068a7..15182149 100644 --- a/src/lib/trace-ir/trace-class.c +++ b/src/lib/trace-ir/trace-class.c @@ -85,7 +85,7 @@ void destroy_trace_class(struct bt_object *obj) /* Call all the trace class destruction listeners */ for (i = 0; i < tc->destruction_listeners->len; i++) { struct bt_trace_class_destruction_listener_elem elem = - g_array_index(tc->destruction_listeners, + bt_g_array_index(tc->destruction_listeners, struct bt_trace_class_destruction_listener_elem, i); if (elem.func) { @@ -188,7 +188,7 @@ enum bt_trace_class_add_listener_status bt_trace_class_add_destruction_listener( /* Find the next available spot */ for (i = 0; i < tc->destruction_listeners->len; i++) { struct bt_trace_class_destruction_listener_elem elem = - g_array_index(tc->destruction_listeners, + bt_g_array_index(tc->destruction_listeners, struct bt_trace_class_destruction_listener_elem, i); if (!elem.func) { @@ -215,7 +215,7 @@ static bool has_listener_id(const struct bt_trace_class *tc, uint64_t listener_id) { BT_ASSERT(listener_id < tc->destruction_listeners->len); - return (&g_array_index(tc->destruction_listeners, + return (&bt_g_array_index(tc->destruction_listeners, struct bt_trace_class_destruction_listener_elem, listener_id))->func; } @@ -233,7 +233,7 @@ enum bt_trace_class_remove_listener_status bt_trace_class_remove_destruction_lis has_listener_id(tc, listener_id), "Trace class has no such trace class destruction listener ID: " "%![tc-]+T, %" PRIu64, tc, listener_id); - elem = &g_array_index(tc->destruction_listeners, + elem = &bt_g_array_index(tc->destruction_listeners, struct bt_trace_class_destruction_listener_elem, listener_id); BT_ASSERT(elem->func); diff --git a/src/lib/trace-ir/trace.c b/src/lib/trace-ir/trace.c index e2a462ec..982325f7 100644 --- a/src/lib/trace-ir/trace.c +++ b/src/lib/trace-ir/trace.c @@ -87,7 +87,7 @@ void destroy_trace(struct bt_object *obj) /* Call all the trace destruction listeners */ for (i = 0; i < trace->destruction_listeners->len; i++) { struct bt_trace_destruction_listener_elem elem = - g_array_index(trace->destruction_listeners, + bt_g_array_index(trace->destruction_listeners, struct bt_trace_destruction_listener_elem, i); if (elem.func) { @@ -453,7 +453,7 @@ enum bt_trace_add_listener_status bt_trace_add_destruction_listener( /* Find the next available spot */ for (i = 0; i < trace->destruction_listeners->len; i++) { struct bt_trace_destruction_listener_elem elem = - g_array_index(trace->destruction_listeners, + bt_g_array_index(trace->destruction_listeners, struct bt_trace_destruction_listener_elem, i); if (!elem.func) { @@ -480,7 +480,7 @@ static bool has_listener_id(const struct bt_trace *trace, uint64_t listener_id) { BT_ASSERT(listener_id < trace->destruction_listeners->len); - return (&g_array_index(trace->destruction_listeners, + return (&bt_g_array_index(trace->destruction_listeners, struct bt_trace_destruction_listener_elem, listener_id))->func; } @@ -498,7 +498,7 @@ enum bt_trace_remove_listener_status bt_trace_remove_destruction_listener( has_listener_id(trace, listener_id), "Trace has no such trace destruction listener ID: " "%![trace-]+t, %" PRIu64, trace, listener_id); - elem = &g_array_index(trace->destruction_listeners, + elem = &bt_g_array_index(trace->destruction_listeners, struct bt_trace_destruction_listener_elem, listener_id); BT_ASSERT(elem->func); diff --git a/src/plugins/common/param-validation/param-validation.c b/src/plugins/common/param-validation/param-validation.c index 4919463d..d1874416 100644 --- a/src/plugins/common/param-validation/param-validation.c +++ b/src/plugins/common/param-validation/param-validation.c @@ -101,12 +101,12 @@ enum bt_param_validation_status bt_param_validation_error( g_string_assign(str, "Error validating parameter `"); - append_scope_to_string(str, &g_array_index(ctx->scope_stack, + append_scope_to_string(str, &bt_g_array_index(ctx->scope_stack, struct validate_ctx_stack_element, 0), true); for (i = 1; i < ctx->scope_stack->len; i++) { append_scope_to_string(str, - &g_array_index(ctx->scope_stack, + &bt_g_array_index(ctx->scope_stack, struct validate_ctx_stack_element, i), false); } diff --git a/src/plugins/ctf/common/bfcr/bfcr.cpp b/src/plugins/ctf/common/bfcr/bfcr.cpp index 3c204b6a..7014f102 100644 --- a/src/plugins/ctf/common/bfcr/bfcr.cpp +++ b/src/plugins/ctf/common/bfcr/bfcr.cpp @@ -238,7 +238,7 @@ static int stack_push(struct stack *stack, struct ctf_field_class *base_class, s g_array_set_size(stack->entries, stack->size + 1); } - entry = &g_array_index(stack->entries, struct stack_entry, stack->size); + entry = &bt_g_array_index(stack->entries, struct stack_entry, stack->size); entry->base_class = base_class; entry->base_len = base_len; entry->index = 0; @@ -335,7 +335,7 @@ static inline struct stack_entry *stack_top(struct stack *stack) { BT_ASSERT_DBG(stack); BT_ASSERT_DBG(stack_size(stack)); - return &g_array_index(stack->entries, struct stack_entry, stack->size - 1); + return &bt_g_array_index(stack->entries, struct stack_entry, stack->size - 1); } static inline size_t available_bits(struct bt_bfcr *bfcr) diff --git a/src/plugins/ctf/common/metadata/ctf-meta.hpp b/src/plugins/ctf/common/metadata/ctf-meta.hpp index 6bf43756..f87b4260 100644 --- a/src/plugins/ctf/common/metadata/ctf-meta.hpp +++ b/src/plugins/ctf/common/metadata/ctf-meta.hpp @@ -598,7 +598,7 @@ static inline void _ctf_field_class_enum_destroy(struct ctf_field_class_enum *fc for (i = 0; i < fc->mappings->len; i++) { struct ctf_field_class_enum_mapping *mapping = - &g_array_index(fc->mappings, struct ctf_field_class_enum_mapping, i); + &bt_g_array_index(fc->mappings, struct ctf_field_class_enum_mapping, i); _ctf_field_class_enum_mapping_fini(mapping); } @@ -630,7 +630,7 @@ static inline void _ctf_field_class_struct_destroy(struct ctf_field_class_struct for (i = 0; i < fc->members->len; i++) { struct ctf_named_field_class *named_fc = - &g_array_index(fc->members, struct ctf_named_field_class, i); + &bt_g_array_index(fc->members, struct ctf_named_field_class, i); _ctf_named_field_class_fini(named_fc); } @@ -676,7 +676,7 @@ static inline void _ctf_field_class_variant_destroy(struct ctf_field_class_varia for (i = 0; i < fc->options->len; i++) { struct ctf_named_field_class *named_fc = - &g_array_index(fc->options, struct ctf_named_field_class, i); + &bt_g_array_index(fc->options, struct ctf_named_field_class, i); _ctf_named_field_class_fini(named_fc); } @@ -738,7 +738,7 @@ ctf_field_class_enum_mapping_borrow_range_by_index(struct ctf_field_class_enum_m { BT_ASSERT_DBG(mapping); BT_ASSERT_DBG(index < mapping->ranges->len); - return &g_array_index(mapping->ranges, struct ctf_range, index); + return &bt_g_array_index(mapping->ranges, struct ctf_range, index); } static inline struct ctf_field_class_enum_mapping * @@ -746,7 +746,7 @@ ctf_field_class_enum_borrow_mapping_by_index(struct ctf_field_class_enum *fc, ui { BT_ASSERT_DBG(fc); BT_ASSERT_DBG(index < fc->mappings->len); - return &g_array_index(fc->mappings, struct ctf_field_class_enum_mapping, index); + return &bt_g_array_index(fc->mappings, struct ctf_field_class_enum_mapping, index); } static inline struct ctf_field_class_enum_mapping * @@ -819,7 +819,7 @@ ctf_field_class_struct_borrow_member_by_index(struct ctf_field_class_struct *fc, { BT_ASSERT_DBG(fc); BT_ASSERT_DBG(index < fc->members->len); - return &g_array_index(fc->members, struct ctf_named_field_class, index); + return &bt_g_array_index(fc->members, struct ctf_named_field_class, index); } static inline struct ctf_named_field_class * @@ -907,7 +907,7 @@ static inline void ctf_field_class_struct_append_member(struct ctf_field_class_s BT_ASSERT(orig_name); g_array_set_size(fc->members, fc->members->len + 1); - named_fc = &g_array_index(fc->members, struct ctf_named_field_class, fc->members->len - 1); + named_fc = &bt_g_array_index(fc->members, struct ctf_named_field_class, fc->members->len - 1); _ctf_named_field_class_init(named_fc); g_string_assign(named_fc->orig_name, orig_name); _ctf_named_field_class_unescape_orig_name(named_fc); @@ -923,7 +923,7 @@ ctf_field_class_variant_borrow_option_by_index(struct ctf_field_class_variant *f { BT_ASSERT_DBG(fc); BT_ASSERT_DBG(index < fc->options->len); - return &g_array_index(fc->options, struct ctf_named_field_class, index); + return &bt_g_array_index(fc->options, struct ctf_named_field_class, index); } static inline struct ctf_named_field_class * @@ -954,7 +954,7 @@ ctf_field_class_variant_borrow_range_by_index(struct ctf_field_class_variant *fc { BT_ASSERT_DBG(fc); BT_ASSERT_DBG(index < fc->ranges->len); - return &g_array_index(fc->ranges, struct ctf_field_class_variant_range, index); + return &bt_g_array_index(fc->ranges, struct ctf_field_class_variant_range, index); } static inline void ctf_field_class_variant_append_option(struct ctf_field_class_variant *fc, @@ -967,7 +967,7 @@ static inline void ctf_field_class_variant_append_option(struct ctf_field_class_ BT_ASSERT(orig_name); g_array_set_size(fc->options, fc->options->len + 1); - named_fc = &g_array_index(fc->options, struct ctf_named_field_class, fc->options->len - 1); + named_fc = &bt_g_array_index(fc->options, struct ctf_named_field_class, fc->options->len - 1); _ctf_named_field_class_init(named_fc); g_string_assign(named_fc->orig_name, orig_name); _ctf_named_field_class_unescape_orig_name(named_fc); @@ -1139,7 +1139,7 @@ static inline int64_t ctf_field_path_borrow_index_by_index(struct ctf_field_path { BT_ASSERT_DBG(fp); BT_ASSERT_DBG(index < fp->path->len); - return g_array_index(fp->path, int64_t, index); + return bt_g_array_index(fp->path, int64_t, index); } static inline void ctf_field_path_clear(struct ctf_field_path *fp) @@ -1280,10 +1280,10 @@ _ctf_field_class_enum_copy(struct ctf_field_class_enum *fc) uint64_t range_i; struct ctf_field_class_enum_mapping *mapping = - &g_array_index(fc->mappings, struct ctf_field_class_enum_mapping, i); + &bt_g_array_index(fc->mappings, struct ctf_field_class_enum_mapping, i); for (range_i = 0; range_i < mapping->ranges->len; range_i++) { - struct ctf_range *range = &g_array_index(mapping->ranges, struct ctf_range, range_i); + struct ctf_range *range = &bt_g_array_index(mapping->ranges, struct ctf_range, range_i); ctf_field_class_enum_map_range(copy_fc, mapping->label->str, range->lower.u, range->upper.u); @@ -1322,7 +1322,7 @@ _ctf_field_class_struct_copy(struct ctf_field_class_struct *fc) for (i = 0; i < fc->members->len; i++) { struct ctf_named_field_class *named_fc = - &g_array_index(fc->members, struct ctf_named_field_class, i); + &bt_g_array_index(fc->members, struct ctf_named_field_class, i); ctf_field_class_struct_append_member(copy_fc, named_fc->name->str, ctf_field_class_copy(named_fc->fc)); @@ -1358,7 +1358,7 @@ _ctf_field_class_variant_copy(struct ctf_field_class_variant *fc) for (i = 0; i < fc->options->len; i++) { struct ctf_named_field_class *named_fc = - &g_array_index(fc->options, struct ctf_named_field_class, i); + &bt_g_array_index(fc->options, struct ctf_named_field_class, i); ctf_field_class_variant_append_option(copy_fc, named_fc->name->str, ctf_field_class_copy(named_fc->fc)); @@ -1366,7 +1366,7 @@ _ctf_field_class_variant_copy(struct ctf_field_class_variant *fc) for (i = 0; i < fc->ranges->len; i++) { struct ctf_field_class_variant_range *range = - &g_array_index(fc->ranges, struct ctf_field_class_variant_range, i); + &bt_g_array_index(fc->ranges, struct ctf_field_class_variant_range, i); g_array_append_val(copy_fc->ranges, *range); } @@ -1635,7 +1635,7 @@ static inline void ctf_trace_class_destroy(struct ctf_trace_class *tc) for (i = 0; i < tc->env_entries->len; i++) { struct ctf_trace_class_env_entry *entry = - &g_array_index(tc->env_entries, struct ctf_trace_class_env_entry, i); + &bt_g_array_index(tc->env_entries, struct ctf_trace_class_env_entry, i); _ctf_trace_class_env_entry_fini(entry); } @@ -1656,8 +1656,8 @@ static inline void ctf_trace_class_append_env_entry(struct ctf_trace_class *tc, BT_ASSERT(name); g_array_set_size(tc->env_entries, tc->env_entries->len + 1); - entry = - &g_array_index(tc->env_entries, struct ctf_trace_class_env_entry, tc->env_entries->len - 1); + entry = &bt_g_array_index(tc->env_entries, struct ctf_trace_class_env_entry, + tc->env_entries->len - 1); entry->type = type; _ctf_trace_class_env_entry_init(entry); g_string_assign(entry->name, name); @@ -1718,7 +1718,7 @@ ctf_trace_class_borrow_env_entry_by_index(struct ctf_trace_class *tc, uint64_t i { BT_ASSERT_DBG(tc); BT_ASSERT_DBG(index < tc->env_entries->len); - return &g_array_index(tc->env_entries, struct ctf_trace_class_env_entry, index); + return &bt_g_array_index(tc->env_entries, struct ctf_trace_class_env_entry, index); } static inline struct ctf_trace_class_env_entry * diff --git a/src/plugins/ctf/common/msg-iter/msg-iter.cpp b/src/plugins/ctf/common/msg-iter/msg-iter.cpp index eed75853..4efc5ed6 100644 --- a/src/plugins/ctf/common/msg-iter/msg-iter.cpp +++ b/src/plugins/ctf/common/msg-iter/msg-iter.cpp @@ -394,7 +394,7 @@ static void stack_push(struct stack *stack, bt_field *base) g_array_set_size(stack->entries, stack->size + 1); } - entry = &g_array_index(stack->entries, struct stack_entry, stack->size); + entry = &bt_g_array_index(stack->entries, struct stack_entry, stack->size); entry->base = base; entry->index = 0; stack->size++; @@ -423,7 +423,7 @@ static inline struct stack_entry *stack_top(struct stack *stack) { BT_ASSERT_DBG(stack); BT_ASSERT_DBG(stack_size(stack)); - return &g_array_index(stack->entries, struct stack_entry, stack->size - 1); + return &bt_g_array_index(stack->entries, struct stack_entry, stack->size - 1); } static inline bool stack_empty(struct stack *stack) @@ -1862,7 +1862,7 @@ update_def_clock: } if (G_UNLIKELY(int_fc->storing_index >= 0)) { - g_array_index(msg_it->stored_values, uint64_t, (uint64_t) int_fc->storing_index) = value; + bt_g_array_index(msg_it->stored_values, uint64_t, (uint64_t) int_fc->storing_index) = value; } if (G_UNLIKELY(!fc->in_ir || msg_it->dry_run)) { @@ -1948,7 +1948,7 @@ static enum bt_bfcr_status bfcr_signed_int_cb(int64_t value, struct ctf_field_cl BT_ASSERT_DBG(int_fc->meaning == CTF_FIELD_CLASS_MEANING_NONE); if (G_UNLIKELY(int_fc->storing_index >= 0)) { - g_array_index(msg_it->stored_values, uint64_t, (uint64_t) int_fc->storing_index) = + bt_g_array_index(msg_it->stored_values, uint64_t, (uint64_t) int_fc->storing_index) = (uint64_t) value; } @@ -2191,7 +2191,8 @@ static int64_t bfcr_get_sequence_length_cb(struct ctf_field_class *fc, void *dat int64_t length; int ret; - length = (uint64_t) g_array_index(msg_it->stored_values, uint64_t, seq_fc->stored_length_index); + length = + (uint64_t) bt_g_array_index(msg_it->stored_values, uint64_t, seq_fc->stored_length_index); if (G_UNLIKELY(msg_it->dry_run)) { goto end; @@ -2242,7 +2243,7 @@ bfcr_borrow_variant_selected_field_class_cb(struct ctf_field_class *fc, void *da } tag; /* Get variant's tag */ - tag.u = g_array_index(msg_it->stored_values, uint64_t, var_fc->stored_tag_index); + tag.u = bt_g_array_index(msg_it->stored_values, uint64_t, var_fc->stored_tag_index); /* * Check each range to find the selected option's index. diff --git a/src/plugins/ctf/fs-sink/fs-sink-ctf-meta.hpp b/src/plugins/ctf/fs-sink/fs-sink-ctf-meta.hpp index e56ab526..8795b451 100644 --- a/src/plugins/ctf/fs-sink/fs-sink-ctf-meta.hpp +++ b/src/plugins/ctf/fs-sink/fs-sink-ctf-meta.hpp @@ -668,7 +668,7 @@ fs_sink_ctf_field_class_struct_borrow_member_by_index(struct fs_sink_ctf_field_c { BT_ASSERT_DBG(fc); BT_ASSERT_DBG(index < fc->members->len); - return &g_array_index(fc->members, struct fs_sink_ctf_named_field_class, index); + return &bt_g_array_index(fc->members, struct fs_sink_ctf_named_field_class, index); } static inline struct fs_sink_ctf_named_field_class * @@ -759,7 +759,7 @@ fs_sink_ctf_field_class_struct_append_member(struct fs_sink_ctf_field_class_stru g_array_set_size(fc->members, fc->members->len + 1); named_fc = - &g_array_index(fc->members, struct fs_sink_ctf_named_field_class, fc->members->len - 1); + &bt_g_array_index(fc->members, struct fs_sink_ctf_named_field_class, fc->members->len - 1); _fs_sink_ctf_named_field_class_init(named_fc); g_string_assign(named_fc->name, name); named_fc->fc = member_fc; @@ -772,7 +772,7 @@ fs_sink_ctf_field_class_variant_borrow_option_by_index(struct fs_sink_ctf_field_ { BT_ASSERT_DBG(fc); BT_ASSERT_DBG(index < fc->options->len); - return &g_array_index(fc->options, struct fs_sink_ctf_named_field_class, index); + return &bt_g_array_index(fc->options, struct fs_sink_ctf_named_field_class, index); } static inline struct fs_sink_ctf_named_field_class * @@ -811,7 +811,7 @@ fs_sink_ctf_field_class_variant_append_option(struct fs_sink_ctf_field_class_var g_array_set_size(fc->options, fc->options->len + 1); named_fc = - &g_array_index(fc->options, struct fs_sink_ctf_named_field_class, fc->options->len - 1); + &bt_g_array_index(fc->options, struct fs_sink_ctf_named_field_class, fc->options->len - 1); _fs_sink_ctf_named_field_class_init(named_fc); g_string_assign(named_fc->name, name); named_fc->fc = option_fc; diff --git a/src/plugins/ctf/fs-sink/translate-trace-ir-to-ctf-ir.cpp b/src/plugins/ctf/fs-sink/translate-trace-ir-to-ctf-ir.cpp index 4030d7d2..80adcc3a 100644 --- a/src/plugins/ctf/fs-sink/translate-trace-ir-to-ctf-ir.cpp +++ b/src/plugins/ctf/fs-sink/translate-trace-ir-to-ctf-ir.cpp @@ -57,7 +57,7 @@ struct ctx static inline struct field_path_elem *cur_path_stack_at(struct ctx *ctx, uint64_t i) { BT_ASSERT(i < ctx->cur_path->len); - return &g_array_index(ctx->cur_path, struct field_path_elem, i); + return &bt_g_array_index(ctx->cur_path, struct field_path_elem, i); } static inline struct field_path_elem *cur_path_stack_top(struct ctx *ctx) diff --git a/src/plugins/text/details/write.c b/src/plugins/text/details/write.c index a98de988..a99599e3 100644 --- a/src/plugins/text/details/write.c +++ b/src/plugins/text/details/write.c @@ -660,7 +660,7 @@ void destroy_enum_field_class_mapping(struct enum_field_class_mapping *mapping) static struct int_range *int_range_at(GArray *ranges, uint64_t index) { - return &g_array_index(ranges, struct int_range, index); + return &bt_g_array_index(ranges, struct int_range, index); } static diff --git a/tests/lib/test_graph_topo.c b/tests/lib/test_graph_topo.c index c31f7c8b..0a0f2bc4 100644 --- a/tests/lib/test_graph_topo.c +++ b/tests/lib/test_graph_topo.c @@ -151,7 +151,7 @@ bool has_event(struct event *event) size_t i; for (i = 0; i < events->len; i++) { - struct event *ev = &g_array_index(events, struct event, i); + struct event *ev = &bt_g_array_index(events, struct event, i); if (compare_events(event, ev)) { return true; @@ -167,7 +167,7 @@ size_t event_pos(struct event *event) size_t i; for (i = 0; i < events->len; i++) { - struct event *ev = &g_array_index(events, struct event, i); + struct event *ev = &bt_g_array_index(events, struct event, i); if (compare_events(event, ev)) { return i;