Before this patch, the following functions return a new reference when
their last parameter is not `NULL`:
* bt_graph_add_filter_component()
* bt_graph_add_filter_component_with_initialize_method_data()
* bt_graph_add_simple_sink_component()
* bt_graph_add_sink_component()
* bt_graph_add_sink_component_with_initialize_method_data()
* bt_graph_add_source_component()
* bt_graph_add_source_component_with_initialize_method_data()
* bt_graph_connect_ports()
* bt_self_component_filter_add_input_port()
* bt_self_component_filter_add_output_port()
* bt_self_component_sink_add_input_port()
* bt_self_component_source_add_output_port()
I'm changing this so that they return a borrowed reference instead. This
is more in line with other non-creating functions which always return
borrowed references.
It's okay to borrow here because the object to which you add an object
becomes its owner anyway.
Most sites are updated by removing the *_put_ref() call as the reference
is now borrowed.
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I71a5e18760504d8f8610162e3f6d7bd8d87474f9
Reviewed-on: https://review.lttng.org/c/babeltrace/+/2762
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
comp_status, 'cannot add output port to source component object'
)
assert self_port_ptr is not None
comp_status, 'cannot add output port to source component object'
)
assert self_port_ptr is not None
- return bt2_port._UserComponentOutputPort._create_from_ptr(self_port_ptr)
+ return bt2_port._UserComponentOutputPort._create_from_ptr_and_get_ref(
+ self_port_ptr
+ )
class _UserFilterComponent(_UserComponent, _FilterComponentConst):
class _UserFilterComponent(_UserComponent, _FilterComponentConst):
comp_status, 'cannot add output port to filter component object'
)
assert self_port_ptr
comp_status, 'cannot add output port to filter component object'
)
assert self_port_ptr
- return bt2_port._UserComponentOutputPort._create_from_ptr(self_port_ptr)
+ return bt2_port._UserComponentOutputPort._create_from_ptr_and_get_ref(
+ self_port_ptr
+ )
def _add_input_port(self, name, user_data=None):
utils._check_str(name)
def _add_input_port(self, name, user_data=None):
utils._check_str(name)
comp_status, 'cannot add input port to filter component object'
)
assert self_port_ptr
comp_status, 'cannot add input port to filter component object'
)
assert self_port_ptr
- return bt2_port._UserComponentInputPort._create_from_ptr(self_port_ptr)
+ return bt2_port._UserComponentInputPort._create_from_ptr_and_get_ref(
+ self_port_ptr
+ )
class _UserSinkComponent(_UserComponent, _SinkComponentConst):
class _UserSinkComponent(_UserComponent, _SinkComponentConst):
comp_status, 'cannot add input port to sink component object'
)
assert self_port_ptr
comp_status, 'cannot add input port to sink component object'
)
assert self_port_ptr
- return bt2_port._UserComponentInputPort._create_from_ptr(self_port_ptr)
+ return bt2_port._UserComponentInputPort._create_from_ptr_and_get_ref(
+ self_port_ptr
+ )
def _create_message_iterator(self, input_port):
utils._check_type(input_port, bt2_port._UserComponentInputPort)
def _create_message_iterator(self, input_port):
utils._check_type(input_port, bt2_port._UserComponentInputPort)
)
utils._handle_func_status(status, 'cannot add component to graph')
assert comp_ptr
)
utils._handle_func_status(status, 'cannot add component to graph')
assert comp_ptr
- return bt2_component._create_component_from_const_ptr(comp_ptr, cc_type)
+ return bt2_component._create_component_from_const_ptr_and_get_ref(
+ comp_ptr, cc_type
+ )
def connect_ports(self, upstream_port, downstream_port):
utils._check_type(upstream_port, bt2_port._OutputPortConst)
def connect_ports(self, upstream_port, downstream_port):
utils._check_type(upstream_port, bt2_port._OutputPortConst)
)
utils._handle_func_status(status, 'cannot connect component ports within graph')
assert conn_ptr
)
utils._handle_func_status(status, 'cannot connect component ports within graph')
assert conn_ptr
- return bt2_connection._ConnectionConst._create_from_ptr(conn_ptr)
+ return bt2_connection._ConnectionConst._create_from_ptr_and_get_ref(conn_ptr)
def add_port_added_listener(self, listener):
if not callable(listener):
def add_port_added_listener(self, listener):
if not callable(listener):
ctx->graph, trimmer_class, trimmer_name,
trimmer_params, ctx->cfg->log_level,
&trimmer);
ctx->graph, trimmer_class, trimmer_name,
trimmer_params, ctx->cfg->log_level,
&trimmer);
+ bt_component_filter_get_ref(trimmer);
free(trimmer_name);
if (add_comp_status !=
BT_GRAPH_ADD_COMPONENT_STATUS_OK) {
free(trimmer_name);
if (add_comp_status !=
BT_GRAPH_ADD_COMPONENT_STATUS_OK) {
comp_cls, cfg_comp->instance_name->str,
cfg_comp->params, cfg_comp->log_level,
(void *) &comp);
comp_cls, cfg_comp->instance_name->str,
cfg_comp->params, cfg_comp->log_level,
(void *) &comp);
+ bt_component_source_get_ref(comp);
break;
case BT_COMPONENT_CLASS_TYPE_FILTER:
ret = bt_graph_add_filter_component(ctx->graph,
comp_cls, cfg_comp->instance_name->str,
cfg_comp->params, cfg_comp->log_level,
(void *) &comp);
break;
case BT_COMPONENT_CLASS_TYPE_FILTER:
ret = bt_graph_add_filter_component(ctx->graph,
comp_cls, cfg_comp->instance_name->str,
cfg_comp->params, cfg_comp->log_level,
(void *) &comp);
+ bt_component_filter_get_ref(comp);
break;
case BT_COMPONENT_CLASS_TYPE_SINK:
ret = bt_graph_add_sink_component(ctx->graph,
comp_cls, cfg_comp->instance_name->str,
cfg_comp->params, cfg_comp->log_level,
(void *) &comp);
break;
case BT_COMPONENT_CLASS_TYPE_SINK:
ret = bt_graph_add_sink_component(ctx->graph,
comp_cls, cfg_comp->instance_name->str,
cfg_comp->params, cfg_comp->log_level,
(void *) &comp);
+ bt_component_sink_get_ref(comp);
break;
default:
bt_common_abort();
break;
default:
bt_common_abort();
if (self_port) {
/* Move reference to user */
*self_port = (void *) port;
if (self_port) {
/* Move reference to user */
*self_port = (void *) port;
if (self_port) {
/* Move reference to user */
*self_port = (void *) port;
if (self_port) {
/* Move reference to user */
*self_port = (void *) port;
if (self_port) {
/* Move reference to user */
*self_port = (void *) port;
if (self_port) {
/* Move reference to user */
*self_port = (void *) port;
if (self_port) {
/* Move reference to user */
*self_port = (void *) port;
if (self_port) {
/* Move reference to user */
*self_port = (void *) port;
if (user_connection) {
/* Move reference to user */
*user_connection = connection;
if (user_connection) {
/* Move reference to user */
*user_connection = connection;
if (user_component) {
/* Move reference to user */
*user_component = component;
if (user_component) {
/* Move reference to user */
*user_component = component;
"the-sink", NULL, BT_LOGGING_LEVEL_NONE, &sink_component);
ok(graph_ret == BT_GRAPH_ADD_COMPONENT_STATUS_OK && sink_component,
"bt_graph_add_sink_component() still works after the plugin object is destroyed");
"the-sink", NULL, BT_LOGGING_LEVEL_NONE, &sink_component);
ok(graph_ret == BT_GRAPH_ADD_COMPONENT_STATUS_OK && sink_component,
"bt_graph_add_sink_component() still works after the plugin object is destroyed");
- BT_COMPONENT_SINK_PUT_REF_AND_RESET(sink_component);
bt_graph_put_ref(graph);
free(sfs_path);
bt_graph_put_ref(graph);
free(sfs_path);
ok(src_port_connected_pos < graph_port_added_src_pos,
"event order is good");
ok(src_port_connected_pos < graph_port_added_src_pos,
"event order is good");
- bt_component_source_put_ref(src);
- bt_component_sink_put_ref(sink);
bt_graph_put_ref(graph);
}
bt_graph_put_ref(graph);
}
event.data.sink_comp_input_port_connected.other_port = gsrc_def_port;
ok(has_event(&event), "got the expected sink's port connected event");
event.data.sink_comp_input_port_connected.other_port = gsrc_def_port;
ok(has_event(&event), "got the expected sink's port connected event");
- bt_component_sink_put_ref(sink);
- bt_component_source_put_ref(src);
ok(has_event(&event), "got the expected source's port connected event");
bt_graph_put_ref(graph);
ok(has_event(&event), "got the expected source's port connected event");
bt_graph_put_ref(graph);
- bt_component_sink_put_ref(sink);
- bt_component_source_put_ref(src);
- bt_connection_put_ref(conn);
event.data.sink_comp_input_port_connected.other_port = gsrc_def_port;
ok(has_event(&event), "got the expected sink's port connected event");
event.data.sink_comp_input_port_connected.other_port = gsrc_def_port;
ok(has_event(&event), "got the expected sink's port connected event");
- bt_connection_put_ref(conn);
- bt_component_sink_put_ref(sink);
- bt_component_source_put_ref(src);
BT_LOGGING_LEVEL_WARNING, &source);
BT_ASSERT(add_component_status == BT_GRAPH_ADD_COMPONENT_STATUS_OK);
BT_LOGGING_LEVEL_WARNING, &source);
BT_ASSERT(add_component_status == BT_GRAPH_ADD_COMPONENT_STATUS_OK);
- bt_component_source_put_ref(source);
bt_component_class_source_put_ref(source_cc);
bt_message_iterator_class_put_ref(msg_iter_cls);
bt_graph_put_ref(graph);
bt_component_class_source_put_ref(source_cc);
bt_message_iterator_class_put_ref(msg_iter_cls);
bt_graph_put_ref(graph);
*out_port = bt_component_source_borrow_output_port_by_index_const(
src_comp, 0);
BT_ASSERT(*out_port);
*out_port = bt_component_source_borrow_output_port_by_index_const(
src_comp, 0);
BT_ASSERT(*out_port);
- bt_component_source_put_ref(src_comp);
bt_component_class_source_put_ref(src_comp_cls);
bt_message_iterator_class_put_ref(msg_iter_cls);
return graph;
bt_component_class_source_put_ref(src_comp_cls);
bt_message_iterator_class_put_ref(msg_iter_cls);
return graph;
ok((run_once_status < 0) == (err != NULL),
"Current thread error is set if bt_graph_run_once returned an error");
ok((run_once_status < 0) == (err != NULL),
"Current thread error is set if bt_graph_run_once returned an error");
- bt_component_sink_put_ref(sink_comp);
bt_graph_put_ref(graph);
if (err) {
bt_error_release(err);
bt_graph_put_ref(graph);
if (err) {
bt_error_release(err);