From 2e8876d36d8df5011071725df6a2f80861817434 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Tue, 13 Feb 2018 17:17:31 -0500 Subject: [PATCH] lib: add internal bt_field_sequence_get_int_length() This new internal helper returns a sequence field's length as an `int64_t` value instead of returning the integer field. Returns a negative value on error or if the sequence fields's length field is not set. Signed-off-by: Philippe Proulx --- include/babeltrace/ctf-ir/fields-internal.h | 3 +++ lib/ctf-ir/fields.c | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/include/babeltrace/ctf-ir/fields-internal.h b/include/babeltrace/ctf-ir/fields-internal.h index 43e79b72..6c25b26c 100644 --- a/include/babeltrace/ctf-ir/fields-internal.h +++ b/include/babeltrace/ctf-ir/fields-internal.h @@ -102,4 +102,7 @@ int bt_field_serialize(struct bt_field *field, BT_HIDDEN void bt_field_freeze(struct bt_field *field); +BT_HIDDEN +int64_t bt_field_sequence_get_int_length(struct bt_field *field); + #endif /* BABELTRACE_CTF_IR_FIELDS_INTERNAL_H */ diff --git a/lib/ctf-ir/fields.c b/lib/ctf-ir/fields.c index 1525934e..0fe5630e 100644 --- a/lib/ctf-ir/fields.c +++ b/lib/ctf-ir/fields.c @@ -406,6 +406,27 @@ bt_bool bt_field_is_variant(struct bt_field *field) return bt_field_get_type_id(field) == BT_FIELD_TYPE_ID_VARIANT; } +BT_HIDDEN +int64_t bt_field_sequence_get_int_length(struct bt_field *field) +{ + struct bt_field_sequence *sequence; + int64_t ret; + + assert(field); + assert(bt_field_type_get_type_id(field->type) == + BT_FIELD_TYPE_ID_SEQUENCE); + sequence = container_of(field, struct bt_field_sequence, parent); + if (!sequence->length) { + ret = -1; + goto end; + } + + ret = (int64_t) sequence->elements->len; + +end: + return ret; +} + struct bt_field *bt_field_sequence_get_length( struct bt_field *field) { -- 2.34.1