bt_ctf_field_type_get_byte_order(): support enum FT
[babeltrace.git] / formats / ctf / ir / field-types.c
index 4f2bc03449bd438c5d3f648907aab4c66c9d6dac..c9c424ea76a3e901c80453a06a780ab919f952f6 100644 (file)
@@ -844,7 +844,7 @@ int bt_ctf_field_type_integer_set_mapped_clock(
        struct bt_ctf_field_type_integer *integer;
        int ret = 0;
 
-       if (!type || type->frozen) {
+       if (!type || type->frozen || !bt_ctf_clock_is_valid(clock)) {
                ret = -1;
                goto end;
        }
@@ -1410,9 +1410,14 @@ int bt_ctf_field_type_structure_add_field(struct bt_ctf_field_type *type,
        int ret = 0;
        struct bt_ctf_field_type_structure *structure;
 
+       /*
+        * TODO: check that `field_type` does not contain `type`,
+        *       recursively.
+        */
        if (!type || !field_type || type->frozen ||
                bt_ctf_validate_identifier(field_name) ||
-               (type->declaration->id != BT_CTF_TYPE_ID_STRUCT)) {
+               (type->declaration->id != BT_CTF_TYPE_ID_STRUCT) ||
+               type == field_type) {
                ret = -1;
                goto end;
        }
@@ -1615,9 +1620,14 @@ int bt_ctf_field_type_variant_add_field(struct bt_ctf_field_type *type,
        struct bt_ctf_field_type_variant *variant;
        GQuark field_name_quark = g_quark_from_string(field_name);
 
+       /*
+        * TODO: check that `field_type` does not contain `type`,
+        *       recursively.
+        */
        if (!type || !field_type || type->frozen ||
                bt_ctf_validate_identifier(field_name) ||
-               (type->declaration->id != BT_CTF_TYPE_ID_VARIANT)) {
+               (type->declaration->id != BT_CTF_TYPE_ID_VARIANT) ||
+               type == field_type) {
                ret = -1;
                goto end;
        }
@@ -2140,6 +2150,13 @@ enum bt_ctf_byte_order bt_ctf_field_type_get_byte_order(
                ret = integer->user_byte_order;
                break;
        }
+       case BT_CTF_TYPE_ID_ENUM:
+       {
+               struct bt_ctf_field_type_enumeration *enum_ft = container_of(
+                       type, struct bt_ctf_field_type_enumeration, parent);
+               ret = bt_ctf_field_type_get_byte_order(enum_ft->container);
+               break;
+       }
        case BT_CTF_TYPE_ID_FLOAT:
        {
                struct bt_ctf_field_type_floating_point *floating_point =
@@ -2372,7 +2389,6 @@ void bt_ctf_field_type_set_native_byte_order(struct bt_ctf_field_type *type,
        }
 }
 
-BT_HIDDEN
 struct bt_ctf_field_type *bt_ctf_field_type_copy(struct bt_ctf_field_type *type)
 {
        struct bt_ctf_field_type *copy = NULL;
This page took 0.025133 seconds and 4 git commands to generate.