lib: bt_object_{get,put}_ref(): accept a `const` parameter
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Mon, 3 Dec 2018 21:43:05 +0000 (16:43 -0500)
committerFrancis Deslauriers <francis.deslauriers@efficios.com>
Thu, 2 May 2019 20:50:15 +0000 (20:50 +0000)
This is the first step to make the whole API const-correct.
bt_object_get_ref() and bt_object_put_ref() are not considered to
logically modify the object: they change the reference count, but the
object's readable properties remain unchanged. Considering this, it is
simpler to have a single version of each of them accepting a const
object so as to be able to get and put const objects (eventually).

bt_object_put_ref() can have the effect of destroying/freeing the
object, just like Linux's kfree() does while accepting a `const void *`
parameter.

It is safe to cast away `const` in this library because the user only
passes opaque handles to functions (`struct bt_X *` types) pointing to
non-const objects defined by the library itself in writable memory
(usually through g_new0()).

In C++11, the equivalent of having a `const struct bt_X *` object on
which you can increment and decrement the reference count would be
having an `std::shared_ptr<const bt_X>` object: the wrapper is mutable,
but the contained object is const.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
29 files changed:
cli/babeltrace-cfg-cli-args-connect.c
cli/babeltrace-cfg-cli-args.c
cli/babeltrace-cfg.h
cli/babeltrace.c
include/babeltrace/object-internal.h
include/babeltrace/object.h
include/babeltrace/plugin/plugin-internal.h
lib/graph/component-class-sink-colander.c
lib/graph/component.c
lib/graph/iterator.c
lib/graph/notification/stream.c
lib/object.c
lib/plugin/plugin-so.c
lib/plugin/plugin.c
lib/trace-ir/clock-value.c
lib/trace-ir/event-class.c
lib/trace-ir/field-classes.c
lib/trace-ir/fields.c
lib/trace-ir/packet.c
lib/trace-ir/stream-class.c
lib/trace-ir/trace.c
plugins/ctf/common/metadata/ctf-meta-update-default-clock-classes.c
plugins/ctf/common/metadata/ctf-meta.h
plugins/ctf/common/metadata/visitor-generate-ir.c
plugins/ctf/common/notif-iter/notif-iter.c
plugins/ctf/fs-src/data-stream-file.c
plugins/ctf/fs-src/fs.c
plugins/utils/muxer/muxer.c
tests/lib/test_trace_ir_ref.c

index c22fe6ad2e8bf1f75c5a0ccebe4178dff25870fe..7b4961652b7c532dc7fc97debd5ab4a94c71b883 100644 (file)
@@ -296,7 +296,8 @@ static struct bt_config_component *find_component_in_array(GPtrArray *comps,
                struct bt_config_component *comp = g_ptr_array_index(comps, i);
 
                if (strcmp(name, comp->instance_name->str) == 0) {
-                       found_comp = bt_object_get_ref(comp);
+                       found_comp = comp;
+                       bt_object_get_ref(found_comp);
                        goto end;
                }
        }
index 80802fbedf022b6a04d009e2bae2048ec965fa92..784cd5fde70be99d171c590cc76d1e9f42f488ab 100644 (file)
@@ -1516,7 +1516,8 @@ struct bt_config *bt_config_base_create(enum bt_config_command command,
        cfg->command_needs_plugins = needs_plugins;
 
        if (initial_plugin_paths) {
-               cfg->plugin_paths = bt_object_get_ref(initial_plugin_paths);
+               cfg->plugin_paths = initial_plugin_paths;
+               bt_object_get_ref(cfg->plugin_paths);
        } else {
                cfg->plugin_paths = bt_private_value_array_create();
                if (!cfg->plugin_paths) {
@@ -3630,13 +3631,15 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
        struct implicit_component_args implicit_debug_info_args = { 0 };
        struct implicit_component_args implicit_muxer_args = { 0 };
        struct implicit_component_args implicit_trimmer_args = { 0 };
-       struct bt_private_value *plugin_paths =
-               bt_object_get_ref(initial_plugin_paths);
+       struct bt_private_value *plugin_paths;
        char error_buf[256] = { 0 };
        size_t i;
        struct bt_common_lttng_live_url_parts lttng_live_url_parts = { 0 };
        char *output = NULL;
 
+       plugin_paths = initial_plugin_paths;
+       bt_object_get_ref(plugin_paths);
+
        *retcode = 0;
 
        if (argc <= 1) {
index b63c6c5ced2e130f7e6cbe281638058b53f6294a..d72348d38da2a5b9b070937874d55e1156f032f2 100644 (file)
@@ -129,7 +129,10 @@ static inline
 struct bt_config_component *bt_config_get_component(GPtrArray *array,
                size_t index)
 {
-       return bt_object_get_ref(g_ptr_array_index(array, index));
+       struct bt_config_component *comp = g_ptr_array_index(array, index);
+
+       bt_object_get_ref(comp);
+       return comp;
 }
 
 int bt_config_append_plugin_paths(struct bt_private_value *plugin_paths,
index 8a917a79ba5ec413f06ca822806a5c89e29fea6e..71e5baf9bae93999ed4860883094d41ca7db3715 100644 (file)
@@ -138,7 +138,8 @@ void set_signal_handler(void)
 static
 void init_static_data(void)
 {
-       loaded_plugins = g_ptr_array_new_with_free_func(bt_object_put_ref);
+       loaded_plugins = g_ptr_array_new_with_free_func(
+               (GDestroyNotify) bt_object_put_ref);
 }
 
 static
@@ -287,7 +288,8 @@ struct bt_plugin *find_plugin(const char *name)
                }
        }
 
-       return bt_object_get_ref(plugin);
+       bt_object_get_ref(plugin);
+       return plugin;
 }
 
 typedef void *(*plugin_borrow_comp_cls_func_t)(struct bt_plugin *,
@@ -309,8 +311,8 @@ void *find_component_class_from_plugin(const char *plugin_name,
                goto end;
        }
 
-       comp_class = bt_object_get_ref(
-               plugin_borrow_comp_cls_func(plugin, comp_class_name));
+       comp_class = plugin_borrow_comp_cls_func(plugin, comp_class_name);
+       bt_object_get_ref(comp_class);
        BT_OBJECT_PUT_REF_AND_RESET(plugin);
 
 end:
@@ -787,7 +789,8 @@ void add_to_loaded_plugins(struct bt_plugin_set *plugin_set)
                        /* Add to global array. */
                        BT_LOGD("Adding plugin to loaded plugins: plugin-path=\"%s\"",
                                bt_plugin_get_name(plugin));
-                       g_ptr_array_add(loaded_plugins, bt_object_get_ref(plugin));
+                       bt_object_get_ref(plugin);
+                       g_ptr_array_add(loaded_plugins, plugin);
                }
        }
 }
@@ -2085,19 +2088,19 @@ int cmd_run_ctx_init(struct cmd_run_ctx *ctx, struct bt_config *cfg)
        ctx->cfg = cfg;
        ctx->connect_ports = false;
        ctx->src_components = g_hash_table_new_full(g_direct_hash,
-               g_direct_equal, NULL, bt_object_put_ref);
+               g_direct_equal, NULL, (GDestroyNotify) bt_object_put_ref);
        if (!ctx->src_components) {
                goto error;
        }
 
        ctx->flt_components = g_hash_table_new_full(g_direct_hash,
-               g_direct_equal, NULL, bt_object_put_ref);
+               g_direct_equal, NULL, (GDestroyNotify) bt_object_put_ref);
        if (!ctx->flt_components) {
                goto error;
        }
 
        ctx->sink_components = g_hash_table_new_full(g_direct_hash,
-               g_direct_equal, NULL, bt_object_put_ref);
+               g_direct_equal, NULL, (GDestroyNotify) bt_object_put_ref);
        if (!ctx->sink_components) {
                goto error;
        }
index ff11e90742fb0ad7ae0a5c1e8cb26d80e9ab86f8..b5a7a1f845f1efd54e911ad53cdc5ceb78c401c5 100644 (file)
@@ -36,10 +36,10 @@ typedef void (*bt_object_parent_is_owner_listener_func)(
                struct bt_object *);
 
 static inline
-void bt_object_get_no_null_check(struct bt_object *obj);
+void bt_object_get_no_null_check(const void *obj);
 
 static inline
-void bt_object_put_no_null_check(struct bt_object *obj);
+void bt_object_put_no_null_check(const void *obj);
 
 /*
  * Babeltrace object base.
@@ -89,24 +89,29 @@ struct bt_object {
 };
 
 static inline
-unsigned long long bt_object_get_ref_count(struct bt_object *obj)
+unsigned long long bt_object_get_ref_count(const struct bt_object *c_obj)
 {
+       struct bt_object *obj = (void *) c_obj;
+
        BT_ASSERT(obj);
        BT_ASSERT(obj->is_shared);
        return obj->ref_count;
 }
 
 static inline
-struct bt_object *bt_object_borrow_parent(struct bt_object *obj)
+struct bt_object *bt_object_borrow_parent(const struct bt_object *c_obj)
 {
+       struct bt_object *obj = (void *) c_obj;
+
        BT_ASSERT(obj);
        BT_ASSERT(obj->is_shared);
        return obj->parent;
 }
 
 static inline
-struct bt_object *bt_object_get_parent(struct bt_object *obj)
+struct bt_object *bt_object_get_parent(const struct bt_object *c_obj)
 {
+       struct bt_object *obj = (void *) c_obj;
        struct bt_object *parent = bt_object_borrow_parent(obj);
 
        if (parent) {
@@ -241,8 +246,10 @@ void bt_object_set_parent_is_owner_listener_func(struct bt_object *obj,
 }
 
 static inline
-void bt_object_inc_ref_count(struct bt_object *obj)
+void bt_object_inc_ref_count(const struct bt_object *c_obj)
 {
+       struct bt_object *obj = (void *) c_obj;
+
        BT_ASSERT(obj);
        BT_ASSERT(obj->is_shared);
        obj->ref_count++;
@@ -250,8 +257,10 @@ void bt_object_inc_ref_count(struct bt_object *obj)
 }
 
 static inline
-void bt_object_get_no_null_check_no_parent_check(struct bt_object *obj)
+void bt_object_get_no_null_check_no_parent_check(const struct bt_object *c_obj)
 {
+       struct bt_object *obj = (void *) c_obj;
+
        BT_ASSERT(obj);
        BT_ASSERT(obj->is_shared);
 
@@ -266,8 +275,10 @@ void bt_object_get_no_null_check_no_parent_check(struct bt_object *obj)
 }
 
 static inline
-void bt_object_get_no_null_check(struct bt_object *obj)
+void bt_object_get_no_null_check(const void *c_obj)
 {
+       struct bt_object *obj = (void *) c_obj;
+
        BT_ASSERT(obj);
        BT_ASSERT(obj->is_shared);
 
@@ -291,8 +302,10 @@ void bt_object_get_no_null_check(struct bt_object *obj)
 }
 
 static inline
-void bt_object_put_no_null_check(struct bt_object *obj)
+void bt_object_put_no_null_check(const void *c_obj)
 {
+       struct bt_object *obj = (void *) c_obj;
+
        BT_ASSERT(obj);
        BT_ASSERT(obj->is_shared);
        BT_ASSERT(obj->ref_count > 0);
index e72614fbe5eaad236f718e8cab60267a46296767..10f94c44518af8601b05544f186517ccdd23185b 100644 (file)
@@ -178,7 +178,7 @@ would destroy the object and leave a dangling pointer in \p _var_dst.
 
 @sa bt_object_put_ref(): Decrements the reference count of a Babeltrace object.
 */
-void *bt_object_get_ref(void *obj);
+void bt_object_get_ref(const void *obj);
 
 /**
 @brief Decrements the reference count of the Babeltrace object
@@ -202,7 +202,7 @@ former is generally safer.
        variable to another.
 @sa bt_object_get_ref(): Increments the reference count of a Babeltrace object.
 */
-void bt_object_put_ref(void *obj);
+void bt_object_put_ref(const void *obj);
 
 /**
 @}
index de1035c76f14ca6eaf9aa202c0e19856a4eb665e..7ca57ba9a34a6e0446952e36302e174862c20a53 100644 (file)
@@ -362,7 +362,8 @@ enum bt_plugin_status bt_plugin_add_component_class(
        }
 
        /* Add new component class */
-       g_ptr_array_add(comp_classes, bt_object_get_ref(comp_class));
+       bt_object_get_ref(comp_class);
+       g_ptr_array_add(comp_classes, comp_class);
 
        /* Special case for a shared object plugin */
        if (plugin->type == BT_PLUGIN_TYPE_SO) {
@@ -426,7 +427,8 @@ void bt_plugin_set_add_plugin(struct bt_plugin_set *plugin_set,
 {
        BT_ASSERT(plugin_set);
        BT_ASSERT(plugin);
-       g_ptr_array_add(plugin_set->plugins, bt_object_get_ref(plugin));
+       bt_object_get_ref(plugin);
+       g_ptr_array_add(plugin_set->plugins, plugin);
        BT_LIB_LOGV("Added plugin to plugin set: "
                "plugin-set-addr=%p, %![plugin-]+l",
                plugin_set, plugin);
index 712c473177c632cbe944315ab8a046f92e0c9fae..724d7de19f2b12bba3a5d0f304904fa17ae8d65e 100644 (file)
@@ -195,9 +195,8 @@ struct bt_component_class_sink *bt_component_class_sink_colander_get(void)
                colander_comp_cls, colander_input_port_connected);
 
 end:
-       return bt_object_get_ref(
-               bt_private_component_class_sink_as_component_class_sink(
-                       colander_comp_cls));
+       bt_object_get_ref(colander_comp_cls);
+       return (void *) colander_comp_cls;
 }
 
 __attribute__((destructor)) static
index 7bca1bfd7ef542fcc50aea65094c2c48fece7cbb..84a850100a91d505a18690d80d8e544f509ff8fd 100644 (file)
@@ -227,7 +227,8 @@ struct bt_port *add_port(
        /*
         * Notify the graph's creator that a new port was added.
         */
-       graph = bt_object_get_ref(bt_component_borrow_graph(component));
+       bt_object_get_ref(bt_component_borrow_graph(component));
+       graph = bt_component_borrow_graph(component);
        if (graph) {
                bt_graph_notify_port_added(graph, new_port);
                BT_OBJECT_PUT_REF_AND_RESET(graph);
@@ -278,7 +279,8 @@ int bt_component_create(struct bt_component_class *component_class,
 
        bt_object_init_shared_with_parent(&component->base,
                destroy_component);
-       component->class = bt_object_get_ref(component_class);
+       component->class = component_class;
+       bt_object_get_no_null_check(component->class);
        component->destroy = component_destroy_funcs[type];
        component->name = g_string_new(name);
        if (!component->name) {
index fd728ad7311febb651ac00f4ab8c178e352e338a..ffd2de5a28fa01b9e4ece401e307238b47463e64 100644 (file)
@@ -103,7 +103,8 @@ struct stream_state *create_stream_state(struct bt_stream *stream)
        /*
         * We keep a reference to the stream until we know it's ended.
         */
-       stream_state->stream = bt_object_get_ref(stream);
+       stream_state->stream = stream;
+       bt_object_get_no_null_check(stream_state->stream);
        BT_LIB_LOGV("Created stream state: %![stream-]+s, "
                "stream-state-addr=%p",
                stream, stream_state);
@@ -609,7 +610,8 @@ bool validate_notification(
                        goto end;
                }
                stream_state->expected_notif_seq_num++;
-               stream_state->cur_packet = bt_object_get_ref(packet);
+               stream_state->cur_packet = packet;
+               bt_object_get_no_null_check(stream_state->cur_packet);
                goto end;
        case BT_NOTIFICATION_TYPE_PACKET_END:
                if (!stream_state->cur_packet) {
@@ -956,7 +958,8 @@ bt_port_output_notification_iterator_create(
                goto error;
        }
 
-       iterator->graph = bt_object_get_ref(graph);
+       iterator->graph = graph;
+       bt_object_get_no_null_check(iterator->graph);
        colander_data.notifs = (void *) iterator->base.notifs->pdata;
        colander_data.count_addr = &iterator->count;
 
index f24194d81efea23f84488ca9f66cf02dd2d0868f..11af10b8e36c5b476c4684820596898b44173485 100644 (file)
@@ -78,7 +78,8 @@ struct bt_private_notification *bt_private_notification_stream_end_create(
        bt_notification_init(&notification->parent,
                        BT_NOTIFICATION_TYPE_STREAM_END,
                        bt_notification_stream_end_destroy, NULL);
-       notification->stream = bt_object_get_ref(stream);
+       notification->stream = stream;
+       bt_object_get_no_null_check(notification->stream);
        BT_LIB_LOGD("Created stream end notification object: "
                "%![notif-]+n, %![stream-]+s, %![sc-]+S", notification,
                stream, stream_class);
@@ -183,7 +184,8 @@ struct bt_private_notification *bt_private_notification_stream_begin_create(
        bt_notification_init(&notification->parent,
                        BT_NOTIFICATION_TYPE_STREAM_BEGIN,
                        bt_notification_stream_begin_destroy, NULL);
-       notification->stream = bt_object_get_ref(stream);
+       notification->stream = stream;
+       bt_object_get_no_null_check(notification->stream);
        BT_LIB_LOGD("Created stream beginning notification object: "
                "%![notif-]+n, %![stream-]+s, %![sc-]+S", notification,
                stream, stream_class);
index 600365441d25f495098ceb2d6fed8f6f18e9e33d..5194dd889b86c498990b346982523b692753286b 100644 (file)
@@ -26,9 +26,9 @@
 #include <babeltrace/assert-pre-internal.h>
 #include <babeltrace/object-internal.h>
 
-void *bt_object_get_ref(void *ptr)
+void bt_object_get_ref(const void *ptr)
 {
-       struct bt_object *obj = ptr;
+       struct bt_object *obj = (void *) ptr;
 
        if (unlikely(!obj)) {
                goto end;
@@ -38,12 +38,12 @@ void *bt_object_get_ref(void *ptr)
        bt_object_get_no_null_check(obj);
 
 end:
-       return ptr;
+       return;
 }
 
-void bt_object_put_ref(void *ptr)
+void bt_object_put_ref(const void *ptr)
 {
-       struct bt_object *obj = ptr;
+       struct bt_object *obj = (void *) ptr;
 
        if (unlikely(!obj)) {
                return;
index 9208dc535bb967b60661c000d868e2b5648f6799..1c3e348a04b759d07dcd5b56944fa99f84be37b7 100644 (file)
@@ -1130,7 +1130,8 @@ struct bt_plugin *bt_plugin_so_create_empty(
        }
 
        spec = plugin->spec_data;
-       spec->shared_lib_handle = bt_object_get_ref(shared_lib_handle);
+       spec->shared_lib_handle = shared_lib_handle;
+       bt_object_get_no_null_check(spec->shared_lib_handle);
        goto end;
 
 error:
@@ -1498,7 +1499,8 @@ void bt_plugin_so_on_add_component_class(struct bt_plugin *plugin,
        BT_ASSERT(plugin->type == BT_PLUGIN_TYPE_SO);
 
        bt_list_add(&comp_class->node, &component_class_list);
-       comp_class->so_handle = bt_object_get_ref(spec->shared_lib_handle);
+       comp_class->so_handle = spec->shared_lib_handle;
+       bt_object_get_no_null_check(comp_class->so_handle);
 
        /* Add our custom destroy listener */
        bt_component_class_add_destroy_listener(comp_class,
index f70f5c315af7a5697769828372a483bca63f0df7..70e99e4f033d7fd018c25e1efa546f48e7c3c55c 100644 (file)
@@ -271,7 +271,8 @@ struct bt_plugin *bt_plugin_find(const char *plugin_name)
                                        plugin_name) == 0) {
                                BT_LOGD("Plugin found in directory: name=\"%s\", path=\"%s\"",
                                        plugin_name, dir->str);
-                               plugin = bt_object_get_ref(candidate_plugin);
+                               plugin = candidate_plugin;
+                               bt_object_get_no_null_check(plugin);
                                goto end;
                        }
                }
@@ -291,7 +292,8 @@ struct bt_plugin *bt_plugin_find(const char *plugin_name)
                                        plugin_name) == 0) {
                                BT_LOGD("Plugin found in built-in plugins: "
                                        "name=\"%s\"", plugin_name);
-                               plugin = bt_object_get_ref(candidate_plugin);
+                               plugin = candidate_plugin;
+                               bt_object_get_no_null_check(plugin);
                                goto end;
                        }
                }
index affc565c02cd1a0f5eb543a952df10fdb995f296..32c4b8628861cd19ed434c9c0add82f88e51fae0 100644 (file)
@@ -58,7 +58,8 @@ struct bt_clock_value *bt_clock_value_new(struct bt_clock_class *clock_class)
        }
 
        bt_object_init_unique(&ret->base);
-       ret->clock_class = bt_object_get_ref(clock_class);
+       ret->clock_class = clock_class;
+       bt_object_get_no_null_check(clock_class);
        bt_clock_class_freeze(clock_class);
        BT_LIB_LOGD("Created clock value object: %!+k", ret);
 
@@ -80,7 +81,8 @@ struct bt_clock_value *bt_clock_value_create(struct bt_clock_class *clock_class)
        }
 
        if (likely(!clock_value->clock_class)) {
-               clock_value->clock_class = bt_object_get_ref(clock_class);
+               clock_value->clock_class = clock_class;
+               bt_object_get_no_null_check(clock_class);
        }
 
        goto end;
index 685c09c32b2153ce2d65bad7072a05e590de81f0..839e9a995aa94eb9963d792cd9fdb6cc7d0841ca 100644 (file)
@@ -334,7 +334,8 @@ int bt_private_event_class_set_specific_context_field_class(
 
        bt_field_class_make_part_of_trace(field_class);
        bt_object_put_ref(event_class->specific_context_fc);
-       event_class->specific_context_fc = bt_object_get_ref(field_class);
+       event_class->specific_context_fc = field_class;
+       bt_object_get_no_null_check(event_class->specific_context_fc);
        bt_field_class_freeze(field_class);
        BT_LIB_LOGV("Set event class's specific context field classe: %!+E",
                event_class);
@@ -399,7 +400,8 @@ int bt_private_event_class_set_payload_field_class(
 
        bt_field_class_make_part_of_trace(field_class);
        bt_object_put_ref(event_class->payload_fc);
-       event_class->payload_fc = bt_object_get_ref(field_class);
+       event_class->payload_fc = field_class;
+       bt_object_get_no_null_check(event_class->payload_fc);
        bt_field_class_freeze(field_class);
        BT_LIB_LOGV("Set event class's payload field classe: %!+E", event_class);
 
index 2adf0348b9d78a26daea2c2db31e636a53ce506b..325d18109058a8348872dbb886fb055bef18e785 100644 (file)
@@ -762,7 +762,8 @@ int append_named_field_class_to_container_field_class(
        named_fc = &g_array_index(container_fc->named_fcs,
                struct bt_named_field_class, container_fc->named_fcs->len - 1);
        named_fc->name = name_str;
-       named_fc->fc = bt_object_get_ref(fc);
+       named_fc->fc = fc;
+       bt_object_get_no_null_check(fc);
        g_hash_table_insert(container_fc->name_to_index, named_fc->name->str,
                GUINT_TO_POINTER(container_fc->named_fcs->len - 1));
        bt_field_class_freeze(fc);
@@ -924,7 +925,8 @@ int bt_private_field_class_variant_set_selector_field_class(
        BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_VARIANT, "Field class");
        BT_ASSERT_PRE_FC_IS_ENUM(selector_fc, "Selector field class");
        BT_ASSERT_PRE_FC_HOT(fc, "Variant field class");
-       var_fc->selector_fc = bt_object_get_ref(selector_fc);
+       var_fc->selector_fc = (void *) selector_fc;
+       bt_object_get_no_null_check(selector_fc);
        bt_field_class_freeze((void *) selector_fc);
        return 0;
 }
@@ -1003,7 +1005,8 @@ void init_array_field_class(struct bt_field_class_array *fc,
 {
        BT_ASSERT(element_fc);
        init_field_class((void *) fc, type, release_func);
-       fc->element_fc = bt_object_get_ref(element_fc);
+       fc->element_fc = element_fc;
+       bt_object_get_no_null_check(element_fc);
        bt_field_class_freeze(element_fc);
 }
 
@@ -1136,7 +1139,8 @@ int bt_private_field_class_dynamic_array_set_length_field_class(
                "Field class");
        BT_ASSERT_PRE_FC_IS_UNSIGNED_INT(length_fc, "Length field class");
        BT_ASSERT_PRE_FC_HOT(fc, "Dynamic array field class");
-       array_fc->length_fc = bt_object_get_ref(length_fc);
+       array_fc->length_fc = (void *) length_fc;
+       bt_object_get_no_null_check(length_fc);
        bt_field_class_freeze(length_fc);
        return 0;
 }
index 8eadc75711f9e902fbe187ae9e90a99dacec7865..c769c8a014b1361d9a94b26c84c0f7a5d0b106a8 100644 (file)
@@ -227,7 +227,8 @@ void init_field(struct bt_field *field, struct bt_field_class *fc,
        BT_ASSERT(fc);
        bt_object_init_unique(&field->base);
        field->methods = methods;
-       field->class = bt_object_get_ref(fc);
+       field->class = fc;
+       bt_object_get_no_null_check(fc);
 }
 
 static
index 983887c42ebe1166cd5a8612cf48d7f2e8ad1799..52f462a46d10f30b113f15744970ed2c5b310dac 100644 (file)
@@ -267,7 +267,8 @@ struct bt_packet *bt_packet_new(struct bt_stream *stream)
 
        bt_object_init_shared(&packet->base,
                (bt_object_release_func) bt_packet_recycle);
-       packet->stream = bt_object_get_ref(stream);
+       packet->stream = stream;
+       bt_object_get_no_null_check(stream);
        trace = bt_stream_class_borrow_trace_inline(stream->class);
        BT_ASSERT(trace);
 
index 9d016844f83bfe14038dbe1845e1bc78679607c8..6b33bca6473a2cc7e1bf5fa7cbc3ca513a2b3fa6 100644 (file)
@@ -345,7 +345,8 @@ int bt_private_stream_class_set_packet_context_field_class(
 
        bt_field_class_make_part_of_trace(field_class);
        bt_object_put_ref(stream_class->packet_context_fc);
-       stream_class->packet_context_fc = bt_object_get_ref(field_class);
+       stream_class->packet_context_fc = field_class;
+       bt_object_get_no_null_check(stream_class->packet_context_fc);
        bt_field_class_freeze(field_class);
        BT_LIB_LOGV("Set stream class's packet context field classe: %!+S",
                stream_class);
@@ -402,7 +403,8 @@ int bt_private_stream_class_set_event_header_field_class(
 
        bt_field_class_make_part_of_trace(field_class);
        bt_object_put_ref(stream_class->event_header_fc);
-       stream_class->event_header_fc = bt_object_get_ref(field_class);
+       stream_class->event_header_fc = field_class;
+       bt_object_get_no_null_check(stream_class->event_header_fc);
        bt_field_class_freeze(field_class);
        BT_LIB_LOGV("Set stream class's event header field classe: %!+S",
                stream_class);
@@ -460,7 +462,8 @@ int bt_private_stream_class_set_event_common_context_field_class(
 
        bt_field_class_make_part_of_trace(field_class);
        bt_object_put_ref(stream_class->event_common_context_fc);
-       stream_class->event_common_context_fc = bt_object_get_ref(field_class);
+       stream_class->event_common_context_fc = field_class;
+       bt_object_get_no_null_check(stream_class->event_common_context_fc);
        bt_field_class_freeze(field_class);
        BT_LIB_LOGV("Set stream class's event common context field classe: %!+S",
                stream_class);
@@ -488,7 +491,8 @@ int bt_private_stream_class_set_default_clock_class(
        BT_ASSERT_PRE_NON_NULL(clock_class, "Clock class");
        BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class);
        bt_object_put_ref(stream_class->default_clock_class);
-       stream_class->default_clock_class = bt_object_get_ref(clock_class);
+       stream_class->default_clock_class = clock_class;
+       bt_object_get_no_null_check(stream_class->default_clock_class);
        bt_clock_class_freeze(clock_class);
        BT_LIB_LOGV("Set stream class's default clock class: %!+S",
                stream_class);
index be791f36fe2142b4a65a561662f41abc2cfc0bfa..d33a4dc49710e8bfdafba85df38706e644c60f67 100644 (file)
@@ -525,7 +525,8 @@ int bt_private_trace_set_packet_header_field_class(
 
        bt_field_class_make_part_of_trace(field_class);
        bt_object_put_ref(trace->packet_header_fc);
-       trace->packet_header_fc = bt_object_get_ref(field_class);
+       trace->packet_header_fc = field_class;
+       bt_object_get_no_null_check(trace->packet_header_fc);
        bt_field_class_freeze(field_class);
        BT_LIB_LOGV("Set trace's packet header field classe: %!+t", trace);
 
index f2e48aae8fa081e2c072e02206638324f3380314..01d949466287b5652dd5ba8b1bc821420a4381cf 100644 (file)
@@ -164,7 +164,8 @@ int update_stream_class_default_clock_class(
        }
 
        if (!stream_class->default_clock_class) {
-               stream_class->default_clock_class = bt_object_get_ref(clock_class);
+               stream_class->default_clock_class = clock_class;
+               bt_object_get_ref(stream_class->default_clock_class);
        }
 
 end:
index cb84d77866031777a4dda929b5643058ac4ad26a..481a3b6c6206c38121b6c843baef0746454f0894 100644 (file)
@@ -1108,7 +1108,8 @@ void ctf_field_class_int_copy_content(
        dst_fc->is_signed = src_fc->is_signed;
        dst_fc->disp_base = src_fc->disp_base;
        dst_fc->encoding = src_fc->encoding;
-       dst_fc->mapped_clock_class = bt_object_get_ref(src_fc->mapped_clock_class);
+       dst_fc->mapped_clock_class = src_fc->mapped_clock_class;
+       bt_object_get_ref(dst_fc->mapped_clock_class);
        dst_fc->storing_index = src_fc->storing_index;
 }
 
index 44c4e92782ca698b254971668df7c5a94e994b33..69149a509592cebc8889b44b7709613161ee8f27 100644 (file)
@@ -2719,7 +2719,8 @@ int visit_integer_decl(struct ctx *ctx,
        (*integer_decl)->is_signed = (signedness > 0);
        (*integer_decl)->disp_base = base;
        (*integer_decl)->encoding = encoding;
-       (*integer_decl)->mapped_clock_class = bt_object_get_ref(mapped_clock_class);
+       (*integer_decl)->mapped_clock_class = mapped_clock_class;
+       bt_object_get_ref((*integer_decl)->mapped_clock_class);
        return 0;
 
 error:
@@ -3612,15 +3613,16 @@ int auto_map_field_to_trace_clock_class(struct ctx *ctx,
                        "default");
                BT_ASSERT(ret == 0);
                g_ptr_array_add(ctx->ctf_tc->clock_classes,
-                       bt_object_get_ref(clock_class_to_map_to));
+                       clock_class_to_map_to);
+               bt_object_get_ref(clock_class_to_map_to);
                break;
        case 1:
                /*
                 * Only one clock class exists in the trace at this point: use
                 * this one.
                 */
-               clock_class_to_map_to =
-                       bt_object_get_ref(ctx->ctf_tc->clock_classes->pdata[0]);
+               clock_class_to_map_to = ctx->ctf_tc->clock_classes->pdata[0];
+               bt_object_get_ref(clock_class_to_map_to);
                break;
        default:
                /*
@@ -3634,7 +3636,8 @@ int auto_map_field_to_trace_clock_class(struct ctx *ctx,
        }
 
        BT_ASSERT(clock_class_to_map_to);
-       int_fc->mapped_clock_class = bt_object_get_ref(clock_class_to_map_to);
+       int_fc->mapped_clock_class = clock_class_to_map_to;
+       bt_object_get_ref(int_fc->mapped_clock_class);
 
 end:
        bt_object_put_ref(clock_class_to_map_to);
@@ -4744,7 +4747,8 @@ int visit_clock_decl(struct ctx *ctx, struct ctf_node *clock_node)
                bt_private_clock_class_as_clock_class(clock)));
        bt_private_clock_class_set_offset(clock, offset_seconds, offset_cycles);
        apply_clock_class_offset(ctx, clock);
-       g_ptr_array_add(ctx->ctf_tc->clock_classes, bt_object_get_ref(clock));
+       g_ptr_array_add(ctx->ctf_tc->clock_classes, clock);
+       bt_object_get_ref(clock);
 
 end:
        BT_OBJECT_PUT_REF_AND_RESET(clock);
@@ -4902,7 +4906,8 @@ struct bt_private_trace *ctf_visitor_generate_ir_get_ir_trace(
 
        BT_ASSERT(ctx);
        BT_ASSERT(ctx->trace);
-       return bt_object_get_ref(ctx->trace);
+       bt_object_get_ref(ctx->trace);
+       return ctx->trace;
 }
 
 BT_HIDDEN
index 4ebff2ae0e6fa3462d49647ff297f67b59e64085..750f4a10c3a2367770b492773ffe327748c97069 100644 (file)
@@ -805,9 +805,10 @@ enum bt_notif_iter_status set_current_stream(struct bt_notif_iter *notit)
                "stream-class-addr=%p, stream-class-id=%" PRId64,
                notit, notit->meta.sc,
                notit->meta.sc->id);
-       stream = bt_object_get_ref(notit->medium.medops.borrow_stream(
+       stream = notit->medium.medops.borrow_stream(
                notit->meta.sc->ir_sc, notit->cur_data_stream_id,
-               notit->medium.data));
+               notit->medium.data);
+       bt_object_get_ref(stream);
        BT_LOGV("User function returned: stream-addr=%p", stream);
        if (!stream) {
                BT_LOGW_STR("User function failed to return a stream object "
index f700b02ffffec2a96f85584ddcb42cd328c68bc8..1a95ae0964e848eff0f1abfc84ebc2800e59ec70 100644 (file)
@@ -642,7 +642,8 @@ struct ctf_fs_ds_file *ctf_fs_ds_file_create(
                goto error;
        }
 
-       ds_file->stream = bt_object_get_ref(stream);
+       ds_file->stream = stream;
+       bt_object_get_ref(ds_file->stream);
        ds_file->metadata = ctf_fs_trace->metadata;
        g_string_assign(ds_file->file->path, path);
        ret = ctf_fs_file_open(ds_file->file, "rb");
index 082d8fa48c978647a50a7da06a1f196a06847fea..24bfa04a5ebeaa605e8245b770c0b33bf40173c6 100644 (file)
@@ -536,7 +536,8 @@ struct ctf_fs_ds_file_group *ctf_fs_ds_file_group_create(
 
        ds_file_group->stream_id = stream_instance_id;
        BT_ASSERT(stream_class);
-       ds_file_group->stream_class = bt_object_get_ref(stream_class);
+       ds_file_group->stream_class = stream_class;
+       bt_object_get_ref(ds_file_group->stream_class);
        ds_file_group->ctf_fs_trace = ctf_fs_trace;
        goto end;
 
index 8cd83299436b9e2c1a92632c012bea943def0283..275f8e7eae698ae9e2a8f30bfba8e86e629d3254 100644 (file)
@@ -151,7 +151,8 @@ struct muxer_upstream_notif_iter *muxer_notif_iter_add_upstream_notif_iter(
                goto end;
        }
 
-       muxer_upstream_notif_iter->notif_iter = bt_object_get_ref(self_notif_iter);
+       muxer_upstream_notif_iter->notif_iter = self_notif_iter;
+       bt_object_get_ref(muxer_upstream_notif_iter->notif_iter);
        muxer_upstream_notif_iter->notifs = g_queue_new();
        if (!muxer_upstream_notif_iter->notifs) {
                BT_LOGE_STR("Failed to allocate a GQueue.");
index 380fbe562ca855ef4759caea40552865cef7d51e..d8af80b97c49e1d01f5ff6e8a5b44af2072599ab 100644 (file)
@@ -360,9 +360,9 @@ static void test_example_scenario(void)
                        "TC1 reference count is 1");
 
        /* User A acquires a reference to SC2 from TC1. */
-       user_a.sc = bt_object_get_ref(
-               bt_private_trace_borrow_stream_class_by_index(
-                       user_a.tc, 1));
+       user_a.sc = bt_private_trace_borrow_stream_class_by_index(
+                       user_a.tc, 1);
+       bt_object_get_ref(user_a.sc);
        ok(user_a.sc, "User A acquires SC2 from TC1");
        ok(bt_object_get_ref_count((void *) weak_tc1) == 2,
                        "TC1 reference count is 2");
@@ -370,9 +370,9 @@ static void test_example_scenario(void)
                        "SC2 reference count is 1");
 
        /* User A acquires a reference to EC3 from SC2. */
-       user_a.ec = bt_object_get_ref(
-               bt_private_stream_class_borrow_event_class_by_index(
-                       user_a.sc, 0));
+       user_a.ec = bt_private_stream_class_borrow_event_class_by_index(
+                       user_a.sc, 0);
+       bt_object_get_ref(user_a.ec);
        ok(user_a.ec, "User A acquires EC3 from SC2");
        ok(bt_object_get_ref_count((void *) weak_tc1) == 2,
                        "TC1 reference count is 2");
@@ -411,7 +411,8 @@ static void test_example_scenario(void)
 
        /* User B acquires a reference to SC1. */
        diag("User B acquires a reference to SC1");
-       user_b.sc = bt_object_get_ref(weak_sc1);
+       user_b.sc = weak_sc1;
+       bt_object_get_ref(user_b.sc);
        ok(bt_object_get_ref_count((void *) weak_tc1) == 2,
                        "TC1 reference count is 2");
        ok(bt_object_get_ref_count((void *) weak_sc1) == 1,
@@ -419,9 +420,9 @@ static void test_example_scenario(void)
 
        /* User C acquires a reference to EC1. */
        diag("User C acquires a reference to EC1");
-       user_c.ec = bt_object_get_ref(
-               bt_private_stream_class_borrow_event_class_by_index(
-                       user_b.sc, 0));
+       user_c.ec = bt_private_stream_class_borrow_event_class_by_index(
+                       user_b.sc, 0);
+       bt_object_get_ref(user_c.ec);
        ok(bt_object_get_ref_count((void *) weak_ec1) == 1,
                        "EC1 reference count is 1");
        ok(bt_object_get_ref_count((void *) weak_sc1) == 2,
This page took 0.040698 seconds and 4 git commands to generate.