lib: trace IR, values: reset pointers to `NULL` on destruction
[babeltrace.git] / lib / trace-ir / stream-class.c
index cc51cced718acaf6a8757e7b27251d8caafbcd71..9d016844f83bfe14038dbe1845e1bc78679607c8 100644 (file)
@@ -1,8 +1,4 @@
 /*
- * stream-class.c
- *
- * Babeltrace trace IR - Stream Class
- *
  * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
  *
  * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
@@ -35,6 +31,8 @@
 #include <babeltrace/trace-ir/field-classes-internal.h>
 #include <babeltrace/trace-ir/fields-internal.h>
 #include <babeltrace/trace-ir/stream-class-internal.h>
+#include <babeltrace/trace-ir/private-trace.h>
+#include <babeltrace/trace-ir/trace-internal.h>
 #include <babeltrace/trace-ir/utils-internal.h>
 #include <babeltrace/trace-ir/field-wrapper-internal.h>
 #include <babeltrace/trace-ir/resolve-field-path-internal.h>
@@ -58,23 +56,26 @@ void destroy_stream_class(struct bt_object *obj)
 
        BT_LIB_LOGD("Destroying stream class: %!+S", stream_class);
        BT_LOGD_STR("Putting default clock class.");
-       bt_object_put_ref(stream_class->default_clock_class);
+       BT_OBJECT_PUT_REF_AND_RESET(stream_class->default_clock_class);
 
        if (stream_class->event_classes) {
                BT_LOGD_STR("Destroying event classes.");
                g_ptr_array_free(stream_class->event_classes, TRUE);
+               stream_class->event_classes = NULL;
        }
 
        if (stream_class->name.str) {
                g_string_free(stream_class->name.str, TRUE);
+               stream_class->name.str = NULL;
+               stream_class->name.value = NULL;
        }
 
        BT_LOGD_STR("Putting event header field classe.");
-       bt_object_put_ref(stream_class->event_header_fc);
+       BT_OBJECT_PUT_REF_AND_RESET(stream_class->event_header_fc);
        BT_LOGD_STR("Putting packet context field classe.");
-       bt_object_put_ref(stream_class->packet_context_fc);
+       BT_OBJECT_PUT_REF_AND_RESET(stream_class->packet_context_fc);
        BT_LOGD_STR("Putting event common context field classe.");
-       bt_object_put_ref(stream_class->event_common_context_fc);
+       BT_OBJECT_PUT_REF_AND_RESET(stream_class->event_common_context_fc);
        bt_object_pool_finalize(&stream_class->event_header_field_pool);
        bt_object_pool_finalize(&stream_class->packet_context_field_pool);
        g_free(stream_class);
@@ -180,24 +181,29 @@ end:
        return stream_class;
 }
 
-struct bt_stream_class *bt_stream_class_create(struct bt_trace *trace)
+struct bt_private_stream_class *bt_private_stream_class_create(
+               struct bt_private_trace *priv_trace)
 {
+       struct bt_trace *trace = (void *) priv_trace;
+
        BT_ASSERT_PRE_NON_NULL(trace, "Trace");
        BT_ASSERT_PRE(trace->assigns_automatic_stream_class_id,
                "Trace does not automatically assigns stream class IDs: "
                "%![sc-]+t", trace);
-       return create_stream_class_with_id(trace,
+       return (void *) create_stream_class_with_id(trace,
                (uint64_t) trace->stream_classes->len);
 }
 
-struct bt_stream_class *bt_stream_class_create_with_id(
-               struct bt_trace *trace, uint64_t id)
+struct bt_private_stream_class *bt_private_stream_class_create_with_id(
+               struct bt_private_trace *priv_trace, uint64_t id)
 {
+       struct bt_trace *trace = (void *) priv_trace;
+
        BT_ASSERT_PRE_NON_NULL(trace, "Trace");
        BT_ASSERT_PRE(!trace->assigns_automatic_stream_class_id,
                "Trace automatically assigns stream class IDs: "
                "%![sc-]+t", trace);
-       return create_stream_class_with_id(trace, id);
+       return (void *) create_stream_class_with_id(trace, id);
 }
 
 struct bt_trace *bt_stream_class_borrow_trace(struct bt_stream_class *stream_class)
@@ -206,15 +212,24 @@ struct bt_trace *bt_stream_class_borrow_trace(struct bt_stream_class *stream_cla
        return bt_stream_class_borrow_trace_inline(stream_class);
 }
 
+struct bt_private_trace *bt_private_stream_class_borrow_trace(
+               struct bt_private_stream_class *stream_class)
+{
+       return (void *) bt_stream_class_borrow_trace((void *) stream_class);
+}
+
 const char *bt_stream_class_get_name(struct bt_stream_class *stream_class)
 {
        BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
        return stream_class->name.value;
 }
 
-int bt_stream_class_set_name(struct bt_stream_class *stream_class,
+int bt_private_stream_class_set_name(
+               struct bt_private_stream_class *priv_stream_class,
                const char *name)
 {
+       struct bt_stream_class *stream_class = (void *) priv_stream_class;
+
        BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
        BT_ASSERT_PRE_NON_NULL(name, "Name");
        BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class);
@@ -245,17 +260,25 @@ struct bt_event_class *bt_stream_class_borrow_event_class_by_index(
        return g_ptr_array_index(stream_class->event_classes, index);
 }
 
+struct bt_private_event_class *
+bt_private_stream_class_borrow_event_class_by_index(
+               struct bt_private_stream_class *stream_class, uint64_t index)
+{
+       return (void *) bt_stream_class_borrow_event_class_by_index(
+               (void *) stream_class, index);
+}
+
 struct bt_event_class *bt_stream_class_borrow_event_class_by_id(
-               struct bt_stream_class *trace, uint64_t id)
+               struct bt_stream_class *stream_class, uint64_t id)
 {
        struct bt_event_class *event_class = NULL;
        uint64_t i;
 
-       BT_ASSERT_PRE_NON_NULL(trace, "Trace");
+       BT_ASSERT_PRE_NON_NULL(stream_class, "Trace");
 
-       for (i = 0; i < trace->event_classes->len; i++) {
+       for (i = 0; i < stream_class->event_classes->len; i++) {
                struct bt_event_class *event_class_candidate =
-                       g_ptr_array_index(trace->event_classes, i);
+                       g_ptr_array_index(stream_class->event_classes, i);
 
                if (event_class_candidate->id == id) {
                        event_class = event_class_candidate;
@@ -267,6 +290,14 @@ end:
        return event_class;
 }
 
+struct bt_private_event_class *
+bt_private_stream_class_borrow_event_class_by_id(
+               struct bt_private_stream_class *stream_class, uint64_t id)
+{
+       return (void *) bt_stream_class_borrow_event_class_by_id(
+               (void *) stream_class, id);
+}
+
 struct bt_field_class *bt_stream_class_borrow_packet_context_field_class(
                struct bt_stream_class *stream_class)
 {
@@ -274,11 +305,21 @@ struct bt_field_class *bt_stream_class_borrow_packet_context_field_class(
        return stream_class->packet_context_fc;
 }
 
-int bt_stream_class_set_packet_context_field_class(
-               struct bt_stream_class *stream_class,
-               struct bt_field_class *field_class)
+struct bt_private_field_class *
+bt_private_stream_class_borrow_packet_context_field_class(
+               struct bt_private_stream_class *stream_class)
+{
+       return (void *) bt_stream_class_borrow_packet_context_field_class(
+               (void *) stream_class);
+}
+
+int bt_private_stream_class_set_packet_context_field_class(
+               struct bt_private_stream_class *priv_stream_class,
+               struct bt_private_field_class *priv_field_class)
 {
        int ret;
+       struct bt_stream_class *stream_class = (void *) priv_stream_class;
+       struct bt_field_class *field_class = (void *) priv_field_class;
        struct bt_resolve_field_path_context resolve_ctx = {
                .packet_header = NULL,
                .packet_context = field_class,
@@ -320,11 +361,21 @@ struct bt_field_class *bt_stream_class_borrow_event_header_field_class(
        return stream_class->event_header_fc;
 }
 
-int bt_stream_class_set_event_header_field_class(
-               struct bt_stream_class *stream_class,
-               struct bt_field_class *field_class)
+struct bt_private_field_class *
+bt_private_stream_class_borrow_event_header_field_class(
+               struct bt_private_stream_class *stream_class)
+{
+       return (void *) bt_stream_class_borrow_event_header_field_class(
+               (void *) stream_class);
+}
+
+int bt_private_stream_class_set_event_header_field_class(
+               struct bt_private_stream_class *priv_stream_class,
+               struct bt_private_field_class *priv_field_class)
 {
        int ret;
+       struct bt_stream_class *stream_class = (void *) priv_stream_class;
+       struct bt_field_class *field_class = (void *) priv_field_class;
        struct bt_resolve_field_path_context resolve_ctx = {
                .packet_header = NULL,
                .packet_context = NULL,
@@ -367,11 +418,21 @@ struct bt_field_class *bt_stream_class_borrow_event_common_context_field_class(
        return stream_class->event_common_context_fc;
 }
 
-int bt_stream_class_set_event_common_context_field_class(
-               struct bt_stream_class *stream_class,
-               struct bt_field_class *field_class)
+struct bt_private_field_class *
+bt_private_stream_class_borrow_event_common_context_field_class(
+               struct bt_private_stream_class *stream_class)
+{
+       return (void *) bt_stream_class_borrow_event_common_context_field_class(
+               (void *) stream_class);
+}
+
+int bt_private_stream_class_set_event_common_context_field_class(
+               struct bt_private_stream_class *priv_stream_class,
+               struct bt_private_field_class *priv_field_class)
 {
        int ret;
+       struct bt_stream_class *stream_class = (void *) priv_stream_class;
+       struct bt_field_class *field_class = (void *) priv_field_class;
        struct bt_resolve_field_path_context resolve_ctx = {
                .packet_header = NULL,
                .packet_context = NULL,
@@ -417,10 +478,12 @@ void _bt_stream_class_freeze(struct bt_stream_class *stream_class)
        stream_class->frozen = true;
 }
 
-int bt_stream_class_set_default_clock_class(
-               struct bt_stream_class *stream_class,
+int bt_private_stream_class_set_default_clock_class(
+               struct bt_private_stream_class *priv_stream_class,
                struct bt_clock_class *clock_class)
 {
+       struct bt_stream_class *stream_class = (void *) priv_stream_class;
+
        BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
        BT_ASSERT_PRE_NON_NULL(clock_class, "Clock class");
        BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class);
@@ -446,15 +509,17 @@ bt_bool bt_stream_class_assigns_automatic_event_class_id(
        return (bt_bool) stream_class->assigns_automatic_event_class_id;
 }
 
-int bt_stream_class_set_assigns_automatic_event_class_id(
-               struct bt_stream_class *stream_class, bt_bool value)
+void bt_private_stream_class_set_assigns_automatic_event_class_id(
+               struct bt_private_stream_class *priv_stream_class,
+               bt_bool value)
 {
+       struct bt_stream_class *stream_class = (void *) priv_stream_class;
+
        BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
        BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class);
        stream_class->assigns_automatic_event_class_id = (bool) value;
        BT_LIB_LOGV("Set stream class's automatic event class ID "
                "assignment property: %!+S", stream_class);
-       return 0;
 }
 
 bt_bool bt_stream_class_assigns_automatic_stream_id(
@@ -464,15 +529,17 @@ bt_bool bt_stream_class_assigns_automatic_stream_id(
        return (bt_bool) stream_class->assigns_automatic_stream_id;
 }
 
-int bt_stream_class_set_assigns_automatic_stream_id(
-               struct bt_stream_class *stream_class, bt_bool value)
+void bt_private_stream_class_set_assigns_automatic_stream_id(
+               struct bt_private_stream_class *priv_stream_class,
+               bt_bool value)
 {
+       struct bt_stream_class *stream_class = (void *) priv_stream_class;
+
        BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
        BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class);
        stream_class->assigns_automatic_stream_id = (bool) value;
        BT_LIB_LOGV("Set stream class's automatic stream ID "
                "assignment property: %!+S", stream_class);
-       return 0;
 }
 
 bt_bool bt_stream_class_packets_have_discarded_event_counter_snapshot(
@@ -482,9 +549,12 @@ bt_bool bt_stream_class_packets_have_discarded_event_counter_snapshot(
        return (bt_bool) stream_class->packets_have_discarded_event_counter_snapshot;
 }
 
-int bt_stream_class_set_packets_have_discarded_event_counter_snapshot(
-               struct bt_stream_class *stream_class, bt_bool value)
+void bt_private_stream_class_set_packets_have_discarded_event_counter_snapshot(
+               struct bt_private_stream_class *priv_stream_class,
+               bt_bool value)
 {
+       struct bt_stream_class *stream_class = (void *) priv_stream_class;
+
        BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
        BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class);
        stream_class->packets_have_discarded_event_counter_snapshot =
@@ -492,7 +562,6 @@ int bt_stream_class_set_packets_have_discarded_event_counter_snapshot(
        BT_LIB_LOGV("Set stream class's "
                "\"packets have discarded event counter snapshot\" property: "
                "%!+S", stream_class);
-       return 0;
 }
 
 bt_bool bt_stream_class_packets_have_packet_counter_snapshot(
@@ -502,9 +571,12 @@ bt_bool bt_stream_class_packets_have_packet_counter_snapshot(
        return (bt_bool) stream_class->packets_have_packet_counter_snapshot;
 }
 
-int bt_stream_class_set_packets_have_packet_counter_snapshot(
-               struct bt_stream_class *stream_class, bt_bool value)
+void bt_private_stream_class_set_packets_have_packet_counter_snapshot(
+               struct bt_private_stream_class *priv_stream_class,
+               bt_bool value)
 {
+       struct bt_stream_class *stream_class = (void *) priv_stream_class;
+
        BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
        BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class);
        stream_class->packets_have_packet_counter_snapshot =
@@ -512,7 +584,6 @@ int bt_stream_class_set_packets_have_packet_counter_snapshot(
        BT_LIB_LOGV("Set stream class's "
                "\"packets have packet counter snapshot\" property: "
                "%!+S", stream_class);
-       return 0;
 }
 
 bt_bool bt_stream_class_packets_have_default_beginning_clock_value(
@@ -522,9 +593,12 @@ bt_bool bt_stream_class_packets_have_default_beginning_clock_value(
        return (bt_bool) stream_class->packets_have_default_beginning_cv;
 }
 
-int bt_stream_class_set_packets_have_default_beginning_clock_value(
-               struct bt_stream_class *stream_class, bt_bool value)
+void bt_private_stream_class_set_packets_have_default_beginning_clock_value(
+               struct bt_private_stream_class *priv_stream_class,
+               bt_bool value)
 {
+       struct bt_stream_class *stream_class = (void *) priv_stream_class;
+
        BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
        BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class);
        BT_ASSERT_PRE(!value || stream_class->default_clock_class,
@@ -534,7 +608,6 @@ int bt_stream_class_set_packets_have_default_beginning_clock_value(
        BT_LIB_LOGV("Set stream class's "
                "\"packets have default beginning clock value\" property: "
                "%!+S", stream_class);
-       return 0;
 }
 
 bt_bool bt_stream_class_packets_have_default_end_clock_value(
@@ -544,9 +617,12 @@ bt_bool bt_stream_class_packets_have_default_end_clock_value(
        return (bt_bool) stream_class->packets_have_default_end_cv;
 }
 
-int bt_stream_class_set_packets_have_default_end_clock_value(
-               struct bt_stream_class *stream_class, bt_bool value)
+void bt_private_stream_class_set_packets_have_default_end_clock_value(
+               struct bt_private_stream_class *priv_stream_class,
+               bt_bool value)
 {
+       struct bt_stream_class *stream_class = (void *) priv_stream_class;
+
        BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
        BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class);
        BT_ASSERT_PRE(!value || stream_class->default_clock_class,
@@ -556,7 +632,6 @@ int bt_stream_class_set_packets_have_default_end_clock_value(
        BT_LIB_LOGV("Set stream class's "
                "\"packets have default end clock value\" property: "
                "%!+S", stream_class);
-       return 0;
 }
 
 bt_bool bt_stream_class_default_clock_is_always_known(
This page took 0.02879 seconds and 4 git commands to generate.