X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=formats%2Fctf%2Fwriter%2Fwriter.c;h=460ac81c9c4f158c46dc32e3ed1fb645a1553139;hb=12c8a1a3121ed7125e8758065c44658d8eda1333;hp=13142a12ca1e534fa0b0e3100c77a0839eec9e79;hpb=de9dd3975ba39e915d7e046877af9059990c595e;p=babeltrace.git diff --git a/formats/ctf/writer/writer.c b/formats/ctf/writer/writer.c index 13142a12..460ac81c 100644 --- a/formats/ctf/writer/writer.c +++ b/formats/ctf/writer/writer.c @@ -34,8 +34,8 @@ #include #include #include -#include -#include +#include +#include #include #include #include @@ -215,6 +215,13 @@ struct bt_ctf_stream *bt_ctf_writer_create_stream(struct bt_ctf_writer *writer, goto error; } + ret = bt_ctf_stream_class_set_byte_order(stream_class, + writer->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); if (!stream) { goto error; @@ -227,12 +234,6 @@ struct bt_ctf_stream *bt_ctf_writer_create_stream(struct bt_ctf_writer *writer, bt_ctf_stream_set_flush_callback(stream, (flush_func)stream_flush_cb, writer); - ret = bt_ctf_stream_class_set_byte_order(stream->stream_class, - writer->byte_order == LITTLE_ENDIAN ? - BT_CTF_BYTE_ORDER_LITTLE_ENDIAN : BT_CTF_BYTE_ORDER_BIG_ENDIAN); - if (ret) { - goto error; - } for (i = 0; i < writer->stream_classes->len; i++) { if (writer->stream_classes->pdata[i] == stream->stream_class) { @@ -241,11 +242,21 @@ struct bt_ctf_stream *bt_ctf_writer_create_stream(struct bt_ctf_writer *writer, } if (!stream_class_found) { - if (bt_ctf_stream_class_set_id(stream->stream_class, - writer->next_stream_id++)) { - goto error; + int64_t stream_id = bt_ctf_stream_class_get_id(stream_class); + if (stream_id < 0) { + if (bt_ctf_stream_class_set_id(stream->stream_class, + writer->next_stream_id++)) { + goto error; + } } + for (i = 0; i < writer->stream_classes->len; i++) { + if (stream_id == bt_ctf_stream_class_get_id( + writer->stream_classes->pdata[i])) { + /* Duplicate stream id found */ + goto error; + } + } bt_ctf_stream_class_get(stream->stream_class); g_ptr_array_add(writer->stream_classes, stream->stream_class); } @@ -724,7 +735,7 @@ void stream_flush_cb(struct bt_ctf_stream *stream, struct bt_ctf_writer *writer) stream_id = bt_ctf_field_structure_get_field( writer->trace_packet_header, "stream_id"); - bt_ctf_field_unsigned_integer_set_value(stream_id, stream->id); + bt_ctf_field_unsigned_integer_set_value(stream_id, stream->stream_class->id); bt_ctf_field_put(stream_id); /* Write the trace_packet_header */