From 601b0d3c9a6bf91274d0f01ccdec7fecfe3ed310 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Mon, 19 Nov 2018 14:50:47 -0500 Subject: [PATCH] Values API: standardize parameters and return values Changes: * Remove `BT_VALUE_STATUS_ERROR`: the only possible error in this API is `BT_VALUE_STATUS_NOMEM`. * `BT_VALUE_STATUS_CANCELED` is not considered an error: the loop did not finish, but it was explicitly canceled by the user. * bt_value_copy(): return by parameter (first one, like strcpy()), and return status. * bt_value_bool_get(), bt_value_integer_get(), bt_value_real_get(), and bt_value_string_get(): return value directly. Those functions cannot fail. * bt_value_array_get_size() and bt_value_map_get_size(): return `uint64_t`. * bt_value_array_is_empty() and bt_value_map_is_empty(): make them `static inline`. * bt_value_map_extend(): return by parameter (like bt_value_copy()), and return status. * bt_private_value_bool_set(), bt_private_value_integer_set(), and bt_private_value_real_set(): return `void`. Those functions cannot fail. Signed-off-by: Philippe Proulx --- cli/babeltrace-cfg-cli-args-connect.c | 3 +- cli/babeltrace-cfg-cli-args.c | 35 ++--- cli/babeltrace-cfg.c | 18 +-- cli/babeltrace-cfg.h | 4 +- cli/babeltrace.c | 75 ++-------- include/babeltrace/private-values.h | 32 +++-- include/babeltrace/values.h | 42 +++--- lib/ctf-writer/attributes.c | 21 +-- lib/ctf-writer/trace.c | 12 +- lib/lib-logging.c | 12 +- lib/trace-ir/attributes.c | 21 +-- lib/values.c | 160 +++++++++++---------- plugins/ctf/fs-sink/writer.c | 6 +- plugins/ctf/fs-src/fs.c | 12 +- plugins/ctf/fs-src/query.c | 14 +- plugins/ctf/lttng-live/lttng-live.c | 6 +- plugins/ctf/lttng-live/viewer-connection.c | 20 +-- plugins/lttng-utils/copy.c | 6 +- plugins/lttng-utils/plugin.c | 31 +--- plugins/text/dmesg/dmesg.c | 8 +- plugins/text/pretty/pretty.c | 42 ++---- plugins/text/pretty/print.c | 27 ++-- plugins/utils/counter/counter.c | 5 +- plugins/utils/muxer/muxer.c | 7 +- plugins/utils/trimmer/trimmer.c | 6 +- tests/lib/test_bt_values.c | 141 +++++++++--------- tests/lib/test_ctf_writer.c | 16 +-- tests/lib/test_plugin.c | 4 +- 28 files changed, 301 insertions(+), 485 deletions(-) diff --git a/cli/babeltrace-cfg-cli-args-connect.c b/cli/babeltrace-cfg-cli-args-connect.c index b693455c..a1c72ab2 100644 --- a/cli/babeltrace-cfg-cli-args-connect.c +++ b/cli/babeltrace-cfg-cli-args-connect.c @@ -700,8 +700,7 @@ int bt_config_cli_args_create_connections(struct bt_config *cfg, const char *arg; struct bt_config_connection *cfg_connection; - ret = bt_value_string_get(arg_value, &arg); - BT_ASSERT(ret == 0); + arg = bt_value_string_get(arg_value); cfg_connection = cfg_connection_from_arg(arg); if (!cfg_connection) { snprintf(error_buf, error_buf_size, "Cannot parse --connect option's argument:\n %s\n", diff --git a/cli/babeltrace-cfg-cli-args.c b/cli/babeltrace-cfg-cli-args.c index b844b4e4..b50e0a15 100644 --- a/cli/babeltrace-cfg-cli-args.c +++ b/cli/babeltrace-cfg-cli-args.c @@ -1265,11 +1265,7 @@ int insert_flat_params_from_array(GString *params_arg, goto end; } - ret = bt_value_string_get(str_obj, &suffix); - if (ret) { - printf_err("Unexpected error\n"); - goto end; - } + suffix = bt_value_string_get(str_obj); g_string_assign(tmpstr, prefix); g_string_append(tmpstr, "-"); @@ -2397,6 +2393,7 @@ struct bt_config *bt_config_run_from_args(int argc, const char *argv[], GString *cur_param_key = NULL; char error_buf[256] = { 0 }; long retry_duration = -1; + enum bt_value_status status; struct poptOption run_long_options[] = { { "base-params", 'b', POPT_ARG_STRING, NULL, OPT_BASE_PARAMS, NULL, NULL }, { "component", 'c', POPT_ARG_STRING, NULL, OPT_COMPONENT, NULL, NULL }, @@ -2521,9 +2518,10 @@ struct bt_config *bt_config_run_from_args(int argc, const char *argv[], BT_ASSERT(cur_base_params); bt_object_put_ref(cur_cfg_comp->params); - cur_cfg_comp->params = bt_value_copy( + status = bt_value_copy( + &cur_cfg_comp->params, bt_value_borrow_from_private(cur_base_params)); - if (!cur_cfg_comp->params) { + if (status != BT_VALUE_STATUS_OK) { print_err_oom(); goto error; } @@ -2549,11 +2547,11 @@ struct bt_config *bt_config_run_from_args(int argc, const char *argv[], goto error; } - params_to_set = bt_value_map_extend( + status = bt_value_map_extend(¶ms_to_set, bt_value_borrow_from_private(cur_cfg_comp->params), bt_value_borrow_from_private(params)); BT_OBJECT_PUT_REF_AND_RESET(params); - if (!params_to_set) { + if (status != BT_VALUE_STATUS_OK) { printf_err("Cannot extend current component parameters with --params option's argument:\n %s\n", arg); goto error; @@ -2745,14 +2743,12 @@ struct bt_config *bt_config_run_from_args_array(struct bt_value *run_args, goto end; } for (i = 0; i < len; i++) { - int ret; struct bt_value *arg_value = bt_value_array_borrow_element_by_index(run_args, i); const char *arg; BT_ASSERT(arg_value); - ret = bt_value_string_get(arg_value, &arg); - BT_ASSERT(ret == 0); + arg = bt_value_string_get(arg_value); BT_ASSERT(arg); argv[i + 1] = arg; } @@ -3079,10 +3075,7 @@ int append_run_args_for_implicit_component( } BT_ASSERT(bt_value_is_string(elem)); - if (bt_value_string_get(elem, &arg)) { - goto error; - } - + arg = bt_value_string_get(elem); ret = bt_private_value_array_append_string_element(run_args, arg); if (ret) { print_err_oom(); @@ -3543,6 +3536,7 @@ int fill_implicit_ctf_inputs_args(GPtrArray *implicit_ctf_inputs_args, { int ret = 0; GList *leftover; + enum bt_value_status status; for (leftover = leftovers; leftover != NULL; leftover = g_list_next(leftover)) { @@ -3566,10 +3560,10 @@ int fill_implicit_ctf_inputs_args(GPtrArray *implicit_ctf_inputs_args, * this is where the unique path goes. */ BT_OBJECT_PUT_REF_AND_RESET(impl_args->extra_params); - impl_args->extra_params = - bt_value_copy(bt_value_borrow_from_private( + status = bt_value_copy(&impl_args->extra_params, + bt_value_borrow_from_private( base_implicit_ctf_input_args->extra_params)); - if (!impl_args->extra_params) { + if (status != BT_VALUE_STATUS_OK) { print_err_oom(); destroy_implicit_component_args(impl_args); goto error; @@ -4706,8 +4700,7 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[], const char *arg_to_print; BT_ASSERT(arg_value); - ret = bt_value_string_get(arg_value, &arg); - BT_ASSERT(ret == 0); + arg = bt_value_string_get(arg_value); if (print_run_args) { quoted = bt_common_shell_quote(arg, true); diff --git a/cli/babeltrace-cfg.c b/cli/babeltrace-cfg.c index ef8c12b7..d96fd5ce 100644 --- a/cli/babeltrace-cfg.c +++ b/cli/babeltrace-cfg.c @@ -38,38 +38,38 @@ void destroy_gstring(void *data) * Extracts the various paths from the string arg, delimited by ':', * and appends them to the array value object plugin_paths. */ -enum bt_value_status bt_config_append_plugin_paths( +int bt_config_append_plugin_paths( struct bt_private_value *plugin_paths, const char *arg) { - enum bt_value_status status = BT_VALUE_STATUS_OK; + int ret = 0; GPtrArray *dirs = g_ptr_array_new_with_free_func(destroy_gstring); - int ret; size_t i; if (!dirs) { - status = BT_VALUE_STATUS_ERROR; + ret = -1; goto end; } ret = bt_common_append_plugin_path_dirs(arg, dirs); if (ret) { - status = BT_VALUE_STATUS_ERROR; + ret = -1; goto end; } for (i = 0; i < dirs->len; i++) { GString *dir = g_ptr_array_index(dirs, i); - status = bt_private_value_array_append_string_element( + ret = bt_private_value_array_append_string_element( plugin_paths, dir->str); - if (status != BT_VALUE_STATUS_OK) { - break; + if (ret != BT_VALUE_STATUS_OK) { + ret = -1; + goto end; } } end: g_ptr_array_free(dirs, TRUE); - return status; + return ret; } void bt_config_connection_destroy(struct bt_config_connection *connection) diff --git a/cli/babeltrace-cfg.h b/cli/babeltrace-cfg.h index d5559cae..b63c6c5c 100644 --- a/cli/babeltrace-cfg.h +++ b/cli/babeltrace-cfg.h @@ -132,8 +132,8 @@ struct bt_config_component *bt_config_get_component(GPtrArray *array, return bt_object_get_ref(g_ptr_array_index(array, index)); } -enum bt_value_status bt_config_append_plugin_paths( - struct bt_private_value *plugin_paths, const char *arg); +int bt_config_append_plugin_paths(struct bt_private_value *plugin_paths, + const char *arg); void bt_config_connection_destroy(struct bt_config_connection *connection); diff --git a/cli/babeltrace.c b/cli/babeltrace.c index 8e17c2a1..efc883e2 100644 --- a/cli/babeltrace.c +++ b/cli/babeltrace.c @@ -438,7 +438,6 @@ void print_value_rec(FILE *fp, struct bt_value *value, size_t indent) const char *str_val; int size; int i; - enum bt_value_status status; if (!value) { return; @@ -450,37 +449,25 @@ void print_value_rec(FILE *fp, struct bt_value *value, size_t indent) bt_common_color_reset()); break; case BT_VALUE_TYPE_BOOL: - status = bt_value_bool_get(value, &bool_val); - if (status != BT_VALUE_STATUS_OK) { - goto error; - } + bool_val = bt_value_bool_get(value); fprintf(fp, "%s%s%s%s\n", bt_common_color_bold(), bt_common_color_fg_cyan(), bool_val ? "yes" : "no", bt_common_color_reset()); break; case BT_VALUE_TYPE_INTEGER: - status = bt_value_integer_get(value, &int_val); - if (status != BT_VALUE_STATUS_OK) { - goto error; - } + int_val = bt_value_integer_get(value); fprintf(fp, "%s%s%" PRId64 "%s\n", bt_common_color_bold(), bt_common_color_fg_red(), int_val, bt_common_color_reset()); break; case BT_VALUE_TYPE_REAL: - status = bt_value_real_get(value, &dbl_val); - if (status != BT_VALUE_STATUS_OK) { - goto error; - } + dbl_val = bt_value_real_get(value); fprintf(fp, "%s%s%lf%s\n", bt_common_color_bold(), bt_common_color_fg_red(), dbl_val, bt_common_color_reset()); break; case BT_VALUE_TYPE_STRING: - status = bt_value_string_get(value, &str_val); - if (status != BT_VALUE_STATUS_OK) { - goto error; - } + str_val = bt_value_string_get(value); fprintf(fp, "%s%s%s%s\n", bt_common_color_bold(), bt_common_color_fg_green(), str_val, bt_common_color_reset()); @@ -762,15 +749,10 @@ int load_dynamic_plugins(struct bt_value *plugin_paths) struct bt_value *plugin_path_value = NULL; const char *plugin_path; struct bt_plugin_set *plugin_set; - enum bt_value_status status; plugin_path_value = bt_value_array_borrow_element_by_index( plugin_paths, i); - status = bt_value_string_get(plugin_path_value, &plugin_path); - if (status != BT_VALUE_STATUS_OK) { - BT_LOGD_STR("Cannot get plugin path string."); - continue; - } + plugin_path = bt_value_string_get(plugin_path_value); /* * Skip this if the directory does not exist because @@ -1235,32 +1217,28 @@ int cmd_print_lttng_live_sessions(struct bt_config *cfg) BT_LOGE_STR("Unexpected empty array \"url\" entry."); goto error; } - ret = bt_value_string_get(v, &url_text); - BT_ASSERT(ret == 0); + url_text = bt_value_string_get(v); fprintf(out_stream, "%s", url_text); v = bt_value_map_borrow_entry_value(map, "timer-us"); if (!v) { BT_LOGE_STR("Unexpected empty array \"timer-us\" entry."); goto error; } - ret = bt_value_integer_get(v, &timer_us); - BT_ASSERT(ret == 0); + timer_us = bt_value_integer_get(v); fprintf(out_stream, " (timer = %" PRIu64 ", ", timer_us); v = bt_value_map_borrow_entry_value(map, "stream-count"); if (!v) { BT_LOGE_STR("Unexpected empty array \"stream-count\" entry."); goto error; } - ret = bt_value_integer_get(v, &streams); - BT_ASSERT(ret == 0); + streams = bt_value_integer_get(v); fprintf(out_stream, "%" PRIu64 " stream(s), ", streams); v = bt_value_map_borrow_entry_value(map, "client-count"); if (!v) { BT_LOGE_STR("Unexpected empty array \"client-count\" entry."); goto error; } - ret = bt_value_integer_get(v, &clients); - BT_ASSERT(ret == 0); + clients = bt_value_integer_get(v); fprintf(out_stream, "%" PRIu64 " client(s) connected)\n", clients); } @@ -1356,8 +1334,7 @@ int cmd_print_ctf_metadata(struct bt_config *cfg) goto end; } - ret = bt_value_string_get(metadata_text_value, &metadata_text); - BT_ASSERT(ret == 0); + metadata_text = bt_value_string_get(metadata_text_value); if (cfg->cmd_data.print_ctf_metadata.output_path->len > 0) { out_stream = @@ -2122,14 +2099,7 @@ int set_stream_intersections(struct cmd_run_ctx *ctx, goto error; } - value_status = bt_value_string_get(component_path_value, &path); - if (value_status != BT_VALUE_STATUS_OK) { - BT_LOGD("Cannot get path string value: component-name=%s", - cfg_comp->instance_name->str); - ret = -1; - goto error; - } - + path = bt_value_string_get(component_path_value); query_params = bt_private_value_map_create(); if (!query_params) { BT_LOGE_STR("Cannot create query parameters."); @@ -2209,19 +2179,8 @@ int set_stream_intersections(struct cmd_run_ctx *ctx, goto error; } - value_status = bt_value_integer_get(intersection_begin, &begin); - if (value_status != BT_VALUE_STATUS_OK) { - ret = -1; - BT_LOGD_STR("Cannot retrieve value of intersection-range-ns \'begin\' field from query result."); - goto error; - } - - value_status = bt_value_integer_get(intersection_end, &end); - if (value_status != BT_VALUE_STATUS_OK) { - ret = -1; - BT_LOGD_STR("Cannot retrieve value of intersection-range-ns \'end\' field from query result."); - goto error; - } + begin = bt_value_integer_get(intersection_begin); + end = bt_value_integer_get(intersection_end); if (begin < 0 || end < 0 || end < begin) { BT_LOGW("Invalid trace stream intersection values: " @@ -2309,13 +2268,7 @@ int set_stream_intersections(struct cmd_run_ctx *ctx, goto error; } - value_status = bt_value_string_get(stream_path_value, - &stream_path); - if (value_status != BT_VALUE_STATUS_OK) { - ret = -1; - goto error; - } - + stream_path = bt_value_string_get(stream_path_value); port_id->port_name = strdup(stream_path); if (!port_id->port_name) { ret = -1; diff --git a/include/babeltrace/private-values.h b/include/babeltrace/private-values.h index 1b7dce82..f94f27a0 100644 --- a/include/babeltrace/private-values.h +++ b/include/babeltrace/private-values.h @@ -47,28 +47,31 @@ extern struct bt_private_value *bt_private_value_bool_create(void); extern struct bt_private_value *bt_private_value_bool_create_init(bt_bool val); -extern enum bt_value_status bt_private_value_bool_set(struct bt_private_value *bool_obj, +extern void bt_private_value_bool_set(struct bt_private_value *bool_obj, bt_bool val); extern struct bt_private_value *bt_private_value_integer_create(void); -extern struct bt_private_value *bt_private_value_integer_create_init(int64_t val); +extern struct bt_private_value *bt_private_value_integer_create_init( + int64_t val); -extern enum bt_value_status bt_private_integer_bool_set( +extern void bt_private_value_integer_set( struct bt_private_value *integer_obj, int64_t val); extern struct bt_private_value *bt_private_value_real_create(void); extern struct bt_private_value *bt_private_value_real_create_init(double val); -extern enum bt_value_status bt_private_value_real_set( +extern void bt_private_value_real_set( struct bt_private_value *real_obj, double val); extern struct bt_private_value *bt_private_value_string_create(void); -extern struct bt_private_value *bt_private_value_string_create_init(const char *val); +extern struct bt_private_value *bt_private_value_string_create_init( + const char *val); -extern enum bt_value_status bt_private_value_string_set(struct bt_private_value *string_obj, +extern enum bt_value_status bt_private_value_string_set( + struct bt_private_value *string_obj, const char *val); extern struct bt_private_value *bt_private_value_array_create(void); @@ -77,16 +80,20 @@ extern struct bt_private_value *bt_private_value_array_borrow_element_by_index( const struct bt_private_value *array_obj, uint64_t index); extern enum bt_value_status bt_private_value_array_append_element( - struct bt_private_value *array_obj, struct bt_value *element_obj); + struct bt_private_value *array_obj, + struct bt_value *element_obj); extern enum bt_value_status bt_private_value_array_append_bool_element( - struct bt_private_value *array_obj, bt_bool val); + struct bt_private_value *array_obj, + bt_bool val); extern enum bt_value_status bt_private_value_array_append_integer_element( - struct bt_private_value *array_obj, int64_t val); + struct bt_private_value *array_obj, + int64_t val); extern enum bt_value_status bt_private_value_array_append_real_element( - struct bt_private_value *array_obj, double val); + struct bt_private_value *array_obj, + double val); extern enum bt_value_status bt_private_value_array_append_string_element( struct bt_private_value *array_obj, const char *val); @@ -107,7 +114,7 @@ extern struct bt_private_value *bt_private_value_map_borrow_entry_value( const struct bt_private_value *map_obj, const char *key); typedef bt_bool (* bt_private_value_map_foreach_entry_cb)(const char *key, - struct bt_private_value *object, void *data); + struct bt_private_value *object, void *data); extern enum bt_value_status bt_private_value_map_foreach_entry( const struct bt_private_value *map_obj, @@ -127,7 +134,8 @@ extern enum bt_value_status bt_private_value_map_insert_real_entry( struct bt_private_value *map_obj, const char *key, double val); extern enum bt_value_status bt_private_value_map_insert_string_entry( - struct bt_private_value *map_obj, const char *key, const char *val); + struct bt_private_value *map_obj, const char *key, + const char *val); extern enum bt_value_status bt_private_value_map_insert_empty_array_entry( struct bt_private_value *map_obj, const char *key); diff --git a/include/babeltrace/values.h b/include/babeltrace/values.h index 2f285cd5..eb98e959 100644 --- a/include/babeltrace/values.h +++ b/include/babeltrace/values.h @@ -41,13 +41,13 @@ extern "C" { */ enum bt_value_status { /// Operation canceled. - BT_VALUE_STATUS_CANCELED = -3, + BT_VALUE_STATUS_CANCELED = 125, - /// General error. - BT_VALUE_STATUS_ERROR = -1, + /// Cannot allocate memory. + BT_VALUE_STATUS_NOMEM = -12, /// Okay, no error. - BT_VALUE_STATUS_OK = 0, + BT_VALUE_STATUS_OK = 0, }; struct bt_value; @@ -122,33 +122,38 @@ bt_bool bt_value_is_map(const struct bt_value *object) return bt_value_get_type(object) == BT_VALUE_TYPE_MAP; } -extern struct bt_private_value *bt_value_copy(const struct bt_value *object); +extern enum bt_value_status bt_value_copy(struct bt_private_value **copy, + const struct bt_value *object); extern bt_bool bt_value_compare(const struct bt_value *object_a, const struct bt_value *object_b); -extern enum bt_value_status bt_value_bool_get( - const struct bt_value *bool_obj, bt_bool *val); +extern bt_bool bt_value_bool_get(const struct bt_value *bool_obj); -extern enum bt_value_status bt_value_integer_get( - const struct bt_value *integer_obj, int64_t *val); +extern int64_t bt_value_integer_get(const struct bt_value *integer_obj); -extern enum bt_value_status bt_value_real_get( - const struct bt_value *real_obj, double *val); +extern double bt_value_real_get(const struct bt_value *real_obj); -extern enum bt_value_status bt_value_string_get( - const struct bt_value *string_obj, const char **val); +extern const char *bt_value_string_get(const struct bt_value *string_obj); -extern int64_t bt_value_array_get_size(const struct bt_value *array_obj); +extern uint64_t bt_value_array_get_size(const struct bt_value *array_obj); -extern bt_bool bt_value_array_is_empty(const struct bt_value *array_obj); +static inline +bt_bool bt_value_array_is_empty(const struct bt_value *array_obj) +{ + return bt_value_array_get_size(array_obj) == 0; +} extern struct bt_value *bt_value_array_borrow_element_by_index( const struct bt_value *array_obj, uint64_t index); -extern int64_t bt_value_map_get_size(const struct bt_value *map_obj); +extern uint64_t bt_value_map_get_size(const struct bt_value *map_obj); -extern bt_bool bt_value_map_is_empty(const struct bt_value *map_obj); +static inline +bt_bool bt_value_map_is_empty(const struct bt_value *map_obj) +{ + return bt_value_map_get_size(map_obj) == 0; +} extern struct bt_value *bt_value_map_borrow_entry_value( const struct bt_value *map_obj, const char *key); @@ -163,7 +168,8 @@ extern enum bt_value_status bt_value_map_foreach_entry( extern bt_bool bt_value_map_has_entry(const struct bt_value *map_obj, const char *key); -extern struct bt_private_value *bt_value_map_extend( +extern enum bt_value_status bt_value_map_extend( + struct bt_private_value **extended_map_obj, struct bt_value *base_map_obj, struct bt_value *extension_map_obj); diff --git a/lib/ctf-writer/attributes.c b/lib/ctf-writer/attributes.c index cbc778f7..828ac9d7 100644 --- a/lib/ctf-writer/attributes.c +++ b/lib/ctf-writer/attributes.c @@ -88,7 +88,6 @@ BT_HIDDEN const char *bt_ctf_attributes_get_field_name(struct bt_private_value *attr_obj, uint64_t index) { - int rc; const char *ret = NULL; struct bt_private_value *attr_field_obj = NULL; struct bt_private_value *attr_field_name_obj = NULL; @@ -123,13 +122,8 @@ const char *bt_ctf_attributes_get_field_name(struct bt_private_value *attr_obj, goto end; } - rc = bt_value_string_get( - bt_value_borrow_from_private(attr_field_name_obj), &ret); - if (rc) { - BT_LOGE("Cannot get raw value from string value: value-addr=%p", - attr_field_name_obj); - ret = NULL; - } + ret = bt_value_string_get( + bt_value_borrow_from_private(attr_field_name_obj)); end: return ret; @@ -191,7 +185,6 @@ struct bt_private_value *bt_ctf_attributes_borrow_field_by_name( } for (i = 0; i < attr_size; ++i) { - int ret; const char *field_name; value_obj = bt_private_value_array_borrow_element_by_index(attr_obj, i); @@ -210,14 +203,8 @@ struct bt_private_value *bt_ctf_attributes_borrow_field_by_name( goto error; } - ret = bt_value_string_get( - bt_value_borrow_from_private(attr_field_name_obj), - &field_name); - if (ret) { - BT_LOGE("Cannot get raw value from string value: value-addr=%p", - attr_field_name_obj); - goto error; - } + field_name = bt_value_string_get( + bt_value_borrow_from_private(attr_field_name_obj)); if (!strcmp(field_name, name)) { break; diff --git a/lib/ctf-writer/trace.c b/lib/ctf-writer/trace.c index 98d79b97..7f5f3d55 100644 --- a/lib/ctf-writer/trace.c +++ b/lib/ctf-writer/trace.c @@ -1763,13 +1763,11 @@ void append_env_metadata(struct bt_ctf_trace *trace, bt_value_borrow_from_private(env_field_value_obj))) { case BT_VALUE_TYPE_INTEGER: { - int ret; int64_t int_value; - ret = bt_value_integer_get( + int_value = bt_value_integer_get( bt_value_borrow_from_private( - env_field_value_obj), &int_value); - BT_ASSERT(ret == 0); + env_field_value_obj)); g_string_append_printf(context->string, "\t%s = %" PRId64 ";\n", entry_name, int_value); @@ -1777,14 +1775,12 @@ void append_env_metadata(struct bt_ctf_trace *trace, } case BT_VALUE_TYPE_STRING: { - int ret; const char *str_value; char *escaped_str = NULL; - ret = bt_value_string_get( + str_value = bt_value_string_get( bt_value_borrow_from_private( - env_field_value_obj), &str_value); - BT_ASSERT(ret == 0); + env_field_value_obj)); escaped_str = g_strescape(str_value, NULL); if (!escaped_str) { BT_LOGE("Cannot escape string: string=\"%s\"", diff --git a/lib/lib-logging.c b/lib/lib-logging.c index 9dd8ae7f..3eb3f186 100644 --- a/lib/lib-logging.c +++ b/lib/lib-logging.c @@ -805,33 +805,29 @@ static inline void format_value(char **buf_ch, bool extended, switch (bt_value_get_type(value)) { case BT_VALUE_TYPE_BOOL: { - bt_bool val; + bt_bool val = bt_value_bool_get(value); - (void) bt_value_bool_get(value, &val); BUF_APPEND(", %svalue=%d", PRFIELD(val)); break; } case BT_VALUE_TYPE_INTEGER: { - int64_t val; + int64_t val = bt_value_integer_get(value); - (void) bt_value_integer_get(value, &val); BUF_APPEND(", %svalue=%" PRId64, PRFIELD(val)); break; } case BT_VALUE_TYPE_REAL: { - double val; + double val = bt_value_real_get(value); - (void) bt_value_real_get(value, &val); BUF_APPEND(", %svalue=%f", PRFIELD(val)); break; } case BT_VALUE_TYPE_STRING: { - const char *val; + const char *val = bt_value_string_get(value); - (void) bt_value_string_get(value, &val); BUF_APPEND(", %spartial-value=\"%.32s\"", PRFIELD(val)); break; } diff --git a/lib/trace-ir/attributes.c b/lib/trace-ir/attributes.c index 0b321e2e..d1e644f9 100644 --- a/lib/trace-ir/attributes.c +++ b/lib/trace-ir/attributes.c @@ -88,7 +88,6 @@ BT_HIDDEN const char *bt_attributes_get_field_name(struct bt_private_value *attr_obj, uint64_t index) { - int rc; const char *ret = NULL; struct bt_private_value *attr_field_obj = NULL; struct bt_private_value *attr_field_name_obj = NULL; @@ -125,13 +124,8 @@ const char *bt_attributes_get_field_name(struct bt_private_value *attr_obj, goto end; } - rc = bt_value_string_get( - bt_value_borrow_from_private(attr_field_name_obj), &ret); - if (rc) { - BT_LOGE("Cannot get raw value from string value: value-addr=%p", - attr_field_name_obj); - ret = NULL; - } + ret = bt_value_string_get( + bt_value_borrow_from_private(attr_field_name_obj)); end: return ret; @@ -195,7 +189,6 @@ struct bt_private_value *bt_attributes_borrow_field_by_name( } for (i = 0; i < attr_size; ++i) { - int ret; const char *field_name; value_obj = bt_private_value_array_borrow_element_by_index( @@ -216,14 +209,8 @@ struct bt_private_value *bt_attributes_borrow_field_by_name( goto error; } - ret = bt_value_string_get( - bt_value_borrow_from_private(attr_field_name_obj), - &field_name); - if (ret) { - BT_LOGE("Cannot get raw value from string value: value-addr=%p", - attr_field_name_obj); - goto error; - } + field_name = bt_value_string_get( + bt_value_borrow_from_private(attr_field_name_obj)); if (!strcmp(field_name, name)) { break; diff --git a/lib/values.c b/lib/values.c index d437657c..82765958 100644 --- a/lib/values.c +++ b/lib/values.c @@ -94,7 +94,8 @@ struct bt_value bt_value_null_instance = { }; struct bt_value *bt_value_null = &bt_value_null_instance; -struct bt_private_value *bt_private_value_null = (void *) &bt_value_null_instance; +struct bt_private_value *bt_private_value_null = + (void *) &bt_value_null_instance; struct bt_value_bool { struct bt_value base; @@ -176,7 +177,8 @@ struct bt_private_value *bt_value_null_copy(const struct bt_value *null_obj) static struct bt_private_value *bt_value_bool_copy(const struct bt_value *bool_obj) { - return bt_private_value_bool_create_init(BT_VALUE_TO_BOOL(bool_obj)->value); + return bt_private_value_bool_create_init( + BT_VALUE_TO_BOOL(bool_obj)->value); } static @@ -218,15 +220,16 @@ struct bt_private_value *bt_value_array_copy(const struct bt_value *array_obj) } for (i = 0; i < typed_array_obj->garray->len; ++i) { - struct bt_private_value *element_obj_copy; - struct bt_value *element_obj = bt_value_array_borrow_element_by_index( - array_obj, i); + struct bt_private_value *element_obj_copy = NULL; + struct bt_value *element_obj = + bt_value_array_borrow_element_by_index( + array_obj, i); 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); - if (!element_obj_copy) { + ret = bt_value_copy(&element_obj_copy, element_obj); + if (ret) { BT_LOGE("Cannot copy array value's element: " "array-addr=%p, index=%d", array_obj, i); @@ -234,6 +237,7 @@ struct bt_private_value *bt_value_array_copy(const struct bt_value *array_obj) goto end; } + BT_ASSERT(element_obj_copy); ret = bt_private_value_array_append_element(copy_obj, (void *) element_obj_copy); BT_OBJECT_PUT_REF_AND_RESET(element_obj_copy); @@ -259,7 +263,7 @@ struct bt_private_value *bt_value_map_copy(const struct bt_value *map_obj) GHashTableIter iter; gpointer key, element_obj; struct bt_private_value *copy_obj; - struct bt_private_value *element_obj_copy; + struct bt_private_value *element_obj_copy = NULL; struct bt_value_map *typed_map_obj; BT_LOGD("Copying map value: addr=%p", map_obj); @@ -277,8 +281,8 @@ struct bt_private_value *bt_value_map_copy(const struct bt_value *map_obj) 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); - if (!element_obj_copy) { + ret = bt_value_copy(&element_obj_copy, element_obj); + if (ret) { BT_LOGE("Cannot copy map value's element: " "map-addr=%p, key=\"%s\"", map_obj, key_str); @@ -286,6 +290,7 @@ struct bt_private_value *bt_value_map_copy(const struct bt_value *map_obj) goto end; } + BT_ASSERT(element_obj_copy); ret = bt_private_value_map_insert_entry(copy_obj, key_str, (void *) element_obj_copy); BT_OBJECT_PUT_REF_AND_RESET(element_obj_copy); @@ -442,7 +447,8 @@ bt_bool bt_value_map_compare(const struct bt_value *object_a, gpointer key, element_obj_a; const struct bt_value_map *map_obj_a = BT_VALUE_TO_MAP(object_a); - if (bt_value_map_get_size(object_a) != bt_value_map_get_size(object_b)) { + if (bt_value_map_get_size(object_a) != + bt_value_map_get_size(object_b)) { BT_LOGV("Map values are different: size mismatch " "value-a-addr=%p, value-b-addr=%p, " "value-a-size=%" PRId64 ", value-b-size=%" PRId64, @@ -761,18 +767,14 @@ end: return (void *) BT_VALUE_FROM_CONCRETE(map_obj); } -enum bt_value_status bt_value_bool_get(const struct bt_value *bool_obj, - bt_bool *val) +bt_bool bt_value_bool_get(const struct bt_value *bool_obj) { 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; + return BT_VALUE_TO_BOOL(bool_obj)->value; } -enum bt_value_status bt_private_value_bool_set(struct bt_private_value *bool_obj, - bt_bool val) +void bt_private_value_bool_set(struct bt_private_value *bool_obj, bt_bool val) { BT_ASSERT_PRE_NON_NULL(bool_obj, "Value object"); BT_ASSERT_PRE_VALUE_IS_TYPE(bool_obj, BT_VALUE_TYPE_BOOL); @@ -780,20 +782,16 @@ enum bt_value_status bt_private_value_bool_set(struct bt_private_value *bool_obj BT_VALUE_TO_BOOL(bool_obj)->value = val; BT_LOGV("Set boolean value's raw value: value-addr=%p, value=%d", bool_obj, val); - return BT_VALUE_STATUS_OK; } -enum bt_value_status bt_value_integer_get(const struct bt_value *integer_obj, - int64_t *val) +int64_t bt_value_integer_get(const struct bt_value *integer_obj) { 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; + return BT_VALUE_TO_INTEGER(integer_obj)->value; } -enum bt_value_status bt_private_integer_bool_set(struct bt_private_value *integer_obj, +void bt_private_value_integer_set(struct bt_private_value *integer_obj, int64_t val) { BT_ASSERT_PRE_NON_NULL(integer_obj, "Value object"); @@ -802,21 +800,16 @@ enum bt_value_status bt_private_integer_bool_set(struct bt_private_value *intege BT_VALUE_TO_INTEGER(integer_obj)->value = val; BT_LOGV("Set integer value's raw value: value-addr=%p, value=%" PRId64, integer_obj, val); - return BT_VALUE_STATUS_OK; } -enum bt_value_status bt_value_real_get(const struct bt_value *real_obj, - double *val) +double bt_value_real_get(const struct bt_value *real_obj) { BT_ASSERT_PRE_NON_NULL(real_obj, "Value object"); - BT_ASSERT_PRE_NON_NULL(val, "Raw value"); BT_ASSERT_PRE_VALUE_IS_TYPE(real_obj, BT_VALUE_TYPE_REAL); - *val = BT_VALUE_TO_REAL(real_obj)->value; - return BT_VALUE_STATUS_OK; + return BT_VALUE_TO_REAL(real_obj)->value; } -enum bt_value_status bt_private_value_real_set(struct bt_private_value *real_obj, - double val) +void bt_private_value_real_set(struct bt_private_value *real_obj, double val) { BT_ASSERT_PRE_NON_NULL(real_obj, "Value object"); BT_ASSERT_PRE_VALUE_IS_TYPE(real_obj, BT_VALUE_TYPE_REAL); @@ -824,24 +817,19 @@ enum bt_value_status bt_private_value_real_set(struct bt_private_value *real_obj BT_VALUE_TO_REAL(real_obj)->value = val; BT_LOGV("Set real number value's raw value: value-addr=%p, value=%f", real_obj, val); - return BT_VALUE_STATUS_OK; } -enum bt_value_status bt_value_string_get(const struct bt_value *string_obj, - const char **val) +const char *bt_value_string_get(const struct bt_value *string_obj) { 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; + return BT_VALUE_TO_STRING(string_obj)->gstr->str; } -enum bt_value_status bt_private_value_string_set(struct bt_private_value *string_obj, - const char *val) +enum bt_value_status bt_private_value_string_set( + struct bt_private_value *string_obj, const char *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); @@ -850,16 +838,11 @@ enum bt_value_status bt_private_value_string_set(struct bt_private_value *string return BT_VALUE_STATUS_OK; } -int64_t bt_value_array_get_size(const struct bt_value *array_obj) +uint64_t bt_value_array_get_size(const struct bt_value *array_obj) { 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) -{ - return bt_value_array_get_size(array_obj) == 0; + return (uint64_t) BT_VALUE_TO_ARRAY(array_obj)->garray->len; } struct bt_value *bt_value_array_borrow_element_by_index( @@ -1003,16 +986,11 @@ enum bt_value_status bt_private_value_array_set_element_by_index( return BT_VALUE_STATUS_OK; } -int64_t bt_value_map_get_size(const struct bt_value *map_obj) +uint64_t bt_value_map_get_size(const struct bt_value *map_obj) { 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) -{ - return bt_value_map_get_size(map_obj) == 0; + return (uint64_t) g_hash_table_size(BT_VALUE_TO_MAP(map_obj)->ght); } struct bt_value *bt_value_map_borrow_entry_value(const struct bt_value *map_obj, @@ -1098,7 +1076,8 @@ enum bt_value_status bt_private_value_map_insert_real_entry( } enum bt_value_status bt_private_value_map_insert_string_entry( - struct bt_private_value *map_obj, const char *key, const char *val) + struct bt_private_value *map_obj, const char *key, + const char *val) { enum bt_value_status ret; struct bt_private_value *string_obj = NULL; @@ -1174,7 +1153,7 @@ enum bt_value_status bt_private_value_map_foreach_entry( struct extend_map_element_data { struct bt_private_value *extended_obj; - bt_bool got_error; + enum bt_value_status status; }; static @@ -1182,16 +1161,25 @@ bt_bool extend_map_element(const char *key, struct bt_value *extension_obj_elem, void *data) { bt_bool ret = BT_TRUE; - struct extend_map_element_data *extend_data = data; + struct bt_private_value *extension_obj_elem_copy = NULL; /* Copy object which is to replace the current one */ - struct bt_private_value *extension_obj_elem_copy = - bt_value_copy(extension_obj_elem); + extend_data->status = bt_value_copy(&extension_obj_elem_copy, + extension_obj_elem); + if (extend_data->status) { + BT_LOGE("Cannot copy map element: addr=%p", + extension_obj_elem); + goto error; + } + + BT_ASSERT(extension_obj_elem_copy); /* Replace in extended object */ - if (bt_private_value_map_insert_entry(extend_data->extended_obj, key, - (void *) extension_obj_elem_copy)) { + extend_data->status = bt_private_value_map_insert_entry( + extend_data->extended_obj, key, + (void *) extension_obj_elem_copy); + if (extend_data->status) { BT_LOGE("Cannot replace value in extended value: key=\"%s\", " "extended-value-addr=%p, element-value-addr=%p", key, extend_data->extended_obj, @@ -1202,40 +1190,49 @@ bt_bool extend_map_element(const char *key, goto end; error: + BT_ASSERT(extend_data->status != BT_VALUE_STATUS_OK); ret = BT_FALSE; - extend_data->got_error = BT_TRUE; end: BT_OBJECT_PUT_REF_AND_RESET(extension_obj_elem_copy); return ret; } -struct bt_private_value *bt_value_map_extend(struct bt_value *base_map_obj, +enum bt_value_status bt_value_map_extend( + struct bt_private_value **extended_map_obj, + struct bt_value *base_map_obj, struct bt_value *extension_obj) { - struct bt_private_value *extended_obj = NULL; - struct extend_map_element_data extend_data = { 0 }; + struct extend_map_element_data extend_data = { + .extended_obj = NULL, + .status = BT_VALUE_STATUS_OK, + }; BT_ASSERT_PRE_NON_NULL(base_map_obj, "Base value object"); BT_ASSERT_PRE_NON_NULL(extension_obj, "Extension value object"); + BT_ASSERT_PRE_NON_NULL(extended_map_obj, + "Extended value object (output)"); 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); + *extended_map_obj = NULL; /* Create copy of base map object to start with */ - extended_obj = bt_value_copy(base_map_obj); - if (!extended_obj) { + extend_data.status = bt_value_copy(extended_map_obj, base_map_obj); + if (extend_data.status) { BT_LOGE("Cannot copy base value: base-value-addr=%p", base_map_obj); goto error; } + BT_ASSERT(extended_map_obj); + /* * For each key in the extension map object, replace this key * in the copied map object. */ - extend_data.extended_obj = extended_obj; + extend_data.extended_obj = *extended_map_obj; if (bt_value_map_foreach_entry(extension_obj, extend_map_element, &extend_data)) { @@ -1244,38 +1241,43 @@ struct bt_private_value *bt_value_map_extend(struct bt_value *base_map_obj, goto error; } - if (extend_data.got_error) { + if (extend_data.status) { BT_LOGE("Failed to successfully iterate on the extension object's elements: " "extension-value-addr=%p", extension_obj); goto error; } BT_LOGD("Extended map value: extended-value-addr=%p", - extended_obj); + *extended_map_obj); goto end; error: - BT_OBJECT_PUT_REF_AND_RESET(extended_obj); + BT_OBJECT_PUT_REF_AND_RESET(*extended_map_obj); + *extended_map_obj = NULL; end: - return (void *) extended_obj; + return extend_data.status; } -struct bt_private_value *bt_value_copy(const struct bt_value *object) +enum bt_value_status bt_value_copy(struct bt_private_value **copy_obj, + const struct bt_value *object) { - struct bt_private_value *copy_obj = NULL; + enum bt_value_status status = BT_VALUE_STATUS_OK; BT_ASSERT_PRE_NON_NULL(object, "Value object"); + BT_ASSERT_PRE_NON_NULL(copy_obj, "Value object copy (output)"); BT_LOGD("Copying value object: addr=%p", object); - copy_obj = copy_funcs[object->type](object); - if (copy_obj) { + *copy_obj = copy_funcs[object->type](object); + if (*copy_obj) { BT_LOGD("Copied value object: copy-value-addr=%p", copy_obj); } else { + status = BT_VALUE_STATUS_NOMEM; + *copy_obj = NULL; BT_LOGE_STR("Failed to copy value object."); } - return (void *) copy_obj; + return status; } bt_bool bt_value_compare(const struct bt_value *object_a, diff --git a/plugins/ctf/fs-sink/writer.c b/plugins/ctf/fs-sink/writer.c index b8e21137..d9166834 100644 --- a/plugins/ctf/fs-sink/writer.c +++ b/plugins/ctf/fs-sink/writer.c @@ -278,11 +278,7 @@ enum bt_component_status apply_one_bool(const char *key, if (!value) { goto end; } - status = bt_value_bool_get(value, &bool_val); - if (status != BT_VALUE_STATUS_OK) { - ret = BT_COMPONENT_STATUS_ERROR; - goto end; - } + bool_val = bt_value_bool_get(value); *option = (bool) bool_val; if (found) { diff --git a/plugins/ctf/fs-src/fs.c b/plugins/ctf/fs-src/fs.c index f5a4b57d..405a1838 100644 --- a/plugins/ctf/fs-src/fs.c +++ b/plugins/ctf/fs-src/fs.c @@ -1252,7 +1252,6 @@ struct ctf_fs_component *ctf_fs_create(struct bt_private_component *priv_comp, struct bt_value *value = NULL; const char *path_param; enum bt_component_status ret; - enum bt_value_status value_ret; ctf_fs = g_new0(struct ctf_fs_component, 1); if (!ctf_fs) { @@ -1273,17 +1272,14 @@ struct ctf_fs_component *ctf_fs_create(struct bt_private_component *priv_comp, goto error; } - value_ret = bt_value_string_get(value, &path_param); - BT_ASSERT(value_ret == BT_VALUE_STATUS_OK); + path_param = bt_value_string_get(value); value = bt_value_map_borrow_entry_value(params, "clock-class-offset-s"); if (value) { if (!bt_value_is_integer(value)) { BT_LOGE("clock-class-offset-s should be an integer"); goto error; } - value_ret = bt_value_integer_get(value, - &ctf_fs->metadata_config.clock_class_offset_s); - BT_ASSERT(value_ret == BT_VALUE_STATUS_OK); + ctf_fs->metadata_config.clock_class_offset_s = bt_value_integer_get(value); } value = bt_value_map_borrow_entry_value(params, "clock-class-offset-ns"); @@ -1292,9 +1288,7 @@ struct ctf_fs_component *ctf_fs_create(struct bt_private_component *priv_comp, BT_LOGE("clock-class-offset-ns should be an integer"); goto error; } - value_ret = bt_value_integer_get(value, - &ctf_fs->metadata_config.clock_class_offset_ns); - BT_ASSERT(value_ret == BT_VALUE_STATUS_OK); + ctf_fs->metadata_config.clock_class_offset_ns = bt_value_integer_get(value); } ctf_fs->port_data = g_ptr_array_new_with_free_func(port_data_destroy); diff --git a/plugins/ctf/fs-src/query.c b/plugins/ctf/fs-src/query.c index eef9e9ee..2a587d7b 100644 --- a/plugins/ctf/fs-src/query.c +++ b/plugins/ctf/fs-src/query.c @@ -81,12 +81,7 @@ struct bt_component_class_query_method_return metadata_info_query( } path_value = bt_value_map_borrow_entry_value(params, "path"); - ret = bt_value_string_get(path_value, &path); - if (ret) { - BT_LOGE_STR("Cannot get `path` string parameter."); - query_ret.status = BT_QUERY_STATUS_INVALID_PARAMS; - goto error; - } + path = bt_value_string_get(path_value); BT_ASSERT(path); metadata_fp = ctf_fs_metadata_open_file(path); @@ -499,12 +494,7 @@ struct bt_component_class_query_method_return trace_info_query( } path_value = bt_value_map_borrow_entry_value(params, "path"); - ret = bt_value_string_get(path_value, &path); - if (ret) { - BT_LOGE("Cannot get `path` string parameter."); - query_ret.status = BT_QUERY_STATUS_INVALID_PARAMS; - goto error; - } + path = bt_value_string_get(path_value); normalized_path = bt_common_normalize_path(path, NULL); if (!normalized_path) { diff --git a/plugins/ctf/lttng-live/lttng-live.c b/plugins/ctf/lttng-live/lttng-live.c index 27c2cf5a..098a1836 100644 --- a/plugins/ctf/lttng-live/lttng-live.c +++ b/plugins/ctf/lttng-live/lttng-live.c @@ -1080,11 +1080,7 @@ struct lttng_live_component *lttng_live_component_create(struct bt_value *params BT_LOGW("Mandatory \"url\" parameter missing"); goto error; } - ret = bt_value_string_get(value, &url); - if (ret != BT_VALUE_STATUS_OK) { - BT_LOGW("\"url\" parameter is required to be a string value"); - goto error; - } + url = bt_value_string_get(value); lttng_live->url = g_string_new(url); if (!lttng_live->url) { goto error; diff --git a/plugins/ctf/lttng-live/viewer-connection.c b/plugins/ctf/lttng-live/viewer-connection.c index 79d2c31e..f371095c 100644 --- a/plugins/ctf/lttng-live/viewer-connection.c +++ b/plugins/ctf/lttng-live/viewer-connection.c @@ -327,14 +327,8 @@ enum bt_value_status list_update_session(struct bt_value *results, ret = BT_VALUE_STATUS_ERROR; goto end; } - ret = bt_value_string_get(hostname, &hostname_str); - if (ret != BT_VALUE_STATUS_OK) { - goto end; - } - ret = bt_value_string_get(session_name, &session_name_str); - if (ret != BT_VALUE_STATUS_OK) { - goto end; - } + hostname_str = bt_value_string_get(hostname); + session_name_str = bt_value_string_get(session_name); if (!strcmp(session->hostname, hostname_str) && !strcmp(session->session_name, @@ -350,10 +344,7 @@ enum bt_value_status list_update_session(struct bt_value *results, ret = BT_VALUE_STATUS_ERROR; goto end; } - ret = bt_value_integer_get(btval, &val); - if (ret != BT_VALUE_STATUS_OK) { - goto end; - } + val = bt_value_integer_get(btval); /* sum */ val += streams; ret = bt_private_integer_bool_set(btval, val); @@ -367,10 +358,7 @@ enum bt_value_status list_update_session(struct bt_value *results, ret = BT_VALUE_STATUS_ERROR; goto end; } - ret = bt_value_integer_get(btval, &val); - if (ret != BT_VALUE_STATUS_OK) { - goto end; - } + val = bt_value_integer_get(btval); /* max */ val = max_t(int64_t, clients, val); ret = bt_private_integer_bool_set(btval, val); diff --git a/plugins/lttng-utils/copy.c b/plugins/lttng-utils/copy.c index 80179700..5467d384 100644 --- a/plugins/lttng-utils/copy.c +++ b/plugins/lttng-utils/copy.c @@ -448,8 +448,7 @@ struct debug_info *insert_new_debug_info(struct debug_info_iterator *debug_it, if (!field) { goto end; } - ret = bt_value_string_get(field, &str_value); - BT_ASSERT(ret == BT_VALUE_STATUS_OK); + str_value = bt_value_string_get(field); /* Domain not ust, no debug info */ if (strcmp(str_value, "ust") != 0) { @@ -464,8 +463,7 @@ struct debug_info *insert_new_debug_info(struct debug_info_iterator *debug_it, if (!field) { goto end; } - ret = bt_value_string_get(field, &str_value); - BT_ASSERT(ret == BT_VALUE_STATUS_OK); + str_value = bt_value_string_get(field); /* Tracer_name not lttng-ust, no debug info */ if (strcmp(str_value, "lttng-ust") != 0) { diff --git a/plugins/lttng-utils/plugin.c b/plugins/lttng-utils/plugin.c index fbbdc664..f6ec53d3 100644 --- a/plugins/lttng-utils/plugin.c +++ b/plugins/lttng-utils/plugin.c @@ -338,12 +338,7 @@ enum bt_component_status init_from_params( enum bt_value_status value_ret; const char *tmp; - value_ret = bt_value_string_get(value, &tmp); - if (value_ret) { - ret = BT_COMPONENT_STATUS_INVALID; - BT_LOGE_STR("Failed to retrieve debug-info-field-name value. " - "Expecting a string."); - } + tmp = bt_value_string_get(value); strcpy(debug_info_component->arg_debug_info_field_name, tmp); bt_object_put_ref(value); } else { @@ -365,13 +360,7 @@ enum bt_component_status init_from_params( if (value) { enum bt_value_status value_ret; - value_ret = bt_value_string_get(value, - &debug_info_component->arg_debug_dir); - if (value_ret) { - ret = BT_COMPONENT_STATUS_INVALID; - BT_LOGE_STR("Failed to retrieve debug-info-dir value. " - "Expecting a string."); - } + debug_info_component->arg_debug_dir = bt_value_string_get(value); } bt_object_put_ref(value); if (ret != BT_COMPONENT_STATUS_OK) { @@ -382,13 +371,7 @@ enum bt_component_status init_from_params( if (value) { enum bt_value_status value_ret; - value_ret = bt_value_string_get(value, - &debug_info_component->arg_target_prefix); - if (value_ret) { - ret = BT_COMPONENT_STATUS_INVALID; - BT_LOGE_STR("Failed to retrieve target-prefix value. " - "Expecting a string."); - } + debug_info_component->arg_target_prefix = bt_value_string_get(value); } bt_object_put_ref(value); if (ret != BT_COMPONENT_STATUS_OK) { @@ -400,13 +383,7 @@ enum bt_component_status init_from_params( enum bt_value_status value_ret; bt_bool bool_val; - value_ret = bt_value_bool_get(value, - &bool_val); - if (value_ret) { - ret = BT_COMPONENT_STATUS_INVALID; - BT_LOGE_STR("Failed to retrieve full-path value. " - "Expecting a boolean."); - } + bool_val = bt_value_bool_get(value); debug_info_component->arg_full_path = bool_val; } diff --git a/plugins/text/dmesg/dmesg.c b/plugins/text/dmesg/dmesg.c index 0edc2e61..6659fd1e 100644 --- a/plugins/text/dmesg/dmesg.c +++ b/plugins/text/dmesg/dmesg.c @@ -227,9 +227,8 @@ int handle_params(struct dmesg_component *dmesg_comp, struct bt_value *params) goto error; } - ret = bt_value_bool_get(no_timestamp, - &dmesg_comp->params.no_timestamp); - BT_ASSERT(ret == 0); + dmesg_comp->params.no_timestamp = + bt_value_bool_get(no_timestamp); } path = bt_value_map_borrow_entry_value(params, "path"); @@ -247,8 +246,7 @@ int handle_params(struct dmesg_component *dmesg_comp, struct bt_value *params) goto error; } - ret = bt_value_string_get(path, &path_str); - BT_ASSERT(ret == 0); + path_str = bt_value_string_get(path); g_string_assign(dmesg_comp->params.path, path_str); } else { dmesg_comp->params.read_from_stdin = true; diff --git a/plugins/text/pretty/pretty.c b/plugins/text/pretty/pretty.c index 1d3e5ef7..5ef2c7a7 100644 --- a/plugins/text/pretty/pretty.c +++ b/plugins/text/pretty/pretty.c @@ -272,7 +272,6 @@ enum bt_component_status apply_one_string(const char *key, { enum bt_component_status ret = BT_COMPONENT_STATUS_OK; struct bt_value *value = NULL; - enum bt_value_status status; const char *str; value = bt_value_map_borrow_entry_value(params, key); @@ -282,15 +281,9 @@ enum bt_component_status apply_one_string(const char *key, if (bt_value_is_null(value)) { goto end; } - status = bt_value_string_get(value, &str); - switch (status) { - case BT_VALUE_STATUS_OK: - break; - default: - ret = BT_COMPONENT_STATUS_ERROR; - goto end; - } + str = bt_value_string_get(value); *option = g_strdup(str); + end: return ret; } @@ -303,21 +296,13 @@ enum bt_component_status apply_one_bool(const char *key, { enum bt_component_status ret = BT_COMPONENT_STATUS_OK; struct bt_value *value = NULL; - enum bt_value_status status; bt_bool bool_val; value = bt_value_map_borrow_entry_value(params, key); if (!value) { goto end; } - status = bt_value_bool_get(value, &bool_val); - switch (status) { - case BT_VALUE_STATUS_OK: - break; - default: - ret = BT_COMPONENT_STATUS_ERROR; - goto end; - } + bool_val = bt_value_bool_get(value); *option = (bool) bool_val; if (found) { *found = true; @@ -394,19 +379,16 @@ enum bt_component_status apply_params(struct pretty_component *pretty, goto end; } - status = bt_value_string_get(color_value, &color); - if (status) { - warn_wrong_color_param(pretty); + color = bt_value_string_get(color_value); + + if (strcmp(color, "never") == 0) { + pretty->options.color = PRETTY_COLOR_OPT_NEVER; + } else if (strcmp(color, "auto") == 0) { + pretty->options.color = PRETTY_COLOR_OPT_AUTO; + } else if (strcmp(color, "always") == 0) { + pretty->options.color = PRETTY_COLOR_OPT_ALWAYS; } else { - if (strcmp(color, "never") == 0) { - pretty->options.color = PRETTY_COLOR_OPT_NEVER; - } else if (strcmp(color, "auto") == 0) { - pretty->options.color = PRETTY_COLOR_OPT_AUTO; - } else if (strcmp(color, "always") == 0) { - pretty->options.color = PRETTY_COLOR_OPT_ALWAYS; - } else { - warn_wrong_color_param(pretty); - } + warn_wrong_color_param(pretty); } } diff --git a/plugins/text/pretty/print.c b/plugins/text/pretty/print.c index f4f7a586..7e34af6d 100644 --- a/plugins/text/pretty/print.c +++ b/plugins/text/pretty/print.c @@ -379,10 +379,8 @@ enum bt_component_status print_event_header(struct pretty_component *pretty, if (print_names) { print_name_equal(pretty, "trace:hostname"); } - if (bt_value_string_get(hostname_str, &str) - == BT_VALUE_STATUS_OK) { - g_string_append(pretty->string, str); - } + str = bt_value_string_get(hostname_str); + g_string_append(pretty->string, str); dom_print = 1; } } @@ -402,10 +400,8 @@ enum bt_component_status print_event_header(struct pretty_component *pretty, } else if (dom_print) { g_string_append(pretty->string, ":"); } - if (bt_value_string_get(domain_str, &str) - == BT_VALUE_STATUS_OK) { - g_string_append(pretty->string, str); - } + str = bt_value_string_get(domain_str); + g_string_append(pretty->string, str); dom_print = 1; } } @@ -425,11 +421,8 @@ enum bt_component_status print_event_header(struct pretty_component *pretty, } else if (dom_print) { g_string_append(pretty->string, ":"); } - if (bt_value_string_get(procname_str, &str) - == BT_VALUE_STATUS_OK) { - g_string_append(pretty->string, str); - } - + str = bt_value_string_get(procname_str); + g_string_append(pretty->string, str); dom_print = 1; } } @@ -449,11 +442,9 @@ enum bt_component_status print_event_header(struct pretty_component *pretty, } else if (dom_print) { g_string_append(pretty->string, ":"); } - if (bt_value_integer_get(vpid_value, &value) - == BT_VALUE_STATUS_OK) { - g_string_append_printf(pretty->string, "(%" PRId64 ")", value); - } - + value = bt_value_integer_get(vpid_value); + g_string_append_printf(pretty->string, + "(%" PRId64 ")", value); dom_print = 1; } } diff --git a/plugins/utils/counter/counter.c b/plugins/utils/counter/counter.c index be831ef9..0c2cd3cf 100644 --- a/plugins/utils/counter/counter.c +++ b/plugins/utils/counter/counter.c @@ -144,8 +144,7 @@ enum bt_component_status counter_init(struct bt_private_component *component, if (step && bt_value_is_integer(step)) { int64_t val; - (void) bt_value_integer_get(step, &val); - + val = bt_value_integer_get(step); if (val >= 0) { counter->step = (uint64_t) val; } @@ -155,7 +154,7 @@ enum bt_component_status counter_init(struct bt_private_component *component, if (hide_zero && bt_value_is_bool(hide_zero)) { bt_bool val; - (void) bt_value_bool_get(hide_zero, &val); + val = bt_value_bool_get(hide_zero); counter->hide_zero = (bool) val; } diff --git a/plugins/utils/muxer/muxer.c b/plugins/utils/muxer/muxer.c index e146daad..8275f3e4 100644 --- a/plugins/utils/muxer/muxer.c +++ b/plugins/utils/muxer/muxer.c @@ -287,9 +287,9 @@ int configure_muxer_comp(struct muxer_comp *muxer_comp, struct bt_value *params) goto error; } - real_params = bt_value_map_extend( + ret = bt_value_map_extend(&real_params, bt_value_borrow_from_private(default_params), params); - if (!real_params) { + if (ret) { BT_LOGE("Cannot extend default parameters map value: " "muxer-comp-addr=%p, def-params-addr=%p, " "params-addr=%p", muxer_comp, default_params, @@ -310,8 +310,7 @@ int configure_muxer_comp(struct muxer_comp *muxer_comp, struct bt_value *params) goto error; } - ret = bt_value_bool_get(assume_absolute_clock_classes, &bool_val); - BT_ASSERT(ret == 0); + bool_val = bt_value_bool_get(assume_absolute_clock_classes); muxer_comp->assume_absolute_clock_classes = (bool) bool_val; BT_LOGD("Configured muxer component: muxer-comp-addr=%p, " "assume-absolute-clock-classes=%d", diff --git a/plugins/utils/trimmer/trimmer.c b/plugins/utils/trimmer/trimmer.c index bcb175df..777b14fa 100644 --- a/plugins/utils/trimmer/trimmer.c +++ b/plugins/utils/trimmer/trimmer.c @@ -304,11 +304,7 @@ enum bt_component_status init_from_params(struct trimmer *trimmer, if (value) { enum bt_value_status value_ret; - value_ret = bt_value_bool_get(value, &gmt); - if (value_ret) { - ret = BT_COMPONENT_STATUS_INVALID; - BT_LOGE_STR("Failed to retrieve clock-gmt value. Expecting a boolean"); - } + gmt = bt_value_bool_get(value); } if (ret != BT_COMPONENT_STATUS_OK) { goto end; diff --git a/tests/lib/test_bt_values.c b/tests/lib/test_bt_values.c index f047448b..629982aa 100644 --- a/tests/lib/test_bt_values.c +++ b/tests/lib/test_bt_values.c @@ -27,7 +27,7 @@ #include #include "tap/tap.h" -#define NR_TESTS 158 +#define NR_TESTS 147 static void test_null(void) @@ -44,7 +44,6 @@ void test_null(void) static void test_bool(void) { - int ret; bt_bool value; struct bt_private_value *priv_obj; struct bt_value *obj; @@ -55,14 +54,13 @@ void test_bool(void) "bt_private_value_bool_create() returns a boolean value object"); value = BT_TRUE; - ret = bt_value_bool_get(obj, &value); - ok(!ret && !value, "default boolean value object value is BT_FALSE"); + value = bt_value_bool_get(obj); + ok(!value, "default boolean value object value is BT_FALSE"); - BT_ASSERT(!bt_private_value_bool_set(priv_obj, BT_FALSE)); - ret = bt_private_value_bool_set(priv_obj, BT_TRUE); - ok(!ret, "bt_private_value_bool_set() succeeds"); - ret = bt_value_bool_get(obj, &value); - ok(!ret && value, "bt_private_value_bool_set() works"); + bt_private_value_bool_set(priv_obj, BT_FALSE); + bt_private_value_bool_set(priv_obj, BT_TRUE); + value = bt_value_bool_get(obj); + ok(value, "bt_private_value_bool_set() works"); BT_OBJECT_PUT_REF_AND_RESET(priv_obj); pass("putting an existing boolean value object does not cause a crash") @@ -72,8 +70,8 @@ void test_bool(void) obj = bt_value_borrow_from_private(priv_obj); ok(obj && bt_value_is_bool(obj), "bt_private_value_bool_create_init() returns a boolean value object"); - ret = bt_value_bool_get(obj, &value); - ok(!ret && value, + value = bt_value_bool_get(obj); + ok(value, "bt_private_value_bool_create_init() sets the appropriate initial value"); BT_OBJECT_PUT_REF_AND_RESET(priv_obj); @@ -82,7 +80,6 @@ void test_bool(void) static void test_integer(void) { - int ret; int64_t value; struct bt_private_value *priv_obj; struct bt_value *obj; @@ -93,13 +90,12 @@ void test_integer(void) "bt_private_value_integer_create() returns an integer value object"); value = 1961; - ret = bt_value_integer_get(obj, &value); - ok(!ret && value == 0, "default integer value object value is 0"); + value = bt_value_integer_get(obj); + ok(value == 0, "default integer value object value is 0"); - ret = bt_private_integer_bool_set(priv_obj, -98765); - ok(!ret, "bt_private_integer_bool_set() succeeds"); - ret = bt_value_integer_get(obj, &value); - ok(!ret && value == -98765, "bt_private_integer_bool_set() works"); + bt_private_value_integer_set(priv_obj, -98765); + value = bt_value_integer_get(obj); + ok(value == -98765, "bt_private_integer_bool_set() works"); BT_OBJECT_PUT_REF_AND_RESET(priv_obj); pass("putting an existing integer value object does not cause a crash") @@ -108,8 +104,8 @@ void test_integer(void) obj = bt_value_borrow_from_private(priv_obj); ok(obj && bt_value_is_integer(obj), "bt_private_value_integer_create_init() returns an integer value object"); - ret = bt_value_integer_get(obj, &value); - ok(!ret && value == 321456987, + value = bt_value_integer_get(obj); + ok(value == 321456987, "bt_private_value_integer_create_init() sets the appropriate initial value"); BT_OBJECT_PUT_REF_AND_RESET(priv_obj); @@ -118,7 +114,6 @@ void test_integer(void) static void test_real(void) { - int ret; double value; struct bt_private_value *priv_obj; struct bt_value *obj; @@ -129,14 +124,13 @@ void test_real(void) "bt_private_value_real_create() returns a real number value object"); value = 17.34; - ret = bt_value_real_get(obj, &value); - ok(!ret && value == 0., + value = bt_value_real_get(obj); + ok(value == 0., "default real number value object value is 0"); - ret = bt_private_value_real_set(priv_obj, -3.1416); - ok(!ret, "bt_private_value_real_set() succeeds"); - ret = bt_value_real_get(obj, &value); - ok(!ret && value == -3.1416, "bt_private_value_real_set() works"); + bt_private_value_real_set(priv_obj, -3.1416); + value = bt_value_real_get(obj); + ok(value == -3.1416, "bt_private_value_real_set() works"); BT_OBJECT_PUT_REF_AND_RESET(priv_obj); pass("putting an existing real number value object does not cause a crash") @@ -145,8 +139,8 @@ void test_real(void) obj = bt_value_borrow_from_private(priv_obj); ok(obj && bt_value_is_real(obj), "bt_private_value_real_create_init() returns a real number value object"); - ret = bt_value_real_get(obj, &value); - ok(!ret && value == 33.1649758, + value = bt_value_real_get(obj); + ok(value == 33.1649758, "bt_private_value_real_create_init() sets the appropriate initial value"); BT_OBJECT_PUT_REF_AND_RESET(priv_obj); @@ -155,7 +149,6 @@ void test_real(void) static void test_string(void) { - int ret; const char *value; struct bt_private_value *priv_obj; struct bt_value *obj; @@ -165,14 +158,13 @@ void test_string(void) ok(obj && bt_value_is_string(obj), "bt_private_value_string_create() returns a string value object"); - ret = bt_value_string_get(obj, &value); - ok(!ret && value && !strcmp(value, ""), + value = bt_value_string_get(obj); + ok(value && !strcmp(value, ""), "default string value object value is \"\""); - ret = bt_private_value_string_set(priv_obj, "hello worldz"); - ok(!ret, "bt_private_value_string_set() succeeds"); - ret = bt_value_string_get(obj, &value); - ok(!ret && value && !strcmp(value, "hello worldz"), + bt_private_value_string_set(priv_obj, "hello worldz"); + value = bt_value_string_get(obj); + ok(value && !strcmp(value, "hello worldz"), "bt_value_string_get() works"); BT_OBJECT_PUT_REF_AND_RESET(priv_obj); @@ -182,8 +174,8 @@ void test_string(void) obj = bt_value_borrow_from_private(priv_obj); ok(obj && bt_value_is_string(obj), "bt_private_value_string_create_init() returns a string value object"); - ret = bt_value_string_get(obj, &value); - ok(!ret && value && !strcmp(value, "initial value"), + value = bt_value_string_get(obj); + ok(value && !strcmp(value, "initial value"), "bt_private_value_string_create_init() sets the appropriate initial value"); BT_OBJECT_PUT_REF_AND_RESET(priv_obj); @@ -230,20 +222,20 @@ void test_array(void) obj = bt_value_array_borrow_element_by_index(array_obj, 0); ok(obj && bt_value_is_integer(obj), "bt_value_array_borrow_element_by_index() returns an value object with the appropriate type (integer)"); - ret = bt_value_integer_get(obj, &int_value); - ok(!ret && int_value == 345, + int_value = bt_value_integer_get(obj); + ok(int_value == 345, "bt_value_array_borrow_element_by_index() returns an value object with the appropriate value (integer)"); obj = bt_value_array_borrow_element_by_index(array_obj, 1); ok(obj && bt_value_is_real(obj), "bt_value_array_borrow_element_by_index() returns an value object with the appropriate type (real number)"); - ret = bt_value_real_get(obj, &real_value); - ok(!ret && real_value == -17.45, + real_value = bt_value_real_get(obj); + ok(real_value == -17.45, "bt_value_array_borrow_element_by_index() returns an value object with the appropriate value (real number)"); obj = bt_value_array_borrow_element_by_index(array_obj, 2); ok(obj && bt_value_is_bool(obj), "bt_value_array_borrow_element_by_index() returns an value object with the appropriate type (boolean)"); - ret = bt_value_bool_get(obj, &bool_value); - ok(!ret && bool_value, + bool_value = bt_value_bool_get(obj); + ok(bool_value, "bt_value_array_borrow_element_by_index() returns an value object with the appropriate value (boolean)"); obj = bt_value_array_borrow_element_by_index(array_obj, 3); ok(obj == bt_value_null, @@ -258,7 +250,7 @@ void test_array(void) obj = bt_value_array_borrow_element_by_index(array_obj, 2); ok(obj && bt_value_is_integer(obj), "bt_value_array_set_element_by_index() inserts an value object with the appropriate type"); - ret = bt_value_integer_get(obj, &int_value); + int_value = bt_value_integer_get(obj); BT_ASSERT(!ret); ok(int_value == 1001, "bt_value_array_set_element_by_index() inserts an value object with the appropriate value"); @@ -288,25 +280,25 @@ void test_array(void) obj = bt_value_array_borrow_element_by_index(array_obj, 4); ok(obj && bt_value_is_bool(obj), "bt_private_value_array_append_bool_element() appends a boolean value object"); - ret = bt_value_bool_get(obj, &bool_value); - ok(!ret && !bool_value, + bool_value = bt_value_bool_get(obj); + ok(!bool_value, "bt_private_value_array_append_bool_element() appends the appropriate value"); obj = bt_value_array_borrow_element_by_index(array_obj, 5); ok(obj && bt_value_is_integer(obj), "bt_private_value_array_append_integer_element() appends an integer value object"); - ret = bt_value_integer_get(obj, &int_value); - ok(!ret && int_value == 98765, + int_value = bt_value_integer_get(obj); + ok(int_value == 98765, "bt_private_value_array_append_integer_element() appends the appropriate value"); obj = bt_value_array_borrow_element_by_index(array_obj, 6); ok(obj && bt_value_is_real(obj), "bt_private_value_array_append_real_element() appends a real number value object"); - ret = bt_value_real_get(obj, &real_value); - ok(!ret && real_value == 2.49578, + real_value = bt_value_real_get(obj); + ok(real_value == 2.49578, "bt_private_value_array_append_real_element() appends the appropriate value"); obj = bt_value_array_borrow_element_by_index(array_obj, 7); ok(obj && bt_value_is_string(obj), "bt_private_value_array_append_string_element() appends a string value object"); - ret = bt_value_string_get(obj, &string_value); + string_value = bt_value_string_get(obj); ok(!ret && string_value && !strcmp(string_value, "bt_value"), "bt_private_value_array_append_string_element() appends the appropriate value"); obj = bt_value_array_borrow_element_by_index(array_obj, 8); @@ -356,7 +348,6 @@ static bt_bool test_map_foreach_cb_check(const char *key, struct bt_value *object, void *data) { - int ret; struct map_foreach_checklist *checklist = data; if (!strcmp(key, "bt_bool")) { @@ -365,8 +356,7 @@ bt_bool test_map_foreach_cb_check(const char *key, struct bt_value *object, } else { bt_bool val = BT_FALSE; - ret = bt_value_bool_get(object, &val); - ok(!ret, "test_map_foreach_cb_check(): success getting \"bt_bool\" value"); + val = bt_value_bool_get(object); if (val) { pass("test_map_foreach_cb_check(): \"bt_bool\" value object has the right value"); @@ -381,8 +371,7 @@ bt_bool test_map_foreach_cb_check(const char *key, struct bt_value *object, } else { int64_t val = 0; - ret = bt_value_integer_get(object, &val); - ok(!ret, "test_map_foreach_cb_check(): success getting \"int\" value"); + val = bt_value_integer_get(object); if (val == 19457) { pass("test_map_foreach_cb_check(): \"int\" value object has the right value"); @@ -397,8 +386,7 @@ bt_bool test_map_foreach_cb_check(const char *key, struct bt_value *object, } else { double val = 0; - ret = bt_value_real_get(object, &val); - ok(!ret, "test_map_foreach_cb_check(): success getting \"real\" value"); + val = bt_value_real_get(object); if (val == 5.444) { pass("test_map_foreach_cb_check(): \"real\" value object has the right value"); @@ -420,8 +408,7 @@ bt_bool test_map_foreach_cb_check(const char *key, struct bt_value *object, } else { bt_bool val = BT_FALSE; - ret = bt_value_bool_get(object, &val); - ok(!ret, "test_map_foreach_cb_check(): success getting \"bool2\" value"); + val = bt_value_bool_get(object); if (val) { pass("test_map_foreach_cb_check(): \"bool2\" value object has the right value"); @@ -436,8 +423,7 @@ bt_bool test_map_foreach_cb_check(const char *key, struct bt_value *object, } else { int64_t val = 0; - ret = bt_value_integer_get(object, &val); - ok(!ret, "test_map_foreach_cb_check(): success getting \"int2\" value"); + val = bt_value_integer_get(object); if (val == 98765) { pass("test_map_foreach_cb_check(): \"int2\" value object has the right value"); @@ -452,8 +438,7 @@ bt_bool test_map_foreach_cb_check(const char *key, struct bt_value *object, } else { double val = 0; - ret = bt_value_real_get(object, &val); - ok(!ret, "test_map_foreach_cb_check(): success getting \"real2\" value"); + val = bt_value_real_get(object); if (val == -49.0001) { pass("test_map_foreach_cb_check(): \"real2\" value object has the right value"); @@ -468,8 +453,7 @@ bt_bool test_map_foreach_cb_check(const char *key, struct bt_value *object, } else { const char *val; - ret = bt_value_string_get(object, &val); - ok(!ret, "test_map_foreach_cb_check(): success getting \"string2\" value"); + val = bt_value_string_get(object); if (val && !strcmp(val, "bt_value")) { pass("test_map_foreach_cb_check(): \"string2\" value object has the right value"); @@ -554,14 +538,14 @@ void test_map(void) obj = bt_value_map_borrow_entry_value(map_obj, "real"); ok(obj && bt_value_is_real(obj), "bt_value_map_borrow_entry_value() returns an value object with the appropriate type (real)"); - ret = bt_value_real_get(obj, &real_value); - ok(!ret && real_value == 5.444, + real_value = bt_value_real_get(obj); + ok(real_value == 5.444, "bt_value_map_borrow_entry_value() returns an value object with the appropriate value (real)"); obj = bt_value_map_borrow_entry_value(map_obj, "int"); ok(obj && bt_value_is_integer(obj), "bt_value_map_borrow_entry_value() returns an value object with the appropriate type (integer)"); - ret = bt_value_integer_get(obj, &int_value); - ok(!ret && int_value == 19457, + int_value = bt_value_integer_get(obj); + ok(int_value == 19457, "bt_value_map_borrow_entry_value() returns an value object with the appropriate value (integer)"); obj = bt_value_map_borrow_entry_value(map_obj, "null"); ok(obj && bt_value_is_null(obj), @@ -569,8 +553,8 @@ void test_map(void) obj = bt_value_map_borrow_entry_value(map_obj, "bt_bool"); ok(obj && bt_value_is_bool(obj), "bt_value_map_borrow_entry_value() returns an value object with the appropriate type (boolean)"); - ret = bt_value_bool_get(obj, &bool_value); - ok(!ret && bool_value, + bool_value = bt_value_bool_get(obj); + ok(bool_value, "bt_value_map_borrow_entry_value() returns an value object with the appropriate value (boolean)"); ret = bt_private_value_map_insert_bool_entry(priv_map_obj, "bool2", @@ -935,8 +919,9 @@ void test_copy(void) bt_value_borrow_from_private(string_obj)); BT_ASSERT(status == BT_VALUE_STATUS_OK); - map_copy_obj = bt_value_copy(bt_value_borrow_from_private(map_obj)); - ok(map_copy_obj, + status = bt_value_copy(&map_copy_obj, + bt_value_borrow_from_private(map_obj)); + ok(status == BT_VALUE_STATUS_OK && map_copy_obj, "bt_value_copy() succeeds"); ok(map_obj != map_copy_obj, @@ -1026,10 +1011,12 @@ void test_extend(void) status = bt_private_value_map_insert_real_entry(extension_map, "project", -404); BT_ASSERT(status == BT_VALUE_STATUS_OK); - extended_map = bt_value_map_extend( + status = bt_value_map_extend( + &extended_map, bt_value_borrow_from_private(base_map), bt_value_borrow_from_private(extension_map)); - ok(extended_map, "bt_value_map_extend() succeeds"); + ok(status == BT_VALUE_STATUS_OK && + extended_map, "bt_value_map_extend() succeeds"); ok(bt_value_map_get_size( bt_value_borrow_from_private(extended_map)) == 5, "bt_value_map_extend() returns a map object with the correct size"); diff --git a/tests/lib/test_ctf_writer.c b/tests/lib/test_ctf_writer.c index 8be17894..8e6df9e5 100644 --- a/tests/lib/test_ctf_writer.c +++ b/tests/lib/test_ctf_writer.c @@ -1707,13 +1707,13 @@ int main(int argc, char **argv) /* Test bt_ctf_trace_get_environment_field_value */ obj = bt_ctf_trace_get_environment_field_value_by_index(trace, 1); - ret = bt_value_integer_get(obj, &ret_int64_t); - ok(!ret && ret_int64_t == -164973, + ret_int64_t = bt_value_integer_get(obj); + ok(ret_int64_t == -164973, "bt_ctf_trace_get_environment_field_value succeeds in getting an integer value"); BT_OBJECT_PUT_REF_AND_RESET(obj); obj = bt_ctf_trace_get_environment_field_value_by_index(trace, 2); - ret = bt_value_string_get(obj, &ret_string); - ok(!ret && ret_string && !strcmp(ret_string, "oh yeah"), + ret_string = bt_value_string_get(obj); + ok(ret_string && !strcmp(ret_string, "oh yeah"), "bt_ctf_trace_get_environment_field_value succeeds in getting a string value"); BT_OBJECT_PUT_REF_AND_RESET(obj); @@ -1722,8 +1722,8 @@ int main(int argc, char **argv) "bt_ctf_trace_get_environment_field_value_by_name returns NULL or an unknown field name"); obj = bt_ctf_trace_get_environment_field_value_by_name(trace, "test_env_str"); - ret = bt_value_string_get(obj, &ret_string); - ok(!ret && ret_string && !strcmp(ret_string, "oh yeah"), + ret_string = bt_value_string_get(obj); + ok(ret_string && !strcmp(ret_string, "oh yeah"), "bt_ctf_trace_get_environment_field_value_by_name succeeds in getting an existing field"); BT_OBJECT_PUT_REF_AND_RESET(obj); @@ -1734,8 +1734,8 @@ int main(int argc, char **argv) ok(bt_ctf_trace_get_environment_field_count(trace) == 3, "bt_ctf_trace_set_environment_field_integer with an existing key does not increase the environment size"); obj = bt_ctf_trace_get_environment_field_value_by_index(trace, 1); - ret = bt_value_integer_get(obj, &ret_int64_t); - ok(!ret && ret_int64_t == 654321, + ret_int64_t = bt_value_integer_get(obj); + ok(ret_int64_t == 654321, "bt_ctf_trace_get_environment_field_value successfully replaces an existing field"); BT_OBJECT_PUT_REF_AND_RESET(obj); diff --git a/tests/lib/test_plugin.c b/tests/lib/test_plugin.c index 5e57232b..c11fd12f 100644 --- a/tests/lib/test_plugin.c +++ b/tests/lib/test_plugin.c @@ -168,7 +168,6 @@ static void test_sfs(const char *plugin_dir) struct bt_value *res_params; struct bt_graph *graph; const char *object_str; - enum bt_value_status value_ret; enum bt_graph_status graph_ret; struct bt_query_executor *query_exec = bt_query_executor_create(); int ret; @@ -235,8 +234,7 @@ static void test_sfs(const char *plugin_dir) BT_ASSERT(bt_value_is_array(results) && bt_value_array_get_size(results) == 2); object = bt_value_array_borrow_element_by_index(results, 0); BT_ASSERT(object && bt_value_is_string(object)); - value_ret = bt_value_string_get(object, &object_str); - BT_ASSERT(value_ret == BT_VALUE_STATUS_OK); + object_str = bt_value_string_get(object); ok(strcmp(object_str, "get-something") == 0, "bt_component_class_query() receives the expected object name"); res_params = bt_value_array_borrow_element_by_index(results, 1); -- 2.34.1