Add an alias name attribute and accessor to CTF IR field type
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Sun, 19 Oct 2014 18:45:16 +0000 (14:45 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 20 Oct 2014 12:05:24 +0000 (08:05 -0400)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
formats/ctf/ir/event-types.c
include/babeltrace/ctf-ir/event-types-internal.h
include/babeltrace/ctf-ir/event-types.h

index bed6c0addef89d2702862be152961f99154de648..41ecb5bd8cc34d7a3b79d14c30c3db7f23b6e38d 100644 (file)
@@ -49,6 +49,8 @@ struct range_overlap_query {
        GQuark mapping_name;
 };
 
+static
+void bt_ctf_field_type_destroy(struct bt_ctf_ref *);
 static
 void bt_ctf_field_type_integer_destroy(struct bt_ctf_ref *);
 static
@@ -278,6 +280,29 @@ end:
        return ret;
 }
 
+static
+void bt_ctf_field_type_destroy(struct bt_ctf_ref *ref)
+{
+       struct bt_ctf_field_type *type;
+       enum ctf_type_id type_id;
+
+       if (!ref) {
+               return;
+       }
+
+       type = container_of(ref, struct bt_ctf_field_type, ref_count);
+       type_id = type->declaration->id;
+       if (type_id <= CTF_TYPE_UNKNOWN ||
+               type_id >= NR_CTF_TYPES) {
+               return;
+       }
+
+       if (type->alias_name) {
+               g_string_free(type->alias_name, TRUE);
+       }
+       type_destroy_funcs[type_id](ref);
+}
+
 BT_HIDDEN
 int bt_ctf_field_type_validate(struct bt_ctf_field_type *type)
 {
@@ -1620,6 +1645,20 @@ enum ctf_type_id bt_ctf_field_type_get_type_id(
        return type->declaration->id;
 }
 
+const char *bt_ctf_field_type_get_alias_name(
+               struct bt_ctf_field_type *type)
+{
+       const char *name = NULL;
+
+       if (!type || !type->alias_name) {
+               goto end;
+       }
+
+       name = type->alias_name->str;
+end:
+       return name;
+}
+
 void bt_ctf_field_type_get(struct bt_ctf_field_type *type)
 {
        if (!type) {
@@ -1631,15 +1670,11 @@ void bt_ctf_field_type_get(struct bt_ctf_field_type *type)
 
 void bt_ctf_field_type_put(struct bt_ctf_field_type *type)
 {
-       enum ctf_type_id type_id;
-
        if (!type) {
                return;
        }
 
-       type_id = type->declaration->id;
-       assert(type_id > CTF_TYPE_UNKNOWN && type_id < NR_CTF_TYPES);
-       bt_ctf_ref_put(&type->ref_count, type_destroy_funcs[type_id]);
+       bt_ctf_ref_put(&type->ref_count, bt_ctf_field_type_destroy);
 }
 
 BT_HIDDEN
index 58a94045a034cf9384d5d9372c073652283cb475..dd80bdceb89026560318236b3eaed7286800c9b3 100644 (file)
@@ -44,6 +44,7 @@ typedef int(*type_serialize_func)(struct bt_ctf_field_type *,
 struct bt_ctf_field_type {
        struct bt_ctf_ref ref_count;
        struct bt_declaration *declaration;
+       GString *alias_name;
        type_freeze_func freeze;
        type_serialize_func serialize;
        /*
index 96200ce42d2d06d996b6ede6483345ac887abf55..18929eaa4ac45945fa8a886c1a0983ede553e951 100644 (file)
@@ -718,6 +718,21 @@ extern int bt_ctf_field_type_set_byte_order(struct bt_ctf_field_type *type,
 extern enum ctf_type_id bt_ctf_field_type_get_type_id(
                struct bt_ctf_field_type *type);
 
+/*
+ * bt_ctf_field_type_get_alias_nameL get a field type's alias name
+ *
+ * A type's alias name is set if it was resolved from a typedef or
+ * typealias. Note that types that are resolved from a ypealias or
+ * typedef are distinct from the underlying type and can't be compared
+ * pointer-wise.
+ *
+ * @param type Field type.
+ *
+ * Returns a field type's alias name, NULL on error.
+ */
+extern const char *bt_ctf_field_type_get_alias_name(
+               struct bt_ctf_field_type *type);
+
 /*
  * bt_ctf_field_type_get and bt_ctf_field_type_put: increment and decrement
  * the field type's reference count.
This page took 0.027708 seconds and 4 git commands to generate.