ir: validate sequence length fields and variant tags of stream classes
[babeltrace.git] / formats / ctf / ir / trace.c
index 94a332d162e4052ff9530baf63e0952d45a9b3af..b8f4f7258d0bc66463d03cff58b386b60d3fcfde 100644 (file)
@@ -33,6 +33,7 @@
 #include <babeltrace/ctf-writer/functor-internal.h>
 #include <babeltrace/ctf-ir/event-types-internal.h>
 #include <babeltrace/ctf-ir/attributes-internal.h>
+#include <babeltrace/ctf-ir/visitor-internal.h>
 #include <babeltrace/ctf-ir/utils.h>
 #include <babeltrace/compiler.h>
 #include <babeltrace/objects.h>
@@ -443,11 +444,17 @@ int bt_ctf_trace_add_stream_class(struct bt_ctf_trace *trace,
 
        for (i = 0; i < trace->stream_classes->len; i++) {
                if (trace->stream_classes->pdata[i] == stream_class) {
+                       /* Stream already registered to the trace */
                        ret = -1;
                        goto end;
                }
        }
 
+       ret = bt_ctf_stream_class_resolve_types(stream_class, trace);
+       if (ret) {
+               goto end;
+       }
+
        stream_id = bt_ctf_stream_class_get_id(stream_class);
        if (stream_id < 0) {
                stream_id = trace->next_stream_id++;
@@ -462,7 +469,7 @@ int bt_ctf_trace_add_stream_class(struct bt_ctf_trace *trace,
                        }
                }
 
-               if (_bt_ctf_stream_class_set_id(stream_class,
+               if (bt_ctf_stream_class_set_id_no_check(stream_class,
                        stream_id)) {
                        /* TODO Should retry with a different stream id */
                        ret = -1;
@@ -496,7 +503,9 @@ int bt_ctf_trace_add_stream_class(struct bt_ctf_trace *trace,
        }
 
        bt_ctf_stream_class_freeze(stream_class);
-       bt_ctf_trace_freeze(trace);
+       if (!trace->frozen) {
+               bt_ctf_trace_freeze(trace);
+       }
 end:
        if (ret) {
                (void) bt_ctf_stream_class_set_trace(stream_class, NULL);
@@ -885,6 +894,7 @@ struct bt_ctf_field_type *get_field_type(enum field_type_alias alias)
 static
 void bt_ctf_trace_freeze(struct bt_ctf_trace *trace)
 {
+       bt_ctf_trace_resolve_types(trace);
        bt_ctf_attributes_freeze(trace->environment);
        trace->frozen = 1;
 }
This page took 0.0242 seconds and 4 git commands to generate.