_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:
* <https://stackoverflow.com/questions/37411809/how-to-elegantly-fix-this-unused-variable-warning/37412551#37412551>:
goto end;
}
- ret = g_array_index(field_path->indexes, int, index);
+ ret = bt_g_array_index(field_path->indexes, int, index);
end:
return ret;
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);
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);
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);
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;
}
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);
}
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);
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,
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) {
* 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) {
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);
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);
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) {
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);
#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 {
/* 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 !=
/* 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;
#include <glib.h>
#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 {
{
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);
}
}
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:
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);
}
/* 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) {
/* 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) {
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;
}
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);
/* 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) {
/* 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) {
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;
}
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);
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);
}
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;
{
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)
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);
}
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);
}
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);
}
{
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 *
{
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 *
{
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 *
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);
{
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 *
{
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,
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);
{
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)
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);
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));
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));
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);
}
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);
}
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);
{
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 *
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++;
{
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)
}
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)) {
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;
}
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;
} 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.
{
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 *
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;
{
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 *
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;
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)
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
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;
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;