#include "logging.h"
#include <babeltrace/babeltrace.h>
+#include <babeltrace/assert-internal.h>
typedef const unsigned char *BTUUID;
%}
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;
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;
}
*/
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,
* 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)
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
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,
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) {
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;
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) {
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);
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) {
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);
}
* 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:
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 */
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,
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;
}
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:
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();
}
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;
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(
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) {
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) {
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.");
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(
}
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);
}
}
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);
}
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);
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);
static void graph_listener_removed(void *py_callable)
{
- assert(py_callable);
+ BT_ASSERT(py_callable);
Py_DECREF(py_callable);
}
{
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) {
{
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) {
{
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) {
{
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);
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);
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,
}
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);
}
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) {
bool is_valid = true;
const char *ch = port_glob;
- assert(port_glob);
+ BT_ASSERT(port_glob);
while (*ch != '\0') {
switch (*ch) {
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 &&
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++) {
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",
#include <errno.h>
#include <stdlib.h>
#include <string.h>
-#include <assert.h>
+#include <babeltrace/assert-internal.h>
#include <stdio.h>
#include <stdbool.h>
#include <inttypes.h>
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");
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, ',');
goto error;
}
- assert(params);
+ BT_ASSERT(params);
BT_MOVE(cfg->cmd_data.query.cfg_component->params, params);
} else {
print_query_usage(stdout);
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) {
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);
}
goto error;
}
- assert(bt_value_is_string(elem));
+ BT_ASSERT(bt_value_is_string(elem));
if (bt_value_string_get(elem, &arg)) {
goto error;
}
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);
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);
}
{
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();
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)) {
GString *g_begin = NULL;
GString *g_end = NULL;
- assert(arg);
+ BT_ASSERT(arg);
if (*ch == '[') {
ch++;
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);
int ret = 0;
GString *gs = g_string_new(string);
- assert(list);
+ BT_ASSERT(list);
if (!gs) {
print_err_oom();
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) {
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:
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
-#include <assert.h>
+#include <babeltrace/assert-internal.h>
#include <babeltrace/babeltrace.h>
#include <popt.h>
#include <glib.h>
}
*output_path = strdup(leftover);
- assert(*output_path);
+ BT_ASSERT(*output_path);
goto end;
error:
*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 */
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++) {
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)) {
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 =
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: "
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) {
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) {
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",
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);
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);
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);
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);
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) {
}
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 =
{
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);
}
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) {
}
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 =
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)) {
}
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,
if (graph_status != BT_GRAPH_STATUS_OK) {
goto error;
}
- assert(trimmer);
+ BT_ASSERT(trimmer);
trimmer_input =
bt_component_filter_get_input_port_by_index(
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: "
}
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,
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\", "
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;
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",
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;
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) {
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
-#include <assert.h>
+#include <babeltrace/assert-internal.h>
#include <stdarg.h>
#include <ctype.h>
#include <glib.h>
const char *end;
size_t init_dirs_len;
- assert(dirs);
+ BT_ASSERT(dirs);
init_dirs_len = dirs->len;
if (!paths) {
{
const char *ch;
bool printable = true;
- assert(input);
+ BT_ASSERT(input);
for (ch = input; *ch != '\0'; ch++) {
if (!isprint(*ch) && *ch != '\n' && *ch != '\r' &&
const char *at = url;
size_t end_pos;
- assert(url);
+ BT_ASSERT(url);
memset(&parts, 0, sizeof(parts));
parts.port = -1;
char *np;
bool got_star = false;
- assert(pattern);
+ BT_ASSERT(pattern);
for (p = pattern, np = pattern; *p != '\0'; p++) {
switch (*p) {
* ^ ^ 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;
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);
}
char *tmp;
GString *norm_path = NULL;
- assert(path);
+ BT_ASSERT(path);
tmp = _fullpath(NULL, path, PATH_MAX);
if (!tmp) {
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;
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)
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,
#include <stdint.h> /* C99 5.2.4.2 Numerical limits */
#include <babeltrace/compat/limits-internal.h> /* C99 5.2.4.2 Numerical limits */
-#include <assert.h>
#include <babeltrace/endian-internal.h> /* Non-standard BIG_ENDIAN, LITTLE_ENDIAN, BYTE_ORDER */
/* We can't shift a int from 32 bit, >> 32 and << 32 on int is undefined */
#include <stdio.h>
#include <errno.h>
-#include <assert.h>
#include <stdlib.h>
#include <limits.h>
+#include <babeltrace/assert-internal.h>
#define BT_GETLINE_MINBUFLEN 64
/* ferror() is set, errno set by fgetc(). */
return -1;
}
- assert(feof(stream));
+ BT_ASSERT(feof(stream));
found_eof = 1;
break;
}
#include <babeltrace/ctf-ir/stream.h>
#include <babeltrace/ctf-ir/event-class.h>
#include <babeltrace/object-internal.h>
+#include <babeltrace/assert-internal.h>
#include <glib.h>
struct bt_event_class {
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);
}
#include <babeltrace/ctf-ir/stream.h>
#include <babeltrace/ctf-ir/packet.h>
#include <babeltrace/object-internal.h>
-#include <assert.h>
+#include <babeltrace/assert-internal.h>
#include <glib.h>
struct bt_stream_pos;
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;
}
*/
#include <babeltrace/object-internal.h>
-#include <assert.h>
+#include <babeltrace/assert-internal.h>
#include <glib.h>
struct bt_field_path {
GString *str = g_string_new(NULL);
size_t i;
- assert(path);
+ BT_ASSERT(path);
if (!str) {
goto end;
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(
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);
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
*
#include <babeltrace/ctf-ir/stream.h>
#include <babeltrace/object-internal.h>
#include <babeltrace/babeltrace-internal.h>
-#include <assert.h>
+#include <babeltrace/assert-internal.h>
struct bt_packet {
struct bt_object base;
};
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;
}
#include <babeltrace/object-internal.h>
#include <babeltrace/babeltrace-internal.h>
#include <babeltrace/ctf-ir/trace-internal.h>
-#include <assert.h>
+#include <babeltrace/assert-internal.h>
#include <glib.h>
struct bt_stream_class {
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);
}
#include <babeltrace/ctf-writer/event-types.h>
#include <babeltrace/ctf-writer/serialize-internal.h>
#include <babeltrace/babeltrace-internal.h>
+#include <babeltrace/assert-internal.h>
#include <glib.h>
struct bt_port;
struct bt_stream_class *bt_stream_borrow_stream_class(
struct bt_stream *stream)
{
- assert(stream);
+ BT_ASSERT(stream);
return stream->stream_class;
}
#include <babeltrace/common-internal.h>
#include <babeltrace/mmap-align-internal.h>
#include <babeltrace/types.h>
+#include <babeltrace/assert-internal.h>
#define PACKET_LEN_INCREMENT (bt_common_get_page_size() * 8 * CHAR_BIT)
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);
}
#include <stdint.h>
#include <stddef.h>
-#include <assert.h>
+#include <babeltrace/assert-internal.h>
#include <babeltrace/ctf-ir/clock-class.h>
#include <babeltrace/object-internal.h>
#include <babeltrace/types.h>
};
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 */
#include <babeltrace/graph/port-internal.h>
#include <babeltrace/object-internal.h>
#include <babeltrace/types.h>
+#include <babeltrace/assert-internal.h>
#include <glib.h>
#include <stdio.h>
static inline
struct bt_graph *bt_component_borrow_graph(struct bt_component *comp)
{
- assert(comp);
+ BT_ASSERT(comp);
return (void *) comp->base.parent;
}
#include <babeltrace/graph/notification-iterator-internal.h>
#include <babeltrace/graph/private-connection.h>
#include <babeltrace/object-internal.h>
+#include <babeltrace/assert-internal.h>
#include <stdbool.h>
struct bt_graph;
static inline
struct bt_graph *bt_connection_borrow_graph(struct bt_connection *conn)
{
- assert(conn);
+ BT_ASSERT(conn);
return (void *) conn->base.parent;
}
#include <babeltrace/graph/component-status.h>
#include <babeltrace/babeltrace-internal.h>
#include <babeltrace/object-internal.h>
+#include <babeltrace/assert-internal.h>
#include <stdlib.h>
-#include <assert.h>
#include <glib.h>
struct bt_component;
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;
}
#include <glib.h>
#include <stdint.h>
+#include <babeltrace/assert-internal.h>
#include <babeltrace/compiler-internal.h>
#include <babeltrace/graph/notification.h>
#include <babeltrace/graph/notification-internal.h>
{
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;
#include <babeltrace/ctf-ir/event.h>
#include <babeltrace/graph/notification-internal.h>
#include <babeltrace/graph/clock-class-priority-map.h>
+#include <babeltrace/assert-internal.h>
#ifdef __cplusplus
extern "C" {
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;
}
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;
}
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,
#include <babeltrace/graph/notification-iterator.h>
#include <babeltrace/graph/private-connection-private-notification-iterator.h>
#include <babeltrace/types.h>
+#include <babeltrace/assert-internal.h>
#include <stdbool.h>
-#include <assert.h>
struct bt_port;
struct bt_graph;
struct bt_notification *bt_notification_iterator_borrow_current_notification(
struct bt_notification_iterator *iterator)
{
- assert(iterator);
+ BT_ASSERT(iterator);
return iterator->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);
}
#include <babeltrace/compiler-internal.h>
#include <babeltrace/ctf-ir/packet.h>
#include <babeltrace/graph/notification-internal.h>
+#include <babeltrace/assert-internal.h>
struct bt_notification_packet_begin {
struct bt_notification parent;
container_of(notif,
struct bt_notification_packet_begin, parent);
- assert(notif_packet_begin);
+ BT_ASSERT(notif_packet_begin);
return notif_packet_begin->packet;
}
container_of(notif,
struct bt_notification_packet_end, parent);
- assert(notif_packet_end);
+ BT_ASSERT(notif_packet_end);
return notif_packet_end->packet;
}
#include <babeltrace/compiler-internal.h>
#include <babeltrace/ctf-ir/packet.h>
#include <babeltrace/graph/notification-internal.h>
+#include <babeltrace/assert-internal.h>
struct bt_notification_stream_begin {
struct bt_notification parent;
container_of(notif,
struct bt_notification_stream_begin, parent);
- assert(notif_stream_begin);
+ BT_ASSERT(notif_stream_begin);
return notif_stream_begin->stream;
}
container_of(notif,
struct bt_notification_stream_end, parent);
- assert(notif_stream_end);
+ BT_ASSERT(notif_stream_end);
return notif_stream_end->stream;
}
#include <babeltrace/ref-internal.h>
#include <babeltrace/ref.h>
+#include <babeltrace/assert-internal.h>
/**
* All objects publicly exposed by Babeltrace APIs must contain this structure
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;
}
#include <babeltrace/plugin/plugin-dev.h>
#include <babeltrace/object-internal.h>
#include <babeltrace/types.h>
+#include <babeltrace/assert-internal.h>
#include <glib.h>
enum bt_plugin_type {
{
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);
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\"",
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\"",
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\"",
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\"",
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\"",
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;
static inline
void bt_plugin_freeze(struct bt_plugin *plugin)
{
- assert(plugin);
+ BT_ASSERT(plugin);
if (plugin->frozen) {
return;
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\", "
*/
#include <babeltrace/babeltrace-internal.h>
-#include <assert.h>
+#include <babeltrace/assert-internal.h>
struct bt_object;
typedef void (*bt_object_release_func)(struct bt_object *);
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;
}
static inline
void bt_ref_get(struct bt_ref *ref)
{
- assert(ref);
+ BT_ASSERT(ref);
if (unlikely(!ref->release)) {
return;
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);
#include <babeltrace/values.h>
+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:
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:
@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.
@{
*/
-/**
-@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 <strong>On success</strong>, \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.
@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}
#include <babeltrace/ref.h>
#include <babeltrace/babeltrace-internal.h>
#include <babeltrace/values.h>
+#include <babeltrace/values-internal.h>
#include <inttypes.h>
-#include <assert.h>
#include <babeltrace/compat/string-internal.h>
+#include <babeltrace/assert-internal.h>
#define BT_ATTR_NAME_INDEX 0
#define BT_ATTR_VALUE_INDEX 1
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: "
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: "
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
#include <babeltrace/compat/string-internal.h>
#include <inttypes.h>
#include <babeltrace/object-internal.h>
+#include <babeltrace/assert-internal.h>
static
void bt_clock_class_destroy(struct bt_object *obj);
}
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) {
}
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) {
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) {
#include <babeltrace/endian-internal.h>
#include <babeltrace/types.h>
#include <babeltrace/values-internal.h>
+#include <babeltrace/assert-internal.h>
#include <inttypes.h>
#include <stdlib.h>
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);
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:
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);
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) {
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;
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",
/* 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",
{
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) {
#include <babeltrace/ref.h>
#include <babeltrace/ctf-ir/attributes-internal.h>
#include <babeltrace/compiler-internal.h>
+#include <babeltrace/assert-internal.h>
+#include <babeltrace/assert-pre-internal.h>
#include <inttypes.h>
+#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);
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) {
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;
}
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.
* 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) {
name, payload);
}
-end:
return ret;
}
{
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, "
payload = event->fields_payload;
bt_get(payload);
+
end:
return payload;
}
{
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(
field = event->fields_payload;
bt_get(field);
}
-end:
+
return field;
}
{
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, "
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);
"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, "
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);
"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(
{
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, "
}
stream_event_context = event->stream_event_context;
+
end:
return bt_get(stream_event_context);
}
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);
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 */
{
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: "
}
bt_get(clock_value);
+
end:
return clock_value;
}
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\", "
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: "
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: "
{
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,
}
packet = bt_get(event->packet);
+
end:
return packet;
}
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);
"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;
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;
}
#include <limits.h>
#include <stdint.h>
#include <inttypes.h>
+#include <babeltrace/assert-internal.h>
#include <glib.h>
static
{
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();
#include <babeltrace/ref.h>
#include <babeltrace/compiler-internal.h>
#include <babeltrace/endian-internal.h>
+#include <babeltrace/assert-internal.h>
#include <float.h>
#include <inttypes.h>
#include <stdlib.h>
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);
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;
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);
}
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: "
}
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: "
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: "
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: "
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: "
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 */
if (mapping_name) {
*mapping_name = g_quark_to_string(mapping->string);
- assert(*mapping_name);
+ BT_ASSERT(*mapping_name);
}
if (range_begin) {
if (mapping_name) {
*mapping_name = g_quark_to_string(mapping->string);
- assert(*mapping_name);
+ BT_ASSERT(*mapping_name);
}
if (range_begin) {
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);
}
if (field_name) {
*field_name = g_quark_to_string(field->name);
- assert(*field_name);
+ BT_ASSERT(*field_name);
}
end:
return ret;
}
if (field_name) {
*field_name = g_quark_to_string(field->name);
- assert(*field_name);
+ BT_ASSERT(*field_name);
}
end:
return ret;
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;
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;
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;
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);
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);
}
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;
{
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);
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);
}
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);
#include <babeltrace/compiler-internal.h>
#include <babeltrace/compat/fcntl-internal.h>
#include <babeltrace/align-internal.h>
+#include <babeltrace/assert-internal.h>
+#include <babeltrace/assert-pre-internal.h>
#include <inttypes.h>
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 *);
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 *,
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,
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,
};
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
[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;
{
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)
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) {
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;
}
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);
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;
}
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;
}
ret = bt_get(structure->fields->pdata[index]);
- assert(ret);
+ BT_ASSERT(ret);
+
error:
return ret;
}
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;
}
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;
}
bt_get(value);
BT_MOVE(structure->fields->pdata[index], value);
+
end:
- if (expected_field_type) {
- bt_put(expected_field_type);
- }
return ret;
}
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;
}
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];
}
/* 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;
}
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;
/*
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);
}
/* 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) {
bt_get(tag_field);
variant->tag = tag_field;
variant->payload = new_field;
+
end:
bt_put(tag_enum);
return new_field;
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 *
{
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);
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;
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;
}
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;
}
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;
}
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.");
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);
{
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);
{
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);
}
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);
}
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.");
}
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);
}
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) {
{
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) {
}
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;
}
}
}
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
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) {
}
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)
{
"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);
}
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);
}
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)
{
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,
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,
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)
{
"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)
{
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: "
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)
{
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: "
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;
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));
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,
goto end;
}
}
+
end:
bt_put(character);
bt_put(character_type);
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
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 =
}
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;
{
int ret;
- assert(pos);
+ BT_ASSERT(pos);
BT_LOGV("Increasing packet size: pos-offset=%" PRId64 ", "
"cur-packet-size=%" PRIu64,
pos->offset, pos->packet_size);
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;
}
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 =
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 =
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 =
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 =
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;
}
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;
}
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;
}
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;
}
}
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;
}
#include <babeltrace/ctf-ir/trace-internal.h>
#include <babeltrace/object-internal.h>
#include <babeltrace/ref.h>
+#include <babeltrace/assert-internal.h>
+#include <babeltrace/assert-pre-internal.h>
#include <inttypes.h>
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;
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;
}
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,
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.");
#include <babeltrace/babeltrace-internal.h>
#include <babeltrace/values.h>
#include <babeltrace/types.h>
+#include <babeltrace/assert-internal.h>
#include <limits.h>
#include <inttypes.h>
#include <stdlib.h>
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];
/*
* 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;
{
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;
#include <babeltrace/compiler-internal.h>
#include <babeltrace/align-internal.h>
#include <babeltrace/endian-internal.h>
+#include <babeltrace/assert-internal.h>
#include <inttypes.h>
#include <stdint.h>
#include <stdbool.h>
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): "
* 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 =
* 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);
}
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;
* 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) {
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) {
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);
{
int ret = 0;
- assert(stream_class);
+ BT_ASSERT(stream_class);
if (!stream_class->clock) {
/* No clock class to map to */
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) {
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) {
#include <babeltrace/ctf-writer/functor-internal.h>
#include <babeltrace/compiler-internal.h>
#include <babeltrace/align-internal.h>
+#include <babeltrace/assert-internal.h>
#include <inttypes.h>
#include <unistd.h>
}
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) {
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. */
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. */
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. */
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. */
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. */
* 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,
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;
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;
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) {
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) {
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) {
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 */
*/
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;
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) {
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;
}
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 "
* 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 "
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;
}
}
/* 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:
/* 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");
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");
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);
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: "
struct bt_clock_class *mapped_clock_class = NULL;
int64_t event_class_id;
- assert(event);
+ BT_ASSERT(event);
if (!event->event_header) {
goto end;
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);
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) {
}
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: "
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);
}
}
"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);
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);
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: "
/* 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: "
/* 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) {
goto end;
}
- assert(stream->pos.packet_size % 8 == 0);
+ BT_ASSERT(stream->pos.packet_size % 8 == 0);
/*
* Remove extra padding bytes.
}
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: "
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);
}
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) {
}
/* 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);
}
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
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
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);
}
{
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);
{
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 =
#include <babeltrace/ref.h>
#include <babeltrace/types.h>
#include <babeltrace/endian-internal.h>
+#include <babeltrace/assert-internal.h>
#include <inttypes.h>
#include <stdint.h>
#include <string.h>
}
ret = bt_attributes_get_count(trace->environment);
- assert(ret >= 0);
+ BT_ASSERT(ret >= 0);
end:
return ret;
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: "
}
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: "
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);
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 =
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;
}
{
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;
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);
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:
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);
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\"",
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;
#define BT_LOG_TAG "CTF-IR-UTILS"
#include <babeltrace/lib-logging-internal.h>
-#include <assert.h>
#include <stdlib.h>
#include <glib.h>
#include <babeltrace/ctf-ir/utils.h>
#include <babeltrace/ctf-ir/field-types.h>
#include <babeltrace/ctf-ir/clock-class.h>
#include <babeltrace/ref.h>
+#include <babeltrace/assert-internal.h>
static
const char * const reserved_keywords_str[] = {"align", "callsite",
}
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(
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:
abort();
}
- assert(subtype);
+ BT_ASSERT(subtype);
ret = bt_validate_single_clock_class(subtype,
expected_clock_class);
bt_put(subtype);
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);
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);
* SOFTWARE.
*/
+#define BT_LOG_TAG "CTF-WRITER-CLOCK"
+#include <babeltrace/lib-logging-internal.h>
+
#include <babeltrace/ctf-writer/clock-internal.h>
#include <babeltrace/ctf-ir/clock-class.h>
#include <babeltrace/ctf-ir/clock-class-internal.h>
#include <babeltrace/ref.h>
#include <babeltrace/object-internal.h>
#include <babeltrace/compiler-internal.h>
+#include <babeltrace/assert-internal.h>
+#include <babeltrace/assert-pre-internal.h>
#include <inttypes.h>
static
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;
}
}
ret = bt_clock_class_set_uuid(clock->clock_class, cc_uuid);
- assert(ret == 0);
+ BT_ASSERT(ret == 0);
return clock;
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) {
(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)
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
#include <babeltrace/compat/fcntl-internal.h>
#include <babeltrace/types.h>
#include <babeltrace/common-internal.h>
+#include <babeltrace/assert-internal.h>
#include <glib.h>
#if (FLT_RADIX != 2)
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:
{
int ret;
- assert(whence == SEEK_CUR && index == 0);
+ BT_ASSERT(whence == SEEK_CUR && index == 0);
if (pos->base_mma) {
/* unmap old base */
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. */
#include <babeltrace/endian-internal.h>
#include <babeltrace/compiler-internal.h>
#include <babeltrace/compat/uuid-internal.h>
+#include <babeltrace/assert-internal.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
/* 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)) {
#include <babeltrace/babeltrace-internal.h>
#include <babeltrace/compiler-internal.h>
#include <babeltrace/ref.h>
+#include <babeltrace/assert-internal.h>
+#include <babeltrace/assert-pre-internal.h>
#include <stdint.h>
#include <inttypes.h>
#include <glib.h>
{
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);
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(
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 =
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);
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(
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: "
// 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);
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, "
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;
}
#include <babeltrace/graph/private-connection.h>
#include <babeltrace/graph/private-component.h>
#include <babeltrace/graph/component-class-sink-colander-internal.h>
+#include <babeltrace/assert-internal.h>
#include <glib.h>
-#include <assert.h>
static
struct bt_component_class *colander_comp_cls;
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,
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: "
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. */
#include <babeltrace/graph/component-class-internal.h>
#include <babeltrace/ref.h>
#include <babeltrace/types.h>
+#include <babeltrace/assert-internal.h>
#include <glib.h>
static
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: "
{
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);
#include <babeltrace/types.h>
#include <babeltrace/values.h>
#include <babeltrace/values-internal.h>
+#include <babeltrace/assert-internal.h>
#include <stdint.h>
#include <inttypes.h>
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. */
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;
}
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: "
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);
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);
}
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);
}
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);
}
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);
}
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: "
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);
{
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: "
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: "
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: "
{
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);
{
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 =
#include <babeltrace/graph/port-internal.h>
#include <babeltrace/object-internal.h>
#include <babeltrace/compiler-internal.h>
+#include <babeltrace/assert-internal.h>
#include <stdlib.h>
#include <glib.h>
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);
}
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, "
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);
#include <babeltrace/types.h>
#include <babeltrace/values.h>
#include <babeltrace/values-internal.h>
+#include <babeltrace/assert-internal.h>
+#include <babeltrace/assert-pre-internal.h>
#include <unistd.h>
#include <glib.h>
{
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.");
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),
"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.");
}
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:
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.");
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)
struct bt_graph_listener, i);
bt_graph_port_added_listener func = listener.func;
- assert(func);
+ BT_ASSERT(func);
func(port, listener.data);
}
}
struct bt_graph_listener, i);
bt_graph_port_removed_listener func = listener.func;
- assert(func);
+ BT_ASSERT(func);
func(comp, port, listener.data);
}
}
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);
}
}
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);
}
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);
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);
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)) {
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)) {
#include <babeltrace/graph/port.h>
#include <babeltrace/graph/graph-internal.h>
#include <babeltrace/types.h>
+#include <babeltrace/assert-internal.h>
#include <stdint.h>
#include <inttypes.h>
#include <stdlib.h>
static
void destroy_action(struct action *action)
{
- assert(action);
+ BT_ASSERT(action);
switch (action->type) {
case ACTION_TYPE_PUSH_NOTIF:
{
struct bt_notification_iterator_private_connection *iterator;
- assert(obj);
+ BT_ASSERT(obj);
/*
* The notification iterator's reference count is 0 if we're
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(
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:
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 */
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);
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;
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\", "
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) {
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);
.type = ACTION_TYPE_PUSH_NOTIF,
};
- assert(notif);
+ BT_ASSERT(notif);
if (!is_subscribed_to_notification_type(iterator, notif->type)) {
return;
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.");
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.");
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.");
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.");
},
};
- 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);
},
};
- 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",
},
};
- 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) {
}
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: "
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: "
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: "
}
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: "
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) {
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) {
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) {
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) {
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) {
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) {
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);
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 */
if (notif_packet) {
notif_stream = bt_packet_borrow_stream(notif_packet);
- assert(notif_stream);
+ BT_ASSERT(notif_stream);
}
if (!notif_stream) {
&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;
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,
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) {
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;
}
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;
}
* 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.");
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;
* 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);
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 */
}
graph = bt_component_get_graph(output_port_comp);
- assert(graph);
+ BT_ASSERT(graph);
/* Create notification iterator */
BT_LOGD("Creating notification iterator on output port: "
*/
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) {
*/
ret = bt_graph_remove_unconnected_component(iterator->graph,
colander_comp);
- assert(ret == 0);
+ BT_ASSERT(ret == 0);
}
BT_PUT(iterator);
#include <babeltrace/graph/clock-class-priority-map-internal.h>
#include <babeltrace/graph/notification-internal.h>
#include <babeltrace/graph/notification-discarded-elements-internal.h>
+#include <babeltrace/assert-pre-internal.h>
#include <stdint.h>
#include <inttypes.h>
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, "
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
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
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
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);
}
#include <babeltrace/graph/clock-class-priority-map-internal.h>
#include <babeltrace/graph/notification-event-internal.h>
#include <babeltrace/types.h>
+#include <babeltrace/assert-internal.h>
+#include <babeltrace/assert-pre-internal.h>
#include <stdbool.h>
#include <inttypes.h>
g_free(notification);
}
-static
+BT_ASSERT_PRE_FUNC static inline
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++) {
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 ", "
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) {
}
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\"",
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;
}
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 */
}
}
- 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 ", "
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.");
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.");
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);
}
* SOFTWARE.
*/
-#include <assert.h>
#include <stddef.h>
#include <babeltrace/compiler-internal.h>
#include <babeltrace/graph/notification-heap-internal.h>
+#include <babeltrace/assert-internal.h>
#ifdef DEBUG_HEAP
static
}
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));
}
#include <babeltrace/object-internal.h>
#include <babeltrace/compiler-internal.h>
#include <babeltrace/ctf-ir/clock-class.h>
+#include <babeltrace/ctf-ir/clock-value-internal.h>
#include <babeltrace/graph/clock-class-priority-map.h>
#include <babeltrace/graph/clock-class-priority-map-internal.h>
#include <babeltrace/graph/notification-internal.h>
#include <babeltrace/graph/notification-inactivity-internal.h>
+#include <babeltrace/assert-pre-internal.h>
static
void bt_notification_inactivity_destroy(struct bt_object *obj)
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;
}
* SOFTWARE.
*/
+#define BT_LOG_TAG "NOTIF"
+#include <babeltrace/lib-logging-internal.h>
+
#include <babeltrace/graph/notification-internal.h>
+#include <babeltrace/assert-internal.h>
+#include <babeltrace/assert-pre-internal.h>
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);
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;
}
#include <babeltrace/ctf-ir/stream.h>
#include <babeltrace/ctf-ir/stream-internal.h>
#include <babeltrace/graph/notification-packet-internal.h>
+#include <babeltrace/assert-internal.h>
+#include <babeltrace/assert-pre-internal.h>
#include <inttypes.h>
static
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\", "
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(
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\", "
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);
}
#include <babeltrace/ctf-ir/stream-internal.h>
#include <babeltrace/ctf-ir/stream-class.h>
#include <babeltrace/graph/notification-stream-internal.h>
+#include <babeltrace/assert-internal.h>
+#include <babeltrace/assert-pre-internal.h>
#include <inttypes.h>
static
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\", "
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
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\", "
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);
}
#include <babeltrace/graph/connection-internal.h>
#include <babeltrace/object-internal.h>
#include <babeltrace/compiler-internal.h>
+#include <babeltrace/assert-internal.h>
static
void bt_port_destroy(struct bt_object *obj)
{
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.");
/* 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;
#include <babeltrace/graph/component-internal.h>
#include <babeltrace/graph/notification.h>
#include <babeltrace/graph/graph.h>
+#include <babeltrace/assert-internal.h>
+#include <babeltrace/assert-internal.h>
BT_HIDDEN
void bt_component_sink_destroy(struct bt_component *component)
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));
BT_LOGW_STR("Consume method failed.");
}
-end:
return ret;
}
#include <string.h>
#include <inttypes.h>
#include <stdint.h>
-#include <assert.h>
#include <wchar.h>
#include <glib.h>
#include <babeltrace/common-internal.h>
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; \
{
struct bt_field_string *str = (void *) field;
- assert(str->payload);
+ BT_ASSERT(str->payload);
BUF_APPEND(", %spartial-value=\"%.32s\"",
PRFIELD(str->payload->str));
break;
{
uint64_t i;
- assert(field_path->indexes);
+ BT_ASSERT(field_path->indexes);
BUF_APPEND(", %sindex-count=%u", PRFIELD(field_path->indexes->len));
if (!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;
}
{
int64_t count = bt_value_array_size(value);
- assert(count >= 0);
+ BT_ASSERT(count >= 0);
BUF_APPEND(", %selement-count=%" PRId64, PRFIELD(count));
break;
}
{
int64_t count = bt_value_map_size(value);
- assert(count >= 0);
+ BT_ASSERT(count >= 0);
BUF_APPEND(", %selement-count=%" PRId64, PRFIELD(count));
break;
}
{
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);
#include <babeltrace/graph/component-class-internal.h>
#include <babeltrace/types.h>
#include <babeltrace/list-internal.h>
+#include <babeltrace/assert-internal.h>
#include <string.h>
#include <stdlib.h>
#include <glib.h>
{
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 ?
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;
{
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);
#include <babeltrace/graph/component-class.h>
#include <babeltrace/graph/component-class-internal.h>
#include <babeltrace/types.h>
+#include <babeltrace/assert-internal.h>
#include <glib.h>
#include <unistd.h>
#include <stdlib.h>
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) {
#include <babeltrace/prio-heap-internal.h>
#include <babeltrace/babeltrace-internal.h>
+#include <babeltrace/assert-internal.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
-#include <assert.h>
#ifdef DEBUG_HEAP
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
#include <stdlib.h>
#include <string.h>
-#include <assert.h>
#include <string.h>
#include <inttypes.h>
#include <babeltrace/compiler-internal.h>
#include <babeltrace/types.h>
#include <babeltrace/object-internal.h>
#include <babeltrace/values-internal.h>
+#include <babeltrace/assert-internal.h>
+#include <babeltrace/assert-pre-internal.h>
#define BT_VALUE_FROM_CONCRETE(_concrete) ((struct bt_value *) (_concrete))
#define BT_VALUE_TO_BOOL(_base) ((struct bt_value_bool *) (_base))
#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
.parent = NULL,
},
.type = BT_VALUE_TYPE_NULL,
- .is_frozen = BT_TRUE,
+ .frozen = BT_TRUE,
};
struct bt_value *bt_value_null = &bt_value_null_instance;
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;
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);
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;
}
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);
[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;
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;
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)) {
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;
}
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;
}
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;
}
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;
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;
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;
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;
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);
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;
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);
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;
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);
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)
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,
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)
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,
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;
}
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);
{
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) {
BT_LOGE_STR("Failed to copy value object.");
}
-end:
return copy_obj;
}
{
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: "
#undef __STRICT_ANSI__
#endif
#endif
-#include <assert.h>
+#include <babeltrace/assert-internal.h>
#include <ctype.h>
#include <string.h>
#include <time.h>
#include <stdio.h>
#include <stddef.h>
#include <stdbool.h>
-#include <assert.h>
+#include <babeltrace/assert-internal.h>
#include <string.h>
#include <babeltrace/bitfield-internal.h>
#include <babeltrace/babeltrace.h>
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, "
static inline
unsigned int stack_size(struct stack *stack)
{
- assert(stack);
+ BT_ASSERT(stack);
return stack->entries->len;
}
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);
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);
}
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;
}
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;
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;
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: "
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) {
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);
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) {
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);
{
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:
{
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:
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;
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;
#include <stdint.h>
#include <stdlib.h>
#include <inttypes.h>
-#include <assert.h>
+#include <babeltrace/assert-internal.h>
#include <babeltrace/compat/uuid-internal.h>
#include <babeltrace/compat/memstream-internal.h>
#include <babeltrace/babeltrace.h>
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);
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: "
#include <errno.h>
#include <inttypes.h>
#include <babeltrace/list-internal.h>
+#include <babeltrace/assert-internal.h>
#include "scanner.h"
#include "parser.h"
#include "ast.h"
return -1;
}
}
- assert(nr_char > 0);
+ BT_ASSERT(nr_char > 0);
buffer[nr_char] = '\0';
*buf_len = nr_char;
return 0;
#include <stdbool.h>
#include <stdlib.h>
#include <ctype.h>
-#include <assert.h>
+#include <babeltrace/assert-internal.h>
#include <glib.h>
#include <inttypes.h>
#include <errno.h>
{
GQuark qname = 0;
- assert(name);
+ BT_ASSERT(name);
/* Prefix character + original string + '\0' */
char *prname = g_new(char, strlen(name) + 2);
_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;
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;
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) {
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.");
{
struct ctx_decl_scope *parent_scope = NULL;
- assert(ctx);
+ BT_ASSERT(ctx);
if (!ctx->current_scope) {
goto end;
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",
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;
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);
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.
&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;
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 */
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 */
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;
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;
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: "
ret = visit_integer_decl(ctx, &node->u.integer.expressions,
decl);
if (ret) {
- assert(!*decl);
+ BT_ASSERT(!*decl);
goto error;
}
break;
ret = visit_floating_point_number_decl(ctx,
&node->u.floating_point.expressions, decl);
if (ret) {
- assert(!*decl);
+ BT_ASSERT(!*decl);
goto error;
}
break;
ret = visit_string_decl(ctx,
&node->u.string.expressions, decl);
if (ret) {
- assert(!*decl);
+ BT_ASSERT(!*decl);
goto error;
}
break;
node->u._struct.has_body,
&node->u._struct.min_align, decl);
if (ret) {
- assert(!*decl);
+ BT_ASSERT(!*decl);
goto error;
}
break;
&node->u.variant.declaration_list,
node->u.variant.has_body, decl);
if (ret) {
- assert(!*decl);
+ BT_ASSERT(!*decl);
goto error;
}
break;
&node->u._enum.enumerator_list,
node->u._enum.has_body, decl);
if (ret) {
- assert(!*decl);
+ BT_ASSERT(!*decl);
goto error;
}
break;
_BT_LOGE_NODE(first,
"Cannot visit type specifier: ret=%d",
ret);
- assert(!*decl);
+ BT_ASSERT(!*decl);
goto error;
}
break;
goto error;
}
- assert(*decl);
+ BT_ASSERT(*decl);
return 0;
goto error;
}
- assert(decl);
+ BT_ASSERT(decl);
ret = bt_event_class_set_context_type(
event_class, decl);
BT_PUT(decl);
goto error;
}
- assert(decl);
+ BT_ASSERT(decl);
ret = bt_event_class_set_payload_type(
event_class, decl);
BT_PUT(decl);
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);
}
}
- 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);
}
}
- assert(stream_class);
+ BT_ASSERT(stream_class);
if (!_IS_SET(&set, _EVENT_ID_SET)) {
/* Allow only one event without ID per stream */
}
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:
*/
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:
/*
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) {
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);
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);
goto error;
}
- assert(decl);
+ BT_ASSERT(decl);
ret = auto_map_fields_to_trace_clock_class(ctx,
decl, "timestamp");
if (ret) {
goto error;
}
- assert(decl);
+ BT_ASSERT(decl);
ret = bt_stream_class_set_event_context_type(
stream_class, decl);
goto error;
}
- assert(decl);
+ BT_ASSERT(decl);
ret = auto_map_fields_to_trace_clock_class(ctx,
decl, "timestamp_begin");
if (ret) {
/* 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);
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);
}
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
_BT_LOGE_NODE(root_decl_node,
"Cannot visit root scope's field type: "
"ret=%d", ret);
- assert(!decl);
+ BT_ASSERT(!decl);
goto end;
}
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.");
*/
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) {
{
struct ctx *ctx = (void *) visitor;
- assert(ctx);
- assert(ctx->trace);
+ BT_ASSERT(ctx);
+ BT_ASSERT(ctx->trace);
return bt_get(ctx->trace);
}
}
}
- 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 */
}
}
- assert(ctx->current_scope &&
+ BT_ASSERT(ctx->current_scope &&
ctx->current_scope->parent_scope == NULL);
/*
}
}
- assert(ctx->current_scope &&
+ BT_ASSERT(ctx->current_scope &&
ctx->current_scope->parent_scope == NULL);
/*
}
}
- assert(ctx->current_scope &&
+ BT_ASSERT(ctx->current_scope &&
ctx->current_scope->parent_scope == NULL);
/* Callsite blocks are not supported */
"\"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 */
}
}
- assert(ctx->current_scope &&
+ BT_ASSERT(ctx->current_scope &&
ctx->current_scope->parent_scope == NULL);
/* Streams */
}
}
- assert(ctx->current_scope &&
+ BT_ASSERT(ctx->current_scope &&
ctx->current_scope->parent_scope == NULL);
/* Events */
}
}
- assert(ctx->current_scope &&
+ BT_ASSERT(ctx->current_scope &&
ctx->current_scope->parent_scope == NULL);
break;
}
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
-#include <assert.h>
+#include <babeltrace/assert-internal.h>
#include <glib.h>
#include <inttypes.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
-#include <assert.h>
+#include <babeltrace/assert-internal.h>
#include <glib.h>
#include <inttypes.h>
#include <errno.h>
#include <stdio.h>
#include <stddef.h>
#include <stdbool.h>
-#include <assert.h>
+#include <babeltrace/assert-internal.h>
#include <string.h>
#include <babeltrace/babeltrace.h>
#include <babeltrace/ctf-ir/field-types-internal.h>
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);
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);
static inline
unsigned int stack_size(struct stack *stack)
{
- assert(stack);
+ BT_ASSERT(stack);
return stack->entries->len;
}
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);
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);
}
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",
g_ptr_array_remove_range(stack->entries, 0, stack_size(stack));
}
- assert(stack_empty(stack));
+ BT_ASSERT(stack_empty(stack));
}
static inline
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);
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;
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;
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 =
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;
}
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) {
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",
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;
}
}
/* 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) {
/*
* _ _____ _____
// 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);
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);
}
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;
}
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;
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);
* 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;
}
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:
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
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)) {
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: "
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);
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: "
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);
}
ret = bt_field_floating_point_set_value(field, value);
- assert(!ret);
+ BT_ASSERT(!ret);
stack_top(notit->stack)->index++;
end:
/* 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);
}
/* Push field */
- assert(field);
+ BT_ASSERT(field);
ret = stack_push(notit->stack, field);
if (ret) {
BT_LOGE("Cannot push compound field onto the stack: "
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);
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(
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: "
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: "
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\", "
}
/* 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: "
}
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;
},
};
- 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",
{
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);
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);
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 */
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;
}
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;
off_t bt_notif_iter_get_current_packet_offset(
struct bt_notif_iter *notit)
{
- assert(notit);
+ BT_ASSERT(notit);
return notit->cur_packet_offset;
}
off_t bt_notif_iter_get_current_packet_size(
struct bt_notif_iter *notit)
{
- assert(notit);
+ BT_ASSERT(notit);
return notit->cur_packet_size;
}
#include "logging.h"
#include <babeltrace/babeltrace.h>
-#include <assert.h>
+#include <babeltrace/assert-internal.h>
#include <glib.h>
#include <ctfcopytrace.h>
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);
}
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) {
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);
} 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;
}
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);
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);
{
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);
}
{
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);
}
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);
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) {
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) {
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) {
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) {
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)) {
}
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)) {
}
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);
#include <stdbool.h>
#include <glib.h>
#include "writer.h"
-#include <assert.h>
+#include <babeltrace/assert-internal.h>
static
gboolean empty_trace_map(gpointer key, gpointer value, gpointer user_data)
};
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) {
}
it = writer_component->input_iterator;
- assert(it);
+ BT_ASSERT(it);
it_ret = bt_notification_iterator_next(it);
switch (it_ret) {
}
notification = bt_notification_iterator_get_notification(it);
- assert(notification);
+ BT_ASSERT(notification);
ret = handle_notification(writer_component, notification);
end:
bt_put(notification);
#include "file.h"
#include "metadata.h"
#include "../common/notif-iter/notif-iter.h"
-#include <assert.h>
+#include <babeltrace/assert-internal.h>
#include "data-stream-file.h"
#include <string.h>
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);
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;
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,
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) {
#include <babeltrace/babeltrace.h>
#include <plugins-common.h>
#include <glib.h>
-#include <assert.h>
+#include <babeltrace/assert-internal.h>
#include <inttypes.h>
#include <stdbool.h>
#include "fs.h"
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,
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 ==
* 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:
* 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);
}
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) {
}
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;
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++) {
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;
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);
}
*trace_paths = g_list_prepend(*trace_paths, norm_path);
- assert(*trace_paths);
+ BT_ASSERT(*trace_paths);
norm_path = NULL;
end:
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;
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);
}
}
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
*/
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) {
}
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);
}
}
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);
}
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);
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
-#include <assert.h>
+#include <babeltrace/assert-internal.h>
#include <glib.h>
#include <babeltrace/compat/uuid-internal.h>
#include <babeltrace/compat/memstream-internal.h>
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);
#include "query.h"
#include <stdbool.h>
-#include <assert.h>
+#include <babeltrace/assert-internal.h>
#include "metadata.h"
#include "../common/metadata/decoder.h"
#include <babeltrace/common-internal.h>
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;
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);
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;
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;
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) {
#include <babeltrace/compat/mman-internal.h>
#include <babeltrace/babeltrace.h>
#include "../common/notif-iter/notif-iter.h"
-#include <assert.h>
+#include <babeltrace/assert-internal.h>
#include "data-stream.h"
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);
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);
#include <babeltrace/types.h>
#include <inttypes.h>
#include <glib.h>
-#include <assert.h>
+#include <babeltrace/assert-internal.h>
#include <unistd.h>
#include <plugins-common.h>
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;
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;
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);
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 ==
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) {
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:
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:
{
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);
}
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);
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;
}
*/
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) {
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));
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) {
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++) {
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,
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) {
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++) {
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);
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) {
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");
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);
*/
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");
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)) {
*/
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");
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:
*/
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");
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:
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);
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:
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);
*/
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");
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);
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;
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;
*/
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");
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;
*/
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");
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);
#include "logging.h"
#include <babeltrace/babeltrace.h>
-#include <assert.h>
+#include <babeltrace/assert-internal.h>
#include <stdio.h>
#include "clock-fields.h"
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);
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);
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);
/* 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) {
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:
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);
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) {
}
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);
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) {
}
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);
}
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);
}
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);
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);
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);
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);
}
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);
#include "logging.h"
#include <babeltrace/babeltrace.h>
-#include <assert.h>
+#include <babeltrace/assert-internal.h>
#include "ctfcopytrace.h"
#include "clock-fields.h"
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));
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;
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);
{
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:
}
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;
abort();
}
- assert(subtype);
+ BT_ASSERT(subtype);
replace_clock_classes(trace_copy, subtype);
bt_put(subtype);
break;
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);
}
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);
}
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) {
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(
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) {
}
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;
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);
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;
* 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);
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);
}
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
#include "logging.h"
#include <inttypes.h>
-#include <assert.h>
+#include <babeltrace/assert-internal.h>
#include <babeltrace/babeltrace.h>
#include <ctfcopytrace.h>
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\"",
}
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\"",
}
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_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);
}
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_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);
}
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\"",
}
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);
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) {
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) {
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) {
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);
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) {
}
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) {
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);
} 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;
}
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));
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) {
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,
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);
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) {
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) {
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) {
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++) {
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
!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);
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. */
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;
}
field = bt_event_get_event_payload(event);
- assert(field);
+ BT_ASSERT(field);
copy_field = bt_field_copy(field);
if (copy_field) {
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) {
}
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) {
}
packet = bt_event_get_packet(event);
- assert(packet);
+ BT_ASSERT(packet);
writer_packet = lookup_packet(debug_it, packet, di_trace);
if (!writer_packet) {
#define BT_LOG_TAG "PLUGIN-CTF-LTTNG-UTILS-DEBUG-INFO-FLT"
#include "logging.h"
-#include <assert.h>
+#include <babeltrace/assert-internal.h>
#include <glib.h>
#include "debug-info.h"
#include "bin-info.h"
#include <babeltrace/babeltrace.h>
#include <plugins-common.h>
-#include <assert.h>
+#include <babeltrace/assert-internal.h>
#include "debug-info.h"
#include "copy.h"
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);
}
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;
}
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;
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;
}
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;
}
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;
};
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;
ret.notification = handle_notification(debug_info->err, debug_it,
notification);
- assert(ret.notification);
+ BT_ASSERT(ret.notification);
bt_put(notification);
end:
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) {
#include <string.h>
#include <ctype.h>
#include <stdio.h>
-#include <assert.h>
+#include <babeltrace/assert-internal.h>
#include <babeltrace/babeltrace.h>
#include <babeltrace/values-internal.h>
#include <babeltrace/compat/utc-internal.h>
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) {
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");
}
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;
}
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.");
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.");
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) {
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] == ' ') {
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.");
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.");
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.");
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) {
.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;
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++) {
#include <stdio.h>
#include <stdbool.h>
#include <glib.h>
-#include <assert.h>
+#include <babeltrace/assert-internal.h>
#include "pretty.h"
{
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:
};
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) {
}
notification = bt_notification_iterator_get_notification(it);
- assert(notification);
+ BT_ASSERT(notification);
ret = handle_notification(pretty, notification);
end:
#include <babeltrace/bitfield-internal.h>
#include <babeltrace/common-internal.h>
#include <babeltrace/compat/time-internal.h>
+#include <babeltrace/assert-internal.h>
#include <inttypes.h>
#include <ctype.h>
#include "pretty.h"
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];
}
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;
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);
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 */
/* 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)";
#include <babeltrace/babeltrace-internal.h>
#include <babeltrace/common-internal.h>
#include <plugins-common.h>
-#include <assert.h>
+#include <babeltrace/assert-internal.h>
#include <inttypes.h>
#include <stdint.h>
{
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);
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;
}
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;
}
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) {
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;
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++;
#include <babeltrace/babeltrace.h>
#include <babeltrace/babeltrace-internal.h>
#include <plugins-common.h>
-#include <assert.h>
+#include <babeltrace/assert-internal.h>
#include "dummy.h"
void destroy_private_dummy_data(struct dummy *dummy)
{
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);
}
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) {
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;
#include <glib.h>
#include <stdbool.h>
#include <inttypes.h>
-#include <assert.h>
+#include <babeltrace/assert-internal.h>
#include <stdlib.h>
#include <string.h>
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;
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,
}
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",
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: "
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;
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
priv_port = node->data;
port = bt_port_from_private(priv_port);
- assert(port);
+ BT_ASSERT(port);
if (!bt_port_is_connected(port)) {
/*
&ret);
if (ret) {
/* create_notif_iter_on_input_port() logs errors */
- assert(!upstream_notif_iter);
+ BT_ASSERT(!upstream_notif_iter);
goto error;
}
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, "
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;
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++) {
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);
}
}
- 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
"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
* 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: "
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: "
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);
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",
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:
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, "
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, "
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\", "
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,
#define BT_LOG_TAG "PLUGIN-UTILS-TRIMMER-FLT-COPY"
#include "logging.h"
-#include <assert.h>
+#include <babeltrace/assert-internal.h>
#include <babeltrace/babeltrace.h>
#include <ctfcopytrace.h>
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++) {
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);
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
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);
}
packet = bt_event_get_packet(event);
- assert(packet);
+ BT_ASSERT(packet);
writer_packet = lookup_packet(trim_it, packet);
if (!writer_packet) {
#include <babeltrace/compat/time-internal.h>
#include <babeltrace/compat/utc-internal.h>
#include <babeltrace/babeltrace.h>
-#include <assert.h>
+#include <babeltrace/assert-internal.h>
#include <plugins-common.h>
#include "trimmer.h"
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,
/* 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);
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);
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) {
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);
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;
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;
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);
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);
#include <plugins-common.h>
#include "trimmer.h"
#include "iterator.h"
-#include <assert.h>
+#include <babeltrace/assert-internal.h>
static
void destroy_trimmer_data(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) {
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: "
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);
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);
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);
gchar *basename = NULL;
size_t path_len;
- assert(path);
+ BT_ASSERT(path);
if (python_state == PYTHON_STATE_CANNOT_INITIALIZE) {
/*
#include <string.h>
#include "tap/tap.h"
-#define NR_TESTS 249
+#define NR_TESTS 158
static
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
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");
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);
}
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");
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);
}
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.,
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);
}
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 \"\"");
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");
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);
}
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);
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)");
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),
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");
"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")
}
"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);
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)");
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");
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));
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")
}
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");
}
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();
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");
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,
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;
}
#include "tap/tap.h"
-#define NR_TESTS 21
+#define NR_TESTS 17
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);
#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];
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,
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");
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");
"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");
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");
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 =
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);
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)");
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(
/* 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");
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");
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);
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");
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;
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,
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");
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);
"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++) {
}
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");
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");
* 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);
*/
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
*/
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);
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);
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");
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);