lib: add structure FC member and variant FC option objects
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Wed, 10 Apr 2019 03:03:20 +0000 (23:03 -0400)
committerFrancis Deslauriers <francis.deslauriers@efficios.com>
Thu, 2 May 2019 20:50:15 +0000 (20:50 +0000)
This patch adds the structure field class member and variant field
class option objects to the field class API.

The purpose of those objects is to be able to operate at the structure
FC member or variant FC option level in the future, for example when we
add custom user attributes which you can attach to individual field
classes, but also to members/options themselves.

Behind the scenes, the `bt_field_class_structure_member *` and
`bt_field_class_structure_member *` types are just the existing
`struct bt_named_field_class *` type.

You cannot manually create a structure FC member or variant FC option
object: they are created when calling
bt_field_class_structure_append_member() or
bt_field_class_variant_append_option(). You can then borrow them with
bt_field_class_structure_borrow_member_by_index(),
bt_field_class_structure_borrow_member_by_name(),
bt_field_class_variant_borrow_option_by_index(),
bt_field_class_variant_borrow_option_by_name(), and their const
equivalents.

When you append a member to a structure FC or an option to a variant FC,
the function does not freeze the member/option itself, but only its
contained field class. The member/option object is frozen when the
container field class (structure/variant) is frozen itself. This means,
in the future, that you can borrow a structure FC member or a variant FC
option object and then modify it (set an optional property, for
example).

Structure FC member and variant FC option objects are unique (for the
moment): they are merely a proxy offering accessors to the properties of
a container field class's elements, like enumeration field class mapping
range objects.

The only drawback I can see is that you need three function calls to get
the name and borrow the field class of a structure FC member or variant
FC option instead of a single one, but we can reintroduce a single
accessor later if it's really an issue.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
include/babeltrace/trace-ir/field-class-const.h
include/babeltrace/trace-ir/field-class-internal.h
include/babeltrace/trace-ir/field-class.h
include/babeltrace/types.h
lib/trace-ir/field-class.c
plugins/lttng-utils/trace-ir-data-copy.c
plugins/lttng-utils/trace-ir-metadata-field-class-copy.c
plugins/lttng-utils/utils.c
plugins/text/pretty/print.c

index 96f7802c727f5bdf95c634e130dc952b371d313f..244218d887aaf694574999bbd1abe5eeb123faf1 100644 (file)
@@ -126,15 +126,21 @@ bt_field_class_signed_enumeration_get_mapping_labels_by_value(
 extern uint64_t bt_field_class_structure_get_member_count(
                const bt_field_class *field_class);
 
-extern void bt_field_class_structure_borrow_member_by_index_const(
-               const bt_field_class *struct_field_class, uint64_t index,
-               const char **name, const bt_field_class **field_class);
+extern const bt_field_class_structure_member *
+bt_field_class_structure_borrow_member_by_index_const(
+               const bt_field_class *field_class, uint64_t index);
 
-extern
-const bt_field_class *
-bt_field_class_structure_borrow_member_field_class_by_name_const(
+extern const bt_field_class_structure_member *
+bt_field_class_structure_borrow_member_by_name_const(
                const bt_field_class *field_class, const char *name);
 
+extern const char *bt_field_class_structure_member_get_name(
+               const bt_field_class_structure_member *member);
+
+extern const bt_field_class *
+bt_field_class_structure_member_borrow_field_class_const(
+               const bt_field_class_structure_member *member);
+
 extern const bt_field_class *
 bt_field_class_array_borrow_element_field_class_const(
                const bt_field_class *field_class);
@@ -153,15 +159,20 @@ bt_field_class_variant_borrow_selector_field_path_const(
 extern uint64_t bt_field_class_variant_get_option_count(
                const bt_field_class *field_class);
 
-extern void bt_field_class_variant_borrow_option_by_index_const(
-               const bt_field_class *variant_field_class, uint64_t index,
-               const char **name, const bt_field_class **field_class);
+extern const bt_field_class_variant_option *
+bt_field_class_variant_borrow_option_by_index_const(
+               const bt_field_class *field_class, uint64_t index);
 
-extern
-const bt_field_class *
-bt_field_class_variant_borrow_option_field_class_by_name_const(
-               const bt_field_class *field_class,
-               const char *name);
+extern const bt_field_class_variant_option *
+bt_field_class_variant_borrow_option_by_name_const(
+               const bt_field_class *field_class, const char *name);
+
+extern const char *bt_field_class_variant_option_get_name(
+               const bt_field_class_variant_option *option);
+
+extern const bt_field_class *
+bt_field_class_variant_option_borrow_field_class_const(
+               const bt_field_class_variant_option *option);
 
 extern void bt_field_class_get_ref(const bt_field_class *field_class);
 
index d4814cdb428bec82d7c121549c8b820c72a314fe..77268c5f2bad990f2465d0850caa29b087a0d1cd 100644 (file)
@@ -163,8 +163,13 @@ struct bt_named_field_class {
 
        /* Owned by this */
        struct bt_field_class *fc;
+
+       bool frozen;
 };
 
+struct bt_field_class_structure_member;
+struct bt_field_class_variant_option;
+
 /*
  * This is the base field class for a container of named field classes.
  * Structure and variant field classes inherit this.
@@ -234,6 +239,15 @@ void _bt_field_class_freeze(const struct bt_field_class *field_class);
 # define bt_field_class_freeze(_fc)
 #endif
 
+BT_HIDDEN
+void _bt_named_field_class_freeze(const struct bt_named_field_class *named_fc);
+
+#ifdef BT_DEV_MODE
+# define bt_named_field_class_freeze           _bt_named_field_class_freeze
+#else
+# define bt_named_field_class_freeze(_named_fc)
+#endif
+
 /*
  * This function recursively marks `field_class` and its children as
  * being part of a trace. This is used to validate that all field classes
index a23deb58dbbaacca15faa44a56b1b52977373653..1da111d2e93828128a0c5ac3a72037381b2a42ef 100644 (file)
@@ -86,12 +86,12 @@ extern bt_field_class_status bt_field_class_structure_append_member(
                bt_field_class *struct_field_class,
                const char *name, bt_field_class *field_class);
 
-extern void bt_field_class_structure_borrow_member_by_index(
-               bt_field_class *struct_field_class, uint64_t index,
-               const char **name, bt_field_class **field_class);
+extern bt_field_class_structure_member *
+bt_field_class_structure_borrow_member_by_index(
+               bt_field_class *field_class, uint64_t index);
 
-extern
-bt_field_class *bt_field_class_structure_borrow_member_field_class_by_name(
+extern bt_field_class_structure_member *
+bt_field_class_structure_borrow_member_by_name(
                bt_field_class *field_class, const char *name);
 
 extern bt_field_class *bt_field_class_static_array_create(
@@ -121,13 +121,16 @@ extern bt_field_class_status bt_field_class_variant_append_option(
                bt_field_class *var_field_class,
                const char *name, bt_field_class *field_class);
 
-extern void bt_field_class_variant_borrow_option_by_index(
-               bt_field_class *variant_field_class, uint64_t index,
-               const char **name, bt_field_class **field_class);
+extern bt_field_class_variant_option *
+bt_field_class_variant_borrow_option_by_index(
+               bt_field_class *field_class, uint64_t index);
 
-extern
-bt_field_class *bt_field_class_variant_borrow_option_field_class_by_name(
-               bt_field_class *field_class, const char *name);
+extern bt_field_class_variant_option *
+bt_field_class_variant_borrow_option_by_name(
+               bt_field_class *field_class, char *name);
+
+extern bt_field_class *bt_field_class_variant_option_borrow_field_class(
+               bt_field_class_variant_option *option);
 
 #ifdef __cplusplus
 }
index 39f3f423a6c719216b90f31a7135b64ecb7d89fe..1805431c138d22f50c4549d2c1ca448a7e93096b 100644 (file)
@@ -95,6 +95,8 @@ typedef struct bt_field bt_field;
 typedef struct bt_field_class bt_field_class;
 typedef struct bt_field_class_signed_enumeration_mapping_ranges bt_field_class_signed_enumeration_mapping_ranges;
 typedef struct bt_field_class_unsigned_enumeration_mapping_ranges bt_field_class_unsigned_enumeration_mapping_ranges;
+typedef struct bt_field_class_structure_member bt_field_class_structure_member;
+typedef struct bt_field_class_variant_option bt_field_class_variant_option;
 typedef struct bt_field_path bt_field_path;
 typedef struct bt_graph bt_graph;
 typedef struct bt_message bt_message;
index 59a2c1f50ecf0d2c160662b65aff78f9aec0dd1a..baee77933b1a7f6c9ad2efc81c9a5fcfd0b1c612 100644 (file)
@@ -775,6 +775,12 @@ enum bt_field_class_status append_named_field_class_to_container_field_class(
        bt_object_get_no_null_check(fc);
        g_hash_table_insert(container_fc->name_to_index, named_fc->name->str,
                GUINT_TO_POINTER(container_fc->named_fcs->len - 1));
+
+       /*
+        * Freeze the field class, but not the named field class (the
+        * user can still modify it, if possible, until the container
+        * itself is frozen).
+        */
        bt_field_class_freeze(fc);
 
 end:
@@ -805,52 +811,47 @@ uint64_t bt_field_class_structure_get_member_count(
 }
 
 static
-void borrow_named_field_class_from_container_field_class_at_index(
+struct bt_named_field_class *
+borrow_named_field_class_from_container_field_class_at_index(
                struct bt_field_class_named_field_class_container *fc,
-               uint64_t index, const char **name,
-               struct bt_field_class **out_fc)
+               uint64_t index)
 {
-       struct bt_named_field_class *named_fc;
-
        BT_ASSERT(fc);
-       BT_ASSERT_PRE_NON_NULL(name, "Name");
-       BT_ASSERT_PRE_NON_NULL(out_fc, "Field class (output)");
        BT_ASSERT_PRE_VALID_INDEX(index, fc->named_fcs->len);
-       named_fc = BT_FIELD_CLASS_NAMED_FC_AT_INDEX(fc, index);
-       *name = named_fc->name->str;
-       *out_fc = named_fc->fc;
+       return BT_FIELD_CLASS_NAMED_FC_AT_INDEX(fc, index);
 }
 
-void bt_field_class_structure_borrow_member_by_index_const(
-               const struct bt_field_class *fc, uint64_t index,
-               const char **name, const struct bt_field_class **out_fc)
+const struct bt_field_class_structure_member *
+bt_field_class_structure_borrow_member_by_index_const(
+               const struct bt_field_class *fc, uint64_t index)
 {
        BT_ASSERT_PRE_NON_NULL(fc, "Field class");
        BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE,
                "Field class");
-       borrow_named_field_class_from_container_field_class_at_index(
-               (void *) fc, index, name, (void *) out_fc);
+       return (const void *)
+               borrow_named_field_class_from_container_field_class_at_index(
+                       (void *) fc, index);
 }
 
-void bt_field_class_structure_borrow_member_by_index(
-               struct bt_field_class *fc, uint64_t index,
-               const char **name, struct bt_field_class **out_fc)
+struct bt_field_class_structure_member *
+bt_field_class_structure_borrow_member_by_index(
+               struct bt_field_class *fc, uint64_t index)
 {
        BT_ASSERT_PRE_NON_NULL(fc, "Field class");
        BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE,
                "Field class");
-       borrow_named_field_class_from_container_field_class_at_index(
-               (void *) fc, index, name, out_fc);
+       return (void *)
+               borrow_named_field_class_from_container_field_class_at_index(
+                       (void *) fc, index);
 }
 
 static
-struct bt_field_class *
-borrow_field_class_from_container_field_class_by_name(
+struct bt_named_field_class *
+borrow_named_field_class_from_container_field_class_by_name(
                struct bt_field_class_named_field_class_container *fc,
                const char *name)
 {
-       struct bt_field_class *ret_fc = NULL;
-       struct bt_named_field_class *named_fc;
+       struct bt_named_field_class *named_fc = NULL;
        gpointer orig_key;
        gpointer value;
 
@@ -863,34 +864,64 @@ borrow_field_class_from_container_field_class_by_name(
 
        named_fc = BT_FIELD_CLASS_NAMED_FC_AT_INDEX(fc,
                GPOINTER_TO_UINT(value));
-       ret_fc = named_fc->fc;
 
 end:
-       return ret_fc;
+       return named_fc;
 }
 
-const struct bt_field_class *
+const struct bt_field_class_structure_member *
 bt_field_class_structure_borrow_member_field_class_by_name_const(
                const struct bt_field_class *fc, const char *name)
 {
        BT_ASSERT_PRE_NON_NULL(fc, "Field class");
        BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE,
                "Field class");
-       return borrow_field_class_from_container_field_class_by_name(
+       return (const void *)
+               borrow_named_field_class_from_container_field_class_by_name(
                        (void *) fc, name);
 }
 
-struct bt_field_class *
+struct bt_field_class_structure_member *
 bt_field_class_structure_borrow_member_field_class_by_name(
                struct bt_field_class *fc, const char *name)
 {
        BT_ASSERT_PRE_NON_NULL(fc, "Field class");
        BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE,
                "Field class");
-       return borrow_field_class_from_container_field_class_by_name(
+       return (void *)
+               borrow_named_field_class_from_container_field_class_by_name(
                        (void *) fc, name);
 }
 
+const char *bt_field_class_structure_member_get_name(
+               const struct bt_field_class_structure_member *member)
+{
+       const struct bt_named_field_class *named_fc = (const void *) member;
+
+       BT_ASSERT_PRE_NON_NULL(member, "Structure field class member");
+       return named_fc->name->str;
+}
+
+const struct bt_field_class *
+bt_field_class_structure_member_borrow_field_class_const(
+               const struct bt_field_class_structure_member *member)
+{
+       const struct bt_named_field_class *named_fc = (const void *) member;
+
+       BT_ASSERT_PRE_NON_NULL(member, "Structure field class member");
+       return named_fc->fc;
+}
+
+struct bt_field_class *
+bt_field_class_structure_member_borrow_field_class(
+               struct bt_field_class_structure_member *member)
+{
+       struct bt_named_field_class *named_fc = (void *) member;
+
+       BT_ASSERT_PRE_NON_NULL(member, "Structure field class member");
+       return named_fc->fc;
+}
+
 static
 void destroy_variant_field_class(struct bt_object *obj)
 {
@@ -964,24 +995,26 @@ enum bt_field_class_status bt_field_class_variant_append_option(
                name, option_fc);
 }
 
-const struct bt_field_class *
+const struct bt_field_class_variant_option *
 bt_field_class_variant_borrow_option_field_class_by_name_const(
                const struct bt_field_class *fc, const char *name)
 {
        BT_ASSERT_PRE_NON_NULL(fc, "Field class");
        BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_VARIANT, "Field class");
-       return borrow_field_class_from_container_field_class_by_name(
-               (void *) fc, name);
+       return (const void *)
+               borrow_named_field_class_from_container_field_class_by_name(
+                       (void *) fc, name);
 }
 
-struct bt_field_class *
+struct bt_field_class_variant_option *
 bt_field_class_variant_borrow_option_field_class_by_name(
                struct bt_field_class *fc, const char *name)
 {
        BT_ASSERT_PRE_NON_NULL(fc, "Field class");
        BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_VARIANT, "Field class");
-       return borrow_field_class_from_container_field_class_by_name(
-               (void *) fc, name);
+       return (void *)
+               borrow_named_field_class_from_container_field_class_by_name(
+                       (void *) fc, name);
 }
 
 uint64_t bt_field_class_variant_get_option_count(const struct bt_field_class *fc)
@@ -993,24 +1026,55 @@ uint64_t bt_field_class_variant_get_option_count(const struct bt_field_class *fc
        return (uint64_t) var_fc->common.named_fcs->len;
 }
 
-void bt_field_class_variant_borrow_option_by_index_const(
-               const struct bt_field_class *fc, uint64_t index,
-               const char **name, const struct bt_field_class **out_fc)
+const struct bt_field_class_variant_option *
+bt_field_class_variant_borrow_option_by_index_const(
+               const struct bt_field_class *fc, uint64_t index)
 {
        BT_ASSERT_PRE_NON_NULL(fc, "Field class");
        BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_VARIANT, "Field class");
-       borrow_named_field_class_from_container_field_class_at_index(
-               (void *) fc, index, name, (void *) out_fc);
+       return (const void *)
+               borrow_named_field_class_from_container_field_class_at_index(
+                       (void *) fc, index);
 }
 
-void bt_field_class_variant_borrow_option_by_index(
-               struct bt_field_class *fc, uint64_t index,
-               const char **name, struct bt_field_class **out_fc)
+struct bt_field_class_variant_option *
+bt_field_class_variant_borrow_option_by_index(
+               struct bt_field_class *fc, uint64_t index)
 {
        BT_ASSERT_PRE_NON_NULL(fc, "Field class");
        BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_VARIANT, "Field class");
-       borrow_named_field_class_from_container_field_class_at_index(
-               (void *) fc, index, name, out_fc);
+       return (void *)
+               borrow_named_field_class_from_container_field_class_at_index(
+                       (void *) fc, index);
+}
+
+const char *bt_field_class_variant_option_get_name(
+               const struct bt_field_class_variant_option *option)
+{
+       const struct bt_named_field_class *named_fc = (const void *) option;
+
+       BT_ASSERT_PRE_NON_NULL(option, "Variant field class option");
+       return named_fc->name->str;
+}
+
+const struct bt_field_class *
+bt_field_class_variant_option_borrow_field_class_const(
+               const struct bt_field_class_variant_option *option)
+{
+       const struct bt_named_field_class *named_fc = (const void *) option;
+
+       BT_ASSERT_PRE_NON_NULL(option, "Variant field class option");
+       return named_fc->fc;
+}
+
+struct bt_field_class *
+bt_field_class_variant_option_borrow_field_class(
+               struct bt_field_class_variant_option *option)
+{
+       struct bt_named_field_class *named_fc = (void *) option;
+
+       BT_ASSERT_PRE_NON_NULL(option, "Variant field class option");
+       return named_fc->fc;
 }
 
 const struct bt_field_path *
@@ -1219,14 +1283,46 @@ end:
 }
 
 BT_HIDDEN
-void _bt_field_class_freeze(const struct bt_field_class *fc)
+void _bt_field_class_freeze(const struct bt_field_class *c_fc)
 {
+       struct bt_field_class *fc = (void *) c_fc;
+
        /*
         * Element/member/option field classes are frozen when added to
         * their owner.
         */
        BT_ASSERT(fc);
-       ((struct bt_field_class *) fc)->frozen = true;
+       fc->frozen = true;
+
+       switch (fc->type) {
+       case BT_FIELD_CLASS_TYPE_STRUCTURE:
+       case BT_FIELD_CLASS_TYPE_VARIANT:
+       {
+               struct bt_field_class_named_field_class_container *container_fc =
+                       (void *) fc;
+               uint64_t i;
+
+               for (i = 0; i < container_fc->named_fcs->len; i++) {
+                       struct bt_named_field_class *named_fc =
+                               BT_FIELD_CLASS_NAMED_FC_AT_INDEX(
+                                       container_fc, i);
+
+                       bt_named_field_class_freeze(named_fc);
+               }
+
+               break;
+       }
+       default:
+               break;
+       }
+}
+
+BT_HIDDEN
+void _bt_named_field_class_freeze(const struct bt_named_field_class *named_fc)
+{
+       BT_ASSERT(named_fc);
+       ((struct bt_named_field_class *) named_fc)->frozen = true;
+       bt_field_class_freeze(named_fc->fc);
 }
 
 BT_HIDDEN
index 0d69b4cfc0738c36424fa98d0590aa303772d548..78f611cb54515cdf85f1f2ffa619ec2c8345222e 100644 (file)
@@ -190,7 +190,7 @@ void copy_field_content(const bt_field *in_field, bt_field *out_field)
                uint64_t i, nb_member_struct;
                const bt_field *in_member_field;
                bt_field *out_member_field;
-               const bt_field_class *in_field_class, *in_member_field_class;
+               const bt_field_class *in_field_class;
                const char *in_member_name;
 
                in_field_class = bt_field_borrow_class_const(in_field);
@@ -203,10 +203,13 @@ void copy_field_content(const bt_field *in_field, bt_field *out_field)
                 * the debug-info was added.
                 */
                for (i = 0; i < nb_member_struct; i++) {
-                       bt_field_class_structure_borrow_member_by_index_const(
-                                       in_field_class, i, &in_member_name,
-                                       &in_member_field_class);
+                       const bt_field_class_structure_member *member =
+                               bt_field_class_structure_borrow_member_by_index_const(
+                                       in_field_class, i);
 
+                       in_member_name =
+                               bt_field_class_structure_member_get_name(
+                                       member);
                        in_member_field =
                                bt_field_structure_borrow_member_field_by_name_const(
                                                in_field, in_member_name);
index b6326e964445a30d2201f3c2c5a5d513367be737..df6e26d1dbcadc4e711ae11bd2fe8c75c17747d5 100644 (file)
@@ -54,19 +54,28 @@ const bt_field_class *walk_field_path(const bt_field_path *fp,
        fp_index_count = bt_field_path_get_index_count(fp);
        curr_fc = fc;
        for (i = 0; i < fp_index_count; i++) {
-               const char *fc_name;
                bt_field_class_type fc_type = bt_field_class_get_type(curr_fc);
                uint64_t curr_index = bt_field_path_get_index_by_index(fp, i);
 
                switch (fc_type) {
                case BT_FIELD_CLASS_TYPE_STRUCTURE:
-                       bt_field_class_structure_borrow_member_by_index_const(
-                                       curr_fc, curr_index, &fc_name, &curr_fc);
+               {
+                       const bt_field_class_structure_member *member =
+                               bt_field_class_structure_borrow_member_by_index_const(
+                                       curr_fc, curr_index);
+                       curr_fc = bt_field_class_structure_member_borrow_field_class_const(
+                               member);
                        break;
+               }
                case BT_FIELD_CLASS_TYPE_VARIANT:
-                       bt_field_class_variant_borrow_option_by_index_const(
-                                       curr_fc, curr_index, &fc_name, &curr_fc);
+               {
+                       const bt_field_class_variant_option *option =
+                               bt_field_class_variant_borrow_option_by_index_const(
+                                       curr_fc, curr_index);
+                       curr_fc = bt_field_class_variant_option_borrow_field_class_const(
+                               option);
                        break;
+               }
                default:
                        abort();
                }
@@ -322,12 +331,16 @@ int field_class_structure_copy(
 
        /* Iterate over all the members of the struct. */
        for (i = 0; i < struct_member_count; i++) {
+               const bt_field_class_structure_member *member;
                const char *member_name;
                const bt_field_class *member_fc;
                bt_field_class *out_member_field_class;
 
-               bt_field_class_structure_borrow_member_by_index_const(
-                               in_field_class, i, &member_name, &member_fc);
+               member = bt_field_class_structure_borrow_member_by_index_const(
+                       in_field_class, i);
+               member_fc = bt_field_class_structure_member_borrow_field_class_const(
+                       member);
+               member_name = bt_field_class_structure_member_get_name(member);
                BT_LOGD("Copying structure field class's field: "
                        "index=%" PRId64 ", "
                        "member-fc-addr=%p, field-name=\"%s\"",
@@ -405,22 +418,25 @@ int field_class_variant_copy(
        variant_option_count =
                bt_field_class_variant_get_option_count(in_field_class);
        for (i = 0; i < variant_option_count; i++) {
-               const bt_field_class *option;
+               const bt_field_class *option_fc;
                const char *option_name;
                bt_field_class *out_option_field_class;
                bt_field_class_status status;
+               const bt_field_class_variant_option *option;
 
-               bt_field_class_variant_borrow_option_by_index_const(in_field_class,
-                               i, &option_name, &option);
-
+               option = bt_field_class_variant_borrow_option_by_index_const(
+                       in_field_class, i);
+               option_fc = bt_field_class_variant_option_borrow_field_class_const(
+                       option);
+               option_name = bt_field_class_variant_option_get_name(option);
                out_option_field_class = create_field_class_copy_internal(
-                               md_maps, option);
+                               md_maps, option_fc);
                if (!out_option_field_class) {
                        BT_LOGE_STR("Cannot copy field class.");
                        ret = -1;
                        goto error;
                }
-               ret = copy_field_class_content_internal(md_maps, option,
+               ret = copy_field_class_content_internal(md_maps, option_fc,
                                out_option_field_class);
                if (ret) {
                        BT_LOGE_STR("Error copying content of option variant "
index 9d8a8c9cc0c73035f4a9ea6550581985cf596350..d9c5fa50a35faf3ac3a0aa2a38c98b17a71484cf 100644 (file)
@@ -55,17 +55,18 @@ BT_HIDDEN
 bt_bool is_event_common_ctx_dbg_info_compatible(const bt_field_class *in_field_class,
                const char *debug_info_field_class_name)
 {
-       const bt_field_class *ip_fc, *vpid_fc, *debug_info_fc;
+       const bt_field_class_structure_member *member;
+       const bt_field_class *ip_fc, *vpid_fc;
        bt_bool match = BT_FALSE;
 
        /*
         * If the debug info field is already present in the event common
         * context. Do not try to add it.
         */
-       debug_info_fc =
-               bt_field_class_structure_borrow_member_field_class_by_name_const(
+       member =
+               bt_field_class_structure_borrow_member_by_name_const(
                        in_field_class, debug_info_field_class_name);
-       if (debug_info_fc) {
+       if (member) {
                goto end;
        }
 
@@ -73,12 +74,14 @@ bt_bool is_event_common_ctx_dbg_info_compatible(const bt_field_class *in_field_c
         * Verify that the ip and vpid field are present and of the right field
         * class.
         */
-       ip_fc = bt_field_class_structure_borrow_member_field_class_by_name_const(
+       member = bt_field_class_structure_borrow_member_by_name_const(
                        in_field_class, IP_FIELD_NAME);
-       if (!ip_fc) {
+       if (!member) {
                goto end;
        }
 
+       ip_fc = bt_field_class_structure_member_borrow_field_class_const(
+               member);
        if (bt_field_class_get_type(ip_fc) !=
                        BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER) {
                match = BT_FALSE;
@@ -89,12 +92,15 @@ bt_bool is_event_common_ctx_dbg_info_compatible(const bt_field_class *in_field_c
                goto end;
        }
 
-       vpid_fc = bt_field_class_structure_borrow_member_field_class_by_name_const(
+       member = bt_field_class_structure_borrow_member_by_name_const(
                        in_field_class, VPID_FIELD_NAME);
-       if (!vpid_fc) {
+       if (!member) {
                goto end;
        }
 
+       vpid_fc = bt_field_class_structure_member_borrow_field_class_const(
+               member);
+
        if (bt_field_class_get_type(vpid_fc) !=
                        BT_FIELD_CLASS_TYPE_SIGNED_INTEGER) {
                goto end;
@@ -105,6 +111,7 @@ bt_bool is_event_common_ctx_dbg_info_compatible(const bt_field_class *in_field_c
        }
 
        match = BT_TRUE;
+
 end:
        return match;
 }
index 914ae4c2d1b3b93745741974ce7c376e7dca3b58..0d69b9bcd1f9018869330f85aaddd29d87b90060 100644 (file)
@@ -775,7 +775,7 @@ int print_struct_field(struct pretty_component *pretty,
        int ret = 0;
        const char *field_name;
        const bt_field *field = NULL;
-       const bt_field_class *field_class = NULL;;
+       const bt_field_class_structure_member *member;
 
        field = bt_field_structure_borrow_member_field_by_index_const(_struct, i);
        if (!field) {
@@ -783,8 +783,9 @@ int print_struct_field(struct pretty_component *pretty,
                goto end;
        }
 
-       bt_field_class_structure_borrow_member_by_index_const(struct_class, i,
-               &field_name, &field_class);
+       member = bt_field_class_structure_borrow_member_by_index_const(
+               struct_class, i);
+       field_name = bt_field_class_structure_member_get_name(member);
 
        if (filter_fields && !filter_field_name(pretty, field_name,
                                filter_fields, filter_array_len)) {
This page took 0.036236 seconds and 4 git commands to generate.