From: Philippe Proulx Date: Wed, 28 Feb 2018 23:37:29 +0000 (-0500) Subject: Replace assert() -> BT_ASSERT() and some preconditions with BT_ASSERT_PRE() X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=f6ccaed94e575af57fe6bf38154771bee4871a2a Replace assert() -> BT_ASSERT() and some preconditions with BT_ASSERT_PRE() In the whole project: replace assert() with BT_ASSERT(), and include instead of . This means that, from now on, logic/postcondition assertions are disabled by default: you need to enable them explicitly with `BABELTRACE_DEBUG_MODE=1` when configuring the project. In the library: replace the precondition checks which actively occur while a graph is running with BT_ASSERT_PRE() or other helpers that are only enabled in developer mode. Those are mostly checks for `bt_event`, `bt_packet`, `bt_field`, `bt_notification`, and `bt_value` objects. Frozen and validation flags for those objects are now only handled in developer mode. The concept of set/unset fields is also only handled in developer mode. This is why some internal functions have their name prefixed with `_` and a macro is used instead to do nothing when in non-developer mode (e.g., bt_field_freeze() calls _bt_field_freeze() in developer mode and does nothing in non-developer mode). The transformation of unconditional run-time precondition checks to using BT_ASSERT_PRE() is not done for the notification iterator object. This is a separate concern with different challenges which will be implemented in a subsequent patch. Tests which check that API functions fail when preconditions are not satisfied in `tests/lib/test_bt_values.c` and `tests/lib/test_ctf_writer.c` are removed. From my point of view, checking for those preconditions is not part of the API now: it is only a service provided for developers in developer mode. In other words, because a library user cannot expect a specific reaction when not satisfying the required preconditions, you cannot unit-test them either. What is important is to validate that the library works as expected when used as expected. Signed-off-by: Philippe Proulx --- diff --git a/bindings/python/bt2/bt2/native_bt.i b/bindings/python/bt2/bt2/native_bt.i index 62964f25..7ac34206 100644 --- a/bindings/python/bt2/bt2/native_bt.i +++ b/bindings/python/bt2/bt2/native_bt.i @@ -33,6 +33,7 @@ #include "logging.h" #include +#include typedef const unsigned char *BTUUID; %} @@ -199,16 +200,16 @@ static enum bt_notification_type *bt_py3_notif_types_from_py_list( enum bt_notification_type *notification_types = NULL; size_t i; - assert(!PyErr_Occurred()); + BT_ASSERT(!PyErr_Occurred()); if (py_notif_types == Py_None) { goto end; } - assert(PyList_Check(py_notif_types)); + BT_ASSERT(PyList_Check(py_notif_types)); notification_types = g_new0(enum bt_notification_type, PyList_Size(py_notif_types) + 1); - assert(notification_types); + BT_ASSERT(notification_types); notification_types[PyList_Size(py_notif_types)] = BT_NOTIFICATION_TYPE_SENTINEL; @@ -217,10 +218,10 @@ static enum bt_notification_type *bt_py3_notif_types_from_py_list( long value; int overflow; - assert(item); - assert(PyLong_Check(item)); + BT_ASSERT(item); + BT_ASSERT(PyLong_Check(item)); value = PyLong_AsLongAndOverflow(item, &overflow); - assert(overflow == 0); + BT_ASSERT(overflow == 0); notification_types[i] = value; } diff --git a/bindings/python/bt2/bt2/native_btcomponentclass.i b/bindings/python/bt2/bt2/native_btcomponentclass.i index 43077230..2e296567 100644 --- a/bindings/python/bt2/bt2/native_btcomponentclass.i +++ b/bindings/python/bt2/bt2/native_btcomponentclass.i @@ -75,7 +75,7 @@ static void register_cc_ptr_to_py_cls(struct bt_component_class *bt_cc, */ BT_LOGD_STR("Creating native component class to Python component class hash table."); bt_cc_ptr_to_py_cls = g_hash_table_new(g_direct_hash, g_direct_equal); - assert(bt_cc_ptr_to_py_cls); + BT_ASSERT(bt_cc_ptr_to_py_cls); } g_hash_table_insert(bt_cc_ptr_to_py_cls, (gpointer) bt_cc, @@ -120,28 +120,28 @@ static void bt_py3_cc_init_from_bt2(void) * code here without importing bt2 first. */ py_mod_bt2 = PyImport_ImportModule("bt2"); - assert(py_mod_bt2); + BT_ASSERT(py_mod_bt2); py_mod_bt2_exc_error_type = PyObject_GetAttrString(py_mod_bt2, "Error"); - assert(py_mod_bt2_exc_error_type); + BT_ASSERT(py_mod_bt2_exc_error_type); py_mod_bt2_exc_unsupported_feature_type = PyObject_GetAttrString(py_mod_bt2, "UnsupportedFeature"); - assert(py_mod_bt2_exc_unsupported_feature_type); + BT_ASSERT(py_mod_bt2_exc_unsupported_feature_type); py_mod_bt2_exc_try_again_type = PyObject_GetAttrString(py_mod_bt2, "TryAgain"); - assert(py_mod_bt2_exc_try_again_type); + BT_ASSERT(py_mod_bt2_exc_try_again_type); py_mod_bt2_exc_stop_type = PyObject_GetAttrString(py_mod_bt2, "Stop"); - assert(py_mod_bt2_exc_stop_type); + BT_ASSERT(py_mod_bt2_exc_stop_type); py_mod_bt2_exc_port_connection_refused_type = PyObject_GetAttrString(py_mod_bt2, "PortConnectionRefused"); - assert(py_mod_bt2_exc_port_connection_refused_type); + BT_ASSERT(py_mod_bt2_exc_port_connection_refused_type); py_mod_bt2_exc_invalid_query_object_type = PyObject_GetAttrString(py_mod_bt2, "InvalidQueryObject"); - assert(py_mod_bt2_exc_invalid_query_object_type); + BT_ASSERT(py_mod_bt2_exc_invalid_query_object_type); py_mod_bt2_exc_invalid_query_params_type = PyObject_GetAttrString(py_mod_bt2, "InvalidQueryParams"); - assert(py_mod_bt2_exc_invalid_query_params_type); + BT_ASSERT(py_mod_bt2_exc_invalid_query_params_type); } static void bt_py3_cc_exit_handler(void) @@ -284,8 +284,8 @@ static enum bt_component_status bt_py3_cc_init( PyObject *py_comp_ptr = NULL; (void) init_method_data; - assert(comp); - assert(comp_cls); + BT_ASSERT(comp); + BT_ASSERT(comp_cls); /* * Get the user-defined Python class which created this @@ -365,7 +365,7 @@ static void bt_py3_cc_finalize(struct bt_private_component *priv_comp) PyObject *py_comp = bt_private_component_get_user_data(priv_comp); PyObject *py_method_result = NULL; - assert(py_comp); + BT_ASSERT(py_comp); /* Call user's _finalize() method */ py_method_result = PyObject_CallMethod(py_comp, @@ -397,7 +397,7 @@ static enum bt_component_status bt_py3_cc_accept_port_connection( PyObject *py_method_result = NULL; py_comp = bt_private_component_get_user_data(priv_comp); - assert(py_comp); + BT_ASSERT(py_comp); py_self_port_ptr = SWIG_NewPointerObj(SWIG_as_voidptr(self_priv_port), SWIGTYPE_p_bt_private_port, 0); if (!py_self_port_ptr) { @@ -436,7 +436,7 @@ static enum bt_component_status bt_py3_cc_accept_port_connection( goto error; } - assert(PyBool_Check(py_method_result)); + BT_ASSERT(PyBool_Check(py_method_result)); if (py_method_result == Py_True) { status = BT_COMPONENT_STATUS_OK; @@ -474,7 +474,7 @@ static void bt_py3_cc_port_connected( PyObject *py_method_result = NULL; py_comp = bt_private_component_get_user_data(priv_comp); - assert(py_comp); + BT_ASSERT(py_comp); py_self_port_ptr = SWIG_NewPointerObj(SWIG_as_voidptr(self_priv_port), SWIGTYPE_p_bt_private_port, 0); if (!py_self_port_ptr) { @@ -492,7 +492,7 @@ static void bt_py3_cc_port_connected( py_method_result = PyObject_CallMethod(py_comp, "_port_connected_from_native", "(OO)", py_self_port_ptr, py_other_port_ptr); - assert(py_method_result == Py_None); + BT_ASSERT(py_method_result == Py_None); Py_XDECREF(py_self_port_ptr); Py_XDECREF(py_other_port_ptr); Py_XDECREF(py_method_result); @@ -507,7 +507,7 @@ static void bt_py3_cc_port_disconnected( PyObject *py_method_result = NULL; py_comp = bt_private_component_get_user_data(priv_comp); - assert(py_comp); + BT_ASSERT(py_comp); py_port_ptr = SWIG_NewPointerObj(SWIG_as_voidptr(priv_port), SWIGTYPE_p_bt_private_port, 0); if (!py_port_ptr) { @@ -517,7 +517,7 @@ static void bt_py3_cc_port_disconnected( py_method_result = PyObject_CallMethod(py_comp, "_port_disconnected_from_native", "(O)", py_port_ptr); - assert(py_method_result == Py_None); + BT_ASSERT(py_method_result == Py_None); Py_XDECREF(py_port_ptr); Py_XDECREF(py_method_result); } @@ -592,8 +592,8 @@ static struct bt_component_class_query_method_return bt_py3_cc_query( * reference). */ ret.result = (void *) PyLong_AsUnsignedLongLong(py_results_addr); - assert(!PyErr_Occurred()); - assert(ret.result); + BT_ASSERT(!PyErr_Occurred()); + BT_ASSERT(ret.result); goto end; error: @@ -627,7 +627,7 @@ static enum bt_notification_iterator_status bt_py3_cc_notification_iterator_init priv_notif_iter); PyObject *py_comp; - assert(priv_comp); + BT_ASSERT(priv_comp); py_comp = bt_private_component_get_user_data(priv_comp); /* Find user's Python notification iterator class */ @@ -737,7 +737,7 @@ static void bt_py3_cc_notification_iterator_finalize( bt_private_connection_private_notification_iterator_get_user_data(priv_notif_iter); PyObject *py_method_result = NULL; - assert(py_notif_iter); + BT_ASSERT(py_notif_iter); /* Call user's _finalize() method */ py_method_result = PyObject_CallMethod(py_notif_iter, @@ -769,12 +769,12 @@ bt_py3_cc_notification_iterator_next( bt_private_connection_private_notification_iterator_get_user_data(priv_notif_iter); PyObject *py_method_result = NULL; - assert(py_notif_iter); + BT_ASSERT(py_notif_iter); py_method_result = PyObject_CallMethod(py_notif_iter, "_next_from_native", NULL); if (!py_method_result) { next_ret.status = bt_py3_exc_to_notif_iter_status(); - assert(next_ret.status != BT_NOTIFICATION_ITERATOR_STATUS_OK); + BT_ASSERT(next_ret.status != BT_NOTIFICATION_ITERATOR_STATUS_OK); goto end; } @@ -788,8 +788,8 @@ bt_py3_cc_notification_iterator_next( py_method_result); /* Clear potential overflow error; should never happen */ - assert(!PyErr_Occurred()); - assert(next_ret.notification); + BT_ASSERT(!PyErr_Occurred()); + BT_ASSERT(next_ret.notification); goto end; end: @@ -804,7 +804,7 @@ static enum bt_component_status bt_py3_cc_sink_consume( PyObject *py_method_result = NULL; enum bt_component_status status; - assert(py_comp); + BT_ASSERT(py_comp); py_method_result = PyObject_CallMethod(py_comp, "_consume", NULL); status = bt_py3_exc_to_component_status(); @@ -846,20 +846,20 @@ static int bt_py3_cc_set_optional_attrs_methods(struct bt_component_class *cc, } ret = bt_component_class_set_init_method(cc, bt_py3_cc_init); - assert(ret == 0); + BT_ASSERT(ret == 0); ret = bt_component_class_set_finalize_method(cc, bt_py3_cc_finalize); - assert(ret == 0); + BT_ASSERT(ret == 0); ret = bt_component_class_set_accept_port_connection_method(cc, bt_py3_cc_accept_port_connection); - assert(ret == 0); + BT_ASSERT(ret == 0); ret = bt_component_class_set_port_connected_method(cc, bt_py3_cc_port_connected); - assert(ret == 0); + BT_ASSERT(ret == 0); ret = bt_component_class_set_port_disconnected_method(cc, bt_py3_cc_port_disconnected); - assert(ret == 0); + BT_ASSERT(ret == 0); ret = bt_component_class_set_query_method(cc, bt_py3_cc_query); - assert(ret == 0); + BT_ASSERT(ret == 0); end: return ret; @@ -873,10 +873,10 @@ static void bt_py3_cc_set_optional_iter_methods(struct bt_component_class *cc, ret = set_notif_iter_init_method( cc, bt_py3_cc_notification_iterator_init); - assert(ret == 0); + BT_ASSERT(ret == 0); ret = set_notif_iter_finalize_method( cc, bt_py3_cc_notification_iterator_finalize); - assert(ret == 0); + BT_ASSERT(ret == 0); } static struct bt_component_class *bt_py3_component_class_source_create( @@ -886,7 +886,7 @@ static struct bt_component_class *bt_py3_component_class_source_create( struct bt_component_class *cc; int ret; - assert(py_cls); + BT_ASSERT(py_cls); cc = bt_component_class_source_create(name, bt_py3_cc_notification_iterator_next); if (!cc) { @@ -918,7 +918,7 @@ static struct bt_component_class *bt_py3_component_class_filter_create( struct bt_component_class *cc; int ret; - assert(py_cls); + BT_ASSERT(py_cls); cc = bt_component_class_filter_create(name, bt_py3_cc_notification_iterator_next); if (!cc) { @@ -950,7 +950,7 @@ static struct bt_component_class *bt_py3_component_class_sink_create( struct bt_component_class *cc; int ret; - assert(py_cls); + BT_ASSERT(py_cls); cc = bt_component_class_sink_create(name, bt_py3_cc_sink_consume); if (!cc) { BT_LOGE_STR("Cannot create sink component class."); diff --git a/bindings/python/bt2/bt2/native_btconnection.i b/bindings/python/bt2/bt2/native_btconnection.i index db54a91c..7e6195c1 100644 --- a/bindings/python/bt2/bt2/native_btconnection.i +++ b/bindings/python/bt2/bt2/native_btconnection.i @@ -72,8 +72,8 @@ static struct bt_py3_create_notif_iter_ret bt_py3_create_priv_conn_notif_iter( struct bt_py3_create_notif_iter_ret ret; priv_conn = (void *) priv_conn_addr; - assert(!PyErr_Occurred()); - assert(priv_conn); + BT_ASSERT(!PyErr_Occurred()); + BT_ASSERT(priv_conn); notification_types = bt_py3_notif_types_from_py_list(py_notif_types); ret.status = bt_private_connection_create_notification_iterator( diff --git a/bindings/python/bt2/bt2/native_btgraph.i b/bindings/python/bt2/bt2/native_btgraph.i index 395f6f38..151c13dc 100644 --- a/bindings/python/bt2/bt2/native_btgraph.i +++ b/bindings/python/bt2/bt2/native_btgraph.i @@ -75,7 +75,7 @@ static void port_added_listener(struct bt_port *port, void *py_callable) } py_res = PyObject_CallFunction(py_callable, "(O)", py_port_ptr); - assert(py_res == Py_None); + BT_ASSERT(py_res == Py_None); Py_DECREF(py_port_ptr); Py_DECREF(py_res); } @@ -94,7 +94,7 @@ static void port_removed_listener(struct bt_component *component, } py_res = PyObject_CallFunction(py_callable, "(O)", py_port_ptr); - assert(py_res == Py_None); + BT_ASSERT(py_res == Py_None); Py_DECREF(py_port_ptr); Py_DECREF(py_res); } @@ -122,7 +122,7 @@ static void ports_connected_listener(struct bt_port *upstream_port, py_res = PyObject_CallFunction(py_callable, "(OO)", py_upstream_port_ptr, py_downstream_port_ptr); - assert(py_res == Py_None); + BT_ASSERT(py_res == Py_None); Py_DECREF(py_upstream_port_ptr); Py_DECREF(py_downstream_port_ptr); Py_DECREF(py_res); @@ -173,7 +173,7 @@ static void ports_disconnected_listener( py_res = PyObject_CallFunction(py_callable, "(OOOO)", py_upstream_comp_ptr, py_downstream_comp_ptr, py_upstream_port_ptr, py_downstream_port_ptr); - assert(py_res == Py_None); + BT_ASSERT(py_res == Py_None); Py_DECREF(py_upstream_comp_ptr); Py_DECREF(py_downstream_comp_ptr); Py_DECREF(py_upstream_port_ptr); @@ -183,7 +183,7 @@ static void ports_disconnected_listener( static void graph_listener_removed(void *py_callable) { - assert(py_callable); + BT_ASSERT(py_callable); Py_DECREF(py_callable); } @@ -192,8 +192,8 @@ static int bt_py3_graph_add_port_added_listener(struct bt_graph *graph, { int ret = 0; - assert(graph); - assert(py_callable); + BT_ASSERT(graph); + BT_ASSERT(py_callable); ret = bt_graph_add_port_added_listener(graph, port_added_listener, graph_listener_removed, py_callable); if (ret >= 0) { @@ -208,8 +208,8 @@ static int bt_py3_graph_add_port_removed_listener(struct bt_graph *graph, { int ret = 0; - assert(graph); - assert(py_callable); + BT_ASSERT(graph); + BT_ASSERT(py_callable); ret = bt_graph_add_port_removed_listener(graph, port_removed_listener, graph_listener_removed, py_callable); if (ret >= 0) { @@ -224,8 +224,8 @@ static int bt_py3_graph_add_ports_connected_listener(struct bt_graph *graph, { int ret = 0; - assert(graph); - assert(py_callable); + BT_ASSERT(graph); + BT_ASSERT(py_callable); ret = bt_graph_add_ports_connected_listener(graph, ports_connected_listener, graph_listener_removed, py_callable); if (ret >= 0) { @@ -240,8 +240,8 @@ static int bt_py3_graph_add_ports_disconnected_listener(struct bt_graph *graph, { int ret = 0; - assert(graph); - assert(py_callable); + BT_ASSERT(graph); + BT_ASSERT(py_callable); ret = bt_graph_add_ports_disconnected_listener(graph, ports_disconnected_listener, graph_listener_removed, py_callable); diff --git a/bindings/python/bt2/bt2/native_btnotifiter.i b/bindings/python/bt2/bt2/native_btnotifiter.i index 8963ec99..320e2e95 100644 --- a/bindings/python/bt2/bt2/native_btnotifiter.i +++ b/bindings/python/bt2/bt2/native_btnotifiter.i @@ -62,10 +62,10 @@ static PyObject *bt_py3_get_user_component_from_user_notif_iter( priv_notif_iter); PyObject *py_comp; - assert(priv_comp); + BT_ASSERT(priv_comp); py_comp = bt_private_component_get_user_data(priv_comp); bt_put(priv_comp); - assert(py_comp); + BT_ASSERT(py_comp); /* Return new reference */ Py_INCREF(py_comp); diff --git a/bindings/python/bt2/bt2/native_btport.i b/bindings/python/bt2/bt2/native_btport.i index b14550dc..fef78264 100644 --- a/bindings/python/bt2/bt2/native_btport.i +++ b/bindings/python/bt2/bt2/native_btport.i @@ -69,8 +69,8 @@ static struct bt_notification_iterator *bt_py3_create_output_port_notif_iter( enum bt_notification_type *notification_types; output_port = (void *) port_addr; - assert(!PyErr_Occurred()); - assert(output_port); + BT_ASSERT(!PyErr_Occurred()); + BT_ASSERT(output_port); notification_types = bt_py3_notif_types_from_py_list(py_notif_types); notif_iter = bt_output_port_notification_iterator_create(output_port, diff --git a/bindings/python/bt2/bt2/native_bttrace.i b/bindings/python/bt2/bt2/native_bttrace.i index 3f78f450..62104235 100644 --- a/bindings/python/bt2/bt2/native_bttrace.i +++ b/bindings/python/bt2/bt2/native_bttrace.i @@ -93,14 +93,14 @@ void trace_is_static_listener(struct bt_trace *trace, void *py_callable) } py_res = PyObject_CallFunction(py_callable, "(O)", py_trace_ptr); - assert(py_res == Py_None); + BT_ASSERT(py_res == Py_None); Py_DECREF(py_trace_ptr); Py_DECREF(py_res); } void trace_listener_removed(struct bt_trace *trace, void *py_callable) { - assert(py_callable); + BT_ASSERT(py_callable); Py_DECREF(py_callable); } @@ -110,8 +110,8 @@ static int bt_py3_trace_add_is_staitc_listener(unsigned long long trace_addr, struct bt_trace *trace = (void *) trace_addr; int ret = 0; - assert(trace); - assert(py_callable); + BT_ASSERT(trace); + BT_ASSERT(py_callable); ret = bt_trace_add_is_static_listener(trace, trace_is_static_listener, trace_listener_removed, py_callable); if (ret >= 0) { diff --git a/cli/babeltrace-cfg-cli-args-connect.c b/cli/babeltrace-cfg-cli-args-connect.c index 0a29eb7a..13c91293 100644 --- a/cli/babeltrace-cfg-cli-args-connect.c +++ b/cli/babeltrace-cfg-cli-args-connect.c @@ -105,7 +105,7 @@ static bool validate_port_glob(const char *port_glob) bool is_valid = true; const char *ch = port_glob; - assert(port_glob); + BT_ASSERT(port_glob); while (*ch != '\0') { switch (*ch) { @@ -380,10 +380,10 @@ static int validate_connection_directions(struct bt_config *cfg, src_comp = find_component(cfg, connection->upstream_comp_name->str); - assert(src_comp); + BT_ASSERT(src_comp); dst_comp = find_component(cfg, connection->downstream_comp_name->str); - assert(dst_comp); + BT_ASSERT(dst_comp); if (src_comp->type == BT_COMPONENT_CLASS_TYPE_SOURCE) { if (dst_comp->type != BT_COMPONENT_CLASS_TYPE_FILTER && @@ -432,7 +432,7 @@ static int validate_no_cycles_rec(struct bt_config *cfg, GPtrArray *path, size_t conn_i; const char *src_comp_name; - assert(path && path->len > 0); + BT_ASSERT(path && path->len > 0); src_comp_name = g_ptr_array_index(path, path->len - 1); for (conn_i = 0; conn_i < cfg->cmd_data.run.connections->len; conn_i++) { @@ -694,7 +694,7 @@ int bt_config_cli_args_create_connections(struct bt_config *cfg, ret = bt_value_string_get(arg_value, &arg); BT_PUT(arg_value); - assert(ret == 0); + BT_ASSERT(ret == 0); cfg_connection = cfg_connection_from_arg(arg); if (!cfg_connection) { snprintf(error_buf, error_buf_size, "Cannot parse --connect option's argument:\n %s\n", diff --git a/cli/babeltrace-cfg-cli-args.c b/cli/babeltrace-cfg-cli-args.c index 3af66edf..9d2b684e 100644 --- a/cli/babeltrace-cfg-cli-args.c +++ b/cli/babeltrace-cfg-cli-args.c @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include #include @@ -608,10 +608,10 @@ void plugin_comp_cls_names(const char *arg, char **name, char **plugin, GString *gs_comp_cls = NULL; size_t end_pos; - assert(arg); - assert(plugin); - assert(comp_cls); - assert(comp_cls_type); + BT_ASSERT(arg); + BT_ASSERT(plugin); + BT_ASSERT(comp_cls); + BT_ASSERT(comp_cls_type); if (!bt_common_string_is_printable(arg)) { printf_err("Argument contains a non-printable character\n"); @@ -1191,9 +1191,9 @@ end: static void append_param_arg(GString *params_arg, const char *key, const char *value) { - assert(params_arg); - assert(key); - assert(value); + BT_ASSERT(params_arg); + BT_ASSERT(key); + BT_ASSERT(value); if (params_arg->len != 0) { g_string_append_c(params_arg, ','); @@ -2083,7 +2083,7 @@ struct bt_config *bt_config_query_from_args(int argc, const char *argv[], goto error; } - assert(params); + BT_ASSERT(params); BT_MOVE(cfg->cmd_data.query.cfg_component->params, params); } else { print_query_usage(stdout); @@ -2502,7 +2502,7 @@ struct bt_config *bt_config_run_from_args(int argc, const char *argv[], abort(); } - assert(cur_base_params); + BT_ASSERT(cur_base_params); bt_put(cur_cfg_comp->params); cur_cfg_comp->params = bt_value_copy(cur_base_params); if (!cur_cfg_comp->params) { @@ -2728,10 +2728,10 @@ struct bt_config *bt_config_run_from_args_array(struct bt_value *run_args, struct bt_value *arg_value = bt_value_array_get(run_args, i); const char *arg; - assert(arg_value); + BT_ASSERT(arg_value); ret = bt_value_string_get(arg_value, &arg); - assert(ret == 0); - assert(arg); + BT_ASSERT(ret == 0); + BT_ASSERT(arg); argv[i + 1] = arg; bt_put(arg_value); } @@ -3052,7 +3052,7 @@ int append_run_args_for_implicit_component( goto error; } - assert(bt_value_is_string(elem)); + BT_ASSERT(bt_value_is_string(elem)); if (bt_value_string_get(elem, &arg)) { goto error; } @@ -3077,7 +3077,7 @@ end: static void finalize_implicit_component_args(struct implicit_component_args *args) { - assert(args); + BT_ASSERT(args); if (args->comp_arg) { g_string_free(args->comp_arg, TRUE); @@ -3133,9 +3133,9 @@ static void append_implicit_component_param(struct implicit_component_args *args, const char *key, const char *value) { - assert(args); - assert(key); - assert(value); + BT_ASSERT(args); + BT_ASSERT(key); + BT_ASSERT(value); append_param_arg(args->params_arg, key, value); } @@ -3145,9 +3145,9 @@ int append_implicit_component_extra_param(struct implicit_component_args *args, { int ret = 0; - assert(args); - assert(key); - assert(value); + BT_ASSERT(args); + BT_ASSERT(key); + BT_ASSERT(value); if (bt_value_array_append_string(args->extra_params, "--key")) { print_err_oom(); @@ -3366,9 +3366,9 @@ int convert_auto_connect(struct bt_value *run_args, GList *filter_prev; GList *sink_at = sink_names; - assert(source_names); - assert(filter_names); - assert(sink_names); + BT_ASSERT(source_names); + BT_ASSERT(filter_names); + BT_ASSERT(sink_names); /* Connect all sources to the first filter */ for (source_at = source_names; source_at != NULL; source_at = g_list_next(source_at)) { @@ -3427,7 +3427,7 @@ int split_timerange(const char *arg, char **begin, char **end) GString *g_begin = NULL; GString *g_end = NULL; - assert(arg); + BT_ASSERT(arg); if (*ch == '[') { ch++; @@ -3445,8 +3445,8 @@ int split_timerange(const char *arg, char **begin, char **end) goto error; } - assert(begin); - assert(end); + BT_ASSERT(begin); + BT_ASSERT(end); *begin = g_begin->str; *end = g_end->str; g_string_free(g_begin, FALSE); @@ -3476,7 +3476,7 @@ int g_list_prepend_gstring(GList **list, const char *string) int ret = 0; GString *gs = g_string_new(string); - assert(list); + BT_ASSERT(list); if (!gs) { print_err_oom(); @@ -4673,9 +4673,9 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[], GString *quoted = NULL; const char *arg_to_print; - assert(arg_value); + BT_ASSERT(arg_value); ret = bt_value_string_get(arg_value, &arg); - assert(ret == 0); + BT_ASSERT(ret == 0); BT_PUT(arg_value); if (print_run_args) { @@ -4959,8 +4959,8 @@ struct bt_config *bt_config_cli_args_create(int argc, const char *argv[], goto end; } - assert(command_argv); - assert(command_argc >= 0); + BT_ASSERT(command_argv); + BT_ASSERT(command_argc >= 0); switch (command_type) { case COMMAND_TYPE_RUN: diff --git a/cli/babeltrace-log.c b/cli/babeltrace-log.c index 9037dd93..d429ceb1 100644 --- a/cli/babeltrace-log.c +++ b/cli/babeltrace-log.c @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include #include @@ -96,7 +96,7 @@ int parse_params(int argc, char *argv[], char **output_path, } *output_path = strdup(leftover); - assert(*output_path); + BT_ASSERT(*output_path); goto end; error: diff --git a/cli/babeltrace.c b/cli/babeltrace.c index dfa4512d..ce12900a 100644 --- a/cli/babeltrace.c +++ b/cli/babeltrace.c @@ -178,8 +178,8 @@ int query(struct bt_component_class *comp_cls, const char *obj, *fail_reason = "unknown error"; int ret = 0; - assert(fail_reason); - assert(user_result); + BT_ASSERT(fail_reason); + BT_ASSERT(user_result); ret = create_the_query_executor(); if (ret) { /* create_the_query_executor() logs errors */ @@ -264,7 +264,7 @@ struct bt_plugin *find_plugin(const char *name) int i; struct bt_plugin *plugin = NULL; - assert(name); + BT_ASSERT(name); BT_LOGD("Finding plugin: name=\"%s\"", name); for (i = 0; i < loaded_plugins->len; i++) { @@ -406,6 +406,7 @@ bt_bool print_map_value(const char *key, struct bt_value *object, void *data) print_indent(print_map_value_data->fp, print_map_value_data->indent); fprintf(print_map_value_data->fp, "%s: ", key); + BT_ASSERT(object); if (bt_value_is_array(object) && bt_value_array_is_empty(object)) { @@ -714,7 +715,7 @@ void add_to_loaded_plugins(struct bt_plugin_set *plugin_set) int64_t count; count = bt_plugin_set_get_plugin_count(plugin_set); - assert(count >= 0); + BT_ASSERT(count >= 0); for (i = 0; i < count; i++) { struct bt_plugin *plugin = @@ -722,7 +723,7 @@ void add_to_loaded_plugins(struct bt_plugin_set *plugin_set) struct bt_plugin *loaded_plugin = find_plugin(bt_plugin_get_name(plugin)); - assert(plugin); + BT_ASSERT(plugin); if (loaded_plugin) { BT_LOGI("Not using plugin: another one already exists with the same name: " @@ -1030,7 +1031,7 @@ int cmd_help(struct bt_config *cfg) enum bt_component_class_type type = bt_component_class_get_type(comp_cls); - assert(comp_cls); + BT_ASSERT(comp_cls); if (cfg->cmd_data.help.cfg_component->type != BT_COMPONENT_CLASS_TYPE_UNKNOWN) { @@ -1158,7 +1159,7 @@ int cmd_print_lttng_live_sessions(struct bt_config *cfg) const char *fail_reason = NULL; FILE *out_stream = stdout; - assert(cfg->cmd_data.print_lttng_live_sessions.url); + BT_ASSERT(cfg->cmd_data.print_lttng_live_sessions.url); comp_cls = find_component_class(plugin_name, comp_cls_name, comp_cls_type); if (!comp_cls) { @@ -1192,6 +1193,8 @@ int cmd_print_lttng_live_sessions(struct bt_config *cfg) goto failed; } + BT_ASSERT(results); + if (!bt_value_is_array(results)) { BT_LOGE_STR("Expecting an array for sessions query."); fprintf(stderr, "%s%sUnexpected type returned by session query%s\n", @@ -1235,7 +1238,7 @@ int cmd_print_lttng_live_sessions(struct bt_config *cfg) goto error; } ret = bt_value_string_get(v, &url_text); - assert(ret == 0); + BT_ASSERT(ret == 0); fprintf(out_stream, "%s", url_text); BT_PUT(v); @@ -1245,7 +1248,7 @@ int cmd_print_lttng_live_sessions(struct bt_config *cfg) goto error; } ret = bt_value_integer_get(v, &timer_us); - assert(ret == 0); + BT_ASSERT(ret == 0); fprintf(out_stream, " (timer = %" PRIu64 ", ", timer_us); BT_PUT(v); @@ -1255,7 +1258,7 @@ int cmd_print_lttng_live_sessions(struct bt_config *cfg) goto error; } ret = bt_value_integer_get(v, &streams); - assert(ret == 0); + BT_ASSERT(ret == 0); fprintf(out_stream, "%" PRIu64 " stream(s), ", streams); BT_PUT(v); @@ -1265,7 +1268,7 @@ int cmd_print_lttng_live_sessions(struct bt_config *cfg) goto error; } ret = bt_value_integer_get(v, &clients); - assert(ret == 0); + BT_ASSERT(ret == 0); fprintf(out_stream, "%" PRIu64 " client(s) connected)\n", clients); BT_PUT(v); @@ -1321,7 +1324,7 @@ int cmd_print_ctf_metadata(struct bt_config *cfg) const char *fail_reason = NULL; FILE *out_stream = stdout; - assert(cfg->cmd_data.print_ctf_metadata.path); + BT_ASSERT(cfg->cmd_data.print_ctf_metadata.path); comp_cls = find_component_class(plugin_name, comp_cls_name, comp_cls_type); if (!comp_cls) { @@ -1366,7 +1369,7 @@ int cmd_print_ctf_metadata(struct bt_config *cfg) } ret = bt_value_string_get(metadata_text_value, &metadata_text); - assert(ret == 0); + BT_ASSERT(ret == 0); if (cfg->cmd_data.print_ctf_metadata.output_path->len > 0) { out_stream = @@ -1433,8 +1436,8 @@ guint port_id_hash(gconstpointer v) { const struct port_id *id = v; - assert(id->instance_name); - assert(id->port_name); + BT_ASSERT(id->instance_name); + BT_ASSERT(id->port_name); return g_str_hash(id->instance_name) ^ g_str_hash(id->port_name); } @@ -1613,7 +1616,7 @@ int cmd_run_ctx_connect_upstream_port_to_downstream_component( cfg_conn->arg->str); downstreamp_comp_name_quark = g_quark_from_string( cfg_conn->downstream_comp_name->str); - assert(downstreamp_comp_name_quark > 0); + BT_ASSERT(downstreamp_comp_name_quark > 0); downstream_comp = g_hash_table_lookup(ctx->components, GUINT_TO_POINTER(downstreamp_comp_name_quark)); if (!downstream_comp) { @@ -1642,7 +1645,7 @@ int cmd_run_ctx_connect_upstream_port_to_downstream_component( } downstream_port_count = port_count_fn(downstream_comp); - assert(downstream_port_count >= 0); + BT_ASSERT(downstream_port_count >= 0); for (i = 0; i < downstream_port_count; i++) { struct bt_port *downstream_port = @@ -1650,7 +1653,7 @@ int cmd_run_ctx_connect_upstream_port_to_downstream_component( const char *upstream_port_name; const char *downstream_port_name; - assert(downstream_port); + BT_ASSERT(downstream_port); /* Skip port if it's already connected. */ if (bt_port_is_connected(downstream_port)) { @@ -1663,9 +1666,9 @@ int cmd_run_ctx_connect_upstream_port_to_downstream_component( } downstream_port_name = bt_port_get_name(downstream_port); - assert(downstream_port_name); + BT_ASSERT(downstream_port_name); upstream_port_name = bt_port_get_name(upstream_port); - assert(upstream_port_name); + BT_ASSERT(upstream_port_name); if (!bt_common_star_glob_match( cfg_conn->downstream_port_glob->str, SIZE_MAX, @@ -1707,7 +1710,7 @@ int cmd_run_ctx_connect_upstream_port_to_downstream_component( if (graph_status != BT_GRAPH_STATUS_OK) { goto error; } - assert(trimmer); + BT_ASSERT(trimmer); trimmer_input = bt_component_filter_get_input_port_by_index( @@ -1851,10 +1854,10 @@ int cmd_run_ctx_connect_upstream_port(struct cmd_run_ctx *ctx, struct bt_component *upstream_comp = NULL; size_t i; - assert(ctx); - assert(upstream_port); + BT_ASSERT(ctx); + BT_ASSERT(upstream_port); upstream_port_name = bt_port_get_name(upstream_port); - assert(upstream_port_name); + BT_ASSERT(upstream_port_name); upstream_comp = bt_port_get_component(upstream_port); if (!upstream_comp) { BT_LOGW("Upstream port to connect is not part of a component: " @@ -1865,7 +1868,7 @@ int cmd_run_ctx_connect_upstream_port(struct cmd_run_ctx *ctx, } upstream_comp_name = bt_component_get_name(upstream_comp); - assert(upstream_comp_name); + BT_ASSERT(upstream_comp_name); BT_LOGI("Connecting upstream port: comp-addr=%p, comp-name=\"%s\", " "port-addr=%p, port-name=\"%s\"", upstream_comp, upstream_comp_name, @@ -1978,8 +1981,8 @@ void graph_ports_connected_listener(struct bt_port *upstream_port, struct bt_component *upstream_comp = bt_port_get_component(upstream_port); struct bt_component *downstream_comp = bt_port_get_component(downstream_port); - assert(upstream_comp); - assert(downstream_comp); + BT_ASSERT(upstream_comp); + BT_ASSERT(downstream_comp); BT_LOGI("Graph's component ports connected: " "upstream-comp-addr=%p, upstream-comp-name=\"%s\", " "upstream-port-addr=%p, upstream-port-name=\"%s\", " @@ -2121,7 +2124,7 @@ int set_stream_intersections(struct cmd_run_ctx *ctx, const char *fail_reason = NULL; component_path_value = bt_value_map_get(cfg_comp->params, "path"); - if (!bt_value_is_string(component_path_value)) { + if (component_path_value && !bt_value_is_string(component_path_value)) { BT_LOGD("Cannot get path parameter: component-name=%s", cfg_comp->instance_name->str); ret = -1; @@ -2160,6 +2163,8 @@ int set_stream_intersections(struct cmd_run_ctx *ctx, goto error; } + BT_ASSERT(query_result); + if (!bt_value_is_array(query_result)) { BT_LOGD("Unexpected format of \'trace-info\' query result: " "component-class-name=%s", @@ -2428,7 +2433,7 @@ int cmd_run_ctx_create_components_from_config_components( BT_LOGI("Created and inserted component: comp-addr=%p, comp-name=\"%s\"", comp, cfg_comp->instance_name->str); quark = g_quark_from_string(cfg_comp->instance_name->str); - assert(quark > 0); + BT_ASSERT(quark > 0); g_hash_table_insert(ctx->components, GUINT_TO_POINTER(quark), comp); comp = NULL; @@ -2495,12 +2500,12 @@ int cmd_run_ctx_connect_comp_ports(struct cmd_run_ctx *ctx, uint64_t i; count = port_count_fn(comp); - assert(count >= 0); + BT_ASSERT(count >= 0); for (i = 0; i < count; i++) { struct bt_port *upstream_port = port_by_index_fn(comp, i); - assert(upstream_port); + BT_ASSERT(upstream_port); ret = cmd_run_ctx_connect_upstream_port(ctx, upstream_port); bt_put(upstream_port); if (ret) { diff --git a/common/common.c b/common/common.c index cf31aecc..78ed26ab 100644 --- a/common/common.c +++ b/common/common.c @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include #include #include @@ -194,7 +194,7 @@ int bt_common_append_plugin_path_dirs(const char *paths, GPtrArray *dirs) const char *end; size_t init_dirs_len; - assert(dirs); + BT_ASSERT(dirs); init_dirs_len = dirs->len; if (!paths) { @@ -577,7 +577,7 @@ bool bt_common_string_is_printable(const char *input) { const char *ch; bool printable = true; - assert(input); + BT_ASSERT(input); for (ch = input; *ch != '\0'; ch++) { if (!isprint(*ch) && *ch != '\n' && *ch != '\r' && @@ -631,7 +631,7 @@ struct bt_common_lttng_live_url_parts bt_common_parse_lttng_live_url( const char *at = url; size_t end_pos; - assert(url); + BT_ASSERT(url); memset(&parts, 0, sizeof(parts)); parts.port = -1; @@ -800,7 +800,7 @@ void bt_common_normalize_star_glob_pattern(char *pattern) char *np; bool got_star = false; - assert(pattern); + BT_ASSERT(pattern); for (p = pattern, np = pattern; *p != '\0'; p++) { switch (*p) { @@ -1008,7 +1008,7 @@ retry: * ^ ^ SUCCESS */ while ((c - candidate) < candidate_len && *c != '\0') { - assert(*c); + BT_ASSERT(*c); if (at_end_of_pattern(p, pattern, pattern_len)) { goto end_of_pattern; @@ -1097,7 +1097,7 @@ void append_path_parts(const char *path, GPtrArray *parts) if (ch - last > 0) { GString *part = g_string_new(NULL); - assert(part); + BT_ASSERT(part); g_string_append_len(part, last, ch - last); g_ptr_array_add(parts, part); } @@ -1126,7 +1126,7 @@ GString *bt_common_normalize_path(const char *path, const char *wd) char *tmp; GString *norm_path = NULL; - assert(path); + BT_ASSERT(path); tmp = _fullpath(NULL, path, PATH_MAX); if (!tmp) { @@ -1158,7 +1158,7 @@ GString *bt_common_normalize_path(const char *path, const char *wd) GString *norm_path; GPtrArray *parts = NULL; - assert(path); + BT_ASSERT(path); norm_path = g_string_new(G_DIR_SEPARATOR_S); if (!norm_path) { goto error; @@ -1260,7 +1260,7 @@ size_t bt_common_get_page_size(void) strncpy(_tmp_fmt, *out_fmt_ch, _tmp_fmt_size); \ _tmp_fmt[_tmp_fmt_size] = '\0'; \ _count = snprintf(*buf_ch, _size, _tmp_fmt, __VA_ARGS__); \ - assert(_count >= 0); \ + BT_ASSERT(_count >= 0); \ *buf_ch += MIN(_count, _size); \ } while (0) @@ -1519,14 +1519,14 @@ void bt_common_custom_vsnprintf(char *buf, size_t buf_size, const char *fmt_ch = fmt; char *buf_ch = buf; - assert(buf); - assert(fmt); - assert(*args); + BT_ASSERT(buf); + BT_ASSERT(fmt); + BT_ASSERT(*args); while (*fmt_ch != '\0') { switch (*fmt_ch) { case '%': - assert(fmt_ch[1] != '\0'); + BT_ASSERT(fmt_ch[1] != '\0'); if (fmt_ch[1] == intro) { handle_specifier(priv_data, &buf_ch, diff --git a/include/babeltrace/bitfield-internal.h b/include/babeltrace/bitfield-internal.h index 122ccda6..e5d95e6f 100644 --- a/include/babeltrace/bitfield-internal.h +++ b/include/babeltrace/bitfield-internal.h @@ -29,7 +29,6 @@ #include /* C99 5.2.4.2 Numerical limits */ #include /* C99 5.2.4.2 Numerical limits */ -#include #include /* Non-standard BIG_ENDIAN, LITTLE_ENDIAN, BYTE_ORDER */ /* We can't shift a int from 32 bit, >> 32 and << 32 on int is undefined */ diff --git a/include/babeltrace/compat/stdio-internal.h b/include/babeltrace/compat/stdio-internal.h index 9d8b5241..332d74da 100644 --- a/include/babeltrace/compat/stdio-internal.h +++ b/include/babeltrace/compat/stdio-internal.h @@ -25,9 +25,9 @@ #include #include -#include #include #include +#include #define BT_GETLINE_MINBUFLEN 64 @@ -94,7 +94,7 @@ ssize_t bt_getline(char **lineptr, size_t *n, FILE *stream) /* ferror() is set, errno set by fgetc(). */ return -1; } - assert(feof(stream)); + BT_ASSERT(feof(stream)); found_eof = 1; break; } diff --git a/include/babeltrace/ctf-ir/event-class-internal.h b/include/babeltrace/ctf-ir/event-class-internal.h index 160200bf..81117435 100644 --- a/include/babeltrace/ctf-ir/event-class-internal.h +++ b/include/babeltrace/ctf-ir/event-class-internal.h @@ -36,6 +36,7 @@ #include #include #include +#include #include struct bt_event_class { @@ -77,7 +78,7 @@ static inline struct bt_stream_class *bt_event_class_borrow_stream_class( struct bt_event_class *event_class) { - assert(event_class); + BT_ASSERT(event_class); return (void *) bt_object_borrow_parent(event_class); } diff --git a/include/babeltrace/ctf-ir/event-internal.h b/include/babeltrace/ctf-ir/event-internal.h index b15af110..8dab3789 100644 --- a/include/babeltrace/ctf-ir/event-internal.h +++ b/include/babeltrace/ctf-ir/event-internal.h @@ -35,7 +35,7 @@ #include #include #include -#include +#include #include struct bt_stream_pos; @@ -53,29 +53,39 @@ struct bt_event { int frozen; }; -BT_HIDDEN -int bt_event_validate(struct bt_event *event); - BT_HIDDEN int bt_event_serialize(struct bt_event *event, struct bt_stream_pos *pos, enum bt_byte_order native_byte_order); BT_HIDDEN -void bt_event_freeze(struct bt_event *event); +int _bt_event_validate(struct bt_event *event); -static inline struct bt_packet *bt_event_borrow_packet( - struct bt_event *event) +BT_HIDDEN +void _bt_event_freeze(struct bt_event *event); + +#ifdef BT_DEV_MODE +# define bt_event_validate _bt_event_validate +# define bt_event_freeze _bt_event_freeze +#else +# define bt_event_validate(_event) 0 +# define bt_event_freeze(_event) +#endif + +static inline struct bt_packet *bt_event_borrow_packet(struct bt_event *event) { - assert(event); + BT_ASSERT(event); return event->packet; } +BT_HIDDEN +struct bt_stream *bt_event_borrow_stream(struct bt_event *event); + static inline struct bt_event_class *bt_event_borrow_event_class( struct bt_event *event) { - assert(event); + BT_ASSERT(event); return event->event_class; } diff --git a/include/babeltrace/ctf-ir/field-path-internal.h b/include/babeltrace/ctf-ir/field-path-internal.h index a65ffe10..2f9611c8 100644 --- a/include/babeltrace/ctf-ir/field-path-internal.h +++ b/include/babeltrace/ctf-ir/field-path-internal.h @@ -29,7 +29,7 @@ */ #include -#include +#include #include struct bt_field_path { @@ -61,7 +61,7 @@ GString *bt_field_path_string(struct bt_field_path *path) GString *str = g_string_new(NULL); size_t i; - assert(path); + BT_ASSERT(path); if (!str) { goto end; diff --git a/include/babeltrace/ctf-ir/field-types-internal.h b/include/babeltrace/ctf-ir/field-types-internal.h index fbe0bb78..e418b1f3 100644 --- a/include/babeltrace/ctf-ir/field-types-internal.h +++ b/include/babeltrace/ctf-ir/field-types-internal.h @@ -157,8 +157,14 @@ struct bt_field_type_string { enum bt_string_encoding encoding; }; +#ifdef BT_DEV_MODE +# define bt_field_type_freeze _bt_field_type_freeze +#else +# define bt_field_type_freeze(_ft) +#endif + BT_HIDDEN -void bt_field_type_freeze(struct bt_field_type *type); +void _bt_field_type_freeze(struct bt_field_type *type); BT_HIDDEN struct bt_field_type *bt_field_type_variant_get_field_type_signed( diff --git a/include/babeltrace/ctf-ir/fields-internal.h b/include/babeltrace/ctf-ir/fields-internal.h index 6c25b26c..874e75f3 100644 --- a/include/babeltrace/ctf-ir/fields-internal.h +++ b/include/babeltrace/ctf-ir/fields-internal.h @@ -90,17 +90,40 @@ struct bt_field_string { GString *payload; }; +BT_HIDDEN +int bt_field_serialize_recursive(struct bt_field *field, + struct bt_stream_pos *pos, + enum bt_byte_order native_byte_order); + /* Validate that the field's payload is set (returns 0 if set). */ BT_HIDDEN -int bt_field_validate(struct bt_field *field); +int _bt_field_validate_recursive(struct bt_field *field); BT_HIDDEN -int bt_field_serialize(struct bt_field *field, - struct bt_stream_pos *pos, - enum bt_byte_order native_byte_order); +void _bt_field_freeze_recursive(struct bt_field *field); + +BT_HIDDEN +bt_bool _bt_field_is_set_recursive(struct bt_field *field); + +BT_HIDDEN +void _bt_field_reset_recursive(struct bt_field *field); BT_HIDDEN -void bt_field_freeze(struct bt_field *field); +void _bt_field_set(struct bt_field *field, bool val); + +#ifdef BT_DEV_MODE +# define bt_field_validate_recursive _bt_field_validate_recursive +# define bt_field_freeze_recursive _bt_field_freeze_recursive +# define bt_field_is_set_recursive _bt_field_is_set_recursive +# define bt_field_reset_recursive _bt_field_reset_recursive +# define bt_field_set _bt_field_set +#else +# define bt_field_validate_recursive(_field) (-1) +# define bt_field_freeze_recursive(_field) +# define bt_field_is_set_recursive(_field) (BT_FALSE) +# define bt_field_reset_recursive(_field) (BT_TRUE) +# define bt_field_set(_field, _val) +#endif BT_HIDDEN int64_t bt_field_sequence_get_int_length(struct bt_field *field); diff --git a/include/babeltrace/ctf-ir/fields.h b/include/babeltrace/ctf-ir/fields.h index a5e22b5c..03e6052e 100644 --- a/include/babeltrace/ctf-ir/fields.h +++ b/include/babeltrace/ctf-ir/fields.h @@ -219,11 +219,6 @@ extern struct bt_field_type *bt_field_get_type( extern enum bt_field_type_id bt_field_get_type_id( struct bt_field *field); - -extern bt_bool bt_field_is_set(struct bt_field *field); - -extern int bt_field_reset(struct bt_field *field); - /* * bt_field_signed_integer_get_value: get a signed integer field's value * diff --git a/include/babeltrace/ctf-ir/packet-internal.h b/include/babeltrace/ctf-ir/packet-internal.h index 20cded11..a844ca16 100644 --- a/include/babeltrace/ctf-ir/packet-internal.h +++ b/include/babeltrace/ctf-ir/packet-internal.h @@ -29,7 +29,7 @@ #include #include #include -#include +#include struct bt_packet { struct bt_object base; @@ -40,13 +40,19 @@ struct bt_packet { }; BT_HIDDEN -void bt_packet_freeze(struct bt_packet *packet); +void _bt_packet_freeze(struct bt_packet *packet); + +#ifdef BT_DEV_MODE +# define bt_packet_freeze _bt_packet_freeze +#else +# define bt_packet_freeze +#endif /* BT_DEV_MODE */ static inline struct bt_stream *bt_packet_borrow_stream( struct bt_packet *packet) { - assert(packet); + BT_ASSERT(packet); return packet->stream; } diff --git a/include/babeltrace/ctf-ir/stream-class-internal.h b/include/babeltrace/ctf-ir/stream-class-internal.h index 24c75848..fecf8f29 100644 --- a/include/babeltrace/ctf-ir/stream-class-internal.h +++ b/include/babeltrace/ctf-ir/stream-class-internal.h @@ -34,7 +34,7 @@ #include #include #include -#include +#include #include struct bt_stream_class { @@ -115,7 +115,7 @@ static inline struct bt_trace *bt_stream_class_borrow_trace( struct bt_stream_class *stream_class) { - assert(stream_class); + BT_ASSERT(stream_class); return (void *) bt_object_borrow_parent(stream_class); } diff --git a/include/babeltrace/ctf-ir/stream-internal.h b/include/babeltrace/ctf-ir/stream-internal.h index 3901a9ae..e6b8ea0b 100644 --- a/include/babeltrace/ctf-ir/stream-internal.h +++ b/include/babeltrace/ctf-ir/stream-internal.h @@ -34,6 +34,7 @@ #include #include #include +#include #include struct bt_port; @@ -112,7 +113,7 @@ static inline struct bt_stream_class *bt_stream_borrow_stream_class( struct bt_stream *stream) { - assert(stream); + BT_ASSERT(stream); return stream->stream_class; } diff --git a/include/babeltrace/ctf-writer/serialize-internal.h b/include/babeltrace/ctf-writer/serialize-internal.h index 93708277..09acfc1c 100644 --- a/include/babeltrace/ctf-writer/serialize-internal.h +++ b/include/babeltrace/ctf-writer/serialize-internal.h @@ -40,6 +40,7 @@ #include #include #include +#include #define PACKET_LEN_INCREMENT (bt_common_get_page_size() * 8 * CHAR_BIT) @@ -117,7 +118,7 @@ static inline char *bt_stream_pos_get_addr(struct bt_stream_pos *pos) { /* Only makes sense to get the address after aligning on CHAR_BIT */ - assert(!(pos->offset % CHAR_BIT)); + BT_ASSERT(!(pos->offset % CHAR_BIT)); return ((char *) mmap_align_addr(pos->base_mma)) + pos->mmap_base_offset + (pos->offset / CHAR_BIT); } diff --git a/include/babeltrace/graph/clock-class-priority-map-internal.h b/include/babeltrace/graph/clock-class-priority-map-internal.h index cb73a2c6..be6a9953 100644 --- a/include/babeltrace/graph/clock-class-priority-map-internal.h +++ b/include/babeltrace/graph/clock-class-priority-map-internal.h @@ -28,7 +28,7 @@ #include #include -#include +#include #include #include #include @@ -50,11 +50,17 @@ struct bt_clock_class_priority_map { }; static inline -void bt_clock_class_priority_map_freeze( +void _bt_clock_class_priority_map_freeze( struct bt_clock_class_priority_map *cc_prio_map) { - assert(cc_prio_map); + BT_ASSERT(cc_prio_map); cc_prio_map->frozen = BT_TRUE; } +#ifdef BT_DEV_MODE +# define bt_clock_class_priority_map_freeze _bt_clock_class_priority_map_freeze +#else +# define bt_clock_class_priority_map_freeze(_cc_prio_map) +#endif /* BT_DEV_MODE */ + #endif /* BABELTRACE_GRAPH_CLOCK_CLASS_PRIORITY_MAP_INTERNAL_H */ diff --git a/include/babeltrace/graph/component-internal.h b/include/babeltrace/graph/component-internal.h index 8d3f73a9..540faf4c 100644 --- a/include/babeltrace/graph/component-internal.h +++ b/include/babeltrace/graph/component-internal.h @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -85,7 +86,7 @@ struct bt_private_component *bt_private_component_from_component( static inline struct bt_graph *bt_component_borrow_graph(struct bt_component *comp) { - assert(comp); + BT_ASSERT(comp); return (void *) comp->base.parent; } diff --git a/include/babeltrace/graph/connection-internal.h b/include/babeltrace/graph/connection-internal.h index 587e4822..21dd59a3 100644 --- a/include/babeltrace/graph/connection-internal.h +++ b/include/babeltrace/graph/connection-internal.h @@ -32,6 +32,7 @@ #include #include #include +#include #include struct bt_graph; @@ -88,7 +89,7 @@ void bt_connection_remove_iterator(struct bt_connection *conn, static inline struct bt_graph *bt_connection_borrow_graph(struct bt_connection *conn) { - assert(conn); + BT_ASSERT(conn); return (void *) conn->base.parent; } diff --git a/include/babeltrace/graph/graph-internal.h b/include/babeltrace/graph/graph-internal.h index 09c8b111..c8be19aa 100644 --- a/include/babeltrace/graph/graph-internal.h +++ b/include/babeltrace/graph/graph-internal.h @@ -31,8 +31,8 @@ #include #include #include +#include #include -#include #include struct bt_component; @@ -85,7 +85,7 @@ struct bt_graph { static inline void bt_graph_set_can_consume(struct bt_graph *graph, bt_bool can_consume) { - assert(graph); + BT_ASSERT(graph); graph->can_consume = can_consume; } diff --git a/include/babeltrace/graph/notification-discarded-elements-internal.h b/include/babeltrace/graph/notification-discarded-elements-internal.h index 131050d1..3dbc6368 100644 --- a/include/babeltrace/graph/notification-discarded-elements-internal.h +++ b/include/babeltrace/graph/notification-discarded-elements-internal.h @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -76,7 +77,7 @@ struct bt_stream *bt_notification_discarded_elements_borrow_stream( { struct bt_notification_discarded_elements *discarded_elems_notif; - assert(notification); + BT_ASSERT(notification); discarded_elems_notif = container_of(notification, struct bt_notification_discarded_elements, parent); return discarded_elems_notif->stream; diff --git a/include/babeltrace/graph/notification-event-internal.h b/include/babeltrace/graph/notification-event-internal.h index bfc20929..5447a9a0 100644 --- a/include/babeltrace/graph/notification-event-internal.h +++ b/include/babeltrace/graph/notification-event-internal.h @@ -31,6 +31,7 @@ #include #include #include +#include #ifdef __cplusplus extern "C" { @@ -49,7 +50,7 @@ struct bt_event *bt_notification_event_borrow_event( struct bt_notification_event *notif_event = container_of(notif, struct bt_notification_event, parent); - assert(notif_event); + BT_ASSERT(notif_event); return notif_event->event; } @@ -61,7 +62,7 @@ bt_notification_event_borrow_clock_class_priority_map( struct bt_notification_event *notif_event = container_of(notif, struct bt_notification_event, parent); - assert(notif_event); + BT_ASSERT(notif_event); return notif_event->cc_prio_map; } diff --git a/include/babeltrace/graph/notification-internal.h b/include/babeltrace/graph/notification-internal.h index 631d0adf..c37d2f10 100644 --- a/include/babeltrace/graph/notification-internal.h +++ b/include/babeltrace/graph/notification-internal.h @@ -44,6 +44,12 @@ struct bt_notification { bt_bool frozen; }; +#define BT_ASSERT_PRE_NOTIF_IS_TYPE(_notif, _type) \ + BT_ASSERT_PRE((_notif)->type == (_type), \ + "Notification has the wrong type: expected-type=%s, " \ + "%![notif-]+n", bt_notification_type_string(_type), \ + (_notif)) + BT_HIDDEN void bt_notification_init(struct bt_notification *notification, enum bt_notification_type type, diff --git a/include/babeltrace/graph/notification-iterator-internal.h b/include/babeltrace/graph/notification-iterator-internal.h index ab545008..e0d841fc 100644 --- a/include/babeltrace/graph/notification-iterator-internal.h +++ b/include/babeltrace/graph/notification-iterator-internal.h @@ -34,8 +34,8 @@ #include #include #include +#include #include -#include struct bt_port; struct bt_graph; @@ -147,7 +147,7 @@ static inline struct bt_notification *bt_notification_iterator_borrow_current_notification( struct bt_notification_iterator *iterator) { - assert(iterator); + BT_ASSERT(iterator); return iterator->current_notification; } @@ -156,7 +156,7 @@ void bt_notification_iterator_replace_current_notification( struct bt_notification_iterator *iterator, struct bt_notification *notification) { - assert(iterator); + BT_ASSERT(iterator); bt_put(iterator->current_notification); iterator->current_notification = bt_get(notification); } diff --git a/include/babeltrace/graph/notification-packet-internal.h b/include/babeltrace/graph/notification-packet-internal.h index 7164d55b..4fc40166 100644 --- a/include/babeltrace/graph/notification-packet-internal.h +++ b/include/babeltrace/graph/notification-packet-internal.h @@ -30,6 +30,7 @@ #include #include #include +#include struct bt_notification_packet_begin { struct bt_notification parent; @@ -49,7 +50,7 @@ struct bt_packet *bt_notification_packet_begin_borrow_packet( container_of(notif, struct bt_notification_packet_begin, parent); - assert(notif_packet_begin); + BT_ASSERT(notif_packet_begin); return notif_packet_begin->packet; } @@ -61,7 +62,7 @@ struct bt_packet *bt_notification_packet_end_borrow_packet( container_of(notif, struct bt_notification_packet_end, parent); - assert(notif_packet_end); + BT_ASSERT(notif_packet_end); return notif_packet_end->packet; } diff --git a/include/babeltrace/graph/notification-stream-internal.h b/include/babeltrace/graph/notification-stream-internal.h index df1b3dcb..5c0f7226 100644 --- a/include/babeltrace/graph/notification-stream-internal.h +++ b/include/babeltrace/graph/notification-stream-internal.h @@ -30,6 +30,7 @@ #include #include #include +#include struct bt_notification_stream_begin { struct bt_notification parent; @@ -49,7 +50,7 @@ struct bt_stream *bt_notification_stream_begin_borrow_stream( container_of(notif, struct bt_notification_stream_begin, parent); - assert(notif_stream_begin); + BT_ASSERT(notif_stream_begin); return notif_stream_begin->stream; } @@ -61,7 +62,7 @@ struct bt_stream *bt_notification_stream_end_borrow_stream( container_of(notif, struct bt_notification_stream_end, parent); - assert(notif_stream_end); + BT_ASSERT(notif_stream_end); return notif_stream_end->stream; } diff --git a/include/babeltrace/object-internal.h b/include/babeltrace/object-internal.h index 9859e329..9d906da1 100644 --- a/include/babeltrace/object-internal.h +++ b/include/babeltrace/object-internal.h @@ -29,6 +29,7 @@ #include #include +#include /** * All objects publicly exposed by Babeltrace APIs must contain this structure @@ -151,7 +152,7 @@ static inline void bt_object_set_parent_is_owner_listener(void *obj, bt_object_release_func cb) { - assert(obj); + BT_ASSERT(obj); ((struct bt_object *) obj)->parent_is_owner_listener = cb; } diff --git a/include/babeltrace/plugin/plugin-internal.h b/include/babeltrace/plugin/plugin-internal.h index a4411976..cbcf0274 100644 --- a/include/babeltrace/plugin/plugin-internal.h +++ b/include/babeltrace/plugin/plugin-internal.h @@ -32,6 +32,7 @@ #include #include #include +#include #include enum bt_plugin_type { @@ -113,7 +114,7 @@ void bt_plugin_destroy(struct bt_object *obj) { struct bt_plugin *plugin; - assert(obj); + BT_ASSERT(obj); plugin = container_of(obj, struct bt_plugin, base); BT_LOGD("Destroying plugin object: addr=%p, name=\"%s\"", plugin, plugin->info.name ? plugin->info.name->str : NULL); @@ -230,8 +231,8 @@ end: static inline void bt_plugin_set_path(struct bt_plugin *plugin, const char *path) { - assert(plugin); - assert(path); + BT_ASSERT(plugin); + BT_ASSERT(path); g_string_assign(plugin->info.path, path); plugin->info.path_set = BT_TRUE; BT_LOGV("Set plugin's path: addr=%p, name=\"%s\", path=\"%s\"", @@ -241,8 +242,8 @@ void bt_plugin_set_path(struct bt_plugin *plugin, const char *path) static inline void bt_plugin_set_name(struct bt_plugin *plugin, const char *name) { - assert(plugin); - assert(name); + BT_ASSERT(plugin); + BT_ASSERT(name); g_string_assign(plugin->info.name, name); plugin->info.name_set = BT_TRUE; BT_LOGV("Set plugin's name: addr=%p, name=\"%s\"", @@ -253,8 +254,8 @@ static inline void bt_plugin_set_description(struct bt_plugin *plugin, const char *description) { - assert(plugin); - assert(description); + BT_ASSERT(plugin); + BT_ASSERT(description); g_string_assign(plugin->info.description, description); plugin->info.description_set = BT_TRUE; BT_LOGV("Set plugin's description: addr=%p, name=\"%s\"", @@ -264,8 +265,8 @@ void bt_plugin_set_description(struct bt_plugin *plugin, static inline void bt_plugin_set_author(struct bt_plugin *plugin, const char *author) { - assert(plugin); - assert(author); + BT_ASSERT(plugin); + BT_ASSERT(author); g_string_assign(plugin->info.author, author); plugin->info.author_set = BT_TRUE; BT_LOGV("Set plugin's author: addr=%p, name=\"%s\", author=\"%s\"", @@ -275,8 +276,8 @@ void bt_plugin_set_author(struct bt_plugin *plugin, const char *author) static inline void bt_plugin_set_license(struct bt_plugin *plugin, const char *license) { - assert(plugin); - assert(license); + BT_ASSERT(plugin); + BT_ASSERT(license); g_string_assign(plugin->info.license, license); plugin->info.license_set = BT_TRUE; BT_LOGV("Set plugin's path: addr=%p, name=\"%s\", license=\"%s\"", @@ -287,7 +288,7 @@ static inline void bt_plugin_set_version(struct bt_plugin *plugin, unsigned int major, unsigned int minor, unsigned int patch, const char *extra) { - assert(plugin); + BT_ASSERT(plugin); plugin->info.version.major = major; plugin->info.version.minor = minor; plugin->info.version.patch = patch; @@ -306,7 +307,7 @@ void bt_plugin_set_version(struct bt_plugin *plugin, unsigned int major, static inline void bt_plugin_freeze(struct bt_plugin *plugin) { - assert(plugin); + BT_ASSERT(plugin); if (plugin->frozen) { return; @@ -368,8 +369,8 @@ static inline void bt_plugin_set_add_plugin(struct bt_plugin_set *plugin_set, struct bt_plugin *plugin) { - assert(plugin_set); - assert(plugin); + BT_ASSERT(plugin_set); + BT_ASSERT(plugin); g_ptr_array_add(plugin_set->plugins, bt_get(plugin)); BT_LOGV("Added plugin to plugin set: " "plugin-set-addr=%p, plugin-addr=%p, plugin-name=\"%s\", " diff --git a/include/babeltrace/ref-internal.h b/include/babeltrace/ref-internal.h index c5d8143a..f0d973b6 100644 --- a/include/babeltrace/ref-internal.h +++ b/include/babeltrace/ref-internal.h @@ -28,7 +28,7 @@ */ #include -#include +#include struct bt_object; typedef void (*bt_object_release_func)(struct bt_object *); @@ -41,7 +41,7 @@ struct bt_ref { static inline void bt_ref_init(struct bt_ref *ref, bt_object_release_func release) { - assert(ref); + BT_ASSERT(ref); ref->count = 1; ref->release = release; } @@ -49,7 +49,7 @@ void bt_ref_init(struct bt_ref *ref, bt_object_release_func release) static inline void bt_ref_get(struct bt_ref *ref) { - assert(ref); + BT_ASSERT(ref); if (unlikely(!ref->release)) { return; @@ -57,13 +57,13 @@ void bt_ref_get(struct bt_ref *ref) ref->count++; /* Overflow check. */ - assert(ref->count); + BT_ASSERT(ref->count); } static inline void bt_ref_put(struct bt_ref *ref) { - assert(ref); + BT_ASSERT(ref); /* Only assert if the object has opted-in for reference counting. */ if (unlikely((--ref->count) == 0 && ref->release)) { ref->release((struct bt_object *) ref); diff --git a/include/babeltrace/values-internal.h b/include/babeltrace/values-internal.h index 80981d9c..31f508c8 100644 --- a/include/babeltrace/values-internal.h +++ b/include/babeltrace/values-internal.h @@ -28,14 +28,21 @@ #include +BT_HIDDEN +enum bt_value_status _bt_value_freeze(struct bt_value *object); + +#ifdef BT_DEV_MODE +# define bt_value_freeze _bt_value_freeze +#else +# define bt_value_freeze(_value) +#endif /* BT_DEV_MODE */ + static inline const char *bt_value_status_string(enum bt_value_status status) { switch (status) { - case BT_VALUE_STATUS_FROZEN: - return "BT_VALUE_STATUS_FROZEN"; - case BT_VALUE_STATUS_CANCELLED: - return "BT_VALUE_STATUS_CANCELLED"; + case BT_VALUE_STATUS_CANCELED: + return "BT_VALUE_STATUS_CANCELED"; case BT_VALUE_STATUS_INVAL: return "BT_VALUE_STATUS_INVAL"; case BT_VALUE_STATUS_ERROR: diff --git a/include/babeltrace/values.h b/include/babeltrace/values.h index 58aa99e2..d15256da 100644 --- a/include/babeltrace/values.h +++ b/include/babeltrace/values.h @@ -73,14 +73,6 @@ values of #bt_value_status. You can create a deep copy of any value object with bt_value_copy(). You can compare two value objects with bt_value_compare(). -You can \em freeze a value object with bt_value_freeze(). You can get -the raw value of a frozen value object, but you cannot modify it. -Reference counting still works on frozen value objects. You can copy -a frozen value object: the returned copy is not frozen. You can also -compare a frozen value object to another value object (frozen or not). -Freezing a value object is typically used to make it immutable after -it's built by its initial owner. - The following matrix shows some categorized value object functions to use for each value object type: @@ -175,11 +167,8 @@ to use for each value object type: @brief Status codes. */ enum bt_value_status { - /// Value object cannot be altered because it's frozen. - BT_VALUE_STATUS_FROZEN = -4, - - /// Operation cancelled. - BT_VALUE_STATUS_CANCELLED = -3, + /// Operation canceled. + BT_VALUE_STATUS_CANCELED = -3, /* -22 for compatibility with -EINVAL */ /// Invalid argument. @@ -419,46 +408,6 @@ bt_bool bt_value_is_map(const struct bt_value *object) @{ */ -/** -@brief Recursively freezes the value object \p object. - -You cannot modify a frozen value object: it is considered immutable. -Reference counting still works on a frozen value object, however: you -can pass a frozen value object to bt_get() and bt_put(). - -If \p object is an array value object or a map value object, this -function also freezes all its children recursively. - -Freezing a value object is typically used to make it immutable after -it's built by its initial owner. - -@param[in] object Value object to freeze. -@returns Status code. If \p object - is already frozen, however, #BT_VALUE_STATUS_OK - is returned anyway (that is, this function never - returns #BT_VALUE_STATUS_FROZEN). - -@prenotnull{object} -@postrefcountsame{object} -@post On success, \p object and all its children - are frozen. - -@sa bt_value_is_frozen(): Returns whether or not a value object is - frozen. -*/ -extern enum bt_value_status bt_value_freeze(struct bt_value *object); - -/** -@brief Returns whether or not the value object \p object is frozen. - -@param[in] object Value object to check. -@returns #BT_TRUE if \p object is frozen. - -@prenotnull{object} -@postrefcountsame{object} -*/ -extern bt_bool bt_value_is_frozen(const struct bt_value *object); - /** @brief Creates a \em deep copy of the value object \p object. @@ -1187,8 +1136,8 @@ The user function \em must return #BT_TRUE to continue the traversal of @param[in] cb User function to call back. @param[in] data User data passed to the user function. @returns Status code. More - specifically, #BT_VALUE_STATUS_CANCELLED is - returned if the loop was cancelled by the user + specifically, #BT_VALUE_STATUS_CANCELED is + returned if the loop was canceled by the user function. @prenotnull{map_obj} diff --git a/lib/ctf-ir/attributes.c b/lib/ctf-ir/attributes.c index f3d6ba10..b5fe54cd 100644 --- a/lib/ctf-ir/attributes.c +++ b/lib/ctf-ir/attributes.c @@ -31,9 +31,10 @@ #include #include #include +#include #include -#include #include +#include #define BT_ATTR_NAME_INDEX 0 #define BT_ATTR_VALUE_INDEX 1 @@ -96,6 +97,13 @@ const char *bt_attributes_get_field_name(struct bt_value *attr_obj, goto end; } + if (index >= bt_value_array_size(attr_obj)) { + BT_LOGW("Invalid parameter: index is out of bounds: " + "index=%" PRIu64 ", count=%" PRId64, + index, bt_value_array_size(attr_obj)); + goto end; + } + attr_field_obj = bt_value_array_get(attr_obj, index); if (!attr_field_obj) { BT_LOGE("Cannot get attributes object's array value's element by index: " @@ -137,6 +145,13 @@ struct bt_value *bt_attributes_get_field_value(struct bt_value *attr_obj, goto end; } + if (index >= bt_value_array_size(attr_obj)) { + BT_LOGW("Invalid parameter: index is out of bounds: " + "index=%" PRIu64 ", count=%" PRId64, + index, bt_value_array_size(attr_obj)); + goto end; + } + attr_field_obj = bt_value_array_get(attr_obj, index); if (!attr_field_obj) { BT_LOGE("Cannot get attributes object's array value's element by index: " @@ -316,7 +331,7 @@ int bt_attributes_freeze(struct bt_value *attr_obj) BT_LOGD("Freezing attributes object: value-addr=%p", attr_obj); count = bt_value_array_size(attr_obj); - assert(count >= 0); + BT_ASSERT(count >= 0); /* * We do not freeze the array value object itself here, since diff --git a/lib/ctf-ir/clock-class.c b/lib/ctf-ir/clock-class.c index 730f8f34..990cb08e 100644 --- a/lib/ctf-ir/clock-class.c +++ b/lib/ctf-ir/clock-class.c @@ -39,6 +39,7 @@ #include #include #include +#include static void bt_clock_class_destroy(struct bt_object *obj); @@ -668,7 +669,7 @@ void set_ns_from_epoch(struct bt_clock_value *clock_value) } s_ns = (int64_t) u_ns; - assert(s_ns >= 0); + BT_ASSERT(s_ns >= 0); if (clock_class->offset < 0) { if (clock_value->ns_from_epoch >= 0) { @@ -731,7 +732,7 @@ offset_ok: } s_ns = (int64_t) u_ns; - assert(s_ns >= 0); + BT_ASSERT(s_ns >= 0); /* Clock value (cycles) is always positive */ if (clock_value->ns_from_epoch <= 0) { @@ -865,8 +866,8 @@ int bt_clock_class_compare(struct bt_clock_class *clock_class_a, struct bt_clock_class *clock_class_b) { int ret = 1; - assert(clock_class_a); - assert(clock_class_b); + BT_ASSERT(clock_class_a); + BT_ASSERT(clock_class_b); /* Name */ if (strcmp(clock_class_a->name->str, clock_class_b->name->str) != 0) { diff --git a/lib/ctf-ir/event-class.c b/lib/ctf-ir/event-class.c index 8e685eb7..4152a0b8 100644 --- a/lib/ctf-ir/event-class.c +++ b/lib/ctf-ir/event-class.c @@ -45,6 +45,7 @@ #include #include #include +#include #include #include @@ -410,7 +411,7 @@ int bt_event_class_add_field(struct bt_event_class *event_class, goto end; } - assert(bt_field_type_get_type_id(event_class->fields) == + BT_ASSERT(bt_field_type_get_type_id(event_class->fields) == BT_FIELD_TYPE_ID_STRUCT); ret = bt_field_type_structure_add_field(event_class->fields, type, name); @@ -443,7 +444,7 @@ int64_t bt_event_class_get_payload_type_field_count( goto end; } - assert(bt_field_type_get_type_id(event_class->fields) == + BT_ASSERT(bt_field_type_get_type_id(event_class->fields) == BT_FIELD_TYPE_ID_STRUCT); ret = bt_field_type_structure_get_field_count(event_class->fields); end: @@ -472,7 +473,7 @@ int bt_event_class_get_payload_type_field_by_index( goto end; } - assert(bt_field_type_get_type_id(event_class->fields) == + BT_ASSERT(bt_field_type_get_type_id(event_class->fields) == BT_FIELD_TYPE_ID_STRUCT); ret = bt_field_type_structure_get_field_by_index(event_class->fields, field_name, field_type, index); @@ -502,7 +503,7 @@ bt_event_class_get_payload_type_field_type_by_name( goto end; } - assert(bt_field_type_get_type_id(event_class->fields) == + BT_ASSERT(bt_field_type_get_type_id(event_class->fields) == BT_FIELD_TYPE_ID_STRUCT); name_quark = g_quark_try_string(name); if (!name_quark) { @@ -623,7 +624,7 @@ void bt_event_class_destroy(struct bt_object *obj) BT_HIDDEN void bt_event_class_freeze(struct bt_event_class *event_class) { - assert(event_class); + BT_ASSERT(event_class); if (event_class->frozen) { return; @@ -646,8 +647,8 @@ int bt_event_class_serialize(struct bt_event_class *event_class, int ret = 0; struct bt_value *attr_value = NULL; - assert(event_class); - assert(context); + BT_ASSERT(event_class); + BT_ASSERT(context); BT_LOGD("Serializing event class's metadata: " "event-class-addr=%p, event-class-name=\"%s\", " "event-class-id=%" PRId64 ", metadata-context-addr=%p", @@ -660,7 +661,7 @@ int bt_event_class_serialize(struct bt_event_class *event_class, /* Serialize attributes */ g_string_append_printf(context->string, "\tname = \"%s\";\n", event_class->name->str); - assert(event_class->id >= 0); + BT_ASSERT(event_class->id >= 0); g_string_append_printf(context->string, "\tid = %" PRId64 ";\n", event_class->id); g_string_append_printf(context->string, "\tstream_id = %" PRId64 ";\n", @@ -718,8 +719,8 @@ int bt_event_class_validate_single_clock_class( { int ret = 0; - assert(event_class); - assert(expected_clock_class); + BT_ASSERT(event_class); + BT_ASSERT(expected_clock_class); ret = bt_validate_single_clock_class(event_class->context, expected_clock_class); if (ret) { diff --git a/lib/ctf-ir/event.c b/lib/ctf-ir/event.c index 64385644..2fa1e953 100644 --- a/lib/ctf-ir/event.c +++ b/lib/ctf-ir/event.c @@ -52,8 +52,13 @@ #include #include #include +#include +#include #include +#define BT_ASSERT_PRE_EVENT_HOT(_event, _name) \ + BT_ASSERT_PRE_HOT((_event), (_name), ": +%!+e", (_event)) + static void bt_event_destroy(struct bt_object *obj); @@ -81,29 +86,18 @@ struct bt_event *bt_event_create(struct bt_event_class *event_class) int trace_valid = 0; struct bt_clock_class *expected_clock_class = NULL; + BT_ASSERT_PRE_NON_NULL(event_class, "Event class"); BT_LOGD("Creating event object: event-class-addr=%p, " "event-class-name=\"%s\", event-class-id=%" PRId64, event_class, bt_event_class_get_name(event_class), bt_event_class_get_id(event_class)); - if (!event_class) { - BT_LOGW_STR("Invalid parameter: event class is NULL."); - goto error; - } - stream_class = bt_event_class_get_stream_class(event_class); - - /* - * We disallow the creation of an event if its event class has not been - * associated to a stream class. - */ - if (!stream_class) { - BT_LOGW_STR("Event class is not part of a stream class."); - goto error; - } + BT_ASSERT_PRE(stream_class, + "Event class is not part of a stream class: %!+E", event_class); /* The event class was frozen when added to its stream class */ - assert(event_class->frozen); + BT_ASSERT(event_class->frozen); if (!stream_class->frozen) { if (stream_class->clock) { @@ -145,7 +139,7 @@ struct bt_event *bt_event_create(struct bt_event_class *event_class) BT_LOGD_STR("Event's class is part of a trace."); packet_header_type = bt_trace_get_packet_header_type(trace); trace_valid = trace->valid; - assert(trace_valid); + BT_ASSERT(trace_valid); environment = trace->environment; } @@ -325,38 +319,27 @@ error: BT_PUT(event_context); BT_PUT(event_payload); bt_put(expected_clock_class); - 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); - + BT_ASSERT(!packet_header_type); + BT_ASSERT(!packet_context_type); + BT_ASSERT(!event_header_type); + BT_ASSERT(!stream_event_ctx_type); + BT_ASSERT(!event_context_type); + BT_ASSERT(!event_payload_type); return event; } struct bt_event_class *bt_event_get_class(struct bt_event *event) { - struct bt_event_class *event_class = NULL; - - if (!event) { - BT_LOGW_STR("Invalid parameter: event is NULL."); - goto end; - } - - event_class = bt_get(bt_event_borrow_event_class(event)); -end: - return event_class; + BT_ASSERT_PRE_NON_NULL(event, "Event"); + return bt_get(bt_event_borrow_event_class(event)); } -struct bt_stream *bt_event_get_stream(struct bt_event *event) +BT_HIDDEN +struct bt_stream *bt_event_borrow_stream(struct bt_event *event) { struct bt_stream *stream = NULL; - if (!event) { - BT_LOGW_STR("Invalid parameter: event is NULL."); - goto end; - } + BT_ASSERT(event); /* * If the event has a parent, then this is its (writer) stream. @@ -364,64 +347,45 @@ struct bt_stream *bt_event_get_stream(struct bt_event *event) * is its (non-writer) stream. */ if (event->base.parent) { - stream = (struct bt_stream *) bt_object_get_parent(event); + stream = (struct bt_stream *) bt_object_borrow_parent(event); } else { if (event->packet) { - stream = bt_get(event->packet->stream); + stream = event->packet->stream; } } -end: return stream; } -int bt_event_set_payload(struct bt_event *event, - const char *name, +struct bt_stream *bt_event_get_stream(struct bt_event *event) +{ + BT_ASSERT_PRE_NON_NULL(event, "Event"); + return bt_get(bt_event_borrow_stream(event)); +} + +int bt_event_set_payload(struct bt_event *event, const char *name, struct bt_field *payload) { int ret = 0; - if (!event || !payload) { - BT_LOGW("Invalid parameter: event or payload field is NULL: " - "event-addr=%p, payload-field-addr=%p", - event, payload); - ret = -1; - goto end; - } - - if (event->frozen) { - BT_LOGW("Invalid parameter: event is frozen: addr=%p, " - "event-class-name=\"%s\", event-class-id=%" PRId64, - event, bt_event_class_get_name(event->event_class), - bt_event_class_get_id(event->event_class)); - ret = -1; - goto end; - } + BT_ASSERT_PRE_NON_NULL(event, "Event"); + BT_ASSERT_PRE_NON_NULL(payload, "Payload field"); + BT_ASSERT_PRE_EVENT_HOT(event, "Event"); if (name) { ret = bt_field_structure_set_field_by_name( event->fields_payload, name, payload); } else { - struct bt_field_type *payload_type; - - payload_type = bt_field_get_type(payload); - - if (bt_field_type_compare(payload_type, - event->event_class->fields) == 0) { - bt_put(event->fields_payload); - bt_get(payload); - event->fields_payload = payload; - } else { - BT_LOGW("Invalid parameter: payload field type is different from the expected field type: " - "event-addr=%p, event-class-name=\"%s\", " - "event-class-id=%" PRId64, - event, - bt_event_class_get_name(event->event_class), - bt_event_class_get_id(event->event_class)); - ret = -1; - } + BT_ASSERT_PRE(bt_field_type_compare(payload->type, + event->event_class->fields) == 0, + "Payload field's type is different from the " + "expected field type: %![event-]+e, %![ft-]+F, " + "%![expected-ft-]+F", + event, payload->type, event->event_class->fields); - bt_put(payload_type); + bt_put(event->fields_payload); + bt_get(payload); + event->fields_payload = payload; } if (ret) { @@ -440,7 +404,6 @@ int bt_event_set_payload(struct bt_event *event, name, payload); } -end: return ret; } @@ -448,10 +411,7 @@ struct bt_field *bt_event_get_event_payload(struct bt_event *event) { struct bt_field *payload = NULL; - if (!event) { - BT_LOGW_STR("Invalid parameter: event is NULL."); - goto end; - } + BT_ASSERT_PRE_NON_NULL(event, "Event"); if (!event->fields_payload) { BT_LOGV("Event has no current payload field: addr=%p, " @@ -463,6 +423,7 @@ struct bt_field *bt_event_get_event_payload(struct bt_event *event) payload = event->fields_payload; bt_get(payload); + end: return payload; } @@ -478,10 +439,7 @@ struct bt_field *bt_event_get_payload(struct bt_event *event, { struct bt_field *field = NULL; - if (!event) { - BT_LOGW_STR("Invalid parameter: event is NULL."); - goto end; - } + BT_ASSERT_PRE_NON_NULL(event, "Event"); if (name) { field = bt_field_structure_get_field_by_name( @@ -490,7 +448,7 @@ struct bt_field *bt_event_get_payload(struct bt_event *event, field = event->fields_payload; bt_get(field); } -end: + return field; } @@ -499,26 +457,18 @@ struct bt_field *bt_event_get_payload_by_index( { struct bt_field *field = NULL; - if (!event) { - BT_LOGW_STR("Invalid parameter: event is NULL."); - goto end; - } - + BT_ASSERT_PRE_NON_NULL(event, "Event"); field = bt_field_structure_get_field_by_index(event->fields_payload, index); -end: + return field; } -struct bt_field *bt_event_get_header( - struct bt_event *event) +struct bt_field *bt_event_get_header(struct bt_event *event) { struct bt_field *header = NULL; - if (!event) { - BT_LOGW_STR("Invalid parameter: event is NULL."); - goto end; - } + BT_ASSERT_PRE_NON_NULL(event, "Event"); if (!event->event_header) { BT_LOGV("Event has no current header field: addr=%p, " @@ -530,64 +480,35 @@ struct bt_field *bt_event_get_header( header = event->event_header; bt_get(header); + end: return header; } -int bt_event_set_header(struct bt_event *event, - struct bt_field *header) +int bt_event_set_header(struct bt_event *event, struct bt_field *header) { - int ret = 0; - struct bt_field_type *field_type = NULL; - struct bt_stream_class *stream_class = NULL; - - if (!event) { - BT_LOGW_STR("Invalid parameter: event is NULL."); - ret = -1; - goto end; - } + BT_ASSERT_PRE_NON_NULL(event, "Event"); + BT_ASSERT_PRE_EVENT_HOT(event, "Event"); - if (event->frozen) { - BT_LOGW("Invalid parameter: event is frozen: addr=%p, " - "event-class-name=\"%s\", event-class-id=%" PRId64, - event, bt_event_class_get_name(event->event_class), - bt_event_class_get_id(event->event_class)); - ret = -1; - goto end; - } - - stream_class = (struct bt_stream_class *) bt_object_get_parent( - event->event_class); /* * Ensure the provided header's type matches the one registered to the * stream class. */ if (header) { - field_type = bt_field_get_type(header); - if (bt_field_type_compare(field_type, - stream_class->event_header_type)) { - BT_LOGW("Invalid parameter: header field type is different from the expected field type: " - "event-addr=%p, event-class-name=\"%s\", " - "event-class-id=%" PRId64, - event, - bt_event_class_get_name(event->event_class), - bt_event_class_get_id(event->event_class)); - ret = -1; - goto end; - } + BT_ASSERT_PRE(bt_field_type_compare(header->type, + bt_event_class_borrow_stream_class(event->event_class)->event_header_type) == 0, + "Header field's type is different from the " + "expected field type: %![event-]+e, %![ft-]+F, " + "%![expected-ft-]+F", + event, header->type, + bt_event_class_borrow_stream_class(event->event_class)->event_header_type); } else { - if (stream_class->event_header_type) { - BT_LOGW("Invalid parameter: setting no event header but event header field type is not NULL: " - "event-addr=%p, event-class-name=\"%s\", " - "event-class-id=%" PRId64 ", " - "event-header-ft-addr=%p", - event, - bt_event_class_get_name(event->event_class), - bt_event_class_get_id(event->event_class), - stream_class->event_header_type); - ret = -1; - goto end; - } + BT_ASSERT_PRE(!bt_event_class_borrow_stream_class(event->event_class)->event_header_type, + "Setting no event header field, " + "but event header field type is not NULL: ", + "%![event-]+e, %![header-ft-]+F", + event, + bt_event_class_borrow_stream_class(event->event_class)->event_header_type); } bt_put(event->event_header); @@ -597,21 +518,14 @@ int bt_event_set_header(struct bt_event *event, "header-field-addr=%p", event, bt_event_class_get_name(event->event_class), bt_event_class_get_id(event->event_class), header); -end: - bt_put(stream_class); - bt_put(field_type); - return ret; + return 0; } -struct bt_field *bt_event_get_event_context( - struct bt_event *event) +struct bt_field *bt_event_get_event_context(struct bt_event *event) { struct bt_field *context = NULL; - if (!event) { - BT_LOGW_STR("Invalid parameter: event is NULL."); - goto end; - } + BT_ASSERT_PRE_NON_NULL(event, "Event"); if (!event->context_payload) { BT_LOGV("Event has no current context field: addr=%p, " @@ -623,58 +537,29 @@ struct bt_field *bt_event_get_event_context( context = event->context_payload; bt_get(context); + end: return context; } -int bt_event_set_event_context(struct bt_event *event, - struct bt_field *context) +int bt_event_set_event_context(struct bt_event *event, struct bt_field *context) { - int ret = 0; - struct bt_field_type *field_type = NULL; - - if (!event) { - BT_LOGW_STR("Invalid parameter: event is NULL."); - ret = -1; - goto end; - } - - if (event->frozen) { - BT_LOGW("Invalid parameter: event is frozen: addr=%p, " - "event-class-name=\"%s\", event-class-id=%" PRId64, - event, bt_event_class_get_name(event->event_class), - bt_event_class_get_id(event->event_class)); - ret = -1; - goto end; - } + BT_ASSERT_PRE_NON_NULL(event, "Event"); + BT_ASSERT_PRE_EVENT_HOT(event, "Event"); if (context) { - field_type = bt_field_get_type(context); - - if (bt_field_type_compare(field_type, - event->event_class->context)) { - BT_LOGW("Invalid parameter: context field type is different from the expected field type: " - "event-addr=%p, event-class-name=\"%s\", " - "event-class-id=%" PRId64, - event, - bt_event_class_get_name(event->event_class), - bt_event_class_get_id(event->event_class)); - ret = -1; - goto end; - } + BT_ASSERT_PRE(bt_field_type_compare(context->type, + event->event_class->context) == 0, + "Context field's type is different from the " + "expected field type: %![event-]+e, %![ft-]+F, " + "%![expected-ft-]+F", + event, context->type, event->event_class->context); } else { - if (event->event_class->context) { - BT_LOGW("Invalid parameter: setting no event context but event context field type is not NULL: " - "event-addr=%p, event-class-name=\"%s\", " - "event-class-id=%" PRId64 ", " - "event-context-ft-addr=%p", - event, - bt_event_class_get_name(event->event_class), - bt_event_class_get_id(event->event_class), - event->event_class->context); - ret = -1; - goto end; - } + BT_ASSERT_PRE(!event->event_class->context, + "Setting no event context field, " + "but event context field type is not NULL: ", + "%![event-]+e, %![context-ft-]+F", + event, event->event_class->context); } bt_put(event->context_payload); @@ -684,9 +569,7 @@ int bt_event_set_event_context(struct bt_event *event, "context-field-addr=%p", event, bt_event_class_get_name(event->event_class), bt_event_class_get_id(event->event_class), context); -end: - bt_put(field_type); - return ret; + return 0; } struct bt_field *bt_event_get_stream_event_context( @@ -694,10 +577,7 @@ struct bt_field *bt_event_get_stream_event_context( { struct bt_field *stream_event_context = NULL; - if (!event) { - BT_LOGW_STR("Invalid parameter: event is NULL."); - goto end; - } + BT_ASSERT_PRE_NON_NULL(event, "Event"); if (!event->stream_event_context) { BT_LOGV("Event has no current stream event context field: addr=%p, " @@ -708,6 +588,7 @@ struct bt_field *bt_event_get_stream_event_context( } stream_event_context = event->stream_event_context; + end: return bt_get(stream_event_context); } @@ -715,58 +596,24 @@ end: int bt_event_set_stream_event_context(struct bt_event *event, struct bt_field *stream_event_context) { - int ret = 0; - struct bt_field_type *field_type = NULL; - struct bt_stream_class *stream_class = NULL; - - if (!event) { - BT_LOGW_STR("Invalid parameter: event is NULL."); - ret = -1; - goto end; - } - - if (event->frozen) { - BT_LOGW("Invalid parameter: event is frozen: addr=%p, " - "event-class-name=\"%s\", event-class-id=%" PRId64, - event, bt_event_class_get_name(event->event_class), - bt_event_class_get_id(event->event_class)); - ret = -1; - goto end; - } - - stream_class = bt_event_class_get_stream_class(event->event_class); - /* - * We should not have been able to create the event without associating - * the event class to a stream class. - */ - assert(stream_class); + BT_ASSERT_PRE_NON_NULL(event, "Event"); + BT_ASSERT_PRE_EVENT_HOT(event, "Event"); if (stream_event_context) { - field_type = bt_field_get_type(stream_event_context); - if (bt_field_type_compare(field_type, - stream_class->event_context_type)) { - BT_LOGW("Invalid parameter: stream event context field type is different from the expected field type: " - "event-addr=%p, event-class-name=\"%s\", " - "event-class-id=%" PRId64, - event, - bt_event_class_get_name(event->event_class), - bt_event_class_get_id(event->event_class)); - ret = -1; - goto end; - } + BT_ASSERT_PRE(bt_field_type_compare(stream_event_context->type, + bt_event_class_borrow_stream_class(event->event_class)->event_context_type) == 0, + "Stream event context field's type is different from the " + "expected field type: %![event-]+e, %![ft-]+F, " + "%![expected-ft-]+F", + event, stream_event_context->type, + bt_event_class_borrow_stream_class(event->event_class)->event_context_type); } else { - if (stream_class->event_context_type) { - BT_LOGW("Invalid parameter: setting no stream event context but stream event context field type is not NULL: " - "event-addr=%p, event-class-name=\"%s\", " - "event-class-id=%" PRId64 ", " - "stream-event-context-ft-addr=%p", - event, - bt_event_class_get_name(event->event_class), - bt_event_class_get_id(event->event_class), - stream_class->event_context_type); - ret = -1; - goto end; - } + BT_ASSERT_PRE(!bt_event_class_borrow_stream_class(event->event_class)->event_context_type, + "Setting no stream event context field, " + "but stream event context field type is not NULL: ", + "%![event-]+e, %![context-ft-]+F", + event, + bt_event_class_borrow_stream_class(event->event_class)->event_context_type); } bt_get(stream_event_context); @@ -777,10 +624,7 @@ int bt_event_set_stream_event_context(struct bt_event *event, event, bt_event_class_get_name(event->event_class), bt_event_class_get_id(event->event_class), stream_event_context); -end: - BT_PUT(stream_class); - bt_put(field_type); - return ret; + return 0; } /* Pre-2.0 CTF writer backward compatibility */ @@ -832,13 +676,8 @@ struct bt_clock_value *bt_event_get_clock_value( { struct bt_clock_value *clock_value = NULL; - if (!event || !clock_class) { - BT_LOGW("Invalid parameter: event or clock class is NULL: " - "event-addr=%p, clock-class-addr=%p", - event, clock_class); - goto end; - } - + BT_ASSERT_PRE_NON_NULL(event, "Event"); + BT_ASSERT_PRE_NON_NULL(clock_class, "Clock class"); clock_value = g_hash_table_lookup(event->clock_values, clock_class); if (!clock_value) { BT_LOGV("No clock value associated to the given clock class: " @@ -852,6 +691,7 @@ struct bt_clock_value *bt_event_get_clock_value( } bt_get(clock_value); + end: return clock_value; } @@ -859,49 +699,25 @@ end: int bt_event_set_clock_value(struct bt_event *event, struct bt_clock_value *value) { - int ret = 0; struct bt_trace *trace; struct bt_stream_class *stream_class; struct bt_event_class *event_class; struct bt_clock_class *clock_class = NULL; - if (!event || !value) { - BT_LOGW("Invalid parameter: event or clock value is NULL: " - "event-addr=%p, clock-value-addr=%p", - event, value); - ret = -1; - goto end; - } - - if (event->frozen) { - BT_LOGW("Invalid parameter: event is frozen: addr=%p, " - "event-class-name=\"%s\", event-class-id=%" PRId64, - event, bt_event_class_get_name(event->event_class), - bt_event_class_get_id(event->event_class)); - ret = -1; - goto end; - } - + BT_ASSERT_PRE_NON_NULL(event, "Event"); + BT_ASSERT_PRE_NON_NULL(value, "Clock value"); + BT_ASSERT_PRE_EVENT_HOT(event, "Event"); clock_class = bt_clock_value_get_class(value); event_class = bt_event_borrow_event_class(event); - assert(event_class); + BT_ASSERT(event_class); stream_class = bt_event_class_borrow_stream_class(event_class); - assert(stream_class); + BT_ASSERT(stream_class); trace = bt_stream_class_borrow_trace(stream_class); - assert(trace); - - if (!bt_trace_has_clock_class(trace, clock_class)) { - BT_LOGW("Invalid parameter: clock class is not part of event's trace: " - "event-addr=%p, event-class-name=\"%s\", " - "event-class-id=%" PRId64 ", clock-class-addr=%p, " - "clock-class-name=\"%s\"", - event, bt_event_class_get_name(event->event_class), - bt_event_class_get_id(event->event_class), - clock_class, bt_clock_class_get_name(clock_class)); - ret = -1; - goto end; - } - + BT_ASSERT(trace); + BT_ASSERT_PRE(bt_trace_has_clock_class(trace, clock_class), + "Clock class is not part of event's trace: " + "%![event-]+e, %![clock-class-]+K", + event, clock_class); g_hash_table_insert(event->clock_values, clock_class, bt_get(value)); BT_LOGV("Set event's clock value: " "event-addr=%p, event-class-name=\"%s\", " @@ -913,89 +729,79 @@ int bt_event_set_clock_value(struct bt_event *event, clock_class, bt_clock_class_get_name(clock_class), value, value->value); clock_class = NULL; - -end: bt_put(clock_class); - return ret; + return 0; } BT_HIDDEN -int bt_event_validate(struct bt_event *event) +int _bt_event_validate(struct bt_event *event) { - /* Make sure each field's payload has been set */ - int ret; - struct bt_stream_class *stream_class = NULL; + int ret = 0; + struct bt_stream_class *stream_class; - assert(event); + BT_ASSERT(event); if (event->event_header) { - ret = bt_field_validate(event->event_header); + ret = bt_field_validate_recursive(event->event_header); if (ret) { - BT_LOGD("Invalid event's header field: " - "event-addr=%p, event-class-name=\"%s\", " - "event-class-id=%" PRId64, - event, bt_event_class_get_name(event->event_class), - bt_event_class_get_id(event->event_class)); + BT_ASSERT_PRE_MSG("Invalid event's header field: " + "%![event-]+e, %![field-]+f", + event, event->event_header); goto end; } } - stream_class = bt_event_class_get_stream_class(event->event_class); + stream_class = bt_event_class_borrow_stream_class(event->event_class); + /* * We should not have been able to create the event without associating * the event class to a stream class. */ - assert(stream_class); + BT_ASSERT(stream_class); + if (stream_class->event_context_type) { - ret = bt_field_validate(event->stream_event_context); + ret = bt_field_validate_recursive(event->stream_event_context); if (ret) { - BT_LOGD("Invalid event's stream event context field: " - "event-addr=%p, event-class-name=\"%s\", " - "event-class-id=%" PRId64, - event, - bt_event_class_get_name(event->event_class), - bt_event_class_get_id(event->event_class)); + BT_ASSERT_PRE_MSG("Invalid event's stream event context field: " + "%![event-]+e, %![field-]+f", + event, event->stream_event_context); goto end; } } - ret = bt_field_validate(event->fields_payload); + if (event->event_class->context) { + ret = bt_field_validate_recursive(event->context_payload); + if (ret) { + BT_ASSERT_PRE_MSG("Invalid event's payload field: " + "%![event-]+e, %![field-]+f", + event, event->context_payload); + goto end; + } + } + + ret = bt_field_validate_recursive(event->fields_payload); if (ret) { - BT_LOGD("Invalid event's payload field: " - "event-addr=%p, event-class-name=\"%s\", " - "event-class-id=%" PRId64, - event, - bt_event_class_get_name(event->event_class), - bt_event_class_get_id(event->event_class)); + BT_ASSERT_PRE_MSG("Invalid event's payload field: " + "%![event-]+e, %![field-]+f", + event, event->fields_payload); goto end; } - if (event->event_class->context) { - BT_LOGD("Invalid event's context field: " - "event-addr=%p, event-class-name=\"%s\", " - "event-class-id=%" PRId64, - event, - bt_event_class_get_name(event->event_class), - bt_event_class_get_id(event->event_class)); - ret = bt_field_validate(event->context_payload); - } end: - bt_put(stream_class); return ret; } BT_HIDDEN -int bt_event_serialize(struct bt_event *event, - struct bt_stream_pos *pos, +int bt_event_serialize(struct bt_event *event, struct bt_stream_pos *pos, enum bt_byte_order native_byte_order) { int ret = 0; - assert(event); - assert(pos); + BT_ASSERT(event); + BT_ASSERT(pos); BT_LOGV_STR("Serializing event's context field."); if (event->context_payload) { - ret = bt_field_serialize(event->context_payload, pos, + ret = bt_field_serialize_recursive(event->context_payload, pos, native_byte_order); if (ret) { BT_LOGW("Cannot serialize event's context field: " @@ -1010,7 +816,7 @@ int bt_event_serialize(struct bt_event *event, BT_LOGV_STR("Serializing event's payload field."); if (event->fields_payload) { - ret = bt_field_serialize(event->fields_payload, pos, + ret = bt_field_serialize_recursive(event->fields_payload, pos, native_byte_order); if (ret) { BT_LOGW("Cannot serialize event's payload field: " @@ -1030,11 +836,7 @@ struct bt_packet *bt_event_get_packet(struct bt_event *event) { struct bt_packet *packet = NULL; - if (!event) { - BT_LOGW_STR("Invalid parameter: event is NULL."); - goto end; - } - + BT_ASSERT_PRE_NON_NULL(event, "Event"); if (!event->packet) { BT_LOGV("Event has no current packet: addr=%p, " "event-class-name=\"%s\", event-class-id=%" PRId64, @@ -1044,6 +846,7 @@ struct bt_packet *bt_event_get_packet(struct bt_event *event) } packet = bt_get(event->packet); + end: return packet; } @@ -1051,65 +854,25 @@ end: int bt_event_set_packet(struct bt_event *event, struct bt_packet *packet) { - struct bt_stream_class *event_stream_class = NULL; - struct bt_stream_class *packet_stream_class = NULL; - struct bt_stream *stream = NULL; - int ret = 0; - - if (!event || !packet) { - BT_LOGW("Invalid parameter: event or packet is NULL: " - "event-addr=%p, packet-addr=%p", - event, packet); - ret = -1; - goto end; - } - - if (event->frozen) { - BT_LOGW("Invalid parameter: event is frozen: addr=%p, " - "event-class-name=\"%s\", event-class-id=%" PRId64, - event, bt_event_class_get_name(event->event_class), - bt_event_class_get_id(event->event_class)); - ret = -1; - goto end; - } + BT_ASSERT_PRE_NON_NULL(event, "Event"); + BT_ASSERT_PRE_NON_NULL(packet, "Packet"); + BT_ASSERT_PRE_EVENT_HOT(event, "Event"); /* * Make sure the new packet was created by this event's * stream, if it is set. */ - stream = bt_event_get_stream(event); - if (stream) { - if (packet->stream != stream) { - BT_LOGW("Invalid parameter: packet's stream and event's stream differ: " - "event-addr=%p, event-class-name=\"%s\", " - "event-class-id=%" PRId64 ", packet-stream-addr=%p, " - "event-stream-addr=%p", - event, bt_event_class_get_name(event->event_class), - bt_event_class_get_id(event->event_class), - packet->stream, stream); - ret = -1; - goto end; - } + if (bt_event_borrow_stream(event)) { + BT_ASSERT_PRE(packet->stream == bt_event_borrow_stream(event), + "Packet's stream and event's stream differ: " + "%![event-]+e, %![packet-]+a", + event, packet); } else { - event_stream_class = - bt_event_class_get_stream_class(event->event_class); - packet_stream_class = - bt_stream_get_class(packet->stream); - - assert(event_stream_class); - assert(packet_stream_class); - - if (event_stream_class != packet_stream_class) { - BT_LOGW("Invalid parameter: packet's stream class and event's stream class differ: " - "event-addr=%p, event-class-name=\"%s\", " - "event-class-id=%" PRId64 ", packet-stream-class-addr=%p, " - "event-stream-class-addr=%p", - event, bt_event_class_get_name(event->event_class), - bt_event_class_get_id(event->event_class), - packet_stream_class, event_stream_class); - ret = -1; - goto end; - } + BT_ASSERT_PRE(bt_event_class_borrow_stream_class(event->event_class) == + packet->stream->stream_class, + "Packet's stream class and event's stream class differ: " + "%![event-]+e, %![packet-]+a", + event, packet); } bt_get(packet); @@ -1119,19 +882,13 @@ int bt_event_set_packet(struct bt_event *event, "packet-addr=%p", event, bt_event_class_get_name(event->event_class), bt_event_class_get_id(event->event_class), packet); - -end: - BT_PUT(stream); - BT_PUT(event_stream_class); - BT_PUT(packet_stream_class); - - return ret; + return 0; } BT_HIDDEN -void bt_event_freeze(struct bt_event *event) +void _bt_event_freeze(struct bt_event *event) { - assert(event); + BT_ASSERT(event); if (event->frozen) { return; @@ -1143,12 +900,12 @@ void bt_event_freeze(struct bt_event *event) bt_event_class_get_id(event->event_class)); bt_packet_freeze(event->packet); BT_LOGD_STR("Freezing event's header field."); - bt_field_freeze(event->event_header); + bt_field_freeze_recursive(event->event_header); BT_LOGD_STR("Freezing event's stream event context field."); - bt_field_freeze(event->stream_event_context); + bt_field_freeze_recursive(event->stream_event_context); BT_LOGD_STR("Freezing event's context field."); - bt_field_freeze(event->context_payload); + bt_field_freeze_recursive(event->context_payload); BT_LOGD_STR("Freezing event's payload field."); - bt_field_freeze(event->fields_payload); + bt_field_freeze_recursive(event->fields_payload); event->frozen = 1; } diff --git a/lib/ctf-ir/field-path.c b/lib/ctf-ir/field-path.c index 32ba02ae..61a57fe3 100644 --- a/lib/ctf-ir/field-path.c +++ b/lib/ctf-ir/field-path.c @@ -35,6 +35,7 @@ #include #include #include +#include #include static @@ -98,7 +99,7 @@ struct bt_field_path *bt_field_path_copy( { struct bt_field_path *new_path; - assert(path); + BT_ASSERT(path); BT_LOGD("Copying field path: addr=%p, index-count=%u", path, path->indexes->len); new_path = bt_field_path_create(); diff --git a/lib/ctf-ir/field-types.c b/lib/ctf-ir/field-types.c index ba288b2e..a04384d2 100644 --- a/lib/ctf-ir/field-types.c +++ b/lib/ctf-ir/field-types.c @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -397,7 +398,7 @@ gint compare_enumeration_mappings_unsigned(struct enumeration_mapping **a, static void bt_field_type_init(struct bt_field_type *type, bt_bool init_bo) { - assert(type && (type->id > BT_FIELD_TYPE_ID_UNKNOWN) && + BT_ASSERT(type && (type->id > BT_FIELD_TYPE_ID_UNKNOWN) && (type->id < BT_FIELD_TYPE_ID_NR)); bt_object_init(type, bt_field_type_destroy); @@ -411,7 +412,7 @@ void bt_field_type_init(struct bt_field_type *type, bt_bool init_bo) BT_LOGD("Setting initial field type's byte order: bo=%s", bt_byte_order_string(bo)); ret = bt_field_type_set_byte_order(type, bo); - assert(ret == 0); + BT_ASSERT(ret == 0); } type->alignment = 1; @@ -464,7 +465,7 @@ void bt_field_type_destroy(struct bt_object *obj) type = container_of(obj, struct bt_field_type, base); type_id = type->id; - assert(type_id > BT_FIELD_TYPE_ID_UNKNOWN && + BT_ASSERT(type_id > BT_FIELD_TYPE_ID_UNKNOWN && type_id < BT_FIELD_TYPE_ID_NR); type_destroy_funcs[type_id](type); } @@ -579,7 +580,7 @@ int bt_field_type_enumeration_validate(struct bt_field_type *type) struct bt_field_type *container_type = bt_field_type_enumeration_get_container_type(type); - assert(container_type); + BT_ASSERT(container_type); ret = bt_field_type_validate(container_type); if (ret) { BT_LOGW("Invalid enumeration field type: container type is invalid: " @@ -619,7 +620,7 @@ int bt_field_type_sequence_validate(struct bt_field_type *type) } element_type = bt_field_type_sequence_get_element_type(type); - assert(element_type); + BT_ASSERT(element_type); ret = bt_field_type_validate(element_type); if (ret) { BT_LOGW("Invalid sequence field type: invalid element field type: " @@ -640,7 +641,7 @@ int bt_field_type_array_validate(struct bt_field_type *type) struct bt_field_type *element_type = NULL; element_type = bt_field_type_array_get_element_type(type); - assert(element_type); + BT_ASSERT(element_type); ret = bt_field_type_validate(element_type); if (ret) { BT_LOGW("Invalid array field type: invalid element field type: " @@ -660,14 +661,14 @@ int bt_field_type_structure_validate(struct bt_field_type *type) int64_t field_count = bt_field_type_structure_get_field_count(type); int64_t i; - assert(field_count >= 0); + BT_ASSERT(field_count >= 0); for (i = 0; i < field_count; ++i) { const char *field_name; ret = bt_field_type_structure_get_field_by_index(type, &field_name, &child_type, i); - assert(ret == 0); + BT_ASSERT(ret == 0); ret = bt_field_type_validate(child_type); if (ret) { BT_LOGW("Invalid structure field type: " @@ -761,7 +762,7 @@ int bt_field_type_variant_validate(struct bt_field_type *type) ret = bt_field_type_variant_get_field_by_index(type, &field_name, &child_type, i); - assert(ret == 0); + BT_ASSERT(ret == 0); ret = bt_field_type_validate(child_type); if (ret) { BT_LOGW("Invalid variant field type: " @@ -795,7 +796,7 @@ int bt_field_type_validate(struct bt_field_type *type) int ret = 0; enum bt_field_type_id id = bt_field_type_get_type_id(type); - assert(type); + BT_ASSERT(type); if (type->valid) { /* Already marked as valid */ @@ -1485,7 +1486,7 @@ int bt_field_type_enumeration_get_mapping_signed( if (mapping_name) { *mapping_name = g_quark_to_string(mapping->string); - assert(*mapping_name); + BT_ASSERT(*mapping_name); } if (range_begin) { @@ -1523,7 +1524,7 @@ int bt_field_type_enumeration_get_mapping_unsigned( if (mapping_name) { *mapping_name = g_quark_to_string(mapping->string); - assert(*mapping_name); + BT_ASSERT(*mapping_name); } if (range_begin) { @@ -2015,10 +2016,10 @@ int bt_field_type_structure_replace_field(struct bt_field_type *type, GQuark name_quark; uint64_t i; - assert(type); - assert(field_name); - assert(field_type); - assert(type->id == BT_FIELD_TYPE_ID_STRUCT); + BT_ASSERT(type); + BT_ASSERT(field_name); + BT_ASSERT(field_type); + BT_ASSERT(type->id == BT_FIELD_TYPE_ID_STRUCT); structure = container_of(type, struct bt_field_type_structure, parent); name_quark = g_quark_from_string(field_name); @@ -2165,7 +2166,7 @@ int bt_field_type_structure_get_field_by_index( } if (field_name) { *field_name = g_quark_to_string(field->name); - assert(*field_name); + BT_ASSERT(*field_name); } end: return ret; @@ -2611,7 +2612,7 @@ int bt_field_type_variant_get_field_by_index(struct bt_field_type *type, } if (field_name) { *field_name = g_quark_to_string(field->name); - assert(*field_name); + BT_ASSERT(*field_name); } end: return ret; @@ -2982,7 +2983,7 @@ int bt_field_type_get_alignment(struct bt_field_type *type) struct bt_field_type *element = bt_field_type_sequence_get_element_type(type); - assert(element); + BT_ASSERT(element); ret = bt_field_type_get_alignment(element); bt_put(element); break; @@ -2992,7 +2993,7 @@ int bt_field_type_get_alignment(struct bt_field_type *type) struct bt_field_type *element = bt_field_type_array_get_element_type(type); - assert(element); + BT_ASSERT(element); ret = bt_field_type_get_alignment(element); bt_put(element); break; @@ -3003,7 +3004,7 @@ int bt_field_type_get_alignment(struct bt_field_type *type) element_count = bt_field_type_structure_get_field_count( type); - assert(element_count >= 0); + BT_ASSERT(element_count >= 0); for (i = 0; i < element_count; i++) { struct bt_field_type *field = NULL; @@ -3011,8 +3012,8 @@ int bt_field_type_get_alignment(struct bt_field_type *type) ret = bt_field_type_structure_get_field_by_index( type, NULL, &field, i); - assert(ret == 0); - assert(field); + BT_ASSERT(ret == 0); + BT_ASSERT(field); field_alignment = bt_field_type_get_alignment( field); bt_put(field); @@ -3157,7 +3158,7 @@ enum bt_byte_order bt_field_type_get_byte_order( goto end; } - assert(ret == BT_BYTE_ORDER_NATIVE || + BT_ASSERT(ret == BT_BYTE_ORDER_NATIVE || ret == BT_BYTE_ORDER_LITTLE_ENDIAN || ret == BT_BYTE_ORDER_BIG_ENDIAN || ret == BT_BYTE_ORDER_NETWORK); @@ -3270,7 +3271,7 @@ void bt_ctf_field_type_put(struct bt_field_type *type) } BT_HIDDEN -void bt_field_type_freeze(struct bt_field_type *type) +void _bt_field_type_freeze(struct bt_field_type *type) { if (!type || type->frozen) { return; @@ -3354,8 +3355,8 @@ int bt_field_type_serialize(struct bt_field_type *type, { int ret; - assert(type); - assert(context); + BT_ASSERT(type); + BT_ASSERT(context); /* Make sure field type is valid before serializing it */ ret = bt_field_type_validate(type); @@ -3920,7 +3921,7 @@ int bt_field_type_integer_serialize(struct bt_field_type *type, const char *clock_name = bt_clock_class_get_name( integer->mapped_clock); - assert(clock_name); + BT_ASSERT(clock_name); g_string_append_printf(context->string, "; map = clock.%s.value", clock_name); } @@ -3943,9 +3944,9 @@ int bt_field_type_enumeration_serialize(struct bt_field_type *type, BT_LOGD("Serializing enumeration field type's metadata: " "ft-addr=%p, metadata-context-addr=%p", type, context); container_type = bt_field_type_enumeration_get_container_type(type); - assert(container_type); + BT_ASSERT(container_type); container_signed = bt_ctf_field_type_integer_get_signed(container_type); - assert(container_signed >= 0); + BT_ASSERT(container_signed >= 0); g_string_append(context->string, "enum : "); BT_LOGD_STR("Serializing enumeration field type's container field type's metadata."); ret = bt_field_type_serialize(enumeration->container, context); diff --git a/lib/ctf-ir/fields.c b/lib/ctf-ir/fields.c index 0fe5630e..5faaaec8 100644 --- a/lib/ctf-ir/fields.c +++ b/lib/ctf-ir/fields.c @@ -37,28 +37,24 @@ #include #include #include +#include +#include #include static struct bt_field *bt_field_integer_create(struct bt_field_type *); static -struct bt_field *bt_field_enumeration_create( - struct bt_field_type *); +struct bt_field *bt_field_enumeration_create(struct bt_field_type *); static -struct bt_field *bt_field_floating_point_create( - struct bt_field_type *); +struct bt_field *bt_field_floating_point_create(struct bt_field_type *); static -struct bt_field *bt_field_structure_create( - struct bt_field_type *); +struct bt_field *bt_field_structure_create(struct bt_field_type *); static -struct bt_field *bt_field_variant_create( - struct bt_field_type *); +struct bt_field *bt_field_variant_create(struct bt_field_type *); static -struct bt_field *bt_field_array_create( - struct bt_field_type *); +struct bt_field *bt_field_array_create(struct bt_field_type *); static -struct bt_field *bt_field_sequence_create( - struct bt_field_type *); +struct bt_field *bt_field_sequence_create(struct bt_field_type *); static struct bt_field *bt_field_string_create(struct bt_field_type *); @@ -67,68 +63,68 @@ void bt_field_destroy(struct bt_object *); static void bt_field_integer_destroy(struct bt_field *); static -void bt_field_enumeration_destroy(struct bt_field *); +void bt_field_enumeration_destroy_recursive(struct bt_field *); static void bt_field_floating_point_destroy(struct bt_field *); static -void bt_field_structure_destroy(struct bt_field *); +void bt_field_structure_destroy_recursive(struct bt_field *); static -void bt_field_variant_destroy(struct bt_field *); +void bt_field_variant_destroy_recursive(struct bt_field *); static -void bt_field_array_destroy(struct bt_field *); +void bt_field_array_destroy_recursive(struct bt_field *); static -void bt_field_sequence_destroy(struct bt_field *); +void bt_field_sequence_destroy_recursive(struct bt_field *); static void bt_field_string_destroy(struct bt_field *); static int bt_field_generic_validate(struct bt_field *); static -int bt_field_structure_validate(struct bt_field *); +int bt_field_structure_validate_recursive(struct bt_field *); static -int bt_field_variant_validate(struct bt_field *); +int bt_field_variant_validate_recursive(struct bt_field *); static -int bt_field_enumeration_validate(struct bt_field *); +int bt_field_enumeration_validate_recursive(struct bt_field *); static -int bt_field_array_validate(struct bt_field *); +int bt_field_array_validate_recursive(struct bt_field *); static -int bt_field_sequence_validate(struct bt_field *); +int bt_field_sequence_validate_recursive(struct bt_field *); static -int bt_field_generic_reset(struct bt_field *); +void bt_field_generic_reset(struct bt_field *); static -int bt_field_structure_reset(struct bt_field *); +void bt_field_structure_reset_recursive(struct bt_field *); static -int bt_field_variant_reset(struct bt_field *); +void bt_field_variant_reset_recursive(struct bt_field *); static -int bt_field_enumeration_reset(struct bt_field *); +void bt_field_enumeration_reset_recursive(struct bt_field *); static -int bt_field_array_reset(struct bt_field *); +void bt_field_array_reset_recursive(struct bt_field *); static -int bt_field_sequence_reset(struct bt_field *); +void bt_field_sequence_reset_recursive(struct bt_field *); static -int bt_field_string_reset(struct bt_field *); +void bt_field_string_reset_recursive(struct bt_field *); static int bt_field_integer_serialize(struct bt_field *, struct bt_stream_pos *, enum bt_byte_order); static -int bt_field_enumeration_serialize(struct bt_field *, +int bt_field_enumeration_serialize_recursive(struct bt_field *, struct bt_stream_pos *, enum bt_byte_order); static int bt_field_floating_point_serialize(struct bt_field *, struct bt_stream_pos *, enum bt_byte_order); static -int bt_field_structure_serialize(struct bt_field *, +int bt_field_structure_serialize_recursive(struct bt_field *, struct bt_stream_pos *, enum bt_byte_order); static -int bt_field_variant_serialize(struct bt_field *, +int bt_field_variant_serialize_recursive(struct bt_field *, struct bt_stream_pos *, enum bt_byte_order); static -int bt_field_array_serialize(struct bt_field *, +int bt_field_array_serialize_recursive(struct bt_field *, struct bt_stream_pos *, enum bt_byte_order); static -int bt_field_sequence_serialize(struct bt_field *, +int bt_field_sequence_serialize_recursive(struct bt_field *, struct bt_stream_pos *, enum bt_byte_order); static int bt_field_string_serialize(struct bt_field *, @@ -137,57 +133,54 @@ int bt_field_string_serialize(struct bt_field *, static int bt_field_integer_copy(struct bt_field *, struct bt_field *); static -int bt_field_enumeration_copy(struct bt_field *, struct bt_field *); +int bt_field_enumeration_copy_recursive(struct bt_field *, struct bt_field *); static -int bt_field_floating_point_copy(struct bt_field *, - struct bt_field *); +int bt_field_floating_point_copy(struct bt_field *, struct bt_field *); static -int bt_field_structure_copy(struct bt_field *, struct bt_field *); +int bt_field_structure_copy_recursive(struct bt_field *, struct bt_field *); static -int bt_field_variant_copy(struct bt_field *, struct bt_field *); +int bt_field_variant_copy_recursive(struct bt_field *, struct bt_field *); static -int bt_field_array_copy(struct bt_field *, struct bt_field *); +int bt_field_array_copy_recursive(struct bt_field *, struct bt_field *); static -int bt_field_sequence_copy(struct bt_field *, struct bt_field *); +int bt_field_sequence_copy_recursive(struct bt_field *, struct bt_field *); static -int bt_field_string_copy(struct bt_field *, struct bt_field *); +int bt_field_string_copy_recursive(struct bt_field *, struct bt_field *); static void generic_field_freeze(struct bt_field *); static -void bt_field_enumeration_freeze(struct bt_field *); +void bt_field_enumeration_freeze_recursive(struct bt_field *); static -void bt_field_structure_freeze(struct bt_field *); +void bt_field_structure_freeze_recursive(struct bt_field *); static -void bt_field_variant_freeze(struct bt_field *); +void bt_field_variant_freeze_recursive(struct bt_field *); static -void bt_field_array_freeze(struct bt_field *); +void bt_field_array_freeze_recursive(struct bt_field *); static -void bt_field_sequence_freeze(struct bt_field *); +void bt_field_sequence_freeze_recursive(struct bt_field *); static bt_bool bt_field_generic_is_set(struct bt_field *); static -bt_bool bt_field_structure_is_set(struct bt_field *); +bt_bool bt_field_structure_is_set_recursive(struct bt_field *); static -bt_bool bt_field_variant_is_set(struct bt_field *); +bt_bool bt_field_variant_is_set_recursive(struct bt_field *); static -bt_bool bt_field_enumeration_is_set(struct bt_field *); +bt_bool bt_field_enumeration_is_set_recursive(struct bt_field *); static -bt_bool bt_field_array_is_set(struct bt_field *); +bt_bool bt_field_array_is_set_recursive(struct bt_field *); static -bt_bool bt_field_sequence_is_set(struct bt_field *); +bt_bool bt_field_sequence_is_set_recursive(struct bt_field *); static int increase_packet_size(struct bt_stream_pos *pos); static -struct bt_field *(* const field_create_funcs[])( - struct bt_field_type *) = { +struct bt_field *(* const field_create_funcs[])(struct bt_field_type *) = { [BT_FIELD_TYPE_ID_INTEGER] = bt_field_integer_create, [BT_FIELD_TYPE_ID_ENUM] = bt_field_enumeration_create, - [BT_FIELD_TYPE_ID_FLOAT] = - bt_field_floating_point_create, + [BT_FIELD_TYPE_ID_FLOAT] = bt_field_floating_point_create, [BT_FIELD_TYPE_ID_STRUCT] = bt_field_structure_create, [BT_FIELD_TYPE_ID_VARIANT] = bt_field_variant_create, [BT_FIELD_TYPE_ID_ARRAY] = bt_field_array_create, @@ -198,51 +191,49 @@ struct bt_field *(* const field_create_funcs[])( static void (* const field_destroy_funcs[])(struct bt_field *) = { [BT_FIELD_TYPE_ID_INTEGER] = bt_field_integer_destroy, - [BT_FIELD_TYPE_ID_ENUM] = bt_field_enumeration_destroy, - [BT_FIELD_TYPE_ID_FLOAT] = - bt_field_floating_point_destroy, - [BT_FIELD_TYPE_ID_STRUCT] = bt_field_structure_destroy, - [BT_FIELD_TYPE_ID_VARIANT] = bt_field_variant_destroy, - [BT_FIELD_TYPE_ID_ARRAY] = bt_field_array_destroy, - [BT_FIELD_TYPE_ID_SEQUENCE] = bt_field_sequence_destroy, + [BT_FIELD_TYPE_ID_ENUM] = bt_field_enumeration_destroy_recursive, + [BT_FIELD_TYPE_ID_FLOAT] = bt_field_floating_point_destroy, + [BT_FIELD_TYPE_ID_STRUCT] = bt_field_structure_destroy_recursive, + [BT_FIELD_TYPE_ID_VARIANT] = bt_field_variant_destroy_recursive, + [BT_FIELD_TYPE_ID_ARRAY] = bt_field_array_destroy_recursive, + [BT_FIELD_TYPE_ID_SEQUENCE] = bt_field_sequence_destroy_recursive, [BT_FIELD_TYPE_ID_STRING] = bt_field_string_destroy, }; static int (* const field_validate_funcs[])(struct bt_field *) = { [BT_FIELD_TYPE_ID_INTEGER] = bt_field_generic_validate, - [BT_FIELD_TYPE_ID_ENUM] = bt_field_enumeration_validate, + [BT_FIELD_TYPE_ID_ENUM] = bt_field_enumeration_validate_recursive, [BT_FIELD_TYPE_ID_FLOAT] = bt_field_generic_validate, - [BT_FIELD_TYPE_ID_STRUCT] = bt_field_structure_validate, - [BT_FIELD_TYPE_ID_VARIANT] = bt_field_variant_validate, - [BT_FIELD_TYPE_ID_ARRAY] = bt_field_array_validate, - [BT_FIELD_TYPE_ID_SEQUENCE] = bt_field_sequence_validate, + [BT_FIELD_TYPE_ID_STRUCT] = bt_field_structure_validate_recursive, + [BT_FIELD_TYPE_ID_VARIANT] = bt_field_variant_validate_recursive, + [BT_FIELD_TYPE_ID_ARRAY] = bt_field_array_validate_recursive, + [BT_FIELD_TYPE_ID_SEQUENCE] = bt_field_sequence_validate_recursive, [BT_FIELD_TYPE_ID_STRING] = bt_field_generic_validate, }; static -int (* const field_reset_funcs[])(struct bt_field *) = { +void (* const field_reset_funcs[])(struct bt_field *) = { [BT_FIELD_TYPE_ID_INTEGER] = bt_field_generic_reset, - [BT_FIELD_TYPE_ID_ENUM] = bt_field_enumeration_reset, + [BT_FIELD_TYPE_ID_ENUM] = bt_field_enumeration_reset_recursive, [BT_FIELD_TYPE_ID_FLOAT] = bt_field_generic_reset, - [BT_FIELD_TYPE_ID_STRUCT] = bt_field_structure_reset, - [BT_FIELD_TYPE_ID_VARIANT] = bt_field_variant_reset, - [BT_FIELD_TYPE_ID_ARRAY] = bt_field_array_reset, - [BT_FIELD_TYPE_ID_SEQUENCE] = bt_field_sequence_reset, - [BT_FIELD_TYPE_ID_STRING] = bt_field_string_reset, + [BT_FIELD_TYPE_ID_STRUCT] = bt_field_structure_reset_recursive, + [BT_FIELD_TYPE_ID_VARIANT] = bt_field_variant_reset_recursive, + [BT_FIELD_TYPE_ID_ARRAY] = bt_field_array_reset_recursive, + [BT_FIELD_TYPE_ID_SEQUENCE] = bt_field_sequence_reset_recursive, + [BT_FIELD_TYPE_ID_STRING] = bt_field_string_reset_recursive, }; static int (* const field_serialize_funcs[])(struct bt_field *, struct bt_stream_pos *, enum bt_byte_order) = { [BT_FIELD_TYPE_ID_INTEGER] = bt_field_integer_serialize, - [BT_FIELD_TYPE_ID_ENUM] = bt_field_enumeration_serialize, - [BT_FIELD_TYPE_ID_FLOAT] = - bt_field_floating_point_serialize, - [BT_FIELD_TYPE_ID_STRUCT] = bt_field_structure_serialize, - [BT_FIELD_TYPE_ID_VARIANT] = bt_field_variant_serialize, - [BT_FIELD_TYPE_ID_ARRAY] = bt_field_array_serialize, - [BT_FIELD_TYPE_ID_SEQUENCE] = bt_field_sequence_serialize, + [BT_FIELD_TYPE_ID_ENUM] = bt_field_enumeration_serialize_recursive, + [BT_FIELD_TYPE_ID_FLOAT] = bt_field_floating_point_serialize, + [BT_FIELD_TYPE_ID_STRUCT] = bt_field_structure_serialize_recursive, + [BT_FIELD_TYPE_ID_VARIANT] = bt_field_variant_serialize_recursive, + [BT_FIELD_TYPE_ID_ARRAY] = bt_field_array_serialize_recursive, + [BT_FIELD_TYPE_ID_SEQUENCE] = bt_field_sequence_serialize_recursive, [BT_FIELD_TYPE_ID_STRING] = bt_field_string_serialize, }; @@ -250,13 +241,13 @@ static int (* const field_copy_funcs[])(struct bt_field *, struct bt_field *) = { [BT_FIELD_TYPE_ID_INTEGER] = bt_field_integer_copy, - [BT_FIELD_TYPE_ID_ENUM] = bt_field_enumeration_copy, + [BT_FIELD_TYPE_ID_ENUM] = bt_field_enumeration_copy_recursive, [BT_FIELD_TYPE_ID_FLOAT] = bt_field_floating_point_copy, - [BT_FIELD_TYPE_ID_STRUCT] = bt_field_structure_copy, - [BT_FIELD_TYPE_ID_VARIANT] = bt_field_variant_copy, - [BT_FIELD_TYPE_ID_ARRAY] = bt_field_array_copy, - [BT_FIELD_TYPE_ID_SEQUENCE] = bt_field_sequence_copy, - [BT_FIELD_TYPE_ID_STRING] = bt_field_string_copy, + [BT_FIELD_TYPE_ID_STRUCT] = bt_field_structure_copy_recursive, + [BT_FIELD_TYPE_ID_VARIANT] = bt_field_variant_copy_recursive, + [BT_FIELD_TYPE_ID_ARRAY] = bt_field_array_copy_recursive, + [BT_FIELD_TYPE_ID_SEQUENCE] = bt_field_sequence_copy_recursive, + [BT_FIELD_TYPE_ID_STRING] = bt_field_string_copy_recursive, }; static @@ -264,53 +255,56 @@ void (* const field_freeze_funcs[])(struct bt_field *) = { [BT_FIELD_TYPE_ID_INTEGER] = generic_field_freeze, [BT_FIELD_TYPE_ID_FLOAT] = generic_field_freeze, [BT_FIELD_TYPE_ID_STRING] = generic_field_freeze, - [BT_FIELD_TYPE_ID_ENUM] = bt_field_enumeration_freeze, - [BT_FIELD_TYPE_ID_STRUCT] = bt_field_structure_freeze, - [BT_FIELD_TYPE_ID_VARIANT] = bt_field_variant_freeze, - [BT_FIELD_TYPE_ID_ARRAY] = bt_field_array_freeze, - [BT_FIELD_TYPE_ID_SEQUENCE] = bt_field_sequence_freeze, + [BT_FIELD_TYPE_ID_ENUM] = bt_field_enumeration_freeze_recursive, + [BT_FIELD_TYPE_ID_STRUCT] = bt_field_structure_freeze_recursive, + [BT_FIELD_TYPE_ID_VARIANT] = bt_field_variant_freeze_recursive, + [BT_FIELD_TYPE_ID_ARRAY] = bt_field_array_freeze_recursive, + [BT_FIELD_TYPE_ID_SEQUENCE] = bt_field_sequence_freeze_recursive, }; static bt_bool (* const field_is_set_funcs[])(struct bt_field *) = { [BT_FIELD_TYPE_ID_INTEGER] = bt_field_generic_is_set, - [BT_FIELD_TYPE_ID_ENUM] = bt_field_enumeration_is_set, + [BT_FIELD_TYPE_ID_ENUM] = bt_field_enumeration_is_set_recursive, [BT_FIELD_TYPE_ID_FLOAT] = bt_field_generic_is_set, - [BT_FIELD_TYPE_ID_STRUCT] = bt_field_structure_is_set, - [BT_FIELD_TYPE_ID_VARIANT] = bt_field_variant_is_set, - [BT_FIELD_TYPE_ID_ARRAY] = bt_field_array_is_set, - [BT_FIELD_TYPE_ID_SEQUENCE] = bt_field_sequence_is_set, + [BT_FIELD_TYPE_ID_STRUCT] = bt_field_structure_is_set_recursive, + [BT_FIELD_TYPE_ID_VARIANT] = bt_field_variant_is_set_recursive, + [BT_FIELD_TYPE_ID_ARRAY] = bt_field_array_is_set_recursive, + [BT_FIELD_TYPE_ID_SEQUENCE] = bt_field_sequence_is_set_recursive, [BT_FIELD_TYPE_ID_STRING] = bt_field_generic_is_set, }; +BT_ASSERT_FUNC +static inline bool field_type_has_known_id(struct bt_field_type *ft) +{ + return ft->id > BT_FIELD_TYPE_ID_UNKNOWN || + ft->id < BT_FIELD_TYPE_ID_NR; +} + +#define BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(_field, _type_id, _name) \ + BT_ASSERT_PRE((_field)->type->id == (_type_id), \ + _name " has the wrong type ID: expected-type-id=%s, " \ + "%![field-]+f", bt_field_type_id_string(_type_id), \ + (_field)) + +#define BT_ASSERT_PRE_FIELD_IS_SET(_field, _name) \ + BT_ASSERT_PRE(bt_field_is_set_recursive(_field), \ + _name " is not set: %!+f", (_field)) + +#define BT_ASSERT_PRE_FIELD_HOT(_field, _name) \ + BT_ASSERT_PRE_HOT((_field), (_name), ": +%!+f", (_field)) + struct bt_field *bt_field_create(struct bt_field_type *type) { struct bt_field *field = NULL; enum bt_field_type_id type_id; - int ret; - if (!type) { - BT_LOGW_STR("Invalid parameter: field type is NULL."); - goto error; - } + BT_ASSERT_PRE_NON_NULL(type, "Field type"); + BT_ASSERT(field_type_has_known_id(type)); + BT_ASSERT_PRE(bt_field_type_validate(type) == 0, + "Field type is invalid: %!+F", type); type_id = bt_field_type_get_type_id(type); - if (type_id <= BT_FIELD_TYPE_ID_UNKNOWN || - type_id >= BT_FIELD_TYPE_ID_NR) { - BT_LOGW("Invalid parameter: unknown field type ID: " - "ft-addr=%p, ft-id=%d", type, type_id); - goto error; - } - - /* Field class MUST be valid */ - ret = bt_field_type_validate(type); - if (ret) { - /* Invalid */ - BT_LOGW("Invalid parameter: field type is invalid: " - "ft-addr=%p", type); - goto error; - } - field = field_create_funcs[type_id](type); if (!field) { goto error; @@ -341,29 +335,16 @@ struct bt_field_type *bt_field_get_type(struct bt_field *field) { struct bt_field_type *ret = NULL; - if (!field) { - BT_LOGW_STR("Invalid parameter: field is NULL."); - goto end; - } - + BT_ASSERT_PRE_NON_NULL(field, "Field"); ret = field->type; bt_get(ret); -end: return ret; } enum bt_field_type_id bt_field_get_type_id(struct bt_field *field) { - enum bt_field_type_id ret = BT_FIELD_TYPE_ID_UNKNOWN; - - if (!field) { - BT_LOGW_STR("Invalid parameter: field is NULL."); - goto end; - } - - ret = bt_field_type_get_type_id(field->type); -end: - return ret; + BT_ASSERT_PRE_NON_NULL(field, "Field"); + return bt_field_type_get_type_id(field->type); } bt_bool bt_field_is_integer(struct bt_field *field) @@ -412,8 +393,8 @@ int64_t bt_field_sequence_get_int_length(struct bt_field *field) struct bt_field_sequence *sequence; int64_t ret; - assert(field); - assert(bt_field_type_get_type_id(field->type) == + BT_ASSERT(field); + BT_ASSERT(bt_field_type_get_type_id(field->type) == BT_FIELD_TYPE_ID_SEQUENCE); sequence = container_of(field, struct bt_field_sequence, parent); if (!sequence->length) { @@ -433,24 +414,12 @@ struct bt_field *bt_field_sequence_get_length( struct bt_field *ret = NULL; struct bt_field_sequence *sequence; - if (!field) { - BT_LOGW_STR("Invalid parameter: field is NULL."); - goto end; - } - - if (bt_field_type_get_type_id(field->type) != - BT_FIELD_TYPE_ID_SEQUENCE) { - BT_LOGW("Invalid parameter: field's type is not a sequence field type: " - "field-addr=%p, ft-addr=%p, ft-id=%s", field, - field->type, - bt_field_type_id_string(field->type->id)); - goto end; - } - + BT_ASSERT_PRE_NON_NULL(field, "Sequence field"); + BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(field, BT_FIELD_TYPE_ID_SEQUENCE, + "Field"); sequence = container_of(field, struct bt_field_sequence, parent); ret = sequence->length; bt_get(ret); -end: return ret; } @@ -458,60 +427,18 @@ int bt_field_sequence_set_length(struct bt_field *field, struct bt_field *length_field) { int ret = 0; - struct bt_field_type_integer *length_type; struct bt_field_integer *length; struct bt_field_sequence *sequence; uint64_t sequence_length; - if (!field) { - BT_LOGW_STR("Invalid parameter: field is NULL."); - ret = -1; - goto end; - } - - if (!length_field) { - BT_LOGW_STR("Invalid parameter: length field is NULL."); - ret = -1; - goto end; - } - - if (field->frozen) { - BT_LOGW("Invalid parameter: field is frozen: addr=%p", - field); - ret = -1; - goto end; - } - - if (bt_field_type_get_type_id(length_field->type) != - BT_FIELD_TYPE_ID_INTEGER) { - BT_LOGW("Invalid parameter: length field's type is not an integer field type: " - "field-addr=%p, length-field-addr=%p, length-ft-addr=%p, length-ft-id=%s", - field, length_field, length_field->type, - bt_field_type_id_string(length_field->type->id)); - ret = -1; - goto end; - } - - length_type = container_of(length_field->type, - struct bt_field_type_integer, parent); - /* The length field must be unsigned */ - if (length_type->is_signed) { - BT_LOGW("Invalid parameter: length field's type is signed: " - "field-addr=%p, length-field-addr=%p, " - "length-field-ft-addr=%p", field, length_field, - length_field->type); - ret = -1; - goto end; - } - - if (!bt_field_is_set(length_field)) { - BT_LOGW("Invalid parameter: length field's value is not set: " - "field-addr=%p, length-field-addr=%p, " - "length-field-ft-addr=%p", field, length_field, - length_field->type); - ret = -1; - goto end; - } + BT_ASSERT_PRE_NON_NULL(field, "Sequence field"); + BT_ASSERT_PRE_NON_NULL(length_field, "Length field"); + BT_ASSERT_PRE_FIELD_HOT(field, "Sequence field"); + BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(length_field, BT_FIELD_TYPE_ID_INTEGER, + "Length field"); + BT_ASSERT_PRE(!bt_field_type_integer_is_signed(length_field->type), + "Length field's type is signed: %!+f", length_field); + BT_ASSERT_PRE_FIELD_IS_SET(length_field, "Length field"); length = container_of(length_field, struct bt_field_integer, parent); @@ -534,7 +461,8 @@ int bt_field_sequence_set_length(struct bt_field *field, g_ptr_array_set_size(sequence->elements, (size_t) sequence_length); bt_get(length_field); sequence->length = length_field; - bt_field_freeze(length_field); + bt_field_freeze_recursive(length_field); + end: return ret; } @@ -548,25 +476,9 @@ struct bt_field *bt_field_structure_get_field_by_name( size_t index; GHashTable *field_name_to_index; - if (!field) { - BT_LOGW_STR("Invalid parameter: field is NULL."); - goto error; - } - - if (!name) { - BT_LOGW_STR("Invalid parameter: field name is NULL."); - goto error; - } - - if (bt_field_type_get_type_id(field->type) != - BT_FIELD_TYPE_ID_STRUCT) { - BT_LOGW("Invalid parameter: field's type is not a structure field type: " - "field-addr=%p, ft-addr=%p, ft-id=%s", field, - field->type, - bt_field_type_id_string(field->type->id)); - goto error; - } - + BT_ASSERT_PRE_NON_NULL(field, "Structure field"); + BT_ASSERT_PRE_NON_NULL(name, "Field name"); + BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(field, BT_FIELD_TYPE_ID_STRUCT, "Field"); field_name_to_index = container_of(field->type, struct bt_field_type_structure, parent)->field_name_to_index; @@ -582,7 +494,8 @@ struct bt_field *bt_field_structure_get_field_by_name( } ret = bt_get(structure->fields->pdata[index]); - assert(ret); + BT_ASSERT(ret); + error: return ret; } @@ -593,30 +506,38 @@ struct bt_field *bt_field_structure_get_field_by_index( struct bt_field_structure *structure; struct bt_field *ret = NULL; - if (!field) { - BT_LOGW_STR("Invalid parameter: field is NULL."); - goto end; - } + BT_ASSERT_PRE_NON_NULL(field, "Structure field"); + BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(field, BT_FIELD_TYPE_ID_STRUCT, "Field"); + structure = container_of(field, struct bt_field_structure, parent); + BT_ASSERT_PRE(index < structure->fields->len, + "Index is out of bound: %![struct-field-]+f, " + "index=%" PRIu64 ", count=%u", field, index, + structure->fields->len); + ret = bt_get(structure->fields->pdata[index]); + return ret; +} - if (bt_field_type_get_type_id(field->type) != - BT_FIELD_TYPE_ID_STRUCT) { - BT_LOGW("Invalid parameter: field's type is not a structure field type: " - "field-addr=%p, ft-addr=%p, ft-id=%s", field, - field->type, - bt_field_type_id_string(field->type->id)); - goto end; - } +BT_ASSERT_PRE_FUNC +static inline bool field_to_set_has_expected_type(struct bt_field *struct_field, + const char *name, struct bt_field *value) +{ + bool ret = true; + struct bt_field_type *expected_field_type = NULL; - structure = container_of(field, struct bt_field_structure, parent); - if (index >= structure->fields->len) { - BT_LOGW("Invalid parameter: index is out of bounds: " - "addr=%p, index=%" PRIu64 ", count=%u", - field, index, structure->fields->len); + expected_field_type = + bt_field_type_structure_get_field_type_by_name( + struct_field->type, name); + + if (bt_field_type_compare(expected_field_type, value->type)) { + BT_ASSERT_PRE_MSG("Value field's type is different from the expected field type: " + "%![value-ft-]+F, %![expected-ft-]+F", value->type, + expected_field_type); + ret = false; goto end; } - ret = bt_get(structure->fields->pdata[index]); end: + bt_put(expected_field_type); return ret; } @@ -626,53 +547,18 @@ int bt_field_structure_set_field_by_name(struct bt_field *field, int ret = 0; GQuark field_quark; struct bt_field_structure *structure; - struct bt_field_type *expected_field_type = NULL; size_t index; GHashTable *field_name_to_index; - if (!field) { - BT_LOGW_STR("Invalid parameter: structure field is NULL."); - ret = -1; - goto end; - } - - if (!name) { - BT_LOGW_STR("Invalid parameter: field name is NULL."); - ret = -1; - goto end; - } - - if (!value) { - BT_LOGW_STR("Invalid parameter: field is NULL."); - ret = -1; - goto end; - } - - if (bt_field_type_get_type_id(field->type) != - BT_FIELD_TYPE_ID_STRUCT) { - BT_LOGW("Invalid parameter: field's type is not a structure field type: " - "field-addr=%p, ft-addr=%p, ft-id=%s", field, - field->type, - bt_field_type_id_string(field->type->id)); - ret = -1; - goto end; - } - + BT_ASSERT_PRE_NON_NULL(field, "Structure field"); + BT_ASSERT_PRE_NON_NULL(name, "Field name"); + BT_ASSERT_PRE_NON_NULL(value, "Value field"); + BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(field, BT_FIELD_TYPE_ID_STRUCT, + "Parent field"); + BT_ASSERT_PRE(field_to_set_has_expected_type(field, name, value), + "Value field's type is different from the expected field type."); field_quark = g_quark_from_string(name); structure = container_of(field, struct bt_field_structure, parent); - expected_field_type = - bt_field_type_structure_get_field_type_by_name(field->type, - name); - - if (bt_field_type_compare(expected_field_type, value->type)) { - BT_LOGW("Invalid parameter: field type of field to set is different from the expected field type: " - "struct-field-addr=%p, field-addr=%p, " - "field-ft-addr=%p, expected-ft-addr=%p", - field, value, value->type, expected_field_type); - ret = -1; - goto end; - } - field_name_to_index = container_of(field->type, struct bt_field_type_structure, parent)->field_name_to_index; @@ -688,10 +574,8 @@ int bt_field_structure_set_field_by_name(struct bt_field *field, } bt_get(value); BT_MOVE(structure->fields->pdata[index], value); + end: - if (expected_field_type) { - bt_put(expected_field_type); - } return ret; } @@ -702,56 +586,28 @@ struct bt_field *bt_field_array_get_field(struct bt_field *field, struct bt_field_type *field_type = NULL; struct bt_field_array *array; - if (!field) { - BT_LOGW_STR("Invalid parameter: field is NULL."); - goto end; - } - - if (bt_field_type_get_type_id(field->type) != - BT_FIELD_TYPE_ID_ARRAY) { - BT_LOGW("Invalid parameter: field's type is not an array field type: " - "field-addr=%p, ft-addr=%p, ft-id=%s", field, - field->type, - bt_field_type_id_string(field->type->id)); - goto end; - } - + BT_ASSERT_PRE_NON_NULL(field, "Array field"); + BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(field, BT_FIELD_TYPE_ID_ARRAY, "Field"); array = container_of(field, struct bt_field_array, parent); - if (index >= array->elements->len) { - BT_LOGW("Invalid parameter: index is out of bounds: " - "addr=%p, index=%" PRIu64 ", count=%u", - field, index, array->elements->len); - goto end; - } + BT_ASSERT_PRE(index < array->elements->len, + "Index is out of bound: %![array-field-]+f, " + "index=%" PRIu64 ", count=%u", field, + index, array->elements->len); field_type = bt_field_type_array_get_element_type(field->type); - if (array->elements->pdata[(size_t)index]) { - new_field = array->elements->pdata[(size_t)index]; + if (array->elements->pdata[(size_t) index]) { + new_field = array->elements->pdata[(size_t) index]; goto end; } /* We don't want to modify this field if it's frozen */ - if (field->frozen) { - /* - * Not logging a warning here because the user could - * legitimately check if a array field is set with - * this function: if the preconditions are satisfied, - * a NULL return value means this. - */ - BT_LOGV("Not creating a field because array field is frozen: " - "array-field-addr=%p, index=%" PRIu64, field, index); - goto end; - } - + BT_ASSERT_PRE_FIELD_HOT(field, "Array field"); new_field = bt_field_create(field_type); array->elements->pdata[(size_t)index] = new_field; + end: - if (field_type) { - bt_put(field_type); - } - if (new_field) { - bt_get(new_field); - } + bt_put(field_type); + bt_get(new_field); return new_field; } @@ -762,34 +618,15 @@ struct bt_field *bt_field_sequence_get_field(struct bt_field *field, struct bt_field_type *field_type = NULL; struct bt_field_sequence *sequence; - if (!field) { - BT_LOGW_STR("Invalid parameter: field is NULL."); - goto end; - } - - if (bt_field_type_get_type_id(field->type) != - BT_FIELD_TYPE_ID_SEQUENCE) { - BT_LOGW("Invalid parameter: field's type is not a sequence field type: " - "field-addr=%p, ft-addr=%p, ft-id=%s", field, - field->type, - bt_field_type_id_string(field->type->id)); - goto end; - } - + BT_ASSERT_PRE_NON_NULL(field, "Sequence field"); + BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(field, BT_FIELD_TYPE_ID_SEQUENCE, + "Field"); sequence = container_of(field, struct bt_field_sequence, parent); - if (!sequence->elements) { - BT_LOGV("Sequence field's elements do not exist: addr=%p", - field); - goto end; - } - - if (index >= sequence->elements->len) { - BT_LOGW("Invalid parameter: index is out of bounds: " - "addr=%p, index=%" PRIu64 ", count=%u", - field, index, sequence->elements->len); - goto end; - } - + BT_ASSERT_PRE_NON_NULL(sequence->elements, "Sequence field's element array"); + BT_ASSERT_PRE(index < sequence->elements->len, + "Index is out of bound: %![seq-field-]+f, " + "index=%" PRIu64 ", count=%u", field, index, + sequence->elements->len); field_type = bt_field_type_sequence_get_element_type(field->type); if (sequence->elements->pdata[(size_t) index]) { new_field = sequence->elements->pdata[(size_t) index]; @@ -797,27 +634,13 @@ struct bt_field *bt_field_sequence_get_field(struct bt_field *field, } /* We don't want to modify this field if it's frozen */ - if (field->frozen) { - /* - * Not logging a warning here because the user could - * legitimately check if a sequence field is set with - * this function: if the preconditions are satisfied, - * a NULL return value means this. - */ - BT_LOGV("Not creating a field because sequence field is frozen: " - "sequence-field-addr=%p, index=%" PRIu64, field, index); - goto end; - } - + BT_ASSERT_PRE_FIELD_HOT(field, "Sequence field"); new_field = bt_field_create(field_type); sequence->elements->pdata[(size_t) index] = new_field; + end: - if (field_type) { - bt_put(field_type); - } - if (new_field) { - bt_get(new_field); - } + bt_put(field_type); + bt_get(new_field); return new_field; } @@ -832,52 +655,21 @@ struct bt_field *bt_field_variant_get_field(struct bt_field *field, struct bt_field_integer *tag_enum_integer; int64_t tag_enum_value; - if (!field) { - BT_LOGW_STR("Invalid parameter: field is NULL."); - goto end; - } - - if (!tag_field) { - BT_LOGW_STR("Invalid parameter: tag field is NULL."); - goto end; - } - - if (bt_field_type_get_type_id(field->type) != - BT_FIELD_TYPE_ID_VARIANT) { - BT_LOGW("Invalid parameter: field's type is not a variant field type: " - "field-addr=%p, ft-addr=%p, ft-id=%s", field, - field->type, - bt_field_type_id_string(field->type->id)); - goto end; - } - - if (bt_field_type_get_type_id(tag_field->type) != - BT_FIELD_TYPE_ID_ENUM) { - BT_LOGW("Invalid parameter: tag field's type is not an enumeration field type: " - "field-addr=%p, ft-addr=%p, ft-id=%s", tag_field, - tag_field->type, - bt_field_type_id_string(tag_field->type->id)); - goto end; - } - + BT_ASSERT_PRE_NON_NULL(field, "Variant field"); + BT_ASSERT_PRE_NON_NULL(tag_field, "Tag field"); + BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(field, BT_FIELD_TYPE_ID_VARIANT, + "Variant field"); + BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(tag_field, BT_FIELD_TYPE_ID_ENUM, + "Tag field"); variant = container_of(field, struct bt_field_variant, parent); variant_type = container_of(field->type, struct bt_field_type_variant, parent); tag_enum = bt_field_enumeration_get_container(tag_field); - if (!tag_enum) { - goto end; - } - + BT_ASSERT_PRE_NON_NULL(tag_enum, "Tag field's container"); tag_enum_integer = container_of(tag_enum, struct bt_field_integer, parent); - - if (bt_field_validate(tag_field) < 0) { - BT_LOGW("Invalid parameter: tag field is invalid: " - "variant-field-addr=%p, tag-field-addr=%p", - field, tag_field); - goto end; - } - + BT_ASSERT_PRE(bt_field_validate_recursive(tag_field) == 0, + "Tag field is invalid: %!+f", tag_field); tag_enum_value = tag_enum_integer->payload.signd; /* @@ -892,7 +684,7 @@ struct bt_field *bt_field_variant_get_field(struct bt_field *field, cur_tag_container = bt_field_enumeration_get_container(variant->tag); - assert(cur_tag_container); + BT_ASSERT(cur_tag_container); cur_tag_enum_integer = container_of(cur_tag_container, struct bt_field_integer, parent); bt_put(cur_tag_container); @@ -906,28 +698,16 @@ struct bt_field *bt_field_variant_get_field(struct bt_field *field, } /* We don't want to modify this field if it's frozen */ - if (field->frozen) { - /* - * Not logging a warning here because the user could - * legitimately check if a variant field is set with - * this function: if the preconditions are satisfied, - * a NULL return value means this. - */ - BT_LOGV("Not creating a field because variant field is frozen: " - "variant-field-addr=%p, tag-field-addr=%p", - field, tag_field); - goto end; - } - + BT_ASSERT_PRE_FIELD_HOT(field, "Variant field"); field_type = bt_field_type_variant_get_field_type_signed( variant_type, tag_enum_value); - if (!field_type) { - BT_LOGW("Cannot get variant field type's field: " - "variant-field-addr=%p, variant-ft-addr=%p, " - "tag-value-signed=%" PRId64, - field, variant_type, tag_enum_value); - goto end; - } + + /* It's the caller's job to make sure the tag's value is valid */ + BT_ASSERT_PRE(field_type, + "Variant field's type does not contain a field type for " + "this tag value: tag-value-signed=%" PRId64 ", " + "%![var-ft-]+F, %![tag-field-]+f", tag_enum_value, + variant_type, tag_field); new_field = bt_field_create(field_type); if (!new_field) { @@ -943,6 +723,7 @@ struct bt_field *bt_field_variant_get_field(struct bt_field *field, bt_get(tag_field); variant->tag = tag_field; variant->payload = new_field; + end: bt_put(tag_enum); return new_field; @@ -951,113 +732,51 @@ end: struct bt_field *bt_field_variant_get_current_field( struct bt_field *variant_field) { - struct bt_field *current_field = NULL; struct bt_field_variant *variant; - if (!variant_field) { - BT_LOGW_STR("Invalid parameter: field is NULL."); - goto end; - } - - if (bt_field_type_get_type_id(variant_field->type) != - BT_FIELD_TYPE_ID_VARIANT) { - BT_LOGW("Invalid parameter: field's type is not a variant field type: " - "field-addr=%p, ft-addr=%p, ft-id=%s", variant_field, - variant_field->type, - bt_field_type_id_string(variant_field->type->id)); - goto end; - } - + BT_ASSERT_PRE_NON_NULL(variant_field, "Variant field"); + BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(variant_field, BT_FIELD_TYPE_ID_VARIANT, + "Field"); variant = container_of(variant_field, struct bt_field_variant, parent); - - if (variant->payload) { - current_field = variant->payload; - bt_get(current_field); - goto end; - } - -end: - return current_field; + return bt_get(variant->payload); } -struct bt_field *bt_field_variant_get_tag( - struct bt_field *variant_field) +struct bt_field *bt_field_variant_get_tag(struct bt_field *variant_field) { - struct bt_field *tag = NULL; struct bt_field_variant *variant; - if (!variant_field) { - BT_LOGW_STR("Invalid parameter: field is NULL."); - goto end; - } - - if (bt_field_type_get_type_id(variant_field->type) != - BT_FIELD_TYPE_ID_VARIANT) { - BT_LOGW("Invalid parameter: field's type is not a variant field type: " - "field-addr=%p, ft-addr=%p, ft-id=%s", variant_field, - variant_field->type, - bt_field_type_id_string(variant_field->type->id)); - goto end; - } - + BT_ASSERT_PRE_NON_NULL(variant_field, "Variant field"); + BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(variant_field, BT_FIELD_TYPE_ID_VARIANT, + "Field"); variant = container_of(variant_field, struct bt_field_variant, parent); - if (variant->tag) { - tag = bt_get(variant->tag); - } -end: - return tag; + return bt_get(variant->tag); } -struct bt_field *bt_field_enumeration_get_container( - struct bt_field *field) +struct bt_field *bt_field_enumeration_get_container(struct bt_field *field) { struct bt_field *container = NULL; struct bt_field_enumeration *enumeration; - if (!field) { - BT_LOGW_STR("Invalid parameter: field is NULL."); - goto end; - } - - if (bt_field_type_get_type_id(field->type) != - BT_FIELD_TYPE_ID_ENUM) { - BT_LOGW("Invalid parameter: field's type is not an enumeration field type: " - "field-addr=%p, ft-addr=%p, ft-id=%s", field, - field->type, - bt_field_type_id_string(field->type->id)); - goto end; - } - + BT_ASSERT_PRE_NON_NULL(field, "Enumeration field"); + BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(field, BT_FIELD_TYPE_ID_ENUM, "Field"); enumeration = container_of(field, struct bt_field_enumeration, parent); if (!enumeration->payload) { + struct bt_field_type_enumeration *enumeration_type; + /* We don't want to modify this field if it's frozen */ - if (field->frozen) { - /* - * Not logging a warning here because the user - * could legitimately check if an enumeration's - * container field is set with this function: if - * the preconditions are satisfied, a NULL - * return value means this. - */ - BT_LOGV("Not creating a field because enumeration field is frozen: " - "enum-field-addr=%p", field); - goto end; - } + BT_ASSERT_PRE_FIELD_HOT(field, "Enumeration field"); - struct bt_field_type_enumeration *enumeration_type = - container_of(field->type, + enumeration_type = container_of(field->type, struct bt_field_type_enumeration, parent); enumeration->payload = bt_field_create(enumeration_type->container); } container = enumeration->payload; - bt_get(container); -end: - return container; + return bt_get(container); } struct bt_field_type_enumeration_mapping_iterator * @@ -1065,422 +784,202 @@ bt_field_enumeration_get_mappings(struct bt_field *field) { int ret; struct bt_field *container = NULL; - struct bt_field_type *container_type = NULL; struct bt_field_type_integer *integer_type = NULL; struct bt_field_type_enumeration_mapping_iterator *iter = NULL; + BT_ASSERT_PRE_NON_NULL(field, "Enumeration field"); + BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(field, BT_FIELD_TYPE_ID_ENUM, "Field"); container = bt_field_enumeration_get_container(field); - if (!container) { - BT_LOGW("Invalid parameter: enumeration field has no container field: " - "addr=%p", field); - goto end; - } - - container_type = bt_field_get_type(container); - assert(container_type); - integer_type = container_of(container_type, + BT_ASSERT_PRE(container, + "Enumeration field has no container field: %!+f", field); + BT_ASSERT(container->type); + integer_type = container_of(container->type, struct bt_field_type_integer, parent); + BT_ASSERT_PRE_FIELD_IS_SET(container, + "Enumeration field's payload field"); if (!integer_type->is_signed) { uint64_t value; - ret = bt_field_unsigned_integer_get_value(container, - &value); - if (ret) { - BT_LOGW("Cannot get value from signed enumeration field's payload field: " - "enum-field-addr=%p, payload-field-addr=%p", - field, container); - goto error_put_container_type; - } + ret = bt_field_unsigned_integer_get_value(container, &value); + BT_ASSERT(ret == 0); iter = bt_field_type_enumeration_find_mappings_by_unsigned_value( field->type, value); } else { int64_t value; - ret = bt_field_signed_integer_get_value(container, - &value); - if (ret) { - BT_LOGW("Cannot get value from unsigned enumeration field's payload field: " - "enum-field-addr=%p, payload-field-addr=%p", - field, container); - goto error_put_container_type; - } + ret = bt_field_signed_integer_get_value(container, &value); + BT_ASSERT(ret == 0); iter = bt_field_type_enumeration_find_mappings_by_signed_value( field->type, value); } -error_put_container_type: - bt_put(container_type); bt_put(container); -end: return iter; } -int bt_field_signed_integer_get_value(struct bt_field *field, - int64_t *value) +int bt_field_signed_integer_get_value(struct bt_field *field, int64_t *value) { - int ret = 0; struct bt_field_integer *integer; struct bt_field_type_integer *integer_type; - if (!field) { - BT_LOGW_STR("Invalid parameter: field is NULL."); - ret = -1; - goto end; - } - - if (!value) { - BT_LOGW_STR("Invalid parameter: value is NULL."); - ret = -1; - goto end; - } - - if (!field->payload_set) { - BT_LOGV("Field's payload is not set: addr=%p", field); - ret = -1; - goto end; - } - - if (bt_field_type_get_type_id(field->type) != - BT_FIELD_TYPE_ID_INTEGER) { - BT_LOGW("Invalid parameter: field's type is not an integer field type: " - "field-addr=%p, ft-addr=%p, ft-id=%s", field, - field->type, - bt_field_type_id_string(field->type->id)); - ret = -1; - goto end; - } - + BT_ASSERT_PRE_NON_NULL(field, "Integer field"); + BT_ASSERT_PRE_NON_NULL(value, "Value"); + BT_ASSERT_PRE_FIELD_IS_SET(field, "Integer field"); + BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(field, BT_FIELD_TYPE_ID_INTEGER, "Field"); integer_type = container_of(field->type, struct bt_field_type_integer, parent); - if (!integer_type->is_signed) { - BT_LOGW("Invalid parameter: integer field's type is not signed: " - "field-addr=%p, ft-addr=%p", field, field->type); - ret = -1; - goto end; - } - + BT_ASSERT_PRE(bt_field_type_integer_is_signed(field->type), + "Field's type is unsigned: %!+f", field); integer = container_of(field, struct bt_field_integer, parent); *value = integer->payload.signd; -end: - return ret; + return 0; } -int bt_field_signed_integer_set_value(struct bt_field *field, - int64_t value) +BT_ASSERT_PRE_FUNC +static inline bool value_is_in_range_signed(unsigned int size, int64_t value) { - int ret = 0; - struct bt_field_integer *integer; - struct bt_field_type_integer *integer_type; - unsigned int size; + bool ret = true; int64_t min_value, max_value; - if (!field) { - BT_LOGW_STR("Invalid parameter: field is NULL."); - ret = -1; - goto end; - } - - if (field->frozen) { - BT_LOGW("Invalid parameter: field is frozen: addr=%p", - field); - ret = -1; - goto end; - } - - if (bt_field_type_get_type_id(field->type) != - BT_FIELD_TYPE_ID_INTEGER) { - BT_LOGW("Invalid parameter: field's type is not an integer field type: " - "field-addr=%p, ft-addr=%p, ft-id=%s", field, - field->type, - bt_field_type_id_string(field->type->id)); - ret = -1; - goto end; - } - - integer = container_of(field, struct bt_field_integer, parent); - integer_type = container_of(field->type, - struct bt_field_type_integer, parent); - if (!integer_type->is_signed) { - BT_LOGW("Invalid parameter: integer field's type is not signed: " - "field-addr=%p, ft-addr=%p", field, field->type); - ret = -1; - goto end; - } - - size = integer_type->size; min_value = -(1ULL << (size - 1)); max_value = (1ULL << (size - 1)) - 1; if (value < min_value || value > max_value) { - BT_LOGW("Invalid parameter: value is out of bounds: " - "addr=%p, value=%" PRId64 ", " + BT_LOGF("Value is out of bounds: value=%" PRId64 ", " "min-value=%" PRId64 ", max-value=%" PRId64, - field, value, min_value, max_value); - ret = -1; - goto end; + value, min_value, max_value); + ret = false; } - integer->payload.signd = value; - integer->parent.payload_set = true; -end: return ret; } -int bt_field_unsigned_integer_get_value(struct bt_field *field, - uint64_t *value) +int bt_field_signed_integer_set_value(struct bt_field *field, int64_t value) { int ret = 0; struct bt_field_integer *integer; struct bt_field_type_integer *integer_type; - if (!field) { - BT_LOGW_STR("Invalid parameter: field is NULL."); - ret = -1; - goto end; - } - - if (!value) { - BT_LOGW_STR("Invalid parameter: value is NULL."); - ret = -1; - goto end; - } - - if (!field->payload_set) { - BT_LOGV("Field's payload is not set: addr=%p", field); - ret = -1; - goto end; - } - - if (bt_field_type_get_type_id(field->type) != - BT_FIELD_TYPE_ID_INTEGER) { - BT_LOGW("Invalid parameter: field's type is not an integer field type: " - "field-addr=%p, ft-addr=%p, ft-id=%s", field, - field->type, - bt_field_type_id_string(field->type->id)); - ret = -1; - goto end; - } - + BT_ASSERT_PRE_NON_NULL(field, "Integer field"); + BT_ASSERT_PRE_FIELD_HOT(field, "Integer field"); + BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(field, BT_FIELD_TYPE_ID_INTEGER, "Field"); + integer = container_of(field, struct bt_field_integer, parent); integer_type = container_of(field->type, struct bt_field_type_integer, parent); - if (integer_type->is_signed) { - BT_LOGW("Invalid parameter: integer field's type is signed: " - "field-addr=%p, ft-addr=%p", field, field->type); - ret = -1; - goto end; - } - - integer = container_of(field, - struct bt_field_integer, parent); - *value = integer->payload.unsignd; -end: + BT_ASSERT_PRE(bt_field_type_integer_is_signed(field->type), + "Field's type is unsigned: %!+f", field); + BT_ASSERT_PRE(value_is_in_range_signed(integer_type->size, value), + "Value is out of bounds: value=%" PRId64 ", %![field-]+f", + value, field); + integer->payload.signd = value; + bt_field_set(field, true); return ret; } -int bt_field_unsigned_integer_set_value(struct bt_field *field, - uint64_t value) +int bt_field_unsigned_integer_get_value(struct bt_field *field, uint64_t *value) { - int ret = 0; struct bt_field_integer *integer; struct bt_field_type_integer *integer_type; - unsigned int size; - uint64_t max_value; - - if (!field) { - BT_LOGW_STR("Invalid parameter: field is NULL."); - ret = -1; - goto end; - } - - if (field->frozen) { - BT_LOGW("Invalid parameter: field is frozen: addr=%p", - field); - ret = -1; - goto end; - } - if (bt_field_type_get_type_id(field->type) != - BT_FIELD_TYPE_ID_INTEGER) { - BT_LOGW("Invalid parameter: field's type is not an integer field type: " - "field-addr=%p, ft-addr=%p, ft-id=%s", field, - field->type, - bt_field_type_id_string(field->type->id)); - ret = -1; - goto end; - } - - integer = container_of(field, struct bt_field_integer, parent); + BT_ASSERT_PRE_NON_NULL(field, "Integer field"); + BT_ASSERT_PRE_NON_NULL(value, "Value"); + BT_ASSERT_PRE_FIELD_IS_SET(field, "Integer field"); + BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(field, BT_FIELD_TYPE_ID_INTEGER, "Field"); integer_type = container_of(field->type, struct bt_field_type_integer, parent); - if (integer_type->is_signed) { - BT_LOGW("Invalid parameter: integer field's type is signed: " - "field-addr=%p, ft-addr=%p", field, field->type); - ret = -1; - goto end; - } + BT_ASSERT_PRE(!bt_field_type_integer_is_signed(field->type), + "Field's type is signed: %!+f", field); + integer = container_of(field, struct bt_field_integer, parent); + *value = integer->payload.unsignd; + return 0; +} + +BT_ASSERT_PRE_FUNC +static inline bool value_is_in_range_unsigned(unsigned int size, uint64_t value) +{ + bool ret = true; + int64_t max_value; - size = integer_type->size; max_value = (size == 64) ? UINT64_MAX : ((uint64_t) 1 << size) - 1; if (value > max_value) { - BT_LOGW("Invalid parameter: value is out of bounds: " - "addr=%p, value=%" PRIu64 ", " - "min-value=%" PRIu64 ", max-value=%" PRIu64, - field, value, (uint64_t) 0, max_value); - ret = -1; - goto end; + BT_LOGF("Value is out of bounds: value=%" PRIu64 ", " + "max-value=%" PRIu64, + value, max_value); + ret = false; } - integer->payload.unsignd = value; - integer->parent.payload_set = true; -end: return ret; } -int bt_field_floating_point_get_value(struct bt_field *field, - double *value) +int bt_field_unsigned_integer_set_value(struct bt_field *field, uint64_t value) { - int ret = 0; - struct bt_field_floating_point *floating_point; - - if (!field) { - BT_LOGW_STR("Invalid parameter: field is NULL."); - ret = -1; - goto end; - } - - if (!value) { - BT_LOGW_STR("Invalid parameter: value is NULL."); - ret = -1; - goto end; - } + struct bt_field_integer *integer; + struct bt_field_type_integer *integer_type; - if (!field->payload_set) { - BT_LOGV("Field's payload is not set: addr=%p", field); - ret = -1; - goto end; - } + BT_ASSERT_PRE_NON_NULL(field, "Integer field"); + BT_ASSERT_PRE_FIELD_HOT(field, "Integer field"); + BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(field, BT_FIELD_TYPE_ID_INTEGER, "Field"); + integer = container_of(field, struct bt_field_integer, parent); + integer_type = container_of(field->type, + struct bt_field_type_integer, parent); + BT_ASSERT_PRE(!bt_field_type_integer_is_signed(field->type), + "Field's type is signed: %!+f", field); + BT_ASSERT_PRE(value_is_in_range_unsigned(integer_type->size, value), + "Value is out of bounds: value=%" PRIu64 ", %![field-]+f", + value, field); + integer->payload.unsignd = value; + bt_field_set(field, true); + return 0; +} - if (bt_field_type_get_type_id(field->type) != - BT_FIELD_TYPE_ID_FLOAT) { - BT_LOGW("Invalid parameter: field's type is not a floating point number field type: " - "field-addr=%p, ft-addr=%p, ft-id=%s", field, - field->type, - bt_field_type_id_string(field->type->id)); - ret = -1; - goto end; - } +int bt_field_floating_point_get_value(struct bt_field *field, double *value) +{ + struct bt_field_floating_point *floating_point; + BT_ASSERT_PRE_NON_NULL(field, "Floating point number field"); + BT_ASSERT_PRE_NON_NULL(value, "Value"); + BT_ASSERT_PRE_FIELD_IS_SET(field, "Floating point number field"); + BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(field, BT_FIELD_TYPE_ID_FLOAT, "Field"); floating_point = container_of(field, struct bt_field_floating_point, parent); *value = floating_point->payload; -end: - return ret; + return 0; } -int bt_field_floating_point_set_value(struct bt_field *field, - double value) +int bt_field_floating_point_set_value(struct bt_field *field, double value) { - int ret = 0; struct bt_field_floating_point *floating_point; - if (!field) { - BT_LOGW_STR("Invalid parameter: field is NULL."); - ret = -1; - goto end; - } - - if (field->frozen) { - BT_LOGW("Invalid parameter: field is frozen: addr=%p", - field); - ret = -1; - goto end; - } - - if (bt_field_type_get_type_id(field->type) != - BT_FIELD_TYPE_ID_FLOAT) { - BT_LOGW("Invalid parameter: field's type is not a floating point number field type: " - "field-addr=%p, ft-addr=%p, ft-id=%s", field, - field->type, - bt_field_type_id_string(field->type->id)); - ret = -1; - goto end; - } - + BT_ASSERT_PRE_NON_NULL(field, "Floating point number field"); + BT_ASSERT_PRE_FIELD_HOT(field, "Floating point number field"); + BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(field, BT_FIELD_TYPE_ID_FLOAT, "Field"); floating_point = container_of(field, struct bt_field_floating_point, parent); floating_point->payload = value; - floating_point->parent.payload_set = true; -end: - return ret; + bt_field_set(field, true); + return 0; } const char *bt_field_string_get_value(struct bt_field *field) { - const char *ret = NULL; struct bt_field_string *string; - if (!field) { - BT_LOGW_STR("Invalid parameter: field is NULL."); - goto end; - } - - if (!field->payload_set) { - BT_LOGV("Field's payload is not set: addr=%p", field); - goto end; - } - - if (bt_field_type_get_type_id(field->type) != - BT_FIELD_TYPE_ID_STRING) { - BT_LOGW("Invalid parameter: field's type is not a string field type: " - "field-addr=%p, ft-addr=%p, ft-id=%s", field, - field->type, - bt_field_type_id_string(field->type->id)); - goto end; - } - - string = container_of(field, - struct bt_field_string, parent); - ret = string->payload->str; -end: - return ret; + BT_ASSERT_PRE_NON_NULL(field, "String field"); + BT_ASSERT_PRE_FIELD_IS_SET(field, "String field"); + BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(field, BT_FIELD_TYPE_ID_STRING, "Field"); + string = container_of(field, struct bt_field_string, parent); + return string->payload->str; } -int bt_field_string_set_value(struct bt_field *field, - const char *value) +int bt_field_string_set_value(struct bt_field *field, const char *value) { - int ret = 0; struct bt_field_string *string; - if (!field) { - BT_LOGW_STR("Invalid parameter: field is NULL."); - ret = -1; - goto end; - } - - if (!value) { - BT_LOGW_STR("Invalid parameter: value is NULL."); - ret = -1; - goto end; - } - - if (field->frozen) { - BT_LOGW("Invalid parameter: field is frozen: addr=%p", - field); - ret = -1; - goto end; - } - - if (bt_field_type_get_type_id(field->type) != - BT_FIELD_TYPE_ID_STRING) { - BT_LOGW("Invalid parameter: field's type is not a string field type: " - "field-addr=%p, ft-addr=%p, ft-id=%s", field, - field->type, - bt_field_type_id_string(field->type->id)); - ret = -1; - goto end; - } - + BT_ASSERT_PRE_NON_NULL(field, "String field"); + BT_ASSERT_PRE_NON_NULL(value, "Value"); + BT_ASSERT_PRE_FIELD_HOT(field, "String field"); + BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(field, BT_FIELD_TYPE_ID_STRING, "Field"); string = container_of(field, struct bt_field_string, parent); if (string->payload) { g_string_assign(string->payload, value); @@ -1488,210 +987,103 @@ int bt_field_string_set_value(struct bt_field *field, string->payload = g_string_new(value); } - string->parent.payload_set = true; -end: - return ret; + bt_field_set(field, true); + return 0; } -int bt_field_string_append(struct bt_field *field, - const char *value) +int bt_field_string_append(struct bt_field *field, const char *value) { - int ret = 0; struct bt_field_string *string_field; - if (!field) { - BT_LOGW_STR("Invalid parameter: field is NULL."); - ret = -1; - goto end; - } - - if (!value) { - BT_LOGW_STR("Invalid parameter: value is NULL."); - ret = -1; - goto end; - } - - if (field->frozen) { - BT_LOGW("Invalid parameter: field is frozen: addr=%p", - field); - ret = -1; - goto end; - } - - if (bt_field_type_get_type_id(field->type) != - BT_FIELD_TYPE_ID_STRING) { - BT_LOGW("Invalid parameter: field's type is not a string field type: " - "field-addr=%p, ft-addr=%p, ft-id=%s", field, - field->type, - bt_field_type_id_string(field->type->id)); - ret = -1; - goto end; - } - + BT_ASSERT_PRE_NON_NULL(field, "String field"); + BT_ASSERT_PRE_NON_NULL(value, "Value"); + BT_ASSERT_PRE_FIELD_HOT(field, "String field"); + BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(field, BT_FIELD_TYPE_ID_STRING, "Field"); string_field = container_of(field, struct bt_field_string, parent); - if (string_field->payload) { g_string_append(string_field->payload, value); } else { string_field->payload = g_string_new(value); } - string_field->parent.payload_set = true; - -end: - return ret; + bt_field_set(field, true); + return 0; } -int bt_field_string_append_len(struct bt_field *field, - const char *value, unsigned int length) +int bt_field_string_append_len(struct bt_field *field, const char *value, + unsigned int length) { - int i; - int ret = 0; - unsigned int effective_length = length; struct bt_field_string *string_field; - if (!field) { - BT_LOGW_STR("Invalid parameter: field is NULL."); - ret = -1; - goto end; - } - - if (!value) { - BT_LOGW_STR("Invalid parameter: value is NULL."); - ret = -1; - goto end; - } - - if (field->frozen) { - BT_LOGW("Invalid parameter: field is frozen: addr=%p", - field); - ret = -1; - goto end; - } - - if (bt_field_type_get_type_id(field->type) != - BT_FIELD_TYPE_ID_STRING) { - BT_LOGW("Invalid parameter: field's type is not a string field type: " - "field-addr=%p, ft-addr=%p, ft-id=%s", field, - field->type, - bt_field_type_id_string(field->type->id)); - ret = -1; - goto end; - } - + BT_ASSERT_PRE_NON_NULL(field, "String field"); + BT_ASSERT_PRE_NON_NULL(value, "Value"); + BT_ASSERT_PRE_FIELD_HOT(field, "String field"); + BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(field, BT_FIELD_TYPE_ID_STRING, "Field"); string_field = container_of(field, struct bt_field_string, parent); /* make sure no null bytes are appended */ - for (i = 0; i < length; ++i) { - if (value[i] == '\0') { - effective_length = i; - break; - } - } + BT_ASSERT_PRE(memchr(value, '\0', length) == NULL, + "String value to append contains a null character: " + "partial-value=\"%.32s\", length=%u", value, length); if (string_field->payload) { - g_string_append_len(string_field->payload, value, - effective_length); + g_string_append_len(string_field->payload, value, length); } else { - string_field->payload = g_string_new_len(value, - effective_length); + string_field->payload = g_string_new_len(value, length); } - string_field->parent.payload_set = true; - -end: - return ret; + bt_field_set(field, true); + return 0; } BT_HIDDEN -int bt_field_validate(struct bt_field *field) +int _bt_field_validate_recursive(struct bt_field *field) { int ret = 0; enum bt_field_type_id type_id; if (!field) { - BT_LOGD_STR("Invalid parameter: field is NULL."); + BT_ASSERT_PRE_MSG("%s", "Invalid field: field is NULL."); ret = -1; goto end; } + BT_ASSERT(field_type_has_known_id(field->type)); type_id = bt_field_type_get_type_id(field->type); - if (type_id <= BT_FIELD_TYPE_ID_UNKNOWN || type_id >= BT_FIELD_TYPE_ID_NR) { - BT_LOGW("Invalid parameter: unknown field type ID: " - "addr=%p, ft-addr=%p, ft-id=%d", - field, field->type, type_id); - ret = -1; - goto end; - } - ret = field_validate_funcs[type_id](field); + end: return ret; } -int bt_field_reset(struct bt_field *field) -{ - int ret = 0; - enum bt_field_type_id type_id; - - if (!field) { - BT_LOGD_STR("Invalid parameter: field is NULL."); - ret = -1; - goto end; - } - - if (field->frozen) { - BT_LOGW("Invalid parameter: field is frozen: addr=%p", - field); - ret = -1; - goto end; - } - - type_id = bt_field_type_get_type_id(field->type); - if (type_id <= BT_FIELD_TYPE_ID_UNKNOWN || type_id >= BT_FIELD_TYPE_ID_NR) { - BT_LOGW("Invalid parameter: unknown field type ID: " - "addr=%p, ft-addr=%p, ft-id=%d", - field, field->type, type_id); - ret = -1; - goto end; - } +BT_HIDDEN +void _bt_field_reset_recursive(struct bt_field *field) +{ BT_ASSERT(field); + field_reset_funcs[field->type->id](field); +} - ret = field_reset_funcs[type_id](field); -end: - return ret; +BT_HIDDEN +void _bt_field_set(struct bt_field *field, bool value) +{ + BT_ASSERT(field); + field->payload_set = value; } BT_HIDDEN -int bt_field_serialize(struct bt_field *field, - struct bt_stream_pos *pos, +int bt_field_serialize_recursive(struct bt_field *field, struct bt_stream_pos *pos, enum bt_byte_order native_byte_order) { - int ret = 0; enum bt_field_type_id type_id; - assert(pos); - - if (!field) { - BT_LOGD_STR("Invalid parameter: field is NULL."); - ret = -1; - goto end; - } - + BT_ASSERT(pos); + BT_ASSERT_PRE_NON_NULL(field, "Field"); + BT_ASSERT(field_type_has_known_id(field->type)); type_id = bt_field_type_get_type_id(field->type); - if (type_id <= BT_FIELD_TYPE_ID_UNKNOWN || type_id >= BT_FIELD_TYPE_ID_NR) { - BT_LOGW("Invalid parameter: unknown field type ID: " - "addr=%p, ft-addr=%p, ft-id=%d", - field, field->type, type_id); - ret = -1; - goto end; - } - - ret = field_serialize_funcs[type_id](field, pos, native_byte_order); -end: - return ret; + return field_serialize_funcs[type_id](field, pos, native_byte_order); } -bt_bool bt_field_is_set(struct bt_field *field) +BT_HIDDEN +bt_bool _bt_field_is_set_recursive(struct bt_field *field) { bt_bool is_set = BT_FALSE; enum bt_field_type_id type_id; @@ -1700,15 +1092,10 @@ bt_bool bt_field_is_set(struct bt_field *field) goto end; } + BT_ASSERT(field_type_has_known_id(field->type)); type_id = bt_field_type_get_type_id(field->type); - if (type_id <= BT_FIELD_TYPE_ID_UNKNOWN || type_id >= BT_FIELD_TYPE_ID_NR) { - BT_LOGW("Invalid parameter: unknown field type ID: " - "field-addr=%p, ft-addr=%p, ft-id=%d", - field, field->type, type_id); - goto end; - } - is_set = field_is_set_funcs[type_id](field); + end: return is_set; } @@ -1719,31 +1106,21 @@ struct bt_field *bt_field_copy(struct bt_field *field) struct bt_field *copy = NULL; enum bt_field_type_id type_id; - if (!field) { - BT_LOGW_STR("Invalid parameter: field is NULL."); - goto end; - } - - type_id = bt_field_type_get_type_id(field->type); - if (type_id <= BT_FIELD_TYPE_ID_UNKNOWN || type_id >= BT_FIELD_TYPE_ID_NR) { - BT_LOGW("Invalid parameter: unknown field type ID: " - "field-addr=%p, ft-addr=%p, ft-id=%d", - field, field->type, type_id); - goto end; - } - + BT_ASSERT_PRE_NON_NULL(field, "Field"); + BT_ASSERT(field_type_has_known_id(field->type)); copy = bt_field_create(field->type); if (!copy) { BT_LOGW("Cannot create field: ft-addr=%p", field->type); goto end; } - copy->payload_set = field->payload_set; + bt_field_set(copy, field->payload_set); + type_id = bt_field_type_get_type_id(field->type); ret = field_copy_funcs[type_id](field, copy); if (ret) { - bt_put(copy); - copy = NULL; + BT_PUT(copy); } + end: return copy; } @@ -1837,7 +1214,7 @@ struct bt_field *bt_field_structure_create( if (!field) { BT_LOGE("Failed to create structure field's member: name=\"%s\", index=%zu", g_quark_to_string(field_type->name), i); - bt_field_structure_destroy(&structure->parent); + bt_field_structure_destroy_recursive(&structure->parent); goto end; } @@ -1877,7 +1254,7 @@ struct bt_field *bt_field_array_create(struct bt_field_type *type) unsigned int array_length; BT_LOGD("Creating array field object: ft-addr=%p", type); - assert(type); + BT_ASSERT(type); if (!array) { BT_LOGE_STR("Failed to allocate one array field."); @@ -1946,11 +1323,11 @@ void bt_field_destroy(struct bt_object *obj) struct bt_field_type *type; enum bt_field_type_id type_id; + BT_ASSERT(obj); field = container_of(obj, struct bt_field, base); type = field->type; + BT_ASSERT(field_type_has_known_id(type)); type_id = bt_field_type_get_type_id(type); - assert(type_id > BT_FIELD_TYPE_ID_UNKNOWN && - type_id < BT_FIELD_TYPE_ID_NR); field_destroy_funcs[type_id](field); BT_LOGD_STR("Putting field's type."); bt_put(type); @@ -1961,24 +1338,18 @@ void bt_field_integer_destroy(struct bt_field *field) { struct bt_field_integer *integer; - if (!field) { - return; - } - + BT_ASSERT(field); BT_LOGD("Destroying integer field object: addr=%p", field); integer = container_of(field, struct bt_field_integer, parent); g_free(integer); } static -void bt_field_enumeration_destroy(struct bt_field *field) +void bt_field_enumeration_destroy_recursive(struct bt_field *field) { struct bt_field_enumeration *enumeration; - if (!field) { - return; - } - + BT_ASSERT(field); BT_LOGD("Destroying enumeration field object: addr=%p", field); enumeration = container_of(field, struct bt_field_enumeration, parent); @@ -1992,10 +1363,7 @@ void bt_field_floating_point_destroy(struct bt_field *field) { struct bt_field_floating_point *floating_point; - if (!field) { - return; - } - + BT_ASSERT(field); BT_LOGD("Destroying floating point number field object: addr=%p", field); floating_point = container_of(field, struct bt_field_floating_point, parent); @@ -2003,14 +1371,11 @@ void bt_field_floating_point_destroy(struct bt_field *field) } static -void bt_field_structure_destroy(struct bt_field *field) +void bt_field_structure_destroy_recursive(struct bt_field *field) { struct bt_field_structure *structure; - if (!field) { - return; - } - + BT_ASSERT(field); BT_LOGD("Destroying structure field object: addr=%p", field); structure = container_of(field, struct bt_field_structure, parent); g_ptr_array_free(structure->fields, TRUE); @@ -2018,14 +1383,11 @@ void bt_field_structure_destroy(struct bt_field *field) } static -void bt_field_variant_destroy(struct bt_field *field) +void bt_field_variant_destroy_recursive(struct bt_field *field) { struct bt_field_variant *variant; - if (!field) { - return; - } - + BT_ASSERT(field); BT_LOGD("Destroying variant field object: addr=%p", field); variant = container_of(field, struct bt_field_variant, parent); BT_LOGD_STR("Putting tag field."); @@ -2036,14 +1398,11 @@ void bt_field_variant_destroy(struct bt_field *field) } static -void bt_field_array_destroy(struct bt_field *field) +void bt_field_array_destroy_recursive(struct bt_field *field) { struct bt_field_array *array; - if (!field) { - return; - } - + BT_ASSERT(field); BT_LOGD("Destroying array field object: addr=%p", field); array = container_of(field, struct bt_field_array, parent); g_ptr_array_free(array->elements, TRUE); @@ -2051,14 +1410,11 @@ void bt_field_array_destroy(struct bt_field *field) } static -void bt_field_sequence_destroy(struct bt_field *field) +void bt_field_sequence_destroy_recursive(struct bt_field *field) { struct bt_field_sequence *sequence; - if (!field) { - return; - } - + BT_ASSERT(field); BT_LOGD("Destroying sequence field object: addr=%p", field); sequence = container_of(field, struct bt_field_sequence, parent); if (sequence->elements) { @@ -2074,10 +1430,7 @@ void bt_field_string_destroy(struct bt_field *field) { struct bt_field_string *string; - if (!field) { - return; - } - + BT_ASSERT(field); BT_LOGD("Destroying string field object: addr=%p", field); string = container_of(field, struct bt_field_string, parent); if (string->payload) { @@ -2093,144 +1446,119 @@ int bt_field_generic_validate(struct bt_field *field) } static -int bt_field_enumeration_validate(struct bt_field *field) +int bt_field_enumeration_validate_recursive(struct bt_field *field) { int ret; struct bt_field_enumeration *enumeration; - if (!field) { - BT_LOGD_STR("Invalid parameter: field is NULL."); - ret = -1; - goto end; - } - + BT_ASSERT(field); enumeration = container_of(field, struct bt_field_enumeration, parent); if (!enumeration->payload) { - BT_LOGW("Invalid enumeration field: payload is not set: " - "addr=%p", field); + BT_ASSERT_PRE_MSG("Invalid enumeration field: payload is not set: " + "%!+f", field); ret = -1; goto end; } - ret = bt_field_validate(enumeration->payload); + ret = bt_field_validate_recursive(enumeration->payload); + end: return ret; } static -int bt_field_structure_validate(struct bt_field *field) +int bt_field_structure_validate_recursive(struct bt_field *field) { int64_t i; int ret = 0; struct bt_field_structure *structure; - if (!field) { - BT_LOGD_STR("Invalid parameter: field is NULL."); - ret = -1; - goto end; - } - + BT_ASSERT(field); structure = container_of(field, struct bt_field_structure, parent); + for (i = 0; i < structure->fields->len; i++) { - struct bt_field *entry_field = structure->fields->pdata[i]; - ret = bt_field_validate(entry_field); + ret = bt_field_validate_recursive( + (void *) structure->fields->pdata[i]); if (ret) { int this_ret; const char *name; - struct bt_field_type *field_type = - bt_field_get_type(field); this_ret = bt_field_type_structure_get_field_by_index( - field_type, &name, NULL, i); - assert(this_ret == 0); - BT_LOGW("Invalid structure field's field: " - "struct-field-addr=%p, field-addr=%p, " - "field-name=\"%s\", index=%" PRId64, - field, entry_field, name, i); - bt_put(field_type); + field->type, &name, NULL, i); + BT_ASSERT(this_ret == 0); + BT_ASSERT_PRE_MSG("Invalid structure field's field: " + "%![struct-field-]+f, field-name=\"%s\", " + "index=%" PRId64 ", %![field-]+f", + field, name, i, structure->fields->pdata[i]); goto end; } } + end: return ret; } static -int bt_field_variant_validate(struct bt_field *field) +int bt_field_variant_validate_recursive(struct bt_field *field) { int ret = 0; struct bt_field_variant *variant; - if (!field) { - BT_LOGD_STR("Invalid parameter: field is NULL."); - ret = -1; - goto end; - } - + BT_ASSERT(field); variant = container_of(field, struct bt_field_variant, parent); - ret = bt_field_validate(variant->payload); + ret = bt_field_validate_recursive(variant->payload); if (ret) { - BT_LOGW("Invalid variant field's payload field: " - "variant-field-addr=%p, variant-payload-field-addr=%p", + BT_ASSERT_PRE_MSG("Invalid variant field's payload field: " + "%![variant-field-]+f, %![payload-field-]+f", field, variant->payload); } -end: + return ret; } static -int bt_field_array_validate(struct bt_field *field) +int bt_field_array_validate_recursive(struct bt_field *field) { int64_t i; int ret = 0; struct bt_field_array *array; - if (!field) { - BT_LOGD_STR("Invalid parameter: field is NULL."); - ret = -1; - goto end; - } - + BT_ASSERT(field); array = container_of(field, struct bt_field_array, parent); for (i = 0; i < array->elements->len; i++) { - struct bt_field *elem_field = array->elements->pdata[i]; - - ret = bt_field_validate(elem_field); + ret = bt_field_validate_recursive((void *) array->elements->pdata[i]); if (ret) { - BT_LOGW("Invalid array field's element field: " - "array-field-addr=%p, field-addr=%p, " - "index=%" PRId64, field, elem_field, i); + BT_ASSERT_PRE_MSG("Invalid array field's element field: " + "%![array-field-]+f, " PRId64 ", " + "%![elem-field-]+f", + field, i, array->elements->pdata[i]); goto end; } } + end: return ret; } static -int bt_field_sequence_validate(struct bt_field *field) +int bt_field_sequence_validate_recursive(struct bt_field *field) { size_t i; int ret = 0; struct bt_field_sequence *sequence; - if (!field) { - BT_LOGD_STR("Invalid parameter: field is NULL."); - ret = -1; - goto end; - } - + BT_ASSERT(field); sequence = container_of(field, struct bt_field_sequence, parent); for (i = 0; i < sequence->elements->len; i++) { - struct bt_field *elem_field = sequence->elements->pdata[i]; - - ret = bt_field_validate(elem_field); + ret = bt_field_validate_recursive( + (void *) sequence->elements->pdata[i]); if (ret) { - BT_LOGW("Invalid sequence field's element field: " - "sequence-field-addr=%p, field-addr=%p, " - "index=%zu", field, elem_field, i); + BT_ASSERT_PRE_MSG("Invalid sequence field's element field: " + "%![seq-field-]+f, " PRId64 ", " + "%![elem-field-]+f", + field, i, sequence->elements->pdata[i]); goto end; } } @@ -2239,182 +1567,114 @@ end: } static -int bt_field_generic_reset(struct bt_field *field) +void bt_field_generic_reset(struct bt_field *field) { - int ret = 0; - - if (!field) { - BT_LOGD_STR("Invalid parameter: field is NULL."); - ret = -1; - goto end; - } - + BT_ASSERT(field); field->payload_set = false; -end: - return ret; } static -int bt_field_enumeration_reset(struct bt_field *field) +void bt_field_enumeration_reset_recursive(struct bt_field *field) { - int ret = 0; struct bt_field_enumeration *enumeration; - if (!field) { - BT_LOGD_STR("Invalid parameter: field is NULL."); - ret = -1; - goto end; - } - + BT_ASSERT(field); enumeration = container_of(field, struct bt_field_enumeration, parent); if (!enumeration->payload) { - goto end; + return; } - ret = bt_field_reset(enumeration->payload); -end: - return ret; + bt_field_reset_recursive(enumeration->payload); } static -int bt_field_structure_reset(struct bt_field *field) +void bt_field_structure_reset_recursive(struct bt_field *field) { int64_t i; - int ret = 0; struct bt_field_structure *structure; - if (!field) { - BT_LOGD_STR("Invalid parameter: field is NULL."); - ret = -1; - goto end; - } - + BT_ASSERT(field); structure = container_of(field, struct bt_field_structure, parent); + for (i = 0; i < structure->fields->len; i++) { struct bt_field *member = structure->fields->pdata[i]; if (!member) { /* - * Structure members are lazily initialized; skip if - * this member has not been allocated yet. + * Structure members are lazily initialized; + * skip if this member has not been allocated + * yet. */ continue; } - ret = bt_field_reset(member); - if (ret) { - BT_LOGE("Failed to reset structure field's field: " - "struct-field-addr=%p, field-addr=%p, " - "index=%" PRId64, field, member, i); - goto end; - } + bt_field_reset_recursive(member); } -end: - return ret; } static -int bt_field_variant_reset(struct bt_field *field) +void bt_field_variant_reset_recursive(struct bt_field *field) { - int ret = 0; struct bt_field_variant *variant; - if (!field) { - BT_LOGD_STR("Invalid parameter: field is NULL."); - ret = -1; - goto end; - } - + BT_ASSERT(field); variant = container_of(field, struct bt_field_variant, parent); BT_PUT(variant->tag); BT_PUT(variant->payload); -end: - return ret; } static -int bt_field_array_reset(struct bt_field *field) +void bt_field_array_reset_recursive(struct bt_field *field) { size_t i; - int ret = 0; struct bt_field_array *array; - if (!field) { - BT_LOGD_STR("Invalid parameter: field is NULL."); - ret = -1; - goto end; - } - + BT_ASSERT(field); array = container_of(field, struct bt_field_array, parent); + for (i = 0; i < array->elements->len; i++) { struct bt_field *member = array->elements->pdata[i]; if (!member) { /* - * Array elements are lazily initialized; skip if - * this member has not been allocated yet. + * Array elements are lazily initialized; skip + * if this member has not been allocated yet. */ continue; } - ret = bt_field_reset(member); - if (ret) { - BT_LOGE("Failed to reset array field's field: " - "array-field-addr=%p, field-addr=%p, " - "index=%zu", field, member, i); - goto end; - } + bt_field_reset_recursive(member); } -end: - return ret; } static -int bt_field_sequence_reset(struct bt_field *field) +void bt_field_sequence_reset_recursive(struct bt_field *field) { - int ret = 0; struct bt_field_sequence *sequence; - if (!field) { - BT_LOGD_STR("Invalid parameter: field is NULL."); - ret = -1; - goto end; - } - + BT_ASSERT(field); sequence = container_of(field, struct bt_field_sequence, parent); + if (sequence->elements) { g_ptr_array_free(sequence->elements, TRUE); sequence->elements = NULL; } + BT_PUT(sequence->length); -end: - return ret; } static -int bt_field_string_reset(struct bt_field *field) +void bt_field_string_reset_recursive(struct bt_field *field) { - int ret = 0; struct bt_field_string *string; - if (!field) { - BT_LOGD_STR("Invalid parameter: field is NULL."); - ret = -1; - goto end; - } - - ret = bt_field_generic_reset(field); - if (ret) { - goto end; - } - + BT_ASSERT(field); + bt_field_generic_reset(field); string = container_of(field, struct bt_field_string, parent); if (string->payload) { g_string_truncate(string->payload, 0); } -end: - return ret; } static @@ -2426,15 +1686,11 @@ int bt_field_integer_serialize(struct bt_field *field, struct bt_field_integer *integer = container_of(field, struct bt_field_integer, parent); + BT_ASSERT_PRE_FIELD_IS_SET(field, "Integer field"); BT_LOGV("Serializing integer field: addr=%p, pos-offset=%" PRId64 ", " "native-bo=%s", field, pos->offset, bt_byte_order_string(native_byte_order)); - if (!bt_field_generic_is_set(field)) { - BT_LOGW_STR("Field's payload is not set."); - ret = -1; - goto end; - } retry: ret = bt_field_integer_write(integer, pos, native_byte_order); if (ret == -EFAULT) { @@ -2449,12 +1705,13 @@ retry: } goto retry; } + end: return ret; } static -int bt_field_enumeration_serialize(struct bt_field *field, +int bt_field_enumeration_serialize_recursive(struct bt_field *field, struct bt_stream_pos *pos, enum bt_byte_order native_byte_order) { @@ -2465,7 +1722,7 @@ int bt_field_enumeration_serialize(struct bt_field *field, "native-bo=%s", field, pos->offset, bt_byte_order_string(native_byte_order)); BT_LOGV_STR("Serializing enumeration field's payload field."); - return bt_field_serialize(enumeration->payload, pos, + return bt_field_serialize_recursive(enumeration->payload, pos, native_byte_order); } @@ -2478,15 +1735,11 @@ int bt_field_floating_point_serialize(struct bt_field *field, struct bt_field_floating_point *floating_point = container_of(field, struct bt_field_floating_point, parent); + BT_ASSERT_PRE_FIELD_IS_SET(field, "Floating point number field"); BT_LOGV("Serializing floating point number field: addr=%p, pos-offset=%" PRId64 ", " "native-bo=%s", field, pos->offset, bt_byte_order_string(native_byte_order)); - if (!bt_field_generic_is_set(field)) { - BT_LOGW_STR("Field's payload is not set."); - ret = -1; - goto end; - } retry: ret = bt_field_floating_point_write(floating_point, pos, native_byte_order); @@ -2502,12 +1755,13 @@ retry: } goto retry; } + end: return ret; } static -int bt_field_structure_serialize(struct bt_field *field, +int bt_field_structure_serialize_recursive(struct bt_field *field, struct bt_stream_pos *pos, enum bt_byte_order native_byte_order) { @@ -2541,17 +1795,14 @@ int bt_field_structure_serialize(struct bt_field *field, structure->fields, i); const char *field_name = NULL; - if (BT_LOG_ON_WARN) { - ret = bt_field_type_structure_get_field_by_index( - field->type, &field_name, NULL, i); - assert(ret == 0); - } - BT_LOGV("Serializing structure field's field: pos-offset=%" PRId64 ", " "field-addr=%p, index=%" PRId64, pos->offset, member, i); if (!member) { + ret = bt_field_type_structure_get_field_by_index( + field->type, &field_name, NULL, i); + BT_ASSERT(ret == 0); BT_LOGW("Cannot serialize structure field's field: field is not set: " "struct-field-addr=%p, " "field-name=\"%s\", index=%" PRId64, @@ -2560,8 +1811,12 @@ int bt_field_structure_serialize(struct bt_field *field, goto end; } - ret = bt_field_serialize(member, pos, native_byte_order); + ret = bt_field_serialize_recursive(member, pos, + native_byte_order); if (ret) { + ret = bt_field_type_structure_get_field_by_index( + field->type, &field_name, NULL, i); + BT_ASSERT(ret == 0); BT_LOGW("Cannot serialize structure field's field: " "struct-field-addr=%p, field-addr=%p, " "field-name=\"%s\", index=%" PRId64, @@ -2569,12 +1824,13 @@ int bt_field_structure_serialize(struct bt_field *field, break; } } + end: return ret; } static -int bt_field_variant_serialize(struct bt_field *field, +int bt_field_variant_serialize_recursive(struct bt_field *field, struct bt_stream_pos *pos, enum bt_byte_order native_byte_order) { @@ -2585,12 +1841,12 @@ int bt_field_variant_serialize(struct bt_field *field, "native-bo=%s", field, pos->offset, bt_byte_order_string(native_byte_order)); BT_LOGV_STR("Serializing variant field's payload field."); - return bt_field_serialize(variant->payload, pos, + return bt_field_serialize_recursive(variant->payload, pos, native_byte_order); } static -int bt_field_array_serialize(struct bt_field *field, +int bt_field_array_serialize_recursive(struct bt_field *field, struct bt_stream_pos *pos, enum bt_byte_order native_byte_order) { @@ -2610,7 +1866,7 @@ int bt_field_array_serialize(struct bt_field *field, BT_LOGV("Serializing array field's element field: " "pos-offset=%" PRId64 ", field-addr=%p, index=%" PRId64, pos->offset, elem_field, i); - ret = bt_field_serialize(elem_field, pos, + ret = bt_field_serialize_recursive(elem_field, pos, native_byte_order); if (ret) { BT_LOGW("Cannot serialize array field's element field: " @@ -2619,12 +1875,13 @@ int bt_field_array_serialize(struct bt_field *field, goto end; } } + end: return ret; } static -int bt_field_sequence_serialize(struct bt_field *field, +int bt_field_sequence_serialize_recursive(struct bt_field *field, struct bt_stream_pos *pos, enum bt_byte_order native_byte_order) { @@ -2644,7 +1901,7 @@ int bt_field_sequence_serialize(struct bt_field *field, BT_LOGV("Serializing sequence field's element field: " "pos-offset=%" PRId64 ", field-addr=%p, index=%" PRId64, pos->offset, elem_field, i); - ret = bt_field_serialize(elem_field, pos, + ret = bt_field_serialize_recursive(elem_field, pos, native_byte_order); if (ret) { BT_LOGW("Cannot serialize sequence field's element field: " @@ -2653,13 +1910,13 @@ int bt_field_sequence_serialize(struct bt_field *field, goto end; } } + end: return ret; } static -int bt_field_string_serialize(struct bt_field *field, - struct bt_stream_pos *pos, +int bt_field_string_serialize(struct bt_field *field, struct bt_stream_pos *pos, enum bt_byte_order native_byte_order) { int64_t i; @@ -2670,6 +1927,7 @@ int bt_field_string_serialize(struct bt_field *field, get_field_type(FIELD_TYPE_ALIAS_UINT8_T); struct bt_field *character; + BT_ASSERT_PRE_FIELD_IS_SET(field, "String field"); BT_LOGV("Serializing string field: addr=%p, pos-offset=%" PRId64 ", " "native-bo=%s", field, pos->offset, bt_byte_order_string(native_byte_order)); @@ -2681,14 +1939,7 @@ int bt_field_string_serialize(struct bt_field *field, const uint64_t chr = (uint64_t) string->payload->str[i]; ret = bt_field_unsigned_integer_set_value(character, chr); - if (ret) { - BT_LOGW("Cannot set character field's value: " - "pos-offset=%" PRId64 ", field-addr=%p, " - "index=%" PRId64 ", char-int=%" PRIu64, - pos->offset, character, i, chr); - goto end; - } - + BT_ASSERT(ret == 0); BT_LOGV("Serializing string field's character field: " "pos-offset=%" PRId64 ", field-addr=%p, " "index=%" PRId64 ", char-int=%" PRIu64, @@ -2700,6 +1951,7 @@ int bt_field_string_serialize(struct bt_field *field, goto end; } } + end: bt_put(character); bt_put(character_type); @@ -2707,8 +1959,7 @@ end: } static -int bt_field_integer_copy(struct bt_field *src, - struct bt_field *dst) +int bt_field_integer_copy(struct bt_field *src, struct bt_field *dst) { struct bt_field_integer *integer_src, *integer_dst; @@ -2722,7 +1973,7 @@ int bt_field_integer_copy(struct bt_field *src, } static -int bt_field_enumeration_copy(struct bt_field *src, +int bt_field_enumeration_copy_recursive(struct bt_field *src, struct bt_field *dst) { int ret = 0; @@ -2749,8 +2000,7 @@ end: } static -int bt_field_floating_point_copy( - struct bt_field *src, struct bt_field *dst) +int bt_field_floating_point_copy(struct bt_field *src, struct bt_field *dst) { struct bt_field_floating_point *float_src, *float_dst; @@ -2766,7 +2016,7 @@ int bt_field_floating_point_copy( } static -int bt_field_structure_copy(struct bt_field *src, +int bt_field_structure_copy_recursive(struct bt_field *src, struct bt_field *dst) { int ret = 0; @@ -2808,7 +2058,7 @@ end: } static -int bt_field_variant_copy(struct bt_field *src, +int bt_field_variant_copy_recursive(struct bt_field *src, struct bt_field *dst) { int ret = 0; @@ -2845,7 +2095,7 @@ end: } static -int bt_field_array_copy(struct bt_field *src, +int bt_field_array_copy_recursive(struct bt_field *src, struct bt_field *dst) { int ret = 0; @@ -2886,7 +2136,7 @@ end: } static -int bt_field_sequence_copy(struct bt_field *src, +int bt_field_sequence_copy_recursive(struct bt_field *src, struct bt_field *dst) { int ret = 0; @@ -2926,7 +2176,7 @@ int bt_field_sequence_copy(struct bt_field *src, goto end; } - assert(sequence_dst->elements->len == sequence_src->elements->len); + BT_ASSERT(sequence_dst->elements->len == sequence_src->elements->len); for (i = 0; i < sequence_src->elements->len; i++) { struct bt_field *field = @@ -2956,7 +2206,7 @@ end: } static -int bt_field_string_copy(struct bt_field *src, +int bt_field_string_copy_recursive(struct bt_field *src, struct bt_field *dst) { int ret = 0; @@ -2987,7 +2237,7 @@ int increase_packet_size(struct bt_stream_pos *pos) { int ret; - assert(pos); + BT_ASSERT(pos); BT_LOGV("Increasing packet size: pos-offset=%" PRId64 ", " "cur-packet-size=%" PRIu64, pos->offset, pos->packet_size); @@ -3022,7 +2272,7 @@ int increase_packet_size(struct bt_stream_pos *pos) BT_LOGV("Increased packet size: pos-offset=%" PRId64 ", " "new-packet-size=%" PRIu64, pos->offset, pos->packet_size); - assert(pos->packet_size % 8 == 0); + BT_ASSERT(pos->packet_size % 8 == 0); end: return ret; @@ -3035,19 +2285,19 @@ void generic_field_freeze(struct bt_field *field) } static -void bt_field_enumeration_freeze(struct bt_field *field) +void bt_field_enumeration_freeze_recursive(struct bt_field *field) { struct bt_field_enumeration *enum_field = container_of(field, struct bt_field_enumeration, parent); BT_LOGD("Freezing enumeration field object: addr=%p", field); BT_LOGD("Freezing enumeration field object's contained payload field: payload-field-addr=%p", enum_field->payload); - bt_field_freeze(enum_field->payload); + bt_field_freeze_recursive(enum_field->payload); generic_field_freeze(field); } static -void bt_field_structure_freeze(struct bt_field *field) +void bt_field_structure_freeze_recursive(struct bt_field *field) { int64_t i; struct bt_field_structure *structure_field = @@ -3061,28 +2311,28 @@ void bt_field_structure_freeze(struct bt_field *field) BT_LOGD("Freezing structure field's field: field-addr=%p, index=%" PRId64, field, i); - bt_field_freeze(field); + bt_field_freeze_recursive(field); } generic_field_freeze(field); } static -void bt_field_variant_freeze(struct bt_field *field) +void bt_field_variant_freeze_recursive(struct bt_field *field) { struct bt_field_variant *variant_field = container_of(field, struct bt_field_variant, parent); BT_LOGD("Freezing variant field object: addr=%p", field); BT_LOGD("Freezing variant field object's tag field: tag-field-addr=%p", variant_field->tag); - bt_field_freeze(variant_field->tag); + bt_field_freeze_recursive(variant_field->tag); BT_LOGD("Freezing variant field object's payload field: payload-field-addr=%p", variant_field->payload); - bt_field_freeze(variant_field->payload); + bt_field_freeze_recursive(variant_field->payload); generic_field_freeze(field); } static -void bt_field_array_freeze(struct bt_field *field) +void bt_field_array_freeze_recursive(struct bt_field *field) { int64_t i; struct bt_field_array *array_field = @@ -3097,14 +2347,14 @@ void bt_field_array_freeze(struct bt_field *field) BT_LOGD("Freezing array field object's element field: " "element-field-addr=%p, index=%" PRId64, elem_field, i); - bt_field_freeze(elem_field); + bt_field_freeze_recursive(elem_field); } generic_field_freeze(field); } static -void bt_field_sequence_freeze(struct bt_field *field) +void bt_field_sequence_freeze_recursive(struct bt_field *field) { int64_t i; struct bt_field_sequence *sequence_field = @@ -3113,7 +2363,7 @@ void bt_field_sequence_freeze(struct bt_field *field) BT_LOGD("Freezing sequence field object: addr=%p", field); BT_LOGD("Freezing sequence field object's length field: length-field-addr=%p", sequence_field->length); - bt_field_freeze(sequence_field->length); + bt_field_freeze_recursive(sequence_field->length); for (i = 0; i < sequence_field->elements->len; i++) { struct bt_field *elem_field = @@ -3122,14 +2372,14 @@ void bt_field_sequence_freeze(struct bt_field *field) BT_LOGD("Freezing sequence field object's element field: " "element-field-addr=%p, index=%" PRId64, elem_field, i); - bt_field_freeze(elem_field); + bt_field_freeze_recursive(elem_field); } generic_field_freeze(field); } BT_HIDDEN -void bt_field_freeze(struct bt_field *field) +void _bt_field_freeze_recursive(struct bt_field *field) { enum bt_field_type_id type_id; @@ -3142,9 +2392,8 @@ void bt_field_freeze(struct bt_field *field) } BT_LOGD("Freezing field object: addr=%p", field); + BT_ASSERT(field_type_has_known_id(field->type)); type_id = bt_field_get_type_id(field); - assert(type_id > BT_FIELD_TYPE_ID_UNKNOWN && - type_id < BT_FIELD_TYPE_ID_NR); field_freeze_funcs[type_id](field); end: return; @@ -3157,40 +2406,34 @@ bt_bool bt_field_generic_is_set(struct bt_field *field) } static -bt_bool bt_field_enumeration_is_set(struct bt_field *field) +bt_bool bt_field_enumeration_is_set_recursive(struct bt_field *field) { bt_bool is_set = BT_FALSE; struct bt_field_enumeration *enumeration; - if (!field) { - goto end; - } - + BT_ASSERT(field); enumeration = container_of(field, struct bt_field_enumeration, parent); if (!enumeration->payload) { goto end; } - is_set = bt_field_is_set(enumeration->payload); + is_set = bt_field_is_set_recursive(enumeration->payload); end: return is_set; } static -bt_bool bt_field_structure_is_set(struct bt_field *field) +bt_bool bt_field_structure_is_set_recursive(struct bt_field *field) { bt_bool is_set = BT_FALSE; size_t i; struct bt_field_structure *structure; - if (!field) { - goto end; - } - + BT_ASSERT(field); structure = container_of(field, struct bt_field_structure, parent); for (i = 0; i < structure->fields->len; i++) { - is_set = bt_field_is_set( + is_set = bt_field_is_set_recursive( structure->fields->pdata[i]); if (!is_set) { goto end; @@ -3201,35 +2444,26 @@ end: } static -bt_bool bt_field_variant_is_set(struct bt_field *field) +bt_bool bt_field_variant_is_set_recursive(struct bt_field *field) { - bt_bool is_set = BT_FALSE; struct bt_field_variant *variant; - if (!field) { - goto end; - } - + BT_ASSERT(field); variant = container_of(field, struct bt_field_variant, parent); - is_set = bt_field_is_set(variant->payload); -end: - return is_set; + return bt_field_is_set_recursive(variant->payload); } static -bt_bool bt_field_array_is_set(struct bt_field *field) +bt_bool bt_field_array_is_set_recursive(struct bt_field *field) { size_t i; bt_bool is_set = BT_FALSE; struct bt_field_array *array; - if (!field) { - goto end; - } - + BT_ASSERT(field); array = container_of(field, struct bt_field_array, parent); for (i = 0; i < array->elements->len; i++) { - is_set = bt_field_is_set(array->elements->pdata[i]); + is_set = bt_field_is_set_recursive(array->elements->pdata[i]); if (!is_set) { goto end; } @@ -3239,23 +2473,20 @@ end: } static -bt_bool bt_field_sequence_is_set(struct bt_field *field) +bt_bool bt_field_sequence_is_set_recursive(struct bt_field *field) { size_t i; bt_bool is_set = BT_FALSE; struct bt_field_sequence *sequence; - if (!field) { - goto end; - } - + BT_ASSERT(field); sequence = container_of(field, struct bt_field_sequence, parent); if (!sequence->elements) { goto end; } for (i = 0; i < sequence->elements->len; i++) { - is_set = bt_field_is_set(sequence->elements->pdata[i]); + is_set = bt_field_is_set_recursive(sequence->elements->pdata[i]); if (!is_set) { goto end; } diff --git a/lib/ctf-ir/packet.c b/lib/ctf-ir/packet.c index 5bd77274..ac3321a9 100644 --- a/lib/ctf-ir/packet.c +++ b/lib/ctf-ir/packet.c @@ -38,157 +38,94 @@ #include #include #include +#include +#include #include struct bt_stream *bt_packet_get_stream(struct bt_packet *packet) { - return packet ? bt_get(packet->stream) : NULL; + BT_ASSERT_PRE_NON_NULL(packet, "Packet"); + return bt_get(packet->stream); } struct bt_field *bt_packet_get_header( struct bt_packet *packet) { - return packet ? bt_get(packet->header) : NULL; + BT_ASSERT_PRE_NON_NULL(packet, "Packet"); + return bt_get(packet->header); } -int bt_packet_set_header(struct bt_packet *packet, - struct bt_field *header) +BT_ASSERT_PRE_FUNC +static inline bool validate_field_to_set(struct bt_field *field, + struct bt_field_type *expected_ft) { - int ret = 0; - struct bt_trace *trace = NULL; - struct bt_stream_class *stream_class = NULL; - struct bt_field_type *header_field_type = NULL; - struct bt_field_type *expected_header_field_type = NULL; - - if (!packet) { - BT_LOGW_STR("Invalid parameter: packet is NULL."); - ret = -1; - goto end; - } - - if (packet->frozen) { - BT_LOGW("Invalid parameter: packet is frozen: addr=%p", - packet); - ret = -1; - goto end; - } - - stream_class = bt_stream_get_class(packet->stream); - assert(stream_class); - trace = bt_stream_class_get_trace(stream_class); - assert(trace); - expected_header_field_type = bt_trace_get_packet_header_type(trace); - - if (!header) { - if (expected_header_field_type) { - BT_LOGW("Invalid parameter: setting no packet header but packet header field type is not NULL: " - "packet-addr=%p, packet-header-ft-addr=%p", - packet, expected_header_field_type); - ret = -1; + bool ret = true; + + if (!field) { + if (expected_ft) { + BT_ASSERT_PRE_MSG("Setting no field, but expected " + "field type is not NULL: " + "%![field-]+f, %![expected-ft-]+F", + field, expected_ft); + ret = false; goto end; } - goto skip_validation; + goto end; } - header_field_type = bt_field_get_type(header); - assert(header_field_type); - - if (bt_field_type_compare(header_field_type, - expected_header_field_type)) { - BT_LOGW("Invalid parameter: packet header's field type is different from the trace's packet header field type: " - "packet-addr=%p, packet-header-addr=%p", - packet, header); - ret = -1; + if (bt_field_type_compare(field->type, expected_ft) != 0) { + BT_ASSERT_PRE_MSG("Field type is different from expected " + " field type: %![field-ft-]+F, %![expected-ft-]+F", + field->type, expected_ft); + ret = false; goto end; } -skip_validation: +end: + return ret; +} + +int bt_packet_set_header(struct bt_packet *packet, + struct bt_field *header) +{ + BT_ASSERT_PRE_NON_NULL(packet, "Packet"); + BT_ASSERT_PRE_HOT(packet, "Packet", ": +%!+a", packet); + BT_ASSERT_PRE(validate_field_to_set(header, + bt_stream_class_borrow_trace(packet->stream->stream_class)->packet_header_type), + "Invalid packet header field: " + "%![packet-]+a, %![field-]+f", packet, header); bt_put(packet->header); packet->header = bt_get(header); BT_LOGV("Set packet's header field: packet-addr=%p, packet-header-addr=%p", packet, header); - -end: - BT_PUT(trace); - BT_PUT(stream_class); - BT_PUT(header_field_type); - BT_PUT(expected_header_field_type); - - return ret; + return 0; } -struct bt_field *bt_packet_get_context( - struct bt_packet *packet) +struct bt_field *bt_packet_get_context(struct bt_packet *packet) { - return packet ? bt_get(packet->context) : NULL; + BT_ASSERT_PRE_NON_NULL(packet, "Packet"); + return bt_get(packet->context); } int bt_packet_set_context(struct bt_packet *packet, struct bt_field *context) { - int ret = 0; - struct bt_stream_class *stream_class = NULL; - struct bt_field_type *context_field_type = NULL; - struct bt_field_type *expected_context_field_type = NULL; - - if (!packet) { - BT_LOGW_STR("Invalid parameter: packet is NULL."); - ret = -1; - goto end; - } - - if (packet->frozen) { - BT_LOGW("Invalid parameter: packet is frozen: addr=%p", - packet); - ret = -1; - goto end; - } - - stream_class = bt_stream_get_class(packet->stream); - assert(stream_class); - expected_context_field_type = - bt_stream_class_get_packet_context_type(stream_class); - - if (!context) { - if (expected_context_field_type) { - BT_LOGW("Invalid parameter: setting no packet context but packet context field type is not NULL: " - "packet-addr=%p, packet-context-ft-addr=%p", - packet, expected_context_field_type); - ret = -1; - goto end; - } - - goto skip_validation; - } - - context_field_type = bt_field_get_type(context); - assert(context_field_type); - - if (bt_field_type_compare(context_field_type, - expected_context_field_type)) { - BT_LOGW("Invalid parameter: packet context's field type is different from the stream class's packet context field type: " - "packet-addr=%p, packet-context-addr=%p", - packet, context); - ret = -1; - goto end; - } - -skip_validation: + BT_ASSERT_PRE_NON_NULL(packet, "Packet"); + BT_ASSERT_PRE_HOT(packet, "Packet", ": +%!+a", packet); + BT_ASSERT_PRE(validate_field_to_set(context, + packet->stream->stream_class->packet_context_type), + "Invalid packet context field: " + "%![packet-]+a, %![field-]+f", packet, context); bt_put(packet->context); packet->context = bt_get(context); BT_LOGV("Set packet's context field: packet-addr=%p, packet-context-addr=%p", packet, context); - -end: - BT_PUT(stream_class); - BT_PUT(context_field_type); - BT_PUT(expected_context_field_type); - return ret; + return 0; } BT_HIDDEN -void bt_packet_freeze(struct bt_packet *packet) +void _bt_packet_freeze(struct bt_packet *packet) { if (!packet || packet->frozen) { return; @@ -196,9 +133,9 @@ void bt_packet_freeze(struct bt_packet *packet) BT_LOGD("Freezing packet: addr=%p", packet); BT_LOGD_STR("Freezing packet's header field."); - bt_field_freeze(packet->header); + bt_field_freeze_recursive(packet->header); BT_LOGD_STR("Freezing packet's context field."); - bt_field_freeze(packet->context); + bt_field_freeze_recursive(packet->context); packet->frozen = 1; } @@ -225,11 +162,7 @@ struct bt_packet *bt_packet_create( struct bt_stream_class *stream_class = NULL; struct bt_trace *trace = NULL; - if (!stream) { - BT_LOGW_STR("Invalid parameter: stream is NULL."); - goto end; - } - + BT_ASSERT_PRE_NON_NULL(stream, "Stream"); BT_LOGD("Creating packet object: stream-addr=%p, " "stream-name=\"%s\", stream-class-addr=%p, " "stream-class-name=\"%s\", stream-class-id=%" PRId64, @@ -237,16 +170,12 @@ struct bt_packet *bt_packet_create( stream->stream_class, bt_stream_class_get_name(stream->stream_class), bt_stream_class_get_id(stream->stream_class)); - - if (stream->pos.fd >= 0) { - BT_LOGW_STR("Invalid parameter: stream is a CTF writer stream."); - goto end; - } - + BT_ASSERT_PRE(stream->pos.fd < 0, + "Stream is a CTF writer stream: %!+s", stream); stream_class = bt_stream_get_class(stream); - assert(stream_class); + BT_ASSERT(stream_class); trace = bt_stream_class_get_trace(stream_class); - assert(trace); + BT_ASSERT(trace); packet = g_new0(struct bt_packet, 1); if (!packet) { BT_LOGE_STR("Failed to allocate one packet object."); diff --git a/lib/ctf-ir/resolve.c b/lib/ctf-ir/resolve.c index 2a6ba2b2..049ddda7 100644 --- a/lib/ctf-ir/resolve.c +++ b/lib/ctf-ir/resolve.c @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -257,7 +258,7 @@ static struct bt_field_type *get_type_from_ctx(struct resolve_context *ctx, enum bt_scope scope) { - assert(scope >= BT_SCOPE_TRACE_PACKET_HEADER && + BT_ASSERT(scope >= BT_SCOPE_TRACE_PACKET_HEADER && scope <= BT_SCOPE_EVENT_FIELDS); return ctx->scopes[scope - BT_SCOPE_TRACE_PACKET_HEADER]; @@ -833,7 +834,7 @@ int get_field_paths_lca_index(struct bt_field_path *field_path1, /* * Start from both roots and find the first mismatch. */ - assert(field_path1->root == field_path2->root); + BT_ASSERT(field_path1->root == field_path2->root); field_path1_len = field_path1->indexes->len; field_path2_len = field_path2->indexes->len; @@ -1218,7 +1219,7 @@ int resolve_root_type(enum bt_scope root_scope, struct resolve_context *ctx) { int ret; - assert(type_stack_size(ctx->type_stack) == 0); + BT_ASSERT(type_stack_size(ctx->type_stack) == 0); ctx->root_scope = root_scope; ret = resolve_type(get_type_from_ctx(ctx, root_scope), ctx); ctx->root_scope = BT_SCOPE_UNKNOWN; diff --git a/lib/ctf-ir/stream-class.c b/lib/ctf-ir/stream-class.c index fe33b61d..3ce610a5 100644 --- a/lib/ctf-ir/stream-class.c +++ b/lib/ctf-ir/stream-class.c @@ -48,6 +48,7 @@ #include #include #include +#include #include #include #include @@ -281,7 +282,7 @@ BT_HIDDEN void _bt_stream_class_set_id( struct bt_stream_class *stream_class, int64_t id) { - assert(stream_class); + BT_ASSERT(stream_class); stream_class->id = id; stream_class->id_set = 1; BT_LOGV("Set stream class's ID (internal): " @@ -512,8 +513,8 @@ int bt_stream_class_add_event_class( * The trace and stream class should be valid at this * point. */ - assert(trace->valid); - assert(stream_class->valid); + BT_ASSERT(trace->valid); + BT_ASSERT(stream_class->valid); packet_header_type = bt_trace_get_packet_header_type(trace); packet_context_type = @@ -614,7 +615,7 @@ int bt_stream_class_add_event_class( * now if the stream class is frozen. */ if (stream_class->frozen && expected_clock_class) { - assert(!stream_class->clock_class || + BT_ASSERT(!stream_class->clock_class || stream_class->clock_class == expected_clock_class); BT_MOVE(stream_class->clock_class, expected_clock_class); } @@ -642,12 +643,12 @@ end: BT_PUT(old_stream_class); bt_validation_output_put_types(&validation_output); bt_put(expected_clock_class); - 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); + BT_ASSERT(!packet_header_type); + BT_ASSERT(!packet_context_type); + BT_ASSERT(!event_header_type); + BT_ASSERT(!stream_event_ctx_type); + BT_ASSERT(!event_context_type); + BT_ASSERT(!event_payload_type); g_free(event_id); return ret; @@ -1045,7 +1046,7 @@ int bt_stream_class_serialize(struct bt_stream_class *stream_class, * and serialization. */ trace = bt_stream_class_borrow_trace(stream_class); - assert(trace); + BT_ASSERT(trace); packet_header_type = bt_trace_get_packet_header_type(trace); trace = NULL; if (packet_header_type) { @@ -1288,14 +1289,14 @@ int try_map_clock_class(struct bt_stream_class *stream_class, bt_field_type_structure_get_field_type_by_name(parent_ft, field_name); - assert(stream_class->clock); + BT_ASSERT(stream_class->clock); if (!ft) { /* Field does not exist: not an error */ goto end; } - assert(bt_field_type_is_integer(ft)); + BT_ASSERT(bt_field_type_is_integer(ft)); mapped_clock_class = bt_field_type_integer_get_mapped_clock_class(ft); if (!mapped_clock_class) { @@ -1319,7 +1320,7 @@ int try_map_clock_class(struct bt_stream_class *stream_class, ret = bt_field_type_integer_set_mapped_clock_class_no_check( ft_copy, stream_class->clock->clock_class); - assert(ret == 0); + BT_ASSERT(ret == 0); ret = bt_field_type_structure_replace_field(parent_ft, field_name, ft_copy); bt_put(ft_copy); @@ -1345,7 +1346,7 @@ int bt_stream_class_map_clock_class( { int ret = 0; - assert(stream_class); + BT_ASSERT(stream_class); if (!stream_class->clock) { /* No clock class to map to */ @@ -1389,8 +1390,8 @@ int bt_stream_class_validate_single_clock_class( int ret; uint64_t i; - assert(stream_class); - assert(expected_clock_class); + BT_ASSERT(stream_class); + BT_ASSERT(expected_clock_class); ret = bt_validate_single_clock_class(stream_class->packet_context_type, expected_clock_class); if (ret) { @@ -1446,7 +1447,7 @@ int bt_stream_class_validate_single_clock_class( struct bt_event_class *event_class = g_ptr_array_index(stream_class->event_classes, i); - assert(event_class); + BT_ASSERT(event_class); ret = bt_event_class_validate_single_clock_class(event_class, expected_clock_class); if (ret) { diff --git a/lib/ctf-ir/stream.c b/lib/ctf-ir/stream.c index ecff9923..64f82d4a 100644 --- a/lib/ctf-ir/stream.c +++ b/lib/ctf-ir/stream.c @@ -47,6 +47,7 @@ #include #include #include +#include #include #include @@ -68,7 +69,7 @@ int set_integer_field_value(struct bt_field* field, uint64_t value) } field_type = bt_field_get_type(field); - assert(field_type); + BT_ASSERT(field_type); if (bt_field_type_get_type_id(field_type) != BT_FIELD_TYPE_ID_INTEGER) { @@ -113,7 +114,7 @@ int set_packet_header_magic(struct bt_stream *stream) stream->packet_header, "magic"); const uint32_t magic_value = 0xc1fc1fc1; - assert(stream); + BT_ASSERT(stream); if (!magic_field) { /* No magic field found. Not an error, skip. */ @@ -151,7 +152,7 @@ int set_packet_header_uuid(struct bt_stream *stream) struct bt_field *uuid_field = bt_field_structure_get_field_by_name( stream->packet_header, "uuid"); - assert(stream); + BT_ASSERT(stream); if (!uuid_field) { /* No uuid field found. Not an error, skip. */ @@ -272,7 +273,7 @@ int set_packet_context_packet_size(struct bt_stream *stream) struct bt_field *field = bt_field_structure_get_field_by_name( stream->packet_context, "packet_size"); - assert(stream); + BT_ASSERT(stream); if (!field) { /* No packet size field found. Not an error, skip. */ @@ -308,7 +309,7 @@ int set_packet_context_content_size(struct bt_stream *stream) struct bt_field *field = bt_field_structure_get_field_by_name( stream->packet_context, "content_size"); - assert(stream); + BT_ASSERT(stream); if (!field) { /* No content size field found. Not an error, skip. */ @@ -344,7 +345,7 @@ int set_packet_context_events_discarded(struct bt_stream *stream) struct bt_field *field = bt_field_structure_get_field_by_name( stream->packet_context, "events_discarded"); - assert(stream); + BT_ASSERT(stream); if (!field) { /* No discarded events count field found. Not an error, skip. */ @@ -360,7 +361,7 @@ int set_packet_context_events_discarded(struct bt_stream *stream) * discarded events. We do not allow wrapping here. If it's * valid, update the stream's current count. */ - if (bt_field_is_set(field)) { + if (bt_field_is_set_recursive(field)) { uint64_t user_val; ret = bt_field_unsigned_integer_get_value(field, @@ -462,7 +463,7 @@ int visit_field_update_clock_value(struct bt_field *field, uint64_t *val) bt_put(cc); val_size = bt_field_type_integer_get_size(field->type); - assert(val_size >= 1); + BT_ASSERT(val_size >= 1); if (bt_field_type_integer_is_signed(field->type)) { int64_t ival; @@ -486,7 +487,7 @@ int visit_field_update_clock_value(struct bt_field *field, uint64_t *val) struct bt_field *int_field = bt_field_enumeration_get_container(field); - assert(int_field); + BT_ASSERT(int_field); ret = visit_field_update_clock_value(int_field, val); bt_put(int_field); break; @@ -496,13 +497,13 @@ int visit_field_update_clock_value(struct bt_field *field, uint64_t *val) uint64_t i; int64_t len = bt_field_type_array_get_length(field->type); - assert(len >= 0); + BT_ASSERT(len >= 0); for (i = 0; i < len; i++) { struct bt_field *elem_field = bt_field_array_get_field(field, i); - assert(elem_field); + BT_ASSERT(elem_field); ret = visit_field_update_clock_value(elem_field, val); bt_put(elem_field); if (ret) { @@ -525,7 +526,7 @@ int visit_field_update_clock_value(struct bt_field *field, uint64_t *val) struct bt_field *elem_field = bt_field_sequence_get_field(field, i); - assert(elem_field); + BT_ASSERT(elem_field); ret = visit_field_update_clock_value(elem_field, val); bt_put(elem_field); if (ret) { @@ -540,13 +541,13 @@ int visit_field_update_clock_value(struct bt_field *field, uint64_t *val) int64_t len = bt_field_type_structure_get_field_count( field->type); - assert(len >= 0); + BT_ASSERT(len >= 0); for (i = 0; i < len; i++) { struct bt_field *member_field = bt_field_structure_get_field_by_index(field, i); - assert(member_field); + BT_ASSERT(member_field); ret = visit_field_update_clock_value(member_field, val); bt_put(member_field); if (ret) { @@ -636,10 +637,10 @@ int set_packet_context_timestamps(struct bt_stream *stream) uint64_t i; int64_t len; - if (ts_begin_field && bt_field_is_set(ts_begin_field)) { + if (ts_begin_field && bt_field_is_set_recursive(ts_begin_field)) { /* Use provided `timestamp_begin` value as starting value */ ret = bt_field_unsigned_integer_get_value(ts_begin_field, &val); - assert(ret == 0); + BT_ASSERT(ret == 0); init_clock_value = val; } else if (stream->last_ts_end != -1ULL) { /* Use last packet's ending timestamp as starting value */ @@ -675,7 +676,7 @@ int set_packet_context_timestamps(struct bt_stream *stream) */ len = bt_field_type_structure_get_field_count( stream->packet_context->type); - assert(len >= 0); + BT_ASSERT(len >= 0); for (i = 0; i < len; i++) { const char *member_name; @@ -683,7 +684,7 @@ int set_packet_context_timestamps(struct bt_stream *stream) ret = bt_field_type_structure_get_field_by_index( stream->packet_context->type, &member_name, NULL, i); - assert(ret == 0); + BT_ASSERT(ret == 0); if (strcmp(member_name, "timestamp_begin") == 0 || strcmp(member_name, "timestamp_end") == 0) { @@ -692,28 +693,28 @@ int set_packet_context_timestamps(struct bt_stream *stream) member_field = bt_field_structure_get_field_by_index( stream->packet_context, i); - assert(member_field); + BT_ASSERT(member_field); if (strcmp(member_name, "packet_size") == 0 && - !bt_field_is_set(member_field)) { + !bt_field_is_set_recursive(member_field)) { bt_put(member_field); continue; } if (strcmp(member_name, "content_size") == 0 && - !bt_field_is_set(member_field)) { + !bt_field_is_set_recursive(member_field)) { bt_put(member_field); continue; } if (strcmp(member_name, "events_discarded") == 0 && - !bt_field_is_set(member_field)) { + !bt_field_is_set_recursive(member_field)) { bt_put(member_field); continue; } if (strcmp(member_name, "packet_seq_num") == 0 && - !bt_field_is_set(member_field)) { + !bt_field_is_set_recursive(member_field)) { bt_put(member_field); continue; } @@ -735,7 +736,7 @@ int set_packet_context_timestamps(struct bt_stream *stream) for (i = 0; i < stream->events->len; i++) { struct bt_event *event = g_ptr_array_index(stream->events, i); - assert(event); + BT_ASSERT(event); ret = visit_event_update_clock_value(event, &cur_clock_value); if (ret) { BT_LOGW("Cannot automatically update clock value " @@ -758,9 +759,9 @@ int set_packet_context_timestamps(struct bt_stream *stream) * against the provided value of `timestamp_end`, if any, * otherwise set it. */ - if (ts_end_field && bt_field_is_set(ts_end_field)) { + if (ts_end_field && bt_field_is_set_recursive(ts_end_field)) { ret = bt_field_unsigned_integer_get_value(ts_end_field, &val); - assert(ret == 0); + BT_ASSERT(ret == 0); if (val < cur_clock_value) { BT_LOGW("Packet's final timestamp is less than " @@ -777,9 +778,9 @@ int set_packet_context_timestamps(struct bt_stream *stream) stream->last_ts_end = val; } - if (ts_end_field && !bt_field_is_set(ts_end_field)) { + if (ts_end_field && !bt_field_is_set_recursive(ts_end_field)) { ret = set_integer_field_value(ts_end_field, cur_clock_value); - assert(ret == 0); + BT_ASSERT(ret == 0); stream->last_ts_end = cur_clock_value; } @@ -788,9 +789,9 @@ int set_packet_context_timestamps(struct bt_stream *stream) } /* Set `timestamp_begin` field to initial clock value */ - if (ts_begin_field && !bt_field_is_set(ts_begin_field)) { + if (ts_begin_field && !bt_field_is_set_recursive(ts_begin_field)) { ret = set_integer_field_value(ts_begin_field, init_clock_value); - assert(ret == 0); + BT_ASSERT(ret == 0); } end: @@ -884,7 +885,7 @@ int create_stream_file(struct bt_ctf_writer *writer, /* Use stream name's base name as prefix */ gchar *basename = g_path_get_basename(stream->name->str); - assert(basename); + BT_ASSERT(basename); if (strcmp(basename, G_DIR_SEPARATOR_S) == 0) { g_string_assign(filename, "stream"); @@ -902,7 +903,7 @@ int create_stream_file(struct bt_ctf_writer *writer, gchar *basename = g_path_get_basename(stream->stream_class->name->str); - assert(basename); + BT_ASSERT(basename); if (strcmp(basename, G_DIR_SEPARATOR_S) == 0) { g_string_assign(filename, "stream"); @@ -919,8 +920,8 @@ int create_stream_file(struct bt_ctf_writer *writer, append_ids: stream_class_id = bt_stream_class_get_id(stream->stream_class); - assert(stream_class_id >= 0); - assert(stream->id >= 0); + BT_ASSERT(stream_class_id >= 0); + BT_ASSERT(stream->id >= 0); g_string_append_printf(filename, "-%" PRId64 "-%" PRId64, stream_class_id, stream->id); @@ -1077,7 +1078,7 @@ struct bt_stream *bt_stream_create_with_id_no_check( BT_LOGD("Stream object belongs to a writer's trace: " "writer-addr=%p", writer); - assert(writer); + BT_ASSERT(writer); if (stream_class->packet_context_type) { BT_LOGD("Creating stream's packet context field: " @@ -1364,7 +1365,7 @@ static int auto_populate_event_header(struct bt_stream *stream, struct bt_clock_class *mapped_clock_class = NULL; int64_t event_class_id; - assert(event); + BT_ASSERT(event); if (!event->event_header) { goto end; @@ -1382,7 +1383,7 @@ static int auto_populate_event_header(struct bt_stream *stream, id_field = bt_field_structure_get_field_by_name(event->event_header, "id"); event_class_id = bt_event_class_get_id(event->event_class); - assert(event_class_id >= 0); + BT_ASSERT(event_class_id >= 0); if (id_field && bt_field_type_is_integer(id_field->type)) { ret = set_integer_field_value(id_field, event_class_id); @@ -1407,21 +1408,19 @@ static int auto_populate_event_header(struct bt_stream *stream, event->event_header, "timestamp"); if (timestamp_field && stream->stream_class->clock && bt_field_type_is_integer(timestamp_field->type) && - !bt_field_is_set(timestamp_field)) { - struct bt_clock_class *stream_class_clock_class = - stream->stream_class->clock->clock_class; - + !bt_field_is_set_recursive(timestamp_field)) { mapped_clock_class = bt_field_type_integer_get_mapped_clock_class( timestamp_field->type); if (mapped_clock_class) { uint64_t timestamp; - assert(mapped_clock_class == stream_class_clock_class); + BT_ASSERT(mapped_clock_class == + stream->stream_class->clock->clock_class); ret = bt_ctf_clock_get_value( stream->stream_class->clock, ×tamp); - assert(ret == 0); + BT_ASSERT(ret == 0); ret = set_integer_field_value(timestamp_field, timestamp); if (ret) { @@ -1662,7 +1661,7 @@ int bt_stream_set_packet_header(struct bt_stream *stream, } field_type = bt_field_get_type(field); - assert(field_type); + BT_ASSERT(field_type); if (bt_field_type_compare(field_type, trace->packet_header_type)) { BT_LOGW("Invalid parameter: packet header's field type is different from the stream's packet header field type: " @@ -1695,7 +1694,7 @@ void reset_structure_field(struct bt_field *structure, const char *name) member = bt_field_structure_get_field_by_name(structure, name); if (member) { - (void) bt_field_reset(member); + (void) bt_field_reset_recursive(member); bt_put(member); } } @@ -1748,7 +1747,7 @@ int bt_stream_flush(struct bt_stream *stream) "stream-name=\"%s\", packet-index=%u", stream, bt_stream_get_name(stream), stream->flushed_packet_count); trace = bt_stream_class_borrow_trace(stream->stream_class); - assert(trace); + BT_ASSERT(trace); native_byte_order = bt_trace_get_native_byte_order(trace); ret = auto_populate_packet_header(stream); @@ -1769,12 +1768,12 @@ int bt_stream_flush(struct bt_stream *stream) BT_LOGV("Seeking to the next packet: pos-offset=%" PRId64, stream->pos.offset); bt_stream_pos_packet_seek(&stream->pos, 0, SEEK_CUR); - assert(stream->pos.packet_size % 8 == 0); + BT_ASSERT(stream->pos.packet_size % 8 == 0); if (stream->packet_header) { BT_LOGV_STR("Serializing packet header field."); - ret = bt_field_serialize(stream->packet_header, &stream->pos, - native_byte_order); + ret = bt_field_serialize_recursive(stream->packet_header, + &stream->pos, native_byte_order); if (ret) { BT_LOGW("Cannot serialize stream's packet header field: " "field-addr=%p", stream->packet_header); @@ -1787,7 +1786,7 @@ int bt_stream_flush(struct bt_stream *stream) memcpy(&packet_context_pos, &stream->pos, sizeof(packet_context_pos)); BT_LOGV_STR("Serializing packet context field."); - ret = bt_field_serialize(stream->packet_context, + ret = bt_field_serialize_recursive(stream->packet_context, &stream->pos, native_byte_order); if (ret) { BT_LOGW("Cannot serialize stream's packet context field: " @@ -1814,7 +1813,7 @@ int bt_stream_flush(struct bt_stream *stream) /* Write event header */ if (event->event_header) { BT_LOGV_STR("Serializing event's header field."); - ret = bt_field_serialize(event->event_header, + ret = bt_field_serialize_recursive(event->event_header, &stream->pos, native_byte_order); if (ret) { BT_LOGW("Cannot serialize event's header field: " @@ -1826,7 +1825,7 @@ int bt_stream_flush(struct bt_stream *stream) /* Write stream event context */ if (event->stream_event_context) { BT_LOGV_STR("Serializing event's stream event context field."); - ret = bt_field_serialize( + ret = bt_field_serialize_recursive( event->stream_event_context, &stream->pos, native_byte_order); if (ret) { @@ -1856,7 +1855,7 @@ int bt_stream_flush(struct bt_stream *stream) goto end; } - assert(stream->pos.packet_size % 8 == 0); + BT_ASSERT(stream->pos.packet_size % 8 == 0); /* * Remove extra padding bytes. @@ -1903,7 +1902,7 @@ int bt_stream_flush(struct bt_stream *stream) } BT_LOGV("Rewriting (serializing) packet context field."); - ret = bt_field_serialize(stream->packet_context, + ret = bt_field_serialize_recursive(stream->packet_context, &packet_context_pos, native_byte_order); if (ret) { BT_LOGW("Cannot serialize stream's packet context field: " @@ -2024,7 +2023,7 @@ void bt_stream_destroy(struct bt_object *obj) g_hash_table_iter_init(&ht_iter, stream->comp_cur_port); while (g_hash_table_iter_next(&ht_iter, &comp_gptr, &port_gptr)) { - assert(comp_gptr); + BT_ASSERT(comp_gptr); bt_component_remove_destroy_listener((void *) comp_gptr, component_destroy_listener, stream); } @@ -2051,8 +2050,8 @@ int _set_structure_field_integer(struct bt_field *structure, char *name, struct bt_field_type *field_type = NULL; struct bt_field *integer; - assert(structure); - assert(name); + BT_ASSERT(structure); + BT_ASSERT(name); integer = bt_field_structure_get_field_by_name(structure, name); if (!integer) { @@ -2063,7 +2062,7 @@ int _set_structure_field_integer(struct bt_field *structure, char *name, } /* Make sure the payload has not already been set. */ - if (!force && bt_field_is_set(integer)) { + if (!force && bt_field_is_set_recursive(integer)) { /* Payload already set, not an error */ BT_LOGV("Field's payload is already set: struct-field-addr=%p, " "name=\"%s\", force=%d", structure, name, force); @@ -2071,7 +2070,7 @@ int _set_structure_field_integer(struct bt_field *structure, char *name, } field_type = bt_field_get_type(integer); - assert(field_type); + BT_ASSERT(field_type); if (bt_field_type_get_type_id(field_type) != BT_FIELD_TYPE_ID_INTEGER) { /* * The user most likely meant for us to populate this field @@ -2147,10 +2146,10 @@ void bt_stream_map_component_to_port(struct bt_stream *stream, struct bt_component *comp, struct bt_port *port) { - assert(stream); - assert(comp); - assert(port); - assert(stream->comp_cur_port); + BT_ASSERT(stream); + BT_ASSERT(comp); + BT_ASSERT(port); + BT_ASSERT(stream->comp_cur_port); /* * Do not take a reference to the component here because we @@ -2175,9 +2174,9 @@ BT_HIDDEN struct bt_port *bt_stream_port_for_component(struct bt_stream *stream, struct bt_component *comp) { - assert(stream); - assert(comp); - assert(stream->comp_cur_port); + BT_ASSERT(stream); + BT_ASSERT(comp); + BT_ASSERT(stream->comp_cur_port); return g_hash_table_lookup(stream->comp_cur_port, comp); } @@ -2187,8 +2186,8 @@ void bt_stream_add_destroy_listener(struct bt_stream *stream, { struct bt_stream_destroy_listener listener; - assert(stream); - assert(func); + BT_ASSERT(stream); + BT_ASSERT(func); listener.func = func; listener.data = data; g_array_append_val(stream->destroy_listeners, listener); @@ -2203,8 +2202,8 @@ void bt_stream_remove_destroy_listener(struct bt_stream *stream, { size_t i; - assert(stream); - assert(func); + BT_ASSERT(stream); + BT_ASSERT(func); for (i = 0; i < stream->destroy_listeners->len; i++) { struct bt_stream_destroy_listener *listener = diff --git a/lib/ctf-ir/trace.c b/lib/ctf-ir/trace.c index 284427ee..1b1e5f82 100644 --- a/lib/ctf-ir/trace.c +++ b/lib/ctf-ir/trace.c @@ -50,6 +50,7 @@ #include #include #include +#include #include #include #include @@ -481,7 +482,7 @@ int64_t bt_trace_get_environment_field_count(struct bt_trace *trace) } ret = bt_attributes_get_count(trace->environment); - assert(ret >= 0); + BT_ASSERT(ret >= 0); end: return ret; @@ -707,7 +708,7 @@ bool packet_header_field_type_is_valid(struct bt_trace *trace, ret = bt_field_type_structure_get_field_by_index( packet_header_type, &field_name, NULL, 0); - assert(ret == 0); + BT_ASSERT(ret == 0); if (strcmp(field_name, "magic") != 0) { BT_LOGW("Invalid packet header field type: `magic` field must be the first field: " @@ -745,7 +746,7 @@ bool packet_header_field_type_is_valid(struct bt_trace *trace, } elem_ft = bt_field_type_array_get_element_type(field_type); - assert(elem_ft); + BT_ASSERT(elem_ft); if (!bt_field_type_is_integer(elem_ft)) { BT_LOGW("Invalid packet header field type: `uuid` field's element field type must be an integer field type: " @@ -1088,7 +1089,7 @@ bool event_header_field_type_is_valid(struct bt_trace *trace, goto invalid; } - assert(int_ft); + BT_ASSERT(int_ft); if (bt_field_type_integer_is_signed(int_ft)) { BT_LOGW("Invalid event header field type: `id` field must be an unsigned integer or enumeration field type: " "id-ft-addr=%p", int_ft); @@ -1198,7 +1199,7 @@ int bt_trace_add_stream_class(struct bt_trace *trace, event_class_count = bt_stream_class_get_event_class_count(stream_class); - assert(event_class_count >= 0); + BT_ASSERT(event_class_count >= 0); if (stream_class->clock) { struct bt_clock_class *stream_clock_class = @@ -1595,10 +1596,10 @@ end: bt_validation_output_put_types(&trace_sc_validation_output); bt_put(current_parent_trace); bt_put(expected_clock_class); - assert(!packet_header_type); - assert(!packet_context_type); - assert(!event_header_type); - assert(!stream_event_ctx_type); + BT_ASSERT(!packet_header_type); + BT_ASSERT(!packet_context_type); + BT_ASSERT(!event_header_type); + BT_ASSERT(!stream_event_ctx_type); return ret; } @@ -1763,8 +1764,8 @@ bt_bool bt_trace_has_clock_class(struct bt_trace *trace, { struct search_query query = { .value = clock_class, .found = 0 }; - assert(trace); - assert(clock_class); + BT_ASSERT(trace); + BT_ASSERT(clock_class); g_ptr_array_foreach(trace->clocks, value_exists, &query); return query.found; @@ -1812,7 +1813,7 @@ int append_trace_metadata(struct bt_trace *trace, g_string_append(context->string, "trace {\n"); g_string_append(context->string, "\tmajor = 1;\n"); g_string_append(context->string, "\tminor = 8;\n"); - assert(trace->native_byte_order == BT_BYTE_ORDER_LITTLE_ENDIAN || + BT_ASSERT(trace->native_byte_order == BT_BYTE_ORDER_LITTLE_ENDIAN || trace->native_byte_order == BT_BYTE_ORDER_BIG_ENDIAN || trace->native_byte_order == BT_BYTE_ORDER_NETWORK); @@ -1869,8 +1870,8 @@ void append_env_metadata(struct bt_trace *trace, env_field_value_obj = bt_attributes_get_field_value( trace->environment, i); - assert(entry_name); - assert(env_field_value_obj); + BT_ASSERT(entry_name); + BT_ASSERT(env_field_value_obj); switch (bt_value_get_type(env_field_value_obj)) { case BT_VALUE_TYPE_INTEGER: @@ -1880,7 +1881,7 @@ void append_env_metadata(struct bt_trace *trace, ret = bt_value_integer_get(env_field_value_obj, &int_value); - assert(ret == 0); + BT_ASSERT(ret == 0); g_string_append_printf(context->string, "\t%s = %" PRId64 ";\n", entry_name, int_value); @@ -1894,7 +1895,7 @@ void append_env_metadata(struct bt_trace *trace, ret = bt_value_string_get(env_field_value_obj, &str_value); - assert(ret == 0); + BT_ASSERT(ret == 0); escaped_str = g_strescape(str_value, NULL); if (!escaped_str) { BT_LOGE("Cannot escape string: string=\"%s\"", @@ -2187,8 +2188,8 @@ int bt_trace_object_modification(struct bt_visitor_object *object, size_t i; struct bt_trace *trace = trace_ptr; - assert(trace); - assert(object); + BT_ASSERT(trace); + BT_ASSERT(object); if (trace->listeners->len == 0) { goto end; diff --git a/lib/ctf-ir/utils.c b/lib/ctf-ir/utils.c index 8690f025..8fffff9e 100644 --- a/lib/ctf-ir/utils.c +++ b/lib/ctf-ir/utils.c @@ -29,13 +29,13 @@ #define BT_LOG_TAG "CTF-IR-UTILS" #include -#include #include #include #include #include #include #include +#include static const char * const reserved_keywords_str[] = {"align", "callsite", @@ -59,7 +59,7 @@ void try_init_reserved_keywords(void) } reserved_keywords_set = g_hash_table_new(g_direct_hash, g_direct_equal); - assert(reserved_keywords_set); + BT_ASSERT(reserved_keywords_set); for (i = 0; i < reserved_keywords_count; i++) { gpointer quark = GINT_TO_POINTER(g_quark_from_string( @@ -136,7 +136,7 @@ int bt_validate_single_clock_class(struct bt_field_type *field_type, goto end; } - assert(expected_clock_class); + BT_ASSERT(expected_clock_class); switch (bt_field_type_get_type_id(field_type)) { case BT_FIELD_TYPE_ID_INTEGER: @@ -201,7 +201,7 @@ int bt_validate_single_clock_class(struct bt_field_type *field_type, abort(); } - assert(subtype); + BT_ASSERT(subtype); ret = bt_validate_single_clock_class(subtype, expected_clock_class); bt_put(subtype); @@ -219,7 +219,7 @@ int bt_validate_single_clock_class(struct bt_field_type *field_type, ret = bt_field_type_structure_get_field_by_index( field_type, &name, &member_type, i); - assert(ret == 0); + BT_ASSERT(ret == 0); ret = bt_validate_single_clock_class(member_type, expected_clock_class); bt_put(member_type); @@ -247,7 +247,7 @@ int bt_validate_single_clock_class(struct bt_field_type *field_type, ret = bt_field_type_variant_get_field_by_index( field_type, &name, &member_type, i); - assert(ret == 0); + BT_ASSERT(ret == 0); ret = bt_validate_single_clock_class(member_type, expected_clock_class); bt_put(member_type); diff --git a/lib/ctf-writer/clock.c b/lib/ctf-writer/clock.c index 5afe3fd5..7386096c 100644 --- a/lib/ctf-writer/clock.c +++ b/lib/ctf-writer/clock.c @@ -27,6 +27,9 @@ * SOFTWARE. */ +#define BT_LOG_TAG "CTF-WRITER-CLOCK" +#include + #include #include #include @@ -35,6 +38,8 @@ #include #include #include +#include +#include #include static @@ -46,12 +51,8 @@ struct bt_ctf_clock *bt_ctf_clock_create(const char *name) struct bt_ctf_clock *clock = NULL; unsigned char cc_uuid[BABELTRACE_UUID_LEN]; - if (!name) { - goto error; - } - + BT_ASSERT_PRE_NON_NULL(name, "Name"); clock = g_new0(struct bt_ctf_clock, 1); - if (!clock) { goto error; } @@ -72,7 +73,7 @@ struct bt_ctf_clock *bt_ctf_clock_create(const char *name) } ret = bt_clock_class_set_uuid(clock->clock_class, cc_uuid); - assert(ret == 0); + BT_ASSERT(ret == 0); return clock; error: @@ -82,189 +83,99 @@ error: const char *bt_ctf_clock_get_name(struct bt_ctf_clock *clock) { - const char *name = NULL; - - if (clock) { - name = bt_clock_class_get_name(clock->clock_class); - } - - return name; + BT_ASSERT_PRE_NON_NULL(clock, "CTF writer clock"); + return bt_clock_class_get_name(clock->clock_class); } const char *bt_ctf_clock_get_description(struct bt_ctf_clock *clock) { - const char *description = NULL; - - if (clock) { - description = bt_clock_class_get_description( - clock->clock_class); - } - - return description; + BT_ASSERT_PRE_NON_NULL(clock, "CTF writer clock"); + return bt_clock_class_get_description(clock->clock_class); } int bt_ctf_clock_set_description(struct bt_ctf_clock *clock, const char *desc) { - int ret = -1; - - if (clock) { - ret = bt_clock_class_set_description(clock->clock_class, - desc); - } - - return ret; + BT_ASSERT_PRE_NON_NULL(clock, "CTF writer clock"); + return bt_clock_class_set_description(clock->clock_class, desc); } uint64_t bt_ctf_clock_get_frequency(struct bt_ctf_clock *clock) { - uint64_t freq = -1ULL; - - if (clock) { - freq = bt_clock_class_get_frequency(clock->clock_class); - } - - return freq; + BT_ASSERT_PRE_NON_NULL(clock, "CTF writer clock"); + return bt_clock_class_get_frequency(clock->clock_class); } int bt_ctf_clock_set_frequency(struct bt_ctf_clock *clock, uint64_t freq) { - int ret = -1; - - if (clock) { - ret = bt_clock_class_set_frequency(clock->clock_class, - freq); - } - - return ret; + BT_ASSERT_PRE_NON_NULL(clock, "CTF writer clock"); + return bt_clock_class_set_frequency(clock->clock_class, freq); } uint64_t bt_ctf_clock_get_precision(struct bt_ctf_clock *clock) { - uint64_t precision = -1ULL; - - if (clock) { - precision = bt_clock_class_get_precision( - clock->clock_class); - } - - return precision; + BT_ASSERT_PRE_NON_NULL(clock, "CTF writer clock"); + return bt_clock_class_get_precision(clock->clock_class); } int bt_ctf_clock_set_precision(struct bt_ctf_clock *clock, uint64_t precision) { - int ret = -1; - - if (clock) { - ret = bt_clock_class_set_precision(clock->clock_class, - precision); - } - - return ret; + BT_ASSERT_PRE_NON_NULL(clock, "CTF writer clock"); + return bt_clock_class_set_precision(clock->clock_class, precision); } int bt_ctf_clock_get_offset_s(struct bt_ctf_clock *clock, int64_t *offset_s) { - int ret = -1; - - if (clock) { - ret = bt_clock_class_get_offset_s(clock->clock_class, - offset_s); - } - - return ret; + BT_ASSERT_PRE_NON_NULL(clock, "CTF writer clock"); + return bt_clock_class_get_offset_s(clock->clock_class, offset_s); } int bt_ctf_clock_set_offset_s(struct bt_ctf_clock *clock, int64_t offset_s) { - int ret = -1; - - if (clock) { - ret = bt_clock_class_set_offset_s(clock->clock_class, - offset_s); - } - - return ret; + BT_ASSERT_PRE_NON_NULL(clock, "CTF writer clock"); + return bt_clock_class_set_offset_s(clock->clock_class, offset_s); } int bt_ctf_clock_get_offset(struct bt_ctf_clock *clock, int64_t *offset) { - int ret = -1; - - if (clock) { - ret = bt_clock_class_get_offset_cycles(clock->clock_class, - offset); - } - - return ret; + BT_ASSERT_PRE_NON_NULL(clock, "CTF writer clock"); + return bt_clock_class_get_offset_cycles(clock->clock_class, offset); } int bt_ctf_clock_set_offset(struct bt_ctf_clock *clock, int64_t offset) { - int ret = -1; - - if (clock) { - ret = bt_clock_class_set_offset_cycles(clock->clock_class, - offset); - } - - return ret; + BT_ASSERT_PRE_NON_NULL(clock, "CTF writer clock"); + return bt_clock_class_set_offset_cycles(clock->clock_class, offset); } int bt_ctf_clock_get_is_absolute(struct bt_ctf_clock *clock) { - int is_absolute = -1; - - if (clock) { - is_absolute = bt_clock_class_is_absolute( - clock->clock_class); - } - - return is_absolute; + BT_ASSERT_PRE_NON_NULL(clock, "CTF writer clock"); + return bt_clock_class_is_absolute(clock->clock_class); } int bt_ctf_clock_set_is_absolute(struct bt_ctf_clock *clock, int is_absolute) { - int ret = -1; - - if (clock) { - ret = bt_clock_class_set_is_absolute(clock->clock_class, - is_absolute); - } - - return ret; + BT_ASSERT_PRE_NON_NULL(clock, "CTF writer clock"); + return bt_clock_class_set_is_absolute(clock->clock_class, is_absolute); } const unsigned char *bt_ctf_clock_get_uuid(struct bt_ctf_clock *clock) { - const unsigned char *uuid = NULL; - - if (clock) { - uuid = bt_clock_class_get_uuid(clock->clock_class); - } - - return uuid; + BT_ASSERT_PRE_NON_NULL(clock, "CTF writer clock"); + return bt_clock_class_get_uuid(clock->clock_class); } int bt_ctf_clock_set_uuid(struct bt_ctf_clock *clock, const unsigned char *uuid) { - int ret = -1; - - if (clock) { - ret = bt_clock_class_set_uuid(clock->clock_class, uuid); - } - - return ret; + BT_ASSERT_PRE_NON_NULL(clock, "CTF writer clock"); + return bt_clock_class_set_uuid(clock->clock_class, uuid); } int bt_ctf_clock_set_time(struct bt_ctf_clock *clock, int64_t time) { - int ret = 0; int64_t value; - if (!clock) { - ret = -1; - goto end; - } + BT_ASSERT_PRE_NON_NULL(clock, "CTF writer clock"); /* Common case where cycles are actually nanoseconds */ if (clock->clock_class->frequency == 1000000000) { @@ -274,15 +185,12 @@ int bt_ctf_clock_set_time(struct bt_ctf_clock *clock, int64_t time) (double) clock->clock_class->frequency) / 1e9); } - if (clock->value > value) { - /* Timestamps must be strictly monotonic. */ - ret = -1; - goto end; - } - + BT_ASSERT_PRE(clock->value <= value, + "CTF writer clock value must be updated monotonically: " + "prev-value=%" PRId64 ", new-value=%" PRId64, + clock->value, value); clock->value = value; -end: - return ret; + return 0; } void bt_ctf_clock_get(struct bt_ctf_clock *clock) @@ -298,16 +206,10 @@ void bt_ctf_clock_put(struct bt_ctf_clock *clock) BT_HIDDEN int bt_ctf_clock_get_value(struct bt_ctf_clock *clock, uint64_t *value) { - int ret = 0; - - if (!clock || !value) { - ret = -1; - goto end; - } - + BT_ASSERT_PRE_NON_NULL(clock, "CTF writer clock"); + BT_ASSERT_PRE_NON_NULL(value, "Value"); *value = clock->value; -end: - return ret; + return 0; } static diff --git a/lib/ctf-writer/serialize.c b/lib/ctf-writer/serialize.c index 459cf9df..ce6b96b3 100644 --- a/lib/ctf-writer/serialize.c +++ b/lib/ctf-writer/serialize.c @@ -43,6 +43,7 @@ #include #include #include +#include #include #if (FLT_RADIX != 2) @@ -72,7 +73,7 @@ int aligned_integer_write(struct bt_stream_pos *pos, if (!bt_stream_pos_access_ok(pos, size)) return -EFAULT; - assert(!(pos->offset % CHAR_BIT)); + BT_ASSERT(!(pos->offset % CHAR_BIT)); if (!is_signed) { switch (size) { case 8: @@ -271,7 +272,7 @@ void bt_stream_pos_packet_seek(struct bt_stream_pos *pos, size_t index, { int ret; - assert(whence == SEEK_CUR && index == 0); + BT_ASSERT(whence == SEEK_CUR && index == 0); if (pos->base_mma) { /* unmap old base */ @@ -290,7 +291,7 @@ void bt_stream_pos_packet_seek(struct bt_stream_pos *pos, size_t index, ret = bt_posix_fallocate(pos->fd, pos->mmap_offset, pos->packet_size / CHAR_BIT); } while (ret == EINTR); - assert(ret == 0); + BT_ASSERT(ret == 0); pos->offset = 0; /* map new base. Need mapping length from header. */ diff --git a/lib/ctf-writer/writer.c b/lib/ctf-writer/writer.c index ce884ea6..a4ad7fe8 100644 --- a/lib/ctf-writer/writer.c +++ b/lib/ctf-writer/writer.c @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -156,7 +157,7 @@ struct bt_ctf_writer *bt_ctf_writer_create(const char *path) /* Default to little-endian */ ret = bt_ctf_writer_set_byte_order(writer, BT_BYTE_ORDER_NATIVE); - assert(ret == 0); + BT_ASSERT(ret == 0); /* Create trace directory if necessary and open a metadata file */ if (g_mkdir_with_parents(path, S_IRWXU | S_IRWXG)) { diff --git a/lib/graph/clock-class-priority-map.c b/lib/graph/clock-class-priority-map.c index b385d39b..94a3ef0f 100644 --- a/lib/graph/clock-class-priority-map.c +++ b/lib/graph/clock-class-priority-map.c @@ -32,6 +32,8 @@ #include #include #include +#include +#include #include #include #include @@ -41,10 +43,6 @@ void bt_clock_class_priority_map_destroy(struct bt_object *obj) { struct bt_clock_class_priority_map *cc_prio_map = (void *) obj; - if (!cc_prio_map) { - return; - } - BT_LOGD("Destroying component class priority map object: addr=%p", cc_prio_map); @@ -101,42 +99,19 @@ end: int64_t bt_clock_class_priority_map_get_clock_class_count( struct bt_clock_class_priority_map *cc_prio_map) { - int64_t ret = (int64_t) -1; - - if (!cc_prio_map) { - BT_LOGW_STR("Invalid parameter: clock class priority map is NULL."); - goto end; - } - - ret = (int64_t) cc_prio_map->entries->len; - -end: - return ret; + BT_ASSERT_PRE_NON_NULL(cc_prio_map, "Clock class priority map"); + return (int64_t) cc_prio_map->entries->len; } struct bt_clock_class *bt_clock_class_priority_map_get_clock_class_by_index( struct bt_clock_class_priority_map *cc_prio_map, uint64_t index) { - struct bt_clock_class *clock_class = NULL; - - if (!cc_prio_map) { - BT_LOGW_STR("Invalid parameter: clock class priority map is NULL."); - goto end; - } - - if (index >= cc_prio_map->entries->len) { - BT_LOGW("Invalid parameter: index is out of bounds: " - "addr=%p, index=%" PRIu64 ", count=%u", - cc_prio_map, index, cc_prio_map->entries->len); - goto end; - } - - clock_class = g_ptr_array_index(cc_prio_map->entries, index); - bt_get(clock_class); - -end: - return clock_class; + BT_ASSERT_PRE_NON_NULL(cc_prio_map, "Clock class priority map"); + BT_ASSERT_PRE(index < cc_prio_map->entries->len, + "Index is out of bounds: index=%" PRIu64 ", count=%" PRIu64, + index, cc_prio_map->entries->len); + return bt_get(g_ptr_array_index(cc_prio_map->entries, index)); } struct bt_clock_class *bt_clock_class_priority_map_get_clock_class_by_name( @@ -146,15 +121,8 @@ struct bt_clock_class *bt_clock_class_priority_map_get_clock_class_by_name( size_t i; struct bt_clock_class *clock_class = NULL; - if (!cc_prio_map) { - BT_LOGW_STR("Invalid parameter: clock class priority map is NULL."); - goto end; - } - - if (!name) { - BT_LOGW_STR("Invalid parameter: name is NULL."); - goto end; - } + BT_ASSERT_PRE_NON_NULL(cc_prio_map, "Clock class priority map"); + BT_ASSERT_PRE_NON_NULL(name, "Name"); for (i = 0; i < cc_prio_map->entries->len; i++) { struct bt_clock_class *cur_cc = @@ -162,7 +130,7 @@ struct bt_clock_class *bt_clock_class_priority_map_get_clock_class_by_name( const char *cur_cc_name = bt_clock_class_get_name(cur_cc); - assert(cur_cc_name); + BT_ASSERT(cur_cc_name); if (strcmp(cur_cc_name, name) == 0) { clock_class = bt_get(cur_cc); @@ -211,17 +179,8 @@ struct bt_clock_class * bt_clock_class_priority_map_get_highest_priority_clock_class( struct bt_clock_class_priority_map *cc_prio_map) { - struct bt_clock_class *clock_class = NULL; - - if (!cc_prio_map) { - BT_LOGW_STR("Invalid parameter: clock class priority map is NULL."); - goto end; - } - - clock_class = bt_get(cc_prio_map->highest_prio_cc); - -end: - return clock_class; + BT_ASSERT_PRE_NON_NULL(cc_prio_map, "Clock class priority map"); + return(bt_get(cc_prio_map->highest_prio_cc)); } int bt_clock_class_priority_map_get_clock_class_priority( @@ -231,24 +190,9 @@ int bt_clock_class_priority_map_get_clock_class_priority( int ret = 0; uint64_t *prio; - if (!cc_prio_map) { - BT_LOGW_STR("Invalid parameter: clock class priority map is NULL."); - ret = -1; - goto end; - } - - if (!clock_class) { - BT_LOGW_STR("Invalid parameter: clock class is NULL."); - ret = -1; - goto end; - } - - if (!priority) { - BT_LOGW_STR("Invalid parameter: priority is NULL."); - ret = -1; - goto end; - } - + BT_ASSERT_PRE_NON_NULL(cc_prio_map, "Clock class priority map"); + BT_ASSERT_PRE_NON_NULL(clock_class, "Clock class"); + BT_ASSERT_PRE_NON_NULL(priority, "Priority"); prio = g_hash_table_lookup(cc_prio_map->prios, clock_class); if (!prio) { BT_LOGV("Clock class does not exist in clock class priority map: " @@ -276,24 +220,9 @@ int bt_clock_class_priority_map_add_clock_class( // FIXME when available: check // bt_clock_class_is_valid(clock_class) - if (!cc_prio_map) { - BT_LOGW_STR("Invalid parameter: clock class priority map is NULL."); - ret = -1; - goto end; - } - - if (!clock_class) { - BT_LOGW_STR("Invalid parameter: clock class is NULL."); - ret = -1; - goto end; - } - - if (cc_prio_map->frozen) { - BT_LOGW("Invalid parameter: clock class priority map is frozen: " - "addr=%p", cc_prio_map); - ret = -1; - goto end; - } + BT_ASSERT_PRE_NON_NULL(cc_prio_map, "Clock class priority map"); + BT_ASSERT_PRE_NON_NULL(clock_class, "Clock class"); + BT_ASSERT_PRE_HOT(cc_prio_map, "Clock class priority map", ""); /* Check for existing clock class */ prio_ptr = g_hash_table_lookup(cc_prio_map->prios, clock_class); @@ -319,7 +248,7 @@ int bt_clock_class_priority_map_add_clock_class( set_highest_prio: cc_prio = bt_clock_class_priority_map_current_highest_prio( cc_prio_map); - assert(cc_prio.clock_class); + BT_ASSERT(cc_prio.clock_class); cc_prio_map->highest_prio_cc = cc_prio.clock_class; BT_LOGV("Added clock class to clock class priority map: " "cc-prio-map-addr=%p, added-clock-class-addr=%p, " @@ -345,7 +274,7 @@ struct bt_clock_class_priority_map *bt_clock_class_priority_map_copy( cc_prio_map = bt_clock_class_priority_map_create(); if (!cc_prio_map) { - BT_LOGW_STR("Invalid parameter: clock class priority map is NULL."); + BT_LOGE_STR("Cannot create empty clock class priority map."); goto error; } diff --git a/lib/graph/component-class-sink-colander.c b/lib/graph/component-class-sink-colander.c index 25176ea3..d284ba4b 100644 --- a/lib/graph/component-class-sink-colander.c +++ b/lib/graph/component-class-sink-colander.c @@ -31,8 +31,8 @@ #include #include #include +#include #include -#include static struct bt_component_class *colander_comp_cls; @@ -134,8 +134,8 @@ void colander_port_connected(struct bt_private_component *priv_comp, struct colander_data *colander_data = bt_private_component_get_user_data(priv_comp); - assert(priv_conn); - assert(colander_data); + BT_ASSERT(priv_conn); + BT_ASSERT(colander_data); BT_PUT(colander_data->notif_iter); conn_status = bt_private_connection_create_notification_iterator( priv_conn, colander_data->notif_types, @@ -160,7 +160,7 @@ enum bt_component_status colander_consume( struct colander_data *colander_data = bt_private_component_get_user_data(priv_comp); - assert(colander_data); + BT_ASSERT(colander_data); if (!colander_data->notif_iter) { BT_LOGW("Trying to consume without an upstream notification iterator: " @@ -189,7 +189,7 @@ enum bt_component_status colander_consume( notif = bt_notification_iterator_get_notification( colander_data->notif_iter); - assert(notif); + BT_ASSERT(notif); end: /* Move notification to user's pointer, even if NULL. */ diff --git a/lib/graph/component-class.c b/lib/graph/component-class.c index 2e7b3c9c..1df85b48 100644 --- a/lib/graph/component-class.c +++ b/lib/graph/component-class.c @@ -33,6 +33,7 @@ #include #include #include +#include #include static @@ -41,7 +42,7 @@ void bt_component_class_destroy(struct bt_object *obj) struct bt_component_class *class; int i; - assert(obj); + BT_ASSERT(obj); class = container_of(obj, struct bt_component_class, base); BT_LOGD("Destroying component class: " @@ -824,8 +825,8 @@ void bt_component_class_add_destroy_listener(struct bt_component_class *class, { struct bt_component_class_destroy_listener listener; - assert(class); - assert(func); + BT_ASSERT(class); + BT_ASSERT(func); listener.func = func; listener.data = data; g_array_append_val(class->destroy_listeners, listener); diff --git a/lib/graph/component.c b/lib/graph/component.c index 42ba13f4..1c83b4b3 100644 --- a/lib/graph/component.c +++ b/lib/graph/component.c @@ -47,6 +47,7 @@ #include #include #include +#include #include #include @@ -185,7 +186,7 @@ struct bt_port *bt_component_add_port( struct bt_port *port = g_ptr_array_index(ports, i); port_name = bt_port_get_name(port); - assert(port_name); + BT_ASSERT(port_name); if (!strcmp(name, port_name)) { /* Port name clash, abort. */ @@ -230,14 +231,14 @@ end: BT_HIDDEN int64_t bt_component_get_input_port_count(struct bt_component *comp) { - assert(comp); + BT_ASSERT(comp); return (int64_t) comp->input_ports->len; } BT_HIDDEN int64_t bt_component_get_output_port_count(struct bt_component *comp) { - assert(comp); + BT_ASSERT(comp); return (int64_t) comp->output_ports->len; } @@ -250,9 +251,9 @@ enum bt_component_status bt_component_create( struct bt_component *component = NULL; enum bt_component_class_type type; - assert(user_component); - assert(component_class); - assert(name); + BT_ASSERT(user_component); + BT_ASSERT(component_class); + BT_ASSERT(name); type = bt_component_class_get_type(component_class); BT_LOGD("Creating empty component from component class: " @@ -383,7 +384,7 @@ struct bt_port *bt_component_get_port_by_name(GPtrArray *ports, size_t i; struct bt_port *ret_port = NULL; - assert(name); + BT_ASSERT(name); for (i = 0; i < ports->len; i++) { struct bt_port *port = g_ptr_array_index(ports, i); @@ -406,7 +407,7 @@ BT_HIDDEN struct bt_port *bt_component_get_input_port_by_name(struct bt_component *comp, const char *name) { - assert(comp); + BT_ASSERT(comp); return bt_component_get_port_by_name(comp->input_ports, name); } @@ -415,7 +416,7 @@ BT_HIDDEN struct bt_port *bt_component_get_output_port_by_name(struct bt_component *comp, const char *name) { - assert(comp); + BT_ASSERT(comp); return bt_component_get_port_by_name(comp->output_ports, name); } @@ -441,7 +442,7 @@ BT_HIDDEN struct bt_port *bt_component_get_input_port_by_index(struct bt_component *comp, uint64_t index) { - assert(comp); + BT_ASSERT(comp); return bt_component_get_port_by_index(comp->input_ports, index); } @@ -450,7 +451,7 @@ BT_HIDDEN struct bt_port *bt_component_get_output_port_by_index(struct bt_component *comp, uint64_t index) { - assert(comp); + BT_ASSERT(comp); return bt_component_get_port_by_index(comp->output_ports, index); } @@ -482,8 +483,8 @@ void bt_component_remove_port_by_index(struct bt_component *component, struct bt_port *port; struct bt_graph *graph; - assert(ports); - assert(index < ports->len); + BT_ASSERT(ports); + BT_ASSERT(index < ports->len); port = g_ptr_array_index(ports, index); BT_LOGD("Removing port from component: " @@ -545,7 +546,7 @@ enum bt_component_status bt_component_remove_port( ports = component->output_ports; } - assert(ports); + BT_ASSERT(ports); for (i = 0; i < ports->len; i++) { struct bt_port *cur_port = g_ptr_array_index(ports, i); @@ -575,9 +576,9 @@ enum bt_component_status bt_component_accept_port_connection( { enum bt_component_status status = BT_COMPONENT_STATUS_OK; - assert(comp); - assert(self_port); - assert(other_port); + BT_ASSERT(comp); + BT_ASSERT(self_port); + BT_ASSERT(other_port); if (comp->class->methods.accept_port_connection) { BT_LOGD("Calling user's \"accept port connection\" method: " @@ -602,9 +603,9 @@ BT_HIDDEN void bt_component_port_connected(struct bt_component *comp, struct bt_port *self_port, struct bt_port *other_port) { - assert(comp); - assert(self_port); - assert(other_port); + BT_ASSERT(comp); + BT_ASSERT(self_port); + BT_ASSERT(other_port); if (comp->class->methods.port_connected) { BT_LOGD("Calling user's \"port connected\" method: " @@ -624,8 +625,8 @@ BT_HIDDEN void bt_component_port_disconnected(struct bt_component *comp, struct bt_port *port) { - assert(comp); - assert(port); + BT_ASSERT(comp); + BT_ASSERT(port); if (comp->class->methods.port_disconnected) { BT_LOGD("Calling user's \"port disconnected\" method: " @@ -645,8 +646,8 @@ void bt_component_add_destroy_listener(struct bt_component *component, { struct bt_component_destroy_listener listener; - assert(component); - assert(func); + BT_ASSERT(component); + BT_ASSERT(func); listener.func = func; listener.data = data; g_array_append_val(component->destroy_listeners, listener); @@ -663,8 +664,8 @@ void bt_component_remove_destroy_listener(struct bt_component *component, { size_t i; - assert(component); - assert(func); + BT_ASSERT(component); + BT_ASSERT(func); for (i = 0; i < component->destroy_listeners->len; i++) { struct bt_component_destroy_listener *listener = diff --git a/lib/graph/connection.c b/lib/graph/connection.c index 6c41f4c9..93c101e6 100644 --- a/lib/graph/connection.c +++ b/lib/graph/connection.c @@ -39,6 +39,7 @@ #include #include #include +#include #include #include @@ -223,7 +224,7 @@ void bt_connection_end(struct bt_connection *conn, bt_component_port_disconnected(upstream_comp, upstream_port); } - assert(graph); + BT_ASSERT(graph); /* bt_graph_notify_ports_disconnected() logs details */ bt_graph_notify_ports_disconnected(graph, upstream_comp, downstream_comp, upstream_port, downstream_port); @@ -331,9 +332,9 @@ bt_private_connection_create_notification_iterator( } upstream_port = connection->upstream_port; - assert(upstream_port); + BT_ASSERT(upstream_port); upstream_component = bt_port_get_component(upstream_port); - assert(upstream_component); + BT_ASSERT(upstream_component); upstream_comp_class = upstream_component->class; BT_LOGD("Creating notification iterator from connection: " "conn-addr=%p, upstream-port-addr=%p, " @@ -344,7 +345,7 @@ bt_private_connection_create_notification_iterator( upstream_component, bt_component_get_name(upstream_component)); upstream_comp_class_type = bt_component_get_class_type(upstream_component); - assert(upstream_comp_class_type == BT_COMPONENT_CLASS_TYPE_SOURCE || + BT_ASSERT(upstream_comp_class_type == BT_COMPONENT_CLASS_TYPE_SOURCE || upstream_comp_class_type == BT_COMPONENT_CLASS_TYPE_FILTER); status = bt_private_connection_notification_iterator_create(upstream_component, upstream_port, notification_types, connection, &iterator); diff --git a/lib/graph/graph.c b/lib/graph/graph.c index c62712cc..c7c27058 100644 --- a/lib/graph/graph.c +++ b/lib/graph/graph.c @@ -39,6 +39,8 @@ #include #include #include +#include +#include #include #include @@ -53,7 +55,7 @@ int init_listeners_array(GArray **listeners) { int ret = 0; - assert(listeners); + BT_ASSERT(listeners); *listeners = g_array_new(FALSE, TRUE, sizeof(struct bt_graph_listener)); if (!*listeners) { BT_LOGE_STR("Failed to allocate one GArray."); @@ -423,7 +425,7 @@ enum bt_graph_status consume_graph_sink(struct bt_component *sink) enum bt_graph_status status = BT_GRAPH_STATUS_OK; enum bt_component_status comp_status; - assert(sink); + BT_ASSERT(sink); comp_status = bt_component_sink_consume(sink); BT_LOGV("Consumed from sink: addr=%p, name=\"%s\", status=%s", sink, bt_component_get_name(sink), @@ -494,7 +496,7 @@ enum bt_graph_status bt_graph_consume_sink_no_check(struct bt_graph *graph, "comp-addr=%p, comp-name=\"%s\"", graph, sink, bt_component_get_name(sink)); - assert(bt_component_borrow_graph(sink) == graph); + BT_ASSERT(bt_component_borrow_graph(sink) == graph); if (g_queue_is_empty(graph->sinks_to_consume)) { BT_LOGV_STR("Graph's sink queue is empty: end of graph."); @@ -510,7 +512,7 @@ enum bt_graph_status bt_graph_consume_sink_no_check(struct bt_graph *graph, } sink_node = g_queue_pop_nth_link(graph->sinks_to_consume, index); - assert(sink_node); + BT_ASSERT(sink_node); status = consume_sink_node(graph, sink_node); end: @@ -525,12 +527,8 @@ enum bt_graph_status bt_graph_consume_no_check(struct bt_graph *graph) GList *current_node; BT_LOGV("Making next sink consume: addr=%p", graph); - - if (!graph->has_sink) { - BT_LOGW_STR("Graph has no sink component."); - status = BT_GRAPH_STATUS_NO_SINK; - goto end; - } + BT_ASSERT_PRE(graph->has_sink, + "Graph has no sink component: %!+g", graph); if (g_queue_is_empty(graph->sinks_to_consume)) { BT_LOGV_STR("Graph's sink queue is empty: end of graph."); @@ -550,33 +548,16 @@ end: enum bt_graph_status bt_graph_consume(struct bt_graph *graph) { - enum bt_graph_status status = BT_GRAPH_STATUS_OK; - - if (!graph) { - BT_LOGW_STR("Invalid parameter: graph is NULL."); - status = BT_GRAPH_STATUS_INVALID; - goto end; - } - - if (graph->canceled) { - BT_LOGW("Invalid parameter: graph is canceled: " - "graph-addr=%p", graph); - status = BT_GRAPH_STATUS_CANCELED; - goto end; - } - - if (!graph->can_consume) { - BT_LOGW_STR("Cannot consume graph in its current state."); - status = BT_GRAPH_STATUS_CANNOT_CONSUME; - goto end; - } + enum bt_graph_status status; + BT_ASSERT_PRE_NON_NULL(graph, "Graph"); + BT_ASSERT_PRE(!graph->canceled, "Graph is canceled: %!+g", graph); + BT_ASSERT_PRE(graph->can_consume, + "Cannot consume graph in its current state: %!+g", graph); graph->can_consume = BT_FALSE; status = bt_graph_consume_no_check(graph); graph->can_consume = BT_TRUE; - -end: - return status; + return BT_GRAPH_STATUS_OK; } enum bt_graph_status bt_graph_run(struct bt_graph *graph) @@ -824,7 +805,7 @@ void bt_graph_notify_port_added(struct bt_graph *graph, struct bt_port *port) struct bt_graph_listener, i); bt_graph_port_added_listener func = listener.func; - assert(func); + BT_ASSERT(func); func(port, listener.data); } } @@ -845,7 +826,7 @@ void bt_graph_notify_port_removed(struct bt_graph *graph, struct bt_graph_listener, i); bt_graph_port_removed_listener func = listener.func; - assert(func); + BT_ASSERT(func); func(comp, port, listener.data); } } @@ -869,7 +850,7 @@ void bt_graph_notify_ports_connected(struct bt_graph *graph, struct bt_graph_listener, i); bt_graph_ports_connected_listener func = listener.func; - assert(func); + BT_ASSERT(func); func(upstream_port, downstream_port, listener.data); } } @@ -895,7 +876,7 @@ void bt_graph_notify_ports_disconnected(struct bt_graph *graph, struct bt_graph_listener, i); bt_graph_ports_disconnected_listener func = listener.func; - assert(func); + BT_ASSERT(func); func(upstream_comp, downstream_comp, upstream_port, downstream_port, listener.data); } @@ -937,8 +918,8 @@ BT_HIDDEN void bt_graph_remove_connection(struct bt_graph *graph, struct bt_connection *connection) { - assert(graph); - assert(connection); + BT_ASSERT(graph); + BT_ASSERT(connection); BT_LOGV("Removing graph's connection: graph-addr=%p, conn-addr=%p", graph, connection); g_ptr_array_remove(graph->connections, connection); @@ -1132,10 +1113,10 @@ int bt_graph_remove_unconnected_component(struct bt_graph *graph, uint64_t i; int ret = 0; - assert(graph); - assert(component); - assert(component->base.ref_count.count == 0); - assert(bt_component_borrow_graph(component) == graph); + BT_ASSERT(graph); + BT_ASSERT(component); + BT_ASSERT(component->base.ref_count.count == 0); + BT_ASSERT(bt_component_borrow_graph(component) == graph); init_can_consume = graph->can_consume; count = bt_component_get_input_port_count(component); @@ -1144,7 +1125,7 @@ int bt_graph_remove_unconnected_component(struct bt_graph *graph, struct bt_port *port = bt_component_get_input_port_by_index(component, i); - assert(port); + BT_ASSERT(port); bt_put(port); if (bt_port_is_connected(port)) { @@ -1166,7 +1147,7 @@ int bt_graph_remove_unconnected_component(struct bt_graph *graph, struct bt_port *port = bt_component_get_output_port_by_index(component, i); - assert(port); + BT_ASSERT(port); bt_put(port); if (bt_port_is_connected(port)) { diff --git a/lib/graph/iterator.c b/lib/graph/iterator.c index c5a00d62..0cd93172 100644 --- a/lib/graph/iterator.c +++ b/lib/graph/iterator.c @@ -57,6 +57,7 @@ #include #include #include +#include #include #include #include @@ -155,7 +156,7 @@ void destroy_stream_state(struct stream_state *stream_state) static void destroy_action(struct action *action) { - assert(action); + BT_ASSERT(action); switch (action->type) { case ACTION_TYPE_PUSH_NOTIF: @@ -376,7 +377,7 @@ void bt_private_connection_notification_iterator_destroy(struct bt_object *obj) { struct bt_notification_iterator_private_connection *iterator; - assert(obj); + BT_ASSERT(obj); /* * The notification iterator's reference count is 0 if we're @@ -419,7 +420,7 @@ void bt_private_connection_notification_iterator_destroy(struct bt_object *obj) g_hash_table_iter_init(&ht_iter, iterator->stream_states); while (g_hash_table_iter_next(&ht_iter, &stream_gptr, &stream_state_gptr)) { - assert(stream_gptr); + BT_ASSERT(stream_gptr); BT_LOGD_STR("Removing stream's destroy listener for notification iterator."); bt_stream_remove_destroy_listener( @@ -454,7 +455,7 @@ void bt_private_connection_notification_iterator_finalize( bt_component_class_notification_iterator_finalize_method finalize_method = NULL; - assert(iterator); + BT_ASSERT(iterator); switch (iterator->state) { case BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_STATE_NON_INITIALIZED: @@ -484,7 +485,7 @@ void bt_private_connection_notification_iterator_finalize( iterator->state = BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_STATE_FINALIZED; } - assert(iterator->upstream_component); + BT_ASSERT(iterator->upstream_component); comp_class = iterator->upstream_component->class; /* Call user-defined destroy method */ @@ -527,7 +528,7 @@ void bt_private_connection_notification_iterator_set_connection( struct bt_notification_iterator_private_connection *iterator, struct bt_connection *connection) { - assert(iterator); + BT_ASSERT(iterator); iterator->connection = connection; BT_LOGV("Set notification iterator's connection: " "iter-addr=%p, conn-addr=%p", iterator, connection); @@ -541,7 +542,7 @@ int create_subscription_mask_from_notification_types( const enum bt_notification_type *notif_type; int ret = 0; - assert(notif_types); + BT_ASSERT(notif_types); iterator->subscription_mask = 0; for (notif_type = notif_types; @@ -619,11 +620,11 @@ enum bt_connection_status bt_private_connection_notification_iterator_create( enum bt_component_class_type type; struct bt_notification_iterator_private_connection *iterator = NULL; - assert(upstream_comp); - assert(upstream_port); - assert(notification_types); - assert(bt_port_is_connected(upstream_port)); - assert(user_iterator); + BT_ASSERT(upstream_comp); + BT_ASSERT(upstream_port); + BT_ASSERT(notification_types); + BT_ASSERT(bt_port_is_connected(upstream_port)); + BT_ASSERT(user_iterator); BT_LOGD("Creating notification iterator on private connection: " "upstream-comp-addr=%p, upstream-comp-name=\"%s\", " "upstream-port-addr=%p, upstream-port-name=\"%s\", " @@ -632,7 +633,7 @@ enum bt_connection_status bt_private_connection_notification_iterator_create( upstream_port, bt_port_get_name(upstream_port), connection); type = bt_component_get_class_type(upstream_comp); - assert(type == BT_COMPONENT_CLASS_TYPE_SOURCE || + BT_ASSERT(type == BT_COMPONENT_CLASS_TYPE_SOURCE || type == BT_COMPONENT_CLASS_TYPE_FILTER); iterator = g_new0(struct bt_notification_iterator_private_connection, 1); if (!iterator) { @@ -795,7 +796,7 @@ bt_bool validate_notification( struct stream_state *stream_state; struct bt_port *stream_comp_cur_port; - assert(notif_stream); + BT_ASSERT(notif_stream); stream_comp_cur_port = bt_stream_port_for_component(notif_stream, iterator->upstream_component); @@ -925,7 +926,7 @@ void add_action_push_notif( .type = ACTION_TYPE_PUSH_NOTIF, }; - assert(notif); + BT_ASSERT(notif); if (!is_subscribed_to_notification_type(iterator, notif->type)) { return; @@ -952,7 +953,7 @@ int add_action_push_notif_stream_begin( goto end; } - assert(stream); + BT_ASSERT(stream); stream_begin_notif = bt_notification_stream_begin_create(stream); if (!stream_begin_notif) { BT_LOGE_STR("Cannot create stream beginning notification."); @@ -989,7 +990,7 @@ int add_action_push_notif_stream_end( goto end; } - assert(stream); + BT_ASSERT(stream); stream_end_notif = bt_notification_stream_end_create(stream); if (!stream_end_notif) { BT_LOGE_STR("Cannot create stream end notification."); @@ -1026,7 +1027,7 @@ int add_action_push_notif_packet_begin( goto end; } - assert(packet); + BT_ASSERT(packet); packet_begin_notif = bt_notification_packet_begin_create(packet); if (!packet_begin_notif) { BT_LOGE_STR("Cannot create packet beginning notification."); @@ -1062,7 +1063,7 @@ int add_action_push_notif_packet_end( goto end; } - assert(packet); + BT_ASSERT(packet); packet_end_notif = bt_notification_packet_end_create(packet); if (!packet_end_notif) { BT_LOGE_STR("Cannot create packet end notification."); @@ -1094,7 +1095,7 @@ void add_action_set_stream_state_is_ended( }, }; - assert(stream_state); + BT_ASSERT(stream_state); add_action(iterator, &action); BT_LOGV("Added \"set stream state's ended\" action: " "stream-state-addr=%p", stream_state); @@ -1114,7 +1115,7 @@ void add_action_set_stream_state_cur_packet( }, }; - assert(stream_state); + BT_ASSERT(stream_state); add_action(iterator, &action); BT_LOGV("Added \"set stream state's current packet\" action: " "stream-state-addr=%p, packet-addr=%p", @@ -1138,8 +1139,8 @@ void add_action_update_stream_state_discarded_elements( }, }; - assert(stream_state); - assert(type == ACTION_TYPE_UPDATE_STREAM_STATE_DISCARDED_PACKETS || + BT_ASSERT(stream_state); + BT_ASSERT(type == ACTION_TYPE_UPDATE_STREAM_STATE_DISCARDED_PACKETS || type == ACTION_TYPE_UPDATE_STREAM_STATE_DISCARDED_EVENTS); add_action(iterator, &action); if (type == ACTION_TYPE_UPDATE_STREAM_STATE_DISCARDED_PACKETS) { @@ -1243,7 +1244,7 @@ struct bt_field *get_struct_field_uint(struct bt_field *struct_field, } ft = bt_field_get_type(field); - assert(ft); + BT_ASSERT(ft); if (bt_field_type_integer_is_signed(ft)) { BT_LOGV("Skipping `%s` integer field because its type is signed: " @@ -1278,7 +1279,7 @@ uint64_t get_packet_context_events_discarded(struct bt_packet *packet) goto end; } - assert(bt_field_is_integer(field)); + BT_ASSERT(bt_field_is_integer(field)); ret = bt_field_unsigned_integer_get_value(field, &retval); if (ret) { BT_LOGV("Cannot get raw value of packet's context field's `events_discarded` integer field: " @@ -1315,7 +1316,7 @@ uint64_t get_packet_context_packet_seq_num(struct bt_packet *packet) goto end; } - assert(bt_field_is_integer(field)); + BT_ASSERT(bt_field_is_integer(field)); ret = bt_field_unsigned_integer_get_value(field, &retval); if (ret) { BT_LOGV("Cannot get raw value of packet's context field's `packet_seq_num` integer field: " @@ -1485,7 +1486,7 @@ int get_field_clock_value(struct bt_field *root_field, } ft = bt_field_get_type(field); - assert(ft); + BT_ASSERT(ft); clock_class = bt_field_type_integer_get_mapped_clock_class(ft); if (!clock_class) { BT_LOGW("Integer field type has no mapped clock class but it's expected to have one: " @@ -1677,8 +1678,8 @@ int handle_notif_stream_begin( int ret = 0; struct stream_state *stream_state; - assert(notif->type == BT_NOTIFICATION_TYPE_STREAM_BEGIN); - assert(notif_stream); + BT_ASSERT(notif->type == BT_NOTIFICATION_TYPE_STREAM_BEGIN); + BT_ASSERT(notif_stream); ret = ensure_stream_state_exists(iterator, notif, notif_stream, &stream_state); if (ret) { @@ -1704,8 +1705,8 @@ int handle_notif_stream_end( int ret = 0; struct stream_state *stream_state; - assert(notif->type == BT_NOTIFICATION_TYPE_STREAM_END); - assert(notif_stream); + BT_ASSERT(notif->type == BT_NOTIFICATION_TYPE_STREAM_END); + BT_ASSERT(notif_stream); ret = ensure_stream_state_exists(iterator, NULL, notif_stream, &stream_state); if (ret) { @@ -1739,9 +1740,9 @@ int handle_notif_discarded_elements( int ret = 0; struct stream_state *stream_state; - assert(notif->type == BT_NOTIFICATION_TYPE_DISCARDED_EVENTS || + BT_ASSERT(notif->type == BT_NOTIFICATION_TYPE_DISCARDED_EVENTS || notif->type == BT_NOTIFICATION_TYPE_DISCARDED_PACKETS); - assert(notif_stream); + BT_ASSERT(notif_stream); ret = ensure_stream_state_exists(iterator, NULL, notif_stream, &stream_state); if (ret) { @@ -1769,8 +1770,8 @@ int handle_notif_packet_begin( int ret = 0; struct stream_state *stream_state; - assert(notif->type == BT_NOTIFICATION_TYPE_PACKET_BEGIN); - assert(notif_packet); + BT_ASSERT(notif->type == BT_NOTIFICATION_TYPE_PACKET_BEGIN); + BT_ASSERT(notif_packet); ret = ensure_stream_state_exists(iterator, NULL, notif_stream, &stream_state); if (ret) { @@ -1803,8 +1804,8 @@ int handle_notif_packet_end( int ret = 0; struct stream_state *stream_state; - assert(notif->type == BT_NOTIFICATION_TYPE_PACKET_END); - assert(notif_packet); + BT_ASSERT(notif->type == BT_NOTIFICATION_TYPE_PACKET_END); + BT_ASSERT(notif_packet); ret = ensure_stream_state_exists(iterator, NULL, notif_stream, &stream_state); if (ret) { @@ -1840,8 +1841,8 @@ int handle_notif_event( int ret = 0; struct stream_state *stream_state; - assert(notif->type == BT_NOTIFICATION_TYPE_EVENT); - assert(notif_packet); + BT_ASSERT(notif->type == BT_NOTIFICATION_TYPE_EVENT); + BT_ASSERT(notif_packet); ret = ensure_stream_state_exists(iterator, NULL, notif_stream, &stream_state); if (ret) { @@ -1875,7 +1876,7 @@ int enqueue_notification_and_automatic( struct bt_stream *notif_stream = NULL; struct bt_packet *notif_packet = NULL; - assert(notif); + BT_ASSERT(notif); BT_LOGV("Enqueuing user notification and automatic notifications: " "iter-addr=%p, notif-addr=%p", iterator, notif); @@ -1887,27 +1888,27 @@ int enqueue_notification_and_automatic( switch (notif->type) { case BT_NOTIFICATION_TYPE_EVENT: notif_event = bt_notification_event_borrow_event(notif); - assert(notif_event); + BT_ASSERT(notif_event); notif_packet = bt_event_borrow_packet(notif_event); - assert(notif_packet); + BT_ASSERT(notif_packet); break; case BT_NOTIFICATION_TYPE_STREAM_BEGIN: notif_stream = bt_notification_stream_begin_borrow_stream(notif); - assert(notif_stream); + BT_ASSERT(notif_stream); break; case BT_NOTIFICATION_TYPE_STREAM_END: notif_stream = bt_notification_stream_end_borrow_stream(notif); - assert(notif_stream); + BT_ASSERT(notif_stream); break; case BT_NOTIFICATION_TYPE_PACKET_BEGIN: notif_packet = bt_notification_packet_begin_borrow_packet(notif); - assert(notif_packet); + BT_ASSERT(notif_packet); break; case BT_NOTIFICATION_TYPE_PACKET_END: notif_packet = bt_notification_packet_end_borrow_packet(notif); - assert(notif_packet); + BT_ASSERT(notif_packet); break; case BT_NOTIFICATION_TYPE_INACTIVITY: /* Always valid */ @@ -1926,7 +1927,7 @@ int enqueue_notification_and_automatic( if (notif_packet) { notif_stream = bt_packet_borrow_stream(notif_packet); - assert(notif_stream); + BT_ASSERT(notif_stream); } if (!notif_stream) { @@ -2012,7 +2013,7 @@ int handle_end(struct bt_notification_iterator_private_connection *iterator) &stream_state_gptr)) { struct stream_state *stream_state = stream_state_gptr; - assert(stream_state_gptr); + BT_ASSERT(stream_state_gptr); if (stream_state->is_ended) { continue; @@ -2059,7 +2060,7 @@ enum bt_notification_iterator_status ensure_queue_has_notifications( BT_NOTIFICATION_ITERATOR_STATUS_OK; int ret; - assert(iterator); + BT_ASSERT(iterator); BT_LOGD("Ensuring that notification iterator's queue has at least one notification: " "iter-addr=%p, queue-size=%u, iter-state=%s", iterator, iterator->queue->length, @@ -2091,8 +2092,8 @@ enum bt_notification_iterator_status ensure_queue_has_notifications( break; } - assert(iterator->upstream_component); - assert(iterator->upstream_component->class); + BT_ASSERT(iterator->upstream_component); + BT_ASSERT(iterator->upstream_component->class); /* Pick the appropriate "next" method */ switch (iterator->upstream_component->class->type) { @@ -2102,7 +2103,7 @@ enum bt_notification_iterator_status ensure_queue_has_notifications( container_of(iterator->upstream_component->class, struct bt_component_class_source, parent); - assert(source_class->methods.iterator.next); + BT_ASSERT(source_class->methods.iterator.next); next_method = source_class->methods.iterator.next; break; } @@ -2112,7 +2113,7 @@ enum bt_notification_iterator_status ensure_queue_has_notifications( container_of(iterator->upstream_component->class, struct bt_component_class_filter, parent); - assert(filter_class->methods.iterator.next); + BT_ASSERT(filter_class->methods.iterator.next); next_method = filter_class->methods.iterator.next; break; } @@ -2124,7 +2125,7 @@ enum bt_notification_iterator_status ensure_queue_has_notifications( * Call the user's "next" method to get the next notification * and status. */ - assert(next_method); + BT_ASSERT(next_method); while (iterator->queue->length == 0) { BT_LOGD_STR("Calling user's \"next\" method."); @@ -2172,7 +2173,7 @@ enum bt_notification_iterator_status ensure_queue_has_notifications( goto end; } - assert(iterator->state == + BT_ASSERT(iterator->state == BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_STATE_ACTIVE); iterator->state = BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_STATE_ENDED; @@ -2267,7 +2268,7 @@ bt_notification_iterator_next(struct bt_notification_iterator *iterator) * Move the notification at the tail of the queue to the * iterator's current notification. */ - assert(priv_conn_iter->queue->length > 0); + BT_ASSERT(priv_conn_iter->queue->length > 0); notif = g_queue_pop_tail(priv_conn_iter->queue); bt_notification_iterator_replace_current_notification( iterator, notif); @@ -2314,7 +2315,7 @@ bt_notification_iterator_next(struct bt_notification_iterator *iterator) break; case BT_GRAPH_STATUS_OK: status = BT_NOTIFICATION_ITERATOR_STATUS_OK; - assert(bt_notification_iterator_borrow_current_notification(iterator)); + BT_ASSERT(bt_notification_iterator_borrow_current_notification(iterator)); break; default: /* Other errors */ @@ -2424,7 +2425,7 @@ struct bt_notification_iterator *bt_output_port_notification_iterator_create( } graph = bt_component_get_graph(output_port_comp); - assert(graph); + BT_ASSERT(graph); /* Create notification iterator */ BT_LOGD("Creating notification iterator on output port: " @@ -2471,7 +2472,7 @@ struct bt_notification_iterator *bt_output_port_notification_iterator_create( */ colander_in_port = bt_component_sink_get_input_port_by_index( iterator->colander, 0); - assert(colander_in_port); + BT_ASSERT(colander_in_port); graph_status = bt_graph_connect_ports(iterator->graph, output_port, colander_in_port, NULL); if (graph_status != BT_GRAPH_STATUS_OK) { @@ -2514,7 +2515,7 @@ error: */ ret = bt_graph_remove_unconnected_component(iterator->graph, colander_comp); - assert(ret == 0); + BT_ASSERT(ret == 0); } BT_PUT(iterator); diff --git a/lib/graph/notification/discarded-elements.c b/lib/graph/notification/discarded-elements.c index f1369131..3154fee3 100644 --- a/lib/graph/notification/discarded-elements.c +++ b/lib/graph/notification/discarded-elements.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -61,10 +62,7 @@ struct bt_notification *bt_notification_discarded_elements_create( struct bt_notification_discarded_elements *notification; struct bt_notification *ret_notif = NULL; - if (!stream) { - BT_LOGW_STR("Invalid parameter: stream is NULL."); - } - + BT_ASSERT_PRE_NON_NULL(stream, "Stream"); BT_LOGD("Creating discarded elements notification object: " "type=%s, stream-addr=%p, stream-name=\"%s\", " "begin-clock-value-addr=%p, end-clock-value-addr=%p, " @@ -107,29 +105,13 @@ bt_notification_discarded_elements_get_begin_clock_value( enum bt_notification_type type, struct bt_notification *notification) { - struct bt_clock_value *clock_value = NULL; struct bt_notification_discarded_elements *discarded_elems_notif; - if (!notification) { - BT_LOGW_STR("Invalid parameter: notification is NULL."); - goto end; - } - - if (bt_notification_get_type(notification) != type) { - BT_LOGW("Invalid parameter: notification has not the expected type: " - "addr%p, expected-type=%s, notif-type=%s", - notification, bt_notification_type_string(type), - bt_notification_type_string( - bt_notification_get_type(notification))); - goto end; - } - + BT_ASSERT_PRE_NON_NULL(notification, "Notification"); + BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, type); discarded_elems_notif = container_of(notification, struct bt_notification_discarded_elements, parent); - clock_value = bt_get(discarded_elems_notif->begin_clock_value); - -end: - return clock_value; + return bt_get(discarded_elems_notif->begin_clock_value); } BT_HIDDEN @@ -138,29 +120,13 @@ bt_notification_discarded_elements_get_end_clock_value( enum bt_notification_type type, struct bt_notification *notification) { - struct bt_clock_value *clock_value = NULL; struct bt_notification_discarded_elements *discarded_elems_notif; - if (!notification) { - BT_LOGW_STR("Invalid parameter: notification is NULL."); - goto end; - } - - if (bt_notification_get_type(notification) != type) { - BT_LOGW("Invalid parameter: notification has not the expected type: " - "addr%p, expected-type=%s, notif-type=%s", - notification, bt_notification_type_string(type), - bt_notification_type_string( - bt_notification_get_type(notification))); - goto end; - } - + BT_ASSERT_PRE_NON_NULL(notification, "Notification"); + BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, type); discarded_elems_notif = container_of(notification, struct bt_notification_discarded_elements, parent); - clock_value = bt_get(discarded_elems_notif->end_clock_value); - -end: - return clock_value; + return bt_get(discarded_elems_notif->end_clock_value); } BT_HIDDEN @@ -168,29 +134,13 @@ int64_t bt_notification_discarded_elements_get_count( enum bt_notification_type type, struct bt_notification *notification) { - int64_t count = (int64_t) -1; struct bt_notification_discarded_elements *discarded_elems_notif; - if (!notification) { - BT_LOGW_STR("Invalid parameter: notification is NULL."); - goto end; - } - - if (bt_notification_get_type(notification) != type) { - BT_LOGW("Invalid parameter: notification has not the expected type: " - "addr%p, expected-type=%s, notif-type=%s", - notification, bt_notification_type_string(type), - bt_notification_type_string( - bt_notification_get_type(notification))); - goto end; - } - + BT_ASSERT_PRE_NON_NULL(notification, "Notification"); + BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, type); discarded_elems_notif = container_of(notification, struct bt_notification_discarded_elements, parent); - count = discarded_elems_notif->count; - -end: - return count; + return discarded_elems_notif->count; } BT_HIDDEN @@ -198,27 +148,11 @@ struct bt_stream *bt_notification_discarded_elements_get_stream( enum bt_notification_type type, struct bt_notification *notification) { - struct bt_stream *stream = NULL; struct bt_notification_discarded_elements *discarded_elems_notif; - if (!notification) { - BT_LOGW_STR("Invalid parameter: notification is NULL."); - goto end; - } - - if (bt_notification_get_type(notification) != type) { - BT_LOGW("Invalid parameter: notification has not the expected type: " - "addr%p, expected-type=%s, notif-type=%s", - notification, bt_notification_type_string(type), - bt_notification_type_string( - bt_notification_get_type(notification))); - goto end; - } - + BT_ASSERT_PRE_NON_NULL(notification, "Notification"); + BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, type); discarded_elems_notif = container_of(notification, struct bt_notification_discarded_elements, parent); - stream = bt_get(discarded_elems_notif->stream); - -end: - return stream; + return bt_get(discarded_elems_notif->stream); } diff --git a/lib/graph/notification/event.c b/lib/graph/notification/event.c index 73165737..b42801d7 100644 --- a/lib/graph/notification/event.c +++ b/lib/graph/notification/event.c @@ -37,6 +37,8 @@ #include #include #include +#include +#include #include #include @@ -54,7 +56,7 @@ void bt_notification_event_destroy(struct bt_object *obj) g_free(notification); } -static +BT_ASSERT_PRE_FUNC static inline bt_bool validate_clock_classes(struct bt_notification_event *notif) { /* @@ -75,17 +77,17 @@ bt_bool validate_clock_classes(struct bt_notification_event *notif) struct bt_trace *trace = NULL; event_class = bt_event_borrow_event_class(notif->event); - assert(event_class); + BT_ASSERT(event_class); stream_class = bt_event_class_borrow_stream_class(event_class); - assert(stream_class); + BT_ASSERT(stream_class); trace = bt_stream_class_borrow_trace(stream_class); - assert(trace); + BT_ASSERT(trace); trace_cc_count = bt_trace_get_clock_class_count(trace); - assert(trace_cc_count >= 0); + BT_ASSERT(trace_cc_count >= 0); cc_prio_map_cc_count = bt_clock_class_priority_map_get_clock_class_count( notif->cc_prio_map); - assert(cc_prio_map_cc_count >= 0); + BT_ASSERT(cc_prio_map_cc_count >= 0); for (cc_prio_map_cc_i = 0; cc_prio_map_cc_i < cc_prio_map_cc_count; cc_prio_map_cc_i++) { @@ -94,11 +96,11 @@ bt_bool validate_clock_classes(struct bt_notification_event *notif) clock_class = bt_clock_class_priority_map_get_clock_class_by_index( notif->cc_prio_map, cc_prio_map_cc_i); - assert(clock_class); + BT_ASSERT(clock_class); clock_value = bt_event_get_clock_value(notif->event, clock_class); if (!clock_value) { - BT_LOGW("Event has no clock value for a clock class which exists in the notification's clock class priority map: " + BT_ASSERT_PRE_MSG("Event has no clock value for a clock class which exists in the notification's clock class priority map: " "notif-addr=%p, event-addr=%p, " "event-class-addr=%p, event-class-name=\"%s\", " "event-class-id=%" PRId64 ", " @@ -119,7 +121,7 @@ bt_bool validate_clock_classes(struct bt_notification_event *notif) bt_trace_get_clock_class_by_index(trace, trace_cc_i); - assert(trace_clock_class); + BT_ASSERT(trace_clock_class); bt_put(trace_clock_class); if (trace_clock_class == clock_class) { @@ -129,7 +131,7 @@ bt_bool validate_clock_classes(struct bt_notification_event *notif) } if (!found_in_trace) { - BT_LOGW("A clock class found in the event notification's clock class priority map does not exist in the notification's event's trace: " + BT_ASSERT_PRE_MSG("A clock class found in the event notification's clock class priority map does not exist in the notification's event's trace: " "notif-addr=%p, trace-addr=%p, " "trace-name=\"%s\", cc-prio-map-addr=%p, " "clock-class-addr=%p, clock-class-name=\"%s\"", @@ -150,16 +152,16 @@ end: return is_valid; } -static -bool event_has_trace(struct bt_event *event) +BT_ASSERT_PRE_FUNC +static inline bool event_has_trace(struct bt_event *event) { struct bt_event_class *event_class; struct bt_stream_class *stream_class; event_class = bt_event_borrow_event_class(event); - assert(event_class); + BT_ASSERT(event_class); stream_class = bt_event_class_borrow_stream_class(event_class); - assert(stream_class); + BT_ASSERT(stream_class); return bt_stream_class_borrow_trace(stream_class) != NULL; } @@ -169,10 +171,7 @@ struct bt_notification *bt_notification_event_create(struct bt_event *event, struct bt_notification_event *notification = NULL; struct bt_event_class *event_class; - if (!event) { - BT_LOGW_STR("Invalid parameter: event is NULL."); - goto error; - } + BT_ASSERT_PRE_NON_NULL(event, "Event"); if (cc_prio_map) { /* Function's reference, released at the end */ @@ -185,9 +184,9 @@ struct bt_notification *bt_notification_event_create(struct bt_event *event, } } - assert(cc_prio_map); + BT_ASSERT(cc_prio_map); event_class = bt_event_borrow_event_class(event); - assert(event_class); + BT_ASSERT(event_class); BT_LOGD("Creating event notification object: " "event-addr=%p, event-class-addr=%p, " "event-class-name=\"%s\", event-class-id=%" PRId64 ", " @@ -196,28 +195,10 @@ struct bt_notification *bt_notification_event_create(struct bt_event *event, bt_event_class_get_name(event_class), bt_event_class_get_id(event_class), cc_prio_map); - if (!bt_event_borrow_packet(event)) { - BT_LOGW("Invalid parameter: event has no packet: " - "event-addr=%p, event-class-addr=%p, " - "event-class-name=\"%s\", " - "event-class-id=%" PRId64, - event, event_class, - bt_event_class_get_name(event_class), - bt_event_class_get_id(event_class)); - goto error; - } - - if (!event_has_trace(event)) { - BT_LOGW("Invalid parameter: event has no trace: " - "event-addr=%p, event-class-addr=%p, " - "event-class-name=\"%s\", " - "event-class-id=%" PRId64, - event, event_class, - bt_event_class_get_name(event_class), - bt_event_class_get_id(event_class)); - goto error; - } - + BT_ASSERT_PRE(bt_event_borrow_packet(event), + "Event has no packet: %!+e", event); + BT_ASSERT_PRE(event_has_trace(event), + "Event has no trace: %!+e", event); notification = g_new0(struct bt_notification_event, 1); if (!notification) { BT_LOGE_STR("Failed to allocate one event notification."); @@ -228,17 +209,8 @@ struct bt_notification *bt_notification_event_create(struct bt_event *event, bt_notification_event_destroy); notification->event = bt_get(event); notification->cc_prio_map = bt_get(cc_prio_map); - if (!validate_clock_classes(notification)) { - BT_LOGW("Invalid event: invalid clock class: " - "event-addr=%p, event-class-addr=%p, " - "event-class-name=\"%s\", " - "event-class-id=%" PRId64, - event, event_class, - bt_event_class_get_name(event_class), - bt_event_class_get_id(event_class)); - goto error; - } - + BT_ASSERT_PRE(validate_clock_classes(notification), + "Invalid clock classes: %![event-]+e", event); BT_LOGD_STR("Freezing event notification's event."); bt_event_freeze(notification->event); BT_LOGD_STR("Freezing event notification's clock class priority map."); @@ -264,56 +236,24 @@ end: struct bt_event *bt_notification_event_get_event( struct bt_notification *notification) { - struct bt_event *event = NULL; struct bt_notification_event *event_notification; - if (!notification) { - BT_LOGW_STR("Invalid parameter: notification is NULL."); - goto end; - } - - if (bt_notification_get_type(notification) != - BT_NOTIFICATION_TYPE_EVENT) { - BT_LOGW("Invalid parameter: notification is not an event notification: " - "addr%p, notif-type=%s", - notification, bt_notification_type_string( - bt_notification_get_type(notification))); - goto end; - } - + BT_ASSERT_PRE_NON_NULL(notification, "Notification"); + BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, BT_NOTIFICATION_TYPE_EVENT); event_notification = container_of(notification, struct bt_notification_event, parent); - event = bt_get(event_notification->event); - -end: - return event; + return bt_get(event_notification->event); } extern struct bt_clock_class_priority_map * bt_notification_event_get_clock_class_priority_map( struct bt_notification *notification) { - struct bt_clock_class_priority_map *cc_prio_map = NULL; struct bt_notification_event *event_notification; - if (!notification) { - BT_LOGW_STR("Invalid parameter: notification is NULL."); - goto end; - } - - if (bt_notification_get_type(notification) != - BT_NOTIFICATION_TYPE_EVENT) { - BT_LOGW("Invalid parameter: notification is not an event notification: " - "addr%p, notif-type=%s", - notification, bt_notification_type_string( - bt_notification_get_type(notification))); - goto end; - } - + BT_ASSERT_PRE_NON_NULL(notification, "Notification"); + BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, BT_NOTIFICATION_TYPE_EVENT); event_notification = container_of(notification, struct bt_notification_event, parent); - cc_prio_map = bt_get(event_notification->cc_prio_map); - -end: - return cc_prio_map; + return bt_get(event_notification->cc_prio_map); } diff --git a/lib/graph/notification/heap.c b/lib/graph/notification/heap.c index fc0bce81..f2d87a8b 100644 --- a/lib/graph/notification/heap.c +++ b/lib/graph/notification/heap.c @@ -26,10 +26,10 @@ * SOFTWARE. */ -#include #include #include #include +#include #ifdef DEBUG_HEAP static @@ -42,7 +42,7 @@ void check_heap(struct bt_notification_heap *heap) } for (i = 1; i < heap->count; i++) { - assert(!heap->compare(g_ptr_array_index(heap->ptrs, i), + BT_ASSERT(!heap->compare(g_ptr_array_index(heap->ptrs, i), g_ptr_array_index(heap->ptrs, 0), heap->compare_data)); } diff --git a/lib/graph/notification/inactivity.c b/lib/graph/notification/inactivity.c index 118b18d6..181625db 100644 --- a/lib/graph/notification/inactivity.c +++ b/lib/graph/notification/inactivity.c @@ -26,10 +26,12 @@ #include #include #include +#include #include #include #include #include +#include static void bt_notification_inactivity_destroy(struct bt_object *obj) @@ -105,134 +107,78 @@ extern struct bt_clock_class_priority_map * bt_notification_inactivity_get_clock_class_priority_map( struct bt_notification *notification) { - struct bt_clock_class_priority_map *cc_prio_map = NULL; struct bt_notification_inactivity *inactivity_notification; - if (!notification) { - BT_LOGW_STR("Invalid parameter: notification is NULL."); - goto end; - } - - if (bt_notification_get_type(notification) != - BT_NOTIFICATION_TYPE_INACTIVITY) { - BT_LOGW("Invalid parameter: notification is not an inactivity notification: " - "addr%p, notif-type=%s", - notification, bt_notification_type_string( - bt_notification_get_type(notification))); - goto end; - } - + BT_ASSERT_PRE_NON_NULL(notification, "Notification"); + BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, + BT_NOTIFICATION_TYPE_INACTIVITY); inactivity_notification = container_of(notification, struct bt_notification_inactivity, parent); - cc_prio_map = bt_get(inactivity_notification->cc_prio_map); -end: - return cc_prio_map; + return bt_get(inactivity_notification->cc_prio_map); } struct bt_clock_value *bt_notification_inactivity_get_clock_value( struct bt_notification *notification, struct bt_clock_class *clock_class) { - struct bt_clock_value *clock_value = NULL; struct bt_notification_inactivity *inactivity_notification; - if (!notification) { - BT_LOGW_STR("Invalid parameter: notification is NULL."); - goto end; - } - - if (!clock_class) { - BT_LOGW_STR("Invalid parameter: clock class is NULL."); - goto end; - } - - if (bt_notification_get_type(notification) != - BT_NOTIFICATION_TYPE_INACTIVITY) { - BT_LOGW("Invalid parameter: notification is not an inactivity notification: " - "addr%p, notif-type=%s", - notification, bt_notification_type_string( - bt_notification_get_type(notification))); - goto end; - } - + BT_ASSERT_PRE_NON_NULL(notification, "Notification"); + BT_ASSERT_PRE_NON_NULL(clock_class, "Clock_class"); + BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, + BT_NOTIFICATION_TYPE_INACTIVITY); inactivity_notification = container_of(notification, struct bt_notification_inactivity, parent); - clock_value = g_hash_table_lookup(inactivity_notification->clock_values, - clock_class); - bt_get(clock_value); + return bt_get(g_hash_table_lookup( + inactivity_notification->clock_values, clock_class)); +} -end: - return clock_value; +BT_ASSERT_PRE_FUNC +static inline bool cc_prio_map_contains_clock_class( + struct bt_clock_class_priority_map *cc_prio_map, + struct bt_clock_class *clock_class) +{ + int ret = 0; + uint64_t prio; + + ret = bt_clock_class_priority_map_get_clock_class_priority( + cc_prio_map, clock_class, &prio); + return ret == 0; } int bt_notification_inactivity_set_clock_value( struct bt_notification *notification, struct bt_clock_value *clock_value) { - int ret = 0; - uint64_t prio; - struct bt_clock_class *clock_class = NULL; struct bt_notification_inactivity *inactivity_notification; - if (!notification) { - BT_LOGW_STR("Invalid parameter: notification is NULL."); - ret = -1; - goto end; - } - - if (!clock_value) { - BT_LOGW_STR("Invalid parameter: clock value is NULL."); - ret = -1; - goto end; - } - - if (notification->frozen) { - BT_LOGW_STR("Invalid parameter: notification is frozen."); - ret = -1; - goto end; - } - - if (bt_notification_get_type(notification) != - BT_NOTIFICATION_TYPE_INACTIVITY) { - BT_LOGW("Invalid parameter: notification is not an inactivity notification: " - "addr%p, notif-type=%s", - notification, bt_notification_type_string( - bt_notification_get_type(notification))); - ret = -1; - goto end; - } - + BT_ASSERT_PRE_NON_NULL(notification, "Notification"); + BT_ASSERT_PRE_NON_NULL(clock_value, "Clock value"); + BT_ASSERT_PRE_HOT(notification, "notification", + ": +%!+n", notification); + BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, + BT_NOTIFICATION_TYPE_INACTIVITY); inactivity_notification = container_of(notification, struct bt_notification_inactivity, parent); - clock_class = bt_clock_value_get_class(clock_value); - ret = bt_clock_class_priority_map_get_clock_class_priority( - inactivity_notification->cc_prio_map, clock_class, &prio); - if (ret) { - BT_LOGW("Clock value's class is not mapped to a priority within the scope of the inactivity notification: " - "notif-addr=%p, cc-prio-map-addr=%p, " - "clock-class-addr=%p, clock-class-name=\"%s\", " - "clock-value-addr=%p", - inactivity_notification, - inactivity_notification->cc_prio_map, - clock_class, bt_clock_class_get_name(clock_class), - clock_value); - ret = -1; - goto end; - } - + BT_ASSERT_PRE(cc_prio_map_contains_clock_class( + inactivity_notification->cc_prio_map, clock_value->clock_class), + "Clock value's class is not mapped to a priority within the scope of the inactivity notification: " + "notif-addr=%p, cc-prio-map-addr=%p, " + "clock-class-addr=%p, clock-class-name=\"%s\", " + "clock-value-addr=%p", + inactivity_notification, + inactivity_notification->cc_prio_map, + clock_value->clock_class, + bt_clock_class_get_name(clock_value->clock_class), clock_value); g_hash_table_insert(inactivity_notification->clock_values, - clock_class, bt_get(clock_value)); - clock_class = NULL; + clock_value->clock_class, bt_get(clock_value)); BT_LOGV("Set inactivity notification's clock value: " "notif-addr=%p, cc-prio-map-addr=%p, " "clock-class-addr=%p, clock-class-name=\"%s\", " "clock-value-addr=%p", inactivity_notification, inactivity_notification->cc_prio_map, - clock_class, bt_clock_class_get_name(clock_class), - clock_value); - -end: - bt_put(clock_class); - return ret; + clock_value->clock_class, + bt_clock_class_get_name(clock_value->clock_class), clock_value); + return 0; } diff --git a/lib/graph/notification/notification.c b/lib/graph/notification/notification.c index 692f740c..8d045fa5 100644 --- a/lib/graph/notification/notification.c +++ b/lib/graph/notification/notification.c @@ -24,14 +24,19 @@ * SOFTWARE. */ +#define BT_LOG_TAG "NOTIF" +#include + #include +#include +#include BT_HIDDEN void bt_notification_init(struct bt_notification *notification, enum bt_notification_type type, bt_object_release_func release) { - assert(type > BT_NOTIFICATION_TYPE_ALL && + BT_ASSERT(type > BT_NOTIFICATION_TYPE_ALL && type < BT_NOTIFICATION_TYPE_NR); notification->type = type; bt_object_init(¬ification->base, release); @@ -40,5 +45,6 @@ void bt_notification_init(struct bt_notification *notification, enum bt_notification_type bt_notification_get_type( struct bt_notification *notification) { - return notification ? notification->type : BT_NOTIFICATION_TYPE_UNKNOWN; + BT_ASSERT_PRE_NON_NULL(notification, "Notification"); + return notification->type; } diff --git a/lib/graph/notification/packet.c b/lib/graph/notification/packet.c index 76a9337b..0bbfa8ea 100644 --- a/lib/graph/notification/packet.c +++ b/lib/graph/notification/packet.c @@ -34,6 +34,8 @@ #include #include #include +#include +#include #include static @@ -69,15 +71,11 @@ struct bt_notification *bt_notification_packet_begin_create( struct bt_stream *stream; struct bt_stream_class *stream_class; - if (!packet) { - BT_LOGW_STR("Invalid parameter: packet is NULL."); - goto error; - } - + BT_ASSERT_PRE_NON_NULL(packet, "Packet"); stream = bt_packet_borrow_stream(packet); - assert(stream); + BT_ASSERT(stream); stream_class = bt_stream_borrow_stream_class(stream); - assert(stream_class); + BT_ASSERT(stream_class); BT_LOGD("Creating packet beginning notification object: " "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", " "stream-class-addr=%p, stream-class-name=\"%s\", " @@ -112,27 +110,14 @@ error: struct bt_packet *bt_notification_packet_begin_get_packet( struct bt_notification *notification) { - struct bt_packet *ret = NULL; struct bt_notification_packet_begin *packet_begin; - if (!notification) { - BT_LOGW_STR("Invalid parameter: notification is NULL."); - goto end; - } - - if (notification->type != BT_NOTIFICATION_TYPE_PACKET_BEGIN) { - BT_LOGW("Invalid parameter: notification is not a packet beginning notification: " - "addr%p, notif-type=%s", - notification, bt_notification_type_string( - bt_notification_get_type(notification))); - goto end; - } - + BT_ASSERT_PRE_NON_NULL(notification, "Notification"); + BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, + BT_NOTIFICATION_TYPE_PACKET_BEGIN); packet_begin = container_of(notification, struct bt_notification_packet_begin, parent); - ret = bt_get(packet_begin->packet); -end: - return ret; + return bt_get(packet_begin->packet); } struct bt_notification *bt_notification_packet_end_create( @@ -142,15 +127,11 @@ struct bt_notification *bt_notification_packet_end_create( struct bt_stream *stream; struct bt_stream_class *stream_class; - if (!packet) { - BT_LOGW_STR("Invalid parameter: packet is NULL."); - goto error; - } - + BT_ASSERT_PRE_NON_NULL(packet, "Packet"); stream = bt_packet_borrow_stream(packet); - assert(stream); + BT_ASSERT(stream); stream_class = bt_stream_borrow_stream_class(stream); - assert(stream_class); + BT_ASSERT(stream_class); BT_LOGD("Creating packet end notification object: " "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", " "stream-class-addr=%p, stream-class-name=\"%s\", " @@ -185,25 +166,12 @@ error: struct bt_packet *bt_notification_packet_end_get_packet( struct bt_notification *notification) { - struct bt_packet *ret = NULL; struct bt_notification_packet_end *packet_end; - if (!notification) { - BT_LOGW_STR("Invalid parameter: notification is NULL."); - goto end; - } - - if (notification->type != BT_NOTIFICATION_TYPE_PACKET_END) { - BT_LOGW("Invalid parameter: notification is not a packet end notification: " - "addr%p, notif-type=%s", - notification, bt_notification_type_string( - bt_notification_get_type(notification))); - goto end; - } - + BT_ASSERT_PRE_NON_NULL(notification, "Notification"); + BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, + BT_NOTIFICATION_TYPE_PACKET_END); packet_end = container_of(notification, struct bt_notification_packet_end, parent); - ret = bt_get(packet_end->packet); -end: - return ret; + return bt_get(packet_end->packet); } diff --git a/lib/graph/notification/stream.c b/lib/graph/notification/stream.c index c036d1bf..af615633 100644 --- a/lib/graph/notification/stream.c +++ b/lib/graph/notification/stream.c @@ -31,6 +31,8 @@ #include #include #include +#include +#include #include static @@ -52,25 +54,11 @@ struct bt_notification *bt_notification_stream_end_create( struct bt_notification_stream_end *notification; struct bt_stream_class *stream_class; - if (!stream) { - BT_LOGW_STR("Invalid parameter: stream is NULL."); - goto error; - } - + BT_ASSERT_PRE_NON_NULL(stream, "Stream"); + BT_ASSERT_PRE(stream->pos.fd < 0, + "Stream is a CTF writer stream: %!+s", stream); stream_class = bt_stream_borrow_stream_class(stream); - assert(stream_class); - - if (stream->pos.fd >= 0) { - BT_LOGW("Invalid parameter: stream is a CTF writer stream: " - "stream-addr=%p, stream-name=\"%s\", " - "stream-class-addr=%p, stream-class-name\"%s\", " - "stream-class-id=%" PRId64, - stream, bt_stream_get_name(stream), stream_class, - bt_stream_class_get_name(stream_class), - bt_stream_class_get_id(stream_class)); - goto error; - } - + BT_ASSERT(stream_class); BT_LOGD("Creating stream end notification object: " "stream-addr=%p, stream-name=\"%s\", " "stream-class-addr=%p, stream-class-name=\"%s\", " @@ -106,27 +94,13 @@ struct bt_stream *bt_notification_stream_end_get_stream( struct bt_notification *notification) { struct bt_notification_stream_end *stream_end; - struct bt_stream *stream = NULL; - - if (!notification) { - BT_LOGW_STR("Invalid parameter: notification is NULL."); - goto end; - } - - if (notification->type != BT_NOTIFICATION_TYPE_STREAM_END) { - BT_LOGW("Invalid parameter: notification is not a stream end notification: " - "addr%p, notif-type=%s", - notification, bt_notification_type_string( - bt_notification_get_type(notification))); - goto end; - } + BT_ASSERT_PRE_NON_NULL(notification, "Notification"); + BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, + BT_NOTIFICATION_TYPE_STREAM_END); stream_end = container_of(notification, struct bt_notification_stream_end, parent); - stream = bt_get(stream_end->stream); - -end: - return stream; + return bt_get(stream_end->stream); } static @@ -148,25 +122,11 @@ struct bt_notification *bt_notification_stream_begin_create( struct bt_notification_stream_begin *notification; struct bt_stream_class *stream_class; - if (!stream) { - BT_LOGW_STR("Invalid parameter: stream is NULL."); - goto error; - } - + BT_ASSERT_PRE_NON_NULL(stream, "Stream"); + BT_ASSERT_PRE(stream->pos.fd < 0, + "Stream is a CTF writer stream: %!+s", stream); stream_class = bt_stream_borrow_stream_class(stream); - assert(stream_class); - - if (stream->pos.fd >= 0) { - BT_LOGW("Invalid parameter: stream is a CTF writer stream: " - "stream-addr=%p, stream-name=\"%s\", " - "stream-class-addr=%p, stream-class-name\"%s\", " - "stream-class-id=%" PRId64, - stream, bt_stream_get_name(stream), stream_class, - bt_stream_class_get_name(stream_class), - bt_stream_class_get_id(stream_class)); - goto error; - } - + BT_ASSERT(stream_class); BT_LOGD("Creating stream beginning notification object: " "stream-addr=%p, stream-name=\"%s\", " "stream-class-addr=%p, stream-class-name=\"%s\", " @@ -202,25 +162,11 @@ struct bt_stream *bt_notification_stream_begin_get_stream( struct bt_notification *notification) { struct bt_notification_stream_begin *stream_begin; - struct bt_stream *stream = NULL; - - if (!notification) { - BT_LOGW_STR("Invalid parameter: notification is NULL."); - goto end; - } - - if (notification->type != BT_NOTIFICATION_TYPE_STREAM_BEGIN) { - BT_LOGW("Invalid parameter: notification is not a stream beginning notification: " - "addr%p, notif-type=%s", - notification, bt_notification_type_string( - bt_notification_get_type(notification))); - goto end; - } + BT_ASSERT_PRE_NON_NULL(notification, "Notification"); + BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, + BT_NOTIFICATION_TYPE_STREAM_BEGIN); stream_begin = container_of(notification, struct bt_notification_stream_begin, parent); - stream = bt_get(stream_begin->stream); - -end: - return stream; + return bt_get(stream_begin->stream); } diff --git a/lib/graph/port.c b/lib/graph/port.c index 43f3134c..25b427d2 100644 --- a/lib/graph/port.c +++ b/lib/graph/port.c @@ -35,6 +35,7 @@ #include #include #include +#include static void bt_port_destroy(struct bt_object *obj) @@ -63,9 +64,9 @@ struct bt_port *bt_port_create(struct bt_component *parent_component, { struct bt_port *port = NULL; - assert(name); - assert(parent_component); - assert(type == BT_PORT_TYPE_INPUT || type == BT_PORT_TYPE_OUTPUT); + BT_ASSERT(name); + BT_ASSERT(parent_component); + BT_ASSERT(type == BT_PORT_TYPE_INPUT || type == BT_PORT_TYPE_OUTPUT); if (strlen(name) == 0) { BT_LOGW_STR("Invalid parameter: name is an empty string."); @@ -193,7 +194,7 @@ enum bt_port_status bt_private_port_remove_from_component( /* bt_component_remove_port() logs details */ comp_status = bt_component_remove_port(comp, port); - assert(comp_status != BT_COMPONENT_STATUS_INVALID); + BT_ASSERT(comp_status != BT_COMPONENT_STATUS_INVALID); if (comp_status < 0) { status = BT_PORT_STATUS_ERROR; goto end; diff --git a/lib/graph/sink.c b/lib/graph/sink.c index f0feb3b4..5c8bec7a 100644 --- a/lib/graph/sink.c +++ b/lib/graph/sink.c @@ -35,6 +35,8 @@ #include #include #include +#include +#include BT_HIDDEN void bt_component_sink_destroy(struct bt_component *component) @@ -64,23 +66,10 @@ enum bt_component_status bt_component_sink_consume( enum bt_component_status ret = BT_COMPONENT_STATUS_OK; struct bt_component_class_sink *sink_class = NULL; - if (!component) { - BT_LOGW_STR("Invalid parameter: component is NULL."); - ret = BT_COMPONENT_STATUS_INVALID; - goto end; - } - - if (bt_component_get_class_type(component) != BT_COMPONENT_CLASS_TYPE_SINK) { - BT_LOGW("Invalid parameter: component's class is not a sink component class: " - "comp-addr=%p, comp-name=\"%s\", comp-class-type=%s", - component, bt_component_get_name(component), - bt_component_class_type_string(component->class->type)); - ret = BT_COMPONENT_STATUS_UNSUPPORTED; - goto end; - } - + BT_ASSERT(component); + BT_ASSERT(bt_component_get_class_type(component) == BT_COMPONENT_CLASS_TYPE_SINK); sink_class = container_of(component->class, struct bt_component_class_sink, parent); - assert(sink_class->methods.consume); + BT_ASSERT(sink_class->methods.consume); BT_LOGD("Calling user's consume method: " "comp-addr=%p, comp-name=\"%s\"", component, bt_component_get_name(component)); @@ -91,7 +80,6 @@ enum bt_component_status bt_component_sink_consume( BT_LOGW_STR("Consume method failed."); } -end: return ret; } diff --git a/lib/lib-logging.c b/lib/lib-logging.c index 57398492..65d33138 100644 --- a/lib/lib-logging.c +++ b/lib/lib-logging.c @@ -26,7 +26,6 @@ #include #include #include -#include #include #include #include @@ -78,7 +77,7 @@ static char __thread lib_logging_buf[LIB_LOGGING_BUF_SIZE]; size_t _size = LIB_LOGGING_BUF_SIZE - \ (size_t) (*buf_ch - lib_logging_buf); \ _count = snprintf(*buf_ch, _size, (_fmt), __VA_ARGS__); \ - assert(_count >= 0); \ + BT_ASSERT(_count >= 0); \ *buf_ch += MIN(_count, _size); \ if (*buf_ch >= lib_logging_buf + LIB_LOGGING_BUF_SIZE - 1) { \ return; \ @@ -295,7 +294,7 @@ static inline void format_field(char **buf_ch, bool extended, { struct bt_field_string *str = (void *) field; - assert(str->payload); + BT_ASSERT(str->payload); BUF_APPEND(", %spartial-value=\"%.32s\"", PRFIELD(str->payload->str)); break; @@ -325,7 +324,7 @@ static inline void format_field_path(char **buf_ch, bool extended, { uint64_t i; - assert(field_path->indexes); + BT_ASSERT(field_path->indexes); BUF_APPEND(", %sindex-count=%u", PRFIELD(field_path->indexes->len)); if (!extended) { @@ -678,36 +677,32 @@ static inline void format_value(char **buf_ch, bool extended, case BT_VALUE_TYPE_BOOL: { bt_bool val; - int status = bt_value_bool_get(value, &val); - assert(status == 0); + (void) bt_value_bool_get(value, &val); BUF_APPEND(", %svalue=%d", PRFIELD(val)); break; } case BT_VALUE_TYPE_INTEGER: { int64_t val; - int status = bt_value_integer_get(value, &val); - assert(status == 0); + (void) bt_value_integer_get(value, &val); BUF_APPEND(", %svalue=%" PRId64, PRFIELD(val)); break; } case BT_VALUE_TYPE_FLOAT: { double val; - int status = bt_value_float_get(value, &val); - assert(status == 0); + (void) bt_value_float_get(value, &val); BUF_APPEND(", %svalue=%f", PRFIELD(val)); break; } case BT_VALUE_TYPE_STRING: { const char *val; - int status = bt_value_string_get(value, &val); - assert(status == 0); + (void) bt_value_string_get(value, &val); BUF_APPEND(", %spartial-value=\"%.32s\"", PRFIELD(val)); break; } @@ -715,7 +710,7 @@ static inline void format_value(char **buf_ch, bool extended, { int64_t count = bt_value_array_size(value); - assert(count >= 0); + BT_ASSERT(count >= 0); BUF_APPEND(", %selement-count=%" PRId64, PRFIELD(count)); break; } @@ -723,7 +718,7 @@ static inline void format_value(char **buf_ch, bool extended, { int64_t count = bt_value_map_size(value); - assert(count >= 0); + BT_ASSERT(count >= 0); BUF_APPEND(", %selement-count=%" PRId64, PRFIELD(count)); break; } @@ -1202,8 +1197,7 @@ void bt_lib_log(const char *func, const char *file, unsigned line, { va_list args; - assert(tag); - assert(fmt); + BT_ASSERT(fmt); va_start(args, fmt); bt_common_custom_vsnprintf(lib_logging_buf, LIB_LOGGING_BUF_SIZE, '!', handle_conversion_specifier_bt, NULL, fmt, &args); diff --git a/lib/plugin/plugin-so.c b/lib/plugin/plugin-so.c index d21a30c9..2326ed8f 100644 --- a/lib/plugin/plugin-so.c +++ b/lib/plugin/plugin-so.c @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -105,7 +106,7 @@ void bt_plugin_so_shared_lib_handle_destroy(struct bt_object *obj) { struct bt_plugin_so_shared_lib_handle *shared_lib_handle; - assert(obj); + BT_ASSERT(obj); shared_lib_handle = container_of(obj, struct bt_plugin_so_shared_lib_handle, base); const char *path = shared_lib_handle->path ? @@ -223,8 +224,8 @@ void bt_plugin_so_destroy_spec_data(struct bt_plugin *plugin) return; } - assert(plugin->type == BT_PLUGIN_TYPE_SO); - assert(spec); + BT_ASSERT(plugin->type == BT_PLUGIN_TYPE_SO); + BT_ASSERT(spec); BT_PUT(spec->shared_lib_handle); g_free(plugin->spec_data); plugin->spec_data = NULL; @@ -1132,8 +1133,8 @@ void bt_plugin_so_on_add_component_class(struct bt_plugin *plugin, { struct bt_plugin_so_spec_data *spec = plugin->spec_data; - assert(plugin->spec_data); - assert(plugin->type == BT_PLUGIN_TYPE_SO); + BT_ASSERT(plugin->spec_data); + BT_ASSERT(plugin->type == BT_PLUGIN_TYPE_SO); bt_list_add(&comp_class->node, &component_class_list); comp_class->so_handle = bt_get(spec->shared_lib_handle); diff --git a/lib/plugin/plugin.c b/lib/plugin/plugin.c index 3ff50de6..59b87273 100644 --- a/lib/plugin/plugin.c +++ b/lib/plugin/plugin.c @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -713,8 +714,8 @@ struct bt_component_class *bt_plugin_get_component_class_by_name_and_type( enum bt_component_class_type comp_class_cand_type = bt_component_class_get_type(comp_class_candidate); - assert(comp_class_cand_name); - assert(comp_class_cand_type >= 0); + BT_ASSERT(comp_class_cand_name); + BT_ASSERT(comp_class_cand_type >= 0); if (strcmp(name, comp_class_cand_name) == 0 && comp_class_cand_type == type) { diff --git a/lib/prio_heap/prio_heap.c b/lib/prio_heap/prio_heap.c index cd7098ff..ec5d1f97 100644 --- a/lib/prio_heap/prio_heap.c +++ b/lib/prio_heap/prio_heap.c @@ -27,10 +27,10 @@ #include #include +#include #include #include #include -#include #ifdef DEBUG_HEAP void check_heap(const struct ptr_heap *heap) @@ -41,7 +41,7 @@ void check_heap(const struct ptr_heap *heap) return; for (i = 1; i < heap->len; i++) - assert(!heap->gt(heap->ptrs[i], heap->ptrs[0])); + BT_ASSERT(!heap->gt(heap->ptrs[i], heap->ptrs[0])); } #endif diff --git a/lib/values.c b/lib/values.c index ea69643e..0fb6c2be 100644 --- a/lib/values.c +++ b/lib/values.c @@ -30,7 +30,6 @@ #include #include -#include #include #include #include @@ -40,6 +39,8 @@ #include #include #include +#include +#include #define BT_VALUE_FROM_CONCRETE(_concrete) ((struct bt_value *) (_concrete)) #define BT_VALUE_TO_BOOL(_base) ((struct bt_value_bool *) (_base)) @@ -49,10 +50,25 @@ #define BT_VALUE_TO_ARRAY(_base) ((struct bt_value_array *) (_base)) #define BT_VALUE_TO_MAP(_base) ((struct bt_value_map *) (_base)) +#define BT_ASSERT_PRE_VALUE_IS_TYPE(_value, _type) \ + BT_ASSERT_PRE((_value)->type == (_type), \ + "Value has the wrong type ID: expected-type=%s, " \ + "%![value-]+v", bt_value_type_string(_type), \ + (_value)) + +#define BT_ASSERT_PRE_VALUE_HOT(_value, _name) \ + BT_ASSERT_PRE_HOT((_value), (_name), ": +%!+v", (_value)) + +#define BT_ASSERT_PRE_VALUE_INDEX_IN_BOUNDS(_index, _count) \ + BT_ASSERT_PRE((_index) < (_count), \ + "Index is out of bound: " \ + "index=%" PRIu64 ", count=%u", (_index), (_count)); + + struct bt_value { struct bt_object base; enum bt_value_type type; - bt_bool is_frozen; + bt_bool frozen; }; static @@ -66,7 +82,7 @@ struct bt_value bt_value_null_instance = { .parent = NULL, }, .type = BT_VALUE_TYPE_NULL, - .is_frozen = BT_TRUE, + .frozen = BT_TRUE, }; struct bt_value *bt_value_null = &bt_value_null_instance; @@ -186,7 +202,6 @@ struct bt_value *bt_value_array_copy(const struct bt_value *array_obj) BT_LOGD("Copying array value: addr=%p", array_obj); typed_array_obj = BT_VALUE_TO_ARRAY(array_obj); copy_obj = bt_value_array_create(); - if (!copy_obj) { BT_LOGE_STR("Cannot create empty array value."); goto end; @@ -196,7 +211,7 @@ struct bt_value *bt_value_array_copy(const struct bt_value *array_obj) struct bt_value *element_obj_copy; struct bt_value *element_obj = bt_value_array_get(array_obj, i); - assert(element_obj); + BT_ASSERT(element_obj); BT_LOGD("Copying array value's element: element-addr=%p, " "index=%d", element_obj, i); element_obj_copy = bt_value_copy(element_obj); @@ -239,7 +254,6 @@ struct bt_value *bt_value_map_copy(const struct bt_value *map_obj) BT_LOGD("Copying map value: addr=%p", map_obj); typed_map_obj = BT_VALUE_TO_MAP(map_obj); copy_obj = bt_value_map_create(); - if (!copy_obj) { goto end; } @@ -249,7 +263,7 @@ struct bt_value *bt_value_map_copy(const struct bt_value *map_obj) while (g_hash_table_iter_next(&iter, &key, &element_obj)) { const char *key_str = g_quark_to_string(GPOINTER_TO_UINT(key)); - assert(key_str); + BT_ASSERT(key_str); BT_LOGD("Copying map value's element: element-addr=%p, " "key=\"%s\"", element_obj, key_str); element_obj_copy = bt_value_copy(element_obj); @@ -465,15 +479,18 @@ bt_bool (* const compare_funcs[])(const struct bt_value *, [BT_VALUE_TYPE_MAP] = bt_value_map_compare, }; +static void bt_value_null_freeze(struct bt_value *object) { } +static void bt_value_generic_freeze(struct bt_value *object) { - object->is_frozen = BT_TRUE; + object->frozen = BT_TRUE; } +static void bt_value_array_freeze(struct bt_value *object) { int i; @@ -481,15 +498,13 @@ void bt_value_array_freeze(struct bt_value *object) BT_VALUE_TO_ARRAY(object); for (i = 0; i < typed_array_obj->garray->len; ++i) { - struct bt_value *element_obj = - g_ptr_array_index(typed_array_obj->garray, i); - - bt_value_freeze(element_obj); + bt_value_freeze(g_ptr_array_index(typed_array_obj->garray, i)); } bt_value_generic_freeze(object); } +static void bt_value_map_freeze(struct bt_value *object) { GHashTableIter iter; @@ -522,7 +537,7 @@ void bt_value_destroy(struct bt_object *obj) struct bt_value *value; value = container_of(obj, struct bt_value, base); - assert(value->type != BT_VALUE_TYPE_UNKNOWN); + BT_ASSERT(value->type != BT_VALUE_TYPE_UNKNOWN); BT_LOGD("Destroying value: addr=%p", value); if (bt_value_is_null(value)) { @@ -537,17 +552,14 @@ void bt_value_destroy(struct bt_object *obj) g_free(value); } -enum bt_value_status bt_value_freeze(struct bt_value *object) +BT_HIDDEN +enum bt_value_status _bt_value_freeze(struct bt_value *object) { enum bt_value_status ret = BT_VALUE_STATUS_OK; - if (!object) { - BT_LOGW_STR("Invalid parameter: value object is NULL."); - ret = BT_VALUE_STATUS_INVAL; - goto end; - } + BT_ASSERT(object); - if (object->is_frozen) { + if (object->frozen) { goto end; } @@ -558,22 +570,9 @@ end: return ret; } -bt_bool bt_value_is_frozen(const struct bt_value *object) -{ - return object && object->is_frozen; -} - enum bt_value_type bt_value_get_type(const struct bt_value *object) { - if (!object) { - /* - * Not an error: user can test NULL value object with - * this function. - */ - BT_LOGV_STR("Value object is NULL."); - return BT_VALUE_TYPE_UNKNOWN; - } - + BT_ASSERT_PRE_NON_NULL(object, "Value object"); return object->type; } @@ -583,7 +582,7 @@ struct bt_value bt_value_create_base(enum bt_value_type type) struct bt_value base; base.type = type; - base.is_frozen = BT_FALSE; + base.frozen = BT_FALSE; bt_object_init(&base, bt_value_destroy); return base; } @@ -594,7 +593,6 @@ struct bt_value *bt_value_bool_create_init(bt_bool val) BT_LOGD("Creating boolean value object: val=%d", val); bool_obj = g_new0(struct bt_value_bool, 1); - if (!bool_obj) { BT_LOGE_STR("Failed to allocate one boolean value object."); goto end; @@ -619,7 +617,6 @@ struct bt_value *bt_value_integer_create_init(int64_t val) BT_LOGD("Creating integer value object: val=%" PRId64, val); integer_obj = g_new0(struct bt_value_integer, 1); - if (!integer_obj) { BT_LOGE_STR("Failed to allocate one integer value object."); goto end; @@ -645,7 +642,6 @@ struct bt_value *bt_value_float_create_init(double val) BT_LOGD("Creating floating point number value object: val=%f", val); float_obj = g_new0(struct bt_value_float, 1); - if (!float_obj) { BT_LOGE_STR("Failed to allocate one floating point number value object."); goto end; @@ -676,7 +672,6 @@ struct bt_value *bt_value_string_create_init(const char *val) BT_LOGD("Creating string value object: val-len=%zu", strlen(val)); string_obj = g_new0(struct bt_value_string, 1); - if (!string_obj) { BT_LOGE_STR("Failed to allocate one string object."); goto end; @@ -684,7 +679,6 @@ struct bt_value *bt_value_string_create_init(const char *val) string_obj->base = bt_value_create_base(BT_VALUE_TYPE_STRING); string_obj->gstr = g_string_new(val); - if (!string_obj->gstr) { BT_LOGE_STR("Failed to allocate a GString."); g_free(string_obj); @@ -710,7 +704,6 @@ struct bt_value *bt_value_array_create(void) BT_LOGD_STR("Creating empty array value object."); array_obj = g_new0(struct bt_value_array, 1); - if (!array_obj) { BT_LOGE_STR("Failed to allocate one array object."); goto end; @@ -719,7 +712,6 @@ struct bt_value *bt_value_array_create(void) array_obj->base = bt_value_create_base(BT_VALUE_TYPE_ARRAY); array_obj->garray = bt_g_ptr_array_new_full(0, (GDestroyNotify) bt_put); - if (!array_obj->garray) { BT_LOGE_STR("Failed to allocate a GPtrArray."); g_free(array_obj); @@ -740,7 +732,6 @@ struct bt_value *bt_value_map_create(void) BT_LOGD_STR("Creating empty map value object."); map_obj = g_new0(struct bt_value_map, 1); - if (!map_obj) { BT_LOGE_STR("Failed to allocate one map object."); goto end; @@ -749,7 +740,6 @@ struct bt_value *bt_value_map_create(void) map_obj->base = bt_value_create_base(BT_VALUE_TYPE_MAP); map_obj->ght = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, (GDestroyNotify) bt_put); - if (!map_obj->ght) { BT_LOGE_STR("Failed to allocate a GHashTable."); g_free(map_obj); @@ -767,286 +757,96 @@ end: enum bt_value_status bt_value_bool_get(const struct bt_value *bool_obj, bt_bool *val) { - enum bt_value_status ret = BT_VALUE_STATUS_OK; - struct bt_value_bool *typed_bool_obj = BT_VALUE_TO_BOOL(bool_obj); - - if (!bool_obj || !val) { - BT_LOGW("Invalid parameter: value object or value is NULL: " - "value-addr=%p, raw-value-addr=%p", - bool_obj, val); - ret = BT_VALUE_STATUS_INVAL; - goto end; - } - - if (!bt_value_is_bool(bool_obj)) { - BT_LOGW("Invalid parameter: value is not a boolean value: addr=%p, " - "type=%s", bool_obj, - bt_value_type_string(bool_obj->type)); - ret = BT_VALUE_STATUS_INVAL; - goto end; - } - - *val = typed_bool_obj->value; - -end: - return ret; + BT_ASSERT_PRE_NON_NULL(bool_obj, "Value object"); + BT_ASSERT_PRE_NON_NULL(val, "Raw value"); + BT_ASSERT_PRE_VALUE_IS_TYPE(bool_obj, BT_VALUE_TYPE_BOOL); + *val = BT_VALUE_TO_BOOL(bool_obj)->value; + return BT_VALUE_STATUS_OK; } enum bt_value_status bt_value_bool_set(struct bt_value *bool_obj, bt_bool val) { - enum bt_value_status ret = BT_VALUE_STATUS_OK; - struct bt_value_bool *typed_bool_obj = BT_VALUE_TO_BOOL(bool_obj); - - if (!bool_obj) { - BT_LOGW_STR("Invalid parameter: value object is NULL."); - ret = BT_VALUE_STATUS_INVAL; - goto end; - } - - if (!bt_value_is_bool(bool_obj)) { - BT_LOGW("Invalid parameter: value is not a boolean value: addr=%p, " - "type=%s", bool_obj, - bt_value_type_string(bool_obj->type)); - ret = BT_VALUE_STATUS_INVAL; - goto end; - } - - if (bool_obj->is_frozen) { - BT_LOGW("Invalid parameter: value is frozen: addr=%p", - bool_obj); - ret = BT_VALUE_STATUS_FROZEN; - goto end; - } - - typed_bool_obj->value = val; + BT_ASSERT_PRE_NON_NULL(bool_obj, "Value object"); + BT_ASSERT_PRE_VALUE_IS_TYPE(bool_obj, BT_VALUE_TYPE_BOOL); + BT_ASSERT_PRE_VALUE_HOT(bool_obj, "Value object"); + BT_VALUE_TO_BOOL(bool_obj)->value = val; BT_LOGV("Set boolean value's raw value: value-addr=%p, value=%d", bool_obj, val); - -end: - return ret; + return BT_VALUE_STATUS_OK; } enum bt_value_status bt_value_integer_get(const struct bt_value *integer_obj, int64_t *val) { - enum bt_value_status ret = BT_VALUE_STATUS_OK; - struct bt_value_integer *typed_integer_obj = - BT_VALUE_TO_INTEGER(integer_obj); - - if (!integer_obj || !val) { - BT_LOGW("Invalid parameter: value object or value is NULL: " - "value-addr=%p, raw-value-addr=%p", - integer_obj, val); - ret = BT_VALUE_STATUS_INVAL; - goto end; - } - - if (!bt_value_is_integer(integer_obj)) { - BT_LOGW("Invalid parameter: value is not an integer value: addr=%p, " - "type=%s", integer_obj, - bt_value_type_string(integer_obj->type)); - ret = BT_VALUE_STATUS_INVAL; - goto end; - } - - *val = typed_integer_obj->value; - -end: - return ret; + BT_ASSERT_PRE_NON_NULL(integer_obj, "Value object"); + BT_ASSERT_PRE_NON_NULL(val, "Raw value"); + BT_ASSERT_PRE_VALUE_IS_TYPE(integer_obj, BT_VALUE_TYPE_INTEGER); + *val = BT_VALUE_TO_INTEGER(integer_obj)->value; + return BT_VALUE_STATUS_OK; } enum bt_value_status bt_value_integer_set(struct bt_value *integer_obj, int64_t val) { - enum bt_value_status ret = BT_VALUE_STATUS_OK; - struct bt_value_integer *typed_integer_obj = - BT_VALUE_TO_INTEGER(integer_obj); - - if (!integer_obj) { - BT_LOGW_STR("Invalid parameter: value object is NULL."); - ret = BT_VALUE_STATUS_INVAL; - goto end; - } - - if (!bt_value_is_integer(integer_obj)) { - BT_LOGW("Invalid parameter: value is not an integer value: addr=%p, " - "type=%s", integer_obj, - bt_value_type_string(integer_obj->type)); - ret = BT_VALUE_STATUS_INVAL; - goto end; - } - - if (integer_obj->is_frozen) { - BT_LOGW("Invalid parameter: value is frozen: addr=%p", - integer_obj); - ret = BT_VALUE_STATUS_FROZEN; - goto end; - } - - typed_integer_obj->value = val; + BT_ASSERT_PRE_NON_NULL(integer_obj, "Value object"); + BT_ASSERT_PRE_VALUE_IS_TYPE(integer_obj, BT_VALUE_TYPE_INTEGER); + BT_ASSERT_PRE_VALUE_HOT(integer_obj, "Value object"); + BT_VALUE_TO_INTEGER(integer_obj)->value = val; BT_LOGV("Set integer value's raw value: value-addr=%p, value=%" PRId64, integer_obj, val); - -end: - return ret; + return BT_VALUE_STATUS_OK; } enum bt_value_status bt_value_float_get(const struct bt_value *float_obj, double *val) { - enum bt_value_status ret = BT_VALUE_STATUS_OK; - struct bt_value_float *typed_float_obj = - BT_VALUE_TO_FLOAT(float_obj); - - if (!float_obj || !val) { - BT_LOGW("Invalid parameter: value object or value is NULL: " - "value-addr=%p, raw-value-addr=%p", - float_obj, val); - ret = BT_VALUE_STATUS_INVAL; - goto end; - } - - if (!bt_value_is_float(float_obj)) { - BT_LOGW("Invalid parameter: value is not a floating point number value: addr=%p, " - "type=%s", float_obj, - bt_value_type_string(float_obj->type)); - ret = BT_VALUE_STATUS_INVAL; - goto end; - } - - *val = typed_float_obj->value; - -end: - return ret; + BT_ASSERT_PRE_NON_NULL(float_obj, "Value object"); + BT_ASSERT_PRE_NON_NULL(val, "Raw value"); + BT_ASSERT_PRE_VALUE_IS_TYPE(float_obj, BT_VALUE_TYPE_FLOAT); + *val = BT_VALUE_TO_FLOAT(float_obj)->value; + return BT_VALUE_STATUS_OK; } enum bt_value_status bt_value_float_set(struct bt_value *float_obj, double val) { - enum bt_value_status ret = BT_VALUE_STATUS_OK; - struct bt_value_float *typed_float_obj = - BT_VALUE_TO_FLOAT(float_obj); - - if (!float_obj) { - BT_LOGW_STR("Invalid parameter: value object is NULL."); - ret = BT_VALUE_STATUS_INVAL; - goto end; - } - - if (!bt_value_is_float(float_obj)) { - BT_LOGW("Invalid parameter: value is not a floating point number value: addr=%p, " - "type=%s", float_obj, - bt_value_type_string(float_obj->type)); - ret = BT_VALUE_STATUS_INVAL; - goto end; - } - - if (float_obj->is_frozen) { - BT_LOGW("Invalid parameter: value is frozen: addr=%p", - float_obj); - ret = BT_VALUE_STATUS_FROZEN; - goto end; - } - - typed_float_obj->value = val; + BT_ASSERT_PRE_NON_NULL(float_obj, "Value object"); + BT_ASSERT_PRE_VALUE_IS_TYPE(float_obj, BT_VALUE_TYPE_FLOAT); + BT_ASSERT_PRE_VALUE_HOT(float_obj, "Value object"); + BT_VALUE_TO_FLOAT(float_obj)->value = val; BT_LOGV("Set floating point number value's raw value: value-addr=%p, value=%f", float_obj, val); - -end: - return ret; + return BT_VALUE_STATUS_OK; } enum bt_value_status bt_value_string_get(const struct bt_value *string_obj, const char **val) { - enum bt_value_status ret = BT_VALUE_STATUS_OK; - struct bt_value_string *typed_string_obj = - BT_VALUE_TO_STRING(string_obj); - - if (!string_obj || !val) { - BT_LOGW("Invalid parameter: value object or value is NULL: " - "value-addr=%p, raw-value-addr=%p", - string_obj, val); - ret = BT_VALUE_STATUS_INVAL; - goto end; - } - - if (!bt_value_is_string(string_obj)) { - BT_LOGW("Invalid parameter: value is not a string value: addr=%p, " - "type=%s", string_obj, - bt_value_type_string(string_obj->type)); - ret = BT_VALUE_STATUS_INVAL; - goto end; - } - - *val = typed_string_obj->gstr->str; - -end: - return ret; + BT_ASSERT_PRE_NON_NULL(string_obj, "Value object"); + BT_ASSERT_PRE_NON_NULL(val, "Raw value"); + BT_ASSERT_PRE_VALUE_IS_TYPE(string_obj, BT_VALUE_TYPE_STRING); + *val = BT_VALUE_TO_STRING(string_obj)->gstr->str; + return BT_VALUE_STATUS_OK; } enum bt_value_status bt_value_string_set(struct bt_value *string_obj, const char *val) { - enum bt_value_status ret = BT_VALUE_STATUS_OK; - struct bt_value_string *typed_string_obj = - BT_VALUE_TO_STRING(string_obj); - - if (!string_obj || !val) { - BT_LOGW("Invalid parameter: value object or value is NULL: " - "value-addr=%p, raw-value-addr=%p", - string_obj, val); - ret = BT_VALUE_STATUS_INVAL; - goto end; - } - - if (!bt_value_is_string(string_obj)) { - BT_LOGW("Invalid parameter: value is not a string value: addr=%p, " - "type=%s", string_obj, - bt_value_type_string(string_obj->type)); - ret = BT_VALUE_STATUS_INVAL; - goto end; - } - - if (string_obj->is_frozen) { - BT_LOGW("Invalid parameter: value is frozen: addr=%p", - string_obj); - ret = BT_VALUE_STATUS_FROZEN; - goto end; - } - - g_string_assign(typed_string_obj->gstr, val); + BT_ASSERT_PRE_NON_NULL(string_obj, "Value object"); + BT_ASSERT_PRE_NON_NULL(val, "Raw value"); + BT_ASSERT_PRE_VALUE_IS_TYPE(string_obj, BT_VALUE_TYPE_STRING); + BT_ASSERT_PRE_VALUE_HOT(string_obj, "Value object"); + g_string_assign(BT_VALUE_TO_STRING(string_obj)->gstr, val); BT_LOGV("Set string value's raw value: value-addr=%p, raw-value-addr=%p", string_obj, val); - -end: - return ret; + return BT_VALUE_STATUS_OK; } int64_t bt_value_array_size(const struct bt_value *array_obj) { - int64_t ret; - struct bt_value_array *typed_array_obj = - BT_VALUE_TO_ARRAY(array_obj); - - if (!array_obj) { - BT_LOGW_STR("Invalid parameter: value object is NULL."); - ret = (int64_t) BT_VALUE_STATUS_INVAL; - goto end; - } - - if (!bt_value_is_array(array_obj)) { - BT_LOGW("Invalid parameter: value is not an array value: addr=%p, " - "type=%s", array_obj, - bt_value_type_string(array_obj->type)); - ret = BT_VALUE_STATUS_INVAL; - goto end; - } - - ret = (int64_t) typed_array_obj->garray->len; - -end: - return ret; + BT_ASSERT_PRE_NON_NULL(array_obj, "Value object"); + BT_ASSERT_PRE_VALUE_IS_TYPE(array_obj, BT_VALUE_TYPE_ARRAY); + return (int64_t) BT_VALUE_TO_ARRAY(array_obj)->garray->len; } bt_bool bt_value_array_is_empty(const struct bt_value *array_obj) @@ -1057,78 +857,32 @@ bt_bool bt_value_array_is_empty(const struct bt_value *array_obj) struct bt_value *bt_value_array_get(const struct bt_value *array_obj, uint64_t index) { - struct bt_value *ret; struct bt_value_array *typed_array_obj = BT_VALUE_TO_ARRAY(array_obj); - if (!array_obj) { - BT_LOGW("Invalid parameter: value object is NULL: index=%" PRIu64, - index); - ret = NULL; - goto end; - } - - if (!bt_value_is_array(array_obj)) { - BT_LOGW("Invalid parameter: value is not an array value: addr=%p, " - "type=%s", array_obj, - bt_value_type_string(array_obj->type)); - ret = NULL; - goto end; - } - - if (index >= typed_array_obj->garray->len) { - BT_LOGW("Invalid parameter: index is out of bounds: " - "addr=%p, index=%" PRIu64 ", size=%u", - array_obj, index, typed_array_obj->garray->len); - ret = NULL; - goto end; - } - - ret = g_ptr_array_index(typed_array_obj->garray, index); - bt_get(ret); - -end: - return ret; + BT_ASSERT_PRE_NON_NULL(array_obj, "Value object"); + BT_ASSERT_PRE_VALUE_IS_TYPE(array_obj, BT_VALUE_TYPE_ARRAY); + BT_ASSERT_PRE_VALUE_INDEX_IN_BOUNDS(index, + typed_array_obj->garray->len); + return bt_get(g_ptr_array_index(typed_array_obj->garray, index)); } enum bt_value_status bt_value_array_append(struct bt_value *array_obj, struct bt_value *element_obj) { - enum bt_value_status ret = BT_VALUE_STATUS_OK; struct bt_value_array *typed_array_obj = BT_VALUE_TO_ARRAY(array_obj); - if (!array_obj || !element_obj) { - BT_LOGW("Invalid parameter: array value or element value is NULL: " - "array-value-addr=%p, element-value-addr=%p", - array_obj, element_obj); - ret = BT_VALUE_STATUS_INVAL; - goto end; - } - - if (!bt_value_is_array(array_obj)) { - BT_LOGW("Invalid parameter: value is not an array value: addr=%p, " - "type=%s", array_obj, - bt_value_type_string(array_obj->type)); - ret = BT_VALUE_STATUS_INVAL; - goto end; - } - - if (array_obj->is_frozen) { - BT_LOGW("Invalid parameter: value is frozen: addr=%p", - array_obj); - ret = BT_VALUE_STATUS_FROZEN; - goto end; - } - + BT_ASSERT_PRE_NON_NULL(array_obj, "Array value object"); + BT_ASSERT_PRE_NON_NULL(element_obj, "Element value object"); + BT_ASSERT_PRE_VALUE_IS_TYPE(array_obj, BT_VALUE_TYPE_ARRAY); + BT_ASSERT_PRE_VALUE_HOT(array_obj, "Array value object"); g_ptr_array_add(typed_array_obj->garray, element_obj); bt_get(element_obj); BT_LOGV("Appended element to array value: array-value-addr=%p, " "element-value-addr=%p, new-size=%u", array_obj, element_obj, typed_array_obj->garray->len); - -end: - return ret; + return BT_VALUE_STATUS_OK; } enum bt_value_status bt_value_array_append_bool(struct bt_value *array_obj, @@ -1205,75 +959,29 @@ enum bt_value_status bt_value_array_append_empty_map(struct bt_value *array_obj) enum bt_value_status bt_value_array_set(struct bt_value *array_obj, uint64_t index, struct bt_value *element_obj) { - enum bt_value_status ret = BT_VALUE_STATUS_OK; struct bt_value_array *typed_array_obj = BT_VALUE_TO_ARRAY(array_obj); - if (!array_obj || !element_obj) { - BT_LOGW("Invalid parameter: array value or element value is NULL: " - "index=%" PRIu64 ", array-value-addr=%p, element-value-addr=%p", - index, array_obj, element_obj); - ret = BT_VALUE_STATUS_INVAL; - goto end; - } - - if (!bt_value_is_array(array_obj)) { - BT_LOGW("Invalid parameter: value is not an array value: addr=%p, " - "type=%s", array_obj, - bt_value_type_string(array_obj->type)); - ret = BT_VALUE_STATUS_INVAL; - goto end; - } - - if (index >= typed_array_obj->garray->len) { - BT_LOGW("Invalid parameter: index is out of bounds: " - "addr=%p, index=%" PRIu64 ", size=%u", - array_obj, index, typed_array_obj->garray->len); - ret = BT_VALUE_STATUS_INVAL; - goto end; - } - - if (array_obj->is_frozen) { - BT_LOGW("Invalid parameter: value is frozen: addr=%p", - array_obj); - ret = BT_VALUE_STATUS_FROZEN; - goto end; - } - + BT_ASSERT_PRE_NON_NULL(array_obj, "Array value object"); + BT_ASSERT_PRE_NON_NULL(element_obj, "Element value object"); + BT_ASSERT_PRE_VALUE_IS_TYPE(array_obj, BT_VALUE_TYPE_ARRAY); + BT_ASSERT_PRE_VALUE_HOT(array_obj, "Array value object"); + BT_ASSERT_PRE_VALUE_INDEX_IN_BOUNDS(index, + typed_array_obj->garray->len); bt_put(g_ptr_array_index(typed_array_obj->garray, index)); g_ptr_array_index(typed_array_obj->garray, index) = element_obj; bt_get(element_obj); BT_LOGV("Set array value's element: array-value-addr=%p, " "index=%" PRIu64 ", element-value-addr=%p", array_obj, index, element_obj); - -end: - return ret; + return BT_VALUE_STATUS_OK; } int64_t bt_value_map_size(const struct bt_value *map_obj) { - int64_t ret; - struct bt_value_map *typed_map_obj = BT_VALUE_TO_MAP(map_obj); - - if (!map_obj) { - BT_LOGW_STR("Invalid parameter: value object is NULL."); - ret = (int64_t) BT_VALUE_STATUS_INVAL; - goto end; - } - - if (!bt_value_is_map(map_obj)) { - BT_LOGW("Invalid parameter: value is not a map value: addr=%p, " - "type=%s", map_obj, - bt_value_type_string(map_obj->type)); - ret = (int64_t) BT_VALUE_STATUS_INVAL; - goto end; - } - - ret = (int64_t) g_hash_table_size(typed_map_obj->ght); - -end: - return ret; + BT_ASSERT_PRE_NON_NULL(map_obj, "Value object"); + BT_ASSERT_PRE_VALUE_IS_TYPE(map_obj, BT_VALUE_TYPE_MAP); + return (int64_t) g_hash_table_size(BT_VALUE_TO_MAP(map_obj)->ght); } bt_bool bt_value_map_is_empty(const struct bt_value *map_obj) @@ -1284,104 +992,37 @@ bt_bool bt_value_map_is_empty(const struct bt_value *map_obj) struct bt_value *bt_value_map_get(const struct bt_value *map_obj, const char *key) { - GQuark quark; - struct bt_value *ret; - struct bt_value_map *typed_map_obj = BT_VALUE_TO_MAP(map_obj); - - if (!map_obj || !key) { - BT_LOGW("Invalid parameter: value object or key is NULL: " - "value-addr=%p, key-addr=%p", map_obj, key); - ret = NULL; - goto end; - } - - if (!bt_value_is_map(map_obj)) { - BT_LOGW("Invalid parameter: value is not a map value: addr=%p, " - "type=%s", map_obj, - bt_value_type_string(map_obj->type)); - ret = NULL; - goto end; - } - - quark = g_quark_from_string(key); - ret = g_hash_table_lookup(typed_map_obj->ght, GUINT_TO_POINTER(quark)); - if (ret) { - bt_get(ret); - } - -end: - return ret; + BT_ASSERT_PRE_NON_NULL(map_obj, "Value object"); + BT_ASSERT_PRE_NON_NULL(key, "Key"); + BT_ASSERT_PRE_VALUE_IS_TYPE(map_obj, BT_VALUE_TYPE_MAP); + return bt_get(g_hash_table_lookup(BT_VALUE_TO_MAP(map_obj)->ght, + GUINT_TO_POINTER(g_quark_from_string(key)))); } bt_bool bt_value_map_has_key(const struct bt_value *map_obj, const char *key) { - bt_bool ret; - GQuark quark; - struct bt_value_map *typed_map_obj = BT_VALUE_TO_MAP(map_obj); - - if (!map_obj || !key) { - BT_LOGW("Invalid parameter: value object or key is NULL: " - "value-addr=%p, key-addr=%p", map_obj, key); - ret = BT_FALSE; - goto end; - } - - if (!bt_value_is_map(map_obj)) { - BT_LOGW("Invalid parameter: value is not a map value: addr=%p, " - "type=%s", map_obj, - bt_value_type_string(map_obj->type)); - ret = BT_FALSE; - goto end; - } - - quark = g_quark_from_string(key); - ret = bt_g_hash_table_contains(typed_map_obj->ght, - GUINT_TO_POINTER(quark)); - -end: - return ret; + BT_ASSERT_PRE_NON_NULL(map_obj, "Value object"); + BT_ASSERT_PRE_NON_NULL(key, "Key"); + BT_ASSERT_PRE_VALUE_IS_TYPE(map_obj, BT_VALUE_TYPE_MAP); + return bt_g_hash_table_contains(BT_VALUE_TO_MAP(map_obj)->ght, + GUINT_TO_POINTER(g_quark_from_string(key))); } enum bt_value_status bt_value_map_insert(struct bt_value *map_obj, const char *key, struct bt_value *element_obj) { - GQuark quark; - enum bt_value_status ret = BT_VALUE_STATUS_OK; - struct bt_value_map *typed_map_obj = BT_VALUE_TO_MAP(map_obj); - - if (!map_obj || !key || !element_obj) { - BT_LOGW("Invalid parameter: map value, key, or element value is NULL: " - "map-value-addr=%p, key-addr=%p, element-value-addr=%p", - map_obj, key, element_obj); - ret = BT_VALUE_STATUS_INVAL; - goto end; - } - - if (!bt_value_is_map(map_obj)) { - BT_LOGW("Invalid parameter: value is not a map value: addr=%p, " - "type=%s", map_obj, - bt_value_type_string(map_obj->type)); - ret = BT_VALUE_STATUS_INVAL; - goto end; - } - - if (map_obj->is_frozen) { - BT_LOGW("Invalid parameter: value is frozen: addr=%p", - map_obj); - ret = BT_VALUE_STATUS_FROZEN; - goto end; - } - - quark = g_quark_from_string(key); - g_hash_table_insert(typed_map_obj->ght, - GUINT_TO_POINTER(quark), element_obj); + BT_ASSERT_PRE_NON_NULL(map_obj, "Map value object"); + BT_ASSERT_PRE_NON_NULL(key, "Key"); + BT_ASSERT_PRE_NON_NULL(element_obj, "Element value object"); + BT_ASSERT_PRE_VALUE_IS_TYPE(map_obj, BT_VALUE_TYPE_MAP); + BT_ASSERT_PRE_VALUE_HOT(map_obj, "Map value object"); + g_hash_table_insert(BT_VALUE_TO_MAP(map_obj)->ght, + GUINT_TO_POINTER(g_quark_from_string(key)), element_obj); bt_get(element_obj); BT_LOGV("Inserted value into map value: map-value-addr=%p, " "key=\"%s\", element-value-addr=%p", map_obj, key, element_obj); - -end: - return ret; + return BT_VALUE_STATUS_OK; } enum bt_value_status bt_value_map_insert_bool(struct bt_value *map_obj, @@ -1464,36 +1105,23 @@ enum bt_value_status bt_value_map_foreach(const struct bt_value *map_obj, GHashTableIter iter; struct bt_value_map *typed_map_obj = BT_VALUE_TO_MAP(map_obj); - if (!map_obj || !cb) { - BT_LOGW("Invalid parameter: map value or callback is NULL: " - "value-addr=%p, cb-addr=%p", map_obj, cb); - ret = BT_VALUE_STATUS_INVAL; - goto end; - } - - if (!bt_value_is_map(map_obj)) { - BT_LOGW("Invalid parameter: value is not a map value: addr=%p, " - "type=%s", map_obj, - bt_value_type_string(map_obj->type)); - ret = BT_VALUE_STATUS_INVAL; - goto end; - } - + BT_ASSERT_PRE_NON_NULL(map_obj, "Value object"); + BT_ASSERT_PRE_NON_NULL(cb, "Callback"); + BT_ASSERT_PRE_VALUE_IS_TYPE(map_obj, BT_VALUE_TYPE_MAP); g_hash_table_iter_init(&iter, typed_map_obj->ght); while (g_hash_table_iter_next(&iter, &key, &element_obj)) { const char *key_str = g_quark_to_string(GPOINTER_TO_UINT(key)); if (!cb(key_str, element_obj, data)) { - BT_LOGV("User cancelled the loop: key=\"%s\", " + BT_LOGV("User canceled the loop: key=\"%s\", " "value-addr=%p, data=%p", key_str, element_obj, data); - ret = BT_VALUE_STATUS_CANCELLED; + ret = BT_VALUE_STATUS_CANCELED; break; } } -end: return ret; } @@ -1541,27 +1169,10 @@ struct bt_value *bt_value_map_extend(struct bt_value *base_map_obj, struct bt_value *extended_obj = NULL; struct extend_map_element_data extend_data = { 0 }; - if (!base_map_obj || !extension_obj) { - BT_LOGW("Invalid parameter: base value or extension value is NULL: " - "base-value-addr=%p, extension-value-addr=%p", - base_map_obj, extension_obj); - goto error; - } - - if (!bt_value_is_map(base_map_obj)) { - BT_LOGW("Invalid parameter: value is not a map value: addr=%p, " - "type=%s", base_map_obj, - bt_value_type_string(base_map_obj->type)); - goto error; - } - - if (!bt_value_is_map(extension_obj)) { - BT_LOGW("Invalid parameter: value is not a map value: addr=%p, " - "type=%s", extension_obj, - bt_value_type_string(extension_obj->type)); - goto error; - } - + BT_ASSERT_PRE_NON_NULL(base_map_obj, "Base value object"); + BT_ASSERT_PRE_NON_NULL(extension_obj, "Extension value object"); + BT_ASSERT_PRE_VALUE_IS_TYPE(base_map_obj, BT_VALUE_TYPE_MAP); + BT_ASSERT_PRE_VALUE_IS_TYPE(extension_obj, BT_VALUE_TYPE_MAP); BT_LOGD("Extending map value: base-value-addr=%p, extension-value-addr=%p", base_map_obj, extension_obj); @@ -1607,11 +1218,7 @@ struct bt_value *bt_value_copy(const struct bt_value *object) { struct bt_value *copy_obj = NULL; - if (!object) { - BT_LOGW_STR("Invalid parameter: value object is NULL."); - goto end; - } - + BT_ASSERT_PRE_NON_NULL(object, "Value object"); BT_LOGD("Copying value object: addr=%p", object); copy_obj = copy_funcs[object->type](object); if (copy_obj) { @@ -1621,7 +1228,6 @@ struct bt_value *bt_value_copy(const struct bt_value *object) BT_LOGE_STR("Failed to copy value object."); } -end: return copy_obj; } @@ -1630,12 +1236,8 @@ bt_bool bt_value_compare(const struct bt_value *object_a, { bt_bool ret = BT_FALSE; - if (!object_a || !object_b) { - BT_LOGW("Invalid parameter: value A or value B is NULL: " - "value-a-addr=%p, value-b-addr=%p", - object_a, object_b); - goto end; - } + BT_ASSERT_PRE_NON_NULL(object_a, "Value object A"); + BT_ASSERT_PRE_NON_NULL(object_b, "Value object B"); if (object_a->type != object_b->type) { BT_LOGV("Values are different: type mismatch: " diff --git a/logging/log.c b/logging/log.c index 13fcab8e..f2fa0cb6 100644 --- a/logging/log.c +++ b/logging/log.c @@ -288,7 +288,7 @@ extern unsigned long pthread_getsequence_np(pthread_t *); #undef __STRICT_ANSI__ #endif #endif -#include +#include #include #include #include diff --git a/plugins/ctf/common/btr/btr.c b/plugins/ctf/common/btr/btr.c index b6ccc5d4..ac6ce1a0 100644 --- a/plugins/ctf/common/btr/btr.c +++ b/plugins/ctf/common/btr/btr.c @@ -32,7 +32,7 @@ #include #include #include -#include +#include #include #include #include @@ -264,8 +264,8 @@ int stack_push(struct stack *stack, struct bt_field_type *base_type, int ret = 0; struct stack_entry *entry; - assert(stack); - assert(base_type); + BT_ASSERT(stack); + BT_ASSERT(base_type); BT_LOGV("Pushing field type on stack: stack-addr=%p, " "ft-addr=%p, ft-id=%s, base-length=%zu, " @@ -315,7 +315,7 @@ end: static inline unsigned int stack_size(struct stack *stack) { - assert(stack); + BT_ASSERT(stack); return stack->entries->len; } @@ -323,8 +323,8 @@ unsigned int stack_size(struct stack *stack) static void stack_pop(struct stack *stack) { - assert(stack); - assert(stack_size(stack)); + BT_ASSERT(stack); + BT_ASSERT(stack_size(stack)); BT_LOGV("Popping from stack: " "stack-addr=%p, stack-size-before=%u, stack-size-after=%u", stack, stack->entries->len, stack->entries->len - 1); @@ -340,20 +340,20 @@ bool stack_empty(struct stack *stack) static void stack_clear(struct stack *stack) { - assert(stack); + BT_ASSERT(stack); if (!stack_empty(stack)) { g_ptr_array_remove_range(stack->entries, 0, stack_size(stack)); } - assert(stack_empty(stack)); + BT_ASSERT(stack_empty(stack)); } static inline struct stack_entry *stack_top(struct stack *stack) { - assert(stack); - assert(stack_size(stack)); + BT_ASSERT(stack); + BT_ASSERT(stack_size(stack)); return g_ptr_array_index(stack->entries, stack->entries->len - 1); } @@ -429,8 +429,8 @@ int get_basic_field_type_size(struct bt_btr *btr, mant_dig = bt_field_type_floating_point_get_mantissa_digits( field_type); - assert(exp_dig >= 0); - assert(mant_dig >= 0); + BT_ASSERT(exp_dig >= 0); + BT_ASSERT(mant_dig >= 0); size = exp_dig + mant_dig; break; } @@ -440,7 +440,7 @@ int get_basic_field_type_size(struct bt_btr *btr, int_type = bt_field_type_enumeration_get_container_type( field_type); - assert(int_type); + BT_ASSERT(int_type); size = get_basic_field_type_size(btr, int_type); BT_PUT(int_type); break; @@ -481,8 +481,8 @@ void stitch_append_from_buf(struct bt_btr *btr, size_t sz) BITS_TO_BYTES_FLOOR(stitch_at_from_addr(btr)); buf_byte_at = BITS_TO_BYTES_FLOOR(buf_at_from_addr(btr)); nb_bytes = BITS_TO_BYTES_CEIL(sz); - assert(nb_bytes > 0); - assert(btr->buf.addr); + BT_ASSERT(nb_bytes > 0); + BT_ASSERT(btr->buf.addr); memcpy(&btr->stitch.buf[stitch_byte_at], &btr->buf.addr[buf_byte_at], nb_bytes); btr->stitch.at += sz; @@ -631,10 +631,10 @@ enum bt_btr_status read_basic_float_and_call_cb(struct bt_btr *btr, ret = bt_field_type_floating_point_get_mantissa_digits( btr->cur_basic_field_type); - assert(ret == 24); + BT_ASSERT(ret == 24); ret = bt_field_type_floating_point_get_exponent_digits( btr->cur_basic_field_type); - assert(ret == 8); + BT_ASSERT(ret == 8); status = read_unsigned_bitfield(buf, at, field_size, bo, &v); if (status != BT_BTR_STATUS_OK) { BT_LOGW("Cannot read unsigned 32-bit bit array for floating point number field: " @@ -656,10 +656,10 @@ enum bt_btr_status read_basic_float_and_call_cb(struct bt_btr *btr, ret = bt_field_type_floating_point_get_mantissa_digits( btr->cur_basic_field_type); - assert(ret == 53); + BT_ASSERT(ret == 53); ret = bt_field_type_floating_point_get_exponent_digits( btr->cur_basic_field_type); - assert(ret == 11); + BT_ASSERT(ret == 11); status = read_unsigned_bitfield(buf, at, field_size, bo, &f64.u); if (status != BT_BTR_STATUS_OK) { @@ -798,7 +798,7 @@ enum bt_btr_status read_basic_enum_and_call_cb(struct bt_btr *btr, int_field_type = bt_field_type_enumeration_get_container_type( btr->cur_basic_field_type); - assert(int_field_type); + BT_ASSERT(int_field_type); status = read_basic_int_and_call(btr, buf, at, int_field_type, btr->cur_basic_field_type); bt_put(int_field_type); @@ -904,7 +904,7 @@ enum bt_btr_status read_basic_type_and_call_begin(struct bt_btr *btr, if (field_size <= available) { /* We have all the bits; decode and set now */ - assert(btr->buf.addr); + BT_ASSERT(btr->buf.addr); status = read_basic_and_call_cb(btr, btr->buf.addr, buf_at_from_addr(btr)); if (status != BT_BTR_STATUS_OK) { @@ -1003,10 +1003,10 @@ enum bt_btr_status read_basic_string_type_and_call( goto end; } - assert(buf_at_from_addr(btr) % 8 == 0); + BT_ASSERT(buf_at_from_addr(btr) % 8 == 0); available_bytes = BITS_TO_BYTES_FLOOR(available_bits(btr)); buf_at_bytes = BITS_TO_BYTES_FLOOR(buf_at_from_addr(btr)); - assert(btr->buf.addr); + BT_ASSERT(btr->buf.addr); first_chr = &btr->buf.addr[buf_at_bytes]; result = memchr(first_chr, '\0', available_bytes); @@ -1100,7 +1100,7 @@ enum bt_btr_status read_basic_begin_state(struct bt_btr *btr) { enum bt_btr_status status; - assert(btr->cur_basic_field_type); + BT_ASSERT(btr->cur_basic_field_type); switch (bt_field_type_get_type_id(btr->cur_basic_field_type)) { case BT_FIELD_TYPE_ID_INTEGER: @@ -1133,7 +1133,7 @@ enum bt_btr_status read_basic_continue_state(struct bt_btr *btr) { enum bt_btr_status status; - assert(btr->cur_basic_field_type); + BT_ASSERT(btr->cur_basic_field_type); switch (bt_field_type_get_type_id(btr->cur_basic_field_type)) { case BT_FIELD_TYPE_ID_INTEGER: @@ -1465,8 +1465,8 @@ size_t bt_btr_start(struct bt_btr *btr, size_t offset, size_t packet_offset, size_t sz, enum bt_btr_status *status) { - assert(btr); - assert(BYTES_TO_BITS(sz) >= offset); + BT_ASSERT(btr); + BT_ASSERT(BYTES_TO_BITS(sz) >= offset); reset(btr); btr->buf.addr = buf; btr->buf.offset = offset; @@ -1536,9 +1536,9 @@ size_t bt_btr_continue(struct bt_btr *btr, const uint8_t *buf, size_t sz, enum bt_btr_status *status) { - assert(btr); - assert(buf); - assert(sz > 0); + BT_ASSERT(btr); + BT_ASSERT(buf); + BT_ASSERT(sz > 0); btr->buf.addr = buf; btr->buf.offset = 0; btr->buf.at = 0; diff --git a/plugins/ctf/common/metadata/decoder.c b/plugins/ctf/common/metadata/decoder.c index c52b4fc6..aa3b799f 100644 --- a/plugins/ctf/common/metadata/decoder.c +++ b/plugins/ctf/common/metadata/decoder.c @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include #include #include @@ -417,7 +417,7 @@ enum ctf_metadata_decoder_status ctf_metadata_decoder_decode( char *buf = NULL; bool close_fp = false; - assert(mdec); + BT_ASSERT(mdec); if (ctf_metadata_decoder_is_packetized(fp, &mdec->bo)) { BT_LOGD("Metadata stream is packetized: mdec-addr=%p", mdec); @@ -495,7 +495,7 @@ enum ctf_metadata_decoder_status ctf_metadata_decoder_decode( goto end; } - assert(fp); + BT_ASSERT(fp); ret = ctf_scanner_append_ast(scanner, fp); if (ret) { BT_LOGE("Cannot create the metadata AST out of the metadata text: " diff --git a/plugins/ctf/common/metadata/parser.y b/plugins/ctf/common/metadata/parser.y index 83080063..2d1f3831 100644 --- a/plugins/ctf/common/metadata/parser.y +++ b/plugins/ctf/common/metadata/parser.y @@ -38,6 +38,7 @@ #include #include #include +#include #include "scanner.h" #include "parser.h" #include "ast.h" @@ -163,7 +164,7 @@ int parse_base_sequence(const char *src, size_t len, size_t pos, return -1; } } - assert(nr_char > 0); + BT_ASSERT(nr_char > 0); buffer[nr_char] = '\0'; *buf_len = nr_char; return 0; diff --git a/plugins/ctf/common/metadata/visitor-generate-ir.c b/plugins/ctf/common/metadata/visitor-generate-ir.c index 734ed996..ee6e1166 100644 --- a/plugins/ctf/common/metadata/visitor-generate-ir.c +++ b/plugins/ctf/common/metadata/visitor-generate-ir.c @@ -36,7 +36,7 @@ #include #include #include -#include +#include #include #include #include @@ -278,7 +278,7 @@ GQuark get_prefixed_named_quark(char prefix, const char *name) { GQuark qname = 0; - assert(name); + BT_ASSERT(name); /* Prefix character + original string + '\0' */ char *prname = g_new(char, strlen(name) + 2); @@ -314,8 +314,8 @@ struct bt_field_type *ctx_decl_scope_lookup_prefix_alias( _BT_FIELD_TYPE_INIT(decl); struct ctx_decl_scope *cur_scope = scope; - assert(scope); - assert(name); + BT_ASSERT(scope); + BT_ASSERT(name); qname = get_prefixed_named_quark(prefix, name); if (!qname) { goto error; @@ -425,9 +425,9 @@ int ctx_decl_scope_register_prefix_alias(struct ctx_decl_scope *scope, GQuark qname = 0; _BT_FIELD_TYPE_INIT(edecl); - assert(scope); - assert(name); - assert(decl); + BT_ASSERT(scope); + BT_ASSERT(name); + BT_ASSERT(decl); qname = get_prefixed_named_quark(prefix, name); if (!qname) { ret = -ENOMEM; @@ -571,7 +571,7 @@ struct ctx *ctx_create(struct bt_trace *trace, struct ctx *ctx = NULL; struct ctx_decl_scope *scope = NULL; - assert(decoder_config); + BT_ASSERT(decoder_config); ctx = g_new0(struct ctx, 1); if (!ctx) { @@ -627,7 +627,7 @@ int ctx_push_scope(struct ctx *ctx) int ret = 0; struct ctx_decl_scope *new_scope; - assert(ctx); + BT_ASSERT(ctx); new_scope = ctx_decl_scope_create(ctx->current_scope); if (!new_scope) { BT_LOGE_STR("Cannot create declaration scope."); @@ -646,7 +646,7 @@ void ctx_pop_scope(struct ctx *ctx) { struct ctx_decl_scope *parent_scope = NULL; - assert(ctx); + BT_ASSERT(ctx); if (!ctx->current_scope) { goto end; @@ -675,7 +675,7 @@ char *remove_underscores_from_field_ref(const char *field_ref) UNDERSCORE_REMOVE_STATE_DO_NOT_REMOVE_NEXT_UNDERSCORE, } state = UNDERSCORE_REMOVE_STATE_REMOVE_NEXT_UNDERSCORE; - assert(field_ref); + BT_ASSERT(field_ref); ret = calloc(strlen(field_ref) + 1, 1); if (!ret) { BT_LOGE("Failed to allocate a string: size=%zu", @@ -746,7 +746,7 @@ char *concatenate_unary_strings(struct bt_list_head *head) struct ctf_node *node; str = g_string_new(NULL); - assert(str); + BT_ASSERT(str); bt_list_for_each_entry(node, head, siblings) { char *src_string; @@ -1350,19 +1350,19 @@ int visit_type_declarator(struct ctx *ctx, struct ctf_node *type_specifier_list, ret = bt_field_type_integer_set_base( nested_decl, BT_INTEGER_BASE_HEXADECIMAL); - assert(ret == 0); + BT_ASSERT(ret == 0); } } else { ret = visit_type_specifier_list(ctx, type_specifier_list, &nested_decl); if (ret) { - assert(!nested_decl); + BT_ASSERT(!nested_decl); goto error; } } } - assert(nested_decl); + BT_ASSERT(nested_decl); if (!node_type_declarator) { BT_MOVE(*field_decl, nested_decl); @@ -1471,9 +1471,9 @@ int visit_type_declarator(struct ctx *ctx, struct ctf_node *type_specifier_list, goto error; } - assert(!nested_decl); - assert(decl); - assert(!*field_decl); + BT_ASSERT(!nested_decl); + BT_ASSERT(decl); + BT_ASSERT(!*field_decl); /* * At this point, we found the next nested declaration. @@ -1489,18 +1489,18 @@ int visit_type_declarator(struct ctx *ctx, struct ctf_node *type_specifier_list, &outer_field_decl, decl); decl = NULL; if (ret) { - assert(!outer_field_decl); + BT_ASSERT(!outer_field_decl); ret = -EINVAL; goto error; } - assert(outer_field_decl); + BT_ASSERT(outer_field_decl); BT_MOVE(*field_decl, outer_field_decl); } end: BT_PUT(nested_decl); - assert(*field_decl); + BT_ASSERT(*field_decl); return 0; @@ -1530,13 +1530,13 @@ int visit_struct_decl_field(struct ctx *ctx, ret = visit_type_declarator(ctx, type_specifier_list, &qfield_name, iter, &field_decl, NULL); if (ret) { - assert(!field_decl); + BT_ASSERT(!field_decl); _BT_LOGE_NODE(type_specifier_list, "Cannot visit type declarator: ret=%d", ret); goto error; } - assert(field_decl); + BT_ASSERT(field_decl); field_name = g_quark_to_string(qfield_name); /* Check if field with same name already exists */ @@ -1592,13 +1592,13 @@ int visit_variant_decl_field(struct ctx *ctx, ret = visit_type_declarator(ctx, type_specifier_list, &qfield_name, iter, &field_decl, NULL); if (ret) { - assert(!field_decl); + BT_ASSERT(!field_decl); _BT_LOGE_NODE(type_specifier_list, "Cannot visit type declarator: ret=%d", ret); goto error; } - assert(field_decl); + BT_ASSERT(field_decl); field_name = g_quark_to_string(qfield_name); /* Check if field with same name already exists */ @@ -1703,7 +1703,7 @@ int visit_typealias(struct ctx *ctx, struct ctf_node *target, target->u.typealias_target.type_specifier_list, &qdummy_field_name, node, &type_decl, NULL); if (ret) { - assert(!type_decl); + BT_ASSERT(!type_decl); _BT_LOGE_NODE(node, "Cannot visit type declarator: ret=%d", ret); goto end; @@ -2101,8 +2101,8 @@ int visit_variant_decl(struct ctx *ctx, const char *name, BT_MOVE(*variant_decl, untagged_variant_decl); } - assert(!untagged_variant_decl); - assert(*variant_decl); + BT_ASSERT(!untagged_variant_decl); + BT_ASSERT(*variant_decl); return 0; @@ -2289,13 +2289,13 @@ int visit_enum_decl(struct ctx *ctx, const char *name, ret = visit_type_declarator(ctx, container_type, &qdummy_id, NULL, &integer_decl, NULL); if (ret) { - assert(!integer_decl); + BT_ASSERT(!integer_decl); ret = -EINVAL; goto error; } } - assert(integer_decl); + BT_ASSERT(integer_decl); if (!bt_field_type_is_integer(integer_decl)) { BT_LOGE("Container field type for enumeration field type is not an integer field type: " @@ -3119,7 +3119,7 @@ int visit_type_specifier_list(struct ctx *ctx, ret = visit_integer_decl(ctx, &node->u.integer.expressions, decl); if (ret) { - assert(!*decl); + BT_ASSERT(!*decl); goto error; } break; @@ -3127,7 +3127,7 @@ int visit_type_specifier_list(struct ctx *ctx, ret = visit_floating_point_number_decl(ctx, &node->u.floating_point.expressions, decl); if (ret) { - assert(!*decl); + BT_ASSERT(!*decl); goto error; } break; @@ -3135,7 +3135,7 @@ int visit_type_specifier_list(struct ctx *ctx, ret = visit_string_decl(ctx, &node->u.string.expressions, decl); if (ret) { - assert(!*decl); + BT_ASSERT(!*decl); goto error; } break; @@ -3145,7 +3145,7 @@ int visit_type_specifier_list(struct ctx *ctx, node->u._struct.has_body, &node->u._struct.min_align, decl); if (ret) { - assert(!*decl); + BT_ASSERT(!*decl); goto error; } break; @@ -3155,7 +3155,7 @@ int visit_type_specifier_list(struct ctx *ctx, &node->u.variant.declaration_list, node->u.variant.has_body, decl); if (ret) { - assert(!*decl); + BT_ASSERT(!*decl); goto error; } break; @@ -3165,7 +3165,7 @@ int visit_type_specifier_list(struct ctx *ctx, &node->u._enum.enumerator_list, node->u._enum.has_body, decl); if (ret) { - assert(!*decl); + BT_ASSERT(!*decl); goto error; } break; @@ -3188,7 +3188,7 @@ int visit_type_specifier_list(struct ctx *ctx, _BT_LOGE_NODE(first, "Cannot visit type specifier: ret=%d", ret); - assert(!*decl); + BT_ASSERT(!*decl); goto error; } break; @@ -3200,7 +3200,7 @@ int visit_type_specifier_list(struct ctx *ctx, goto error; } - assert(*decl); + BT_ASSERT(*decl); return 0; @@ -3327,7 +3327,7 @@ int visit_event_decl_entry(struct ctx *ctx, struct ctf_node *node, goto error; } - assert(decl); + BT_ASSERT(decl); ret = bt_event_class_set_context_type( event_class, decl); BT_PUT(decl); @@ -3357,7 +3357,7 @@ int visit_event_decl_entry(struct ctx *ctx, struct ctf_node *node, goto error; } - assert(decl); + BT_ASSERT(decl); ret = bt_event_class_set_payload_type( event_class, decl); BT_PUT(decl); @@ -3759,12 +3759,12 @@ int visit_event_decl(struct ctx *ctx, struct ctf_node *node) stream_id = *((int64_t *) keys->data); g_list_free(keys); } else { - assert(bt_trace_get_stream_class_count( + BT_ASSERT(bt_trace_get_stream_class_count( ctx->trace) == 1); stream_class = bt_trace_get_stream_class_by_index( ctx->trace, 0); - assert(stream_class); + BT_ASSERT(stream_class); stream_id = bt_stream_class_get_id( stream_class); BT_PUT(stream_class); @@ -3778,7 +3778,7 @@ int visit_event_decl(struct ctx *ctx, struct ctf_node *node) } } - assert(stream_id >= 0); + BT_ASSERT(stream_id >= 0); /* We have the stream ID now; get the stream class if found */ stream_class = g_hash_table_lookup(ctx->stream_classes, &stream_id); @@ -3795,7 +3795,7 @@ int visit_event_decl(struct ctx *ctx, struct ctf_node *node) } } - assert(stream_class); + BT_ASSERT(stream_class); if (!_IS_SET(&set, _EVENT_ID_SET)) { /* Allow only one event without ID per stream */ @@ -3878,7 +3878,7 @@ int auto_map_field_to_trace_clock_class(struct ctx *ctx, } clock_class_count = bt_trace_get_clock_class_count(ctx->trace); - assert(clock_class_count >= 0); + BT_ASSERT(clock_class_count >= 0); switch (clock_class_count) { case 0: @@ -3909,7 +3909,7 @@ int auto_map_field_to_trace_clock_class(struct ctx *ctx, */ clock_class_to_map_to = bt_trace_get_clock_class_by_index(ctx->trace, 0); - assert(clock_class_to_map_to); + BT_ASSERT(clock_class_to_map_to); break; default: /* @@ -3923,7 +3923,7 @@ int auto_map_field_to_trace_clock_class(struct ctx *ctx, goto end; } - assert(clock_class_to_map_to); + BT_ASSERT(clock_class_to_map_to); ret = bt_field_type_integer_set_mapped_clock_class(ft, clock_class_to_map_to); if (ret) { @@ -3962,7 +3962,7 @@ int auto_map_fields_to_trace_clock_class(struct ctx *ctx, count = bt_field_type_variant_get_field_count(root_ft); } - assert(count >= 0); + BT_ASSERT(count >= 0); for (i = 0; i < count; i++) { _BT_FIELD_TYPE_INIT(ft); @@ -3976,7 +3976,7 @@ int auto_map_fields_to_trace_clock_class(struct ctx *ctx, root_ft, &name, &ft, i); } - assert(ret == 0); + BT_ASSERT(ret == 0); if (strcmp(name, field_name) == 0) { ret = auto_map_field_to_trace_clock_class(ctx, ft); @@ -4096,7 +4096,7 @@ int visit_stream_decl_entry(struct ctx *ctx, struct ctf_node *node, goto error; } - assert(decl); + BT_ASSERT(decl); ret = auto_map_fields_to_trace_clock_class(ctx, decl, "timestamp"); if (ret) { @@ -4134,7 +4134,7 @@ int visit_stream_decl_entry(struct ctx *ctx, struct ctf_node *node, goto error; } - assert(decl); + BT_ASSERT(decl); ret = bt_stream_class_set_event_context_type( stream_class, decl); @@ -4165,7 +4165,7 @@ int visit_stream_decl_entry(struct ctx *ctx, struct ctf_node *node, goto error; } - assert(decl); + BT_ASSERT(decl); ret = auto_map_fields_to_trace_clock_class(ctx, decl, "timestamp_begin"); if (ret) { @@ -4305,7 +4305,7 @@ int visit_stream_decl(struct ctx *ctx, struct ctf_node *node) /* Automatic ID: 0 */ ret = bt_stream_class_set_id(stream_class, 0); - assert(ret == 0); + BT_ASSERT(ret == 0); } id = bt_stream_class_get_id(stream_class); @@ -4473,7 +4473,7 @@ int visit_trace_decl_entry(struct ctx *ctx, struct ctf_node *node, int *set) goto error; } - assert(packet_header_decl); + BT_ASSERT(packet_header_decl); ret = bt_trace_set_packet_header_type(ctx->trace, packet_header_decl); BT_PUT(packet_header_decl); @@ -5122,7 +5122,7 @@ int visit_clock_decl(struct ctx *ctx, struct ctf_node *clock_node) } clock_class_name = bt_clock_class_get_name(clock); - assert(clock_class_name); + BT_ASSERT(clock_class_name); if (ctx->is_lttng && strcmp(clock_class_name, "monotonic") == 0) { /* * Old versions of LTTng forgot to set its clock class @@ -5202,7 +5202,7 @@ int visit_root_decl(struct ctx *ctx, struct ctf_node *root_decl_node) _BT_LOGE_NODE(root_decl_node, "Cannot visit root scope's field type: " "ret=%d", ret); - assert(!decl); + BT_ASSERT(!decl); goto end; } @@ -5228,7 +5228,7 @@ int set_trace_name(struct ctx *ctx) int ret = 0; struct bt_value *value = NULL; - assert(bt_trace_get_stream_class_count(ctx->trace) == 0); + BT_ASSERT(bt_trace_get_stream_class_count(ctx->trace) == 0); name = g_string_new(NULL); if (!name) { BT_LOGE_STR("Failed to allocate a GString."); @@ -5242,11 +5242,11 @@ int set_trace_name(struct ctx *ctx) */ value = bt_trace_get_environment_field_value_by_name(ctx->trace, "hostname"); - if (bt_value_is_string(value)) { + if (value && bt_value_is_string(value)) { const char *hostname; ret = bt_value_string_get(value, &hostname); - assert(ret == 0); + BT_ASSERT(ret == 0); g_string_append(name, hostname); if (ctx->trace_name_suffix) { @@ -5373,8 +5373,8 @@ struct bt_trace *ctf_visitor_generate_ir_get_trace( { struct ctx *ctx = (void *) visitor; - assert(ctx); - assert(ctx->trace); + BT_ASSERT(ctx); + BT_ASSERT(ctx->trace); return bt_get(ctx->trace); } @@ -5427,9 +5427,9 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor, } } - assert(ctx->trace_bo == BT_BYTE_ORDER_LITTLE_ENDIAN || + BT_ASSERT(ctx->trace_bo == BT_BYTE_ORDER_LITTLE_ENDIAN || ctx->trace_bo == BT_BYTE_ORDER_BIG_ENDIAN); - assert(ctx->current_scope && + BT_ASSERT(ctx->current_scope && ctx->current_scope->parent_scope == NULL); /* Environment */ @@ -5443,7 +5443,7 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor, } } - assert(ctx->current_scope && + BT_ASSERT(ctx->current_scope && ctx->current_scope->parent_scope == NULL); /* @@ -5459,7 +5459,7 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor, } } - assert(ctx->current_scope && + BT_ASSERT(ctx->current_scope && ctx->current_scope->parent_scope == NULL); /* @@ -5477,7 +5477,7 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor, } } - assert(ctx->current_scope && + BT_ASSERT(ctx->current_scope && ctx->current_scope->parent_scope == NULL); /* Callsite blocks are not supported */ @@ -5486,7 +5486,7 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor, "\"callsite\" blocks are not supported as of this version."); } - assert(ctx->current_scope && + BT_ASSERT(ctx->current_scope && ctx->current_scope->parent_scope == NULL); /* Trace */ @@ -5500,7 +5500,7 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor, } } - assert(ctx->current_scope && + BT_ASSERT(ctx->current_scope && ctx->current_scope->parent_scope == NULL); /* Streams */ @@ -5514,7 +5514,7 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor, } } - assert(ctx->current_scope && + BT_ASSERT(ctx->current_scope && ctx->current_scope->parent_scope == NULL); /* Events */ @@ -5528,7 +5528,7 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor, } } - assert(ctx->current_scope && + BT_ASSERT(ctx->current_scope && ctx->current_scope->parent_scope == NULL); break; } diff --git a/plugins/ctf/common/metadata/visitor-parent-links.c b/plugins/ctf/common/metadata/visitor-parent-links.c index ca98701c..cc8b6472 100644 --- a/plugins/ctf/common/metadata/visitor-parent-links.c +++ b/plugins/ctf/common/metadata/visitor-parent-links.c @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/plugins/ctf/common/metadata/visitor-semantic-validator.c b/plugins/ctf/common/metadata/visitor-semantic-validator.c index 527a0ec4..d91acbe5 100644 --- a/plugins/ctf/common/metadata/visitor-semantic-validator.c +++ b/plugins/ctf/common/metadata/visitor-semantic-validator.c @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/plugins/ctf/common/notif-iter/notif-iter.c b/plugins/ctf/common/notif-iter/notif-iter.c index 527147e5..1f3587d7 100644 --- a/plugins/ctf/common/notif-iter/notif-iter.c +++ b/plugins/ctf/common/notif-iter/notif-iter.c @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include #include #include @@ -338,7 +338,7 @@ error: static void stack_destroy(struct stack *stack) { - assert(stack); + BT_ASSERT(stack); BT_LOGD("Destroying stack: addr=%p", stack); g_ptr_array_free(stack->entries, TRUE); g_free(stack); @@ -350,8 +350,8 @@ int stack_push(struct stack *stack, struct bt_field *base) int ret = 0; struct stack_entry *entry; - assert(stack); - assert(base); + BT_ASSERT(stack); + BT_ASSERT(base); BT_LOGV("Pushing base field on stack: stack-addr=%p, " "stack-size-before=%u, stack-size-after=%u", stack, stack->entries->len, stack->entries->len + 1); @@ -372,7 +372,7 @@ end: static inline unsigned int stack_size(struct stack *stack) { - assert(stack); + BT_ASSERT(stack); return stack->entries->len; } @@ -380,8 +380,8 @@ unsigned int stack_size(struct stack *stack) static void stack_pop(struct stack *stack) { - assert(stack); - assert(stack_size(stack)); + BT_ASSERT(stack); + BT_ASSERT(stack_size(stack)); BT_LOGV("Popping from stack: " "stack-addr=%p, stack-size-before=%u, stack-size-after=%u", stack, stack->entries->len, stack->entries->len - 1); @@ -391,8 +391,8 @@ void stack_pop(struct stack *stack) static inline struct stack_entry *stack_top(struct stack *stack) { - assert(stack); - assert(stack_size(stack)); + BT_ASSERT(stack); + BT_ASSERT(stack_size(stack)); return g_ptr_array_index(stack->entries, stack->entries->len - 1); } @@ -406,7 +406,7 @@ bool stack_empty(struct stack *stack) static void stack_clear(struct stack *stack) { - assert(stack); + BT_ASSERT(stack); if (!stack_empty(stack)) { BT_LOGV("Clearing stack: stack-addr=%p, stack-size=%u", @@ -414,7 +414,7 @@ void stack_clear(struct stack *stack) g_ptr_array_remove_range(stack->entries, 0, stack_size(stack)); } - assert(stack_empty(stack)); + BT_ASSERT(stack_empty(stack)); } static inline @@ -467,7 +467,7 @@ enum bt_notif_iter_status request_medium_bytes( bt_notif_iter_medium_status_string(m_status), buffer_addr, buffer_sz); if (m_status == BT_NOTIF_ITER_MEDIUM_STATUS_OK) { - assert(buffer_sz != 0); + BT_ASSERT(buffer_sz != 0); /* New packet offset is old one + old size (in bits) */ notit->buf.packet_offset += buf_size_bits(notit); @@ -758,7 +758,7 @@ create_stream_class_field_path_cache_entry( count = bt_field_type_structure_get_field_count( event_header); - assert(count >= 0); + BT_ASSERT(count >= 0); for (i = 0; i < count; i++) { int ret; @@ -798,7 +798,7 @@ create_stream_class_field_path_cache_entry( count = bt_field_type_structure_get_field_count( packet_context); - assert(count >= 0); + BT_ASSERT(count >= 0); for (i = 0; i < count; i++) { int ret; @@ -911,7 +911,7 @@ enum bt_notif_iter_status set_current_stream_class( goto single_stream_class; } - assert(is_struct_type(packet_header_type)); + BT_ASSERT(is_struct_type(packet_header_type)); // TODO: optimalize! stream_id_field_type = @@ -922,20 +922,20 @@ enum bt_notif_iter_status set_current_stream_class( int ret; struct bt_field *stream_id_field = NULL; - assert(notit->dscopes.trace_packet_header); + BT_ASSERT(notit->dscopes.trace_packet_header); // TODO: optimalize! stream_id_field = bt_field_structure_get_field_by_name( notit->dscopes.trace_packet_header, "stream_id"); - assert(stream_id_field); + BT_ASSERT(stream_id_field); ret = bt_field_unsigned_integer_get_value( stream_id_field, &stream_id); - assert(!ret); + BT_ASSERT(!ret); BT_PUT(stream_id_field); } else { single_stream_class: /* Only one stream: pick the first stream class */ - assert(bt_trace_get_stream_class_count( + BT_ASSERT(bt_trace_get_stream_class_count( notit->meta.trace) == 1); stream_id = 0; } @@ -1034,7 +1034,7 @@ enum bt_notif_iter_status read_packet_context_begin_state( enum bt_notif_iter_status status = BT_NOTIF_ITER_STATUS_OK; struct bt_field_type *packet_context_type; - assert(notit->meta.stream_class); + BT_ASSERT(notit->meta.stream_class); packet_context_type = bt_stream_class_get_packet_context_type( notit->meta.stream_class); if (!packet_context_type) { @@ -1105,7 +1105,7 @@ enum bt_notif_iter_status set_current_packet_content_sizes( int ret = bt_field_unsigned_integer_get_value( packet_size_field, &packet_size); - assert(ret == 0); + BT_ASSERT(ret == 0); if (packet_size == 0) { BT_LOGW("Invalid packet size: packet context field indicates packet size is zero: " "notit-addr=%p, packet-context-field-addr=%p", @@ -1127,7 +1127,7 @@ enum bt_notif_iter_status set_current_packet_content_sizes( int ret = bt_field_unsigned_integer_get_value( content_size_field, &content_size); - assert(ret == 0); + BT_ASSERT(ret == 0); } else { content_size = packet_size; } @@ -1276,12 +1276,12 @@ enum bt_notif_iter_status set_current_event_class(struct bt_notif_iter *notit) } /* Is there any "id"/"v" field in the event header? */ - assert(is_struct_type(event_header_type)); + BT_ASSERT(is_struct_type(event_header_type)); id_field_type = bt_field_type_structure_get_field_type_by_name( event_header_type, "id"); v_field_type = bt_field_type_structure_get_field_type_by_name( event_header_type, "v"); - assert(notit->dscopes.stream_event_header); + BT_ASSERT(notit->dscopes.stream_event_header); if (v_field_type) { /* * _ _____ _____ @@ -1298,7 +1298,7 @@ enum bt_notif_iter_status set_current_event_class(struct bt_notif_iter *notit) // TODO: optimalize! v_field = bt_field_structure_get_field_by_name( notit->dscopes.stream_event_header, "v"); - assert(v_field); + BT_ASSERT(v_field); v_struct_field = bt_field_variant_get_current_field(v_field); @@ -1350,13 +1350,13 @@ end_v_field_type: container = bt_field_enumeration_get_container( id_field); - assert(container); + BT_ASSERT(container); ret_get_value = bt_field_unsigned_integer_get_value( container, &event_id); BT_PUT(container); } - assert(ret_get_value == 0); + BT_ASSERT(ret_get_value == 0); BT_PUT(id_field); } @@ -1364,7 +1364,7 @@ check_event_id: if (event_id == -1ULL) { single_event_class: /* Event ID not found: single event? */ - assert(bt_stream_class_get_event_class_count( + BT_ASSERT(bt_stream_class_get_event_class_count( notit->meta.stream_class) == 1); event_id = 0; } @@ -1585,7 +1585,7 @@ enum bt_notif_iter_status skip_packet_padding_state( enum bt_notif_iter_status status = BT_NOTIF_ITER_STATUS_OK; size_t bits_to_skip; - assert(notit->cur_packet_size > 0); + BT_ASSERT(notit->cur_packet_size > 0); bits_to_skip = notit->cur_packet_size - packet_at(notit); if (bits_to_skip == 0) { notit->state = STATE_DSCOPE_TRACE_PACKET_HEADER_BEGIN; @@ -1705,7 +1705,7 @@ enum bt_notif_iter_status handle_state(struct bt_notif_iter *notit) static void bt_notif_iter_reset(struct bt_notif_iter *notit) { - assert(notit); + BT_ASSERT(notit); BT_LOGD("Resetting notification iterator: addr=%p", notit); stack_clear(notit->stack); BT_PUT(notit->meta.stream_class); @@ -1734,7 +1734,7 @@ int bt_notif_iter_switch_packet(struct bt_notif_iter *notit) * sure that all the packets processed by the same notification * iterator refer to the same stream class (the first one). */ - assert(notit); + BT_ASSERT(notit); if (notit->cur_packet_size != -1) { notit->cur_packet_offset += notit->cur_packet_size; } @@ -1786,12 +1786,12 @@ struct bt_field *get_next_field(struct bt_notif_iter *notit) struct bt_field_type *base_type; size_t index; - assert(!stack_empty(notit->stack)); + BT_ASSERT(!stack_empty(notit->stack)); index = stack_top(notit->stack)->index; base_field = stack_top(notit->stack)->base; - assert(base_field); + BT_ASSERT(base_field); base_type = bt_field_get_type(base_field); - assert(base_type); + BT_ASSERT(base_type); switch (bt_field_type_get_type_id(base_type)) { case BT_FIELD_TYPE_ID_STRUCT: @@ -1832,14 +1832,14 @@ void update_clock_state(uint64_t *state, int ret; value_type = bt_field_get_type(value_field); - assert(value_type); - assert(bt_field_type_is_integer(value_type)); + BT_ASSERT(value_type); + BT_ASSERT(bt_field_type_is_integer(value_type)); requested_new_value_size = bt_field_type_integer_get_size(value_type); - assert(requested_new_value_size > 0); + BT_ASSERT(requested_new_value_size > 0); ret = bt_field_unsigned_integer_get_value(value_field, &requested_new_value); - assert(!ret); + BT_ASSERT(!ret); /* * Special case for a 64-bit new value, which is the limit @@ -1885,7 +1885,7 @@ enum bt_btr_status update_clock(struct bt_notif_iter *notit, struct bt_clock_class *clock_class = NULL; int_field_type = bt_field_get_type(int_field); - assert(int_field_type); + BT_ASSERT(int_field_type); clock_class = bt_field_type_integer_get_mapped_clock_class( int_field_type); if (likely(!clock_class)) { @@ -1954,9 +1954,9 @@ enum bt_btr_status btr_unsigned_int_common(uint64_t value, break; case BT_FIELD_TYPE_ID_ENUM: int_field = bt_field_enumeration_get_container(field); - assert(int_field); + BT_ASSERT(int_field); type = bt_field_get_type(int_field); - assert(type); + BT_ASSERT(type); break; default: BT_LOGF("Unexpected field type ID: " @@ -1967,9 +1967,9 @@ enum bt_btr_status btr_unsigned_int_common(uint64_t value, abort(); } - assert(int_field); + BT_ASSERT(int_field); ret = bt_field_unsigned_integer_set_value(int_field, value); - assert(ret == 0); + BT_ASSERT(ret == 0); stack_top(notit->stack)->index++; *out_int_field = int_field; BT_PUT(field); @@ -2070,9 +2070,9 @@ enum bt_btr_status btr_signed_int_cb(int64_t value, break; case BT_FIELD_TYPE_ID_ENUM: int_field = bt_field_enumeration_get_container(field); - assert(int_field); + BT_ASSERT(int_field); type = bt_field_get_type(int_field); - assert(type); + BT_ASSERT(type); break; default: BT_LOGF("Unexpected field type ID: " @@ -2083,9 +2083,9 @@ enum bt_btr_status btr_signed_int_cb(int64_t value, abort(); } - assert(int_field); + BT_ASSERT(int_field); ret = bt_field_signed_integer_set_value(int_field, value); - assert(!ret); + BT_ASSERT(!ret); stack_top(notit->stack)->index++; status = update_clock(notit, int_field); BT_PUT(field); @@ -2122,7 +2122,7 @@ enum bt_btr_status btr_floating_point_cb(double value, } ret = bt_field_floating_point_set_value(field, value); - assert(!ret); + BT_ASSERT(!ret); stack_top(notit->stack)->index++; end: @@ -2206,7 +2206,7 @@ enum bt_btr_status btr_string_cb(const char *value, /* Get string field */ field = stack_top(notit->stack)->base; - assert(field); + BT_ASSERT(field); /* Append current string */ ret = bt_field_string_append_len(field, value, len); @@ -2291,7 +2291,7 @@ enum bt_btr_status btr_compound_begin_cb( } /* Push field */ - assert(field); + BT_ASSERT(field); ret = stack_push(notit->stack, field); if (ret) { BT_LOGE("Cannot push compound field onto the stack: " @@ -2321,7 +2321,7 @@ enum bt_btr_status btr_compound_end_cb( notit, notit->btr, type, bt_field_type_id_string( bt_field_type_get_type_id(type))); - assert(!stack_empty(notit->stack)); + BT_ASSERT(!stack_empty(notit->stack)); /* Pop stack */ stack_pop(notit->stack); @@ -2395,7 +2395,7 @@ struct bt_field *resolve_field(struct bt_notif_iter *notit, int index = bt_field_path_get_index(path, i); field_type = bt_field_get_type(field); - assert(field_type); + BT_ASSERT(field_type); if (is_struct_type(field_type)) { next_field = bt_field_structure_get_field_by_index( @@ -2438,7 +2438,7 @@ int64_t btr_get_sequence_length_cb(struct bt_field_type *type, void *data) uint64_t length; field_path = bt_field_type_sequence_get_length_field_path(type); - assert(field_path); + BT_ASSERT(field_path); length_field = resolve_field(notit, field_path); if (!length_field) { BT_LOGW("Cannot resolve sequence field type's length field path: " @@ -2486,7 +2486,7 @@ struct bt_field_type *btr_get_variant_type_cb( struct bt_field_type *selected_field_type = NULL; path = bt_field_type_variant_get_tag_field_path(type); - assert(path); + BT_ASSERT(path); tag_field = resolve_field(notit, path); if (!tag_field) { BT_LOGW("Cannot resolve variant field type's tag field path: " @@ -2558,7 +2558,7 @@ int set_event_clocks(struct bt_event *event, struct bt_event_class *event_class = bt_event_get_class(event); - assert(event_class); + BT_ASSERT(event_class); BT_LOGE("Cannot set event's clock value: " "notit-addr=%p, event-addr=%p, " "event-class-name=\"%s\", " @@ -2679,7 +2679,7 @@ struct bt_event *create_event(struct bt_notif_iter *notit) } /* Associate with current packet. */ - assert(notit->packet); + BT_ASSERT(notit->packet); ret = bt_event_set_packet(event, notit->packet); if (ret) { BT_LOGE("Cannot set event's header field: " @@ -2953,7 +2953,7 @@ void init_trace_field_path_cache(struct bt_trace *trace, } count = bt_field_type_structure_get_field_count(packet_header); - assert(count >= 0); + BT_ASSERT(count >= 0); for (i = 0; (i < count && (stream_id == -1 || stream_instance_id == -1)); i++) { int ret; @@ -3005,9 +3005,9 @@ struct bt_notif_iter *bt_notif_iter_create(struct bt_trace *trace, }, }; - assert(trace); - assert(medops.request_bytes); - assert(medops.get_stream); + BT_ASSERT(trace); + BT_ASSERT(medops.request_bytes); + BT_ASSERT(medops.get_stream); BT_LOGD("Creating CTF plugin notification iterator: " "trace-addr=%p, trace-name=\"%s\", max-request-size=%zu, " "data=%p", @@ -3115,8 +3115,8 @@ enum bt_notif_iter_status bt_notif_iter_get_next_notification( { enum bt_notif_iter_status status = BT_NOTIF_ITER_STATUS_OK; - assert(notit); - assert(notification); + BT_ASSERT(notit); + BT_ASSERT(notification); BT_LOGV("Getting next notification: notit-addr=%p, cc-prio-map-addr=%p", notit, cc_prio_map); @@ -3161,7 +3161,7 @@ enum bt_notif_iter_status bt_notif_iter_get_next_notification( bt_field_get_type( notit->cur_timestamp_end); - assert(field_type); + BT_ASSERT(field_type); btr_status = update_clock(notit, notit->cur_timestamp_end); BT_PUT(field_type); @@ -3198,7 +3198,7 @@ enum bt_notif_iter_status bt_notif_iter_get_packet_header_context_fields( int ret; enum bt_notif_iter_status status = BT_NOTIF_ITER_STATUS_OK; - assert(notit); + BT_ASSERT(notit); if (notit->state == STATE_EMIT_NOTIF_NEW_PACKET) { /* We're already there */ @@ -3271,7 +3271,7 @@ BT_HIDDEN void bt_notif_iter_set_medops_data(struct bt_notif_iter *notit, void *medops_data) { - assert(notit); + BT_ASSERT(notit); notit->medium.data = medops_data; } @@ -3282,7 +3282,7 @@ enum bt_notif_iter_status bt_notif_iter_seek( enum bt_notif_iter_status ret = BT_NOTIF_ITER_STATUS_OK; enum bt_notif_iter_medium_status medium_status; - assert(notit); + BT_ASSERT(notit); if (offset < 0) { BT_LOGE("Cannot seek to negative offset: offset=%jd", offset); ret = BT_NOTIF_ITER_STATUS_INVAL; @@ -3317,7 +3317,7 @@ BT_HIDDEN off_t bt_notif_iter_get_current_packet_offset( struct bt_notif_iter *notit) { - assert(notit); + BT_ASSERT(notit); return notit->cur_packet_offset; } @@ -3325,6 +3325,6 @@ BT_HIDDEN off_t bt_notif_iter_get_current_packet_size( struct bt_notif_iter *notit) { - assert(notit); + BT_ASSERT(notit); return notit->cur_packet_size; } diff --git a/plugins/ctf/fs-sink/write.c b/plugins/ctf/fs-sink/write.c index 661cc004..c3f837bf 100644 --- a/plugins/ctf/fs-sink/write.c +++ b/plugins/ctf/fs-sink/write.c @@ -30,7 +30,7 @@ #include "logging.h" #include -#include +#include #include #include @@ -114,10 +114,10 @@ struct bt_stream_class *insert_new_stream_class( enum bt_component_status ret; trace = bt_stream_class_get_trace(stream_class); - assert(trace); + BT_ASSERT(trace); writer_trace = bt_ctf_writer_get_trace(ctf_writer); - assert(writer_trace); + BT_ASSERT(writer_trace); ret = ctf_copy_clock_classes(writer_component->err, writer_trace, writer_stream_class, trace); @@ -310,7 +310,7 @@ struct fs_writer *insert_new_writer( } writer_trace = bt_ctf_writer_get_trace(ctf_writer); - assert(writer_trace); + BT_ASSERT(writer_trace); ret = ctf_copy_trace(writer_component->err, trace, writer_trace); if (ret != BT_COMPONENT_STATUS_OK) { @@ -340,7 +340,7 @@ struct fs_writer *insert_new_writer( nr_stream = bt_trace_get_stream_count(trace); for (i = 0; i < nr_stream; i++) { stream = bt_trace_get_stream_by_index(trace, i); - assert(stream); + BT_ASSERT(stream); insert_new_stream_state(writer_component, fs_writer, stream); BT_PUT(stream); @@ -353,7 +353,7 @@ struct fs_writer *insert_new_writer( } else { ret = bt_trace_add_is_static_listener(trace, trace_is_static_listener, NULL, fs_writer); - assert(ret >= 0); + BT_ASSERT(ret >= 0); fs_writer->static_listener_id = ret; } @@ -381,7 +381,7 @@ struct fs_writer *get_fs_writer(struct writer_component *writer_component, struct fs_writer *fs_writer; trace = bt_stream_class_get_trace(stream_class); - assert(trace); + BT_ASSERT(trace); fs_writer = g_hash_table_lookup(writer_component->trace_map, (gpointer) trace); @@ -402,7 +402,7 @@ struct fs_writer *get_fs_writer_from_stream( struct fs_writer *fs_writer; stream_class = bt_stream_get_class(stream); - assert(stream_class); + BT_ASSERT(stream_class); fs_writer = get_fs_writer(writer_component, stream_class); @@ -417,7 +417,7 @@ struct bt_stream_class *lookup_stream_class( { struct fs_writer *fs_writer = get_fs_writer( writer_component, stream_class); - assert(fs_writer); + BT_ASSERT(fs_writer); return (struct bt_stream_class *) g_hash_table_lookup( fs_writer->stream_class_map, (gpointer) stream_class); } @@ -428,7 +428,7 @@ struct bt_stream *lookup_stream(struct writer_component *writer_component, { struct fs_writer *fs_writer = get_fs_writer_from_stream( writer_component, stream); - assert(fs_writer); + BT_ASSERT(fs_writer); return (struct bt_stream *) g_hash_table_lookup( fs_writer->stream_map, (gpointer) stream); } @@ -458,7 +458,7 @@ struct bt_stream *insert_new_stream( writer_stream = bt_stream_create(writer_stream_class, bt_stream_get_name(stream)); - assert(writer_stream); + BT_ASSERT(writer_stream); g_hash_table_insert(fs_writer->stream_map, (gpointer) stream, writer_stream); @@ -541,7 +541,7 @@ enum bt_component_status writer_stream_begin( enum fs_writer_stream_state *state; stream_class = bt_stream_get_class(stream); - assert(stream_class); + BT_ASSERT(stream_class); fs_writer = get_fs_writer(writer_component, stream_class); if (!fs_writer) { @@ -593,7 +593,7 @@ enum bt_component_status writer_stream_end( enum fs_writer_stream_state *state; stream_class = bt_stream_get_class(stream); - assert(stream_class); + BT_ASSERT(stream_class); fs_writer = get_fs_writer(writer_component, stream_class); if (!fs_writer) { @@ -642,7 +642,7 @@ enum bt_component_status writer_new_packet( int int_ret; stream = bt_packet_get_stream(packet); - assert(stream); + BT_ASSERT(stream); writer_stream = get_writer_stream(writer_component, packet, stream); if (!writer_stream) { @@ -684,7 +684,7 @@ enum bt_component_status writer_close_packet( enum bt_component_status ret; stream = bt_packet_get_stream(packet); - assert(stream); + BT_ASSERT(stream); writer_stream = lookup_stream(writer_component, stream); if (!writer_stream) { @@ -728,10 +728,10 @@ enum bt_component_status writer_output_event( struct bt_trace *writer_trace = NULL; event_class = bt_event_get_class(event); - assert(event_class); + BT_ASSERT(event_class); stream = bt_event_get_stream(event); - assert(stream); + BT_ASSERT(stream); writer_stream = lookup_stream(writer_component, stream); if (!writer_stream || !bt_get(writer_stream)) { @@ -740,7 +740,7 @@ enum bt_component_status writer_output_event( } stream_class = bt_event_class_get_stream_class(event_class); - assert(stream_class); + BT_ASSERT(stream_class); writer_stream_class = lookup_stream_class(writer_component, stream_class); if (!writer_stream_class || !bt_get(writer_stream_class)) { @@ -749,7 +749,7 @@ enum bt_component_status writer_output_event( } writer_trace = bt_stream_class_get_trace(writer_stream_class); - assert(writer_trace); + BT_ASSERT(writer_trace); writer_event_class = get_event_class(writer_component, writer_stream_class, event_class); diff --git a/plugins/ctf/fs-sink/writer.c b/plugins/ctf/fs-sink/writer.c index fcc61866..1ef26ddc 100644 --- a/plugins/ctf/fs-sink/writer.c +++ b/plugins/ctf/fs-sink/writer.c @@ -35,7 +35,7 @@ #include #include #include "writer.h" -#include +#include static gboolean empty_trace_map(gpointer key, gpointer value, gpointer user_data) @@ -216,10 +216,10 @@ void writer_component_port_connected( }; writer = bt_private_component_get_user_data(component); - assert(writer); - assert(!writer->input_iterator); + BT_ASSERT(writer); + BT_ASSERT(!writer->input_iterator); connection = bt_private_port_get_private_connection(self_port); - assert(connection); + BT_ASSERT(connection); conn_status = bt_private_connection_create_notification_iterator( connection, notif_types, &writer->input_iterator); if (conn_status != BT_CONNECTION_STATUS_OK) { @@ -245,7 +245,7 @@ enum bt_component_status writer_run(struct bt_private_component *component) } it = writer_component->input_iterator; - assert(it); + BT_ASSERT(it); it_ret = bt_notification_iterator_next(it); switch (it_ret) { @@ -264,7 +264,7 @@ enum bt_component_status writer_run(struct bt_private_component *component) } notification = bt_notification_iterator_get_notification(it); - assert(notification); + BT_ASSERT(notification); ret = handle_notification(writer_component, notification); end: bt_put(notification); diff --git a/plugins/ctf/fs-src/data-stream-file.c b/plugins/ctf/fs-src/data-stream-file.c index f06457e8..e31f1787 100644 --- a/plugins/ctf/fs-src/data-stream-file.c +++ b/plugins/ctf/fs-src/data-stream-file.c @@ -36,7 +36,7 @@ #include "file.h" #include "metadata.h" #include "../common/notif-iter/notif-iter.h" -#include +#include #include "data-stream-file.h" #include @@ -103,7 +103,7 @@ enum bt_notif_iter_medium_status ds_file_mmap_next( goto end; } /* Map new region */ - assert(ds_file->mmap_len); + BT_ASSERT(ds_file->mmap_len); ds_file->mmap_addr = bt_mmap((void *) 0, ds_file->mmap_len, PROT_READ, MAP_PRIVATE, fileno(ds_file->file->fp), ds_file->mmap_offset); @@ -405,7 +405,7 @@ int convert_cycles_to_ns(struct bt_clock_class *clock_class, int ret = 0; struct bt_clock_value *clock_value; - assert(ns); + BT_ASSERT(ns); clock_value = bt_clock_value_create(clock_class, cycles); if (!clock_value) { ret = -1; @@ -623,10 +623,10 @@ int init_index_entry(struct ctf_fs_ds_index_entry *entry, goto end; } - assert(packet_offset >= 0); + BT_ASSERT(packet_offset >= 0); entry->offset = packet_offset; - assert(packet_size >= 0); + BT_ASSERT(packet_size >= 0); entry->packet_size = packet_size; ret = bt_field_unsigned_integer_get_value(timestamp_begin, @@ -888,7 +888,7 @@ int ctf_fs_ds_file_get_packet_header_context_fields( enum bt_notif_iter_status notif_iter_status; int ret = 0; - assert(ds_file); + BT_ASSERT(ds_file); notif_iter_status = bt_notif_iter_get_packet_header_context_fields( ds_file->notif_iter, packet_header_field, packet_context_field); switch (notif_iter_status) { diff --git a/plugins/ctf/fs-src/fs.c b/plugins/ctf/fs-src/fs.c index 2dacf97d..74e9b52a 100644 --- a/plugins/ctf/fs-src/fs.c +++ b/plugins/ctf/fs-src/fs.c @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include #include "fs.h" @@ -50,7 +50,7 @@ int notif_iter_data_set_current_ds_file(struct ctf_fs_notif_iter_data *notif_ite struct ctf_fs_ds_file_info *ds_file_info; int ret = 0; - assert(notif_iter_data->ds_file_info_index < + BT_ASSERT(notif_iter_data->ds_file_info_index < notif_iter_data->ds_file_group->ds_file_infos->len); ds_file_info = g_ptr_array_index( notif_iter_data->ds_file_group->ds_file_infos, @@ -94,10 +94,10 @@ struct bt_notification_iterator_next_method_return ctf_fs_iterator_next( bt_private_connection_private_notification_iterator_get_user_data(iterator); int ret; - assert(notif_iter_data->ds_file); + BT_ASSERT(notif_iter_data->ds_file); next_ret = ctf_fs_ds_file_next(notif_iter_data->ds_file); if (next_ret.status == BT_NOTIFICATION_ITERATOR_STATUS_END) { - assert(!next_ret.notification); + BT_ASSERT(!next_ret.notification); notif_iter_data->ds_file_info_index++; if (notif_iter_data->ds_file_info_index == @@ -129,7 +129,7 @@ struct bt_notification_iterator_next_method_return ctf_fs_iterator_next( * begin" and "packet end" notifications in the case of * a single, empty packet. */ - assert(next_ret.status != BT_NOTIFICATION_ITERATOR_STATUS_END); + BT_ASSERT(next_ret.status != BT_NOTIFICATION_ITERATOR_STATUS_END); } end: @@ -287,7 +287,7 @@ GString *get_stream_instance_unique_name( * group, the first (earliest) stream file's path is used as * the stream's unique name. */ - assert(ds_file_group->ds_file_infos->len > 0); + BT_ASSERT(ds_file_group->ds_file_infos->len > 0); ds_file_info = g_ptr_array_index(ds_file_group->ds_file_infos, 0); g_string_assign(name, ds_file_info->path->str); @@ -418,7 +418,7 @@ uint64_t get_packet_context_timestamp_begin_ns( } timestamp_begin_ft = bt_field_get_type(timestamp_begin_field); - assert(timestamp_begin_ft); + BT_ASSERT(timestamp_begin_ft); timestamp_begin_clock_class = bt_field_type_integer_get_mapped_clock_class(timestamp_begin_ft); if (!timestamp_begin_clock_class) { @@ -531,7 +531,7 @@ struct ctf_fs_ds_file_group *ctf_fs_ds_file_group_create( } ds_file_group->stream_id = stream_instance_id; - assert(stream_class); + BT_ASSERT(stream_class); ds_file_group->stream_class = bt_get(stream_class); ds_file_group->ctf_fs_trace = ctf_fs_trace; goto end; @@ -691,8 +691,8 @@ int add_ds_file_to_ds_file_group(struct ctf_fs_trace *ctf_fs_trace, goto end; } - assert(stream_instance_id != -1ULL); - assert(begin_ns != -1ULL); + BT_ASSERT(stream_instance_id != -1ULL); + BT_ASSERT(begin_ns != -1ULL); /* Find an existing stream file group with this ID */ for (i = 0; i < ctf_fs_trace->ds_file_groups->len; i++) { @@ -889,7 +889,7 @@ int create_cc_prio_map(struct ctf_fs_trace *ctf_fs_trace) size_t i; int count; - assert(ctf_fs_trace); + BT_ASSERT(ctf_fs_trace); ctf_fs_trace->cc_prio_map = bt_clock_class_priority_map_create(); if (!ctf_fs_trace->cc_prio_map) { ret = -1; @@ -898,14 +898,14 @@ int create_cc_prio_map(struct ctf_fs_trace *ctf_fs_trace) count = bt_trace_get_clock_class_count( ctf_fs_trace->metadata->trace); - assert(count >= 0); + BT_ASSERT(count >= 0); for (i = 0; i < count; i++) { struct bt_clock_class *clock_class = bt_trace_get_clock_class_by_index( ctf_fs_trace->metadata->trace, i); - assert(clock_class); + BT_ASSERT(clock_class); ret = bt_clock_class_priority_map_add_clock_class( ctf_fs_trace->cc_prio_map, clock_class, 0); BT_PUT(clock_class); @@ -1027,7 +1027,7 @@ int add_trace_path(GList **trace_paths, const char *path) } *trace_paths = g_list_prepend(*trace_paths, norm_path); - assert(*trace_paths); + BT_ASSERT(*trace_paths); norm_path = NULL; end: @@ -1144,7 +1144,7 @@ GList *ctf_fs_create_trace_names(GList *trace_paths, const char *base_path) { last_sep = strrchr(base_path, G_DIR_SEPARATOR); /* We know there's at least one separator */ - assert(last_sep); + BT_ASSERT(last_sep); /* Distance to base */ base_dist = last_sep - base_path + 1; @@ -1154,7 +1154,7 @@ GList *ctf_fs_create_trace_names(GList *trace_paths, const char *base_path) { GString *trace_name = g_string_new(NULL); GString *trace_path = node->data; - assert(trace_name); + BT_ASSERT(trace_name); g_string_assign(trace_name, &trace_path->str[base_dist]); trace_names = g_list_append(trace_names, trace_name); } @@ -1271,7 +1271,7 @@ struct ctf_fs_component *ctf_fs_create(struct bt_private_component *priv_comp, } ret = bt_private_component_set_user_data(priv_comp, ctf_fs); - assert(ret == BT_COMPONENT_STATUS_OK); + BT_ASSERT(ret == BT_COMPONENT_STATUS_OK); /* * We don't need to get a new reference here because as long as @@ -1280,12 +1280,12 @@ struct ctf_fs_component *ctf_fs_create(struct bt_private_component *priv_comp, */ ctf_fs->priv_comp = priv_comp; value = bt_value_map_get(params, "path"); - if (!bt_value_is_string(value)) { + if (value && !bt_value_is_string(value)) { goto error; } value_ret = bt_value_string_get(value, &path_param); - assert(value_ret == BT_VALUE_STATUS_OK); + BT_ASSERT(value_ret == BT_VALUE_STATUS_OK); BT_PUT(value); value = bt_value_map_get(params, "clock-class-offset-s"); if (value) { @@ -1295,7 +1295,7 @@ struct ctf_fs_component *ctf_fs_create(struct bt_private_component *priv_comp, } value_ret = bt_value_integer_get(value, &ctf_fs->metadata_config.clock_class_offset_s); - assert(value_ret == BT_VALUE_STATUS_OK); + BT_ASSERT(value_ret == BT_VALUE_STATUS_OK); BT_PUT(value); } @@ -1307,7 +1307,7 @@ struct ctf_fs_component *ctf_fs_create(struct bt_private_component *priv_comp, } value_ret = bt_value_integer_get(value, &ctf_fs->metadata_config.clock_class_offset_ns); - assert(value_ret == BT_VALUE_STATUS_OK); + BT_ASSERT(value_ret == BT_VALUE_STATUS_OK); BT_PUT(value); } @@ -1332,7 +1332,7 @@ error: ctf_fs_destroy(ctf_fs); ctf_fs = NULL; ret = bt_private_component_set_user_data(priv_comp, NULL); - assert(ret == BT_COMPONENT_STATUS_OK); + BT_ASSERT(ret == BT_COMPONENT_STATUS_OK); end: bt_put(value); diff --git a/plugins/ctf/fs-src/metadata.c b/plugins/ctf/fs-src/metadata.c index 231d946c..619e75a0 100644 --- a/plugins/ctf/fs-src/metadata.c +++ b/plugins/ctf/fs-src/metadata.c @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include #include @@ -121,7 +121,7 @@ int ctf_fs_metadata_set_trace(struct ctf_fs_trace *ctf_fs_trace, ctf_fs_trace->metadata->trace = ctf_metadata_decoder_get_trace( metadata_decoder); - assert(ctf_fs_trace->metadata->trace); + BT_ASSERT(ctf_fs_trace->metadata->trace); end: ctf_fs_file_destroy(file); diff --git a/plugins/ctf/fs-src/query.c b/plugins/ctf/fs-src/query.c index 04bf8c5b..04ab457f 100644 --- a/plugins/ctf/fs-src/query.c +++ b/plugins/ctf/fs-src/query.c @@ -26,7 +26,7 @@ #include "query.h" #include -#include +#include #include "metadata.h" #include "../common/metadata/decoder.h" #include @@ -70,6 +70,8 @@ struct bt_component_class_query_method_return metadata_info_query( goto error; } + BT_ASSERT(params); + if (!bt_value_is_map(params)) { BT_LOGE_STR("Query parameters is not a map value object."); query_ret.status = BT_QUERY_STATUS_INVALID_PARAMS; @@ -84,7 +86,7 @@ struct bt_component_class_query_method_return metadata_info_query( goto error; } - assert(path); + BT_ASSERT(path); metadata_fp = ctf_fs_metadata_open_file(path); if (!metadata_fp) { BT_LOGE("Cannot open trace metadata: path=\"%s\".", path); @@ -387,7 +389,7 @@ int populate_trace_info(const char *trace_path, const char *trace_name, goto end; } - assert(trace->ds_file_groups); + BT_ASSERT(trace->ds_file_groups); /* Add trace range info only if it contains streams. */ if (trace->ds_file_groups->len == 0) { ret = -1; @@ -479,6 +481,8 @@ struct bt_component_class_query_method_return trace_info_query( GList *tn_node = NULL; GString *normalized_path = NULL; + BT_ASSERT(params); + if (!bt_value_is_map(params)) { BT_LOGE("Query parameters is not a map value object."); query_ret.status = BT_QUERY_STATUS_INVALID_PARAMS; @@ -498,7 +502,7 @@ struct bt_component_class_query_method_return trace_info_query( BT_LOGE("Failed to normalize path: `%s`.", path); goto error; } - assert(path); + BT_ASSERT(path); ret = ctf_fs_find_traces(&trace_paths, normalized_path->str); if (ret) { diff --git a/plugins/ctf/lttng-live/data-stream.c b/plugins/ctf/lttng-live/data-stream.c index 7bf4c29e..b18dda14 100644 --- a/plugins/ctf/lttng-live/data-stream.c +++ b/plugins/ctf/lttng-live/data-stream.c @@ -34,7 +34,7 @@ #include #include #include "../common/notif-iter/notif-iter.h" -#include +#include #include "data-stream.h" @@ -181,7 +181,7 @@ struct lttng_live_stream_iterator *lttng_live_stream_iterator_create( stream->buflen = session->lttng_live->max_query_size; ret = lttng_live_add_port(lttng_live, stream); - assert(!ret); + BT_ASSERT(!ret); bt_list_add(&stream->node, &trace->streams); @@ -206,7 +206,7 @@ void lttng_live_stream_iterator_destroy(struct lttng_live_stream_iterator *strea lttng_live = stream->trace->session->lttng_live; ret = lttng_live_remove_port(lttng_live, stream->port); - assert(!ret); + BT_ASSERT(!ret); if (stream->stream) { BT_PUT(stream->stream); diff --git a/plugins/ctf/lttng-live/lttng-live.c b/plugins/ctf/lttng-live/lttng-live.c index 72b1b46d..107c4a26 100644 --- a/plugins/ctf/lttng-live/lttng-live.c +++ b/plugins/ctf/lttng-live/lttng-live.c @@ -35,7 +35,7 @@ #include #include #include -#include +#include #include #include @@ -108,7 +108,7 @@ int lttng_live_add_port(struct lttng_live_component *lttng_live, enum bt_component_status status; ret = sprintf(name, STREAM_NAME_PREFIX "%" PRIu64, stream_iter->viewer_stream_id); - assert(ret > 0); + BT_ASSERT(ret > 0); strcpy(stream_iter->name, name); if (lttng_live_is_canceled(lttng_live)) { return 0; @@ -158,7 +158,7 @@ int lttng_live_remove_port(struct lttng_live_component *lttng_live, if (nr_ports == 1) { enum bt_component_status status; - assert(!lttng_live->no_stream_port); + BT_ASSERT(!lttng_live->no_stream_port); if (lttng_live_is_canceled(lttng_live)) { return 0; @@ -206,14 +206,14 @@ void lttng_live_destroy_trace(struct bt_object *obj) struct lttng_live_trace *trace = container_of(obj, struct lttng_live_trace, obj); BT_LOGI("Destroy trace"); - assert(bt_list_empty(&trace->streams)); + BT_ASSERT(bt_list_empty(&trace->streams)); bt_list_del(&trace->node); if (trace->trace) { int retval; retval = bt_trace_set_is_static(trace->trace); - assert(!retval); + BT_ASSERT(!retval); BT_PUT(trace->trace); } lttng_live_metadata_fini(trace); @@ -418,7 +418,7 @@ enum bt_lttng_live_iterator_status lttng_live_iterator_next_handle_one_no_data_s if (ret != BT_LTTNG_LIVE_ITERATOR_STATUS_OK) { goto end; } - assert(lttng_live_stream->state != LTTNG_LIVE_STREAM_EOF); + BT_ASSERT(lttng_live_stream->state != LTTNG_LIVE_STREAM_EOF); if (lttng_live_stream->state == LTTNG_LIVE_STREAM_QUIESCENT) { if (orig_state == LTTNG_LIVE_STREAM_QUIESCENT_NO_DATA && lttng_live_stream->last_returned_inactivity_timestamp == @@ -779,7 +779,7 @@ retry: status = lttng_live_iterator_next_handle_one_quiescent_stream( lttng_live, stream_iter, &next_return.notification); if (status != BT_LTTNG_LIVE_ITERATOR_STATUS_OK) { - assert(next_return.notification == NULL); + BT_ASSERT(next_return.notification == NULL); goto end; } if (next_return.notification) { @@ -788,7 +788,7 @@ retry: status = lttng_live_iterator_next_handle_one_active_data_stream(lttng_live, stream_iter, &next_return.notification); if (status != BT_LTTNG_LIVE_ITERATOR_STATUS_OK) { - assert(next_return.notification == NULL); + BT_ASSERT(next_return.notification == NULL); } end: @@ -907,10 +907,10 @@ enum bt_notification_iterator_status lttng_live_iterator_init( BT_NOTIFICATION_ITERATOR_STATUS_OK; struct lttng_live_stream_iterator_generic *s; - assert(it); + BT_ASSERT(it); s = bt_private_port_get_user_data(port); - assert(s); + BT_ASSERT(s); switch (s->type) { case LIVE_STREAM_TYPE_NO_STREAM: { @@ -1040,7 +1040,7 @@ void lttng_live_component_destroy_data(struct lttng_live_component *lttng_live) bt_get(lttng_live->no_stream_port); ret = bt_private_port_remove_from_component(lttng_live->no_stream_port); bt_put(lttng_live->no_stream_port); - assert(!ret); + BT_ASSERT(!ret); } if (lttng_live->no_stream_iter) { g_free(lttng_live->no_stream_iter); diff --git a/plugins/ctf/lttng-live/metadata.c b/plugins/ctf/lttng-live/metadata.c index 4a3b50b0..0aae051c 100644 --- a/plugins/ctf/lttng-live/metadata.c +++ b/plugins/ctf/lttng-live/metadata.c @@ -69,13 +69,13 @@ enum bt_lttng_live_iterator_status lttng_live_update_clock_map( } count = bt_trace_get_clock_class_count(trace->trace); - assert(count >= 0); + BT_ASSERT(count >= 0); for (i = 0; i < count; i++) { struct bt_clock_class *clock_class = bt_trace_get_clock_class_by_index(trace->trace, i); - assert(clock_class); + BT_ASSERT(clock_class); ret = bt_clock_class_priority_map_add_clock_class( trace->cc_prio_map, clock_class, 0); BT_PUT(clock_class); diff --git a/plugins/ctf/lttng-live/viewer-connection.c b/plugins/ctf/lttng-live/viewer-connection.c index 93ad97a5..0492340c 100644 --- a/plugins/ctf/lttng-live/viewer-connection.c +++ b/plugins/ctf/lttng-live/viewer-connection.c @@ -57,7 +57,7 @@ static ssize_t lttng_live_recv(struct bt_live_viewer_connection *viewer_connecti do { ret = bt_socket_recv(sock, buf + copied, to_copy, 0); if (ret > 0) { - assert(ret <= to_copy); + BT_ASSERT(ret <= to_copy); copied += ret; to_copy -= ret; } @@ -178,13 +178,13 @@ static int lttng_live_handshake(struct bt_live_viewer_connection *viewer_connect */ memcpy(cmd_buf, &cmd, sizeof(cmd)); memcpy(cmd_buf + sizeof(cmd), &connect, sizeof(connect)); - ret_len = lttng_live_send(viewer_connection, &cmd_buf, cmd_buf_len); if (ret_len == BT_SOCKET_ERROR) { BT_LOGE("Error sending version: %s", bt_socket_errormsg()); goto error; } - assert(ret_len == cmd_buf_len); + + BT_ASSERT(ret_len == cmd_buf_len); ret_len = lttng_live_recv(viewer_connection, &connect, sizeof(connect)); if (ret_len == 0) { @@ -195,7 +195,7 @@ static int lttng_live_handshake(struct bt_live_viewer_connection *viewer_connect BT_LOGE("Error receiving version: %s", bt_socket_errormsg()); goto error; } - assert(ret_len == sizeof(connect)); + BT_ASSERT(ret_len == sizeof(connect)); BT_LOGD("Received viewer session ID : %" PRIu64, (uint64_t) be64toh(connect.viewer_session_id)); @@ -577,7 +577,7 @@ struct bt_value *bt_live_viewer_connection_list_sessions(struct bt_live_viewer_c BT_LOGE("Error sending cmd: %s", bt_socket_errormsg()); goto error; } - assert(ret_len == sizeof(cmd)); + BT_ASSERT(ret_len == sizeof(cmd)); ret_len = lttng_live_recv(viewer_connection, &list, sizeof(list)); if (ret_len == 0) { @@ -588,7 +588,7 @@ struct bt_value *bt_live_viewer_connection_list_sessions(struct bt_live_viewer_c BT_LOGE("Error receiving session list: %s", bt_socket_errormsg()); goto error; } - assert(ret_len == sizeof(list)); + BT_ASSERT(ret_len == sizeof(list)); sessions_count = be32toh(list.sessions_count); for (i = 0; i < sessions_count; i++) { @@ -604,7 +604,7 @@ struct bt_value *bt_live_viewer_connection_list_sessions(struct bt_live_viewer_c BT_LOGE("Error receiving session: %s", bt_socket_errormsg()); goto error; } - assert(ret_len == sizeof(lsession)); + BT_ASSERT(ret_len == sizeof(lsession)); lsession.hostname[LTTNG_VIEWER_HOST_NAME_MAX - 1] = '\0'; lsession.session_name[LTTNG_VIEWER_NAME_MAX - 1] = '\0'; if (list_append_session(results, @@ -641,7 +641,7 @@ int lttng_live_query_session_ids(struct lttng_live_component *lttng_live) BT_LOGE("Error sending cmd: %s", bt_socket_errormsg()); goto error; } - assert(ret_len == sizeof(cmd)); + BT_ASSERT(ret_len == sizeof(cmd)); ret_len = lttng_live_recv(viewer_connection, &list, sizeof(list)); if (ret_len == 0) { @@ -652,7 +652,7 @@ int lttng_live_query_session_ids(struct lttng_live_component *lttng_live) BT_LOGE("Error receiving session list: %s", bt_socket_errormsg()); goto error; } - assert(ret_len == sizeof(list)); + BT_ASSERT(ret_len == sizeof(list)); sessions_count = be32toh(list.sessions_count); for (i = 0; i < sessions_count; i++) { @@ -666,7 +666,7 @@ int lttng_live_query_session_ids(struct lttng_live_component *lttng_live) BT_LOGE("Error receiving session: %s", bt_socket_errormsg()); goto error; } - assert(ret_len == sizeof(lsession)); + BT_ASSERT(ret_len == sizeof(lsession)); lsession.hostname[LTTNG_VIEWER_HOST_NAME_MAX - 1] = '\0'; lsession.session_name[LTTNG_VIEWER_NAME_MAX - 1] = '\0'; session_id = be64toh(lsession.id); @@ -712,7 +712,7 @@ int lttng_live_create_viewer_session(struct lttng_live_component *lttng_live) BT_LOGE("Error sending cmd: %s", bt_socket_errormsg()); goto error; } - assert(ret_len == sizeof(cmd)); + BT_ASSERT(ret_len == sizeof(cmd)); ret_len = lttng_live_recv(viewer_connection, &resp, sizeof(resp)); if (ret_len == 0) { @@ -723,7 +723,7 @@ int lttng_live_create_viewer_session(struct lttng_live_component *lttng_live) BT_LOGE("Error receiving create session reply: %s", bt_socket_errormsg()); goto error; } - assert(ret_len == sizeof(resp)); + BT_ASSERT(ret_len == sizeof(resp)); if (be32toh(resp.status) != LTTNG_VIEWER_CREATE_SESSION_OK) { BT_LOGE("Error creating viewer session"); @@ -765,7 +765,7 @@ int receive_streams(struct lttng_live_session *session, BT_LOGE("Error receiving stream"); goto error; } - assert(ret_len == sizeof(stream)); + BT_ASSERT(ret_len == sizeof(stream)); stream.path_name[LTTNG_VIEWER_PATH_MAX - 1] = '\0'; stream.channel_name[LTTNG_VIEWER_NAME_MAX - 1] = '\0'; stream_id = be64toh(stream.id); @@ -837,14 +837,13 @@ int lttng_live_attach_session(struct lttng_live_session *session) */ memcpy(cmd_buf, &cmd, sizeof(cmd)); memcpy(cmd_buf + sizeof(cmd), &rq, sizeof(rq)); - ret_len = lttng_live_send(viewer_connection, &cmd_buf, cmd_buf_len); if (ret_len == BT_SOCKET_ERROR) { BT_LOGE("Error sending attach request: %s", bt_socket_errormsg()); goto error; } - assert(ret_len == cmd_buf_len); + BT_ASSERT(ret_len == cmd_buf_len); ret_len = lttng_live_recv(viewer_connection, &rp, sizeof(rp)); if (ret_len == 0) { BT_LOGI("Remote side has closed connection"); @@ -854,7 +853,7 @@ int lttng_live_attach_session(struct lttng_live_session *session) BT_LOGE("Error receiving attach response: %s", bt_socket_errormsg()); goto error; } - assert(ret_len == sizeof(rp)); + BT_ASSERT(ret_len == sizeof(rp)); streams_count = be32toh(rp.streams_count); switch(be32toh(rp.status)) { @@ -923,14 +922,13 @@ int lttng_live_detach_session(struct lttng_live_session *session) */ memcpy(cmd_buf, &cmd, sizeof(cmd)); memcpy(cmd_buf + sizeof(cmd), &rq, sizeof(rq)); - ret_len = lttng_live_send(viewer_connection, &cmd_buf, cmd_buf_len); if (ret_len == BT_SOCKET_ERROR) { BT_LOGE("Error sending detach request: %s", bt_socket_errormsg()); goto error; } - assert(ret_len == cmd_buf_len); + BT_ASSERT(ret_len == cmd_buf_len); ret_len = lttng_live_recv(viewer_connection, &rp, sizeof(rp)); if (ret_len == 0) { BT_LOGI("Remote side has closed connection"); @@ -940,7 +938,7 @@ int lttng_live_detach_session(struct lttng_live_session *session) BT_LOGE("Error receiving detach response: %s", bt_socket_errormsg()); goto error; } - assert(ret_len == sizeof(rp)); + BT_ASSERT(ret_len == sizeof(rp)); switch(be32toh(rp.status)) { case LTTNG_VIEWER_DETACH_SESSION_OK: @@ -995,14 +993,13 @@ ssize_t lttng_live_get_one_metadata_packet(struct lttng_live_trace *trace, */ memcpy(cmd_buf, &cmd, sizeof(cmd)); memcpy(cmd_buf + sizeof(cmd), &rq, sizeof(rq)); - ret_len = lttng_live_send(viewer_connection, &cmd_buf, cmd_buf_len); if (ret_len == BT_SOCKET_ERROR) { BT_LOGE("Error sending get_metadata request: %s", bt_socket_errormsg()); goto error; } - assert(ret_len == cmd_buf_len); + BT_ASSERT(ret_len == cmd_buf_len); ret_len = lttng_live_recv(viewer_connection, &rp, sizeof(rp)); if (ret_len == 0) { BT_LOGI("Remote side has closed connection"); @@ -1012,7 +1009,7 @@ ssize_t lttng_live_get_one_metadata_packet(struct lttng_live_trace *trace, BT_LOGE("Error receiving get_metadata response: %s", bt_socket_errormsg()); goto error; } - assert(ret_len == sizeof(rp)); + BT_ASSERT(ret_len == sizeof(rp)); switch (be32toh(rp.status)) { case LTTNG_VIEWER_METADATA_OK: @@ -1050,7 +1047,7 @@ ssize_t lttng_live_get_one_metadata_packet(struct lttng_live_trace *trace, BT_LOGE("Error receiving trace packet: %s", bt_socket_errormsg()); goto error_free_data; } - assert(ret_len == len); + BT_ASSERT(ret_len == len); do { ret_len = fwrite(data, 1, len, fp); @@ -1059,7 +1056,7 @@ ssize_t lttng_live_get_one_metadata_packet(struct lttng_live_trace *trace, BT_LOGE("Writing in the metadata fp"); goto error_free_data; } - assert(ret_len == len); + BT_ASSERT(ret_len == len); free(data); ret = len; end: @@ -1078,8 +1075,8 @@ static void lttng_index_to_packet_index(struct lttng_viewer_index *lindex, struct packet_index *pindex) { - assert(lindex); - assert(pindex); + BT_ASSERT(lindex); + BT_ASSERT(pindex); pindex->offset = be64toh(lindex->offset); pindex->packet_size = be64toh(lindex->packet_size); @@ -1122,14 +1119,13 @@ enum bt_lttng_live_iterator_status lttng_live_get_next_index(struct lttng_live_c */ memcpy(cmd_buf, &cmd, sizeof(cmd)); memcpy(cmd_buf + sizeof(cmd), &rq, sizeof(rq)); - ret_len = lttng_live_send(viewer_connection, &cmd_buf, cmd_buf_len); if (ret_len == BT_SOCKET_ERROR) { BT_LOGE("Error sending get_next_index request: %s", bt_socket_errormsg()); goto error; } - assert(ret_len == cmd_buf_len); + BT_ASSERT(ret_len == cmd_buf_len); ret_len = lttng_live_recv(viewer_connection, &rp, sizeof(rp)); if (ret_len == 0) { BT_LOGI("Remote side has closed connection"); @@ -1139,7 +1135,7 @@ enum bt_lttng_live_iterator_status lttng_live_get_next_index(struct lttng_live_c BT_LOGE("Error receiving get_next_index response: %s", bt_socket_errormsg()); goto error; } - assert(ret_len == sizeof(rp)); + BT_ASSERT(ret_len == sizeof(rp)); flags = be32toh(rp.flags); status = be32toh(rp.status); @@ -1155,7 +1151,7 @@ enum bt_lttng_live_iterator_status lttng_live_get_next_index(struct lttng_live_c stream->current_inactivity_timestamp = index->ts_cycles.timestamp_end; ctf_stream_class_id = be64toh(rp.stream_id); if (stream->ctf_stream_class_id != -1ULL) { - assert(stream->ctf_stream_class_id == + BT_ASSERT(stream->ctf_stream_class_id == ctf_stream_class_id); } else { stream->ctf_stream_class_id = ctf_stream_class_id; @@ -1171,7 +1167,7 @@ enum bt_lttng_live_iterator_status lttng_live_get_next_index(struct lttng_live_c lttng_index_to_packet_index(&rp, index); ctf_stream_class_id = be64toh(rp.stream_id); if (stream->ctf_stream_class_id != -1ULL) { - assert(stream->ctf_stream_class_id == + BT_ASSERT(stream->ctf_stream_class_id == ctf_stream_class_id); } else { stream->ctf_stream_class_id = ctf_stream_class_id; @@ -1262,14 +1258,13 @@ enum bt_notif_iter_medium_status lttng_live_get_stream_bytes(struct lttng_live_c */ memcpy(cmd_buf, &cmd, sizeof(cmd)); memcpy(cmd_buf + sizeof(cmd), &rq, sizeof(rq)); - ret_len = lttng_live_send(viewer_connection, &cmd_buf, cmd_buf_len); if (ret_len == BT_SOCKET_ERROR) { BT_LOGE("Error sending get_data request: %s", bt_socket_errormsg()); goto error; } - assert(ret_len == cmd_buf_len); + BT_ASSERT(ret_len == cmd_buf_len); ret_len = lttng_live_recv(viewer_connection, &rp, sizeof(rp)); if (ret_len == 0) { BT_LOGI("Remote side has closed connection"); @@ -1336,7 +1331,7 @@ enum bt_notif_iter_medium_status lttng_live_get_stream_bytes(struct lttng_live_c BT_LOGE("Error receiving trace packet: %s", bt_socket_errormsg()); goto error; } - assert(ret_len == req_len); + BT_ASSERT(ret_len == req_len); *recv_len = ret_len; end: return retstatus; @@ -1388,14 +1383,13 @@ enum bt_lttng_live_iterator_status lttng_live_get_new_streams( */ memcpy(cmd_buf, &cmd, sizeof(cmd)); memcpy(cmd_buf + sizeof(cmd), &rq, sizeof(rq)); - ret_len = lttng_live_send(viewer_connection, &cmd_buf, cmd_buf_len); if (ret_len == BT_SOCKET_ERROR) { BT_LOGE("Error sending get_new_streams request: %s", bt_socket_errormsg()); goto error; } - assert(ret_len == cmd_buf_len); + BT_ASSERT(ret_len == cmd_buf_len); ret_len = lttng_live_recv(viewer_connection, &rp, sizeof(rp)); if (ret_len == 0) { BT_LOGI("Remote side has closed connection"); @@ -1405,7 +1399,7 @@ enum bt_lttng_live_iterator_status lttng_live_get_new_streams( BT_LOGE("Error receiving get_new_streams response"); goto error; } - assert(ret_len == sizeof(rp)); + BT_ASSERT(ret_len == sizeof(rp)); streams_count = be32toh(rp.streams_count); diff --git a/plugins/libctfcopytrace/clock-fields.c b/plugins/libctfcopytrace/clock-fields.c index 4e465827..05a2b0c5 100644 --- a/plugins/libctfcopytrace/clock-fields.c +++ b/plugins/libctfcopytrace/clock-fields.c @@ -30,7 +30,7 @@ #include "logging.h" #include -#include +#include #include #include "clock-fields.h" @@ -226,7 +226,7 @@ int find_update_sequence_clock_fields(FILE *err, struct bt_field_type *type, struct bt_field_type *entry_type = NULL; entry_type = bt_field_type_sequence_get_element_type(type); - assert(entry_type); + BT_ASSERT(entry_type); ret = find_update_clock_fields(err, entry_type, writer_clock_class); BT_PUT(entry_type); @@ -252,7 +252,7 @@ int find_update_array_clock_fields(FILE *err, struct bt_field_type *type, struct bt_field_type *entry_type = NULL; entry_type = bt_field_type_array_get_element_type(type); - assert(entry_type); + BT_ASSERT(entry_type); ret = find_update_clock_fields(err, entry_type, writer_clock_class); BT_PUT(entry_type); @@ -274,7 +274,7 @@ int find_update_enum_clock_fields(FILE *err, struct bt_field_type *type, struct bt_field_type *entry_type = NULL; entry_type = bt_field_type_enumeration_get_container_type(type); - assert(entry_type); + BT_ASSERT(entry_type); ret = find_update_clock_fields(err, entry_type, writer_clock_class); BT_PUT(entry_type); @@ -303,7 +303,7 @@ struct bt_field_type *override_header_type(FILE *err, /* FIXME multi-clock? */ writer_clock_class = bt_trace_get_clock_class_by_index(writer_trace, 0); - assert(writer_clock_class); + BT_ASSERT(writer_clock_class); new_type = bt_field_type_copy(type); if (!new_type) { @@ -402,7 +402,7 @@ int copy_override_field(FILE *err, struct bt_event *event, int ret = 0; type = bt_field_get_type(field); - assert(type); + BT_ASSERT(type); switch (bt_field_type_get_type_id(type)) { case BT_FIELD_TYPE_ID_INTEGER: @@ -455,10 +455,10 @@ int copy_find_clock_enum_field(FILE *err, struct bt_event *event, struct bt_field *container = NULL, *copy_container = NULL; container = bt_field_enumeration_get_container(field); - assert(container); + BT_ASSERT(container); copy_container = bt_field_enumeration_get_container(copy_field); - assert(copy_container); + BT_ASSERT(copy_container); ret = copy_override_field(err, event, writer_event, container, copy_container); @@ -489,7 +489,7 @@ int copy_find_clock_variant_field(FILE *err, struct bt_event *event, struct bt_field *variant_field = NULL, *copy_variant_field = NULL; tag = bt_field_variant_get_tag(field); - assert(tag); + BT_ASSERT(tag); variant_field = bt_field_variant_get_field(field, tag); if (!variant_field) { @@ -498,7 +498,7 @@ int copy_find_clock_variant_field(FILE *err, struct bt_event *event, } copy_variant_field = bt_field_variant_get_field(copy_field, tag); - assert(copy_variant_field); + BT_ASSERT(copy_variant_field); ret = copy_override_field(err, event, writer_event, variant_field, copy_variant_field); @@ -531,7 +531,7 @@ int copy_find_clock_sequence_field(FILE *err, struct bt_field *entry_field = NULL, *entry_copy = NULL; length_field = bt_field_sequence_get_length(field); - assert(length_field); + BT_ASSERT(length_field); ret = bt_field_unsigned_integer_get_value(length_field, &count); if (ret) { @@ -554,7 +554,7 @@ int copy_find_clock_sequence_field(FILE *err, } entry_copy = bt_field_sequence_get_field(copy_field, i); - assert(entry_copy); + BT_ASSERT(entry_copy); ret = copy_override_field(err, event, writer_event, entry_field, entry_copy); @@ -597,7 +597,7 @@ int copy_find_clock_array_field(FILE *err, } entry_copy = bt_field_array_get_field(copy_field, i); - assert(entry_copy); + BT_ASSERT(entry_copy); ret = copy_override_field(err, event, writer_event, entry_field, entry_copy); @@ -649,7 +649,7 @@ int copy_find_clock_struct_field(FILE *err, } entry_copy = bt_field_structure_get_field_by_index(copy_field, i); - assert(entry_copy); + BT_ASSERT(entry_copy); ret = copy_override_field(err, event, writer_event, entry_field, entry_copy); @@ -727,7 +727,7 @@ struct bt_clock_class *stream_class_get_clock_class(FILE *err, struct bt_clock_class *clock_class = NULL; trace = bt_stream_class_get_trace(stream_class); - assert(trace); + BT_ASSERT(trace); /* FIXME multi-clock? */ clock_class = bt_trace_get_clock_class_by_index(trace, 0); @@ -744,11 +744,11 @@ struct bt_clock_class *event_get_clock_class(FILE *err, struct bt_event *event) struct bt_clock_class *clock_class = NULL; event_class = bt_event_get_class(event); - assert(event_class); + BT_ASSERT(event_class); stream_class = bt_event_class_get_stream_class(event_class); BT_PUT(event_class); - assert(stream_class); + BT_ASSERT(stream_class); clock_class = stream_class_get_clock_class(err, stream_class); bt_put(stream_class); @@ -774,7 +774,7 @@ int copy_find_clock_int_field(FILE *err, clock_value = bt_event_get_clock_value(event, clock_class); BT_PUT(clock_class); - assert(clock_value); + BT_ASSERT(clock_value); ret = bt_clock_value_get_value(clock_value, &value); BT_PUT(clock_value); @@ -790,7 +790,7 @@ int copy_find_clock_int_field(FILE *err, } writer_clock_class = event_get_clock_class(err, writer_event); - assert(writer_clock_class); + BT_ASSERT(writer_clock_class); writer_clock_value = bt_clock_value_create(writer_clock_class, value); BT_PUT(writer_clock_class); diff --git a/plugins/libctfcopytrace/ctfcopytrace.c b/plugins/libctfcopytrace/ctfcopytrace.c index 8f63b24b..9e8e16cd 100644 --- a/plugins/libctfcopytrace/ctfcopytrace.c +++ b/plugins/libctfcopytrace/ctfcopytrace.c @@ -30,7 +30,7 @@ #include "logging.h" #include -#include +#include #include "ctfcopytrace.h" #include "clock-fields.h" @@ -45,10 +45,10 @@ struct bt_clock_class *ctf_copy_clock_class(FILE *err, const char *name, *description; struct bt_clock_class *writer_clock_class = NULL; - assert(err && clock_class); + BT_ASSERT(err && clock_class); name = bt_clock_class_get_name(clock_class); - assert(name); + BT_ASSERT(name); writer_clock_class = bt_clock_class_create(name, bt_clock_class_get_frequency(clock_class)); @@ -61,33 +61,33 @@ struct bt_clock_class *ctf_copy_clock_class(FILE *err, if (description) { int_ret = bt_clock_class_set_description(writer_clock_class, description); - assert(!int_ret); + BT_ASSERT(!int_ret); } u64_ret = bt_clock_class_get_precision(clock_class); - assert(u64_ret != -1ULL); + BT_ASSERT(u64_ret != -1ULL); int_ret = bt_clock_class_set_precision(writer_clock_class, u64_ret); - assert(!int_ret); + BT_ASSERT(!int_ret); int_ret = bt_clock_class_get_offset_s(clock_class, &offset_s); - assert(!int_ret); + BT_ASSERT(!int_ret); int_ret = bt_clock_class_set_offset_s(writer_clock_class, offset_s); - assert(!int_ret); + BT_ASSERT(!int_ret); int_ret = bt_clock_class_get_offset_cycles(clock_class, &offset); - assert(!int_ret); + BT_ASSERT(!int_ret); int_ret = bt_clock_class_set_offset_cycles(writer_clock_class, offset); - assert(!int_ret); + BT_ASSERT(!int_ret); int_ret = bt_clock_class_is_absolute(clock_class); - assert(int_ret >= 0); + BT_ASSERT(int_ret >= 0); int_ret = bt_clock_class_set_is_absolute(writer_clock_class, int_ret); - assert(!int_ret); + BT_ASSERT(!int_ret); end: return writer_clock_class; @@ -109,7 +109,7 @@ enum bt_component_status ctf_copy_clock_classes(FILE *err, struct bt_clock_class *clock_class = bt_trace_get_clock_class_by_index(trace, i); - assert(clock_class); + BT_ASSERT(clock_class); writer_clock_class = ctf_copy_clock_class(err, clock_class); bt_put(clock_class); @@ -145,8 +145,8 @@ void replace_clock_classes(struct bt_trace *trace_copy, { int ret; - assert(trace_copy); - assert(field_type); + BT_ASSERT(trace_copy); + BT_ASSERT(field_type); switch (bt_field_type_get_type_id(field_type)) { case BT_FIELD_TYPE_ID_INTEGER: @@ -161,13 +161,13 @@ void replace_clock_classes(struct bt_trace *trace_copy, } name = bt_clock_class_get_name(mapped_clock_class); - assert(name); + BT_ASSERT(name); clock_class_copy = bt_trace_get_clock_class_by_name( trace_copy, name); - assert(clock_class_copy); + BT_ASSERT(clock_class_copy); ret = bt_field_type_integer_set_mapped_clock_class( field_type, clock_class_copy); - assert(ret == 0); + BT_ASSERT(ret == 0); bt_put(mapped_clock_class); bt_put(clock_class_copy); break; @@ -197,7 +197,7 @@ void replace_clock_classes(struct bt_trace *trace_copy, abort(); } - assert(subtype); + BT_ASSERT(subtype); replace_clock_classes(trace_copy, subtype); bt_put(subtype); break; @@ -214,7 +214,7 @@ void replace_clock_classes(struct bt_trace *trace_copy, ret = bt_field_type_structure_get_field_by_index( field_type, &name, &member_type, i); - assert(ret == 0); + BT_ASSERT(ret == 0); replace_clock_classes(trace_copy, member_type); bt_put(member_type); } @@ -233,7 +233,7 @@ void replace_clock_classes(struct bt_trace *trace_copy, ret = bt_field_type_variant_get_field_by_index( field_type, &name, &member_type, i); - assert(ret == 0); + BT_ASSERT(ret == 0); replace_clock_classes(trace_copy, member_type); bt_put(member_type); } @@ -261,10 +261,10 @@ struct bt_event_class *ctf_copy_event_class(FILE *err, name = bt_event_class_get_name(event_class); writer_event_class = bt_event_class_create(name); - assert(writer_event_class); + BT_ASSERT(writer_event_class); id = bt_event_class_get_id(event_class); - assert(id >= 0); + BT_ASSERT(id >= 0); ret = bt_event_class_set_id(writer_event_class, id); if (ret) { @@ -352,16 +352,16 @@ enum bt_component_status ctf_copy_event_classes(FILE *err, struct bt_trace *writer_trace = bt_stream_class_get_trace(writer_stream_class); - assert(writer_trace); + BT_ASSERT(writer_trace); count = bt_stream_class_get_event_class_count(stream_class); - assert(count >= 0); + BT_ASSERT(count >= 0); for (i = 0; i < count; i++) { int int_ret; event_class = bt_stream_class_get_event_class_by_index( stream_class, i); - assert(event_class); + BT_ASSERT(event_class); if (i < bt_stream_class_get_event_class_count(writer_stream_class)) { writer_event_class = bt_stream_class_get_event_class_by_index( @@ -421,7 +421,7 @@ struct bt_stream_class *ctf_copy_stream_class(FILE *err, const char *name = bt_stream_class_get_name(stream_class); writer_stream_class = bt_stream_class_create_empty(name); - assert(writer_stream_class); + BT_ASSERT(writer_stream_class); type = bt_stream_class_get_packet_context_type(stream_class); if (type) { @@ -449,7 +449,7 @@ struct bt_stream_class *ctf_copy_stream_class(FILE *err, } ret_int = bt_trace_get_clock_class_count(writer_trace); - assert(ret_int >= 0); + BT_ASSERT(ret_int >= 0); if (override_ts64 && ret_int > 0) { struct bt_field_type *new_event_header_type; @@ -669,7 +669,7 @@ int ctf_copy_event_header(FILE *err, struct bt_event *event, clock_value = bt_event_get_clock_value(event, clock_class); BT_PUT(clock_class); - assert(clock_value); + BT_ASSERT(clock_value); ret = bt_clock_value_get_value(clock_value, &value); BT_PUT(clock_value); @@ -729,10 +729,10 @@ struct bt_trace *event_class_get_trace(FILE *err, struct bt_stream_class *stream_class = NULL; stream_class = bt_event_class_get_stream_class(event_class); - assert(stream_class); + BT_ASSERT(stream_class); trace = bt_stream_class_get_trace(stream_class); - assert(trace); + BT_ASSERT(trace); bt_put(stream_class); return trace; @@ -768,11 +768,11 @@ struct bt_event *ctf_copy_event(FILE *err, struct bt_event *event, * is. */ ret = bt_trace_get_clock_class_count(writer_trace); - assert(ret >= 0); + BT_ASSERT(ret >= 0); if (override_ts64 && ret > 0) { copy_field = bt_event_get_header(writer_event); - assert(copy_field); + BT_ASSERT(copy_field); ret = copy_override_field(err, event, writer_event, field, copy_field); @@ -873,11 +873,11 @@ enum bt_component_status ctf_copy_trace(FILE *err, struct bt_trace *trace, name = bt_trace_get_environment_field_name_by_index( trace, i); - assert(name); + BT_ASSERT(name); value = bt_trace_get_environment_field_value_by_index( trace, i); - assert(value); + BT_ASSERT(value); ret_int = bt_trace_set_environment_field(writer_trace, name, value); @@ -891,7 +891,7 @@ enum bt_component_status ctf_copy_trace(FILE *err, struct bt_trace *trace, } order = bt_trace_get_native_byte_order(trace); - assert(order != BT_BYTE_ORDER_UNKNOWN); + BT_ASSERT(order != BT_BYTE_ORDER_UNKNOWN); /* * Only explicitly set the writer trace's native byte order if diff --git a/plugins/lttng-utils/copy.c b/plugins/lttng-utils/copy.c index d444ed82..9c51852a 100644 --- a/plugins/lttng-utils/copy.c +++ b/plugins/lttng-utils/copy.c @@ -30,7 +30,7 @@ #include "logging.h" #include -#include +#include #include #include @@ -80,10 +80,10 @@ struct bt_field *get_payload_field(FILE *err, struct bt_field_type *payload_type = NULL; payload = bt_event_get_payload(event, NULL); - assert(payload); + BT_ASSERT(payload); payload_type = bt_field_get_type(payload); - assert(payload_type); + BT_ASSERT(payload_type); if (bt_field_type_get_type_id(payload_type) != BT_FIELD_TYPE_ID_STRUCT) { BT_LOGE("Wrong type, expected struct: field-name=\"%s\"", @@ -112,7 +112,7 @@ struct bt_field *get_stream_event_context_field(FILE *err, } sec_type = bt_field_get_type(sec); - assert(sec_type); + BT_ASSERT(sec_type); if (bt_field_type_get_type_id(sec_type) != BT_FIELD_TYPE_ID_STRUCT) { BT_LOGE("Wrong type, expected struct, field-name=\"%s\"", @@ -143,7 +143,7 @@ int get_stream_event_context_unsigned_int_field_value(FILE *err, } field_type = bt_field_get_type(field); - assert(field_type); + BT_ASSERT(field_type); if (bt_field_type_get_type_id(field_type) != BT_FIELD_TYPE_ID_INTEGER) { BT_LOGE("Wrong type, expected integer: field-name=\"%s\"", @@ -187,7 +187,7 @@ int get_stream_event_context_int_field_value(FILE *err, struct bt_event *event, } field_type = bt_field_get_type(field); - assert(field_type); + BT_ASSERT(field_type); if (bt_field_type_get_type_id(field_type) != BT_FIELD_TYPE_ID_INTEGER) { BT_LOGE("Wrong type, expected integer: field-name=\"%s\"", field_name); @@ -227,7 +227,7 @@ int get_payload_unsigned_int_field_value(FILE *err, } field_type = bt_field_get_type(field); - assert(field_type); + BT_ASSERT(field_type); if (bt_field_type_get_type_id(field_type) != BT_FIELD_TYPE_ID_INTEGER) { BT_LOGE("Wrong type, expected integer: field-name=\"%s\"", @@ -272,7 +272,7 @@ int get_payload_int_field_value(FILE *err, struct bt_event *event, } field_type = bt_field_get_type(field); - assert(field_type); + BT_ASSERT(field_type); if (bt_field_type_get_type_id(field_type) != BT_FIELD_TYPE_ID_INTEGER) { BT_LOGE("Wrong type, expected integer: field-name=\"%s\"", field_name); @@ -319,7 +319,7 @@ int get_payload_string_field_value(FILE *err, } field_type = bt_field_get_type(field); - assert(field_type); + BT_ASSERT(field_type); if (bt_field_type_get_type_id(field_type) != BT_FIELD_TYPE_ID_STRING) { BT_LOGE("Wrong type, expected string: field-name=\"%s\"", @@ -365,7 +365,7 @@ int get_payload_build_id_field_value(FILE *err, } field_type = bt_field_get_type(field); - assert(field_type); + BT_ASSERT(field_type); if (bt_field_type_get_type_id(field_type) != BT_FIELD_TYPE_ID_SEQUENCE) { BT_LOGE("Wrong type, expected sequence: field-name=\"%s\"", field_name); @@ -374,7 +374,7 @@ int get_payload_build_id_field_value(FILE *err, BT_PUT(field_type); seq_len = bt_field_sequence_get_length(field); - assert(seq_len); + BT_ASSERT(seq_len); ret = bt_field_unsigned_integer_get_value(seq_len, build_id_len); if (ret) { @@ -449,7 +449,7 @@ struct debug_info *insert_new_debug_info(struct debug_info_iterator *debug_it, goto end; } ret = bt_value_string_get(field, &str_value); - assert(ret == BT_VALUE_STATUS_OK); + BT_ASSERT(ret == BT_VALUE_STATUS_OK); /* Domain not ust, no debug info */ if (strcmp(str_value, "ust") != 0) { @@ -465,7 +465,7 @@ struct debug_info *insert_new_debug_info(struct debug_info_iterator *debug_it, goto end; } ret = bt_value_string_get(field, &str_value); - assert(ret == BT_VALUE_STATUS_OK); + BT_ASSERT(ret == BT_VALUE_STATUS_OK); /* Tracer_name not lttng-ust, no debug info */ if (strcmp(str_value, "lttng-ust") != 0) { @@ -597,10 +597,10 @@ int sync_event_classes(struct debug_info_iterator *debug_it, enum bt_component_status ret; stream_class = bt_stream_get_class(stream); - assert(stream_class); + BT_ASSERT(stream_class); writer_stream_class = bt_stream_get_class(writer_stream); - assert(writer_stream_class); + BT_ASSERT(writer_stream_class); ret = ctf_copy_event_classes(debug_it->err, stream_class, writer_stream_class); @@ -636,10 +636,10 @@ void trace_is_static_listener(struct bt_trace *trace, void *data) nr_stream = bt_trace_get_stream_count(trace); for (i = 0; i < nr_stream; i++) { stream = bt_trace_get_stream_by_index(trace, i); - assert(stream); + BT_ASSERT(stream); writer_stream = bt_trace_get_stream_by_index(writer_trace, i); - assert(writer_stream); + BT_ASSERT(writer_stream); ret = sync_event_classes(di_trace->debug_it, stream, writer_stream); if (ret) { @@ -683,10 +683,10 @@ struct debug_info_trace *insert_new_trace(struct debug_info_iterator *debug_it, } stream_class = bt_stream_get_class(stream); - assert(stream_class); + BT_ASSERT(stream_class); trace = bt_stream_class_get_trace(stream_class); - assert(trace); + BT_ASSERT(trace); ret = ctf_copy_trace(debug_it->err, trace, writer_trace); if (ret != BT_COMPONENT_STATUS_OK) { @@ -720,7 +720,7 @@ struct debug_info_trace *insert_new_trace(struct debug_info_iterator *debug_it, nr_stream = bt_trace_get_stream_count(trace); for (i = 0; i < nr_stream; i++) { stream = bt_trace_get_stream_by_index(trace, i); - assert(stream); + BT_ASSERT(stream); insert_new_stream_state(debug_it, di_trace, stream); writer_stream = insert_new_stream(debug_it, stream, di_trace); @@ -746,7 +746,7 @@ struct debug_info_trace *insert_new_trace(struct debug_info_iterator *debug_it, } else { ret = bt_trace_add_is_static_listener(trace, trace_is_static_listener, NULL, di_trace); - assert(ret >= 0); + BT_ASSERT(ret >= 0); di_trace->static_listener_id = ret; } @@ -1031,7 +1031,7 @@ int add_clock_classes(FILE *err, struct bt_trace *writer_trace, bt_trace_get_clock_class_by_index(trace, i); struct bt_clock_class *existing_clock_class = NULL; - assert(clock_class); + BT_ASSERT(clock_class); existing_clock_class = bt_trace_get_clock_class_by_name( writer_trace, bt_clock_class_get_name(clock_class)); @@ -1071,7 +1071,7 @@ struct bt_stream_class *insert_new_stream_class( int int_ret; trace = bt_stream_class_get_trace(stream_class); - assert(trace); + BT_ASSERT(trace); di_trace = lookup_trace(debug_it, trace); if (!di_trace) { @@ -1127,7 +1127,7 @@ struct bt_stream *insert_new_stream( int64_t id; stream_class = bt_stream_get_class(stream); - assert(stream_class); + BT_ASSERT(stream_class); writer_stream_class = g_hash_table_lookup( di_trace->stream_class_map, @@ -1199,10 +1199,10 @@ struct debug_info_trace *lookup_di_trace_from_stream( struct debug_info_trace *di_trace = NULL; stream_class = bt_stream_get_class(stream); - assert(stream_class); + BT_ASSERT(stream_class); trace = bt_stream_class_get_trace(stream_class); - assert(trace); + BT_ASSERT(trace); di_trace = (struct debug_info_trace *) g_hash_table_lookup( debug_it->trace_map, (gpointer) trace); @@ -1222,7 +1222,7 @@ struct bt_stream *get_writer_stream( struct debug_info_trace *di_trace = NULL; stream_class = bt_stream_get_class(stream); - assert(stream_class); + BT_ASSERT(stream_class); di_trace = lookup_di_trace_from_stream(debug_it, stream); if (!di_trace) { @@ -1258,7 +1258,7 @@ struct bt_packet *debug_info_new_packet( int int_ret; stream = bt_packet_get_stream(packet); - assert(stream); + BT_ASSERT(stream); writer_stream = get_writer_stream(debug_it, packet, stream); if (!writer_stream) { @@ -1322,7 +1322,7 @@ struct bt_packet *debug_info_close_packet( struct debug_info_trace *di_trace; stream = bt_packet_get_stream(packet); - assert(stream); + BT_ASSERT(stream); di_trace = lookup_di_trace_from_stream(debug_it, stream); if (!di_trace) { @@ -1490,7 +1490,7 @@ int set_debug_info_field(FILE *err, struct bt_field *debug_field, struct bt_field_type *field_type = NULL; debug_field_type = bt_field_get_type(debug_field); - assert(debug_field_type); + BT_ASSERT(debug_field_type); nr_fields = bt_field_type_structure_get_field_count(debug_field_type); for (i = 0; i < nr_fields; i++) { @@ -1585,13 +1585,13 @@ int copy_set_debug_info_stream_event_context(FILE *err, int ret, nr_fields, i; writer_event_context = bt_event_get_stream_event_context(writer_event); - assert(writer_event_context); + BT_ASSERT(writer_event_context); writer_event_context_type = bt_field_get_type(writer_event_context); - assert(writer_event_context_type); + BT_ASSERT(writer_event_context_type); event_context_type = bt_field_get_type(event_context); - assert(event_context_type); + BT_ASSERT(event_context_type); /* * If it is not a structure, we did not modify it to add the debug info @@ -1629,7 +1629,7 @@ int copy_set_debug_info_stream_event_context(FILE *err, !field) { debug_field = bt_field_structure_get_field_by_index( writer_event_context, i); - assert(debug_field); + BT_ASSERT(debug_field); ret = set_debug_info_field(err, debug_field, dbg_info_src, component); @@ -1684,7 +1684,7 @@ struct bt_clock_class *stream_class_get_clock_class(FILE *err, struct bt_clock_class *clock_class = NULL; trace = bt_stream_class_get_trace(stream_class); - assert(trace); + BT_ASSERT(trace); if (!bt_trace_get_clock_class_count(trace)) { /* No clock. */ @@ -1708,10 +1708,10 @@ struct bt_clock_class *event_get_clock_class(FILE *err, struct bt_event *event) struct bt_clock_class *clock_class = NULL; event_class = bt_event_get_class(event); - assert(event_class); + BT_ASSERT(event_class); stream_class = bt_event_class_get_stream_class(event_class); - assert(stream_class); + BT_ASSERT(stream_class); clock_class = stream_class_get_clock_class(err, stream_class); goto end; @@ -1828,7 +1828,7 @@ struct bt_event *debug_info_copy_event(FILE *err, struct bt_event *event, } field = bt_event_get_event_payload(event); - assert(field); + BT_ASSERT(field); copy_field = bt_field_copy(field); if (copy_field) { @@ -1867,13 +1867,13 @@ struct bt_event *debug_info_output_event( int int_ret; event_class = bt_event_get_class(event); - assert(event_class); + BT_ASSERT(event_class); stream_class = bt_event_class_get_stream_class(event_class); - assert(stream_class); + BT_ASSERT(stream_class); stream = bt_event_get_stream(event); - assert(stream); + BT_ASSERT(stream); di_trace = lookup_di_trace_from_stream(debug_it, stream); if (!di_trace) { @@ -1890,7 +1890,7 @@ struct bt_event *debug_info_output_event( } bt_get(writer_stream_class); writer_trace = bt_stream_class_get_trace(writer_stream_class); - assert(writer_trace); + BT_ASSERT(writer_trace); writer_event_class = get_event_class(debug_it, writer_stream_class, event_class); if (!writer_event_class) { @@ -1923,7 +1923,7 @@ struct bt_event *debug_info_output_event( } packet = bt_event_get_packet(event); - assert(packet); + BT_ASSERT(packet); writer_packet = lookup_packet(debug_it, packet, di_trace); if (!writer_packet) { diff --git a/plugins/lttng-utils/debug-info.c b/plugins/lttng-utils/debug-info.c index d34b2c4e..ffe22816 100644 --- a/plugins/lttng-utils/debug-info.c +++ b/plugins/lttng-utils/debug-info.c @@ -28,7 +28,7 @@ #define BT_LOG_TAG "PLUGIN-CTF-LTTNG-UTILS-DEBUG-INFO-FLT" #include "logging.h" -#include +#include #include #include "debug-info.h" #include "bin-info.h" diff --git a/plugins/lttng-utils/plugin.c b/plugins/lttng-utils/plugin.c index 266b4471..6a4841e3 100644 --- a/plugins/lttng-utils/plugin.c +++ b/plugins/lttng-utils/plugin.c @@ -31,7 +31,7 @@ #include #include -#include +#include #include "debug-info.h" #include "copy.h" @@ -88,7 +88,7 @@ void debug_info_iterator_destroy(struct bt_private_connection_private_notificati struct debug_info_iterator *it_data; it_data = bt_private_connection_private_notification_iterator_get_user_data(it); - assert(it_data); + BT_ASSERT(it_data); if (it_data->input_iterator_group) { g_ptr_array_free(it_data->input_iterator_group, TRUE); @@ -123,10 +123,10 @@ struct bt_notification *handle_notification(FILE *err, } writer_packet = debug_info_new_packet(debug_it, packet); - assert(writer_packet); + BT_ASSERT(writer_packet); new_notification = bt_notification_packet_begin_create( writer_packet); - assert(new_notification); + BT_ASSERT(new_notification); bt_put(packet); bt_put(writer_packet); break; @@ -142,10 +142,10 @@ struct bt_notification *handle_notification(FILE *err, } writer_packet = debug_info_close_packet(debug_it, packet); - assert(writer_packet); + BT_ASSERT(writer_packet); new_notification = bt_notification_packet_end_create( writer_packet); - assert(new_notification); + BT_ASSERT(new_notification); bt_put(packet); bt_put(writer_packet); break; @@ -163,11 +163,11 @@ struct bt_notification *handle_notification(FILE *err, goto end; } writer_event = debug_info_output_event(debug_it, event); - assert(writer_event); + BT_ASSERT(writer_event); new_notification = bt_notification_event_create(writer_event, cc_prio_map); bt_put(cc_prio_map); - assert(new_notification); + BT_ASSERT(new_notification); bt_put(event); bt_put(writer_event); break; @@ -183,10 +183,10 @@ struct bt_notification *handle_notification(FILE *err, } writer_stream = debug_info_stream_begin(debug_it, stream); - assert(writer_stream); + BT_ASSERT(writer_stream); new_notification = bt_notification_stream_begin_create( writer_stream); - assert(new_notification); + BT_ASSERT(new_notification); bt_put(stream); bt_put(writer_stream); break; @@ -202,10 +202,10 @@ struct bt_notification *handle_notification(FILE *err, } writer_stream = debug_info_stream_end(debug_it, stream); - assert(writer_stream); + BT_ASSERT(writer_stream); new_notification = bt_notification_stream_end_create( writer_stream); - assert(new_notification); + BT_ASSERT(new_notification); bt_put(stream); bt_put(writer_stream); break; @@ -234,12 +234,12 @@ struct bt_notification_iterator_next_method_return debug_info_iterator_next( }; debug_it = bt_private_connection_private_notification_iterator_get_user_data(iterator); - assert(debug_it); + BT_ASSERT(debug_it); component = bt_private_connection_private_notification_iterator_get_private_component(iterator); - assert(component); + BT_ASSERT(component); debug_info = bt_private_component_get_user_data(component); - assert(debug_info); + BT_ASSERT(debug_info); source_it = debug_it->input_iterator; @@ -257,7 +257,7 @@ struct bt_notification_iterator_next_method_return debug_info_iterator_next( ret.notification = handle_notification(debug_info->err, debug_it, notification); - assert(ret.notification); + BT_ASSERT(ret.notification); bt_put(notification); end: @@ -331,7 +331,7 @@ enum bt_component_status init_from_params( struct bt_value *value = NULL; enum bt_component_status ret = BT_COMPONENT_STATUS_OK; - assert(params); + BT_ASSERT(params); value = bt_value_map_get(params, "debug-info-field-name"); if (value) { diff --git a/plugins/text/dmesg/dmesg.c b/plugins/text/dmesg/dmesg.c index c126a15a..51fa20f8 100644 --- a/plugins/text/dmesg/dmesg.c +++ b/plugins/text/dmesg/dmesg.c @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include #include @@ -278,7 +278,7 @@ int create_meta(struct dmesg_component *dmesg_comp, bool has_ts) trace_name = "STDIN"; } else { basename = g_path_get_basename(dmesg_comp->params.path->str); - assert(basename); + BT_ASSERT(basename); if (strcmp(basename, G_DIR_SEPARATOR_S) != 0 && strcmp(basename, ".") != 0) { @@ -425,7 +425,7 @@ int handle_params(struct dmesg_component *dmesg_comp, struct bt_value *params) ret = bt_value_bool_get(no_timestamp, &dmesg_comp->params.no_timestamp); - assert(ret == 0); + BT_ASSERT(ret == 0); } path = bt_value_map_get(params, "path"); @@ -444,7 +444,7 @@ int handle_params(struct dmesg_component *dmesg_comp, struct bt_value *params) } ret = bt_value_string_get(path, &path_str); - assert(ret == 0); + BT_ASSERT(ret == 0); g_string_assign(dmesg_comp->params.path, path_str); } else { dmesg_comp->params.read_from_stdin = true; @@ -566,7 +566,7 @@ int create_packet_and_stream(struct dmesg_component *dmesg_comp) } ft = bt_trace_get_packet_header_type(dmesg_comp->trace); - assert(ft); + BT_ASSERT(ft); field = create_packet_header_field(ft); if (!field) { BT_LOGE_STR("Cannot create packet header field."); @@ -583,7 +583,7 @@ int create_packet_and_stream(struct dmesg_component *dmesg_comp) bt_put(field); ft = bt_stream_class_get_packet_context_type( dmesg_comp->stream_class); - assert(ft); + BT_ASSERT(ft); field = create_packet_context_field(ft); if (!field) { BT_LOGE_STR("Cannot create packet context field."); @@ -754,8 +754,8 @@ int create_event_header_from_line( struct bt_field *ts_field = NULL; int ret = 0; - assert(user_clock_value); - assert(user_field); + BT_ASSERT(user_clock_value); + BT_ASSERT(user_field); *new_start = line; if (dmesg_comp->params.no_timestamp) { @@ -798,7 +798,7 @@ int create_event_header_from_line( if (has_timestamp) { /* Set new start for the message portion of the line */ *new_start = strchr(line, ']'); - assert(*new_start); + BT_ASSERT(*new_start); (*new_start)++; if ((*new_start)[0] == ' ') { @@ -828,7 +828,7 @@ skip_ts: ft = bt_stream_class_get_event_header_type( dmesg_comp->stream_class); - assert(ft); + BT_ASSERT(ft); eh_field = bt_field_create(ft); if (!eh_field) { BT_LOGE_STR("Cannot create event header field object."); @@ -878,9 +878,9 @@ int create_event_payload_from_line( size_t len; int ret; - assert(user_field); + BT_ASSERT(user_field); ft = bt_event_class_get_payload_type(dmesg_comp->event_class); - assert(ft); + BT_ASSERT(ft); ep_field = bt_field_create(ft); if (!ep_field) { BT_LOGE_STR("Cannot create event payload field object."); @@ -948,7 +948,7 @@ struct bt_notification *create_notif_from_line( goto error; } - assert(ep_field); + BT_ASSERT(ep_field); event = bt_event_create(dmesg_comp->event_class); if (!event) { BT_LOGE_STR("Cannot create event object."); @@ -1038,9 +1038,9 @@ enum bt_notification_iterator_status dmesg_notif_iter_init( priv_comp = bt_private_connection_private_notification_iterator_get_private_component( priv_notif_iter); - assert(priv_comp); + BT_ASSERT(priv_comp); dmesg_comp = bt_private_component_get_user_data(priv_comp); - assert(dmesg_comp); + BT_ASSERT(dmesg_comp); dmesg_notif_iter->dmesg_comp = dmesg_comp; if (dmesg_comp->params.read_from_stdin) { @@ -1093,9 +1093,9 @@ struct bt_notification_iterator_next_method_return dmesg_notif_iter_next( .notification = NULL }; - assert(dmesg_notif_iter); + BT_ASSERT(dmesg_notif_iter); dmesg_comp = dmesg_notif_iter->dmesg_comp; - assert(dmesg_comp); + BT_ASSERT(dmesg_comp); while (true) { const char *ch; @@ -1118,7 +1118,7 @@ struct bt_notification_iterator_next_method_return dmesg_notif_iter_next( goto end; } - assert(dmesg_notif_iter->linebuf); + BT_ASSERT(dmesg_notif_iter->linebuf); /* Ignore empty lines, once trimmed */ for (ch = dmesg_notif_iter->linebuf; *ch != '\0'; ch++) { diff --git a/plugins/text/pretty/pretty.c b/plugins/text/pretty/pretty.c index ad76d823..77d982ef 100644 --- a/plugins/text/pretty/pretty.c +++ b/plugins/text/pretty/pretty.c @@ -35,7 +35,7 @@ #include #include #include -#include +#include #include "pretty.h" @@ -131,7 +131,7 @@ enum bt_component_status handle_notification(struct pretty_component *pretty, { enum bt_component_status ret = BT_COMPONENT_STATUS_OK; - assert(pretty); + BT_ASSERT(pretty); switch (bt_notification_get_type(notification)) { case BT_NOTIFICATION_TYPE_EVENT: @@ -173,10 +173,10 @@ void pretty_port_connected( }; pretty = bt_private_component_get_user_data(component); - assert(pretty); - assert(!pretty->input_iterator); + BT_ASSERT(pretty); + BT_ASSERT(!pretty->input_iterator); connection = bt_private_port_get_private_connection(self_port); - assert(connection); + BT_ASSERT(connection); conn_status = bt_private_connection_create_notification_iterator( connection, notif_types, &pretty->input_iterator); if (conn_status != BT_CONNECTION_STATUS_OK) { @@ -220,7 +220,7 @@ enum bt_component_status pretty_consume(struct bt_private_component *component) } notification = bt_notification_iterator_get_notification(it); - assert(notification); + BT_ASSERT(notification); ret = handle_notification(pretty, notification); end: diff --git a/plugins/text/pretty/print.c b/plugins/text/pretty/print.c index e13b2bc6..821f0347 100644 --- a/plugins/text/pretty/print.c +++ b/plugins/text/pretty/print.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include "pretty.h" @@ -502,7 +503,7 @@ enum bt_component_status print_event_header(struct pretty_component *pretty, const char *log_level_str = NULL; log_level = bt_event_class_get_log_level(event_class); - assert(log_level != BT_EVENT_CLASS_LOG_LEVEL_UNKNOWN); + BT_ASSERT(log_level != BT_EVENT_CLASS_LOG_LEVEL_UNKNOWN); if (log_level != BT_EVENT_CLASS_LOG_LEVEL_UNSPECIFIED) { log_level_str = log_level_names[log_level]; } @@ -658,7 +659,7 @@ enum bt_component_status print_integer(struct pretty_component *pretty, if (len < 64) { size_t rounded_len; - assert(len != 0); + BT_ASSERT(len != 0); /* Round length to the nearest 3-bit */ rounded_len = (((len - 1) / 3) + 1) * 3; v.u &= ((uint64_t) 1 << rounded_len) - 1; @@ -1491,8 +1492,8 @@ enum bt_component_status pretty_print_event(struct pretty_component *pretty, struct bt_clock_class_priority_map *cc_prio_map = bt_notification_event_get_clock_class_priority_map(event_notif); - assert(event); - assert(cc_prio_map); + BT_ASSERT(event); + BT_ASSERT(cc_prio_map); pretty->start_line = true; g_string_assign(pretty->string, ""); ret = print_event_header(pretty, event, cc_prio_map); @@ -1573,12 +1574,12 @@ enum bt_component_status pretty_print_discarded_elements( abort(); } - assert(stream); + BT_ASSERT(stream); stream_name = bt_stream_get_name(stream); /* Stream class ID */ stream_class = bt_stream_get_class(stream); - assert(stream_class); + BT_ASSERT(stream_class); stream_class_id = bt_stream_class_get_id(stream_class); /* Stream ID */ @@ -1586,7 +1587,7 @@ enum bt_component_status pretty_print_discarded_elements( /* Trace path */ trace = bt_stream_class_get_trace(stream_class); - assert(trace); + BT_ASSERT(trace); trace_name = bt_trace_get_name(trace); if (!trace_name) { trace_name = "(unknown)"; diff --git a/plugins/utils/counter/counter.c b/plugins/utils/counter/counter.c index 9ef22372..406a76ee 100644 --- a/plugins/utils/counter/counter.c +++ b/plugins/utils/counter/counter.c @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include @@ -120,9 +120,9 @@ void counter_finalize(struct bt_private_component *component) { struct counter *counter; - assert(component); + BT_ASSERT(component); counter = bt_private_component_get_user_data(component); - assert(counter); + BT_ASSERT(counter); try_print_last(counter); bt_put(counter->notif_iter); g_free(counter); @@ -150,11 +150,10 @@ enum bt_component_status counter_init(struct bt_private_component *component, counter->last_printed_total = -1ULL; counter->step = 1000; step = bt_value_map_get(params, "step"); - if (bt_value_is_integer(step)) { + if (step && bt_value_is_integer(step)) { int64_t val; - int vret = bt_value_integer_get(step, &val); - assert(vret == 0); + (void) bt_value_integer_get(step, &val); if (val >= 0) { counter->step = (uint64_t) val; @@ -162,11 +161,10 @@ enum bt_component_status counter_init(struct bt_private_component *component, } hide_zero = bt_value_map_get(params, "hide-zero"); - if (bt_value_is_bool(hide_zero)) { + if (hide_zero && bt_value_is_bool(hide_zero)) { bt_bool val; - int vret = bt_value_bool_get(hide_zero, &val); - assert(vret == 0); + (void) bt_value_bool_get(hide_zero, &val); counter->hide_zero = (bool) val; } @@ -197,9 +195,9 @@ void counter_port_connected( enum bt_connection_status conn_status; counter = bt_private_component_get_user_data(component); - assert(counter); + BT_ASSERT(counter); connection = bt_private_port_get_private_connection(self_port); - assert(connection); + BT_ASSERT(connection); conn_status = bt_private_connection_create_notification_iterator( connection, NULL, &iterator); if (conn_status != BT_CONNECTION_STATUS_OK) { @@ -222,7 +220,7 @@ enum bt_component_status counter_consume(struct bt_private_component *component) int64_t count; counter = bt_private_component_get_user_data(component); - assert(counter); + BT_ASSERT(counter); if (unlikely(counter->error)) { ret = BT_COMPONENT_STATUS_ERROR; @@ -255,7 +253,7 @@ enum bt_component_status counter_consume(struct bt_private_component *component) struct bt_notification *notif = bt_notification_iterator_get_notification(counter->notif_iter); - assert(notif); + BT_ASSERT(notif); switch (bt_notification_get_type(notif)) { case BT_NOTIFICATION_TYPE_EVENT: counter->count.event++; diff --git a/plugins/utils/dummy/dummy.c b/plugins/utils/dummy/dummy.c index a6e9769b..ad48e698 100644 --- a/plugins/utils/dummy/dummy.c +++ b/plugins/utils/dummy/dummy.c @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include "dummy.h" void destroy_private_dummy_data(struct dummy *dummy) @@ -36,9 +36,9 @@ void dummy_finalize(struct bt_private_component *component) { struct dummy *dummy; - assert(component); + BT_ASSERT(component); dummy = bt_private_component_get_user_data(component); - assert(dummy); + BT_ASSERT(dummy); destroy_private_dummy_data(dummy); } @@ -84,9 +84,9 @@ void dummy_port_connected( enum bt_connection_status conn_status; dummy = bt_private_component_get_user_data(component); - assert(dummy); + BT_ASSERT(dummy); connection = bt_private_port_get_private_connection(self_port); - assert(connection); + BT_ASSERT(connection); conn_status = bt_private_connection_create_notification_iterator( connection, NULL, &iterator); if (conn_status != BT_CONNECTION_STATUS_OK) { @@ -108,7 +108,7 @@ enum bt_component_status dummy_consume(struct bt_private_component *component) enum bt_notification_iterator_status it_ret; dummy = bt_private_component_get_user_data(component); - assert(dummy); + BT_ASSERT(dummy); if (unlikely(dummy->error)) { ret = BT_COMPONENT_STATUS_ERROR; diff --git a/plugins/utils/muxer/muxer.c b/plugins/utils/muxer/muxer.c index 0779ec8f..a13de530 100644 --- a/plugins/utils/muxer/muxer.c +++ b/plugins/utils/muxer/muxer.c @@ -34,7 +34,7 @@ #include #include #include -#include +#include #include #include @@ -174,7 +174,7 @@ enum bt_component_status ensure_available_input_port( enum bt_component_status status = BT_COMPONENT_STATUS_OK; GString *port_name = NULL; - assert(muxer_comp); + BT_ASSERT(muxer_comp); if (muxer_comp->available_input_ports >= 1) { goto end; @@ -293,7 +293,8 @@ int configure_muxer_comp(struct muxer_comp *muxer_comp, struct bt_value *params) assume_absolute_clock_classes = bt_value_map_get(real_params, ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME); - if (!bt_value_is_bool(assume_absolute_clock_classes)) { + if (assume_absolute_clock_classes && + !bt_value_is_bool(assume_absolute_clock_classes)) { BT_LOGE("Expecting a boolean value for the `%s` parameter: " "muxer-comp-addr=%p, value-type=%s", ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME, muxer_comp, @@ -303,7 +304,7 @@ int configure_muxer_comp(struct muxer_comp *muxer_comp, struct bt_value *params) } ret = bt_value_bool_get(assume_absolute_clock_classes, &bool_val); - assert(ret == 0); + BT_ASSERT(ret == 0); muxer_comp->assume_absolute_clock_classes = (bool) bool_val; BT_LOGD("Configured muxer component: muxer-comp-addr=%p, " "assume-absolute-clock-classes=%d", @@ -353,7 +354,7 @@ enum bt_component_status muxer_init( muxer_comp->priv_comp = priv_comp; ret = bt_private_component_set_user_data(priv_comp, muxer_comp); - assert(ret == 0); + BT_ASSERT(ret == 0); status = ensure_available_input_port(priv_comp); if (status != BT_COMPONENT_STATUS_OK) { BT_LOGE("Cannot ensure that at least one muxer component's input port is available: " @@ -381,7 +382,7 @@ enum bt_component_status muxer_init( error: destroy_muxer_comp(muxer_comp); ret = bt_private_component_set_user_data(priv_comp, NULL); - assert(ret == 0); + BT_ASSERT(ret == 0); if (status == BT_COMPONENT_STATUS_OK) { status = BT_COMPONENT_STATUS_ERROR; @@ -411,12 +412,12 @@ struct bt_notification_iterator *create_notif_iter_on_input_port( struct bt_private_connection *priv_conn = NULL; enum bt_connection_status conn_status; - assert(ret); + BT_ASSERT(ret); *ret = 0; - assert(port); - assert(bt_port_is_connected(port)); + BT_ASSERT(port); + BT_ASSERT(bt_port_is_connected(port)); priv_conn = bt_private_port_get_private_connection(priv_port); - assert(priv_conn); + BT_ASSERT(priv_conn); // TODO: Advance the iterator to >= the time of the latest // returned notification by the muxer notification @@ -531,7 +532,7 @@ int muxer_notif_iter_handle_newly_connected_ports( priv_port = node->data; port = bt_port_from_private(priv_port); - assert(port); + BT_ASSERT(port); if (!bt_port_is_connected(port)) { /* @@ -548,7 +549,7 @@ int muxer_notif_iter_handle_newly_connected_ports( &ret); if (ret) { /* create_notif_iter_on_input_port() logs errors */ - assert(!upstream_notif_iter); + BT_ASSERT(!upstream_notif_iter); goto error; } @@ -599,8 +600,8 @@ int get_notif_ts_ns(struct muxer_comp *muxer_comp, const unsigned char *cc_uuid; const char *cc_name; - assert(notif); - assert(ts_ns); + BT_ASSERT(notif); + BT_ASSERT(ts_ns); BT_LOGV("Getting notification's timestamp: " "muxer-notif-iter-addr=%p, notif-addr=%p, " @@ -807,7 +808,7 @@ int get_notif_ts_ns(struct muxer_comp *muxer_comp, switch (bt_notification_get_type(notif)) { case BT_NOTIFICATION_TYPE_EVENT: event = bt_notification_event_get_event(notif); - assert(event); + BT_ASSERT(event); clock_value = bt_event_get_clock_value(event, clock_class); break; @@ -887,9 +888,9 @@ muxer_notif_iter_youngest_upstream_notif_iter( enum bt_notification_iterator_status status = BT_NOTIFICATION_ITERATOR_STATUS_OK; - assert(muxer_comp); - assert(muxer_notif_iter); - assert(muxer_upstream_notif_iter); + BT_ASSERT(muxer_comp); + BT_ASSERT(muxer_notif_iter); + BT_ASSERT(muxer_upstream_notif_iter); *muxer_upstream_notif_iter = NULL; for (i = 0; i < muxer_notif_iter->muxer_upstream_notif_iters->len; i++) { @@ -906,10 +907,10 @@ muxer_notif_iter_youngest_upstream_notif_iter( continue; } - assert(cur_muxer_upstream_notif_iter->is_valid); + BT_ASSERT(cur_muxer_upstream_notif_iter->is_valid); notif = bt_notification_iterator_get_notification( cur_muxer_upstream_notif_iter->notif_iter); - assert(notif); + BT_ASSERT(notif); ret = get_notif_ts_ns(muxer_comp, muxer_notif_iter, notif, muxer_notif_iter->last_returned_ts_ns, ¬if_ts_ns); bt_put(notif); @@ -1069,7 +1070,7 @@ struct bt_notification_iterator_next_method_return muxer_notif_iter_do_next( } } - assert(!muxer_notif_iter->newly_connected_priv_ports); + BT_ASSERT(!muxer_notif_iter->newly_connected_priv_ports); /* * At this point we know that all the existing upstream @@ -1112,11 +1113,11 @@ struct bt_notification_iterator_next_method_return muxer_notif_iter_do_next( "muxer-upstream-notif-iter-wrap-addr=%p, " "ts=%" PRId64, muxer_notif_iter, muxer_upstream_notif_iter, next_return_ts); - assert(next_return.status == BT_NOTIFICATION_ITERATOR_STATUS_OK); - assert(muxer_upstream_notif_iter); + BT_ASSERT(next_return.status == BT_NOTIFICATION_ITERATOR_STATUS_OK); + BT_ASSERT(muxer_upstream_notif_iter); next_return.notification = bt_notification_iterator_get_notification( muxer_upstream_notif_iter->notif_iter); - assert(next_return.notification); + BT_ASSERT(next_return.notification); /* * We invalidate the upstream notification iterator so that, the @@ -1165,7 +1166,7 @@ int muxer_notif_iter_init_newly_connected_ports(struct muxer_comp *muxer_comp, * handled by muxer_notif_iter_handle_newly_connected_ports(). */ comp = bt_component_from_private(muxer_comp->priv_comp); - assert(comp); + BT_ASSERT(comp); count = bt_component_filter_get_input_port_count(comp); if (count < 0) { BT_LOGD("No input port to initialize for muxer component's notification iterator: " @@ -1180,9 +1181,9 @@ int muxer_notif_iter_init_newly_connected_ports(struct muxer_comp *muxer_comp, muxer_comp->priv_comp, i); struct bt_port *port; - assert(priv_port); + BT_ASSERT(priv_port); port = bt_port_from_private(priv_port); - assert(port); + BT_ASSERT(port); if (!bt_port_is_connected(port)) { BT_LOGD("Skipping input port: not connected: " @@ -1233,9 +1234,9 @@ enum bt_notification_iterator_status muxer_notif_iter_init( priv_comp = bt_private_connection_private_notification_iterator_get_private_component( priv_notif_iter); - assert(priv_comp); + BT_ASSERT(priv_comp); muxer_comp = bt_private_component_get_user_data(priv_comp); - assert(muxer_comp); + BT_ASSERT(muxer_comp); BT_LOGD("Initializing muxer component's notification iterator: " "comp-addr=%p, muxer-comp-addr=%p, notif-iter-addr=%p", priv_comp, muxer_comp, priv_notif_iter); @@ -1290,7 +1291,7 @@ enum bt_notification_iterator_status muxer_notif_iter_init( ret = bt_private_connection_private_notification_iterator_set_user_data(priv_notif_iter, muxer_notif_iter); - assert(ret == 0); + BT_ASSERT(ret == 0); BT_LOGD("Initialized muxer component's notification iterator: " "comp-addr=%p, muxer-comp-addr=%p, muxer-notif-iter-addr=%p, " "notif-iter-addr=%p", @@ -1307,7 +1308,7 @@ error: destroy_muxer_notif_iter(muxer_notif_iter); ret = bt_private_connection_private_notification_iterator_set_user_data(priv_notif_iter, NULL); - assert(ret == 0); + BT_ASSERT(ret == 0); status = BT_NOTIFICATION_ITERATOR_STATUS_ERROR; end: @@ -1327,7 +1328,7 @@ void muxer_notif_iter_finalize( priv_comp = bt_private_connection_private_notification_iterator_get_private_component( priv_notif_iter); - assert(priv_comp); + BT_ASSERT(priv_comp); muxer_comp = bt_private_component_get_user_data(priv_comp); BT_LOGD("Finalizing muxer component's notification iterator: " "comp-addr=%p, muxer-comp-addr=%p, muxer-notif-iter-addr=%p, " @@ -1353,12 +1354,12 @@ struct bt_notification_iterator_next_method_return muxer_notif_iter_next( struct bt_private_component *priv_comp = NULL; struct muxer_comp *muxer_comp = NULL; - assert(muxer_notif_iter); + BT_ASSERT(muxer_notif_iter); priv_comp = bt_private_connection_private_notification_iterator_get_private_component( priv_notif_iter); - assert(priv_comp); + BT_ASSERT(priv_comp); muxer_comp = bt_private_component_get_user_data(priv_comp); - assert(muxer_comp); + BT_ASSERT(muxer_comp); BT_LOGV("Muxer component's notification iterator's \"next\" method called: " "comp-addr=%p, muxer-comp-addr=%p, muxer-notif-iter-addr=%p, " @@ -1408,8 +1409,8 @@ void muxer_port_connected( size_t i; int ret; - assert(self_port); - assert(muxer_comp); + BT_ASSERT(self_port); + BT_ASSERT(muxer_comp); BT_LOGD("Port connected: " "comp-addr=%p, muxer-comp-addr=%p, " "port-addr=%p, port-name=\"%s\", " @@ -1478,8 +1479,8 @@ void muxer_port_disconnected(struct bt_private_component *priv_comp, struct muxer_comp *muxer_comp = bt_private_component_get_user_data(priv_comp); - assert(port); - assert(muxer_comp); + BT_ASSERT(port); + BT_ASSERT(muxer_comp); BT_LOGD("Port disconnected: " "comp-addr=%p, muxer-comp-addr=%p, port-addr=%p, " "port-name=\"%s\"", priv_comp, muxer_comp, diff --git a/plugins/utils/trimmer/copy.c b/plugins/utils/trimmer/copy.c index 8b48e754..65f67d76 100644 --- a/plugins/utils/trimmer/copy.c +++ b/plugins/utils/trimmer/copy.c @@ -29,7 +29,7 @@ #define BT_LOG_TAG "PLUGIN-UTILS-TRIMMER-FLT-COPY" #include "logging.h" -#include +#include #include #include @@ -88,13 +88,13 @@ enum bt_component_status update_packet_context_field(FILE *err, BT_LOGD("Updating packet context field: name=%s", name); packet_context = bt_packet_get_context(writer_packet); - assert(packet_context); + BT_ASSERT(packet_context); struct_type = bt_field_get_type(packet_context); - assert(struct_type); + BT_ASSERT(struct_type); writer_packet_context = bt_packet_get_context(writer_packet); - assert(writer_packet_context); + BT_ASSERT(writer_packet_context); nr_fields = bt_field_type_structure_get_field_count(struct_type); for (i = 0; i < nr_fields; i++) { @@ -127,10 +127,10 @@ enum bt_component_status update_packet_context_field(FILE *err, writer_field = bt_field_structure_get_field_by_name(writer_packet_context, field_name); - assert(writer_field); + BT_ASSERT(writer_field); int_ret = bt_field_unsigned_integer_set_value(writer_field, value); - assert(int_ret == 0); + BT_ASSERT(int_ret == 0); BT_PUT(writer_field); BT_PUT(field_type); @@ -161,7 +161,7 @@ struct bt_packet *trimmer_new_packet( int int_ret; stream = bt_packet_get_stream(packet); - assert(stream); + BT_ASSERT(stream); /* * If a packet was already opened, close it and remove it from @@ -227,7 +227,7 @@ struct bt_event *trimmer_output_event( int int_ret; event_class = bt_event_get_class(event); - assert(event_class); + BT_ASSERT(event_class); event_name = bt_event_class_get_name(event_class); @@ -240,7 +240,7 @@ struct bt_event *trimmer_output_event( } packet = bt_event_get_packet(event); - assert(packet); + BT_ASSERT(packet); writer_packet = lookup_packet(trim_it, packet); if (!writer_packet) { diff --git a/plugins/utils/trimmer/iterator.c b/plugins/utils/trimmer/iterator.c index 4c8702b6..8a081bce 100644 --- a/plugins/utils/trimmer/iterator.c +++ b/plugins/utils/trimmer/iterator.c @@ -32,7 +32,7 @@ #include #include #include -#include +#include #include #include "trimmer.h" @@ -54,7 +54,7 @@ void trimmer_iterator_finalize(struct bt_private_connection_private_notification struct trimmer_iterator *trim_it; trim_it = bt_private_connection_private_notification_iterator_get_user_data(it); - assert(trim_it); + BT_ASSERT(trim_it); bt_put(trim_it->input_iterator); g_hash_table_foreach_remove(trim_it->packet_map, @@ -93,9 +93,9 @@ enum bt_notification_iterator_status trimmer_iterator_init( /* Create a new iterator on the upstream component. */ input_port = bt_private_component_filter_get_input_private_port_by_name( component, "in"); - assert(input_port); + BT_ASSERT(input_port); connection = bt_private_port_get_private_connection(input_port); - assert(connection); + BT_ASSERT(connection); conn_status = bt_private_connection_create_notification_iterator(connection, notif_types, &it_data->input_iterator); @@ -201,24 +201,24 @@ struct bt_notification *evaluate_event_notification( struct bt_clock_class_priority_map *cc_prio_map; event = bt_notification_event_get_event(notification); - assert(event); + BT_ASSERT(event); cc_prio_map = bt_notification_event_get_clock_class_priority_map( notification); - assert(cc_prio_map); + BT_ASSERT(cc_prio_map); writer_event = trimmer_output_event(trim_it, event); - assert(writer_event); + BT_ASSERT(writer_event); new_notification = bt_notification_event_create(writer_event, cc_prio_map); - assert(new_notification); + BT_ASSERT(new_notification); bt_put(cc_prio_map); stream = bt_event_get_stream(event); - assert(stream); + BT_ASSERT(stream); stream_class = bt_stream_get_class(stream); - assert(stream_class); + BT_ASSERT(stream_class); trace = bt_stream_class_get_trace(stream_class); - assert(trace); + BT_ASSERT(trace); /* FIXME multi-clock? */ clock_class = bt_trace_get_clock_class_by_index(trace, 0); @@ -285,7 +285,7 @@ int ns_from_integer_field(struct bt_field *integer, int64_t *ns) struct bt_clock_value *clock_value = NULL; integer_type = bt_field_get_type(integer); - assert(integer_type); + BT_ASSERT(integer_type); clock_class = bt_field_type_integer_get_mapped_clock_class( integer_type); if (!clock_class) { @@ -348,28 +348,28 @@ int64_t get_raw_timestamp(struct bt_packet *writer_packet, uint64_t freq; writer_stream = bt_packet_get_stream(writer_packet); - assert(writer_stream); + BT_ASSERT(writer_stream); writer_stream_class = bt_stream_get_class(writer_stream); - assert(writer_stream_class); + BT_ASSERT(writer_stream_class); writer_trace = bt_stream_class_get_trace(writer_stream_class); - assert(writer_trace); + BT_ASSERT(writer_trace); /* FIXME multi-clock? */ writer_clock_class = bt_trace_get_clock_class_by_index( writer_trace, 0); - assert(writer_clock_class); + BT_ASSERT(writer_clock_class); ret = bt_clock_class_get_offset_s(writer_clock_class, &sec_offset); - assert(!ret); + BT_ASSERT(!ret); ns = sec_offset * NSEC_PER_SEC; freq = bt_clock_class_get_frequency(writer_clock_class); - assert(freq != -1ULL); + BT_ASSERT(freq != -1ULL); ret = bt_clock_class_get_offset_cycles(writer_clock_class, &cycles_offset); - assert(!ret); + BT_ASSERT(!ret); ns += ns_from_value(freq, cycles_offset); @@ -401,15 +401,15 @@ struct bt_notification *evaluate_packet_notification( switch (bt_notification_get_type(notification)) { case BT_NOTIFICATION_TYPE_PACKET_BEGIN: packet = bt_notification_packet_begin_get_packet(notification); - assert(packet); + BT_ASSERT(packet); writer_packet = trimmer_new_packet(trim_it, packet); - assert(writer_packet); + BT_ASSERT(writer_packet); break; case BT_NOTIFICATION_TYPE_PACKET_END: packet = bt_notification_packet_end_get_packet(notification); - assert(packet); + BT_ASSERT(packet); writer_packet = trimmer_close_packet(trim_it, packet); - assert(writer_packet); + BT_ASSERT(writer_packet); break; default: goto end; @@ -474,25 +474,25 @@ struct bt_notification *evaluate_packet_notification( ret = update_packet_context_field(trim_it->err, writer_packet, "timestamp_begin", get_raw_timestamp(writer_packet, begin_ns)); - assert(!ret); + BT_ASSERT(!ret); } if (end_ns < pkt_end_ns) { ret = update_packet_context_field(trim_it->err, writer_packet, "timestamp_end", get_raw_timestamp(writer_packet, end_ns)); - assert(!ret); + BT_ASSERT(!ret); } end: switch (bt_notification_get_type(notification)) { case BT_NOTIFICATION_TYPE_PACKET_BEGIN: new_notification = bt_notification_packet_begin_create(writer_packet); - assert(new_notification); + BT_ASSERT(new_notification); break; case BT_NOTIFICATION_TYPE_PACKET_END: new_notification = bt_notification_packet_end_create(writer_packet); - assert(new_notification); + BT_ASSERT(new_notification); break; default: break; @@ -515,7 +515,7 @@ struct bt_notification *evaluate_stream_notification( struct bt_stream *stream; stream = bt_notification_stream_end_get_stream(notification); - assert(stream); + BT_ASSERT(stream); /* FIXME: useless copy */ return bt_notification_stream_end_create(stream); @@ -578,16 +578,16 @@ struct bt_notification_iterator_next_method_return trimmer_iterator_next( bool notification_in_range = false; trim_it = bt_private_connection_private_notification_iterator_get_user_data(iterator); - assert(trim_it); + BT_ASSERT(trim_it); component = bt_private_connection_private_notification_iterator_get_private_component( iterator); - assert(component); + BT_ASSERT(component); trimmer = bt_private_component_get_user_data(component); - assert(trimmer); + BT_ASSERT(trimmer); source_it = trim_it->input_iterator; - assert(source_it); + BT_ASSERT(source_it); while (!notification_in_range) { ret.status = bt_notification_iterator_next(source_it); diff --git a/plugins/utils/trimmer/trimmer.c b/plugins/utils/trimmer/trimmer.c index d00c05e5..4806dc6f 100644 --- a/plugins/utils/trimmer/trimmer.c +++ b/plugins/utils/trimmer/trimmer.c @@ -34,7 +34,7 @@ #include #include "trimmer.h" #include "iterator.h" -#include +#include static void destroy_trimmer_data(struct trimmer *trimmer) @@ -298,7 +298,7 @@ enum bt_component_status init_from_params(struct trimmer *trimmer, bt_bool gmt = BT_FALSE; enum bt_component_status ret = BT_COMPONENT_STATUS_OK; - assert(params); + BT_ASSERT(params); value = bt_value_map_get(params, "clock-gmt"); if (value) { diff --git a/python-plugin-provider/python-plugin-provider.c b/python-plugin-provider/python-plugin-provider.c index 9044d8a2..de677c85 100644 --- a/python-plugin-provider/python-plugin-provider.c +++ b/python-plugin-provider/python-plugin-provider.c @@ -175,8 +175,8 @@ struct bt_plugin *bt_plugin_from_python_plugin_info(PyObject *plugin_info) const char *version_extra = NULL; int ret; - assert(plugin_info); - assert(python_state == PYTHON_STATE_FULLY_INITIALIZED); + BT_ASSERT(plugin_info); + BT_ASSERT(python_state == PYTHON_STATE_FULLY_INITIALIZED); py_name = PyObject_GetAttrString(plugin_info, "name"); if (!py_name) { BT_LOGW("Cannot find `name` attribute in Python plugin info object: " @@ -267,9 +267,9 @@ struct bt_plugin *bt_plugin_from_python_plugin_info(PyObject *plugin_info) PyObject *py_minor = PyTuple_GetItem(py_version, 1); PyObject *py_patch = PyTuple_GetItem(py_version, 2); - assert(py_major); - assert(py_minor); - assert(py_patch); + BT_ASSERT(py_major); + BT_ASSERT(py_minor); + BT_ASSERT(py_patch); if (PyLong_Check(py_major)) { major = PyLong_AsUnsignedLong(py_major); @@ -294,7 +294,7 @@ struct bt_plugin *bt_plugin_from_python_plugin_info(PyObject *plugin_info) if (PyTuple_Size(py_version) >= 4) { PyObject *py_extra = PyTuple_GetItem(py_version, 3); - assert(py_extra); + BT_ASSERT(py_extra); if (PyUnicode_Check(py_extra)) { version_extra = PyUnicode_AsUTF8(py_extra); @@ -338,7 +338,7 @@ struct bt_plugin *bt_plugin_from_python_plugin_info(PyObject *plugin_info) py_comp_class_addr = PyList_GetItem(py_comp_class_addrs, i); - assert(py_comp_class_addr); + BT_ASSERT(py_comp_class_addr); if (PyLong_Check(py_comp_class_addr)) { comp_class = (struct bt_component_class *) PyLong_AsUnsignedLongLong(py_comp_class_addr); @@ -396,7 +396,7 @@ struct bt_plugin_set *bt_plugin_python_create_all_from_file(const char *path) gchar *basename = NULL; size_t path_len; - assert(path); + BT_ASSERT(path); if (python_state == PYTHON_STATE_CANNOT_INITIALIZE) { /* diff --git a/tests/lib/test_bt_values.c b/tests/lib/test_bt_values.c index bd8f22d5..f407a19f 100644 --- a/tests/lib/test_bt_values.c +++ b/tests/lib/test_bt_values.c @@ -26,7 +26,7 @@ #include #include "tap/tap.h" -#define NR_TESTS 249 +#define NR_TESTS 158 static void test_null(void) @@ -38,14 +38,6 @@ void test_null(void) pass("getting bt_value_null does not cause a crash"); bt_put(bt_value_null); pass("putting bt_value_null does not cause a crash"); - - bt_get(NULL); - pass("getting NULL does not cause a crash"); - bt_put(NULL); - pass("putting NULL does not cause a crash"); - - ok(bt_value_get_type(NULL) == BT_VALUE_TYPE_UNKNOWN, - "bt_value_get_type(NULL) returns BT_VALUE_TYPE_UNKNOWN"); } static @@ -63,16 +55,6 @@ void test_bool(void) ret = bt_value_bool_get(obj, &value); ok(!ret && !value, "default boolean value object value is BT_FALSE"); - ret = bt_value_bool_set(NULL, BT_TRUE); - ok(ret == BT_VALUE_STATUS_INVAL, - "bt_value_bool_set() fails with an value object set to NULL"); - ret = bt_value_bool_get(NULL, &value); - ok(ret == BT_VALUE_STATUS_INVAL, - "bt_value_bool_get() fails with an value object set to NULL"); - ret = bt_value_bool_get(obj, NULL); - ok(ret == BT_VALUE_STATUS_INVAL, - "bt_value_bool_get() fails with a return value set to NULL"); - assert(!bt_value_bool_set(obj, BT_FALSE)); ret = bt_value_bool_set(obj, BT_TRUE); ok(!ret, "bt_value_bool_set() succeeds"); @@ -90,14 +72,6 @@ void test_bool(void) ok(!ret && value, "bt_value_bool_create_init() sets the appropriate initial value"); - assert(!bt_value_freeze(obj)); - ok(bt_value_bool_set(obj, BT_FALSE) == BT_VALUE_STATUS_FROZEN, - "bt_value_bool_set() cannot be called on a frozen boolean value object"); - value = BT_FALSE; - ret = bt_value_bool_get(obj, &value); - ok(!ret && value, - "bt_value_bool_set() does not alter a frozen floating point number value object"); - BT_PUT(obj); } @@ -112,16 +86,6 @@ void test_integer(void) ok(obj && bt_value_is_integer(obj), "bt_value_integer_create() returns an integer value object"); - ret = bt_value_integer_set(NULL, -12345); - ok(ret == BT_VALUE_STATUS_INVAL, - "bt_value_integer_set() fails with an value object set to NULL"); - ret = bt_value_integer_get(NULL, &value); - ok(ret == BT_VALUE_STATUS_INVAL, - "bt_value_integer_get() fails with an value object set to NULL"); - ret = bt_value_integer_get(obj, NULL); - ok(ret == BT_VALUE_STATUS_INVAL, - "bt_value_integer_get() fails with a return value set to NULL"); - value = 1961; ret = bt_value_integer_get(obj, &value); ok(!ret && value == 0, "default integer value object value is 0"); @@ -141,14 +105,6 @@ void test_integer(void) ok(!ret && value == 321456987, "bt_value_integer_create_init() sets the appropriate initial value"); - assert(!bt_value_freeze(obj)); - ok(bt_value_integer_set(obj, 18276) == BT_VALUE_STATUS_FROZEN, - "bt_value_integer_set() cannot be called on a frozen integer value object"); - value = 17; - ret = bt_value_integer_get(obj, &value); - ok(!ret && value == 321456987, - "bt_value_integer_set() does not alter a frozen integer value object"); - BT_PUT(obj); } @@ -163,16 +119,6 @@ void test_float(void) ok(obj && bt_value_is_float(obj), "bt_value_float_create() returns a floating point number value object"); - ret = bt_value_float_set(NULL, 1.2345); - ok(ret == BT_VALUE_STATUS_INVAL, - "bt_value_float_set() fails with an value object set to NULL"); - ret = bt_value_float_get(NULL, &value); - ok(ret == BT_VALUE_STATUS_INVAL, - "bt_value_float_get() fails with an value object set to NULL"); - ret = bt_value_float_get(obj, NULL); - ok(ret == BT_VALUE_STATUS_INVAL, - "bt_value_float_get() fails with a return value set to NULL"); - value = 17.34; ret = bt_value_float_get(obj, &value); ok(!ret && value == 0., @@ -193,14 +139,6 @@ void test_float(void) ok(!ret && value == 33.1649758, "bt_value_float_create_init() sets the appropriate initial value"); - assert(!bt_value_freeze(obj)); - ok(bt_value_float_set(obj, 17.88) == BT_VALUE_STATUS_FROZEN, - "bt_value_float_set() fails with a frozen floating point number value object"); - value = 1.2; - ret = bt_value_float_get(obj, &value); - ok(!ret && value == 33.1649758, - "bt_value_float_set() does not alter a frozen floating point number value object"); - BT_PUT(obj); } @@ -215,19 +153,6 @@ void test_string(void) ok(obj && bt_value_is_string(obj), "bt_value_string_create() returns a string value object"); - ret = bt_value_string_set(NULL, "hoho"); - ok(ret == BT_VALUE_STATUS_INVAL, - "bt_value_string_set() fails with an value object set to NULL"); - ret = bt_value_string_set(obj, NULL); - ok(ret == BT_VALUE_STATUS_INVAL, - "bt_value_string_set() fails with a value set to NULL"); - ret = bt_value_string_get(NULL, &value); - ok(ret == BT_VALUE_STATUS_INVAL, - "bt_value_string_get() fails with an value object set to NULL"); - ret = bt_value_string_get(obj, NULL); - ok(ret == BT_VALUE_STATUS_INVAL, - "bt_value_string_get() fails with a return value set to NULL"); - ret = bt_value_string_get(obj, &value); ok(!ret && value && !strcmp(value, ""), "default string value object value is \"\""); @@ -241,8 +166,6 @@ void test_string(void) BT_PUT(obj); pass("putting an existing string value object does not cause a crash") - obj = bt_value_string_create_init(NULL); - ok(!obj, "bt_value_string_create_init() fails with an initial value set to NULL"); obj = bt_value_string_create_init("initial value"); ok(obj && bt_value_is_string(obj), "bt_value_string_create_init() returns a string value object"); @@ -250,14 +173,6 @@ void test_string(void) ok(!ret && value && !strcmp(value, "initial value"), "bt_value_string_create_init() sets the appropriate initial value"); - assert(!bt_value_freeze(obj)); - ok(bt_value_string_set(obj, "new value") == BT_VALUE_STATUS_FROZEN, - "bt_value_string_set() fails with a frozen string value object"); - value = ""; - ret = bt_value_string_get(obj, &value); - ok(!ret && value && !strcmp(value, "initial value"), - "bt_value_string_set() does not alter a frozen string value object"); - BT_PUT(obj); } @@ -275,18 +190,8 @@ void test_array(void) array_obj = bt_value_array_create(); ok(array_obj && bt_value_is_array(array_obj), "bt_value_array_create() returns an array value object"); - ok(bt_value_array_is_empty(NULL) == BT_FALSE, - "bt_value_array_is_empty() returns BT_FALSE with an value object set to NULL"); ok(bt_value_array_is_empty(array_obj), "initial array value object size is 0"); - ok(bt_value_array_size(NULL) == BT_VALUE_STATUS_INVAL, - "bt_value_array_size() fails with an array value object set to NULL"); - - ok(bt_value_array_append(NULL, bt_value_null) - == BT_VALUE_STATUS_INVAL, - "bt_value_array_append() fails with an array value object set to NULL"); - ok(bt_value_array_append(array_obj, NULL) == BT_VALUE_STATUS_INVAL, - "bt_value_array_append() fails with a value set to NULL"); obj = bt_value_integer_create_init(345); ret = bt_value_array_append(array_obj, obj); @@ -302,14 +207,6 @@ void test_array(void) ok(bt_value_array_size(array_obj) == 4, "appending an element to an array value object increment its size"); - obj = bt_value_array_get(array_obj, 4); - ok(!obj, "getting an array value object's element at an index equal to its size fails"); - obj = bt_value_array_get(array_obj, 5); - ok(!obj, "getting an array value object's element at a larger index fails"); - - obj = bt_value_array_get(NULL, 2); - ok(!obj, "bt_value_array_get() fails with an array value object set to NULL"); - obj = bt_value_array_get(array_obj, 0); ok(obj && bt_value_is_integer(obj), "bt_value_array_get() returns an value object with the appropriate type (integer)"); @@ -335,14 +232,6 @@ void test_array(void) ok(obj == bt_value_null, "bt_value_array_get() returns an value object with the appropriate type (null)"); - ok(bt_value_array_set(NULL, 0, bt_value_null) == - BT_VALUE_STATUS_INVAL, - "bt_value_array_set() fails with an array value object set to NULL"); - ok(bt_value_array_set(array_obj, 0, NULL) == BT_VALUE_STATUS_INVAL, - "bt_value_array_set() fails with an element value object set to NULL"); - ok(bt_value_array_set(array_obj, 4, bt_value_null) == - BT_VALUE_STATUS_INVAL, - "bt_value_array_set() fails with an invalid index"); obj = bt_value_integer_create_init(1001); assert(obj); ok(!bt_value_array_set(array_obj, 2, obj), @@ -359,31 +248,16 @@ void test_array(void) ret = bt_value_array_append_bool(array_obj, BT_FALSE); ok(!ret, "bt_value_array_append_bool() succeeds"); - ok(bt_value_array_append_bool(NULL, BT_TRUE) == BT_VALUE_STATUS_INVAL, - "bt_value_array_append_bool() fails with an array value object set to NULL"); ret = bt_value_array_append_integer(array_obj, 98765); ok(!ret, "bt_value_array_append_integer() succeeds"); - ok(bt_value_array_append_integer(NULL, 18765) == - BT_VALUE_STATUS_INVAL, - "bt_value_array_append_integer() fails with an array value object set to NULL"); ret = bt_value_array_append_float(array_obj, 2.49578); ok(!ret, "bt_value_array_append_float() succeeds"); - ok(bt_value_array_append_float(NULL, 1.49578) == - BT_VALUE_STATUS_INVAL, - "bt_value_array_append_float() fails with an array value object set to NULL"); ret = bt_value_array_append_string(array_obj, "bt_value"); ok(!ret, "bt_value_array_append_string() succeeds"); - ok(bt_value_array_append_string(NULL, "bt_obj") == - BT_VALUE_STATUS_INVAL, - "bt_value_array_append_string() fails with an array value object set to NULL"); ret = bt_value_array_append_empty_array(array_obj); ok(!ret, "bt_value_array_append_empty_array() succeeds"); - ok(bt_value_array_append_empty_array(NULL) == BT_VALUE_STATUS_INVAL, - "bt_value_array_append_empty_array() fails with an array value object set to NULL"); ret = bt_value_array_append_empty_map(array_obj); ok(!ret, "bt_value_array_append_empty_map() succeeds"); - ok(bt_value_array_append_empty_map(NULL) == BT_VALUE_STATUS_INVAL, - "bt_value_array_append_empty_map() fails with an array value object set to NULL"); ok(bt_value_array_size(array_obj) == 10, "the bt_value_array_append_*() functions increment the array value object's size"); @@ -431,40 +305,6 @@ void test_array(void) "bt_value_array_append_empty_map() an empty map value object"); BT_PUT(obj); - assert(!bt_value_freeze(array_obj)); - ok(bt_value_array_append(array_obj, bt_value_null) == - BT_VALUE_STATUS_FROZEN, - "bt_value_array_append() fails with a frozen array value object"); - ok(bt_value_array_append_bool(array_obj, BT_FALSE) == - BT_VALUE_STATUS_FROZEN, - "bt_value_array_append_bool() fails with a frozen array value object"); - ok(bt_value_array_append_integer(array_obj, 23) == - BT_VALUE_STATUS_FROZEN, - "bt_value_array_append_integer() fails with a frozen array value object"); - ok(bt_value_array_append_float(array_obj, 2.34) == - BT_VALUE_STATUS_FROZEN, - "bt_value_array_append_float() fails with a frozen array value object"); - ok(bt_value_array_append_string(array_obj, "yayayayaya") == - BT_VALUE_STATUS_FROZEN, - "bt_value_array_append_string() fails with a frozen array value object"); - ok(bt_value_array_append_empty_array(array_obj) == - BT_VALUE_STATUS_FROZEN, - "bt_value_array_append_empty_array() fails with a frozen array value object"); - ok(bt_value_array_append_empty_map(array_obj) == - BT_VALUE_STATUS_FROZEN, - "bt_value_array_append_empty_map() fails with a frozen array value object"); - ok(bt_value_array_set(array_obj, 2, bt_value_null) == - BT_VALUE_STATUS_FROZEN, - "bt_value_array_set() fails with a frozen array value object"); - ok(bt_value_array_size(array_obj) == 10, - "appending to a frozen array value object does not change its size"); - - obj = bt_value_array_get(array_obj, 1); - assert(obj); - ok(bt_value_float_set(obj, 14.52) == BT_VALUE_STATUS_FROZEN, - "freezing an array value object also freezes its elements"); - BT_PUT(obj); - BT_PUT(array_obj); pass("putting an existing array value object does not cause a crash") } @@ -665,18 +505,6 @@ void test_map(void) "bt_value_map_create() returns a map value object"); ok(bt_value_map_size(map_obj) == 0, "initial map value object size is 0"); - ok(bt_value_map_size(NULL) == BT_VALUE_STATUS_INVAL, - "bt_value_map_size() fails with a map value object set to NULL"); - - ok(bt_value_map_insert(NULL, "hello", bt_value_null) == - BT_VALUE_STATUS_INVAL, - "bt_value_array_insert() fails with a map value object set to NULL"); - ok(bt_value_map_insert(map_obj, NULL, bt_value_null) == - BT_VALUE_STATUS_INVAL, - "bt_value_array_insert() fails with a key set to NULL"); - ok(bt_value_map_insert(map_obj, "yeah", NULL) == - BT_VALUE_STATUS_INVAL, - "bt_value_array_insert() fails with an element value object set to NULL"); obj = bt_value_integer_create_init(19457); ret = bt_value_map_insert(map_obj, "int", obj); @@ -697,13 +525,8 @@ void test_map(void) BT_PUT(obj); ok(!ret, "bt_value_map_insert() accepts an existing key"); - obj = bt_value_map_get(map_obj, NULL); - ok(!obj, "bt_value_map_get() fails with a key set to NULL"); - obj = bt_value_map_get(NULL, "bt_bool"); - ok(!obj, "bt_value_map_get() fails with a map value object set to NULL"); - obj = bt_value_map_get(map_obj, "life"); - ok(!obj, "bt_value_map_get() fails with an non existing key"); + ok(!obj, "bt_value_map_get() returns NULL with an non existing key"); obj = bt_value_map_get(map_obj, "float"); ok(obj && bt_value_is_float(obj), "bt_value_map_get() returns an value object with the appropriate type (float)"); @@ -731,32 +554,16 @@ void test_map(void) ret = bt_value_map_insert_bool(map_obj, "bool2", BT_TRUE); ok(!ret, "bt_value_map_insert_bool() succeeds"); - ok(bt_value_map_insert_bool(NULL, "bool2", BT_FALSE) == - BT_VALUE_STATUS_INVAL, - "bt_value_map_insert_bool() fails with a map value object set to NULL"); ret = bt_value_map_insert_integer(map_obj, "int2", 98765); ok(!ret, "bt_value_map_insert_integer() succeeds"); - ok(bt_value_map_insert_integer(NULL, "int2", 1001) == - BT_VALUE_STATUS_INVAL, - "bt_value_map_insert_integer() fails with a map value object set to NULL"); ret = bt_value_map_insert_float(map_obj, "float2", -49.0001); ok(!ret, "bt_value_map_insert_float() succeeds"); - ok(bt_value_map_insert_float(NULL, "float2", 495) == - BT_VALUE_STATUS_INVAL, - "bt_value_map_insert_float() fails with a map value object set to NULL"); ret = bt_value_map_insert_string(map_obj, "string2", "bt_value"); ok(!ret, "bt_value_map_insert_string() succeeds"); - ok(bt_value_map_insert_string(NULL, "string2", "bt_obj") == - BT_VALUE_STATUS_INVAL, - "bt_value_map_insert_string() fails with a map value object set to NULL"); ret = bt_value_map_insert_empty_array(map_obj, "array2"); ok(!ret, "bt_value_map_insert_empty_array() succeeds"); - ok(bt_value_map_insert_empty_array(NULL, "array2") == BT_VALUE_STATUS_INVAL, - "bt_value_map_insert_empty_array() fails with a map value object set to NULL"); ret = bt_value_map_insert_empty_map(map_obj, "map2"); ok(!ret, "bt_value_map_insert_empty_map() succeeds"); - ok(bt_value_map_insert_empty_map(NULL, "map2") == BT_VALUE_STATUS_INVAL, - "bt_value_map_insert_empty_map() fails with a map value object set to NULL"); ok(bt_value_map_size(map_obj) == 10, "the bt_value_map_insert*() functions increment the map value object's size"); @@ -784,14 +591,8 @@ void test_map(void) ok(bt_value_map_has_key(map_obj, "map2"), "map value object has key \"map2\""); - ok(bt_value_map_foreach(NULL, test_map_foreach_cb_count, &count) == - BT_VALUE_STATUS_INVAL, - "bt_value_map_foreach() fails with a map value object set to NULL"); - ok(bt_value_map_foreach(map_obj, NULL, &count) == - BT_VALUE_STATUS_INVAL, - "bt_value_map_foreach() fails with a user function set to NULL"); ret = bt_value_map_foreach(map_obj, test_map_foreach_cb_count, &count); - ok(ret == BT_VALUE_STATUS_CANCELLED && count == 3, + ok(ret == BT_VALUE_STATUS_CANCELED && count == 3, "bt_value_map_foreach() breaks the loop when the user function returns BT_FALSE"); memset(&checklist, 0, sizeof(checklist)); @@ -805,31 +606,6 @@ void test_map(void) checklist.array2 && checklist.map2, "bt_value_map_foreach() iterates over all the map value object's elements"); - assert(!bt_value_freeze(map_obj)); - ok(bt_value_map_insert(map_obj, "allo", bt_value_null) == - BT_VALUE_STATUS_FROZEN, - "bt_value_map_insert() fails with a frozen map value object"); - ok(bt_value_map_insert_bool(map_obj, "duh", BT_FALSE) == - BT_VALUE_STATUS_FROZEN, - "bt_value_map_insert_bool() fails with a frozen array value object"); - ok(bt_value_map_insert_integer(map_obj, "duh", 23) == - BT_VALUE_STATUS_FROZEN, - "bt_value_map_insert_integer() fails with a frozen array value object"); - ok(bt_value_map_insert_float(map_obj, "duh", 2.34) == - BT_VALUE_STATUS_FROZEN, - "bt_value_map_insert_float() fails with a frozen array value object"); - ok(bt_value_map_insert_string(map_obj, "duh", "yayayayaya") == - BT_VALUE_STATUS_FROZEN, - "bt_value_map_insert_string() fails with a frozen array value object"); - ok(bt_value_map_insert_empty_array(map_obj, "duh") == - BT_VALUE_STATUS_FROZEN, - "bt_value_map_insert_empty_array() fails with a frozen array value object"); - ok(bt_value_map_insert_empty_map(map_obj, "duh") == - BT_VALUE_STATUS_FROZEN, - "bt_value_map_insert_empty_map() fails with a frozen array value object"); - ok(bt_value_map_size(map_obj) == 10, - "appending to a frozen map value object does not change its size"); - BT_PUT(map_obj); pass("putting an existing map value object does not cause a crash") } @@ -849,10 +625,6 @@ void test_types(void) static void test_compare_null(void) { - ok(!bt_value_compare(bt_value_null, NULL), - "cannot compare null value object and NULL"); - ok(!bt_value_compare(NULL, bt_value_null), - "cannot compare NULL and null value object"); ok(bt_value_compare(bt_value_null, bt_value_null), "null value objects are equivalent"); } @@ -1016,7 +788,6 @@ void test_compare_map(void) static void test_compare(void) { - ok(!bt_value_compare(NULL, NULL), "cannot compare NULL and NULL"); test_compare_null(); test_compare_bool(); test_compare_integer(); @@ -1062,10 +833,6 @@ void test_copy(void) assert(!bt_value_map_insert(map_obj, "array", array_obj)); assert(!bt_value_map_insert(map_obj, "string", string_obj)); - map_copy_obj = bt_value_copy(NULL); - ok(!map_copy_obj, - "bt_value_copy() fails with a source value object set to NULL"); - map_copy_obj = bt_value_copy(map_obj); ok(map_copy_obj, "bt_value_copy() succeeds"); @@ -1151,17 +918,6 @@ void test_extend(void) assert(status == BT_VALUE_STATUS_OK); status = bt_value_map_insert_float(extension_map, "project", -404); assert(status == BT_VALUE_STATUS_OK); - bt_value_freeze(base_map); - bt_value_freeze(extension_map); - bt_value_freeze(array); - ok(!bt_value_map_extend(NULL, extension_map), - "bt_value_map_extend() fails with a NULL base object"); - ok(!bt_value_map_extend(base_map, NULL), - "bt_value_map_extend() fails with a NULL extension object"); - ok(!bt_value_map_extend(array, extension_map), - "bt_value_map_extend() fails with a non-map base object"); - ok(!bt_value_map_extend(base_map, array), - "bt_value_map_extend() fails with a non-map extension object"); extended_map = bt_value_map_extend(base_map, extension_map); ok(extended_map, "bt_value_map_extend() succeeds"); ok(bt_value_map_size(extended_map) == 5, @@ -1183,63 +939,12 @@ void test_extend(void) BT_PUT(extended_map); } -static -void test_macros(void) -{ - struct bt_value *obj = bt_value_bool_create(); - struct bt_value *src; - struct bt_value *dst = NULL; - - assert(obj); - BT_PUT(obj); - ok(!obj, "BT_PUT() resets the variable to NULL"); - - obj = bt_value_bool_create(); - assert(obj); - src = obj; - BT_MOVE(dst, src); - ok(!src, "BT_MOVE() resets the source variable to NULL"); - ok(dst == obj, "BT_MOVE() moves the ownership"); - - BT_PUT(dst); -} - -static -void test_freeze(void) -{ - struct bt_value *obj; - - ok(bt_value_freeze(NULL) == BT_VALUE_STATUS_INVAL, - "bt_value_freeze() fails with an value object set to NULL"); - ok(!bt_value_freeze(bt_value_null), - "bt_value_freeze() succeeds with a null value object"); - - ok(!bt_value_is_frozen(NULL), "NULL is not frozen"); - ok(bt_value_is_frozen(bt_value_null), - "the null singleton is frozen"); - obj = bt_value_integer_create(); - assert(obj); - ok(!bt_value_is_frozen(obj), - "bt_value_is_frozen() returns BT_FALSE with a fresh value object"); - assert(!bt_value_freeze(obj)); - ok(!bt_value_freeze(obj), - "bt_value_freeze() passes with a frozen value object"); - ok(bt_value_is_frozen(obj), - "bt_value_is_frozen() returns BT_TRUE with a frozen value object"); - - BT_PUT(obj); -} - int main(void) { plan_tests(NR_TESTS); - - test_macros(); - test_freeze(); test_types(); test_compare(); test_copy(); test_extend(); - return 0; } diff --git a/tests/lib/test_cc_prio_map.c b/tests/lib/test_cc_prio_map.c index f2a2f8dc..b9378d34 100644 --- a/tests/lib/test_cc_prio_map.c +++ b/tests/lib/test_cc_prio_map.c @@ -24,7 +24,7 @@ #include "tap/tap.h" -#define NR_TESTS 21 +#define NR_TESTS 17 static void test_clock_class_priority_map(void) { @@ -45,14 +45,6 @@ static void test_clock_class_priority_map(void) assert(cc2); cc3 = bt_clock_class_create("cc3", 3); assert(cc3); - ok(!bt_clock_class_priority_map_get_highest_priority_clock_class(NULL), - "bt_clock_class_priority_map_get_highest_priority_clock_class() handles NULL"); - ok(bt_clock_class_priority_map_get_clock_class_priority(NULL, cc1, &prio) < 0, - "bt_clock_class_priority_map_get_highest_priority_clock_class() handles NULL (CC priority map)"); - ok(bt_clock_class_priority_map_get_clock_class_priority(cc_prio_map, NULL, &prio) < 0, - "bt_clock_class_priority_map_get_highest_priority_clock_class() handles NULL (clock class)"); - ok(bt_clock_class_priority_map_get_clock_class_priority(cc_prio_map, cc1, NULL) < 0, - "bt_clock_class_priority_map_get_highest_priority_clock_class() handles NULL (priority)"); ok(!bt_clock_class_priority_map_get_highest_priority_clock_class(cc_prio_map), "bt_clock_class_priority_map_get_highest_priority_clock_class() returns NULL when there's no clock classes"); ret = bt_clock_class_priority_map_add_clock_class(cc_prio_map, cc2, 75); diff --git a/tests/lib/test_ctf_writer.c b/tests/lib/test_ctf_writer.c index 103de0ab..68961b1d 100644 --- a/tests/lib/test_ctf_writer.c +++ b/tests/lib/test_ctf_writer.c @@ -59,7 +59,7 @@ #define DEFAULT_CLOCK_TIME 0 #define DEFAULT_CLOCK_VALUE 0 -#define NR_TESTS 625 +#define NR_TESTS 552 struct bt_utsname { char sysname[BABELTRACE_HOST_NAME_MAX]; @@ -415,13 +415,7 @@ void append_simple_event(struct bt_stream_class *stream_class, integer_field) == 0, "Use bt_event_set_payload to set a manually allocated field"); float_field = bt_event_get_payload(simple_event, "float_field"); - ok(bt_field_floating_point_get_value(float_field, &ret_double), - "bt_field_floating_point_get_value fails on an unset float field"); bt_field_floating_point_set_value(float_field, double_test_value); - ok(bt_field_floating_point_get_value(NULL, &ret_double), - "bt_field_floating_point_get_value properly handles a NULL field"); - ok(bt_field_floating_point_get_value(float_field, NULL), - "bt_field_floating_point_get_value properly handles a NULL return value pointer"); ok(!bt_field_floating_point_get_value(float_field, &ret_double), "bt_field_floating_point_get_value returns a double value"); ok(fabs(ret_double - double_test_value) <= DBL_EPSILON, @@ -430,12 +424,7 @@ void append_simple_event(struct bt_stream_class *stream_class, enum_field = bt_field_create(ep_enum_field_type); assert(enum_field); - iter = bt_field_enumeration_get_mappings(NULL); - ok(!iter, "bt_field_enumeration_get_mappings handles NULL correctly"); - iter = bt_field_enumeration_get_mappings(enum_field); - ok(!iter, "bt_field_enumeration_get_mappings returns NULL if the enumeration's container field is unset"); - enum_container_field = bt_field_enumeration_get_container( - enum_field); + enum_container_field = bt_field_enumeration_get_container(enum_field); ok(bt_field_signed_integer_set_value( enum_container_field, -42) == 0, "Set signed enumeration container value"); @@ -481,8 +470,6 @@ void append_simple_event(struct bt_stream_class *stream_class, bt_field_unsigned_integer_set_value(stream_event_context_field, 42); /* Populate the event's context */ - ok(bt_event_get_event_context(NULL) == NULL, - "bt_event_get_event_context handles NULL correctly"); event_context = bt_event_get_event_context(simple_event); ok(event_context, "bt_event_get_event_context returns a field"); @@ -493,20 +480,12 @@ void append_simple_event(struct bt_stream_class *stream_class, "event_specific_context"); ok(!bt_field_unsigned_integer_set_value(event_context_field, 1234), "Successfully set an event context's value"); - ok(bt_event_set_event_context(NULL, event_context) < 0, - "bt_event_set_event_context handles a NULL event correctly"); - ok(bt_event_set_event_context(simple_event, NULL) < 0, - "bt_event_set_event_context handles a NULL event context correctly"); - ok(bt_event_set_event_context(simple_event, event_context_field) < 0, - "bt_event_set_event_context rejects a context of the wrong type"); ok(!bt_event_set_event_context(simple_event, event_context), "Set an event context successfully"); ok(bt_stream_append_event(stream, simple_event) == 0, "Append simple event to trace stream"); - ok(bt_stream_get_packet_context(NULL) == NULL, - "bt_stream_get_packet_context handles NULL correctly"); packet_context = bt_stream_get_packet_context(stream); ok(packet_context, "bt_stream_get_packet_context returns a packet context"); @@ -521,10 +500,6 @@ void append_simple_event(struct bt_stream_class *stream_class, ok(bt_field_unsigned_integer_set_value(packet_context_field, 8) == 0, "Custom packet context field value successfully set."); - ok(bt_stream_set_packet_context(NULL, packet_context_field) < 0, - "bt_stream_set_packet_context handles a NULL stream correctly"); - ok(bt_stream_set_packet_context(stream, NULL) < 0, - "bt_stream_set_packet_context handles a NULL packet context correctly"); ok(bt_stream_set_packet_context(stream, packet_context) == 0, "Successfully set a stream's packet context"); @@ -570,7 +545,7 @@ void append_complex_event(struct bt_stream_class *stream_class, const char *test_string_2 = "string "; const char *test_string_3 = "abcdefghi"; const char *test_string_4 = "abcd\0efg\0hi"; - const char *test_string_cat = "Test string abcdeabcd"; + const char *test_string_cat = "Test string abcdeefg"; struct bt_field_type *uint_35_type = bt_field_type_integer_create(35); struct bt_field_type *int_16_type = @@ -871,57 +846,33 @@ void append_complex_event(struct bt_stream_class *stream_class, event = bt_event_create(event_class); ok(event, "Instanciate a complex event"); - ok(bt_event_get_class(NULL) == NULL, - "bt_event_get_class handles NULL correctly"); ret_event_class = bt_event_get_class(event); ok(ret_event_class == event_class, "bt_event_get_class returns the correct event class"); bt_put(ret_event_class); uint_35_field = bt_event_get_payload(event, "uint_35"); - if (!uint_35_field) { - printf("uint_35_field is NULL\n"); - } - ok(uint_35_field, "Use bt_event_get_payload to get a field instance "); bt_field_unsigned_integer_set_value(uint_35_field, 0x0DDF00D); - ok(bt_field_unsigned_integer_get_value(NULL, &ret_unsigned_int) < 0, - "bt_field_unsigned_integer_get_value properly properly handles a NULL field."); - ok(bt_field_unsigned_integer_get_value(uint_35_field, NULL) < 0, - "bt_field_unsigned_integer_get_value properly handles a NULL return value"); ok(bt_field_unsigned_integer_get_value(uint_35_field, &ret_unsigned_int) == 0, "bt_field_unsigned_integer_get_value succeeds after setting a value"); ok(ret_unsigned_int == 0x0DDF00D, "bt_field_unsigned_integer_get_value returns the correct value"); - ok(bt_field_signed_integer_get_value(uint_35_field, - &ret_signed_int) < 0, - "bt_field_signed_integer_get_value fails on an unsigned field"); bt_put(uint_35_field); int_16_field = bt_event_get_payload(event, "int_16"); bt_field_signed_integer_set_value(int_16_field, -12345); - ok(bt_field_signed_integer_get_value(NULL, &ret_signed_int) < 0, - "bt_field_signed_integer_get_value properly handles a NULL field"); - ok(bt_field_signed_integer_get_value(int_16_field, NULL) < 0, - "bt_field_signed_integer_get_value properly handles a NULL return value"); ok(bt_field_signed_integer_get_value(int_16_field, &ret_signed_int) == 0, "bt_field_signed_integer_get_value succeeds after setting a value"); ok(ret_signed_int == -12345, "bt_field_signed_integer_get_value returns the correct value"); - ok(bt_field_unsigned_integer_get_value(int_16_field, - &ret_unsigned_int) < 0, - "bt_field_unsigned_integer_get_value fails on a signed field"); bt_put(int_16_field); complex_structure_field = bt_event_get_payload(event, "complex_structure"); - ok(bt_field_structure_get_field_by_index(NULL, 0) == NULL, - "bt_field_structure_get_field_by_index handles NULL correctly"); - ok(bt_field_structure_get_field_by_index(NULL, 9) == NULL, - "bt_field_structure_get_field_by_index handles an invalid index correctly"); inner_structure_field = bt_field_structure_get_field_by_index( complex_structure_field, 3); ret_field_type = bt_field_get_type(inner_structure_field); @@ -952,27 +903,13 @@ void append_complex_event(struct bt_stream_class *stream_class, enum_variant_field); bt_field_signed_integer_set_value(int_16_field, -200); bt_put(int_16_field); - ok(!bt_field_string_get_value(a_string_field), - "bt_field_string_get_value returns NULL on an unset field"); bt_field_string_set_value(a_string_field, test_string_1); - ok(!bt_field_string_get_value(NULL), - "bt_field_string_get_value correctly handles NULL"); - ok(bt_field_string_append(NULL, "yeah"), - "bt_field_string_append correctly handles a NULL string field"); - ok(bt_field_string_append(a_string_field, NULL), - "bt_field_string_append correctly handles a NULL string value"); ok(!bt_field_string_append(a_string_field, test_string_2), "bt_field_string_append succeeds"); - ok(bt_field_string_append_len(NULL, "oh noes", 3), - "bt_field_string_append_len correctly handles a NULL string field"); - ok(bt_field_string_append_len(a_string_field, NULL, 3), - "bt_field_string_append_len correctly handles a NULL string value"); ok(!bt_field_string_append_len(a_string_field, test_string_3, 5), "bt_field_string_append_len succeeds (append 5 characters)"); - ok(!bt_field_string_append_len(a_string_field, test_string_4, 10), - "bt_field_string_append_len succeeds (append 4 characters)"); - ok(!bt_field_string_append_len(a_string_field, &test_string_4[4], 3), + ok(!bt_field_string_append_len(a_string_field, &test_string_4[5], 3), "bt_field_string_append_len succeeds (append 0 characters)"); ok(!bt_field_string_append_len(a_string_field, test_string_3, 0), "bt_field_string_append_len succeeds (append 0 characters)"); @@ -984,26 +921,16 @@ void append_complex_event(struct bt_stream_class *stream_class, bt_field_unsigned_integer_set_value(uint_35_field, SEQUENCE_TEST_LENGTH); - ok(bt_field_type_variant_get_field_type_from_tag(NULL, - enum_container_field) == NULL, - "bt_field_type_variant_get_field_type_from_tag handles a NULL variant type correctly"); - ok(bt_field_type_variant_get_field_type_from_tag(variant_type, - NULL) == NULL, - "bt_field_type_variant_get_field_type_from_tag handles a NULL tag correctly"); ret_field_type = bt_field_type_variant_get_field_type_from_tag( variant_type, enum_variant_field); ok(ret_field_type == int_16_type, "bt_field_type_variant_get_field_type_from_tag returns the correct field type"); - ok(bt_field_sequence_get_length(a_sequence_field) == NULL, - "bt_field_sequence_get_length returns NULL when length is unset"); ok(bt_field_sequence_set_length(a_sequence_field, uint_35_field) == 0, "Set a sequence field's length"); ret_field = bt_field_sequence_get_length(a_sequence_field); ok(ret_field == uint_35_field, "bt_field_sequence_get_length returns the correct length field"); - ok(bt_field_sequence_get_length(NULL) == NULL, - "bt_field_sequence_get_length properly handles NULL"); for (i = 0; i < SEQUENCE_TEST_LENGTH; i++) { int_16_field = bt_field_sequence_get_field( @@ -1276,8 +1203,6 @@ void field_copy_tests() /* set v field */ v_selected = bt_field_variant_get_field(v, e); assert(v_selected); - ok(!bt_field_variant_get_current_field(NULL), - "bt_field_variant_get_current_field handles NULL correctly"); v_selected_cur = bt_field_variant_get_current_field(v); ok(v_selected_cur == v_selected, "bt_field_variant_get_current_field returns the current field"); @@ -1338,8 +1263,6 @@ void field_copy_tests() assert(!ret); /* create copy of strct */ - ok(!bt_field_copy(NULL), - "bt_field_copy handles NULL correctly"); strct_copy = bt_field_copy(strct); ok(strct_copy, "bt_field_copy returns a valid pointer"); @@ -1373,8 +1296,6 @@ void field_copy_tests() assert(v_selected_5_copy); v_selected_6_copy = bt_field_sequence_get_field(v_selected_copy, 6); assert(v_selected_6_copy); - ok(!bt_field_sequence_get_field(v_selected_copy, 7), - "sequence field copy is not too large"); a_copy = bt_field_structure_get_field_by_name(strct_copy, "a"); assert(a_copy); a_0_copy = bt_field_array_get_field(a_copy, 0); @@ -1387,8 +1308,6 @@ void field_copy_tests() assert(a_3_copy); a_4_copy = bt_field_array_get_field(a_copy, 4); assert(a_4_copy); - ok(!bt_field_array_get_field(v_selected_copy, 5), - "array field copy is not too large"); /* make sure copied fields are different pointers */ field_copy_tests_validate_diff_ptrs(strct_copy, strct, "strct"); @@ -1611,7 +1530,6 @@ void type_field_tests() struct bt_field *uint_12; struct bt_field *int_16; struct bt_field *string; - struct bt_field *enumeration; struct bt_field_type *composite_structure_type; struct bt_field_type *structure_seq_type; struct bt_field_type *string_type; @@ -1624,9 +1542,6 @@ void type_field_tests() struct bt_field_type *returned_type; const char *ret_string; - returned_type = bt_field_get_type(NULL); - ok(!returned_type, "bt_field_get_type handles NULL correctly"); - ok(uint_12_type, "Create an unsigned integer type"); ok(bt_field_type_integer_set_base(uint_12_type, BT_INTEGER_BASE_BINARY) == 0, @@ -1838,28 +1753,16 @@ void type_field_tests() ok(bt_ctf_field_type_integer_set_signed(uint_12_type, 0), "Check an integer type's signedness can't be modified after instanciation"); - /* Check signed property is checked */ - ok(bt_field_signed_integer_set_value(uint_12, -52), - "Check bt_field_signed_integer_set_value is not allowed on an unsigned integer"); - ok(bt_field_unsigned_integer_set_value(int_16, 42), - "Check bt_field_unsigned_integer_set_value is not allowed on a signed integer"); - /* Check overflows are properly tested for */ ok(bt_field_signed_integer_set_value(int_16, -32768) == 0, "Check -32768 is allowed for a signed 16-bit integer"); ok(bt_field_signed_integer_set_value(int_16, 32767) == 0, "Check 32767 is allowed for a signed 16-bit integer"); - ok(bt_field_signed_integer_set_value(int_16, 32768), - "Check 32768 is not allowed for a signed 16-bit integer"); - ok(bt_field_signed_integer_set_value(int_16, -32769), - "Check -32769 is not allowed for a signed 16-bit integer"); ok(bt_field_signed_integer_set_value(int_16, -42) == 0, "Check -42 is allowed for a signed 16-bit integer"); ok(bt_field_unsigned_integer_set_value(uint_12, 4095) == 0, "Check 4095 is allowed for an unsigned 12-bit integer"); - ok(bt_field_unsigned_integer_set_value(uint_12, 4096), - "Check 4096 is not allowed for a unsigned 12-bit integer"); ok(bt_field_unsigned_integer_set_value(uint_12, 0) == 0, "Check 0 is allowed for an unsigned 12-bit integer"); @@ -1871,14 +1774,10 @@ void type_field_tests() enumeration_type = bt_field_type_enumeration_create(uint_12_type); ok(enumeration_type, "Create an enumeration type with an unsigned 12-bit integer as container"); - enumeration = bt_field_create(enumeration_type); - ok(!enumeration, - "Check enumeration types are validated before instantiation"); bt_put(string); bt_put(uint_12); bt_put(int_16); - bt_put(enumeration); bt_put(composite_structure_type); bt_put(structure_seq_type); bt_put(string_type); @@ -1949,11 +1848,6 @@ void packet_resize_test(struct bt_stream_class *stream_class, "bt_event_get_payload_by_index returns a correct field"); bt_put(ret_field_type); bt_put(ret_field); - - ok(bt_event_get_payload_by_index(NULL, 0) == NULL, - "bt_event_get_payload_by_index handles NULL correctly"); - ok(bt_event_get_payload_by_index(event, 4) == NULL, - "bt_event_get_payload_by_index handles an invalid index correctly"); bt_put(event); for (i = 0; i < packet_resize_test_length; i++) { @@ -1992,10 +1886,6 @@ void packet_resize_test(struct bt_stream_class *stream_class, } events_appended = !!(i == packet_resize_test_length); - ok(bt_stream_get_discarded_events_count(NULL, &ret_uint64) < 0, - "bt_stream_get_discarded_events_count handles a NULL stream correctly"); - ok(bt_stream_get_discarded_events_count(stream, NULL) < 0, - "bt_stream_get_discarded_events_count handles a NULL return pointer correctly"); ret = bt_stream_get_discarded_events_count(stream, &ret_uint64); ok(ret == 0 && ret_uint64 == 0, "bt_stream_get_discarded_events_count returns a correct number of discarded events when none were discarded"); @@ -2348,11 +2238,6 @@ void test_instanciate_event_before_stream(struct bt_ctf_writer *writer, goto end; } - ok(bt_event_get_stream(NULL) == NULL, - "bt_event_get_stream handles NULL correctly"); - ok(bt_event_get_stream(event) == NULL, - "bt_event_get_stream returns NULL on event which has not yet been appended to a stream"); - ret = bt_stream_append_event(stream, event); if (ret) { diag("Failed to append event to stream"); @@ -2523,8 +2408,6 @@ void test_create_writer_vs_non_writer_mode(void) * It should be possible to create a packet from a non-writer * stream, but not from a writer stream. */ - packet = bt_packet_create(writer_stream); - ok(!packet, "bt_packet_create() fails with a writer stream"); packet = bt_packet_create(non_writer_stream); ok(packet, "bt_packet_create() succeeds with a non-writer stream"); packet_stream = bt_packet_get_stream(packet); @@ -2537,16 +2420,6 @@ void test_create_writer_vs_non_writer_mode(void) */ writer_stream2 = bt_stream_create(writer_sc, "zoo"); assert(writer_stream2); - ok(bt_stream_append_event(writer_stream2, event), - "bt_stream_append_event() fails with an event associated to another stream"); - - /* - * It should not be possible to set the packet of an event - * associated to a given stream to a packet associated with - * a different stream. - */ - ok(bt_event_set_packet(event, packet), - "bt_event_set_packet() fails with a packet not sharing the event's stream"); /* * It should be possible to set the packet of a fresh event, as @@ -2554,8 +2427,6 @@ void test_create_writer_vs_non_writer_mode(void) */ event2 = bt_event_create(writer_ec); assert(event2); - ok(bt_event_set_packet(event2, packet), - "bt_event_set_packet() fails when the event's and the packet's stream class differ"); non_writer_ec = create_minimal_event_class(); assert(non_writer_ec); ret = bt_stream_class_add_event_class(non_writer_sc, non_writer_ec); @@ -2584,8 +2455,6 @@ void test_create_writer_vs_non_writer_mode(void) assert(non_writer_stream2); packet2 = bt_packet_create(non_writer_stream); assert(packet2); - ok(!bt_event_set_packet(event2, packet2), - "bt_event_set_packet() fails when the event's current packet does not have the same stream"); bt_put(writer); bt_put(writer_trace); @@ -3104,41 +2973,6 @@ int main(int argc, char **argv) ok(bt_ctf_clock_set_time(clock, current_time) == 0, "Set clock time"); - ok(!bt_ctf_clock_get_name(NULL), - "bt_ctf_clock_get_name correctly handles NULL"); - ok(!bt_ctf_clock_get_description(NULL), - "bt_ctf_clock_get_description correctly handles NULL"); - ok(bt_ctf_clock_get_frequency(NULL) == -1ULL, - "bt_ctf_clock_get_frequency correctly handles NULL"); - ok(bt_ctf_clock_get_precision(NULL) == -1ULL, - "bt_ctf_clock_get_precision correctly handles NULL"); - ok(bt_ctf_clock_get_offset_s(NULL, &get_offset_s) < 0, - "bt_ctf_clock_get_offset_s correctly handles NULL clock"); - ok(bt_ctf_clock_get_offset_s(clock, NULL) < 0, - "bt_ctf_clock_get_offset_s correctly handles NULL output"); - ok(bt_ctf_clock_get_offset(NULL, &get_offset) < 0, - "bt_ctf_clock_get_offset correctly handles NULL clock"); - ok(bt_ctf_clock_get_offset(clock, NULL) < 0, - "bt_ctf_clock_get_offset correctly handles NULL output"); - ok(bt_ctf_clock_get_is_absolute(NULL) < 0, - "bt_ctf_clock_get_is_absolute correctly handles NULL"); - - ok(bt_ctf_clock_set_description(NULL, NULL) < 0, - "bt_ctf_clock_set_description correctly handles NULL clock"); - ok(bt_ctf_clock_set_frequency(NULL, frequency) < 0, - "bt_ctf_clock_set_frequency correctly handles NULL clock"); - ok(bt_ctf_clock_set_precision(NULL, precision) < 0, - "bt_ctf_clock_get_precision correctly handles NULL clock"); - ok(bt_ctf_clock_set_offset_s(NULL, offset_s) < 0, - "bt_ctf_clock_set_offset_s correctly handles NULL clock"); - ok(bt_ctf_clock_set_offset(NULL, offset) < 0, - "bt_ctf_clock_set_offset correctly handles NULL clock"); - ok(bt_ctf_clock_set_is_absolute(NULL, is_absolute) < 0, - "bt_ctf_clock_set_is_absolute correctly handles NULL clock"); - ok(bt_ctf_clock_set_time(NULL, current_time) < 0, - "bt_ctf_clock_set_time correctly handles NULL clock"); - ok(bt_ctf_clock_get_uuid(NULL) == NULL, - "bt_ctf_clock_get_uuid correctly handles NULL clock"); ret_uuid = bt_ctf_clock_get_uuid(clock); ok(ret_uuid, "bt_ctf_clock_get_uuid returns a UUID"); @@ -3148,10 +2982,6 @@ int main(int argc, char **argv) tmp_uuid[sizeof(tmp_uuid) - 1]++; } - ok(bt_ctf_clock_set_uuid(NULL, tmp_uuid) < 0, - "bt_ctf_clock_set_uuid correctly handles a NULL clock"); - ok(bt_ctf_clock_set_uuid(clock, NULL) < 0, - "bt_ctf_clock_set_uuid correctly handles a NULL UUID"); ok(bt_ctf_clock_set_uuid(clock, tmp_uuid) == 0, "bt_ctf_clock_set_uuid sets a new uuid successfully"); ret_uuid = bt_ctf_clock_get_uuid(clock);