From c3c35de4da25b506dd423e74706ee302cc0d7e39 Mon Sep 17 00:00:00 2001 From: Julien Desfossez Date: Tue, 14 Feb 2017 12:31:28 -0500 Subject: [PATCH] Allow to set the size of an integer type MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Add bt_ctf_field_type_integer_set_size to the API. Signed-off-by: Julien Desfossez Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- include/babeltrace/ctf-ir/field-types.h | 35 +++++++++++++++++++++++-- lib/ctf-ir/field-types.c | 19 ++++++++++++++ 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/include/babeltrace/ctf-ir/field-types.h b/include/babeltrace/ctf-ir/field-types.h index be004dea..b7e30545 100644 --- a/include/babeltrace/ctf-ir/field-types.h +++ b/include/babeltrace/ctf-ir/field-types.h @@ -31,6 +31,7 @@ */ #include +#include #ifdef __cplusplus extern "C" { @@ -702,7 +703,7 @@ An integer field type has the following properties: integer fields Specified at creation bt_ctf_field_type_integer_get_size() - None: specified at creation (bt_ctf_field_type_integer_create()) + bt_ctf_field_type_integer_set_size() Signedness of the described integer fields @@ -764,6 +765,10 @@ enum bt_ctf_integer_base { @brief Creates a default @intft with \p size bits as the storage size of the @intfields it describes. +You can change the storage size of the integer fields described by +the created integer field type later with +bt_ctf_field_type_integer_set_size(). + @param[in] size Storage size (bits) of the described integer fields. @returns Created integer field type, or \c NULL on error. @@ -787,10 +792,36 @@ extern struct bt_ctf_field_type *bt_ctf_field_type_integer_create( @prenotnull{int_field_type} @preisintft{int_field_type} @postrefcountsame{int_field_type} + +@sa bt_ctf_field_type_integer_set_size(): Sets the storage size of the + integer fields described by a given integer field type. */ extern int bt_ctf_field_type_integer_get_size( struct bt_ctf_field_type *int_field_type); +/** +@brief Sets the storage size, in bits, of the @intfields described by + the @intft \p int_field_type. + +@param[in] int_field_type Integer field type which describes the + integer fields of which to set the + storage size. +@param[in] size Storage size (bits) of the integer fields + described by \p int_field_type. +@returns 0 on success, or a negative value on error. + +@prenotnull{int_field_type} +@preisintft{int_field_type} +@prehot{int_field_type} +@pre \p size is greater than 0 and lesser than or equal to 64. +@postrefcountsame{int_field_type} + +@sa bt_ctf_field_type_integer_get_size(): Returns the storage size of + the integer fields described by a given integer field type. +*/ +extern int bt_ctf_field_type_integer_set_size( + struct bt_ctf_field_type *int_field_type, size_t size); + /** @brief Returns whether or not the @intfields described by the @intft \p int_field_type are signed. @@ -829,7 +860,7 @@ extern int bt_ctf_field_type_integer_get_signed( @preisintft{int_field_type} @prehot{int_field_type} @pre \p is_signed is 0 or 1. -@postrefcountsame{event_class} +@postrefcountsame{int_field_type} @sa bt_ctf_field_type_integer_get_signed(): Returns the signedness of the integer fields described by a given integer field type. diff --git a/lib/ctf-ir/field-types.c b/lib/ctf-ir/field-types.c index 28459821..aac43002 100644 --- a/lib/ctf-ir/field-types.c +++ b/lib/ctf-ir/field-types.c @@ -842,6 +842,25 @@ end: return ret; } +int bt_ctf_field_type_integer_set_size(struct bt_ctf_field_type *type, + size_t size) +{ + int ret = 0; + struct bt_ctf_field_type_integer *integer; + + if (!type || type->frozen || + type->id != BT_CTF_TYPE_ID_INTEGER || + !size || size > 64) { + ret = -1; + goto end; + } + + integer = container_of(type, struct bt_ctf_field_type_integer, parent); + integer->size = size; +end: + return ret; +} + enum bt_ctf_integer_base bt_ctf_field_type_integer_get_base( struct bt_ctf_field_type *type) { -- 2.34.1