From 44514773a92ed494fc9dc8637edcdaa3359baa54 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Thu, 15 Nov 2018 15:34:32 -0500 Subject: [PATCH] Values API: standardize function names Make them look more like the rest of the API. Signed-off-by: Philippe Proulx --- cli/babeltrace-cfg-cli-args-connect.c | 16 +- cli/babeltrace-cfg-cli-args.c | 136 ++++----- cli/babeltrace-cfg.c | 2 +- cli/babeltrace.c | 112 +++---- include/babeltrace/ref.h | 2 +- include/babeltrace/values.h | 196 +++++------- lib/ctf-writer/attributes.c | 36 +-- lib/lib-logging.c | 4 +- lib/trace-ir/attributes.c | 36 +-- lib/values.c | 100 +++---- plugins/ctf/fs-src/fs.c | 6 +- plugins/ctf/fs-src/query.c | 32 +- plugins/ctf/lttng-live/viewer-connection.c | 16 +- plugins/text/dmesg/dmesg.c | 9 +- plugins/text/pretty/pretty.c | 14 +- plugins/utils/counter/counter.c | 4 +- plugins/utils/muxer/muxer.c | 4 +- tests/lib/test-plugin-plugins/sfs.c | 4 +- tests/lib/test_bt_values.c | 331 ++++++++++----------- tests/lib/test_plugin.c | 8 +- 20 files changed, 484 insertions(+), 584 deletions(-) diff --git a/cli/babeltrace-cfg-cli-args-connect.c b/cli/babeltrace-cfg-cli-args-connect.c index 13c91293..e9e8691a 100644 --- a/cli/babeltrace-cfg-cli-args-connect.c +++ b/cli/babeltrace-cfg-cli-args-connect.c @@ -515,7 +515,7 @@ static int validate_all_components_connected_in_array(GPtrArray *comps, for (i = 0; i < comps->len; i++) { struct bt_config_component *comp = g_ptr_array_index(comps, i); - if (!bt_value_map_has_key(connected_components, + if (!bt_value_map_has_entry(connected_components, comp->instance_name->str)) { snprintf(error_buf, error_buf_size, "Component `%s` is not connected\n", @@ -545,13 +545,13 @@ static int validate_all_components_connected(struct bt_config *cfg, struct bt_config_connection *connection = g_ptr_array_index(cfg->cmd_data.run.connections, i); - ret = bt_value_map_insert(connected_components, + ret = bt_value_map_insert_entry(connected_components, connection->upstream_comp_name->str, bt_value_null); if (ret) { goto end; } - ret = bt_value_map_insert(connected_components, + ret = bt_value_map_insert_entry(connected_components, connection->downstream_comp_name->str, bt_value_null); if (ret) { goto end; @@ -613,7 +613,7 @@ static int validate_no_duplicate_connection(struct bt_config *cfg, connection->downstream_comp_name->str, connection->downstream_port_glob->str); - if (bt_value_map_has_key(flat_connection_names, + if (bt_value_map_has_entry(flat_connection_names, flat_connection_name->str)) { snprintf(error_buf, error_buf_size, "Duplicate connection:\n %s\n", @@ -622,7 +622,7 @@ static int validate_no_duplicate_connection(struct bt_config *cfg, goto end; } - ret = bt_value_map_insert(flat_connection_names, + ret = bt_value_map_insert_entry(flat_connection_names, flat_connection_name->str, bt_value_null); if (ret) { goto end; @@ -686,14 +686,14 @@ int bt_config_cli_args_create_connections(struct bt_config *cfg, goto error; } - for (i = 0; i < bt_value_array_size(connection_args); i++) { + for (i = 0; i < bt_value_array_get_size(connection_args); i++) { struct bt_value *arg_value = - bt_value_array_get(connection_args, i); + bt_value_array_borrow_element_by_index( + connection_args, i); const char *arg; struct bt_config_connection *cfg_connection; ret = bt_value_string_get(arg_value, &arg); - BT_PUT(arg_value); BT_ASSERT(ret == 0); cfg_connection = cfg_connection_from_arg(arg); if (!cfg_connection) { diff --git a/cli/babeltrace-cfg-cli-args.c b/cli/babeltrace-cfg-cli-args.c index f15455c7..145333a6 100644 --- a/cli/babeltrace-cfg-cli-args.c +++ b/cli/babeltrace-cfg-cli-args.c @@ -241,7 +241,7 @@ int ini_handle_state(struct ini_parsing_state *state) goto error; } - if (bt_value_map_has_key(state->params, state->last_map_key)) { + if (bt_value_map_has_entry(state->params, state->last_map_key)) { g_string_append_printf(state->ini_error, "Duplicate parameter key: `%s`\n", state->last_map_key); @@ -414,7 +414,7 @@ error: success: if (value) { - if (bt_value_map_insert(state->params, + if (bt_value_map_insert_entry(state->params, state->last_map_key, value)) { /* Only override return value on error */ ret = -1; @@ -1041,33 +1041,33 @@ struct bt_value *names_from_arg(const char *arg) !strcmp(identifier, "args") || !strcmp(identifier, "arg")) { found_item = true; - if (bt_value_array_append_string(names, + if (bt_value_array_append_string_element(names, "payload")) { goto error; } } else if (!strcmp(identifier, "context") || !strcmp(identifier, "ctx")) { found_item = true; - if (bt_value_array_append_string(names, + if (bt_value_array_append_string_element(names, "context")) { goto error; } } else if (!strcmp(identifier, "scope") || !strcmp(identifier, "header")) { found_item = true; - if (bt_value_array_append_string(names, + if (bt_value_array_append_string_element(names, identifier)) { goto error; } } else if (!strcmp(identifier, "all")) { found_all = true; - if (bt_value_array_append_string(names, + if (bt_value_array_append_string_element(names, identifier)) { goto error; } } else if (!strcmp(identifier, "none")) { found_none = true; - if (bt_value_array_append_string(names, + if (bt_value_array_append_string_element(names, identifier)) { goto error; } @@ -1097,7 +1097,7 @@ end: * least one item is specified. */ if (found_item && !found_none && !found_all) { - if (bt_value_array_append_string(names, "none")) { + if (bt_value_array_append_string_element(names, "none")) { goto error; } } @@ -1157,7 +1157,7 @@ struct bt_value *fields_from_arg(const char *arg) !strcmp(identifier, "emf") || !strcmp(identifier, "callsite") || !strcmp(identifier, "all")) { - if (bt_value_array_append_string(fields, + if (bt_value_array_append_string_element(fields, identifier)) { goto error; } @@ -1240,8 +1240,9 @@ int insert_flat_params_from_array(GString *params_arg, goto end; } - for (i = 0; i < bt_value_array_size(names_array); i++) { - struct bt_value *str_obj = bt_value_array_get(names_array, i); + for (i = 0; i < bt_value_array_get_size(names_array); i++) { + struct bt_value *str_obj = + bt_value_array_borrow_element_by_index(names_array, i); const char *suffix; bool is_default = false; @@ -1252,7 +1253,6 @@ int insert_flat_params_from_array(GString *params_arg, } ret = bt_value_string_get(str_obj, &suffix); - BT_PUT(str_obj); if (ret) { printf_err("Unexpected error\n"); goto end; @@ -1395,14 +1395,14 @@ int add_run_cfg_comp_check_name(struct bt_config *cfg, goto end; } - if (bt_value_map_has_key(instance_names, cfg_comp->instance_name->str)) { + if (bt_value_map_has_entry(instance_names, cfg_comp->instance_name->str)) { printf_err("Duplicate component instance name:\n %s\n", cfg_comp->instance_name->str); ret = -1; goto end; } - if (bt_value_map_insert(instance_names, + if (bt_value_map_insert_entry(instance_names, cfg_comp->instance_name->str, bt_value_null)) { print_err_oom(); ret = -1; @@ -2565,7 +2565,7 @@ struct bt_config *bt_config_run_from_args(int argc, const char *argv[], goto error; } - if (bt_value_map_insert_string(cur_cfg_comp->params, + if (bt_value_map_insert_string_entry(cur_cfg_comp->params, cur_param_key->str, arg)) { print_err_oom(); goto error; @@ -2602,8 +2602,8 @@ struct bt_config *bt_config_run_from_args(int argc, const char *argv[], } break; case OPT_CONNECT: - if (bt_value_array_append_string(connection_args, - arg)) { + if (bt_value_array_append_string_element( + connection_args, arg)) { print_err_oom(); goto error; } @@ -2709,7 +2709,7 @@ struct bt_config *bt_config_run_from_args_array(struct bt_value *run_args, struct bt_config *cfg = NULL; const char **argv; int64_t i, len; - const size_t argc = bt_value_array_size(run_args) + 1; + const size_t argc = bt_value_array_get_size(run_args) + 1; argv = calloc(argc, sizeof(*argv)); if (!argv) { @@ -2719,14 +2719,15 @@ struct bt_config *bt_config_run_from_args_array(struct bt_value *run_args, argv[0] = "run"; - len = bt_value_array_size(run_args); + len = bt_value_array_get_size(run_args); if (len < 0) { printf_err("Invalid executable arguments\n"); goto end; } for (i = 0; i < len; i++) { int ret; - struct bt_value *arg_value = bt_value_array_get(run_args, i); + struct bt_value *arg_value = + bt_value_array_borrow_element_by_index(run_args, i); const char *arg; BT_ASSERT(arg_value); @@ -2734,7 +2735,6 @@ struct bt_config *bt_config_run_from_args_array(struct bt_value *run_args, BT_ASSERT(ret == 0); BT_ASSERT(arg); argv[i + 1] = arg; - bt_put(arg_value); } cfg = bt_config_run_from_args(argc, argv, retcode, @@ -2936,7 +2936,7 @@ GString *get_component_auto_name(const char *prefix, goto end; } - if (!bt_value_map_has_key(existing_names, prefix)) { + if (!bt_value_map_has_entry(existing_names, prefix)) { g_string_assign(auto_name, prefix); goto end; } @@ -2944,7 +2944,7 @@ GString *get_component_auto_name(const char *prefix, do { g_string_printf(auto_name, "%s-%d", prefix, i); i++; - } while (bt_value_map_has_key(existing_names, auto_name->str)); + } while (bt_value_map_has_entry(existing_names, auto_name->str)); end: return auto_name; @@ -2979,7 +2979,7 @@ int assign_name_to_implicit_component(struct implicit_component_args *args, g_string_assign(args->name_arg, name->str); - if (bt_value_map_insert(existing_names, name->str, + if (bt_value_map_insert_entry(existing_names, name->str, bt_value_null)) { print_err_oom(); ret = -1; @@ -3011,44 +3011,45 @@ int append_run_args_for_implicit_component( goto end; } - if (bt_value_array_append_string(run_args, "--component")) { + if (bt_value_array_append_string_element(run_args, "--component")) { print_err_oom(); goto error; } - if (bt_value_array_append_string(run_args, impl_args->comp_arg->str)) { + if (bt_value_array_append_string_element(run_args, impl_args->comp_arg->str)) { print_err_oom(); goto error; } - if (bt_value_array_append_string(run_args, "--name")) { + if (bt_value_array_append_string_element(run_args, "--name")) { print_err_oom(); goto error; } - if (bt_value_array_append_string(run_args, impl_args->name_arg->str)) { + if (bt_value_array_append_string_element(run_args, impl_args->name_arg->str)) { print_err_oom(); goto error; } if (impl_args->params_arg->len > 0) { - if (bt_value_array_append_string(run_args, "--params")) { + if (bt_value_array_append_string_element(run_args, "--params")) { print_err_oom(); goto error; } - if (bt_value_array_append_string(run_args, + if (bt_value_array_append_string_element(run_args, impl_args->params_arg->str)) { print_err_oom(); goto error; } } - for (i = 0; i < bt_value_array_size(impl_args->extra_params); i++) { + for (i = 0; i < bt_value_array_get_size(impl_args->extra_params); i++) { struct bt_value *elem; const char *arg; - elem = bt_value_array_get(impl_args->extra_params, i); + elem = bt_value_array_borrow_element_by_index( + impl_args->extra_params, i); if (!elem) { goto error; } @@ -3058,8 +3059,7 @@ int append_run_args_for_implicit_component( goto error; } - ret = bt_value_array_append_string(run_args, arg); - bt_put(elem); + ret = bt_value_array_append_string_element(run_args, arg); if (ret) { print_err_oom(); goto error; @@ -3150,25 +3150,25 @@ int append_implicit_component_extra_param(struct implicit_component_args *args, BT_ASSERT(key); BT_ASSERT(value); - if (bt_value_array_append_string(args->extra_params, "--key")) { + if (bt_value_array_append_string_element(args->extra_params, "--key")) { print_err_oom(); ret = -1; goto end; } - if (bt_value_array_append_string(args->extra_params, key)) { + if (bt_value_array_append_string_element(args->extra_params, key)) { print_err_oom(); ret = -1; goto end; } - if (bt_value_array_append_string(args->extra_params, "--value")) { + if (bt_value_array_append_string_element(args->extra_params, "--value")) { print_err_oom(); ret = -1; goto end; } - if (bt_value_array_append_string(args->extra_params, value)) { + if (bt_value_array_append_string_element(args->extra_params, value)) { print_err_oom(); ret = -1; goto end; @@ -3205,7 +3205,7 @@ int convert_append_name_param(enum bt_config_component_dest dest, * An explicit name was provided for the user * component. */ - if (bt_value_map_has_key(all_names, + if (bt_value_map_has_entry(all_names, cur_name->str)) { printf_err("Duplicate component instance name:\n %s\n", cur_name->str); @@ -3224,7 +3224,7 @@ int convert_append_name_param(enum bt_config_component_dest dest, * Remember this name globally, for the uniqueness of * all component names. */ - if (bt_value_map_insert(all_names, name->str, bt_value_null)) { + if (bt_value_map_insert_entry(all_names, name->str, bt_value_null)) { print_err_oom(); goto error; } @@ -3233,12 +3233,12 @@ int convert_append_name_param(enum bt_config_component_dest dest, * Append the --name option if necessary. */ if (append_name_opt) { - if (bt_value_array_append_string(run_args, "--name")) { + if (bt_value_array_append_string_element(run_args, "--name")) { print_err_oom(); goto error; } - if (bt_value_array_append_string(run_args, name->str)) { + if (bt_value_array_append_string_element(run_args, name->str)) { print_err_oom(); goto error; } @@ -3320,7 +3320,7 @@ int append_connect_arg(struct bt_value *run_args, goto end; } - ret = bt_value_array_append_string(run_args, "--connect"); + ret = bt_value_array_append_string_element(run_args, "--connect"); if (ret) { print_err_oom(); ret = -1; @@ -3330,7 +3330,7 @@ int append_connect_arg(struct bt_value *run_args, g_string_append(arg, e_upstream_name->str); g_string_append_c(arg, ':'); g_string_append(arg, e_downstream_name->str); - ret = bt_value_array_append_string(run_args, arg->str); + ret = bt_value_array_append_string_element(run_args, arg->str); if (ret) { print_err_oom(); ret = -1; @@ -3776,13 +3776,13 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[], abort(); } - if (bt_value_array_append_string(run_args, + if (bt_value_array_append_string_element(run_args, "--component")) { print_err_oom(); goto error; } - if (bt_value_array_append_string(run_args, arg)) { + if (bt_value_array_append_string_element(run_args, arg)) { print_err_oom(); goto error; } @@ -3805,13 +3805,13 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[], goto error; } - if (bt_value_array_append_string(run_args, + if (bt_value_array_append_string_element(run_args, "--params")) { print_err_oom(); goto error; } - if (bt_value_array_append_string(run_args, arg)) { + if (bt_value_array_append_string_element(run_args, arg)) { print_err_oom(); goto error; } @@ -3823,22 +3823,22 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[], goto error; } - if (bt_value_array_append_string(run_args, "--key")) { + if (bt_value_array_append_string_element(run_args, "--key")) { print_err_oom(); goto error; } - if (bt_value_array_append_string(run_args, "path")) { + if (bt_value_array_append_string_element(run_args, "path")) { print_err_oom(); goto error; } - if (bt_value_array_append_string(run_args, "--value")) { + if (bt_value_array_append_string_element(run_args, "--value")) { print_err_oom(); goto error; } - if (bt_value_array_append_string(run_args, arg)) { + if (bt_value_array_append_string_element(run_args, arg)) { print_err_oom(); goto error; } @@ -3850,22 +3850,22 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[], goto error; } - if (bt_value_array_append_string(run_args, "--key")) { + if (bt_value_array_append_string_element(run_args, "--key")) { print_err_oom(); goto error; } - if (bt_value_array_append_string(run_args, "url")) { + if (bt_value_array_append_string_element(run_args, "url")) { print_err_oom(); goto error; } - if (bt_value_array_append_string(run_args, "--value")) { + if (bt_value_array_append_string_element(run_args, "--value")) { print_err_oom(); goto error; } - if (bt_value_array_append_string(run_args, arg)) { + if (bt_value_array_append_string_element(run_args, arg)) { print_err_oom(); goto error; } @@ -3877,12 +3877,12 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[], goto error; } - if (bt_value_array_append_string(run_args, "--name")) { + if (bt_value_array_append_string_element(run_args, "--name")) { print_err_oom(); goto error; } - if (bt_value_array_append_string(run_args, arg)) { + if (bt_value_array_append_string_element(run_args, arg)) { print_err_oom(); goto error; } @@ -3892,20 +3892,20 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[], case OPT_OMIT_HOME_PLUGIN_PATH: force_omit_home_plugin_path = true; - if (bt_value_array_append_string(run_args, + if (bt_value_array_append_string_element(run_args, "--omit-home-plugin-path")) { print_err_oom(); goto error; } break; case OPT_RETRY_DURATION: - if (bt_value_array_append_string(run_args, + if (bt_value_array_append_string_element(run_args, "--retry-duration")) { print_err_oom(); goto error; } - if (bt_value_array_append_string(run_args, arg)) { + if (bt_value_array_append_string_element(run_args, arg)) { print_err_oom(); goto error; } @@ -3913,7 +3913,7 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[], case OPT_OMIT_SYSTEM_PLUGIN_PATH: force_omit_system_plugin_path = true; - if (bt_value_array_append_string(run_args, + if (bt_value_array_append_string_element(run_args, "--omit-system-plugin-path")) { print_err_oom(); goto error; @@ -3925,13 +3925,13 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[], goto error; } - if (bt_value_array_append_string(run_args, + if (bt_value_array_append_string_element(run_args, "--plugin-path")) { print_err_oom(); goto error; } - if (bt_value_array_append_string(run_args, arg)) { + if (bt_value_array_append_string_element(run_args, arg)) { print_err_oom(); goto error; } @@ -4667,9 +4667,10 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[], goto error; } - for (i = 0; i < bt_value_array_size(run_args); i++) { + for (i = 0; i < bt_value_array_get_size(run_args); i++) { struct bt_value *arg_value = - bt_value_array_get(run_args, i); + bt_value_array_borrow_element_by_index( + run_args, i); const char *arg; GString *quoted = NULL; const char *arg_to_print; @@ -4677,7 +4678,6 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[], BT_ASSERT(arg_value); ret = bt_value_string_get(arg_value, &arg); BT_ASSERT(ret == 0); - BT_PUT(arg_value); if (print_run_args) { quoted = bt_common_shell_quote(arg, true); @@ -4696,7 +4696,7 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[], g_string_free(quoted, TRUE); } - if (i < bt_value_array_size(run_args) - 1) { + if (i < bt_value_array_get_size(run_args) - 1) { if (print_run_args) { putchar(' '); } else { diff --git a/cli/babeltrace-cfg.c b/cli/babeltrace-cfg.c index 772cd5a5..759ce377 100644 --- a/cli/babeltrace-cfg.c +++ b/cli/babeltrace-cfg.c @@ -59,7 +59,7 @@ enum bt_value_status bt_config_append_plugin_paths( for (i = 0; i < dirs->len; i++) { GString *dir = g_ptr_array_index(dirs, i); - status = bt_value_array_append_string(plugin_paths, dir->str); + status = bt_value_array_append_string_element(plugin_paths, dir->str); if (status != BT_VALUE_STATUS_OK) { break; } diff --git a/cli/babeltrace.c b/cli/babeltrace.c index 57a477a6..2d273bd1 100644 --- a/cli/babeltrace.c +++ b/cli/babeltrace.c @@ -487,7 +487,7 @@ void print_value_rec(FILE *fp, struct bt_value *value, size_t indent) bt_common_color_reset()); break; case BT_VALUE_TYPE_ARRAY: - size = bt_value_array_size(value); + size = bt_value_array_get_size(value); if (size < 0) { goto error; } @@ -500,7 +500,8 @@ void print_value_rec(FILE *fp, struct bt_value *value, size_t indent) for (i = 0; i < size; i++) { struct bt_value *element = - bt_value_array_get(value, i); + bt_value_array_borrow_element_by_index( + value, i); if (!element) { goto error; @@ -526,7 +527,6 @@ void print_value_rec(FILE *fp, struct bt_value *value, size_t indent) } print_value_rec(fp, element, indent + 2); - BT_PUT(element); } break; case BT_VALUE_TYPE_MAP: @@ -542,7 +542,7 @@ void print_value_rec(FILE *fp, struct bt_value *value, size_t indent) break; } - bt_value_map_foreach(value, print_map_value, &data); + bt_value_map_foreach_entry(value, print_map_value, &data); break; } default: @@ -749,7 +749,7 @@ int load_dynamic_plugins(struct bt_value *plugin_paths) { int nr_paths, i, ret = 0; - nr_paths = bt_value_array_size(plugin_paths); + nr_paths = bt_value_array_get_size(plugin_paths); if (nr_paths < 0) { BT_LOGE_STR("Cannot load dynamic plugins: no plugin path."); ret = -1; @@ -764,11 +764,11 @@ int load_dynamic_plugins(struct bt_value *plugin_paths) struct bt_plugin_set *plugin_set; enum bt_value_status status; - plugin_path_value = bt_value_array_get(plugin_paths, i); + 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."); - BT_PUT(plugin_path_value); continue; } @@ -780,7 +780,6 @@ int load_dynamic_plugins(struct bt_value *plugin_paths) if (!g_file_test(plugin_path, G_FILE_TEST_IS_DIR)) { BT_LOGV("Skipping nonexistent directory path: " "path=\"%s\"", plugin_path); - BT_PUT(plugin_path_value); continue; } @@ -788,13 +787,11 @@ int load_dynamic_plugins(struct bt_value *plugin_paths) if (!plugin_set) { BT_LOGD("Unable to load dynamic plugins: path=\"%s\"", plugin_path); - BT_PUT(plugin_path_value); continue; } add_to_loaded_plugins(plugin_set); bt_put(plugin_set); - BT_PUT(plugin_path_value); } end: return ret; @@ -1182,7 +1179,7 @@ int cmd_print_lttng_live_sessions(struct bt_config *cfg) goto error; } - ret = bt_value_map_insert_string(params, "url", + ret = bt_value_map_insert_string_entry(params, "url", cfg->cmd_data.print_lttng_live_sessions.url->str); if (ret) { goto error; @@ -1217,12 +1214,12 @@ int cmd_print_lttng_live_sessions(struct bt_config *cfg) } } - array_size = bt_value_array_size(results); + array_size = bt_value_array_get_size(results); for (i = 0; i < array_size; i++) { const char *url_text; int64_t timer_us, streams, clients; - map = bt_value_array_get(results, i); + map = bt_value_array_borrow_element_by_index(results, i); if (!map) { BT_LOGE_STR("Unexpected empty array entry."); goto error; @@ -1232,7 +1229,7 @@ int cmd_print_lttng_live_sessions(struct bt_config *cfg) goto error; } - v = bt_value_map_get(map, "url"); + v = bt_value_map_borrow_entry_value(map, "url"); if (!v) { BT_LOGE_STR("Unexpected empty array \"url\" entry."); goto error; @@ -1240,9 +1237,7 @@ int cmd_print_lttng_live_sessions(struct bt_config *cfg) ret = bt_value_string_get(v, &url_text); BT_ASSERT(ret == 0); fprintf(out_stream, "%s", url_text); - BT_PUT(v); - - v = bt_value_map_get(map, "timer-us"); + v = bt_value_map_borrow_entry_value(map, "timer-us"); if (!v) { BT_LOGE_STR("Unexpected empty array \"timer-us\" entry."); goto error; @@ -1250,9 +1245,7 @@ int cmd_print_lttng_live_sessions(struct bt_config *cfg) ret = bt_value_integer_get(v, &timer_us); BT_ASSERT(ret == 0); fprintf(out_stream, " (timer = %" PRIu64 ", ", timer_us); - BT_PUT(v); - - v = bt_value_map_get(map, "stream-count"); + v = bt_value_map_borrow_entry_value(map, "stream-count"); if (!v) { BT_LOGE_STR("Unexpected empty array \"stream-count\" entry."); goto error; @@ -1260,9 +1253,7 @@ int cmd_print_lttng_live_sessions(struct bt_config *cfg) ret = bt_value_integer_get(v, &streams); BT_ASSERT(ret == 0); fprintf(out_stream, "%" PRIu64 " stream(s), ", streams); - BT_PUT(v); - - v = bt_value_map_get(map, "client-count"); + v = bt_value_map_borrow_entry_value(map, "client-count"); if (!v) { BT_LOGE_STR("Unexpected empty array \"client-count\" entry."); goto error; @@ -1270,9 +1261,6 @@ int cmd_print_lttng_live_sessions(struct bt_config *cfg) ret = bt_value_integer_get(v, &clients); BT_ASSERT(ret == 0); fprintf(out_stream, "%" PRIu64 " client(s) connected)\n", clients); - BT_PUT(v); - - BT_PUT(map); } goto end; @@ -1289,8 +1277,6 @@ error: ret = -1; end: - bt_put(v); - bt_put(map); bt_put(results); bt_put(params); bt_put(comp_cls); @@ -1349,7 +1335,7 @@ int cmd_print_ctf_metadata(struct bt_config *cfg) goto end; } - ret = bt_value_map_insert_string(params, "path", + ret = bt_value_map_insert_string_entry(params, "path", cfg->cmd_data.print_ctf_metadata.path->str); if (ret) { ret = -1; @@ -1361,7 +1347,7 @@ int cmd_print_ctf_metadata(struct bt_config *cfg) goto failed; } - metadata_text_value = bt_value_map_get(results, "text"); + metadata_text_value = bt_value_map_borrow_entry_value(results, "text"); if (!metadata_text_value) { BT_LOGE_STR("Cannot find `text` string value in the resulting metadata info object."); ret = -1; @@ -1405,7 +1391,6 @@ end: destroy_the_query_executor(); bt_put(results); bt_put(params); - bt_put(metadata_text_value); bt_put(comp_cls); if (out_stream && out_stream != stdout) { @@ -1589,12 +1574,13 @@ int cmd_run_ctx_connect_upstream_port_to_downstream_component( goto error; } - status = bt_value_map_insert_string(trimmer_params, - "begin", intersection_begin); + status = bt_value_map_insert_string_entry( + trimmer_params, "begin", intersection_begin); if (status != BT_VALUE_STATUS_OK) { goto error; } - status = bt_value_map_insert_string(trimmer_params, + status = bt_value_map_insert_string_entry( + trimmer_params, "end", intersection_end); if (status != BT_VALUE_STATUS_OK) { goto error; @@ -2123,7 +2109,8 @@ int set_stream_intersections(struct cmd_run_ctx *ctx, struct trace_range *trace_range = NULL; const char *fail_reason = NULL; - component_path_value = bt_value_map_get(cfg_comp->params, "path"); + component_path_value = bt_value_map_borrow_entry_value(cfg_comp->params, + "path"); 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); @@ -2146,7 +2133,8 @@ int set_stream_intersections(struct cmd_run_ctx *ctx, goto error; } - value_status = bt_value_map_insert(query_params, "path", component_path_value); + value_status = bt_value_map_insert_entry(query_params, "path", + component_path_value); if (value_status != BT_VALUE_STATUS_OK) { BT_LOGE_STR("Cannot insert path parameter in query parameter map."); ret = -1; @@ -2173,7 +2161,7 @@ int set_stream_intersections(struct cmd_run_ctx *ctx, goto error; } - trace_count = bt_value_array_size(query_result); + trace_count = bt_value_array_get_size(query_result); if (trace_count < 0) { ret = -1; goto error; @@ -2184,14 +2172,15 @@ int set_stream_intersections(struct cmd_run_ctx *ctx, uint64_t stream_idx; int64_t stream_count; - trace_info = bt_value_array_get(query_result, trace_idx); + trace_info = bt_value_array_borrow_element_by_index( + query_result, trace_idx); if (!trace_info || !bt_value_is_map(trace_info)) { ret = -1; BT_LOGD_STR("Cannot retrieve trace from query result."); goto error; } - intersection_range = bt_value_map_get(trace_info, + intersection_range = bt_value_map_borrow_entry_value(trace_info, "intersection-range-ns"); if (!intersection_range) { ret = -1; @@ -2199,16 +2188,16 @@ int set_stream_intersections(struct cmd_run_ctx *ctx, goto error; } - intersection_begin = bt_value_map_get(intersection_range, - "begin"); + intersection_begin = bt_value_map_borrow_entry_value( + intersection_range, "begin"); if (!intersection_begin) { ret = -1; BT_LOGD_STR("Cannot retrieve intersection-range-ns \'begin\' field from query result."); goto error; } - intersection_end = bt_value_map_get(intersection_range, - "end"); + intersection_end = bt_value_map_borrow_entry_value( + intersection_range, "end"); if (!intersection_end) { ret = -1; BT_LOGD_STR("Cannot retrieve intersection-range-ns \'end\' field from query result."); @@ -2238,14 +2227,15 @@ int set_stream_intersections(struct cmd_run_ctx *ctx, goto error; } - stream_infos = bt_value_map_get(trace_info, "streams"); + stream_infos = bt_value_map_borrow_entry_value(trace_info, + "streams"); if (!stream_infos || !bt_value_is_array(stream_infos)) { ret = -1; BT_LOGD_STR("Cannot retrieve stream information from trace in query result."); goto error; } - stream_count = bt_value_array_size(stream_infos); + stream_count = bt_value_array_get_size(stream_infos); if (stream_count < 0) { ret = -1; goto error; @@ -2288,22 +2278,25 @@ int set_stream_intersections(struct cmd_run_ctx *ctx, trace_range->intersection_range_begin_ns = begin; trace_range->intersection_range_end_ns = end; - stream_info = bt_value_array_get(stream_infos, - stream_idx); + stream_info = bt_value_array_borrow_element_by_index( + stream_infos, stream_idx); if (!stream_info || !bt_value_is_map(stream_info)) { ret = -1; BT_LOGD_STR("Cannot retrieve stream informations from trace in query result."); goto error; } - stream_paths = bt_value_map_get(stream_info, "paths"); + stream_paths = bt_value_map_borrow_entry_value( + stream_info, "paths"); if (!stream_paths || !bt_value_is_array(stream_paths)) { ret = -1; BT_LOGD_STR("Cannot retrieve stream paths from trace in query result."); goto error; } - stream_path_value = bt_value_array_get(stream_paths, 0); + stream_path_value = + bt_value_array_borrow_element_by_index( + stream_paths, 0); if (!stream_path_value || !bt_value_is_string(stream_path_value)) { ret = -1; @@ -2331,19 +2324,7 @@ int set_stream_intersections(struct cmd_run_ctx *ctx, port_id = NULL; trace_range = NULL; - BT_PUT(stream_info); - BT_PUT(stream_paths); - BT_PUT(stream_path_value); } - - BT_PUT(trace_info); - BT_PUT(stream_paths); - BT_PUT(stream_path_value); - BT_PUT(intersection_range); - BT_PUT(intersection_begin); - BT_PUT(intersection_end); - BT_PUT(stream_paths); - BT_PUT(stream_path_value); } goto end; @@ -2355,17 +2336,8 @@ error: path ? path : "(unknown)", bt_common_color_reset()); end: - bt_put(component_path_value); bt_put(query_params); bt_put(query_result); - bt_put(trace_info); - bt_put(intersection_range); - bt_put(intersection_begin); - bt_put(intersection_end); - bt_put(stream_infos); - bt_put(stream_info); - bt_put(stream_paths); - bt_put(stream_path_value); g_free(port_id); g_free(trace_range); return ret; diff --git a/include/babeltrace/ref.h b/include/babeltrace/ref.h index fe266ec3..bea62028 100644 --- a/include/babeltrace/ref.h +++ b/include/babeltrace/ref.h @@ -83,7 +83,7 @@ The Babeltrace C API complies with the following key principles: @image html ref-count-callback.png - For example, see bt_value_map_foreach(). + For example, see bt_value_map_foreach_entry(). The two macros BT_PUT() and BT_MOVE() operate on \em variables rather than pointer values. You should use BT_PUT() instead of bt_put() when diff --git a/include/babeltrace/values.h b/include/babeltrace/values.h index 0e03596a..5139773c 100644 --- a/include/babeltrace/values.h +++ b/include/babeltrace/values.h @@ -63,8 +63,8 @@ functions documented here, you can create and modify: As with any Babeltrace object, value objects have reference -counts. When you \link bt_value_array_append() append a value object -to an array value object\endlink, or when you \link bt_value_map_insert() +counts. When you \link bt_value_array_append_element() append a value object +to an array value object\endlink, or when you \link bt_value_map_insert_entry() insert a value object into a map value object\endlink, its reference count is incremented, as well as when you get a value object back from those objects. See \ref refs to learn more about the reference counting @@ -132,14 +132,14 @@ to use for each value object type: bt_value_array_create() bt_value_is_array() bt_value_array_get() - bt_value_array_append()
- bt_value_array_append_bool()
- bt_value_array_append_integer()
- bt_value_array_append_float()
- bt_value_array_append_string()
- bt_value_array_append_empty_array()
- bt_value_array_append_empty_map()
- bt_value_array_set() + bt_value_array_append_element()
+ bt_value_array_append_bool_element()
+ bt_value_array_append_integer_element()
+ bt_value_array_append_element_float()
+ bt_value_array_append_string_element()
+ bt_value_array_append_empty_array_element()
+ bt_value_array_append_empty_map_element()
+ bt_value_array_set_element_by_index() Map @@ -147,14 +147,14 @@ to use for each value object type: bt_value_map_extend() bt_value_is_map() bt_value_map_get()
- bt_value_map_foreach() - bt_value_map_insert()
- bt_value_map_insert_bool()
- bt_value_map_insert_integer()
- bt_value_map_insert_float()
- bt_value_map_insert_string()
- bt_value_map_insert_empty_array()
- bt_value_map_insert_empty_map() + bt_value_map_foreach_entry() + bt_value_map_insert_entry()
+ bt_value_map_insert_bool_entry()
+ bt_value_map_insert_integer_entry()
+ bt_value_map_insert_float_entry()
+ bt_value_map_insert_string_entry()
+ bt_value_map_insert_empty_array_entry()
+ bt_value_map_insert_empty_map_entry() @@ -793,7 +793,7 @@ extern struct bt_value *bt_value_array_create(void); @sa bt_value_array_is_empty(): Checks whether or not a given array value object is empty. */ -extern int64_t bt_value_array_size(const struct bt_value *array_obj); +extern int64_t bt_value_array_get_size(const struct bt_value *array_obj); /** @brief Checks whether or not the array value object \p array_obj @@ -806,37 +806,13 @@ extern int64_t bt_value_array_size(const struct bt_value *array_obj); @pre \p array_obj is an array value object. @postrefcountsame{array_obj} -@sa bt_value_array_size(): Returns the size of a given array value +@sa bt_value_array_get_size(): Returns the size of a given array value object. */ extern bt_bool bt_value_array_is_empty(const struct bt_value *array_obj); -extern struct bt_value *bt_value_array_borrow(const struct bt_value *array_obj, - uint64_t index); - -/** -@brief Returns the value object contained in the array value object - \p array_obj at the index \p index. - -@param[in] array_obj Array value object of which to get an element. -@param[in] index Index of value object to get. -@returns Value object at index \p index on - success, or \c NULL on error. - -@prenotnull{array_obj} -@pre \p array_obj is an array value object. -@pre \p index is lesser than the size of \p array_obj (see - bt_value_array_size()). -@post On success, if the returned value object is not - \ref bt_value_null, its reference count is incremented. -@postrefcountsame{array_obj} -*/ -static inline -struct bt_value *bt_value_array_get(const struct bt_value *array_obj, - uint64_t index) -{ - return bt_get(bt_value_array_borrow(array_obj, index)); -} +extern struct bt_value *bt_value_array_borrow_element_by_index( + const struct bt_value *array_obj, uint64_t index); /** @brief Appends the value object \p element_obj to the array value @@ -855,21 +831,21 @@ struct bt_value *bt_value_array_get(const struct bt_value *array_obj, \ref bt_value_null, its reference count is incremented. @postrefcountsame{array_obj} -@sa bt_value_array_append_bool(): Appends a boolean raw value to a +@sa bt_value_array_append_bool_element(): Appends a boolean raw value to a given array value object. -@sa bt_value_array_append_integer(): Appends an integer raw value +@sa bt_value_array_append_integer_element(): Appends an integer raw value to a given array value object. -@sa bt_value_array_append_float(): Appends a floating point number +@sa bt_value_array_append_element_float(): Appends a floating point number raw value to a given array value object. -@sa bt_value_array_append_string(): Appends a string raw value to a +@sa bt_value_array_append_string_element(): Appends a string raw value to a given array value object. -@sa bt_value_array_append_empty_array(): Appends an empty array value +@sa bt_value_array_append_empty_array_element(): Appends an empty array value object to a given array value object. -@sa bt_value_array_append_empty_map(): Appends an empty map value +@sa bt_value_array_append_empty_map_element(): Appends an empty map value object to a given array value object. */ -extern enum bt_value_status bt_value_array_append(struct bt_value *array_obj, - struct bt_value *element_obj); +extern enum bt_value_status bt_value_array_append_element( + struct bt_value *array_obj, struct bt_value *element_obj); /** @brief Appends the boolean raw value \p val to the array value object @@ -887,10 +863,10 @@ value object before appending it. @prehot{array_obj} @postrefcountsame{array_obj} -@sa bt_value_array_append(): Appends a value object to a given +@sa bt_value_array_append_element(): Appends a value object to a given array value object. */ -extern enum bt_value_status bt_value_array_append_bool( +extern enum bt_value_status bt_value_array_append_bool_element( struct bt_value *array_obj, bt_bool val); /** @@ -909,10 +885,10 @@ value object before appending it. @prehot{array_obj} @postrefcountsame{array_obj} -@sa bt_value_array_append(): Appends a value object to a given +@sa bt_value_array_append_element(): Appends a value object to a given array value object. */ -extern enum bt_value_status bt_value_array_append_integer( +extern enum bt_value_status bt_value_array_append_integer_element( struct bt_value *array_obj, int64_t val); /** @@ -932,10 +908,10 @@ point number value object before appending it. @prehot{array_obj} @postrefcountsame{array_obj} -@sa bt_value_array_append(): Appends a value object to a given +@sa bt_value_array_append_element(): Appends a value object to a given array value object. */ -extern enum bt_value_status bt_value_array_append_real( +extern enum bt_value_status bt_value_array_append_real_element( struct bt_value *array_obj, double val); /** @@ -958,10 +934,10 @@ On success, \p val is copied. @prehot{array_obj} @postrefcountsame{array_obj} -@sa bt_value_array_append(): Appends a value object to a given +@sa bt_value_array_append_element(): Appends a value object to a given array value object. */ -extern enum bt_value_status bt_value_array_append_string( +extern enum bt_value_status bt_value_array_append_string_element( struct bt_value *array_obj, const char *val); /** @@ -980,10 +956,10 @@ object before appending it. @prehot{array_obj} @postrefcountsame{array_obj} -@sa bt_value_array_append(): Appends a value object to a given +@sa bt_value_array_append_element(): Appends a value object to a given array value object. */ -extern enum bt_value_status bt_value_array_append_empty_array( +extern enum bt_value_status bt_value_array_append_empty_array_element( struct bt_value *array_obj); /** @@ -1002,10 +978,10 @@ object before appending it. @prehot{array_obj} @postrefcountsame{array_obj} -@sa bt_value_array_append(): Appends a value object to a given +@sa bt_value_array_append_element(): Appends a value object to a given array value object. */ -extern enum bt_value_status bt_value_array_append_empty_map( +extern enum bt_value_status bt_value_array_append_empty_map_element( struct bt_value *array_obj); /** @@ -1024,7 +1000,7 @@ extern enum bt_value_status bt_value_array_append_empty_map( @prenotnull{element_obj} @pre \p array_obj is an array value object. @pre \p index is lesser than the size of \p array_obj (see - bt_value_array_size()). + bt_value_array_get_size()). @prehot{array_obj} @post On success, if the replaced value object is not \ref bt_value_null, its reference count is decremented. @@ -1032,8 +1008,9 @@ extern enum bt_value_status bt_value_array_append_empty_map( \ref bt_value_null, its reference count is incremented. @postrefcountsame{array_obj} */ -extern enum bt_value_status bt_value_array_set(struct bt_value *array_obj, - uint64_t index, struct bt_value *element_obj); +extern enum bt_value_status bt_value_array_set_element_by_index( + struct bt_value *array_obj, uint64_t index, + struct bt_value *element_obj); /** @} */ @@ -1068,7 +1045,7 @@ extern struct bt_value *bt_value_map_create(void); @sa bt_value_map_is_empty(): Checks whether or not a given map value object is empty. */ -extern int64_t bt_value_map_size(const struct bt_value *map_obj); +extern int64_t bt_value_map_get_size(const struct bt_value *map_obj); /** @brief Checks whether or not the map value object \p map_obj is empty. @@ -1080,38 +1057,15 @@ extern int64_t bt_value_map_size(const struct bt_value *map_obj); @pre \p map_obj is a map value object. @postrefcountsame{map_obj} -@sa bt_value_map_size(): Returns the size of a given map value object. +@sa bt_value_map_get_size(): Returns the size of a given map value object. */ extern bt_bool bt_value_map_is_empty(const struct bt_value *map_obj); -extern struct bt_value *bt_value_map_borrow(const struct bt_value *map_obj, - const char *key); - -/** -@brief Returns the value object associated with the key \p key within - the map value object \p map_obj. - -@param[in] map_obj Map value object of which to get an entry. -@param[in] key Key of the value object to get. -@returns Value object associated with the key \p key - on success, or \c NULL on error. - -@prenotnull{map_obj} -@prenotnull{key} -@pre \p map_obj is a map value object. -@postrefcountsame{map_obj} -@post On success, if the returned value object is not - \ref bt_value_null, its reference count is incremented. -*/ -static inline -struct bt_value *bt_value_map_get(const struct bt_value *map_obj, - const char *key) -{ - return bt_get(bt_value_map_borrow(map_obj, key)); -} +extern struct bt_value *bt_value_map_borrow_entry_value( + const struct bt_value *map_obj, const char *key); /** -@brief User function type to use with bt_value_map_foreach(). +@brief User function type to use with bt_value_map_foreach_entry(). \p object is a weak reference: you \em must pass it to bt_get() if you need to keep a reference after this function returns. @@ -1129,7 +1083,7 @@ traversal, or #BT_FALSE to break it. @post The reference count of \p object is not lesser than what it is when the function is called. */ -typedef bt_bool (* bt_value_map_foreach_cb)(const char *key, +typedef bt_bool (* bt_value_map_foreach_entry_cb)(const char *key, struct bt_value *object, void *data); /** @@ -1159,9 +1113,9 @@ The user function \em must return #BT_TRUE to continue the traversal of @pre \p map_obj is a map value object. @postrefcountsame{map_obj} */ -extern enum bt_value_status bt_value_map_foreach( - const struct bt_value *map_obj, bt_value_map_foreach_cb cb, - void *data); +extern enum bt_value_status bt_value_map_foreach_entry( + const struct bt_value *map_obj, + bt_value_map_foreach_entry_cb cb, void *data); /** @brief Returns whether or not the map value object \p map_obj contains @@ -1178,7 +1132,7 @@ extern enum bt_value_status bt_value_map_foreach( @pre \p map_obj is a map value object. @postrefcountsame{map_obj} */ -extern bt_bool bt_value_map_has_key(const struct bt_value *map_obj, +extern bt_bool bt_value_map_has_entry(const struct bt_value *map_obj, const char *key); /** @@ -1208,20 +1162,20 @@ On success, \p key is copied. \ref bt_value_null, its reference count is incremented. @postrefcountsame{map_obj} -@sa bt_value_map_insert_bool(): Inserts a boolean raw value into a +@sa bt_value_map_insert_bool_entry(): Inserts a boolean raw value into a given map value object. -@sa bt_value_map_insert_integer(): Inserts an integer raw value into +@sa bt_value_map_insert_integer_entry(): Inserts an integer raw value into a given map value object. -@sa bt_value_map_insert_float(): Inserts a floating point number raw +@sa bt_value_map_insert_float_entry(): Inserts a floating point number raw value into a given map value object. -@sa bt_value_map_insert_string(): Inserts a string raw value into a +@sa bt_value_map_insert_string_entry(): Inserts a string raw value into a given map value object. -@sa bt_value_map_insert_empty_array(): Inserts an empty array value +@sa bt_value_map_insert_empty_array_entry(): Inserts an empty array value object into a given map value object. -@sa bt_value_map_insert_empty_map(): Inserts an empty map value +@sa bt_value_map_insert_empty_map_entry(): Inserts an empty map value object into a given map value object. */ -extern enum bt_value_status bt_value_map_insert( +extern enum bt_value_status bt_value_map_insert_entry( struct bt_value *map_obj, const char *key, struct bt_value *element_obj); @@ -1247,10 +1201,10 @@ On success, \p key is copied. @prehot{map_obj} @postrefcountsame{map_obj} -@sa bt_value_map_insert(): Inserts a value object into a given map +@sa bt_value_map_insert_entry(): Inserts a value object into a given map value object. */ -extern enum bt_value_status bt_value_map_insert_bool( +extern enum bt_value_status bt_value_map_insert_bool_entry( struct bt_value *map_obj, const char *key, bt_bool val); /** @@ -1275,10 +1229,10 @@ On success, \p key is copied. @prehot{map_obj} @postrefcountsame{map_obj} -@sa bt_value_map_insert(): Inserts a value object into a given map +@sa bt_value_map_insert_entry(): Inserts a value object into a given map value object. */ -extern enum bt_value_status bt_value_map_insert_integer( +extern enum bt_value_status bt_value_map_insert_integer_entry( struct bt_value *map_obj, const char *key, int64_t val); /** @@ -1303,10 +1257,10 @@ On success, \p key is copied. @prehot{map_obj} @postrefcountsame{map_obj} -@sa bt_value_map_insert(): Inserts a value object into a given map +@sa bt_value_map_insert_entry(): Inserts a value object into a given map value object. */ -extern enum bt_value_status bt_value_map_insert_real( +extern enum bt_value_status bt_value_map_insert_real_entry( struct bt_value *map_obj, const char *key, double val); /** @@ -1332,10 +1286,10 @@ On success, \p val and \p key are copied. @prehot{map_obj} @postrefcountsame{map_obj} -@sa bt_value_map_insert(): Inserts a value object into a given map +@sa bt_value_map_insert_entry(): Inserts a value object into a given map value object. */ -extern enum bt_value_status bt_value_map_insert_string( +extern enum bt_value_status bt_value_map_insert_string_entry( struct bt_value *map_obj, const char *key, const char *val); /** @@ -1359,10 +1313,10 @@ On success, \p key is copied. @prehot{map_obj} @postrefcountsame{map_obj} -@sa bt_value_map_insert(): Inserts a value object into a given map +@sa bt_value_map_insert_entry(): Inserts a value object into a given map value object. */ -extern enum bt_value_status bt_value_map_insert_empty_array( +extern enum bt_value_status bt_value_map_insert_empty_array_entry( struct bt_value *map_obj, const char *key); /** @@ -1386,10 +1340,10 @@ On success, \p key is copied. @prehot{map_obj} @postrefcountsame{map_obj} -@sa bt_value_map_insert(): Inserts a value object into a given map +@sa bt_value_map_insert_entry(): Inserts a value object into a given map value object. */ -extern enum bt_value_status bt_value_map_insert_empty_map( +extern enum bt_value_status bt_value_map_insert_empty_map_entry( struct bt_value *map_obj, const char *key); /** diff --git a/lib/ctf-writer/attributes.c b/lib/ctf-writer/attributes.c index af5bbea0..bc421ace 100644 --- a/lib/ctf-writer/attributes.c +++ b/lib/ctf-writer/attributes.c @@ -80,7 +80,7 @@ void bt_ctf_attributes_destroy(struct bt_value *attr_obj) BT_HIDDEN int64_t bt_ctf_attributes_get_count(struct bt_value *attr_obj) { - return bt_value_array_size(attr_obj); + return bt_value_array_get_size(attr_obj); } BT_HIDDEN @@ -97,21 +97,21 @@ const char *bt_ctf_attributes_get_field_name(struct bt_value *attr_obj, goto end; } - if (index >= bt_value_array_size(attr_obj)) { + if (index >= bt_value_array_get_size(attr_obj)) { BT_LOGW("Invalid parameter: index is out of bounds: " "index=%" PRIu64 ", count=%" PRId64, - index, bt_value_array_size(attr_obj)); + index, bt_value_array_get_size(attr_obj)); goto end; } - attr_field_obj = bt_value_array_borrow(attr_obj, index); + attr_field_obj = bt_value_array_borrow_element_by_index(attr_obj, index); if (!attr_field_obj) { BT_LOGE("Cannot get attributes object's array value's element by index: " "value-addr=%p, index=%" PRIu64, attr_obj, index); goto end; } - attr_field_name_obj = bt_value_array_borrow(attr_field_obj, + attr_field_name_obj = bt_value_array_borrow_element_by_index(attr_field_obj, BT_CTF_ATTR_NAME_INDEX); if (!attr_field_name_obj) { BT_LOGE("Cannot get attribute array value's element by index: " @@ -143,21 +143,21 @@ struct bt_value *bt_ctf_attributes_borrow_field_value(struct bt_value *attr_obj, goto end; } - if (index >= bt_value_array_size(attr_obj)) { + if (index >= bt_value_array_get_size(attr_obj)) { BT_LOGW("Invalid parameter: index is out of bounds: " "index=%" PRIu64 ", count=%" PRId64, - index, bt_value_array_size(attr_obj)); + index, bt_value_array_get_size(attr_obj)); goto end; } - attr_field_obj = bt_value_array_borrow(attr_obj, index); + attr_field_obj = bt_value_array_borrow_element_by_index(attr_obj, index); if (!attr_field_obj) { BT_LOGE("Cannot get attributes object's array value's element by index: " "value-addr=%p, index=%" PRIu64, attr_obj, index); goto end; } - value_obj = bt_value_array_borrow(attr_field_obj, + value_obj = bt_value_array_borrow_element_by_index(attr_field_obj, BT_CTF_ATTR_VALUE_INDEX); if (!value_obj) { BT_LOGE("Cannot get attribute array value's element by index: " @@ -178,7 +178,7 @@ struct bt_value *bt_ctf_attributes_borrow_field_by_name( struct bt_value *value_obj = NULL; struct bt_value *attr_field_name_obj = NULL; - attr_size = bt_value_array_size(attr_obj); + attr_size = bt_value_array_get_size(attr_obj); if (attr_size < 0) { BT_LOGE("Cannot get array value's size: value-addr=%p", attr_obj); @@ -189,14 +189,14 @@ struct bt_value *bt_ctf_attributes_borrow_field_by_name( int ret; const char *field_name; - value_obj = bt_value_array_borrow(attr_obj, i); + value_obj = bt_value_array_borrow_element_by_index(attr_obj, i); if (!value_obj) { BT_LOGE("Cannot get attributes object's array value's element by index: " "value-addr=%p, index=%" PRIu64, attr_obj, i); goto error; } - attr_field_name_obj = bt_value_array_borrow(value_obj, + attr_field_name_obj = bt_value_array_borrow_element_by_index(value_obj, BT_CTF_ATTR_NAME_INDEX); if (!attr_field_name_obj) { BT_LOGE("Cannot get attribute array value's element by index: " @@ -243,7 +243,7 @@ int bt_ctf_attributes_set_field_value(struct bt_value *attr_obj, attr_field_obj = bt_ctf_attributes_borrow_field_by_name(attr_obj, name); if (attr_field_obj) { - ret = bt_value_array_set(attr_field_obj, + ret = bt_value_array_set_element_by_index(attr_field_obj, BT_CTF_ATTR_VALUE_INDEX, value_obj); attr_field_obj = NULL; goto end; @@ -256,15 +256,15 @@ int bt_ctf_attributes_set_field_value(struct bt_value *attr_obj, goto end; } - ret = bt_value_array_append_string(attr_field_obj, name); - ret |= bt_value_array_append(attr_field_obj, value_obj); + ret = bt_value_array_append_string_element(attr_field_obj, name); + ret |= bt_value_array_append_element(attr_field_obj, value_obj); if (ret) { BT_LOGE("Cannot append elements to array value: addr=%p", attr_field_obj); goto end; } - ret = bt_value_array_append(attr_obj, attr_field_obj); + ret = bt_value_array_append_element(attr_obj, attr_field_obj); if (ret) { BT_LOGE("Cannot append element to array value: " "array-value-addr=%p, element-value-addr=%p", @@ -296,7 +296,7 @@ struct bt_value *bt_ctf_attributes_borrow_field_value_by_name( goto end; } - value_obj = bt_value_array_borrow(attr_field_obj, + value_obj = bt_value_array_borrow_element_by_index(attr_field_obj, BT_CTF_ATTR_VALUE_INDEX); if (!value_obj) { BT_LOGE("Cannot get attribute array value's element by index: " @@ -322,7 +322,7 @@ int bt_ctf_attributes_freeze(struct bt_value *attr_obj) } BT_LOGD("Freezing attributes object: value-addr=%p", attr_obj); - count = bt_value_array_size(attr_obj); + count = bt_value_array_get_size(attr_obj); BT_ASSERT(count >= 0); /* diff --git a/lib/lib-logging.c b/lib/lib-logging.c index 0fcf6e2e..3207c3d0 100644 --- a/lib/lib-logging.c +++ b/lib/lib-logging.c @@ -837,7 +837,7 @@ static inline void format_value(char **buf_ch, bool extended, } case BT_VALUE_TYPE_ARRAY: { - int64_t count = bt_value_array_size(value); + int64_t count = bt_value_array_get_size(value); BT_ASSERT(count >= 0); BUF_APPEND(", %selement-count=%" PRId64, PRFIELD(count)); @@ -845,7 +845,7 @@ static inline void format_value(char **buf_ch, bool extended, } case BT_VALUE_TYPE_MAP: { - int64_t count = bt_value_map_size(value); + int64_t count = bt_value_map_get_size(value); BT_ASSERT(count >= 0); BUF_APPEND(", %selement-count=%" PRId64, PRFIELD(count)); diff --git a/lib/trace-ir/attributes.c b/lib/trace-ir/attributes.c index d43fd649..caabda3f 100644 --- a/lib/trace-ir/attributes.c +++ b/lib/trace-ir/attributes.c @@ -80,7 +80,7 @@ void bt_attributes_destroy(struct bt_value *attr_obj) BT_HIDDEN int64_t bt_attributes_get_count(struct bt_value *attr_obj) { - return bt_value_array_size(attr_obj); + return bt_value_array_get_size(attr_obj); } BT_HIDDEN @@ -97,21 +97,21 @@ const char *bt_attributes_get_field_name(struct bt_value *attr_obj, goto end; } - if (index >= bt_value_array_size(attr_obj)) { + if (index >= bt_value_array_get_size(attr_obj)) { BT_LOGW("Invalid parameter: index is out of bounds: " "index=%" PRIu64 ", count=%" PRId64, - index, bt_value_array_size(attr_obj)); + index, bt_value_array_get_size(attr_obj)); goto end; } - attr_field_obj = bt_value_array_borrow(attr_obj, index); + attr_field_obj = bt_value_array_borrow_element_by_index(attr_obj, index); if (!attr_field_obj) { BT_LOGE("Cannot get attributes object's array value's element by index: " "value-addr=%p, index=%" PRIu64, attr_obj, index); goto end; } - attr_field_name_obj = bt_value_array_borrow(attr_field_obj, + attr_field_name_obj = bt_value_array_borrow_element_by_index(attr_field_obj, BT_ATTR_NAME_INDEX); if (!attr_field_name_obj) { BT_LOGE("Cannot get attribute array value's element by index: " @@ -143,21 +143,21 @@ struct bt_value *bt_attributes_borrow_field_value(struct bt_value *attr_obj, goto end; } - if (index >= bt_value_array_size(attr_obj)) { + if (index >= bt_value_array_get_size(attr_obj)) { BT_LOGW("Invalid parameter: index is out of bounds: " "index=%" PRIu64 ", count=%" PRId64, - index, bt_value_array_size(attr_obj)); + index, bt_value_array_get_size(attr_obj)); goto end; } - attr_field_obj = bt_value_array_borrow(attr_obj, index); + attr_field_obj = bt_value_array_borrow_element_by_index(attr_obj, index); if (!attr_field_obj) { BT_LOGE("Cannot get attributes object's array value's element by index: " "value-addr=%p, index=%" PRIu64, attr_obj, index); goto end; } - value_obj = bt_value_array_borrow(attr_field_obj, + value_obj = bt_value_array_borrow_element_by_index(attr_field_obj, BT_ATTR_VALUE_INDEX); if (!value_obj) { BT_LOGE("Cannot get attribute array value's element by index: " @@ -178,7 +178,7 @@ struct bt_value *bt_attributes_borrow_field_by_name( struct bt_value *value_obj = NULL; struct bt_value *attr_field_name_obj = NULL; - attr_size = bt_value_array_size(attr_obj); + attr_size = bt_value_array_get_size(attr_obj); if (attr_size < 0) { BT_LOGE("Cannot get array value's size: value-addr=%p", attr_obj); @@ -189,14 +189,14 @@ struct bt_value *bt_attributes_borrow_field_by_name( int ret; const char *field_name; - value_obj = bt_value_array_borrow(attr_obj, i); + value_obj = bt_value_array_borrow_element_by_index(attr_obj, i); if (!value_obj) { BT_LOGE("Cannot get attributes object's array value's element by index: " "value-addr=%p, index=%" PRIu64, attr_obj, i); goto error; } - attr_field_name_obj = bt_value_array_borrow(value_obj, + attr_field_name_obj = bt_value_array_borrow_element_by_index(value_obj, BT_ATTR_NAME_INDEX); if (!attr_field_name_obj) { BT_LOGE("Cannot get attribute array value's element by index: " @@ -243,7 +243,7 @@ int bt_attributes_set_field_value(struct bt_value *attr_obj, attr_field_obj = bt_attributes_borrow_field_by_name(attr_obj, name); if (attr_field_obj) { - ret = bt_value_array_set(attr_field_obj, + ret = bt_value_array_set_element_by_index(attr_field_obj, BT_ATTR_VALUE_INDEX, value_obj); attr_field_obj = NULL; goto end; @@ -256,15 +256,15 @@ int bt_attributes_set_field_value(struct bt_value *attr_obj, goto end; } - ret = bt_value_array_append_string(attr_field_obj, name); - ret |= bt_value_array_append(attr_field_obj, value_obj); + ret = bt_value_array_append_string_element(attr_field_obj, name); + ret |= bt_value_array_append_element(attr_field_obj, value_obj); if (ret) { BT_LOGE("Cannot append elements to array value: addr=%p", attr_field_obj); goto end; } - ret = bt_value_array_append(attr_obj, attr_field_obj); + ret = bt_value_array_append_element(attr_obj, attr_field_obj); if (ret) { BT_LOGE("Cannot append element to array value: " "array-value-addr=%p, element-value-addr=%p", @@ -296,7 +296,7 @@ struct bt_value *bt_attributes_borrow_field_value_by_name( goto end; } - value_obj = bt_value_array_borrow(attr_field_obj, + value_obj = bt_value_array_borrow_element_by_index(attr_field_obj, BT_ATTR_VALUE_INDEX); if (!value_obj) { BT_LOGE("Cannot get attribute array value's element by index: " @@ -322,7 +322,7 @@ int bt_attributes_freeze(struct bt_value *attr_obj) } BT_LOGD("Freezing attributes object: value-addr=%p", attr_obj); - count = bt_value_array_size(attr_obj); + count = bt_value_array_get_size(attr_obj); BT_ASSERT(count >= 0); /* diff --git a/lib/values.c b/lib/values.c index 7479e81a..8836f01d 100644 --- a/lib/values.c +++ b/lib/values.c @@ -215,7 +215,7 @@ struct bt_value *bt_value_array_copy(const struct bt_value *array_obj) for (i = 0; i < typed_array_obj->garray->len; ++i) { struct bt_value *element_obj_copy; - struct bt_value *element_obj = bt_value_array_borrow( + struct bt_value *element_obj = bt_value_array_borrow_element_by_index( array_obj, i); BT_ASSERT(element_obj); @@ -230,7 +230,7 @@ struct bt_value *bt_value_array_copy(const struct bt_value *array_obj) goto end; } - ret = bt_value_array_append(copy_obj, element_obj_copy); + ret = bt_value_array_append_element(copy_obj, element_obj_copy); BT_PUT(element_obj_copy); if (ret) { BT_LOGE("Cannot append to array value: addr=%p", @@ -281,7 +281,7 @@ struct bt_value *bt_value_map_copy(const struct bt_value *map_obj) goto end; } - ret = bt_value_map_insert(copy_obj, key_str, element_obj_copy); + ret = bt_value_map_insert_entry(copy_obj, key_str, element_obj_copy); BT_PUT(element_obj_copy); if (ret) { BT_LOGE("Cannot insert into map value: addr=%p, key=\"%s\"", @@ -393,13 +393,13 @@ bt_bool bt_value_array_compare(const struct bt_value *object_a, const struct bt_value_array *array_obj_a = BT_VALUE_TO_ARRAY(object_a); - if (bt_value_array_size(object_a) != bt_value_array_size(object_b)) { + if (bt_value_array_get_size(object_a) != bt_value_array_get_size(object_b)) { BT_LOGV("Array values are different: size mismatch " "value-a-addr=%p, value-b-addr=%p, " "value-a-size=%" PRId64 ", value-b-size=%" PRId64, object_a, object_b, - bt_value_array_size(object_a), - bt_value_array_size(object_b)); + bt_value_array_get_size(object_a), + bt_value_array_get_size(object_b)); ret = BT_FALSE; goto end; } @@ -408,8 +408,8 @@ bt_bool bt_value_array_compare(const struct bt_value *object_a, struct bt_value *element_obj_a; struct bt_value *element_obj_b; - element_obj_a = bt_value_array_borrow(object_a, i); - element_obj_b = bt_value_array_borrow(object_b, i); + element_obj_a = bt_value_array_borrow_element_by_index(object_a, i); + element_obj_b = bt_value_array_borrow_element_by_index(object_b, i); if (!bt_value_compare(element_obj_a, element_obj_b)) { BT_LOGV("Array values's elements are different: " @@ -433,13 +433,13 @@ 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_size(object_a) != bt_value_map_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, object_a, object_b, - bt_value_map_size(object_a), - bt_value_map_size(object_b)); + bt_value_map_get_size(object_a), + bt_value_map_get_size(object_b)); ret = BT_FALSE; goto end; } @@ -450,7 +450,7 @@ bt_bool bt_value_map_compare(const struct bt_value *object_a, struct bt_value *element_obj_b; const char *key_str = g_quark_to_string(GPOINTER_TO_UINT(key)); - element_obj_b = bt_value_map_borrow(object_b, key_str); + element_obj_b = bt_value_map_borrow_entry_value(object_b, key_str); if (!bt_value_compare(element_obj_a, element_obj_b)) { BT_LOGV("Map values's elements are different: " @@ -839,7 +839,7 @@ enum bt_value_status bt_value_string_set(struct bt_value *string_obj, return BT_VALUE_STATUS_OK; } -int64_t bt_value_array_size(const struct bt_value *array_obj) +int64_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); @@ -848,10 +848,10 @@ int64_t bt_value_array_size(const struct bt_value *array_obj) bt_bool bt_value_array_is_empty(const struct bt_value *array_obj) { - return bt_value_array_size(array_obj) == 0; + return bt_value_array_get_size(array_obj) == 0; } -struct bt_value *bt_value_array_borrow(const struct bt_value *array_obj, +struct bt_value *bt_value_array_borrow_element_by_index(const struct bt_value *array_obj, uint64_t index) { struct bt_value_array *typed_array_obj = @@ -864,7 +864,7 @@ struct bt_value *bt_value_array_borrow(const struct bt_value *array_obj, return g_ptr_array_index(typed_array_obj->garray, index); } -enum bt_value_status bt_value_array_append(struct bt_value *array_obj, +enum bt_value_status bt_value_array_append_element(struct bt_value *array_obj, struct bt_value *element_obj) { struct bt_value_array *typed_array_obj = @@ -882,78 +882,78 @@ enum bt_value_status bt_value_array_append(struct bt_value *array_obj, 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_append_bool_element(struct bt_value *array_obj, bt_bool val) { enum bt_value_status ret; struct bt_value *bool_obj = NULL; bool_obj = bt_value_bool_create_init(val); - ret = bt_value_array_append(array_obj, bool_obj); + ret = bt_value_array_append_element(array_obj, bool_obj); bt_put(bool_obj); return ret; } -enum bt_value_status bt_value_array_append_integer( +enum bt_value_status bt_value_array_append_integer_element( struct bt_value *array_obj, int64_t val) { enum bt_value_status ret; struct bt_value *integer_obj = NULL; integer_obj = bt_value_integer_create_init(val); - ret = bt_value_array_append(array_obj, integer_obj); + ret = bt_value_array_append_element(array_obj, integer_obj); bt_put(integer_obj); return ret; } -enum bt_value_status bt_value_array_append_real(struct bt_value *array_obj, +enum bt_value_status bt_value_array_append_real_element(struct bt_value *array_obj, double val) { enum bt_value_status ret; struct bt_value *real_obj = NULL; real_obj = bt_value_real_create_init(val); - ret = bt_value_array_append(array_obj, real_obj); + ret = bt_value_array_append_element(array_obj, real_obj); bt_put(real_obj); return ret; } -enum bt_value_status bt_value_array_append_string(struct bt_value *array_obj, +enum bt_value_status bt_value_array_append_string_element(struct bt_value *array_obj, const char *val) { enum bt_value_status ret; struct bt_value *string_obj = NULL; string_obj = bt_value_string_create_init(val); - ret = bt_value_array_append(array_obj, string_obj); + ret = bt_value_array_append_element(array_obj, string_obj); bt_put(string_obj); return ret; } -enum bt_value_status bt_value_array_append_empty_array( +enum bt_value_status bt_value_array_append_empty_array_element( struct bt_value *array_obj) { enum bt_value_status ret; struct bt_value *empty_array_obj = NULL; empty_array_obj = bt_value_array_create(); - ret = bt_value_array_append(array_obj, empty_array_obj); + ret = bt_value_array_append_element(array_obj, empty_array_obj); bt_put(empty_array_obj); return ret; } -enum bt_value_status bt_value_array_append_empty_map(struct bt_value *array_obj) +enum bt_value_status bt_value_array_append_empty_map_element(struct bt_value *array_obj) { enum bt_value_status ret; struct bt_value *map_obj = NULL; map_obj = bt_value_map_create(); - ret = bt_value_array_append(array_obj, map_obj); + ret = bt_value_array_append_element(array_obj, map_obj); bt_put(map_obj); return ret; } -enum bt_value_status bt_value_array_set(struct bt_value *array_obj, +enum bt_value_status bt_value_array_set_element_by_index(struct bt_value *array_obj, uint64_t index, struct bt_value *element_obj) { struct bt_value_array *typed_array_obj = @@ -974,7 +974,7 @@ enum bt_value_status bt_value_array_set(struct bt_value *array_obj, return BT_VALUE_STATUS_OK; } -int64_t bt_value_map_size(const struct bt_value *map_obj) +int64_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); @@ -983,10 +983,10 @@ int64_t bt_value_map_size(const struct bt_value *map_obj) bt_bool bt_value_map_is_empty(const struct bt_value *map_obj) { - return bt_value_map_size(map_obj) == 0; + return bt_value_map_get_size(map_obj) == 0; } -struct bt_value *bt_value_map_borrow(const struct bt_value *map_obj, +struct bt_value *bt_value_map_borrow_entry_value(const struct bt_value *map_obj, const char *key) { BT_ASSERT_PRE_NON_NULL(map_obj, "Value object"); @@ -996,7 +996,7 @@ struct bt_value *bt_value_map_borrow(const struct bt_value *map_obj, 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 bt_value_map_has_entry(const struct bt_value *map_obj, const char *key) { BT_ASSERT_PRE_NON_NULL(map_obj, "Value object"); BT_ASSERT_PRE_NON_NULL(key, "Key"); @@ -1005,7 +1005,7 @@ bt_bool bt_value_map_has_key(const struct bt_value *map_obj, const char *key) GUINT_TO_POINTER(g_quark_from_string(key))); } -enum bt_value_status bt_value_map_insert(struct bt_value *map_obj, +enum bt_value_status bt_value_map_insert_entry(struct bt_value *map_obj, const char *key, struct bt_value *element_obj) { BT_ASSERT_PRE_NON_NULL(map_obj, "Map value object"); @@ -1022,80 +1022,80 @@ enum bt_value_status bt_value_map_insert(struct bt_value *map_obj, return BT_VALUE_STATUS_OK; } -enum bt_value_status bt_value_map_insert_bool(struct bt_value *map_obj, +enum bt_value_status bt_value_map_insert_bool_entry(struct bt_value *map_obj, const char *key, bt_bool val) { enum bt_value_status ret; struct bt_value *bool_obj = NULL; bool_obj = bt_value_bool_create_init(val); - ret = bt_value_map_insert(map_obj, key, bool_obj); + ret = bt_value_map_insert_entry(map_obj, key, bool_obj); bt_put(bool_obj); return ret; } -enum bt_value_status bt_value_map_insert_integer(struct bt_value *map_obj, +enum bt_value_status bt_value_map_insert_integer_entry(struct bt_value *map_obj, const char *key, int64_t val) { enum bt_value_status ret; struct bt_value *integer_obj = NULL; integer_obj = bt_value_integer_create_init(val); - ret = bt_value_map_insert(map_obj, key, integer_obj); + ret = bt_value_map_insert_entry(map_obj, key, integer_obj); bt_put(integer_obj); return ret; } -enum bt_value_status bt_value_map_insert_real(struct bt_value *map_obj, +enum bt_value_status bt_value_map_insert_real_entry(struct bt_value *map_obj, const char *key, double val) { enum bt_value_status ret; struct bt_value *real_obj = NULL; real_obj = bt_value_real_create_init(val); - ret = bt_value_map_insert(map_obj, key, real_obj); + ret = bt_value_map_insert_entry(map_obj, key, real_obj); bt_put(real_obj); return ret; } -enum bt_value_status bt_value_map_insert_string(struct bt_value *map_obj, +enum bt_value_status bt_value_map_insert_string_entry(struct bt_value *map_obj, const char *key, const char *val) { enum bt_value_status ret; struct bt_value *string_obj = NULL; string_obj = bt_value_string_create_init(val); - ret = bt_value_map_insert(map_obj, key, string_obj); + ret = bt_value_map_insert_entry(map_obj, key, string_obj); bt_put(string_obj); return ret; } -enum bt_value_status bt_value_map_insert_empty_array(struct bt_value *map_obj, +enum bt_value_status bt_value_map_insert_empty_array_entry(struct bt_value *map_obj, const char *key) { enum bt_value_status ret; struct bt_value *array_obj = NULL; array_obj = bt_value_array_create(); - ret = bt_value_map_insert(map_obj, key, array_obj); + ret = bt_value_map_insert_entry(map_obj, key, array_obj); bt_put(array_obj); return ret; } -enum bt_value_status bt_value_map_insert_empty_map(struct bt_value *map_obj, +enum bt_value_status bt_value_map_insert_empty_map_entry(struct bt_value *map_obj, const char *key) { enum bt_value_status ret; struct bt_value *empty_map_obj = NULL; empty_map_obj = bt_value_map_create(); - ret = bt_value_map_insert(map_obj, key, empty_map_obj); + ret = bt_value_map_insert_entry(map_obj, key, empty_map_obj); bt_put(empty_map_obj); return ret; } -enum bt_value_status bt_value_map_foreach(const struct bt_value *map_obj, - bt_value_map_foreach_cb cb, void *data) +enum bt_value_status bt_value_map_foreach_entry(const struct bt_value *map_obj, + bt_value_map_foreach_entry_cb cb, void *data) { enum bt_value_status ret = BT_VALUE_STATUS_OK; gpointer key, element_obj; @@ -1140,7 +1140,7 @@ bt_bool extend_map_element(const char *key, bt_value_copy(extension_obj_elem); /* Replace in extended object */ - if (bt_value_map_insert(extend_data->extended_obj, key, + if (bt_value_map_insert_entry(extend_data->extended_obj, key, extension_obj_elem_copy)) { BT_LOGE("Cannot replace value in extended value: key=\"%s\", " "extended-value-addr=%p, element-value-addr=%p", @@ -1187,7 +1187,7 @@ struct bt_value *bt_value_map_extend(struct bt_value *base_map_obj, */ extend_data.extended_obj = extended_obj; - if (bt_value_map_foreach(extension_obj, extend_map_element, + if (bt_value_map_foreach_entry(extension_obj, extend_map_element, &extend_data)) { BT_LOGE("Cannot iterate on the extension object's elements: " "extension-value-addr=%p", extension_obj); diff --git a/plugins/ctf/fs-src/fs.c b/plugins/ctf/fs-src/fs.c index fa341ea1..f48d5087 100644 --- a/plugins/ctf/fs-src/fs.c +++ b/plugins/ctf/fs-src/fs.c @@ -1268,14 +1268,14 @@ struct ctf_fs_component *ctf_fs_create(struct bt_private_component *priv_comp, * private component should also exist. */ ctf_fs->priv_comp = priv_comp; - value = bt_value_map_borrow(params, "path"); + value = bt_value_map_borrow_entry_value(params, "path"); if (value && !bt_value_is_string(value)) { goto error; } value_ret = bt_value_string_get(value, &path_param); BT_ASSERT(value_ret == BT_VALUE_STATUS_OK); - value = bt_value_map_borrow(params, "clock-class-offset-s"); + 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"); @@ -1286,7 +1286,7 @@ struct ctf_fs_component *ctf_fs_create(struct bt_private_component *priv_comp, BT_ASSERT(value_ret == BT_VALUE_STATUS_OK); } - value = bt_value_map_borrow(params, "clock-class-offset-ns"); + value = bt_value_map_borrow_entry_value(params, "clock-class-offset-ns"); if (value) { if (!bt_value_is_integer(value)) { BT_LOGE("clock-class-offset-ns should be an integer"); diff --git a/plugins/ctf/fs-src/query.c b/plugins/ctf/fs-src/query.c index 96bf91ca..b2830a76 100644 --- a/plugins/ctf/fs-src/query.c +++ b/plugins/ctf/fs-src/query.c @@ -78,7 +78,7 @@ struct bt_component_class_query_method_return metadata_info_query( goto error; } - path_value = bt_value_map_borrow(params, "path"); + 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."); @@ -148,14 +148,14 @@ struct bt_component_class_query_method_return metadata_info_query( g_string_append(g_metadata_text, metadata_text); - ret = bt_value_map_insert_string(query_ret.result, "text", + ret = bt_value_map_insert_string_entry(query_ret.result, "text", g_metadata_text->str); if (ret) { BT_LOGE_STR("Cannot insert metadata text into query result."); goto error; } - ret = bt_value_map_insert_bool(query_ret.result, "is-packetized", + ret = bt_value_map_insert_bool_entry(query_ret.result, "is-packetized", is_packetized); if (ret) { BT_LOGE_STR("Cannot insert \"is-packetized\" attribute into query result."); @@ -204,21 +204,21 @@ int add_range(struct bt_value *info, struct range *range, goto end; } - status = bt_value_map_insert_integer(range_map, "begin", + status = bt_value_map_insert_integer_entry(range_map, "begin", range->begin_ns); if (status != BT_VALUE_STATUS_OK) { ret = -1; goto end; } - status = bt_value_map_insert_integer(range_map, "end", + status = bt_value_map_insert_integer_entry(range_map, "end", range->end_ns); if (status != BT_VALUE_STATUS_OK) { ret = -1; goto end; } - status = bt_value_map_insert(info, range_name, range_map); + status = bt_value_map_insert_entry(info, range_name, range_map); if (status != BT_VALUE_STATUS_OK) { ret = -1; goto end; @@ -238,7 +238,7 @@ int add_stream_ids(struct bt_value *info, struct bt_stream *stream) stream_instance_id = bt_stream_get_id(stream); if (stream_instance_id != -1) { - status = bt_value_map_insert_integer(info, "id", + status = bt_value_map_insert_integer_entry(info, "id", stream_instance_id); if (status != BT_VALUE_STATUS_OK) { ret = -1; @@ -258,7 +258,7 @@ int add_stream_ids(struct bt_value *info, struct bt_stream *stream) goto end; } - status = bt_value_map_insert_integer(info, "class-id", stream_class_id); + status = bt_value_map_insert_integer_entry(info, "class-id", stream_class_id); if (status != BT_VALUE_STATUS_OK) { ret = -1; goto end; @@ -300,7 +300,7 @@ int populate_stream_info(struct ctf_fs_ds_file_group *group, goto end; } - status = bt_value_array_append_string(file_paths, + status = bt_value_array_append_string_element(file_paths, info->path->str); if (status != BT_VALUE_STATUS_OK) { ret = -1; @@ -328,7 +328,7 @@ int populate_stream_info(struct ctf_fs_ds_file_group *group, } } - status = bt_value_map_insert(group_info, "paths", file_paths); + status = bt_value_map_insert_entry(group_info, "paths", file_paths); if (status != BT_VALUE_STATUS_OK) { ret = -1; goto end; @@ -368,13 +368,13 @@ int populate_trace_info(const char *trace_path, const char *trace_name, goto end; } - status = bt_value_map_insert_string(trace_info, "name", + status = bt_value_map_insert_string_entry(trace_info, "name", trace_name); if (status != BT_VALUE_STATUS_OK) { ret = -1; goto end; } - status = bt_value_map_insert_string(trace_info, "path", + status = bt_value_map_insert_string_entry(trace_info, "path", trace_path); if (status != BT_VALUE_STATUS_OK) { ret = -1; @@ -427,7 +427,7 @@ int populate_trace_info(const char *trace_path, const char *trace_name, trace_intersection.end_ns = min(trace_intersection.end_ns, group_range.end_ns); trace_intersection.set = true; - status = bt_value_array_append(file_groups, group_info); + status = bt_value_array_append_element(file_groups, group_info); bt_put(group_info); if (status != BT_VALUE_STATUS_OK) { goto end; @@ -448,7 +448,7 @@ int populate_trace_info(const char *trace_path, const char *trace_name, } } - status = bt_value_map_insert(trace_info, "streams", file_groups); + status = bt_value_map_insert_entry(trace_info, "streams", file_groups); BT_PUT(file_groups); if (status != BT_VALUE_STATUS_OK) { ret = -1; @@ -488,7 +488,7 @@ struct bt_component_class_query_method_return trace_info_query( goto error; } - path_value = bt_value_map_borrow(params, "path"); + 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."); @@ -543,7 +543,7 @@ struct bt_component_class_query_method_return trace_info_query( goto error; } - status = bt_value_array_append(query_ret.result, trace_info); + status = bt_value_array_append_element(query_ret.result, trace_info); bt_put(trace_info); if (status != BT_VALUE_STATUS_OK) { goto error; diff --git a/plugins/ctf/lttng-live/viewer-connection.c b/plugins/ctf/lttng-live/viewer-connection.c index 0492340c..067ed269 100644 --- a/plugins/ctf/lttng-live/viewer-connection.c +++ b/plugins/ctf/lttng-live/viewer-connection.c @@ -303,7 +303,7 @@ enum bt_value_status list_update_session(struct bt_value *results, int i, len; bool found = false; - len = bt_value_array_size(results); + len = bt_value_array_get_size(results); if (len < 0) { ret = BT_VALUE_STATUS_ERROR; goto end; @@ -436,7 +436,7 @@ enum bt_value_status list_append_session(struct bt_value *results, g_string_append_c(url, '/'); g_string_append(url, session->session_name); - ret = bt_value_map_insert_string(map, "url", url->str); + ret = bt_value_map_insert_string_entry(map, "url", url->str); if (ret != BT_VALUE_STATUS_OK) { goto end; } @@ -445,7 +445,7 @@ enum bt_value_status list_append_session(struct bt_value *results, * key = "target-hostname", * value = , */ - ret = bt_value_map_insert_string(map, "target-hostname", + ret = bt_value_map_insert_string_entry(map, "target-hostname", session->hostname); if (ret != BT_VALUE_STATUS_OK) { goto end; @@ -455,7 +455,7 @@ enum bt_value_status list_append_session(struct bt_value *results, * key = "session-name", * value = , */ - ret = bt_value_map_insert_string(map, "session-name", + ret = bt_value_map_insert_string_entry(map, "session-name", session->session_name); if (ret != BT_VALUE_STATUS_OK) { goto end; @@ -468,7 +468,7 @@ enum bt_value_status list_append_session(struct bt_value *results, { uint32_t live_timer = be32toh(session->live_timer); - ret = bt_value_map_insert_integer(map, "timer-us", + ret = bt_value_map_insert_integer_entry(map, "timer-us", live_timer); if (ret != BT_VALUE_STATUS_OK) { goto end; @@ -482,7 +482,7 @@ enum bt_value_status list_append_session(struct bt_value *results, { uint32_t streams = be32toh(session->streams); - ret = bt_value_map_insert_integer(map, "stream-count", + ret = bt_value_map_insert_integer_entry(map, "stream-count", streams); if (ret != BT_VALUE_STATUS_OK) { goto end; @@ -497,14 +497,14 @@ enum bt_value_status list_append_session(struct bt_value *results, { uint32_t clients = be32toh(session->clients); - ret = bt_value_map_insert_integer(map, "client-count", + ret = bt_value_map_insert_integer_entry(map, "client-count", clients); if (ret != BT_VALUE_STATUS_OK) { goto end; } } - ret = bt_value_array_append(results, map); + ret = bt_value_array_append_element(results, map); end: if (url) { g_string_free(url, TRUE); diff --git a/plugins/text/dmesg/dmesg.c b/plugins/text/dmesg/dmesg.c index f54af1c1..90527c9d 100644 --- a/plugins/text/dmesg/dmesg.c +++ b/plugins/text/dmesg/dmesg.c @@ -210,13 +210,13 @@ end: static int handle_params(struct dmesg_component *dmesg_comp, struct bt_value *params) { - struct bt_value *read_from_stdin = NULL; struct bt_value *no_timestamp = NULL; struct bt_value *path = NULL; const char *path_str; int ret = 0; - no_timestamp = bt_value_map_get(params, "no-extract-timestamp"); + no_timestamp = bt_value_map_borrow_entry_value(params, + "no-extract-timestamp"); if (no_timestamp) { if (!bt_value_is_bool(no_timestamp)) { BT_LOGE("Expecting a boolean value for the `no-extract-timestamp` parameter: " @@ -231,7 +231,7 @@ int handle_params(struct dmesg_component *dmesg_comp, struct bt_value *params) BT_ASSERT(ret == 0); } - path = bt_value_map_get(params, "path"); + path = bt_value_map_borrow_entry_value(params, "path"); if (path) { if (dmesg_comp->params.read_from_stdin) { BT_LOGE_STR("Cannot specify both `read-from-stdin` and `path` parameters."); @@ -259,9 +259,6 @@ error: ret = -1; end: - bt_put(read_from_stdin); - bt_put(path); - bt_put(no_timestamp); return ret; } diff --git a/plugins/text/pretty/pretty.c b/plugins/text/pretty/pretty.c index 154fa255..51480fbe 100644 --- a/plugins/text/pretty/pretty.c +++ b/plugins/text/pretty/pretty.c @@ -236,7 +236,7 @@ enum bt_component_status add_params_to_map(struct bt_value *plugin_opt_map) const char *key = plugin_options[i]; enum bt_value_status status; - status = bt_value_map_insert(plugin_opt_map, key, bt_value_null); + status = bt_value_map_insert_entry(plugin_opt_map, key, bt_value_null); switch (status) { case BT_VALUE_STATUS_OK: break; @@ -255,7 +255,7 @@ bt_bool check_param_exists(const char *key, struct bt_value *object, void *data) struct pretty_component *pretty = data; struct bt_value *plugin_opt_map = pretty->plugin_opt_map; - if (!bt_value_map_has_key(plugin_opt_map, key)) { + if (!bt_value_map_has_entry(plugin_opt_map, key)) { fprintf(pretty->err, "[warning] Parameter \"%s\" unknown to \"text.pretty\" sink component\n", key); } @@ -272,7 +272,7 @@ enum bt_component_status apply_one_string(const char *key, enum bt_value_status status; const char *str; - value = bt_value_map_borrow(params, key); + value = bt_value_map_borrow_entry_value(params, key); if (!value) { goto end; } @@ -303,7 +303,7 @@ enum bt_component_status apply_one_bool(const char *key, enum bt_value_status status; bt_bool bool_val; - value = bt_value_map_borrow(params, key); + value = bt_value_map_borrow_entry_value(params, key); if (!value) { goto end; } @@ -372,7 +372,7 @@ enum bt_component_status apply_params(struct pretty_component *pretty, goto end; } /* Report unknown parameters. */ - status = bt_value_map_foreach(params, check_param_exists, pretty); + status = bt_value_map_foreach_entry(params, check_param_exists, pretty); switch (status) { case BT_VALUE_STATUS_OK: break; @@ -382,11 +382,11 @@ enum bt_component_status apply_params(struct pretty_component *pretty, } /* Known parameters. */ pretty->options.color = PRETTY_COLOR_OPT_AUTO; - if (bt_value_map_has_key(params, "color")) { + if (bt_value_map_has_entry(params, "color")) { struct bt_value *color_value; const char *color; - color_value = bt_value_map_borrow(params, "color"); + color_value = bt_value_map_borrow_entry_value(params, "color"); if (!color_value) { goto end; } diff --git a/plugins/utils/counter/counter.c b/plugins/utils/counter/counter.c index e782a7b7..353c0f60 100644 --- a/plugins/utils/counter/counter.c +++ b/plugins/utils/counter/counter.c @@ -140,7 +140,7 @@ enum bt_component_status counter_init(struct bt_private_component *component, counter->last_printed_total = -1ULL; counter->step = 1000; - step = bt_value_map_borrow(params, "step"); + step = bt_value_map_borrow_entry_value(params, "step"); if (step && bt_value_is_integer(step)) { int64_t val; @@ -151,7 +151,7 @@ enum bt_component_status counter_init(struct bt_private_component *component, } } - hide_zero = bt_value_map_borrow(params, "hide-zero"); + hide_zero = bt_value_map_borrow_entry_value(params, "hide-zero"); if (hide_zero && bt_value_is_bool(hide_zero)) { bt_bool val; diff --git a/plugins/utils/muxer/muxer.c b/plugins/utils/muxer/muxer.c index c75b5d9b..f629e6d5 100644 --- a/plugins/utils/muxer/muxer.c +++ b/plugins/utils/muxer/muxer.c @@ -254,7 +254,7 @@ struct bt_value *get_default_params(void) goto error; } - ret = bt_value_map_insert_bool(params, + ret = bt_value_map_insert_bool_entry(params, ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME, false); if (ret) { BT_LOGE_STR("Cannot add boolean value to map value object."); @@ -295,7 +295,7 @@ int configure_muxer_comp(struct muxer_comp *muxer_comp, struct bt_value *params) goto error; } - assume_absolute_clock_classes = bt_value_map_borrow(real_params, + assume_absolute_clock_classes = bt_value_map_borrow_entry_value(real_params, ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME); if (assume_absolute_clock_classes && !bt_value_is_bool(assume_absolute_clock_classes)) { diff --git a/tests/lib/test-plugin-plugins/sfs.c b/tests/lib/test-plugin-plugins/sfs.c index 4d0357c6..d8794832 100644 --- a/tests/lib/test-plugin-plugins/sfs.c +++ b/tests/lib/test-plugin-plugins/sfs.c @@ -60,9 +60,9 @@ static struct bt_component_class_query_method_return query_method( int iret; BT_ASSERT(ret.result); - iret = bt_value_array_append_string(ret.result, object); + iret = bt_value_array_append_string_element(ret.result, object); BT_ASSERT(iret == 0); - iret = bt_value_array_append(ret.result, params); + iret = bt_value_array_append_element(ret.result, params); BT_ASSERT(iret == 0); return ret; } diff --git a/tests/lib/test_bt_values.c b/tests/lib/test_bt_values.c index f1c57d23..8d8f323c 100644 --- a/tests/lib/test_bt_values.c +++ b/tests/lib/test_bt_values.c @@ -194,116 +194,106 @@ void test_array(void) "initial array value object size is 0"); obj = bt_value_integer_create_init(345); - ret = bt_value_array_append(array_obj, obj); + ret = bt_value_array_append_element(array_obj, obj); BT_PUT(obj); obj = bt_value_real_create_init(-17.45); - ret |= bt_value_array_append(array_obj, obj); + ret |= bt_value_array_append_element(array_obj, obj); BT_PUT(obj); obj = bt_value_bool_create_init(BT_TRUE); - ret |= bt_value_array_append(array_obj, obj); + ret |= bt_value_array_append_element(array_obj, obj); BT_PUT(obj); - ret |= bt_value_array_append(array_obj, bt_value_null); - ok(!ret, "bt_value_array_append() succeeds"); - ok(bt_value_array_size(array_obj) == 4, + ret |= bt_value_array_append_element(array_obj, bt_value_null); + ok(!ret, "bt_value_array_append_element() succeeds"); + ok(bt_value_array_get_size(array_obj) == 4, "appending an element to an array value object increment its size"); - obj = bt_value_array_get(array_obj, 0); + obj = bt_value_array_borrow_element_by_index(array_obj, 0); ok(obj && bt_value_is_integer(obj), - "bt_value_array_get() returns an value object with the appropriate type (integer)"); + "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, - "bt_value_array_get() returns an value object with the appropriate value (integer)"); - BT_PUT(obj); - obj = bt_value_array_get(array_obj, 1); + "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_get() returns an value object with the appropriate type (real number)"); + "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, - "bt_value_array_get() returns an value object with the appropriate value (real number)"); - BT_PUT(obj); - obj = bt_value_array_get(array_obj, 2); + "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_get() returns an value object with the appropriate type (boolean)"); + "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, - "bt_value_array_get() returns an value object with the appropriate value (boolean)"); - BT_PUT(obj); - obj = bt_value_array_get(array_obj, 3); + "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, - "bt_value_array_get() returns an value object with the appropriate type (null)"); + "bt_value_array_borrow_element_by_index() returns an value object with the appropriate type (null)"); obj = bt_value_integer_create_init(1001); BT_ASSERT(obj); - ok(!bt_value_array_set(array_obj, 2, obj), - "bt_value_array_set() succeeds"); + ok(!bt_value_array_set_element_by_index(array_obj, 2, obj), + "bt_value_array_set_element_by_index() succeeds"); BT_PUT(obj); - obj = bt_value_array_get(array_obj, 2); + obj = bt_value_array_borrow_element_by_index(array_obj, 2); ok(obj && bt_value_is_integer(obj), - "bt_value_array_set() inserts an value object with the appropriate type"); + "bt_value_array_set_element_by_index() inserts an value object with the appropriate type"); ret = bt_value_integer_get(obj, &int_value); BT_ASSERT(!ret); ok(int_value == 1001, - "bt_value_array_set() inserts an value object with the appropriate value"); - BT_PUT(obj); - - ret = bt_value_array_append_bool(array_obj, BT_FALSE); - ok(!ret, "bt_value_array_append_bool() succeeds"); - ret = bt_value_array_append_integer(array_obj, 98765); - ok(!ret, "bt_value_array_append_integer() succeeds"); - ret = bt_value_array_append_real(array_obj, 2.49578); - ok(!ret, "bt_value_array_append_real() succeeds"); - ret = bt_value_array_append_string(array_obj, "bt_value"); - ok(!ret, "bt_value_array_append_string() succeeds"); - ret = bt_value_array_append_empty_array(array_obj); - ok(!ret, "bt_value_array_append_empty_array() succeeds"); - ret = bt_value_array_append_empty_map(array_obj); - ok(!ret, "bt_value_array_append_empty_map() succeeds"); - - ok(bt_value_array_size(array_obj) == 10, - "the bt_value_array_append_*() functions increment the array value object's size"); + "bt_value_array_set_element_by_index() inserts an value object with the appropriate value"); + + ret = bt_value_array_append_bool_element(array_obj, BT_FALSE); + ok(!ret, "bt_value_array_append_bool_element() succeeds"); + ret = bt_value_array_append_integer_element(array_obj, 98765); + ok(!ret, "bt_value_array_append_integer_element() succeeds"); + ret = bt_value_array_append_real_element(array_obj, 2.49578); + ok(!ret, "bt_value_array_append_real_element() succeeds"); + ret = bt_value_array_append_string_element(array_obj, "bt_value"); + ok(!ret, "bt_value_array_append_string_element() succeeds"); + ret = bt_value_array_append_empty_array_element(array_obj); + ok(!ret, "bt_value_array_append_empty_array_element() succeeds"); + ret = bt_value_array_append_empty_map_element(array_obj); + ok(!ret, "bt_value_array_append_empty_map_element() succeeds"); + + ok(bt_value_array_get_size(array_obj) == 10, + "the bt_value_array_append_element_*() functions increment the array value object's size"); ok(!bt_value_array_is_empty(array_obj), "map value object is not empty"); - obj = bt_value_array_get(array_obj, 4); + obj = bt_value_array_borrow_element_by_index(array_obj, 4); ok(obj && bt_value_is_bool(obj), - "bt_value_array_append_bool() appends a boolean value object"); + "bt_value_array_append_bool_element() appends a boolean value object"); ret = bt_value_bool_get(obj, &bool_value); ok(!ret && !bool_value, - "bt_value_array_append_bool() appends the appropriate value"); - BT_PUT(obj); - obj = bt_value_array_get(array_obj, 5); + "bt_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_value_array_append_integer() appends an integer value object"); + "bt_value_array_append_integer_element() appends an integer value object"); ret = bt_value_integer_get(obj, &int_value); ok(!ret && int_value == 98765, - "bt_value_array_append_integer() appends the appropriate value"); - BT_PUT(obj); - obj = bt_value_array_get(array_obj, 6); + "bt_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_value_array_append_real() appends a real number value object"); + "bt_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, - "bt_value_array_append_real() appends the appropriate value"); - BT_PUT(obj); - obj = bt_value_array_get(array_obj, 7); + "bt_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_value_array_append_string() appends a string value object"); + "bt_value_array_append_string_element() appends a string value object"); ret = bt_value_string_get(obj, &string_value); ok(!ret && string_value && !strcmp(string_value, "bt_value"), - "bt_value_array_append_string() appends the appropriate value"); - BT_PUT(obj); - obj = bt_value_array_get(array_obj, 8); + "bt_value_array_append_string_element() appends the appropriate value"); + obj = bt_value_array_borrow_element_by_index(array_obj, 8); ok(obj && bt_value_is_array(obj), - "bt_value_array_append_empty_array() appends an array value object"); + "bt_value_array_append_empty_array_element() appends an array value object"); ok(bt_value_array_is_empty(obj), - "bt_value_array_append_empty_array() an empty array value object"); - BT_PUT(obj); - obj = bt_value_array_get(array_obj, 9); + "bt_value_array_append_empty_array_element() an empty array value object"); + obj = bt_value_array_borrow_element_by_index(array_obj, 9); ok(obj && bt_value_is_map(obj), - "bt_value_array_append_empty_map() appends a map value object"); + "bt_value_array_append_empty_map_element() appends a map value object"); ok(bt_value_map_is_empty(obj), - "bt_value_array_append_empty_map() an empty map value object"); - BT_PUT(obj); + "bt_value_array_append_empty_map_element() an empty map value object"); BT_PUT(array_obj); pass("putting an existing array value object does not cause a crash") @@ -503,108 +493,105 @@ void test_map(void) map_obj = bt_value_map_create(); ok(map_obj && bt_value_is_map(map_obj), "bt_value_map_create() returns a map value object"); - ok(bt_value_map_size(map_obj) == 0, + ok(bt_value_map_get_size(map_obj) == 0, "initial map value object size is 0"); obj = bt_value_integer_create_init(19457); - ret = bt_value_map_insert(map_obj, "int", obj); + ret = bt_value_map_insert_entry(map_obj, "int", obj); BT_PUT(obj); obj = bt_value_real_create_init(5.444); - ret |= bt_value_map_insert(map_obj, "real", obj); + ret |= bt_value_map_insert_entry(map_obj, "real", obj); BT_PUT(obj); obj = bt_value_bool_create(); - ret |= bt_value_map_insert(map_obj, "bt_bool", obj); + ret |= bt_value_map_insert_entry(map_obj, "bt_bool", obj); BT_PUT(obj); - ret |= bt_value_map_insert(map_obj, "null", bt_value_null); - ok(!ret, "bt_value_map_insert() succeeds"); - ok(bt_value_map_size(map_obj) == 4, + ret |= bt_value_map_insert_entry(map_obj, "null", bt_value_null); + ok(!ret, "bt_value_map_insert_entry() succeeds"); + ok(bt_value_map_get_size(map_obj) == 4, "inserting an element into a map value object increment its size"); obj = bt_value_bool_create_init(BT_TRUE); - ret = bt_value_map_insert(map_obj, "bt_bool", obj); + ret = bt_value_map_insert_entry(map_obj, "bt_bool", obj); BT_PUT(obj); - ok(!ret, "bt_value_map_insert() accepts an existing key"); + ok(!ret, "bt_value_map_insert_entry() accepts an existing key"); - obj = bt_value_map_get(map_obj, "life"); - ok(!obj, "bt_value_map_get() returns NULL with an non existing key"); - obj = bt_value_map_get(map_obj, "real"); + obj = bt_value_map_borrow_entry_value(map_obj, "life"); + ok(!obj, "bt_value_map_borrow_entry_value() returns NULL with an non existing key"); + obj = bt_value_map_borrow_entry_value(map_obj, "real"); ok(obj && bt_value_is_real(obj), - "bt_value_map_get() returns an value object with the appropriate type (real)"); + "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, - "bt_value_map_get() returns an value object with the appropriate value (real)"); - BT_PUT(obj); - obj = bt_value_map_get(map_obj, "int"); + "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_get() returns an value object with the appropriate type (integer)"); + "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, - "bt_value_map_get() returns an value object with the appropriate value (integer)"); - BT_PUT(obj); - obj = bt_value_map_get(map_obj, "null"); + "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), - "bt_value_map_get() returns an value object with the appropriate type (null)"); - obj = bt_value_map_get(map_obj, "bt_bool"); + "bt_value_map_borrow_entry_value() returns an value object with the appropriate type (null)"); + obj = bt_value_map_borrow_entry_value(map_obj, "bt_bool"); ok(obj && bt_value_is_bool(obj), - "bt_value_map_get() returns an value object with the appropriate type (boolean)"); + "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, - "bt_value_map_get() returns an value object with the appropriate value (boolean)"); - BT_PUT(obj); - - ret = bt_value_map_insert_bool(map_obj, "bool2", BT_TRUE); - ok(!ret, "bt_value_map_insert_bool() succeeds"); - ret = bt_value_map_insert_integer(map_obj, "int2", 98765); - ok(!ret, "bt_value_map_insert_integer() succeeds"); - ret = bt_value_map_insert_real(map_obj, "real2", -49.0001); - ok(!ret, "bt_value_map_insert_real() succeeds"); - ret = bt_value_map_insert_string(map_obj, "string2", "bt_value"); - ok(!ret, "bt_value_map_insert_string() succeeds"); - ret = bt_value_map_insert_empty_array(map_obj, "array2"); - ok(!ret, "bt_value_map_insert_empty_array() succeeds"); - ret = bt_value_map_insert_empty_map(map_obj, "map2"); - ok(!ret, "bt_value_map_insert_empty_map() succeeds"); - - ok(bt_value_map_size(map_obj) == 10, + "bt_value_map_borrow_entry_value() returns an value object with the appropriate value (boolean)"); + + ret = bt_value_map_insert_bool_entry(map_obj, "bool2", BT_TRUE); + ok(!ret, "bt_value_map_insert_bool_entry() succeeds"); + ret = bt_value_map_insert_integer_entry(map_obj, "int2", 98765); + ok(!ret, "bt_value_map_insert_integer_entry() succeeds"); + ret = bt_value_map_insert_real_entry(map_obj, "real2", -49.0001); + ok(!ret, "bt_value_map_insert_real_entry() succeeds"); + ret = bt_value_map_insert_string_entry(map_obj, "string2", "bt_value"); + ok(!ret, "bt_value_map_insert_string_entry() succeeds"); + ret = bt_value_map_insert_empty_array_entry(map_obj, "array2"); + ok(!ret, "bt_value_map_insert_empty_array_entry() succeeds"); + ret = bt_value_map_insert_empty_map_entry(map_obj, "map2"); + ok(!ret, "bt_value_map_insert_empty_map_entry() succeeds"); + + ok(bt_value_map_get_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, "hello"), + ok(!bt_value_map_has_entry(map_obj, "hello"), "map value object does not have key \"hello\""); - ok(bt_value_map_has_key(map_obj, "bt_bool"), + ok(bt_value_map_has_entry(map_obj, "bt_bool"), "map value object has key \"bt_bool\""); - ok(bt_value_map_has_key(map_obj, "int"), + ok(bt_value_map_has_entry(map_obj, "int"), "map value object has key \"int\""); - ok(bt_value_map_has_key(map_obj, "real"), + ok(bt_value_map_has_entry(map_obj, "real"), "map value object has key \"real\""); - ok(bt_value_map_has_key(map_obj, "null"), + ok(bt_value_map_has_entry(map_obj, "null"), "map value object has key \"null\""); - ok(bt_value_map_has_key(map_obj, "bool2"), + ok(bt_value_map_has_entry(map_obj, "bool2"), "map value object has key \"bool2\""); - ok(bt_value_map_has_key(map_obj, "int2"), + ok(bt_value_map_has_entry(map_obj, "int2"), "map value object has key \"int2\""); - ok(bt_value_map_has_key(map_obj, "real2"), + ok(bt_value_map_has_entry(map_obj, "real2"), "map value object has key \"real2\""); - ok(bt_value_map_has_key(map_obj, "string2"), + ok(bt_value_map_has_entry(map_obj, "string2"), "map value object has key \"string2\""); - ok(bt_value_map_has_key(map_obj, "array2"), + ok(bt_value_map_has_entry(map_obj, "array2"), "map value object has key \"array2\""); - ok(bt_value_map_has_key(map_obj, "map2"), + ok(bt_value_map_has_entry(map_obj, "map2"), "map value object has key \"map2\""); - ret = bt_value_map_foreach(map_obj, test_map_foreach_cb_count, &count); + ret = bt_value_map_foreach_entry(map_obj, test_map_foreach_cb_count, &count); ok(ret == BT_VALUE_STATUS_CANCELED && count == 3, - "bt_value_map_foreach() breaks the loop when the user function returns BT_FALSE"); + "bt_value_map_foreach_entry() breaks the loop when the user function returns BT_FALSE"); memset(&checklist, 0, sizeof(checklist)); - ret = bt_value_map_foreach(map_obj, test_map_foreach_cb_check, + ret = bt_value_map_foreach_entry(map_obj, test_map_foreach_cb_check, &checklist); ok(ret == BT_VALUE_STATUS_OK, - "bt_value_map_foreach() succeeds with test_map_foreach_cb_check()"); + "bt_value_map_foreach_entry() succeeds with test_map_foreach_cb_check()"); ok(checklist.bool1 && checklist.int1 && checklist.real1 && checklist.null1 && checklist.bool2 && checklist.int2 && checklist.real2 && checklist.string2 && checklist.array2 && checklist.map2, - "bt_value_map_foreach() iterates over all the map value object's elements"); + "bt_value_map_foreach_entry() iterates over all the map value object's elements"); BT_PUT(map_obj); pass("putting an existing map value object does not cause a crash") @@ -723,18 +710,18 @@ void test_compare_array(void) ok(bt_value_compare(array1, array2), "empty array value objects are equivalent"); - BT_ASSERT(!bt_value_array_append_integer(array1, 23)); - BT_ASSERT(!bt_value_array_append_real(array1, 14.2)); - BT_ASSERT(!bt_value_array_append_bool(array1, BT_FALSE)); - BT_ASSERT(!bt_value_array_append_real(array2, 14.2)); - BT_ASSERT(!bt_value_array_append_integer(array2, 23)); - BT_ASSERT(!bt_value_array_append_bool(array2, BT_FALSE)); - BT_ASSERT(!bt_value_array_append_integer(array3, 23)); - BT_ASSERT(!bt_value_array_append_real(array3, 14.2)); - BT_ASSERT(!bt_value_array_append_bool(array3, BT_FALSE)); - BT_ASSERT(bt_value_array_size(array1) == 3); - BT_ASSERT(bt_value_array_size(array2) == 3); - BT_ASSERT(bt_value_array_size(array3) == 3); + BT_ASSERT(!bt_value_array_append_integer_element(array1, 23)); + BT_ASSERT(!bt_value_array_append_real_element(array1, 14.2)); + BT_ASSERT(!bt_value_array_append_bool_element(array1, BT_FALSE)); + BT_ASSERT(!bt_value_array_append_real_element(array2, 14.2)); + BT_ASSERT(!bt_value_array_append_integer_element(array2, 23)); + BT_ASSERT(!bt_value_array_append_bool_element(array2, BT_FALSE)); + BT_ASSERT(!bt_value_array_append_integer_element(array3, 23)); + BT_ASSERT(!bt_value_array_append_real_element(array3, 14.2)); + BT_ASSERT(!bt_value_array_append_bool_element(array3, BT_FALSE)); + BT_ASSERT(bt_value_array_get_size(array1) == 3); + BT_ASSERT(bt_value_array_get_size(array2) == 3); + BT_ASSERT(bt_value_array_get_size(array3) == 3); ok(!bt_value_compare(bt_value_null, array1), "cannot compare null value object and array value object"); @@ -760,18 +747,18 @@ void test_compare_map(void) ok(bt_value_compare(map1, map2), "empty map value objects are equivalent"); - BT_ASSERT(!bt_value_map_insert_integer(map1, "one", 23)); - BT_ASSERT(!bt_value_map_insert_real(map1, "two", 14.2)); - BT_ASSERT(!bt_value_map_insert_bool(map1, "three", BT_FALSE)); - BT_ASSERT(!bt_value_map_insert_real(map2, "one", 14.2)); - BT_ASSERT(!bt_value_map_insert_integer(map2, "two", 23)); - BT_ASSERT(!bt_value_map_insert_bool(map2, "three", BT_FALSE)); - BT_ASSERT(!bt_value_map_insert_bool(map3, "three", BT_FALSE)); - BT_ASSERT(!bt_value_map_insert_integer(map3, "one", 23)); - BT_ASSERT(!bt_value_map_insert_real(map3, "two", 14.2)); - BT_ASSERT(bt_value_map_size(map1) == 3); - BT_ASSERT(bt_value_map_size(map2) == 3); - BT_ASSERT(bt_value_map_size(map3) == 3); + BT_ASSERT(!bt_value_map_insert_integer_entry(map1, "one", 23)); + BT_ASSERT(!bt_value_map_insert_real_entry(map1, "two", 14.2)); + BT_ASSERT(!bt_value_map_insert_bool_entry(map1, "three", BT_FALSE)); + BT_ASSERT(!bt_value_map_insert_real_entry(map2, "one", 14.2)); + BT_ASSERT(!bt_value_map_insert_integer_entry(map2, "two", 23)); + BT_ASSERT(!bt_value_map_insert_bool_entry(map2, "three", BT_FALSE)); + BT_ASSERT(!bt_value_map_insert_bool_entry(map3, "three", BT_FALSE)); + BT_ASSERT(!bt_value_map_insert_integer_entry(map3, "one", 23)); + BT_ASSERT(!bt_value_map_insert_real_entry(map3, "two", 14.2)); + BT_ASSERT(bt_value_map_get_size(map1) == 3); + BT_ASSERT(bt_value_map_get_size(map2) == 3); + BT_ASSERT(bt_value_map_get_size(map3) == 3); ok(!bt_value_compare(bt_value_null, map1), "cannot compare null value object and map value object"); @@ -826,12 +813,12 @@ void test_copy(void) BT_ASSERT(bool_obj && integer_obj && real_obj && string_obj && array_obj && map_obj); - BT_ASSERT(!bt_value_array_append(array_obj, bool_obj)); - BT_ASSERT(!bt_value_array_append(array_obj, integer_obj)); - BT_ASSERT(!bt_value_array_append(array_obj, real_obj)); - BT_ASSERT(!bt_value_array_append(array_obj, bt_value_null)); - BT_ASSERT(!bt_value_map_insert(map_obj, "array", array_obj)); - BT_ASSERT(!bt_value_map_insert(map_obj, "string", string_obj)); + BT_ASSERT(!bt_value_array_append_element(array_obj, bool_obj)); + BT_ASSERT(!bt_value_array_append_element(array_obj, integer_obj)); + BT_ASSERT(!bt_value_array_append_element(array_obj, real_obj)); + BT_ASSERT(!bt_value_array_append_element(array_obj, bt_value_null)); + BT_ASSERT(!bt_value_map_insert_entry(map_obj, "array", array_obj)); + BT_ASSERT(!bt_value_map_insert_entry(map_obj, "string", string_obj)); map_copy_obj = bt_value_copy(map_obj); ok(map_copy_obj, @@ -839,33 +826,28 @@ void test_copy(void) ok(map_obj != map_copy_obj, "bt_value_copy() returns a different pointer (map)"); - string_copy_obj = bt_value_map_get(map_copy_obj, "string"); + string_copy_obj = bt_value_map_borrow_entry_value(map_copy_obj, "string"); ok(string_copy_obj != string_obj, "bt_value_copy() returns a different pointer (string)"); - array_copy_obj = bt_value_map_get(map_copy_obj, "array"); + array_copy_obj = bt_value_map_borrow_entry_value(map_copy_obj, "array"); ok(array_copy_obj != array_obj, "bt_value_copy() returns a different pointer (array)"); - bool_copy_obj = bt_value_array_get(array_copy_obj, 0); + bool_copy_obj = bt_value_array_borrow_element_by_index(array_copy_obj, 0); ok(bool_copy_obj != bool_obj, "bt_value_copy() returns a different pointer (bt_bool)"); - integer_copy_obj = bt_value_array_get(array_copy_obj, 1); + integer_copy_obj = bt_value_array_borrow_element_by_index(array_copy_obj, 1); ok(integer_copy_obj != integer_obj, "bt_value_copy() returns a different pointer (integer)"); - real_copy_obj = bt_value_array_get(array_copy_obj, 2); + real_copy_obj = bt_value_array_borrow_element_by_index(array_copy_obj, 2); ok(real_copy_obj != real_obj, "bt_value_copy() returns a different pointer (real)"); - null_copy_obj = bt_value_array_get(array_copy_obj, 3); + null_copy_obj = bt_value_array_borrow_element_by_index(array_copy_obj, 3); ok(null_copy_obj == bt_value_null, "bt_value_copy() returns the same pointer (null)"); ok(bt_value_compare(map_obj, map_copy_obj), "source and destination value objects have the same content"); - BT_PUT(bool_copy_obj); - BT_PUT(integer_copy_obj); - BT_PUT(real_copy_obj); - BT_PUT(string_copy_obj); - BT_PUT(array_copy_obj); BT_PUT(map_copy_obj); BT_PUT(bool_obj); BT_PUT(integer_obj); @@ -883,12 +865,9 @@ bt_bool compare_map_elements(struct bt_value *map_a, struct bt_value *map_b, struct bt_value *elem_b = NULL; bt_bool equal; - elem_a = bt_value_map_get(map_a, key); - elem_b = bt_value_map_get(map_b, key); + elem_a = bt_value_map_borrow_entry_value(map_a, key); + elem_b = bt_value_map_borrow_entry_value(map_b, key); equal = bt_value_compare(elem_a, elem_b); - BT_PUT(elem_a); - BT_PUT(elem_b); - return equal; } @@ -904,23 +883,23 @@ void test_extend(void) BT_ASSERT(base_map); BT_ASSERT(extension_map); BT_ASSERT(array); - status = bt_value_map_insert_bool(base_map, "file", BT_TRUE); + status = bt_value_map_insert_bool_entry(base_map, "file", BT_TRUE); BT_ASSERT(status == BT_VALUE_STATUS_OK); - status = bt_value_map_insert_bool(base_map, "edit", BT_FALSE); + status = bt_value_map_insert_bool_entry(base_map, "edit", BT_FALSE); BT_ASSERT(status == BT_VALUE_STATUS_OK); - status = bt_value_map_insert_integer(base_map, "selection", 17); + status = bt_value_map_insert_integer_entry(base_map, "selection", 17); BT_ASSERT(status == BT_VALUE_STATUS_OK); - status = bt_value_map_insert_integer(base_map, "find", -34); + status = bt_value_map_insert_integer_entry(base_map, "find", -34); BT_ASSERT(status == BT_VALUE_STATUS_OK); - status = bt_value_map_insert_bool(extension_map, "edit", BT_TRUE); + status = bt_value_map_insert_bool_entry(extension_map, "edit", BT_TRUE); BT_ASSERT(status == BT_VALUE_STATUS_OK); - status = bt_value_map_insert_integer(extension_map, "find", 101); + status = bt_value_map_insert_integer_entry(extension_map, "find", 101); BT_ASSERT(status == BT_VALUE_STATUS_OK); - status = bt_value_map_insert_real(extension_map, "project", -404); + status = bt_value_map_insert_real_entry(extension_map, "project", -404); BT_ASSERT(status == BT_VALUE_STATUS_OK); 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, + ok(bt_value_map_get_size(extended_map) == 5, "bt_value_map_extend() returns a map object with the correct size"); ok(compare_map_elements(base_map, extended_map, "file"), "bt_value_map_extend() picks the appropriate element (file)"); diff --git a/tests/lib/test_plugin.c b/tests/lib/test_plugin.c index 2cba9547..13f7e8c4 100644 --- a/tests/lib/test_plugin.c +++ b/tests/lib/test_plugin.c @@ -230,14 +230,14 @@ static void test_sfs(const char *plugin_dir) ret = bt_query_executor_query(query_exec, filter_comp_class, "get-something", params, &results); ok(ret == 0 && results, "bt_query_executor_query() succeeds"); - BT_ASSERT(bt_value_is_array(results) && bt_value_array_size(results) == 2); - object = bt_value_array_get(results, 0); + 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); ok(strcmp(object_str, "get-something") == 0, "bt_component_class_query() receives the expected object name"); - res_params = bt_value_array_get(results, 1); + res_params = bt_value_array_borrow_element_by_index(results, 1); ok(res_params == params, "bt_component_class_query() receives the expected parameters"); @@ -273,8 +273,6 @@ static void test_sfs(const char *plugin_dir) free(sfs_path); bt_put(graph); bt_put(plugin_set); - bt_put(object); - bt_put(res_params); bt_put(results); bt_put(params); bt_put(query_exec); -- 2.34.1