From 2f2d8e05490c5f008df8838ff6b8cf7bfcbd9652 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Sun, 19 Oct 2014 14:45:16 -0400 Subject: [PATCH] Add an alias name attribute and accessor to CTF IR field type MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- formats/ctf/ir/event-types.c | 45 ++++++++++++++++--- .../babeltrace/ctf-ir/event-types-internal.h | 1 + include/babeltrace/ctf-ir/event-types.h | 15 +++++++ 3 files changed, 56 insertions(+), 5 deletions(-) diff --git a/formats/ctf/ir/event-types.c b/formats/ctf/ir/event-types.c index bed6c0ad..41ecb5bd 100644 --- a/formats/ctf/ir/event-types.c +++ b/formats/ctf/ir/event-types.c @@ -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 diff --git a/include/babeltrace/ctf-ir/event-types-internal.h b/include/babeltrace/ctf-ir/event-types-internal.h index 58a94045..dd80bdce 100644 --- a/include/babeltrace/ctf-ir/event-types-internal.h +++ b/include/babeltrace/ctf-ir/event-types-internal.h @@ -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; /* diff --git a/include/babeltrace/ctf-ir/event-types.h b/include/babeltrace/ctf-ir/event-types.h index 96200ce4..18929eaa 100644 --- a/include/babeltrace/ctf-ir/event-types.h +++ b/include/babeltrace/ctf-ir/event-types.h @@ -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. -- 2.34.1