From 626e93aa41c9a6b3f70538aad04a20df07b36b73 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Fri, 31 Jul 2015 10:11:58 -0400 Subject: [PATCH] ir: add bt_ctf_field_type_sequence/array_set_element_type() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- formats/ctf/ir/event-types.c | 52 +++++++++++++++++++ .../babeltrace/ctf-ir/event-types-internal.h | 8 +++ 2 files changed, 60 insertions(+) diff --git a/formats/ctf/ir/event-types.c b/formats/ctf/ir/event-types.c index 91104860..61c0404d 100644 --- a/formats/ctf/ir/event-types.c +++ b/formats/ctf/ir/event-types.c @@ -1545,6 +1545,32 @@ end: return ret; } +BT_HIDDEN +int bt_ctf_field_type_array_set_element_type(struct bt_ctf_field_type *type, + struct bt_ctf_field_type *element_type) +{ + int ret = 0; + struct bt_ctf_field_type_array *array; + + if (!type || !element_type || + (type->declaration->id != CTF_TYPE_ARRAY)) { + ret = -1; + goto end; + } + + array = container_of(type, struct bt_ctf_field_type_array, parent); + + if (array->element_type) { + BT_PUT(array->element_type); + } + + array->element_type = element_type; + bt_get(array->element_type); + +end: + return ret; +} + int64_t bt_ctf_field_type_array_get_length(struct bt_ctf_field_type *type) { int64_t ret; @@ -1606,6 +1632,32 @@ end: return ret; } +BT_HIDDEN +int bt_ctf_field_type_sequence_set_element_type(struct bt_ctf_field_type *type, + struct bt_ctf_field_type *element_type) +{ + int ret = 0; + struct bt_ctf_field_type_sequence *sequence; + + if (!type || !element_type || + (type->declaration->id != CTF_TYPE_SEQUENCE)) { + ret = -1; + goto end; + } + + sequence = container_of(type, struct bt_ctf_field_type_sequence, parent); + + if (sequence->element_type) { + BT_PUT(sequence->element_type); + } + + sequence->element_type = element_type; + bt_get(sequence->element_type); + +end: + return ret; +} + const char *bt_ctf_field_type_sequence_get_length_field_name( struct bt_ctf_field_type *type) { diff --git a/include/babeltrace/ctf-ir/event-types-internal.h b/include/babeltrace/ctf-ir/event-types-internal.h index ed085dab..1dea88d0 100644 --- a/include/babeltrace/ctf-ir/event-types-internal.h +++ b/include/babeltrace/ctf-ir/event-types-internal.h @@ -238,4 +238,12 @@ int bt_ctf_field_type_variant_set_field_index( struct bt_ctf_field_type *variant, struct bt_ctf_field_type *field, int index); +BT_HIDDEN +int bt_ctf_field_type_array_set_element_type(struct bt_ctf_field_type *array, + struct bt_ctf_field_type *element_type); + +BT_HIDDEN +int bt_ctf_field_type_sequence_set_element_type(struct bt_ctf_field_type *array, + struct bt_ctf_field_type *element_type); + #endif /* BABELTRACE_CTF_IR_EVENT_TYPES_INTERNAL_H */ -- 2.34.1