From: Jérémie Galarneau Date: Mon, 11 May 2015 21:31:06 +0000 (-0400) Subject: ir: add bt_ctf_field_type_variant_set_tag() X-Git-Tag: v2.0.0-pre1~1245 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=3f39933a0aa593a6c38039d578ac2ade9c1e1374 ir: add bt_ctf_field_type_variant_set_tag() Signed-off-by: Jérémie Galarneau --- diff --git a/formats/ctf/ir/event-types.c b/formats/ctf/ir/event-types.c index 316efa78..78d0fa0d 100644 --- a/formats/ctf/ir/event-types.c +++ b/formats/ctf/ir/event-types.c @@ -2116,6 +2116,32 @@ int bt_ctf_field_type_variant_set_tag_field_path(struct bt_ctf_field_type *type, end: return ret; } + +BT_HIDDEN +int bt_ctf_field_type_variant_set_tag(struct bt_ctf_field_type *type, + struct bt_ctf_field_type *tag) +{ + int ret = 0; + struct bt_ctf_field_type_variant *variant; + + if (!type || !tag || type->frozen || + bt_ctf_field_type_get_type_id(tag) != CTF_TYPE_ENUM) { + ret = -1; + goto end; + } + + variant = container_of(type, struct bt_ctf_field_type_variant, + parent); + bt_ctf_field_type_get(tag); + if (variant->tag) { + bt_ctf_field_type_put(&variant->tag->parent); + } + variant->tag = container_of(tag, struct bt_ctf_field_type_enumeration, + parent); +end: + return ret; +} + static void bt_ctf_field_type_integer_destroy(struct bt_ctf_ref *ref) { diff --git a/include/babeltrace/ctf-ir/event-types-internal.h b/include/babeltrace/ctf-ir/event-types-internal.h index 6078c345..48ead485 100644 --- a/include/babeltrace/ctf-ir/event-types-internal.h +++ b/include/babeltrace/ctf-ir/event-types-internal.h @@ -213,4 +213,9 @@ int bt_ctf_field_type_sequence_set_length_field_path( BT_HIDDEN int bt_ctf_field_type_variant_set_tag_field_path(struct bt_ctf_field_type *type, struct bt_ctf_field_path *path); + +BT_HIDDEN +int bt_ctf_field_type_variant_set_tag(struct bt_ctf_field_type *type, + struct bt_ctf_field_type *tag); + #endif /* BABELTRACE_CTF_IR_EVENT_TYPES_INTERNAL_H */