ctf.fs: bt_ctf_notif_iter_create(): assert() that all medops exist
[babeltrace.git] / formats / ctf / ir / stream-class.c
index 72b07b84c14cb26b98d983e908f4e88c18635dd3..403f5dbbf51089a5d7783b0701faeaafbd86dff7 100644 (file)
  */
 
 #include <babeltrace/ctf-writer/clock.h>
-#include <babeltrace/ctf-ir/clock-internal.h>
+#include <babeltrace/ctf-writer/clock-internal.h>
+#include <babeltrace/ctf-ir/clock-class-internal.h>
 #include <babeltrace/ctf-writer/event.h>
+#include <babeltrace/ctf-ir/event-class-internal.h>
 #include <babeltrace/ctf-ir/event-internal.h>
-#include <babeltrace/ctf-ir/event-types-internal.h>
-#include <babeltrace/ctf-ir/event-fields-internal.h>
+#include <babeltrace/ctf-ir/field-types-internal.h>
+#include <babeltrace/ctf-ir/fields-internal.h>
 #include <babeltrace/ctf-writer/stream.h>
 #include <babeltrace/ctf-ir/stream-class-internal.h>
+#include <babeltrace/ctf-ir/validation-internal.h>
 #include <babeltrace/ctf-ir/visitor-internal.h>
 #include <babeltrace/ctf-writer/functor-internal.h>
 #include <babeltrace/ctf-ir/utils.h>
+#include <babeltrace/ref.h>
 #include <babeltrace/compiler.h>
 #include <babeltrace/align.h>
+#include <babeltrace/endian.h>
 
 static
-void bt_ctf_stream_class_destroy(struct bt_ctf_ref *ref);
+void bt_ctf_stream_class_destroy(struct bt_object *obj);
 static
 int init_event_header(struct bt_ctf_stream_class *stream_class);
 static
@@ -63,46 +68,37 @@ struct bt_ctf_stream_class *bt_ctf_stream_class_create(const char *name)
 
        stream_class->name = g_string_new(name);
        stream_class->event_classes = g_ptr_array_new_with_free_func(
-               (GDestroyNotify)bt_ctf_event_class_put);
+               (GDestroyNotify) bt_object_release);
        if (!stream_class->event_classes) {
-               goto error_destroy;
+               goto error;
        }
 
+       stream_class->event_classes_ht = g_hash_table_new_full(g_int64_hash,
+                       g_int64_equal, g_free, NULL);
+
        ret = init_event_header(stream_class);
        if (ret) {
-               goto error_destroy;
+               goto error;
        }
 
        ret = init_packet_context(stream_class);
        if (ret) {
-               goto error_destroy;
+               goto error;
        }
 
-       bt_ctf_ref_init(&stream_class->ref_count);
+       bt_object_init(stream_class, bt_ctf_stream_class_destroy);
        return stream_class;
 
-error_destroy:
-       bt_ctf_stream_class_destroy(&stream_class->ref_count);
-       stream_class = NULL;
 error:
+        BT_PUT(stream_class);
        return stream_class;
 }
 
 struct bt_ctf_trace *bt_ctf_stream_class_get_trace(
                struct bt_ctf_stream_class *stream_class)
 {
-       struct bt_ctf_trace *trace = NULL;
-
-       if (!stream_class) {
-               goto end;
-       }
-
-       trace = stream_class->trace;
-       if (trace) {
-               bt_ctf_trace_get(trace);
-       }
-end:
-       return trace;
+       return (struct bt_ctf_trace *) bt_object_get_parent(
+               stream_class);
 }
 
 const char *bt_ctf_stream_class_get_name(
@@ -143,8 +139,7 @@ struct bt_ctf_clock *bt_ctf_stream_class_get_clock(
                goto end;
        }
 
-       clock = stream_class->clock;
-       bt_ctf_clock_get(clock);
+       clock = bt_get(stream_class->clock);
 end:
        return clock;
 }
@@ -161,39 +156,35 @@ int bt_ctf_stream_class_set_clock(struct bt_ctf_stream_class *stream_class,
        }
 
        /*
-        * Look for a "timestamp" field in the stream class' event header type
-        * and map the stream's clock to that field if no current mapping is
-        * currently set.
+        * Look for a "timestamp" integer field type in the stream
+        * class's event header field type and map the stream class's
+        * clock's class to that field type if there's no current
+        * mapping.
         */
        timestamp_field = bt_ctf_field_type_structure_get_field_type_by_name(
                stream_class->event_header_type, "timestamp");
        if (timestamp_field) {
-               struct bt_ctf_clock *mapped_clock;
-
-               mapped_clock = bt_ctf_field_type_integer_get_mapped_clock(
-                       timestamp_field);
-               if (mapped_clock) {
-                       bt_ctf_clock_put(mapped_clock);
-                       goto end;
+               struct bt_ctf_clock_class *mapped_clock_class =
+                       bt_ctf_field_type_integer_get_mapped_clock_class(
+                               timestamp_field);
+
+               if (!mapped_clock_class) {
+                       ret = bt_ctf_field_type_integer_set_mapped_clock_class(
+                               timestamp_field, clock->clock_class);
+                       if (ret) {
+                               goto end;
+                       }
                }
 
-               ret = bt_ctf_field_type_integer_set_mapped_clock(
-                       timestamp_field, clock);
-               if (ret) {
-                       goto end;
-               }
+               BT_PUT(mapped_clock_class);
        }
 
-       if (stream_class->clock) {
-               bt_ctf_clock_put(stream_class->clock);
-       }
+       /* Replace the current clock of this stream class. */
+       bt_put(stream_class->clock);
+       stream_class->clock = bt_get(clock);
 
-       stream_class->clock = clock;
-       bt_ctf_clock_get(clock);
 end:
-       if (timestamp_field) {
-               bt_ctf_field_type_put(timestamp_field);
-       }
+       bt_put(timestamp_field);
        return ret;
 }
 
@@ -325,13 +316,30 @@ int bt_ctf_stream_class_add_event_class(
                struct bt_ctf_event_class *event_class)
 {
        int ret = 0;
-       int64_t event_id;
+       int64_t *event_id = NULL;
+       struct bt_ctf_trace *trace = NULL;
+       struct bt_ctf_stream_class *old_stream_class = NULL;
+       struct bt_ctf_validation_output validation_output = { 0 };
+       struct bt_ctf_field_type *packet_header_type = NULL;
+       struct bt_ctf_field_type *packet_context_type = NULL;
+       struct bt_ctf_field_type *event_header_type = NULL;
+       struct bt_ctf_field_type *stream_event_ctx_type = NULL;
+       struct bt_ctf_field_type *event_context_type = NULL;
+       struct bt_ctf_field_type *event_payload_type = NULL;
+       const enum bt_ctf_validation_flag validation_flags =
+               BT_CTF_VALIDATION_FLAG_EVENT;
 
        if (!stream_class || !event_class) {
                ret = -1;
                goto end;
        }
 
+       event_id = g_new(int64_t, 1);
+       if (!event_id) {
+               ret = -1;
+               goto end;
+       }
+
        /* Check for duplicate event classes */
        struct search_query query = { .value = event_class, .found = 0 };
        g_ptr_array_foreach(stream_class->event_classes, event_class_exists,
@@ -341,42 +349,114 @@ int bt_ctf_stream_class_add_event_class(
                goto end;
        }
 
-       /*
-        * Resolve the event's sequence length and variant tags if the
-        * stream is already associated with a trace. Otherwise, this
-        * validation will be performed once the stream is registered
-        * to a trace.
-        */
-       if (stream_class->trace) {
-               ret = bt_ctf_event_class_resolve_types(event_class,
-                       stream_class->trace, stream_class);
+       old_stream_class = bt_ctf_event_class_get_stream_class(event_class);
+       if (old_stream_class) {
+               /* Event class is already associated to a stream class. */
+               ret = -1;
+               goto end;
+       }
+
+       trace = bt_ctf_stream_class_get_trace(stream_class);
+       if (trace) {
+               /*
+                * If the stream class is associated with a trace, then
+                * both those objects are frozen. Also, this event class
+                * is about to be frozen.
+                *
+                * Therefore the event class must be validated here.
+                * The trace and stream class should be valid at this
+                * point.
+                */
+               assert(trace->valid);
+               assert(stream_class->valid);
+               packet_header_type =
+                       bt_ctf_trace_get_packet_header_type(trace);
+               packet_context_type =
+                       bt_ctf_stream_class_get_packet_context_type(
+                               stream_class);
+               event_header_type =
+                       bt_ctf_stream_class_get_event_header_type(stream_class);
+               stream_event_ctx_type =
+                       bt_ctf_stream_class_get_event_context_type(
+                               stream_class);
+               event_context_type =
+                       bt_ctf_event_class_get_context_type(event_class);
+               event_payload_type =
+                       bt_ctf_event_class_get_payload_type(event_class);
+               ret = bt_ctf_validate_class_types(
+                       trace->environment, packet_header_type,
+                       packet_context_type, event_header_type,
+                       stream_event_ctx_type, event_context_type,
+                       event_payload_type, trace->valid,
+                       stream_class->valid, event_class->valid,
+                       &validation_output, validation_flags);
+               BT_PUT(packet_header_type);
+               BT_PUT(packet_context_type);
+               BT_PUT(event_header_type);
+               BT_PUT(stream_event_ctx_type);
+               BT_PUT(event_context_type);
+               BT_PUT(event_payload_type);
+
                if (ret) {
+                       /*
+                        * This means something went wrong during the
+                        * validation process, not that the objects are
+                        * invalid.
+                        */
+                       goto end;
+               }
+
+               if ((validation_output.valid_flags & validation_flags) !=
+                               validation_flags) {
+                       /* Invalid event class */
+                       ret = -1;
                        goto end;
                }
        }
 
-       /* Only set an event id if none was explicitly set before */
-       event_id = bt_ctf_event_class_get_id(event_class);
-       if (event_id < 0) {
+       /* Only set an event ID if none was explicitly set before */
+       *event_id = bt_ctf_event_class_get_id(event_class);
+       if (*event_id < 0) {
                if (bt_ctf_event_class_set_id(event_class,
                        stream_class->next_event_id++)) {
                        ret = -1;
                        goto end;
                }
+               *event_id = stream_class->next_event_id;
        }
 
-       ret = bt_ctf_event_class_set_stream_class(event_class, stream_class);
+       ret = bt_ctf_event_class_set_stream_id(event_class, stream_class->id);
        if (ret) {
                goto end;
        }
 
-       ret = bt_ctf_event_class_set_stream_id(event_class, stream_class->id);
-       if (ret) {
-               goto end;
+       bt_object_set_parent(event_class, stream_class);
+
+       if (trace) {
+               /*
+                * At this point we know that the function will be
+                * successful. Therefore we can replace the event
+                * class's field types with what's in the validation
+                * output structure and mark this event class as valid.
+                */
+               bt_ctf_validation_replace_types(NULL, NULL, event_class,
+                       &validation_output, validation_flags);
+               event_class->valid = 1;
+
+               /*
+                * Put what was not moved in
+                * bt_ctf_validation_replace_types().
+                */
+               bt_ctf_validation_output_put_types(&validation_output);
        }
 
-       bt_ctf_event_class_get(event_class);
+       /* Add to the event classes of the stream class */
        g_ptr_array_add(stream_class->event_classes, event_class);
+       g_hash_table_insert(stream_class->event_classes_ht, event_id,
+                       event_class);
+       event_id = NULL;
+
+       /* Freeze the event class */
        bt_ctf_event_class_freeze(event_class);
 
        if (stream_class->byte_order) {
@@ -385,12 +465,31 @@ int bt_ctf_stream_class_add_event_class(
                 * when the stream class was added to a trace.
                 *
                 * If not set here, this will be set when the stream
-                * classe will be added to a trace.
+                * class is added to a trace.
                 */
                bt_ctf_event_class_set_native_byte_order(event_class,
                        stream_class->byte_order);
        }
+
+       /* Notifiy listeners of the trace's schema modification. */
+       if (trace) {
+               struct bt_ctf_object obj = { .object = event_class,
+                               .type = BT_CTF_OBJECT_TYPE_EVENT_CLASS };
+
+               (void) bt_ctf_trace_object_modification(&obj, trace);
+       }
 end:
+       BT_PUT(trace);
+       BT_PUT(old_stream_class);
+       bt_ctf_validation_output_put_types(&validation_output);
+       assert(!packet_header_type);
+       assert(!packet_context_type);
+       assert(!event_header_type);
+       assert(!stream_event_ctx_type);
+       assert(!event_context_type);
+       assert(!event_payload_type);
+       g_free(event_id);
+
        return ret;
 }
 
@@ -420,7 +519,7 @@ struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class(
        }
 
        event_class = g_ptr_array_index(stream_class->event_classes, index);
-       bt_ctf_event_class_get(event_class);
+       bt_get(event_class);
 end:
        return event_class;
 }
@@ -443,7 +542,7 @@ struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class_by_name(
 
                if (!strcmp(name, cur_event_class_name)) {
                        event_class = cur_event_class;
-                       bt_ctf_event_class_get(event_class);
+                       bt_get(event_class);
                        goto end;
                }
        }
@@ -454,23 +553,16 @@ end:
 struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class_by_id(
                struct bt_ctf_stream_class *stream_class, uint32_t id)
 {
-       size_t i;
+       int64_t id_key = id;
        struct bt_ctf_event_class *event_class = NULL;
 
        if (!stream_class) {
                goto end;
        }
 
-       for (i = 0; i < stream_class->event_classes->len; i++) {
-               struct bt_ctf_event_class *current_event_class =
-                       g_ptr_array_index(stream_class->event_classes, i);
-
-               if (bt_ctf_event_class_get_id(current_event_class) == id) {
-                       event_class = current_event_class;
-                       bt_ctf_event_class_get(event_class);
-                       goto end;
-               }
-       }
+       event_class = g_hash_table_lookup(stream_class->event_classes_ht,
+                       &id_key);
+       bt_get(event_class);
 end:
        return event_class;
 }
@@ -484,8 +576,7 @@ struct bt_ctf_field_type *bt_ctf_stream_class_get_packet_context_type(
                goto end;
        }
 
-       assert(stream_class->packet_context_type);
-       bt_ctf_field_type_get(stream_class->packet_context_type);
+       bt_get(stream_class->packet_context_type);
        ret = stream_class->packet_context_type;
 end:
        return ret;
@@ -497,24 +588,21 @@ int bt_ctf_stream_class_set_packet_context_type(
 {
        int ret = 0;
 
-       if (!stream_class || !packet_context_type || stream_class->frozen) {
+       if (!stream_class || stream_class->frozen) {
                ret = -1;
                goto end;
        }
 
-       assert(stream_class->packet_context_type);
-       if (stream_class->packet_context_type == packet_context_type) {
-               goto end;
-       }
-       if (bt_ctf_field_type_get_type_id(packet_context_type) !=
-               CTF_TYPE_STRUCT) {
-               /* A packet context must be a structure */
+       if (packet_context_type &&
+                       bt_ctf_field_type_get_type_id(packet_context_type) !=
+                               BT_CTF_TYPE_ID_STRUCT) {
+               /* A packet context must be a structure. */
                ret = -1;
                goto end;
        }
 
-       bt_ctf_field_type_put(stream_class->packet_context_type);
-       bt_ctf_field_type_get(packet_context_type);
+       bt_put(stream_class->packet_context_type);
+       bt_get(packet_context_type);
        stream_class->packet_context_type = packet_context_type;
 end:
        return ret;
@@ -529,8 +617,7 @@ struct bt_ctf_field_type *bt_ctf_stream_class_get_event_header_type(
                goto end;
        }
 
-       assert(stream_class->event_header_type);
-       bt_ctf_field_type_get(stream_class->event_header_type);
+       bt_get(stream_class->event_header_type);
        ret = stream_class->event_header_type;
 end:
        return ret;
@@ -542,25 +629,21 @@ int bt_ctf_stream_class_set_event_header_type(
 {
        int ret = 0;
 
-       if (!stream_class || !event_header_type || stream_class->frozen) {
+       if (!stream_class || stream_class->frozen) {
                ret = -1;
                goto end;
        }
 
-       assert(stream_class->event_header_type);
-       if (stream_class->event_header_type == event_header_type) {
-               goto end;
-       }
-       if (bt_ctf_field_type_get_type_id(event_header_type) !=
-               CTF_TYPE_STRUCT) {
-               /* An event header must be a structure */
+       if (event_header_type &&
+                       bt_ctf_field_type_get_type_id(event_header_type) !=
+                               BT_CTF_TYPE_ID_STRUCT) {
+               /* An event header must be a structure. */
                ret = -1;
                goto end;
        }
 
-       bt_ctf_field_type_put(stream_class->event_header_type);
-       bt_ctf_field_type_get(event_header_type);
-       stream_class->event_header_type = event_header_type;
+       bt_put(stream_class->event_header_type);
+       stream_class->event_header_type = bt_get(event_header_type);
 end:
        return ret;
 }
@@ -574,8 +657,7 @@ struct bt_ctf_field_type *bt_ctf_stream_class_get_event_context_type(
                goto end;
        }
 
-       assert(stream_class->event_context_type);
-       bt_ctf_field_type_get(stream_class->event_context_type);
+       bt_get(stream_class->event_context_type);
        ret = stream_class->event_context_type;
 end:
        return ret;
@@ -587,41 +669,77 @@ int bt_ctf_stream_class_set_event_context_type(
 {
        int ret = 0;
 
-       if (!stream_class || !event_context_type || stream_class->frozen) {
+       if (!stream_class || stream_class->frozen) {
                ret = -1;
                goto end;
        }
 
-       if (bt_ctf_field_type_get_type_id(event_context_type) !=
-               CTF_TYPE_STRUCT) {
-               /* A packet context must be a structure */
+       if (event_context_type &&
+                       bt_ctf_field_type_get_type_id(event_context_type) !=
+                               BT_CTF_TYPE_ID_STRUCT) {
+               /* A packet context must be a structure. */
                ret = -1;
                goto end;
        }
 
-       bt_ctf_field_type_put(stream_class->event_context_type);
-       bt_ctf_field_type_get(event_context_type);
-       stream_class->event_context_type = event_context_type;
+       bt_put(stream_class->event_context_type);
+       stream_class->event_context_type = bt_get(event_context_type);
 end:
        return ret;
 }
 
 void bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class)
 {
-       if (!stream_class) {
-               return;
-       }
-
-       bt_ctf_ref_get(&stream_class->ref_count);
+       bt_get(stream_class);
 }
 
 void bt_ctf_stream_class_put(struct bt_ctf_stream_class *stream_class)
 {
-       if (!stream_class) {
-               return;
+       bt_put(stream_class);
+}
+
+static
+int get_event_class_count(void *element)
+{
+       return bt_ctf_stream_class_get_event_class_count(
+                       (struct bt_ctf_stream_class *) element);
+}
+
+static
+void *get_event_class(void *element, int i)
+{
+       return bt_ctf_stream_class_get_event_class(
+                       (struct bt_ctf_stream_class *) element, i);
+}
+
+static
+int visit_event_class(void *object, bt_ctf_visitor visitor,void *data)
+{
+       struct bt_ctf_object obj =
+                       { .object = object,
+                       .type = BT_CTF_OBJECT_TYPE_EVENT_CLASS };
+
+       return visitor(&obj, data);
+}
+
+int bt_ctf_stream_class_visit(struct bt_ctf_stream_class *stream_class,
+               bt_ctf_visitor visitor, void *data)
+{
+       int ret;
+       struct bt_ctf_object obj =
+                       { .object = stream_class,
+                       .type = BT_CTF_OBJECT_TYPE_STREAM_CLASS };
+
+       if (!stream_class || !visitor) {
+               ret = -1;
+               goto end;
        }
 
-       bt_ctf_ref_put(&stream_class->ref_count, bt_ctf_stream_class_destroy);
+       ret = visitor_helper(&obj, get_event_class_count,
+                       get_event_class,
+                       visit_event_class, visitor, data);
+end:
+       return ret;
 }
 
 BT_HIDDEN
@@ -635,56 +753,38 @@ void bt_ctf_stream_class_freeze(struct bt_ctf_stream_class *stream_class)
        bt_ctf_field_type_freeze(stream_class->event_header_type);
        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);
+
+       if (stream_class->clock) {
+               bt_ctf_clock_class_freeze(stream_class->clock->clock_class);
+       }
 }
 
 BT_HIDDEN
-int bt_ctf_stream_class_set_byte_order(struct bt_ctf_stream_class *stream_class,
-       enum bt_ctf_byte_order byte_order)
+void bt_ctf_stream_class_set_byte_order(
+       struct bt_ctf_stream_class *stream_class, int byte_order)
 {
-       int i, ret = 0;
-       int internal_byte_order;
+       int i;
 
-       /* 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) {
-               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;
+       assert(stream_class);
+       assert(byte_order == LITTLE_ENDIAN || byte_order == BIG_ENDIAN);
+       stream_class->byte_order = byte_order;
 
        /* Set native byte order to little or big endian */
        bt_ctf_field_type_set_native_byte_order(
-               stream_class->event_header_type, stream_class->byte_order);
+               stream_class->event_header_type, byte_order);
        bt_ctf_field_type_set_native_byte_order(
-               stream_class->packet_context_type, stream_class->byte_order);
+               stream_class->packet_context_type, byte_order);
        bt_ctf_field_type_set_native_byte_order(
-               stream_class->event_context_type, stream_class->byte_order);
+               stream_class->event_context_type, byte_order);
 
        /* Set all events' native 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));
+               struct bt_ctf_event_class *event_class =
+                       g_ptr_array_index(stream_class->event_classes, i);
+
+               bt_ctf_event_class_set_native_byte_order(event_class,
+                       byte_order);
        }
-end:
-       return ret;
 }
 
 BT_HIDDEN
@@ -710,11 +810,13 @@ int bt_ctf_stream_class_serialize(struct bt_ctf_stream_class *stream_class,
                goto end;
        }
 
-       g_string_append(context->string, ";\n\n\tpacket.context := ");
-       ret = bt_ctf_field_type_serialize(stream_class->packet_context_type,
-               context);
-       if (ret) {
-               goto end;
+       if (stream_class->packet_context_type) {
+               g_string_append(context->string, ";\n\n\tpacket.context := ");
+               ret = bt_ctf_field_type_serialize(stream_class->packet_context_type,
+                       context);
+               if (ret) {
+                       goto end;
+               }
        }
 
        if (stream_class->event_context_type) {
@@ -741,52 +843,18 @@ end:
        return ret;
 }
 
-BT_HIDDEN
-int bt_ctf_stream_class_set_trace(struct bt_ctf_stream_class *stream_class,
-               struct bt_ctf_trace *trace)
-{
-       int ret = 0;
-
-       if (!stream_class) {
-               ret = -1;
-               goto end;
-       }
-
-       if (stream_class->trace && trace) {
-               /* Already attached to a trace */
-               ret = -1;
-               goto end;
-       }
-
-       stream_class->trace = trace;
-end:
-       return ret;
-}
-
 static
-void bt_ctf_stream_class_destroy(struct bt_ctf_ref *ref)
+void bt_ctf_stream_class_destroy(struct bt_object *obj)
 {
        struct bt_ctf_stream_class *stream_class;
 
-       if (!ref) {
-               return;
-       }
-
-       stream_class = container_of(ref, struct bt_ctf_stream_class, ref_count);
-       bt_ctf_clock_put(stream_class->clock);
+       stream_class = container_of(obj, struct bt_ctf_stream_class, base);
+       bt_put(stream_class->clock);
 
+       if (stream_class->event_classes_ht) {
+               g_hash_table_destroy(stream_class->event_classes_ht);
+       }
        if (stream_class->event_classes) {
-               size_t i;
-
-               /* Unregister this stream class from the event classes */
-               for (i = 0; i < stream_class->event_classes->len; i++) {
-                       struct bt_ctf_event_class *event_class =
-                               g_ptr_array_index(stream_class->event_classes,
-                               i);
-
-                       bt_ctf_event_class_set_stream_class(event_class, NULL);
-               }
-
                g_ptr_array_free(stream_class->event_classes, TRUE);
        }
 
@@ -794,11 +862,9 @@ void bt_ctf_stream_class_destroy(struct bt_ctf_ref *ref)
                g_string_free(stream_class->name, TRUE);
        }
 
-       bt_ctf_field_type_put(stream_class->event_header_type);
-       bt_ctf_field_type_put(stream_class->packet_context_type);
-       if (stream_class->event_context_type) {
-               bt_ctf_field_type_put(stream_class->event_context_type);
-       }
+       bt_put(stream_class->event_header_type);
+       bt_put(stream_class->packet_context_type);
+       bt_put(stream_class->event_context_type);
        g_free(stream_class);
 }
 
@@ -831,16 +897,16 @@ int init_event_header(struct bt_ctf_stream_class *stream_class)
        }
 
        if (stream_class->event_header_type) {
-               bt_ctf_field_type_put(stream_class->event_header_type);
+               bt_put(stream_class->event_header_type);
        }
        stream_class->event_header_type = event_header_type;
 end:
        if (ret) {
-               bt_ctf_field_type_put(event_header_type);
+               bt_put(event_header_type);
        }
 
-       bt_ctf_field_type_put(_uint32_t);
-       bt_ctf_field_type_put(_uint64_t);
+       bt_put(_uint32_t);
+       bt_put(_uint64_t);
        return ret;
 }
 
@@ -892,16 +958,14 @@ int init_packet_context(struct bt_ctf_stream_class *stream_class)
                goto end;
        }
 
-       if (stream_class->packet_context_type) {
-               bt_ctf_field_type_put(stream_class->packet_context_type);
-       }
+       bt_put(stream_class->packet_context_type);
        stream_class->packet_context_type = packet_context_type;
 end:
        if (ret) {
-               bt_ctf_field_type_put(packet_context_type);
+               bt_put(packet_context_type);
                goto end;
        }
 
-       bt_ctf_field_type_put(_uint64_t);
+       bt_put(_uint64_t);
        return ret;
 }
This page took 0.033671 seconds and 4 git commands to generate.