ctf.fs: bt_ctf_notif_iter_create(): assert() that all medops exist
[babeltrace.git] / formats / ctf / ir / packet.c
index 76a2f0455752b63f8e1cf558a1d32a860746f60c..6236e00bdb5e7cbc4837feed6f76b4d88151532c 100644 (file)
@@ -56,11 +56,15 @@ int bt_ctf_packet_set_header(struct bt_ctf_packet *packet,
        struct bt_ctf_field_type *header_field_type = NULL;
        struct bt_ctf_field_type *expected_header_field_type = NULL;
 
-       if (!packet || !header || packet->frozen) {
+       if (!packet || packet->frozen) {
                ret = -1;
                goto end;
        }
 
+       if (!header) {
+               goto skip_validation;
+       }
+
        stream_class = bt_ctf_stream_get_class(packet->stream);
        assert(stream_class);
        trace = bt_ctf_stream_class_get_trace(stream_class);
@@ -75,6 +79,7 @@ int bt_ctf_packet_set_header(struct bt_ctf_packet *packet,
                goto end;
        }
 
+skip_validation:
        bt_put(packet->header);
        packet->header = bt_get(header);
 
@@ -101,11 +106,15 @@ int bt_ctf_packet_set_context(struct bt_ctf_packet *packet,
        struct bt_ctf_field_type *context_field_type = NULL;
        struct bt_ctf_field_type *expected_context_field_type = NULL;
 
-       if (!packet || !context || packet->frozen) {
+       if (!packet || packet->frozen) {
                ret = -1;
                goto end;
        }
 
+       if (!context) {
+               goto skip_validation;
+       }
+
        stream_class = bt_ctf_stream_get_class(packet->stream);
        assert(stream_class);
        context_field_type = bt_ctf_field_get_type(context);
@@ -119,6 +128,7 @@ int bt_ctf_packet_set_context(struct bt_ctf_packet *packet,
                goto end;
        }
 
+skip_validation:
        bt_put(packet->context);
        packet->context = bt_get(context);
 
@@ -134,15 +144,12 @@ BT_HIDDEN
 void bt_ctf_packet_freeze(struct bt_ctf_packet *packet)
 {
        if (!packet) {
-               goto end;
+               return;
        }
 
        bt_ctf_field_freeze(packet->header);
        bt_ctf_field_freeze(packet->context);
        packet->frozen = 1;
-
-end:
-       return;
 }
 
 static
@@ -157,7 +164,7 @@ void bt_ctf_packet_destroy(struct bt_object *obj)
        g_free(packet);
 }
 
-extern struct bt_ctf_packet *bt_ctf_packet_create(
+struct bt_ctf_packet *bt_ctf_packet_create(
                struct bt_ctf_stream *stream)
 {
        struct bt_ctf_packet *packet = NULL;
@@ -180,14 +187,14 @@ extern struct bt_ctf_packet *bt_ctf_packet_create(
        bt_object_init(packet, bt_ctf_packet_destroy);
        packet->stream = bt_get(stream);
        packet->header = bt_ctf_field_create(trace->packet_header_type);
-       if (!packet->header) {
+       if (!packet->header && trace->packet_header_type) {
                BT_PUT(packet);
                goto end;
        }
 
        packet->context = bt_ctf_field_create(
                stream->stream_class->packet_context_type);
-       if (!packet->context) {
+       if (!packet->context && stream->stream_class->packet_context_type) {
                BT_PUT(packet);
                goto end;
        }
This page took 0.024743 seconds and 4 git commands to generate.