Allow to set the size of an integer type
authorJulien Desfossez <jdesfossez@efficios.com>
Tue, 14 Feb 2017 17:31:28 +0000 (12:31 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sun, 28 May 2017 16:57:39 +0000 (12:57 -0400)
Add bt_ctf_field_type_integer_set_size to the API.

Signed-off-by: Julien Desfossez <jdesfossez@efficios.com>
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
include/babeltrace/ctf-ir/field-types.h
lib/ctf-ir/field-types.c

index be004deaa7477c7341169c5395d012f4810b82df..b7e305456dabe993b27fad7b011471d112b37ae4 100644 (file)
@@ -31,6 +31,7 @@
  */
 
 #include <stdint.h>
+#include <stddef.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -702,7 +703,7 @@ An integer field type has the following properties:
         integer fields
     <td>Specified at creation
     <td>bt_ctf_field_type_integer_get_size()
-    <td>None: specified at creation (bt_ctf_field_type_integer_create())
+    <td>bt_ctf_field_type_integer_set_size()
   </tr>
   <tr>
     <td><strong>Signedness</strong> 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.
index 284598212f83bf51e9ea097b163e253dcf6c7ee4..aac430024a7c9f19951cd537ddf76fc11f49a9d5 100644 (file)
@@ -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)
 {
This page took 0.028105 seconds and 4 git commands to generate.