From c35a1669cedba73681bd259ea7945aa55643e158 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Wed, 4 Feb 2015 15:38:06 -0500 Subject: [PATCH] Fix: Field types native byte order refers to the trace MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 --- bindings/python/babeltrace.i.in | 2 +- formats/ctf/ir/event-types.c | 207 +++++++++++++++--- formats/ctf/ir/event.c | 15 ++ formats/ctf/ir/stream-class.c | 56 +++-- formats/ctf/ir/trace.c | 43 ++-- include/babeltrace/ctf-ir/event-internal.h | 5 + .../babeltrace/ctf-ir/event-types-internal.h | 4 + include/babeltrace/ctf-ir/event-types.h | 7 +- .../babeltrace/ctf-ir/stream-class-internal.h | 1 + include/babeltrace/ctf-ir/trace-internal.h | 2 +- include/babeltrace/ctf-ir/trace.h | 7 +- include/babeltrace/ctf-writer/writer.h | 7 +- include/babeltrace/types.h | 4 +- 13 files changed, 289 insertions(+), 71 deletions(-) diff --git a/bindings/python/babeltrace.i.in b/bindings/python/babeltrace.i.in index 2dd77a54..d255f766 100644 --- a/bindings/python/babeltrace.i.in +++ b/bindings/python/babeltrace.i.in @@ -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): diff --git a/formats/ctf/ir/event-types.c b/formats/ctf/ir/event-types.c index a57aaf5a..c24ef93f 100644 --- a/formats/ctf/ir/event-types.c +++ b/formats/ctf/ir/event-types.c @@ -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); + } } diff --git a/formats/ctf/ir/event.c b/formats/ctf/ir/event.c index 000f5f7c..ad667838 100644 --- a/formats/ctf/ir/event.c +++ b/formats/ctf/ir/event.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -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) { diff --git a/formats/ctf/ir/stream-class.c b/formats/ctf/ir/stream-class.c index d034340d..ab62fa53 100644 --- a/formats/ctf/ir/stream-class.c +++ b/formats/ctf/ir/stream-class.c @@ -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) { diff --git a/formats/ctf/ir/trace.c b/formats/ctf/ir/trace.c index 59f696eb..a886b69a 100644 --- a/formats/ctf/ir/trace.c +++ b/formats/ctf/ir/trace.c @@ -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) { diff --git a/include/babeltrace/ctf-ir/event-internal.h b/include/babeltrace/ctf-ir/event-internal.h index ac4cd6de..5d3484b4 100644 --- a/include/babeltrace/ctf-ir/event-internal.h +++ b/include/babeltrace/ctf-ir/event-internal.h @@ -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); diff --git a/include/babeltrace/ctf-ir/event-types-internal.h b/include/babeltrace/ctf-ir/event-types-internal.h index dd80bdce..198497df 100644 --- a/include/babeltrace/ctf-ir/event-types-internal.h +++ b/include/babeltrace/ctf-ir/event-types-internal.h @@ -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 */ diff --git a/include/babeltrace/ctf-ir/event-types.h b/include/babeltrace/ctf-ir/event-types.h index d445812f..258c7473 100644 --- a/include/babeltrace/ctf-ir/event-types.h +++ b/include/babeltrace/ctf-ir/event-types.h @@ -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. */ diff --git a/include/babeltrace/ctf-ir/stream-class-internal.h b/include/babeltrace/ctf-ir/stream-class-internal.h index 55ad787e..ed995b1c 100644 --- a/include/babeltrace/ctf-ir/stream-class-internal.h +++ b/include/babeltrace/ctf-ir/stream-class-internal.h @@ -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 diff --git a/include/babeltrace/ctf-ir/trace-internal.h b/include/babeltrace/ctf-ir/trace-internal.h index 125b554b..19cdd361 100644 --- a/include/babeltrace/ctf-ir/trace-internal.h +++ b/include/babeltrace/ctf-ir/trace-internal.h @@ -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 */ diff --git a/include/babeltrace/ctf-ir/trace.h b/include/babeltrace/ctf-ir/trace.h index dea9f70a..6a0148c6 100644 --- a/include/babeltrace/ctf-ir/trace.h +++ b/include/babeltrace/ctf-ir/trace.h @@ -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); diff --git a/include/babeltrace/ctf-writer/writer.h b/include/babeltrace/ctf-writer/writer.h index f6051b4e..f189ab5c 100644 --- a/include/babeltrace/ctf-writer/writer.h +++ b/include/babeltrace/ctf-writer/writer.h @@ -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); diff --git a/include/babeltrace/types.h b/include/babeltrace/types.h index b32d2a41..b2bcf0e8 100644 --- a/include/babeltrace/types.h +++ b/include/babeltrace/types.h @@ -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 */ }; -- 2.34.1