Update autoconf archive macros
[babeltrace.git] / plugins / lttng-utils / copy.c
index 2d48ac61b86e37dadbddf892ea5c4daba097ea4c..a2250c2c75f28a052878e15e29e5b83d7339a6f5 100644 (file)
@@ -867,15 +867,28 @@ struct bt_ctf_packet *insert_new_packet(struct debug_info_iterator *debug_it,
                struct debug_info_trace *di_trace)
 {
        struct bt_ctf_packet *writer_packet;
+       int ret;
 
        writer_packet = bt_ctf_packet_create(writer_stream);
        if (!writer_packet) {
                fprintf(debug_it->err, "[error] %s in %s:%d\n", __func__,
                                __FILE__, __LINE__);
-               goto end;
+               goto error;
        }
-       g_hash_table_insert(di_trace->packet_map, (gpointer) packet, writer_packet);
 
+       ret = ctf_packet_copy_header(debug_it->err, packet, writer_packet);
+       if (ret) {
+               fprintf(debug_it->err, "[error] %s in %s:%d\n", __func__,
+                               __FILE__, __LINE__);
+               goto error;
+       }
+
+       g_hash_table_insert(di_trace->packet_map, (gpointer) packet,
+                       writer_packet);
+       goto end;
+
+error:
+       BT_PUT(writer_packet);
 end:
        return writer_packet;
 }
@@ -1032,10 +1045,6 @@ struct bt_ctf_stream_class *copy_stream_class_debug_info(FILE *err,
        int ret_int;
        const char *name = bt_ctf_stream_class_get_name(stream_class);
 
-       if (strlen(name) == 0) {
-               name = NULL;
-       }
-
        writer_stream_class = bt_ctf_stream_class_create_empty(name);
        if (!writer_stream_class) {
                fprintf(err, "[error] %s in %s:%d\n",
@@ -1121,6 +1130,7 @@ int add_clock_classes(FILE *err, struct bt_ctf_trace *writer_trace,
        for (i = 0; i < clock_class_count; i++) {
                struct bt_ctf_clock_class *clock_class =
                        bt_ctf_trace_get_clock_class_by_index(trace, i);
+               struct bt_ctf_clock_class *existing_clock_class = NULL;
 
                if (!clock_class) {
                        fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
@@ -1128,6 +1138,14 @@ int add_clock_classes(FILE *err, struct bt_ctf_trace *writer_trace,
                        goto error;
                }
 
+               existing_clock_class = bt_ctf_trace_get_clock_class_by_name(
+                       writer_trace, bt_ctf_clock_class_get_name(clock_class));
+               bt_put(existing_clock_class);
+               if (existing_clock_class) {
+                       bt_put(clock_class);
+                       continue;
+               }
+
                ret = bt_ctf_trace_add_clock_class(writer_trace, clock_class);
                BT_PUT(clock_class);
                if (ret != 0) {
@@ -1224,6 +1242,7 @@ struct bt_ctf_stream *insert_new_stream(
        struct bt_ctf_stream *writer_stream = NULL;
        struct bt_ctf_stream_class *stream_class = NULL;
        struct bt_ctf_stream_class *writer_stream_class = NULL;
+       int64_t id;
 
        stream_class = bt_ctf_stream_get_class(stream);
        if (!stream_class) {
@@ -1247,8 +1266,16 @@ struct bt_ctf_stream *insert_new_stream(
        }
        bt_get(writer_stream_class);
 
-       writer_stream = bt_ctf_stream_create(writer_stream_class,
-                       bt_ctf_stream_get_name(stream));
+       id = bt_ctf_stream_get_id(stream);
+       if (id < 0) {
+               writer_stream = bt_ctf_stream_create(writer_stream_class,
+                               bt_ctf_stream_get_name(stream));
+       } else {
+               writer_stream = bt_ctf_stream_create_with_id(
+                       writer_stream_class,
+                       bt_ctf_stream_get_name(stream), id);
+       }
+
        if (!writer_stream) {
                fprintf(debug_it->err, "[error] %s in %s:%d\n",
                                __func__, __FILE__, __LINE__);
@@ -1364,7 +1391,6 @@ struct bt_ctf_packet *debug_info_new_packet(
                struct bt_ctf_packet *packet)
 {
        struct bt_ctf_stream *stream = NULL, *writer_stream = NULL;
-       struct bt_ctf_field *writer_packet_context = NULL;
        struct bt_ctf_packet *writer_packet = NULL;
        struct bt_ctf_field *packet_context = NULL;
        struct debug_info_trace *di_trace;
@@ -1411,9 +1437,9 @@ struct bt_ctf_packet *debug_info_new_packet(
 
        packet_context = bt_ctf_packet_get_context(packet);
        if (packet_context) {
-               writer_packet_context = ctf_copy_packet_context(debug_it->err,
-                               packet, writer_stream);
-               if (!writer_packet_context) {
+               int_ret = ctf_packet_copy_context(debug_it->err,
+                               packet, writer_stream, writer_packet);
+               if (int_ret < 0) {
                        fprintf(debug_it->err, "[error] %s in %s:%d\n",
                                        __func__, __FILE__, __LINE__);
                        goto error;
@@ -1421,13 +1447,6 @@ struct bt_ctf_packet *debug_info_new_packet(
                BT_PUT(packet_context);
        }
 
-       int_ret = bt_ctf_packet_set_context(writer_packet, writer_packet_context);
-       if (int_ret) {
-               fprintf(debug_it->err, "[error] %s in %s:%d\n",
-                               __func__, __FILE__, __LINE__);
-               goto error;
-       }
-
        bt_get(writer_packet);
        goto end;
 
@@ -1435,7 +1454,6 @@ error:
 
 end:
        bt_put(packet_context);
-       bt_put(writer_packet_context);
        bt_put(writer_stream);
        bt_put(stream);
        return writer_packet;
This page took 0.025734 seconds and 4 git commands to generate.