lib: trace IR, values: reset pointers to `NULL` on destruction
[babeltrace.git] / lib / trace-ir / event-class.c
index e47c77f8548a485d60c3629b868d96ed5f6851e1..685c09c32b2153ce2d65bad7072a05e590de81f0 100644 (file)
@@ -1,8 +1,4 @@
 /*
- * event-class.c
- *
- * Babeltrace trace IR - Event class
- *
  * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
  *
  * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
 #include <babeltrace/trace-ir/fields-internal.h>
 #include <babeltrace/trace-ir/field-classes.h>
 #include <babeltrace/trace-ir/field-classes-internal.h>
+#include <babeltrace/trace-ir/private-event-class.h>
 #include <babeltrace/trace-ir/event-class.h>
 #include <babeltrace/trace-ir/event-class-internal.h>
 #include <babeltrace/trace-ir/event-internal.h>
+#include <babeltrace/trace-ir/private-stream-class.h>
 #include <babeltrace/trace-ir/stream-class.h>
 #include <babeltrace/trace-ir/stream-class-internal.h>
 #include <babeltrace/trace-ir/trace-internal.h>
 #include <babeltrace/trace-ir/utils-internal.h>
 #include <babeltrace/trace-ir/resolve-field-path-internal.h>
-#include <babeltrace/ref.h>
+#include <babeltrace/object.h>
 #include <babeltrace/trace-ir/attributes-internal.h>
 #include <babeltrace/compiler-internal.h>
 #include <babeltrace/endian-internal.h>
@@ -53,7 +51,8 @@
 #include <stdlib.h>
 
 #define BT_ASSERT_PRE_EVENT_CLASS_HOT(_ec) \
-       BT_ASSERT_PRE_HOT((_ec), "Event class", ": %!+E", (_ec))
+       BT_ASSERT_PRE_HOT(((struct bt_event_class *) (_ec)),            \
+               "Event class", ": %!+E", (_ec))
 
 static
 void destroy_event_class(struct bt_object *obj)
@@ -64,16 +63,18 @@ void destroy_event_class(struct bt_object *obj)
 
        if (event_class->name.str) {
                g_string_free(event_class->name.str, TRUE);
+               event_class->name.str = NULL;
        }
 
        if (event_class->emf_uri.str) {
                g_string_free(event_class->emf_uri.str, TRUE);
+               event_class->emf_uri.str = NULL;
        }
 
        BT_LOGD_STR("Putting context field classe.");
-       bt_put(event_class->specific_context_fc);
+       BT_OBJECT_PUT_REF_AND_RESET(event_class->specific_context_fc);
        BT_LOGD_STR("Putting payload field classe.");
-       bt_put(event_class->payload_fc);
+       BT_OBJECT_PUT_REF_AND_RESET(event_class->payload_fc);
        bt_object_pool_finalize(&event_class->event_pool);
        g_free(obj);
 }
@@ -161,30 +162,34 @@ struct bt_event_class *create_event_class_with_id(
        goto end;
 
 error:
-       BT_PUT(event_class);
+       BT_OBJECT_PUT_REF_AND_RESET(event_class);
 
 end:
        return event_class;
 }
 
-struct bt_event_class *bt_event_class_create(
-               struct bt_stream_class *stream_class)
+struct bt_private_event_class *bt_private_event_class_create(
+               struct bt_private_stream_class *priv_stream_class)
 {
+       struct bt_stream_class *stream_class = (void *) priv_stream_class;
+
        BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
        BT_ASSERT_PRE(stream_class->assigns_automatic_event_class_id,
                "Stream class does not automatically assigns event class IDs: "
                "%![sc-]+S", stream_class);
-       return create_event_class_with_id(stream_class,
+       return (void *) create_event_class_with_id((void *) stream_class,
                (uint64_t) stream_class->event_classes->len);
 }
 
-struct bt_event_class *bt_event_class_create_with_id(
-               struct bt_stream_class *stream_class, uint64_t id)
+struct bt_private_event_class *bt_private_event_class_create_with_id(
+               struct bt_private_stream_class *priv_stream_class, uint64_t id)
 {
+       struct bt_stream_class *stream_class = (void *) priv_stream_class;
+
        BT_ASSERT_PRE(!stream_class->assigns_automatic_event_class_id,
                "Stream class automatically assigns event class IDs: "
                "%![sc-]+S", stream_class);
-       return create_event_class_with_id(stream_class, id);
+       return (void *) create_event_class_with_id((void *) stream_class, id);
 }
 
 const char *bt_event_class_get_name(struct bt_event_class *event_class)
@@ -193,9 +198,11 @@ const char *bt_event_class_get_name(struct bt_event_class *event_class)
        return event_class->name.value;
 }
 
-int bt_event_class_set_name(struct bt_event_class *event_class,
+int bt_private_event_class_set_name(struct bt_private_event_class *priv_event_class,
                const char *name)
 {
+       struct bt_event_class *event_class = (void *) priv_event_class;
+
        BT_ASSERT_PRE_NON_NULL(event_class, "Event class");
        BT_ASSERT_PRE_NON_NULL(name, "Name");
        BT_ASSERT_PRE_EVENT_CLASS_HOT(event_class);
@@ -222,15 +229,17 @@ enum bt_property_availability bt_event_class_get_log_level(
        return event_class->log_level.base.avail;
 }
 
-int bt_event_class_set_log_level(struct bt_event_class *event_class,
+void bt_private_event_class_set_log_level(
+               struct bt_private_event_class *priv_event_class,
                enum bt_event_class_log_level log_level)
 {
+       struct bt_event_class *event_class = (void *) priv_event_class;
+
        BT_ASSERT_PRE_NON_NULL(event_class, "Event class");
        BT_ASSERT_PRE_EVENT_CLASS_HOT(event_class);
        bt_property_uint_set(&event_class->log_level,
                (uint64_t) log_level);
        BT_LIB_LOGV("Set event class's log level: %!+E", event_class);
-       return 0;
 }
 
 const char *bt_event_class_get_emf_uri(struct bt_event_class *event_class)
@@ -239,9 +248,12 @@ const char *bt_event_class_get_emf_uri(struct bt_event_class *event_class)
        return event_class->emf_uri.value;
 }
 
-int bt_event_class_set_emf_uri(struct bt_event_class *event_class,
+int bt_private_event_class_set_emf_uri(
+               struct bt_private_event_class *priv_event_class,
                const char *emf_uri)
 {
+       struct bt_event_class *event_class = (void *) priv_event_class;
+
        BT_ASSERT_PRE_NON_NULL(event_class, "Event class");
        BT_ASSERT_PRE_NON_NULL(emf_uri, "EMF URI");
        BT_ASSERT_PRE_EVENT_CLASS_HOT(event_class);
@@ -258,6 +270,14 @@ struct bt_stream_class *bt_event_class_borrow_stream_class(
        return bt_event_class_borrow_stream_class_inline(event_class);
 }
 
+struct bt_private_stream_class *
+bt_private_event_class_borrow_stream_class(
+               struct bt_private_event_class *event_class)
+{
+       return (void *) bt_event_class_borrow_stream_class(
+               (void *) event_class);
+}
+
 struct bt_field_class *bt_event_class_borrow_specific_context_field_class(
                struct bt_event_class *event_class)
 {
@@ -265,11 +285,21 @@ struct bt_field_class *bt_event_class_borrow_specific_context_field_class(
        return event_class->specific_context_fc;
 }
 
-int bt_event_class_set_specific_context_field_class(
-               struct bt_event_class *event_class,
-               struct bt_field_class *field_class)
+struct bt_private_field_class *
+bt_private_event_class_borrow_specific_context_field_class(
+               struct bt_private_event_class *event_class)
+{
+       return (void *) bt_event_class_borrow_specific_context_field_class(
+               (void *) event_class);
+}
+
+int bt_private_event_class_set_specific_context_field_class(
+               struct bt_private_event_class *priv_event_class,
+               struct bt_private_field_class *priv_field_class)
 {
        int ret;
+       struct bt_event_class *event_class = (void *) priv_event_class;
+       struct bt_field_class *field_class = (void *) priv_field_class;
        struct bt_stream_class *stream_class;
        struct bt_trace *trace;
        struct bt_resolve_field_path_context resolve_ctx = {
@@ -284,8 +314,8 @@ int bt_event_class_set_specific_context_field_class(
        BT_ASSERT_PRE_NON_NULL(event_class, "Event class");
        BT_ASSERT_PRE_NON_NULL(field_class, "Field class");
        BT_ASSERT_PRE_EVENT_CLASS_HOT(event_class);
-       BT_ASSERT_PRE(bt_field_class_get_id(field_class) ==
-               BT_FIELD_CLASS_ID_STRUCTURE,
+       BT_ASSERT_PRE(bt_field_class_get_type(field_class) ==
+               BT_FIELD_CLASS_TYPE_STRUCTURE,
                "Specific context field classe is not a structure field classe: "
                "%!+F", field_class);
        stream_class = bt_event_class_borrow_stream_class_inline(
@@ -303,8 +333,8 @@ int bt_event_class_set_specific_context_field_class(
        }
 
        bt_field_class_make_part_of_trace(field_class);
-       bt_put(event_class->specific_context_fc);
-       event_class->specific_context_fc = bt_get(field_class);
+       bt_object_put_ref(event_class->specific_context_fc);
+       event_class->specific_context_fc = bt_object_get_ref(field_class);
        bt_field_class_freeze(field_class);
        BT_LIB_LOGV("Set event class's specific context field classe: %!+E",
                event_class);
@@ -320,10 +350,20 @@ struct bt_field_class *bt_event_class_borrow_payload_field_class(
        return event_class->payload_fc;
 }
 
-int bt_event_class_set_payload_field_class(struct bt_event_class *event_class,
-               struct bt_field_class *field_class)
+struct bt_private_field_class *bt_private_event_class_borrow_payload_field_class(
+               struct bt_private_event_class *event_class)
+{
+       return (void *) bt_event_class_borrow_payload_field_class(
+               (void *) event_class);
+}
+
+int bt_private_event_class_set_payload_field_class(
+               struct bt_private_event_class *priv_event_class,
+               struct bt_private_field_class *priv_field_class)
 {
        int ret;
+       struct bt_event_class *event_class = (void *) priv_event_class;
+       struct bt_field_class *field_class = (void *) priv_field_class;
        struct bt_stream_class *stream_class;
        struct bt_trace *trace;
        struct bt_resolve_field_path_context resolve_ctx = {
@@ -338,8 +378,8 @@ int bt_event_class_set_payload_field_class(struct bt_event_class *event_class,
        BT_ASSERT_PRE_NON_NULL(event_class, "Event class");
        BT_ASSERT_PRE_NON_NULL(field_class, "Field class");
        BT_ASSERT_PRE_EVENT_CLASS_HOT(event_class);
-       BT_ASSERT_PRE(bt_field_class_get_id(field_class) ==
-               BT_FIELD_CLASS_ID_STRUCTURE,
+       BT_ASSERT_PRE(bt_field_class_get_type(field_class) ==
+               BT_FIELD_CLASS_TYPE_STRUCTURE,
                "Payload field classe is not a structure field classe: %!+F",
                field_class);
        stream_class = bt_event_class_borrow_stream_class_inline(
@@ -358,8 +398,8 @@ int bt_event_class_set_payload_field_class(struct bt_event_class *event_class,
        }
 
        bt_field_class_make_part_of_trace(field_class);
-       bt_put(event_class->payload_fc);
-       event_class->payload_fc = bt_get(field_class);
+       bt_object_put_ref(event_class->payload_fc);
+       event_class->payload_fc = bt_object_get_ref(field_class);
        bt_field_class_freeze(field_class);
        BT_LIB_LOGV("Set event class's payload field classe: %!+E", event_class);
 
This page took 0.028557 seconds and 4 git commands to generate.