Fix: Field types native byte order refers to the trace
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 4 Feb 2015 20:38:06 +0000 (15:38 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 4 Feb 2015 20:38:06 +0000 (15:38 -0500)
Following a misunderstanding of the CTF specification, the native
byte order was implemented as meaning the host's endianness. It should
refer to the Trace's endianness.

This modification ensures that stream classes, event classes and field
types correctly inherit the trace's endianness when "native" is used.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
13 files changed:
bindings/python/babeltrace.i.in
formats/ctf/ir/event-types.c
formats/ctf/ir/event.c
formats/ctf/ir/stream-class.c
formats/ctf/ir/trace.c
include/babeltrace/ctf-ir/event-internal.h
include/babeltrace/ctf-ir/event-types-internal.h
include/babeltrace/ctf-ir/event-types.h
include/babeltrace/ctf-ir/stream-class-internal.h
include/babeltrace/ctf-ir/trace-internal.h
include/babeltrace/ctf-ir/trace.h
include/babeltrace/ctf-writer/writer.h
include/babeltrace/types.h

index 2dd77a549cf9694edb1a95dcd9ed51df6fefc540..d255f766a5c8f718b2eafd339fc0f929e7396d03 100644 (file)
@@ -3190,7 +3190,7 @@ class CTFWriter:
 
         """
                Set the trace's byte order. Must be a constant from the ByteOrder
-               class. Defaults to BYTE_ORDER_NATIVE, the host machine's endianness.
+               class. Defaults to the host machine's endianness.
                """
         @byte_order.setter
         def byte_order(self, byte_order):
index a57aaf5a5c5556c5be12204afc9b2c9e705b8ff4..c24ef93fc5a7c33b88a5c23c155260d863811d70 100644 (file)
@@ -150,19 +150,41 @@ type_serialize_func const type_serialize_funcs[] = {
 
 static
 void bt_ctf_field_type_integer_set_byte_order(struct bt_ctf_field_type *,
-               int byte_order);
+               int byte_order, int set_native);
+static
+void bt_ctf_field_type_enumeration_set_byte_order(struct bt_ctf_field_type *,
+               int byte_order, int set_native);
 static
 void bt_ctf_field_type_floating_point_set_byte_order(
-               struct bt_ctf_field_type *, int byte_order);
+               struct bt_ctf_field_type *, int byte_order, int set_native);
+static
+void bt_ctf_field_type_structure_set_byte_order(struct bt_ctf_field_type *,
+               int byte_order, int set_native);
+static
+void bt_ctf_field_type_variant_set_byte_order(struct bt_ctf_field_type *,
+               int byte_order, int set_native);
+static
+void bt_ctf_field_type_array_set_byte_order(struct bt_ctf_field_type *,
+               int byte_order, int set_native);
+static
+void bt_ctf_field_type_sequence_set_byte_order(struct bt_ctf_field_type *,
+               int byte_order, int set_native);
 
+/* The set_native flag only set the byte order if it is set to native */
 static
 void (* const set_byte_order_funcs[])(struct bt_ctf_field_type *,
-       int) = {
-       [CTF_TYPE_INTEGER] =
-               bt_ctf_field_type_integer_set_byte_order,
+               int byte_order, int set_native) = {
+       [CTF_TYPE_INTEGER] = bt_ctf_field_type_integer_set_byte_order,
+       [CTF_TYPE_ENUM] =
+               bt_ctf_field_type_enumeration_set_byte_order,
        [CTF_TYPE_FLOAT] =
                bt_ctf_field_type_floating_point_set_byte_order,
-       [CTF_TYPE_ENUM ... CTF_TYPE_SEQUENCE] = NULL,
+       [CTF_TYPE_STRUCT] =
+               bt_ctf_field_type_structure_set_byte_order,
+       [CTF_TYPE_VARIANT] = bt_ctf_field_type_variant_set_byte_order,
+       [CTF_TYPE_ARRAY] = bt_ctf_field_type_array_set_byte_order,
+       [CTF_TYPE_SEQUENCE] = bt_ctf_field_type_sequence_set_byte_order,
+       [CTF_TYPE_STRING] = NULL,
 };
 
 static
@@ -1016,10 +1038,10 @@ struct bt_ctf_field_type *bt_ctf_field_type_structure_create(void)
 
        structure->parent.declaration = &structure->declaration.p;
        structure->parent.declaration->id = CTF_TYPE_STRUCT;
-       bt_ctf_field_type_init(&structure->parent);
        structure->fields = g_ptr_array_new_with_free_func(
                (GDestroyNotify)destroy_structure_field);
        structure->field_name_to_index = g_hash_table_new(NULL, NULL);
+       bt_ctf_field_type_init(&structure->parent);
        return &structure->parent;
 error:
        return NULL;
@@ -1154,13 +1176,13 @@ struct bt_ctf_field_type *bt_ctf_field_type_variant_create(
        variant->parent.declaration = &variant->declaration.p;
        variant->parent.declaration->id = CTF_TYPE_VARIANT;
        variant->tag_name = g_string_new(tag_name);
-       bt_ctf_field_type_init(&variant->parent);
        variant->field_name_to_index = g_hash_table_new(NULL, NULL);
        variant->fields = g_ptr_array_new_with_free_func(
                (GDestroyNotify)destroy_structure_field);
        bt_ctf_field_type_get(enum_tag);
        variant->tag = container_of(enum_tag,
                struct bt_ctf_field_type_enumeration, parent);
+       bt_ctf_field_type_init(&variant->parent);
        return &variant->parent;
 error:
        return NULL;
@@ -1358,10 +1380,11 @@ struct bt_ctf_field_type *bt_ctf_field_type_array_create(
 
        array->parent.declaration = &array->declaration.p;
        array->parent.declaration->id = CTF_TYPE_ARRAY;
-       bt_ctf_field_type_init(&array->parent);
+
        bt_ctf_field_type_get(element_type);
        array->element_type = element_type;
        array->length = length;
+       bt_ctf_field_type_init(&array->parent);
        array->parent.declaration->alignment =
                element_type->declaration->alignment;
        return &array->parent;
@@ -1420,10 +1443,10 @@ struct bt_ctf_field_type *bt_ctf_field_type_sequence_create(
 
        sequence->parent.declaration = &sequence->declaration.p;
        sequence->parent.declaration->id = CTF_TYPE_SEQUENCE;
-       bt_ctf_field_type_init(&sequence->parent);
        bt_ctf_field_type_get(element_type);
        sequence->element_type = element_type;
        sequence->length_field_name = g_string_new(length_field_name);
+       bt_ctf_field_type_init(&sequence->parent);
        sequence->parent.declaration->alignment =
                element_type->declaration->alignment;
        return &sequence->parent;
@@ -1560,6 +1583,7 @@ enum bt_ctf_byte_order bt_ctf_field_type_get_byte_order(
                struct bt_ctf_field_type *type)
 {
        enum bt_ctf_byte_order ret = BT_CTF_BYTE_ORDER_UNKNOWN;
+       int internal_byte_order = -1;
 
        if (!type) {
                goto end;
@@ -1570,9 +1594,7 @@ enum bt_ctf_byte_order bt_ctf_field_type_get_byte_order(
        {
                struct bt_ctf_field_type_integer *integer = container_of(
                        type, struct bt_ctf_field_type_integer, parent);
-               ret = integer->declaration.byte_order == LITTLE_ENDIAN ?
-                       BT_CTF_BYTE_ORDER_LITTLE_ENDIAN :
-                       BT_CTF_BYTE_ORDER_BIG_ENDIAN;
+               internal_byte_order = integer->declaration.byte_order;
                break;
        }
        case CTF_TYPE_FLOAT:
@@ -1581,13 +1603,25 @@ enum bt_ctf_byte_order bt_ctf_field_type_get_byte_order(
                        container_of(type,
                                struct bt_ctf_field_type_floating_point,
                                parent);
-               ret = floating_point->declaration.byte_order == LITTLE_ENDIAN ?
-                       BT_CTF_BYTE_ORDER_LITTLE_ENDIAN :
-                       BT_CTF_BYTE_ORDER_BIG_ENDIAN;
+               internal_byte_order = floating_point->declaration.byte_order;
                break;
        }
        default:
+               goto end;
+       }
+
+       switch (internal_byte_order) {
+       case LITTLE_ENDIAN:
+               ret = BT_CTF_BYTE_ORDER_LITTLE_ENDIAN;
                break;
+       case BIG_ENDIAN:
+               ret = BT_CTF_BYTE_ORDER_BIG_ENDIAN;
+               break;
+       case 0:
+               ret = BT_CTF_BYTE_ORDER_NATIVE;
+               break;
+       default:
+               ret = BT_CTF_BYTE_ORDER_UNKNOWN;
        }
 end:
        return ret;
@@ -1608,8 +1642,8 @@ int bt_ctf_field_type_set_byte_order(struct bt_ctf_field_type *type,
        type_id = type->declaration->id;
        switch (byte_order) {
        case BT_CTF_BYTE_ORDER_NATIVE:
-               internal_byte_order = (G_BYTE_ORDER == G_LITTLE_ENDIAN ?
-                       LITTLE_ENDIAN : BIG_ENDIAN);
+               /* Leave unset. Will be initialized by parent. */
+               internal_byte_order = 0;
                break;
        case BT_CTF_BYTE_ORDER_LITTLE_ENDIAN:
                internal_byte_order = LITTLE_ENDIAN;
@@ -1624,7 +1658,7 @@ int bt_ctf_field_type_set_byte_order(struct bt_ctf_field_type *type,
        }
 
        if (set_byte_order_funcs[type_id]) {
-               set_byte_order_funcs[type_id](type, internal_byte_order);
+               set_byte_order_funcs[type_id](type, internal_byte_order, 0);
        }
 end:
        return ret;
@@ -1763,6 +1797,21 @@ end:
        return ret;
 }
 
+BT_HIDDEN
+void bt_ctf_field_type_set_native_byte_order(struct bt_ctf_field_type *type,
+               int byte_order)
+{
+       if (!type) {
+               return;
+       }
+
+       assert(byte_order == LITTLE_ENDIAN || byte_order == BIG_ENDIAN);
+       if (set_byte_order_funcs[type->declaration->id]) {
+               set_byte_order_funcs[type->declaration->id](type,
+                       byte_order, 1);
+       }
+}
+
 static
 void bt_ctf_field_type_integer_destroy(struct bt_ctf_ref *ref)
 {
@@ -2296,24 +2345,130 @@ int bt_ctf_field_type_string_serialize(struct bt_ctf_field_type *type,
 
 static
 void bt_ctf_field_type_integer_set_byte_order(struct bt_ctf_field_type *type,
-               int byte_order)
+               int byte_order, int set_native)
 {
        struct bt_ctf_field_type_integer *integer_type = container_of(type,
                struct bt_ctf_field_type_integer, parent);
 
-       integer_type->declaration.byte_order = byte_order;
+       if (set_native) {
+               integer_type->declaration.byte_order =
+                       integer_type->declaration.byte_order == 0 ?
+                       byte_order : integer_type->declaration.byte_order;
+       } else {
+               integer_type->declaration.byte_order = byte_order;
+       }
+}
+
+static
+void bt_ctf_field_type_enumeration_set_byte_order(
+               struct bt_ctf_field_type *type, int byte_order, int set_native)
+{
+       struct bt_ctf_field_type_enumeration *enum_type = container_of(type,
+               struct bt_ctf_field_type_enumeration, parent);
+
+       /* Safe to assume that container is an integer */
+       bt_ctf_field_type_integer_set_byte_order(enum_type->container,
+               byte_order, set_native);
 }
 
 static
 void bt_ctf_field_type_floating_point_set_byte_order(
-               struct bt_ctf_field_type *type, int byte_order)
+               struct bt_ctf_field_type *type, int byte_order, int set_native)
 {
        struct bt_ctf_field_type_floating_point *floating_point_type =
                container_of(type, struct bt_ctf_field_type_floating_point,
                parent);
 
-       floating_point_type->declaration.byte_order = byte_order;
-       floating_point_type->sign.byte_order = byte_order;
-       floating_point_type->mantissa.byte_order = byte_order;
-       floating_point_type->exp.byte_order = byte_order;
+       if (set_native) {
+               floating_point_type->declaration.byte_order =
+                       floating_point_type->declaration.byte_order == 0 ?
+                       byte_order :
+                       floating_point_type->declaration.byte_order;
+               floating_point_type->sign.byte_order =
+                       floating_point_type->sign.byte_order == 0 ?
+                       byte_order : floating_point_type->sign.byte_order;
+               floating_point_type->mantissa.byte_order =
+                       floating_point_type->mantissa.byte_order == 0 ?
+                       byte_order : floating_point_type->mantissa.byte_order;
+               floating_point_type->exp.byte_order =
+                       floating_point_type->exp.byte_order == 0 ?
+                       byte_order : floating_point_type->exp.byte_order;
+       } else {
+               floating_point_type->declaration.byte_order = byte_order;
+               floating_point_type->sign.byte_order = byte_order;
+               floating_point_type->mantissa.byte_order = byte_order;
+               floating_point_type->exp.byte_order = byte_order;
+       }
+}
+
+static
+void bt_ctf_field_type_structure_set_byte_order(struct bt_ctf_field_type *type,
+               int byte_order, int set_native)
+{
+       int i;
+       struct bt_ctf_field_type_structure *structure_type =
+               container_of(type, struct bt_ctf_field_type_structure,
+               parent);
+
+       for (i = 0; i < structure_type->fields->len; i++) {
+               struct structure_field *field = g_ptr_array_index(
+                       structure_type->fields, i);
+               struct bt_ctf_field_type *field_type = field->type;
+
+               if (set_byte_order_funcs[field_type->declaration->id]) {
+                       set_byte_order_funcs[field_type->declaration->id](
+                               field_type, byte_order, set_native);
+               }
+       }
+}
+
+static
+void bt_ctf_field_type_variant_set_byte_order(struct bt_ctf_field_type *type,
+               int byte_order, int set_native)
+{
+       int i;
+       struct bt_ctf_field_type_variant *variant_type =
+               container_of(type, struct bt_ctf_field_type_variant,
+               parent);
+
+       for (i = 0; i < variant_type->fields->len; i++) {
+               struct structure_field *field = g_ptr_array_index(
+                       variant_type->fields, i);
+               struct bt_ctf_field_type *field_type = field->type;
+
+               if (set_byte_order_funcs[field_type->declaration->id]) {
+                       set_byte_order_funcs[field_type->declaration->id](
+                               field_type, byte_order, set_native);
+               }
+       }
+}
+
+static
+void bt_ctf_field_type_array_set_byte_order(struct bt_ctf_field_type *type,
+               int byte_order, int set_native)
+{
+       struct bt_ctf_field_type_array *array_type =
+               container_of(type, struct bt_ctf_field_type_array,
+               parent);
+
+       if (set_byte_order_funcs[array_type->element_type->declaration->id]) {
+               set_byte_order_funcs[array_type->element_type->declaration->id](
+                       array_type->element_type, byte_order, set_native);
+       }
+}
+
+static
+void bt_ctf_field_type_sequence_set_byte_order(struct bt_ctf_field_type *type,
+               int byte_order, int set_native)
+{
+       struct bt_ctf_field_type_sequence *sequence_type =
+               container_of(type, struct bt_ctf_field_type_sequence,
+               parent);
+
+       if (set_byte_order_funcs[
+               sequence_type->element_type->declaration->id]) {
+               set_byte_order_funcs[
+                       sequence_type->element_type->declaration->id](
+                       sequence_type->element_type, byte_order, set_native);
+       }
 }
index 000f5f7c7461b21b3db0e2a465c2cf3d347d573a..ad66783854a2b0174986fc0af2646d9f31ee9771 100644 (file)
@@ -33,6 +33,7 @@
 #include <babeltrace/ctf-ir/event-types-internal.h>
 #include <babeltrace/ctf-ir/event-internal.h>
 #include <babeltrace/ctf-ir/stream-class.h>
+#include <babeltrace/ctf-ir/stream-class-internal.h>
 #include <babeltrace/ctf-ir/trace-internal.h>
 #include <babeltrace/ctf-ir/utils.h>
 #include <babeltrace/compiler.h>
@@ -580,6 +581,20 @@ end:
        return ret;
 }
 
+void bt_ctf_event_class_set_native_byte_order(
+               struct bt_ctf_event_class *event_class,
+               int byte_order)
+{
+       if (!event_class) {
+               return;
+       }
+
+       bt_ctf_field_type_set_native_byte_order(event_class->context,
+               byte_order);
+       bt_ctf_field_type_set_native_byte_order(event_class->fields,
+               byte_order);
+}
+
 BT_HIDDEN
 int bt_ctf_event_validate(struct bt_ctf_event *event)
 {
index d034340da2df756e6e20e4704f59250fe815eb3c..ab62fa532f4fe2592b8d08c45894d12d1f1a8dc4 100644 (file)
@@ -369,6 +369,8 @@ void bt_ctf_stream_class_put(struct bt_ctf_stream_class *stream_class)
 BT_HIDDEN
 void bt_ctf_stream_class_freeze(struct bt_ctf_stream_class *stream_class)
 {
+       size_t i;
+
        if (!stream_class) {
                return;
        }
@@ -377,8 +379,20 @@ void bt_ctf_stream_class_freeze(struct bt_ctf_stream_class *stream_class)
        bt_ctf_field_type_freeze(stream_class->packet_context_type);
        bt_ctf_field_type_freeze(stream_class->event_context_type);
        bt_ctf_clock_freeze(stream_class->clock);
-       g_ptr_array_foreach(stream_class->event_classes,
-               (GFunc)bt_ctf_event_class_freeze, NULL);
+
+       bt_ctf_field_type_set_native_byte_order(
+               stream_class->event_header_type, stream_class->byte_order);
+       bt_ctf_field_type_set_native_byte_order(
+               stream_class->packet_context_type, stream_class->byte_order);
+       bt_ctf_field_type_set_native_byte_order(
+               stream_class->event_context_type, stream_class->byte_order);
+       for (i = 0; i < stream_class->event_classes->len; i++) {
+               bt_ctf_event_class_set_native_byte_order(
+                       g_ptr_array_index(stream_class->event_classes, i),
+                       stream_class->byte_order);
+               bt_ctf_event_class_freeze(
+                       g_ptr_array_index(stream_class->event_classes, i));
+       }
 }
 
 BT_HIDDEN
@@ -386,11 +400,30 @@ int bt_ctf_stream_class_set_byte_order(struct bt_ctf_stream_class *stream_class,
        enum bt_ctf_byte_order byte_order)
 {
        int ret = 0;
+       int internal_byte_order;
 
-       ret = init_event_header(stream_class, byte_order);
-       if (ret) {
+       /* Note that "NATIVE" means the trace's endianness, not the host's. */
+       if (!stream_class || byte_order <= BT_CTF_BYTE_ORDER_UNKNOWN ||
+               byte_order > BT_CTF_BYTE_ORDER_NETWORK ||
+               stream_class->frozen) {
+               ret = -1;
+               goto end;
+       }
+
+       switch (byte_order) {
+       case BT_CTF_BYTE_ORDER_NETWORK:
+       case BT_CTF_BYTE_ORDER_BIG_ENDIAN:
+               internal_byte_order = BIG_ENDIAN;
+               break;
+       case BT_CTF_BYTE_ORDER_LITTLE_ENDIAN:
+               internal_byte_order = LITTLE_ENDIAN;
+               break;
+       default:
+               ret = -1;
                goto end;
        }
+
+       stream_class->byte_order = internal_byte_order;
 end:
        return ret;
 }
@@ -506,16 +539,6 @@ int init_event_header(struct bt_ctf_stream_class *stream_class,
                goto end;
        }
 
-       ret = bt_ctf_field_type_set_byte_order(_uint32_t, byte_order);
-       if (ret) {
-               goto end;
-       }
-
-       ret = bt_ctf_field_type_set_byte_order(_uint64_t, byte_order);
-       if (ret) {
-               goto end;
-       }
-
        ret = bt_ctf_field_type_structure_add_field(event_header_type,
                _uint32_t, "id");
        if (ret) {
@@ -563,11 +586,6 @@ int init_packet_context(struct bt_ctf_stream_class *stream_class,
         * We create a stream packet context as proposed in the CTF
         * specification.
         */
-       ret = bt_ctf_field_type_set_byte_order(_uint64_t, byte_order);
-       if (ret) {
-               goto end;
-       }
-
        ret = bt_ctf_field_type_structure_add_field(packet_context_type,
                _uint64_t, "timestamp_begin");
        if (ret) {
index 59f696ebc9eab6280801de9e15c65292e00fd7cf..a886b69afd6526b60e4e3be869219f0e7cbfd37f 100644 (file)
@@ -143,13 +143,6 @@ struct bt_ctf_stream *bt_ctf_trace_create_stream(struct bt_ctf_trace *trace,
                goto error;
        }
 
-       ret = bt_ctf_stream_class_set_byte_order(stream_class,
-               trace->byte_order == LITTLE_ENDIAN ?
-               BT_CTF_BYTE_ORDER_LITTLE_ENDIAN : BT_CTF_BYTE_ORDER_BIG_ENDIAN);
-       if (ret) {
-               goto error;
-       }
-
        stream = bt_ctf_stream_create(stream_class, trace);
        if (!stream) {
                goto error;
@@ -185,10 +178,25 @@ struct bt_ctf_stream *bt_ctf_trace_create_stream(struct bt_ctf_trace *trace,
 
        bt_ctf_stream_get(stream);
        g_ptr_array_add(trace->streams, stream);
+
+       /*
+        * Freeze the trace and its packet header.
+        *
+        * All field type byte orders set as "native" byte ordering can now be
+        * safely set to trace's own endianness, including the stream class'.
+        */
+       bt_ctf_field_type_set_native_byte_order(trace->packet_header_type,
+               trace->byte_order);
+       ret = bt_ctf_stream_class_set_byte_order(stream_class,
+               trace->byte_order == LITTLE_ENDIAN ?
+               BT_CTF_BYTE_ORDER_LITTLE_ENDIAN : BT_CTF_BYTE_ORDER_BIG_ENDIAN);
+       if (ret) {
+               goto error;
+       }
+
        bt_ctf_stream_class_freeze(stream_class);
        trace->frozen = 1;
        return stream;
-
 error:
        bt_ctf_stream_put(stream);
        return NULL;
@@ -434,7 +442,16 @@ int bt_ctf_trace_set_byte_order(struct bt_ctf_trace *trace,
 
        switch (byte_order) {
        case BT_CTF_BYTE_ORDER_NATIVE:
-               internal_byte_order =  (G_BYTE_ORDER == G_LITTLE_ENDIAN) ?
+               /*
+                * This doesn't make sense since the CTF specification defines
+                * the "native" byte order as "the byte order described in the
+                * trace description". However, this behavior had been
+                * implemented as part of v1.2 and is kept to maintain
+                * compatibility.
+                *
+                * This may be changed on a major version bump only.
+                */
+               internal_byte_order = (G_BYTE_ORDER == G_LITTLE_ENDIAN) ?
                        LITTLE_ENDIAN : BIG_ENDIAN;
                break;
        case BT_CTF_BYTE_ORDER_LITTLE_ENDIAN:
@@ -550,14 +567,6 @@ int init_trace_packet_header(struct bt_ctf_trace *trace)
                goto end;
        }
 
-       ret = bt_ctf_field_type_set_byte_order(_uint32_t,
-               (trace->byte_order == LITTLE_ENDIAN ?
-               BT_CTF_BYTE_ORDER_LITTLE_ENDIAN :
-               BT_CTF_BYTE_ORDER_BIG_ENDIAN));
-       if (ret) {
-               goto end;
-       }
-
        ret = bt_ctf_field_type_structure_add_field(trace_packet_header_type,
                _uint32_t, "magic");
        if (ret) {
index ac4cd6de83041946b3d720a04ff93238ddda3fe7..5d3484b4e1b5ceddf4664b845e83cbb2d9d352bc 100644 (file)
@@ -66,6 +66,11 @@ BT_HIDDEN
 int bt_ctf_event_class_serialize(struct bt_ctf_event_class *event_class,
                struct metadata_context *context);
 
+BT_HIDDEN
+void bt_ctf_event_class_set_native_byte_order(
+               struct bt_ctf_event_class *event_class,
+               int byte_order);
+
 BT_HIDDEN
 int bt_ctf_event_validate(struct bt_ctf_event *event);
 
index dd80bdceb89026560318236b3eaed7286800c9b3..198497dff68da45ce2bde43ade4a5d400554e8de 100644 (file)
@@ -155,4 +155,8 @@ const char *bt_ctf_field_type_enumeration_get_mapping_name_signed(
                struct bt_ctf_field_type_enumeration *enumeration_type,
                int64_t value);
 
+/* Override field type's byte order only if it is set to "native" */
+BT_HIDDEN
+void bt_ctf_field_type_set_native_byte_order(
+               struct bt_ctf_field_type *type, int byte_order);
 #endif /* BABELTRACE_CTF_IR_EVENT_TYPES_INTERNAL_H */
index d445812f4363292a16ccfd0a01967e9a7d1de7bd..258c7473d66328a599d9ba5bf075512606f2f10c 100644 (file)
@@ -52,6 +52,11 @@ enum bt_ctf_integer_base {
 
 enum bt_ctf_byte_order {
        BT_CTF_BYTE_ORDER_UNKNOWN = -1,
+       /*
+        * Note that native, in the context of the CTF specification, is defined as
+        * "the byte order described in the trace" and does not mean that the host's
+        * endianness will be used.
+        */
        BT_CTF_BYTE_ORDER_NATIVE = 0,
        BT_CTF_BYTE_ORDER_LITTLE_ENDIAN,
        BT_CTF_BYTE_ORDER_BIG_ENDIAN,
@@ -695,7 +700,7 @@ extern enum bt_ctf_byte_order bt_ctf_field_type_get_byte_order(
  *
  * @param type Field type.
  * @param byte_order Field type's byte order. Defaults to
- * BT_CTF_BYTE_ORDER_NATIVE, the host machine's endianness.
+ * BT_CTF_BYTE_ORDER_NATIVE; the trace's endianness.
  *
  * Returns 0 on success, a negative value on error.
  */
index 55ad787e50723d11548f04d9d0e0bfa9d88bbdeb..ed995b1c3e1d8ebea9a2f327abc8043731e2d850 100644 (file)
@@ -49,6 +49,7 @@ struct bt_ctf_stream_class {
        struct bt_ctf_field_type *packet_context_type;
        struct bt_ctf_field_type *event_context_type;
        int frozen;
+       int byte_order;
 };
 
 BT_HIDDEN
index 125b554b49b90f4d23a62f50b61fa91a5fca8aa3..19cdd3615571c04e962a0245808324c6cac2d247 100644 (file)
@@ -50,7 +50,7 @@ struct bt_ctf_trace {
        struct bt_ctf_ref ref_count;
        int frozen;
        uuid_t uuid;
-       int byte_order;
+       int byte_order; /* A value defined in Babeltrace's "endian.h" */
        GPtrArray *environment; /* Array of pointers to environment_variable */
        GPtrArray *clocks; /* Array of pointers to bt_ctf_clock */
        GPtrArray *stream_classes; /* Array of ptrs to bt_ctf_stream_class */
index dea9f70a40c72e84d424bf6f2315bf38abf829f2..6a0148c63cf1965304f85946d7be737f50f97b77 100644 (file)
@@ -137,13 +137,16 @@ extern char *bt_ctf_trace_get_metadata_string(struct bt_ctf_trace *trace);
 /*
  * bt_ctf_trace_set_byte_order: set a field type's byte order.
  *
- * Set the trace's byte order. Defaults to BT_CTF_BYTE_ORDER_NATIVE,
- * the host machine's endianness.
+ * Set the trace's byte order. Defaults to the current host's endianness.
  *
  * @param trace Trace instance.
  * @param byte_order Trace's byte order.
  *
  * Returns 0 on success, a negative value on error.
+ *
+ * Note: byte_order must not be BT_CTF_BYTE_ORDER_NATIVE since, according
+ * to the CTF specification, is defined as "the byte order described in the
+ * trace description".
  */
 extern int bt_ctf_trace_set_byte_order(struct bt_ctf_trace *trace,
                enum bt_ctf_byte_order byte_order);
index f6051b4ed821fcedbcc9f539547b79d11a3a1f2e..f189ab5cb2656d5b586ea31b717a51ea2af346cb 100644 (file)
@@ -135,13 +135,16 @@ extern void bt_ctf_writer_flush_metadata(struct bt_ctf_writer *writer);
 /*
  * bt_ctf_writer_set_byte_order: set a field type's byte order.
  *
- * Set the trace's byte order. Defaults to BT_CTF_BYTE_ORDER_NATIVE,
- * the host machine's endianness.
+ * Set the trace's byte order. Defaults to the host machine's endianness.
  *
  * @param writer Writer instance.
  * @param byte_order Trace's byte order.
  *
  * Returns 0 on success, a negative value on error.
+ *
+ * Note: byte_order must not be BT_CTF_BYTE_ORDER_NATIVE since, according
+ * to the CTF specification, is defined as "the byte order described in the
+ * trace description".
  */
 extern int bt_ctf_writer_set_byte_order(struct bt_ctf_writer *writer,
                enum bt_ctf_byte_order byte_order);
index b32d2a41582e03f3c66ac1aad19fbcf6d4e554c5..b2bcf0e8b46b1b48f2d867a5d3c90973be207102 100644 (file)
@@ -141,7 +141,7 @@ int generic_rw(struct bt_stream_pos *pos, struct bt_definition *definition)
 struct declaration_integer {
        struct bt_declaration p;
        size_t len;             /* length, in bits. */
-       int byte_order;         /* byte order */
+       int byte_order;         /* LITTLE_ENDIAN/BIG_ENDIAN, 0 == "Native" */
        int signedness;
        int base;               /* Base for pretty-printing: 2, 8, 10, 16 */
        enum ctf_string_encoding encoding;
@@ -163,7 +163,7 @@ struct declaration_float {
        struct declaration_integer *sign;
        struct declaration_integer *mantissa;
        struct declaration_integer *exp;
-       int byte_order;
+       int byte_order;         /* LITTLE_ENDIAN/BIG_ENDIAN, 0 == "Native" */
        /* TODO: we might want to express more info about NaN, +inf and -inf */
 };
 
This page took 0.037222 seconds and 4 git commands to generate.