From da91b29ad2964b85601e25843f1dca92f6c97406 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Fri, 16 Nov 2018 12:59:13 -0500 Subject: [PATCH] Values API: split into private and public APIs Signed-off-by: Philippe Proulx --- cli/babeltrace-cfg-cli-args-connect.c | 25 +- cli/babeltrace-cfg-cli-args-default.c | 5 +- cli/babeltrace-cfg-cli-args.c | 312 ++-- cli/babeltrace-cfg-cli-args.h | 2 +- cli/babeltrace-cfg.c | 6 +- cli/babeltrace-cfg.h | 6 +- cli/babeltrace.c | 71 +- include/Makefile.am | 1 + include/babeltrace/babeltrace.h | 1 + include/babeltrace/common-internal.h | 24 + .../ctf-writer/attributes-internal.h | 22 +- .../babeltrace/ctf-writer/resolve-internal.h | 4 +- .../babeltrace/ctf-writer/trace-internal.h | 11 +- include/babeltrace/ctf-writer/trace.h | 4 - .../ctf-writer/validation-internal.h | 4 +- include/babeltrace/private-values.h | 142 ++ .../babeltrace/trace-ir/attributes-internal.h | 21 +- include/babeltrace/trace-ir/trace-internal.h | 2 +- include/babeltrace/values-internal.h | 40 - include/babeltrace/values.h | 1254 +---------------- lib/ctf-writer/attributes.c | 106 +- lib/ctf-writer/event.c | 2 +- lib/ctf-writer/resolve.c | 4 +- lib/ctf-writer/trace.c | 43 +- lib/ctf-writer/validation.c | 8 +- lib/graph/graph.c | 8 +- lib/lib-logging.c | 2 +- lib/trace-ir/attributes.c | 121 +- lib/trace-ir/trace.c | 28 +- lib/values.c | 314 +++-- plugins/ctf/fs-src/query.c | 84 +- plugins/ctf/lttng-live/viewer-connection.c | 22 +- plugins/text/dmesg/dmesg.c | 5 +- plugins/text/pretty/pretty.c | 13 +- plugins/text/pretty/pretty.h | 2 +- plugins/utils/muxer/muxer.c | 21 +- tests/lib/test-plugin-plugins/sfs.c | 8 +- tests/lib/test_bt_values.c | 587 +++++--- tests/lib/test_ctf_writer.c | 40 +- tests/lib/test_plugin.c | 16 +- 40 files changed, 1272 insertions(+), 2119 deletions(-) create mode 100644 include/babeltrace/private-values.h diff --git a/cli/babeltrace-cfg-cli-args-connect.c b/cli/babeltrace-cfg-cli-args-connect.c index fc692391..b693455c 100644 --- a/cli/babeltrace-cfg-cli-args-connect.c +++ b/cli/babeltrace-cfg-cli-args-connect.c @@ -22,6 +22,7 @@ #include #include +#include #include #include "babeltrace-cfg.h" #include "babeltrace-cfg-cli-args-connect.h" @@ -534,7 +535,8 @@ static int validate_all_components_connected(struct bt_config *cfg, { size_t i; int ret = 0; - struct bt_value *connected_components = bt_value_map_create(); + struct bt_private_value *connected_components = + bt_private_value_map_create(); if (!connected_components) { ret = -1; @@ -545,13 +547,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_entry(connected_components, + ret = bt_private_value_map_insert_entry(connected_components, connection->upstream_comp_name->str, bt_value_null); if (ret) { goto end; } - ret = bt_value_map_insert_entry(connected_components, + ret = bt_private_value_map_insert_entry(connected_components, connection->downstream_comp_name->str, bt_value_null); if (ret) { goto end; @@ -559,21 +561,24 @@ static int validate_all_components_connected(struct bt_config *cfg, } ret = validate_all_components_connected_in_array( - cfg->cmd_data.run.sources, connected_components, + cfg->cmd_data.run.sources, + bt_value_borrow_from_private(connected_components), error_buf, error_buf_size); if (ret) { goto end; } ret = validate_all_components_connected_in_array( - cfg->cmd_data.run.filters, connected_components, + cfg->cmd_data.run.filters, + bt_value_borrow_from_private(connected_components), error_buf, error_buf_size); if (ret) { goto end; } ret = validate_all_components_connected_in_array( - cfg->cmd_data.run.sinks, connected_components, + cfg->cmd_data.run.sinks, + bt_value_borrow_from_private(connected_components), error_buf, error_buf_size); if (ret) { goto end; @@ -589,7 +594,8 @@ static int validate_no_duplicate_connection(struct bt_config *cfg, { size_t i; int ret = 0; - struct bt_value *flat_connection_names = bt_value_map_create(); + struct bt_private_value *flat_connection_names = + bt_private_value_map_create(); GString *flat_connection_name = NULL; if (!flat_connection_names) { @@ -613,7 +619,8 @@ 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_entry(flat_connection_names, + if (bt_value_map_has_entry(bt_value_borrow_from_private( + flat_connection_names), flat_connection_name->str)) { snprintf(error_buf, error_buf_size, "Duplicate connection:\n %s\n", @@ -622,7 +629,7 @@ static int validate_no_duplicate_connection(struct bt_config *cfg, goto end; } - ret = bt_value_map_insert_entry(flat_connection_names, + ret = bt_private_value_map_insert_entry(flat_connection_names, flat_connection_name->str, bt_value_null); if (ret) { goto end; diff --git a/cli/babeltrace-cfg-cli-args-default.c b/cli/babeltrace-cfg-cli-args-default.c index dad339ad..61251726 100644 --- a/cli/babeltrace-cfg-cli-args-default.c +++ b/cli/babeltrace-cfg-cli-args-default.c @@ -22,6 +22,7 @@ */ #include +#include #include "babeltrace-cfg.h" #include "babeltrace-cfg-cli-args.h" #include "babeltrace-cfg-cli-args-default.h" @@ -37,11 +38,11 @@ struct bt_config *bt_config_cli_args_create_with_default(int argc, const char *argv[], int *retcode) { - struct bt_value *initial_plugin_paths; + struct bt_private_value *initial_plugin_paths; struct bt_config *cfg = NULL; int ret; - initial_plugin_paths = bt_value_array_create(); + initial_plugin_paths = bt_private_value_array_create(); if (!initial_plugin_paths) { goto error; } diff --git a/cli/babeltrace-cfg-cli-args.c b/cli/babeltrace-cfg-cli-args.c index 1fb9add0..b844b4e4 100644 --- a/cli/babeltrace-cfg-cli-args.c +++ b/cli/babeltrace-cfg-cli-args.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -84,7 +85,7 @@ struct ini_parsing_state { GScanner *scanner; /* Output map value object being filled (owned by this) */ - struct bt_value *params; + struct bt_private_value *params; /* Next expected FSM state */ enum ini_parsing_fsm_state expecting; @@ -241,7 +242,9 @@ int ini_handle_state(struct ini_parsing_state *state) goto error; } - if (bt_value_map_has_entry(state->params, state->last_map_key)) { + if (bt_value_map_has_entry( + bt_value_borrow_from_private(state->params), + state->last_map_key)) { g_string_append_printf(state->ini_error, "Duplicate parameter key: `%s`\n", state->last_map_key); @@ -292,19 +295,22 @@ int ini_handle_state(struct ini_parsing_state *state) goto error; } - value = bt_value_integer_create_init( - (int64_t) int_val); + value = bt_value_borrow_from_private( + bt_private_value_integer_create_init( + (int64_t) int_val)); break; } case G_TOKEN_FLOAT: /* Positive floating point number */ - value = bt_value_real_create_init( - state->scanner->value.v_float); + value = bt_value_borrow_from_private( + bt_private_value_real_create_init( + state->scanner->value.v_float)); break; case G_TOKEN_STRING: /* Quoted string */ - value = bt_value_string_create_init( - state->scanner->value.v_string); + value = bt_value_borrow_from_private( + bt_private_value_string_create_init( + state->scanner->value.v_string)); break; case G_TOKEN_IDENTIFIER: { @@ -326,14 +332,17 @@ int ini_handle_state(struct ini_parsing_state *state) } else if (!strcmp(id, "true") || !strcmp(id, "TRUE") || !strcmp(id, "yes") || !strcmp(id, "YES")) { - value = bt_value_bool_create_init(true); + value = bt_value_borrow_from_private( + bt_private_value_bool_create_init(true)); } else if (!strcmp(id, "false") || !strcmp(id, "FALSE") || !strcmp(id, "no") || !strcmp(id, "NO")) { - value = bt_value_bool_create_init(false); + value = bt_value_borrow_from_private( + bt_private_value_bool_create_init(false)); } else { - value = bt_value_string_create_init(id); + value = bt_value_borrow_from_private( + bt_private_value_string_create_init(id)); } break; } @@ -366,14 +375,16 @@ int ini_handle_state(struct ini_parsing_state *state) goto error; } - value = bt_value_integer_create_init( - -((int64_t) int_val)); + value = bt_value_borrow_from_private( + bt_private_value_integer_create_init( + -((int64_t) int_val))); break; } case G_TOKEN_FLOAT: /* Negative floating point number */ - value = bt_value_real_create_init( - -state->scanner->value.v_float); + value = bt_value_borrow_from_private( + bt_private_value_real_create_init( + -state->scanner->value.v_float)); break; default: /* Unset value variable will trigger the error */ @@ -414,7 +425,7 @@ error: success: if (value) { - if (bt_value_map_insert_entry(state->params, + if (bt_private_value_map_insert_entry(state->params, state->last_map_key, value)) { /* Only override return value on error */ ret = -1; @@ -432,7 +443,8 @@ end: * Return value is owned by the caller. */ static -struct bt_value *bt_value_from_ini(const char *arg, GString *ini_error) +struct bt_private_value *bt_private_value_from_ini(const char *arg, + GString *ini_error) { /* Lexical scanner configuration */ GScannerConfig scanner_config = { @@ -511,7 +523,7 @@ struct bt_value *bt_value_from_ini(const char *arg, GString *ini_error) .ini_error = ini_error, }; - state.params = bt_value_map_create(); + state.params = bt_private_value_map_create(); if (!state.params) { goto error; } @@ -557,9 +569,9 @@ end: * Return value is owned by the caller. */ static -struct bt_value *bt_value_from_arg(const char *arg) +struct bt_private_value *bt_private_value_from_arg(const char *arg) { - struct bt_value *params = NULL; + struct bt_private_value *params = NULL; GString *ini_error = NULL; ini_error = g_string_new(NULL); @@ -569,7 +581,7 @@ struct bt_value *bt_value_from_arg(const char *arg) } /* Try INI-style parsing */ - params = bt_value_from_ini(arg, ini_error); + params = bt_private_value_from_ini(arg, ini_error); if (!params) { printf_err("%s", ini_error->str); goto end; @@ -579,6 +591,7 @@ end: if (ini_error) { g_string_free(ini_error, TRUE); } + return params; } @@ -811,7 +824,7 @@ struct bt_config_component *bt_config_component_create( } /* Start with empty parameters */ - cfg_component->params = bt_value_map_create(); + cfg_component->params = bt_private_value_map_create(); if (!cfg_component->params) { print_err_oom(); goto error; @@ -1010,13 +1023,13 @@ GScanner *create_csv_identifiers_scanner(void) * Return value is owned by the caller. */ static -struct bt_value *names_from_arg(const char *arg) +struct bt_private_value *names_from_arg(const char *arg) { GScanner *scanner = NULL; - struct bt_value *names = NULL; + struct bt_private_value *names = NULL; bool found_all = false, found_none = false, found_item = false; - names = bt_value_array_create(); + names = bt_private_value_array_create(); if (!names) { print_err_oom(); goto error; @@ -1041,33 +1054,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_element(names, + if (bt_private_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_element(names, + if (bt_private_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_element(names, + if (bt_private_value_array_append_string_element(names, identifier)) { goto error; } } else if (!strcmp(identifier, "all")) { found_all = true; - if (bt_value_array_append_string_element(names, + if (bt_private_value_array_append_string_element(names, identifier)) { goto error; } } else if (!strcmp(identifier, "none")) { found_none = true; - if (bt_value_array_append_string_element(names, + if (bt_private_value_array_append_string_element(names, identifier)) { goto error; } @@ -1097,7 +1110,7 @@ end: * least one item is specified. */ if (found_item && !found_none && !found_all) { - if (bt_value_array_append_string_element(names, "none")) { + if (bt_private_value_array_append_string_element(names, "none")) { goto error; } } @@ -1122,12 +1135,12 @@ error: * Return value is owned by the caller. */ static -struct bt_value *fields_from_arg(const char *arg) +struct bt_private_value *fields_from_arg(const char *arg) { GScanner *scanner = NULL; - struct bt_value *fields; + struct bt_private_value *fields; - fields = bt_value_array_create(); + fields = bt_private_value_array_create(); if (!fields) { print_err_oom(); goto error; @@ -1157,7 +1170,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_element(fields, + if (bt_private_value_array_append_string_element(fields, identifier)) { goto error; } @@ -1385,7 +1398,7 @@ static int add_run_cfg_comp_check_name(struct bt_config *cfg, struct bt_config_component *cfg_comp, enum bt_config_component_dest dest, - struct bt_value *instance_names) + struct bt_private_value *instance_names) { int ret = 0; @@ -1395,14 +1408,15 @@ int add_run_cfg_comp_check_name(struct bt_config *cfg, goto end; } - if (bt_value_map_has_entry(instance_names, cfg_comp->instance_name->str)) { + if (bt_value_map_has_entry(bt_value_borrow_from_private(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_entry(instance_names, + if (bt_private_value_map_insert_entry(instance_names, cfg_comp->instance_name->str, bt_value_null)) { print_err_oom(); ret = -1; @@ -1416,7 +1430,7 @@ end: } static -int append_env_var_plugin_paths(struct bt_value *plugin_paths) +int append_env_var_plugin_paths(struct bt_private_value *plugin_paths) { int ret = 0; const char *envvar; @@ -1442,7 +1456,7 @@ end: } static -int append_home_and_system_plugin_paths(struct bt_value *plugin_paths, +int append_home_and_system_plugin_paths(struct bt_private_value *plugin_paths, bool omit_system_plugin_path, bool omit_home_plugin_path) { int ret; @@ -1489,7 +1503,8 @@ int append_home_and_system_plugin_paths_cfg(struct bt_config *cfg) static struct bt_config *bt_config_base_create(enum bt_config_command command, - struct bt_value *initial_plugin_paths, bool needs_plugins) + struct bt_private_value *initial_plugin_paths, + bool needs_plugins) { struct bt_config *cfg; @@ -1507,7 +1522,7 @@ struct bt_config *bt_config_base_create(enum bt_config_command command, if (initial_plugin_paths) { cfg->plugin_paths = bt_object_get_ref(initial_plugin_paths); } else { - cfg->plugin_paths = bt_value_array_create(); + cfg->plugin_paths = bt_private_value_array_create(); if (!cfg->plugin_paths) { print_err_oom(); goto error; @@ -1525,7 +1540,7 @@ end: static struct bt_config *bt_config_run_create( - struct bt_value *initial_plugin_paths) + struct bt_private_value *initial_plugin_paths) { struct bt_config *cfg; @@ -1575,7 +1590,7 @@ end: static struct bt_config *bt_config_list_plugins_create( - struct bt_value *initial_plugin_paths) + struct bt_private_value *initial_plugin_paths) { struct bt_config *cfg; @@ -1597,7 +1612,7 @@ end: static struct bt_config *bt_config_help_create( - struct bt_value *initial_plugin_paths) + struct bt_private_value *initial_plugin_paths) { struct bt_config *cfg; @@ -1626,7 +1641,7 @@ end: static struct bt_config *bt_config_query_create( - struct bt_value *initial_plugin_paths) + struct bt_private_value *initial_plugin_paths) { struct bt_config *cfg; @@ -1654,7 +1669,7 @@ end: static struct bt_config *bt_config_print_ctf_metadata_create( - struct bt_value *initial_plugin_paths) + struct bt_private_value *initial_plugin_paths) { struct bt_config *cfg; @@ -1688,7 +1703,7 @@ end: static struct bt_config *bt_config_print_lttng_live_sessions_create( - struct bt_value *initial_plugin_paths) + struct bt_private_value *initial_plugin_paths) { struct bt_config *cfg; @@ -1723,7 +1738,7 @@ end: static int bt_config_append_plugin_paths_check_setuid_setgid( - struct bt_value *plugin_paths, const char *arg) + struct bt_private_value *plugin_paths, const char *arg) { int ret = 0; @@ -1824,7 +1839,7 @@ static struct bt_config *bt_config_help_from_args(int argc, const char *argv[], int *retcode, bool force_omit_system_plugin_path, bool force_omit_home_plugin_path, - struct bt_value *initial_plugin_paths) + struct bt_private_value *initial_plugin_paths) { poptContext pc = NULL; char *arg = NULL; @@ -1988,7 +2003,7 @@ static struct bt_config *bt_config_query_from_args(int argc, const char *argv[], int *retcode, bool force_omit_system_plugin_path, bool force_omit_home_plugin_path, - struct bt_value *initial_plugin_paths) + struct bt_private_value *initial_plugin_paths) { poptContext pc = NULL; char *arg = NULL; @@ -1996,7 +2011,7 @@ struct bt_config *bt_config_query_from_args(int argc, const char *argv[], int ret; struct bt_config *cfg = NULL; const char *leftover; - struct bt_value *params = bt_value_null; + struct bt_private_value *params = bt_private_value_null; *retcode = 0; cfg = bt_config_query_create(initial_plugin_paths); @@ -2040,7 +2055,7 @@ struct bt_config *bt_config_query_from_args(int argc, const char *argv[], case OPT_PARAMS: { bt_object_put_ref(params); - params = bt_value_from_arg(arg); + params = bt_private_value_from_arg(arg); if (!params) { printf_err("Invalid format for --params option's argument:\n %s\n", arg); @@ -2085,7 +2100,8 @@ struct bt_config *bt_config_query_from_args(int argc, const char *argv[], } BT_ASSERT(params); - BT_OBJECT_MOVE_REF(cfg->cmd_data.query.cfg_component->params, params); + BT_OBJECT_MOVE_REF(cfg->cmd_data.query.cfg_component->params, + params); } else { print_query_usage(stdout); *retcode = -1; @@ -2176,7 +2192,7 @@ static struct bt_config *bt_config_list_plugins_from_args(int argc, const char *argv[], int *retcode, bool force_omit_system_plugin_path, bool force_omit_home_plugin_path, - struct bt_value *initial_plugin_paths) + struct bt_private_value *initial_plugin_paths) { poptContext pc = NULL; char *arg = NULL; @@ -2366,18 +2382,18 @@ static struct bt_config *bt_config_run_from_args(int argc, const char *argv[], int *retcode, bool force_omit_system_plugin_path, bool force_omit_home_plugin_path, - struct bt_value *initial_plugin_paths) + struct bt_private_value *initial_plugin_paths) { poptContext pc = NULL; char *arg = NULL; struct bt_config_component *cur_cfg_comp = NULL; enum bt_config_component_dest cur_cfg_comp_dest = BT_CONFIG_COMPONENT_DEST_UNKNOWN; - struct bt_value *cur_base_params = NULL; + struct bt_private_value *cur_base_params = NULL; int opt, ret = 0; struct bt_config *cfg = NULL; - struct bt_value *instance_names = NULL; - struct bt_value *connection_args = NULL; + struct bt_private_value *instance_names = NULL; + struct bt_private_value *connection_args = NULL; GString *cur_param_key = NULL; char error_buf[256] = { 0 }; long retry_duration = -1; @@ -2419,19 +2435,19 @@ struct bt_config *bt_config_run_from_args(int argc, const char *argv[], cfg->cmd_data.run.retry_duration_us = 100000; cfg->omit_system_plugin_path = force_omit_system_plugin_path; cfg->omit_home_plugin_path = force_omit_home_plugin_path; - cur_base_params = bt_value_map_create(); + cur_base_params = bt_private_value_map_create(); if (!cur_base_params) { print_err_oom(); goto error; } - instance_names = bt_value_map_create(); + instance_names = bt_private_value_map_create(); if (!instance_names) { print_err_oom(); goto error; } - connection_args = bt_value_array_create(); + connection_args = bt_private_value_array_create(); if (!connection_args) { print_err_oom(); goto error; @@ -2505,7 +2521,8 @@ struct bt_config *bt_config_run_from_args(int argc, const char *argv[], BT_ASSERT(cur_base_params); bt_object_put_ref(cur_cfg_comp->params); - cur_cfg_comp->params = bt_value_copy(cur_base_params); + cur_cfg_comp->params = bt_value_copy( + bt_value_borrow_from_private(cur_base_params)); if (!cur_cfg_comp->params) { print_err_oom(); goto error; @@ -2516,8 +2533,8 @@ struct bt_config *bt_config_run_from_args(int argc, const char *argv[], } case OPT_PARAMS: { - struct bt_value *params; - struct bt_value *params_to_set; + struct bt_private_value *params; + struct bt_private_value *params_to_set; if (!cur_cfg_comp) { printf_err("Cannot add parameters to unavailable component:\n %s\n", @@ -2525,15 +2542,16 @@ struct bt_config *bt_config_run_from_args(int argc, const char *argv[], goto error; } - params = bt_value_from_arg(arg); + params = bt_private_value_from_arg(arg); if (!params) { printf_err("Invalid format for --params option's argument:\n %s\n", arg); goto error; } - params_to_set = bt_value_map_extend(cur_cfg_comp->params, - params); + params_to_set = bt_value_map_extend( + bt_value_borrow_from_private(cur_cfg_comp->params), + bt_value_borrow_from_private(params)); BT_OBJECT_PUT_REF_AND_RESET(params); if (!params_to_set) { printf_err("Cannot extend current component parameters with --params option's argument:\n %s\n", @@ -2565,7 +2583,7 @@ struct bt_config *bt_config_run_from_args(int argc, const char *argv[], goto error; } - if (bt_value_map_insert_string_entry(cur_cfg_comp->params, + if (bt_private_value_map_insert_string_entry(cur_cfg_comp->params, cur_param_key->str, arg)) { print_err_oom(); goto error; @@ -2582,7 +2600,8 @@ struct bt_config *bt_config_run_from_args(int argc, const char *argv[], break; case OPT_BASE_PARAMS: { - struct bt_value *params = bt_value_from_arg(arg); + struct bt_private_value *params = + bt_private_value_from_arg(arg); if (!params) { printf_err("Invalid format for --base-params option's argument:\n %s\n", @@ -2595,14 +2614,14 @@ struct bt_config *bt_config_run_from_args(int argc, const char *argv[], } case OPT_RESET_BASE_PARAMS: BT_OBJECT_PUT_REF_AND_RESET(cur_base_params); - cur_base_params = bt_value_map_create(); + cur_base_params = bt_private_value_map_create(); if (!cur_base_params) { print_err_oom(); goto error; } break; case OPT_CONNECT: - if (bt_value_array_append_string_element( + if (bt_private_value_array_append_string_element( connection_args, arg)) { print_err_oom(); goto error; @@ -2670,7 +2689,8 @@ struct bt_config *bt_config_run_from_args(int argc, const char *argv[], goto error; } - ret = bt_config_cli_args_create_connections(cfg, connection_args, + ret = bt_config_cli_args_create_connections(cfg, + bt_value_borrow_from_private(connection_args), error_buf, 256); if (ret) { printf_err("Cannot creation connections:\n%s", error_buf); @@ -2704,7 +2724,7 @@ static struct bt_config *bt_config_run_from_args_array(struct bt_value *run_args, int *retcode, bool force_omit_system_plugin_path, bool force_omit_home_plugin_path, - struct bt_value *initial_plugin_paths) + struct bt_private_value *initial_plugin_paths) { struct bt_config *cfg = NULL; const char **argv; @@ -2955,12 +2975,12 @@ struct implicit_component_args { GString *comp_arg; GString *name_arg; GString *params_arg; - struct bt_value *extra_params; + struct bt_private_value *extra_params; }; static int assign_name_to_implicit_component(struct implicit_component_args *args, - const char *prefix, struct bt_value *existing_names, + const char *prefix, struct bt_private_value *existing_names, GList **comp_names, bool append_to_comp_names) { int ret = 0; @@ -2970,7 +2990,8 @@ int assign_name_to_implicit_component(struct implicit_component_args *args, goto end; } - name = get_component_auto_name(prefix, existing_names); + name = get_component_auto_name(prefix, + bt_value_borrow_from_private(existing_names)); if (!name) { ret = -1; @@ -2979,7 +3000,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_entry(existing_names, name->str, + if (bt_private_value_map_insert_entry(existing_names, name->str, bt_value_null)) { print_err_oom(); ret = -1; @@ -3002,7 +3023,7 @@ end: static int append_run_args_for_implicit_component( struct implicit_component_args *impl_args, - struct bt_value *run_args) + struct bt_private_value *run_args) { int ret = 0; size_t i; @@ -3011,45 +3032,48 @@ int append_run_args_for_implicit_component( goto end; } - if (bt_value_array_append_string_element(run_args, "--component")) { + if (bt_private_value_array_append_string_element(run_args, "--component")) { print_err_oom(); goto error; } - if (bt_value_array_append_string_element(run_args, impl_args->comp_arg->str)) { + if (bt_private_value_array_append_string_element(run_args, impl_args->comp_arg->str)) { print_err_oom(); goto error; } - if (bt_value_array_append_string_element(run_args, "--name")) { + if (bt_private_value_array_append_string_element(run_args, "--name")) { print_err_oom(); goto error; } - if (bt_value_array_append_string_element(run_args, impl_args->name_arg->str)) { + if (bt_private_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_element(run_args, "--params")) { + if (bt_private_value_array_append_string_element(run_args, "--params")) { print_err_oom(); goto error; } - if (bt_value_array_append_string_element(run_args, + if (bt_private_value_array_append_string_element(run_args, impl_args->params_arg->str)) { print_err_oom(); goto error; } } - for (i = 0; i < bt_value_array_get_size(impl_args->extra_params); i++) { + for (i = 0; i < bt_value_array_get_size( + bt_value_borrow_from_private(impl_args->extra_params)); + i++) { struct bt_value *elem; const char *arg; elem = bt_value_array_borrow_element_by_index( - impl_args->extra_params, i); + bt_value_borrow_from_private(impl_args->extra_params), + i); if (!elem) { goto error; } @@ -3059,7 +3083,7 @@ int append_run_args_for_implicit_component( goto error; } - ret = bt_value_array_append_string_element(run_args, arg); + ret = bt_private_value_array_append_string_element(run_args, arg); if (ret) { print_err_oom(); goto error; @@ -3116,7 +3140,7 @@ int init_implicit_component_args(struct implicit_component_args *args, args->comp_arg = g_string_new(comp_arg); args->name_arg = g_string_new(NULL); args->params_arg = g_string_new(NULL); - args->extra_params = bt_value_array_create(); + args->extra_params = bt_private_value_array_create(); if (!args->comp_arg || !args->name_arg || !args->params_arg || !args->extra_params) { @@ -3150,25 +3174,25 @@ int append_implicit_component_extra_param(struct implicit_component_args *args, BT_ASSERT(key); BT_ASSERT(value); - if (bt_value_array_append_string_element(args->extra_params, "--key")) { + if (bt_private_value_array_append_string_element(args->extra_params, "--key")) { print_err_oom(); ret = -1; goto end; } - if (bt_value_array_append_string_element(args->extra_params, key)) { + if (bt_private_value_array_append_string_element(args->extra_params, key)) { print_err_oom(); ret = -1; goto end; } - if (bt_value_array_append_string_element(args->extra_params, "--value")) { + if (bt_private_value_array_append_string_element(args->extra_params, "--value")) { print_err_oom(); ret = -1; goto end; } - if (bt_value_array_append_string_element(args->extra_params, value)) { + if (bt_private_value_array_append_string_element(args->extra_params, value)) { print_err_oom(); ret = -1; goto end; @@ -3181,7 +3205,8 @@ end: static int convert_append_name_param(enum bt_config_component_dest dest, GString *cur_name, GString *cur_name_prefix, - struct bt_value *run_args, struct bt_value *all_names, + struct bt_private_value *run_args, + struct bt_private_value *all_names, GList **source_names, GList **filter_names, GList **sink_names) { @@ -3198,14 +3223,15 @@ int convert_append_name_param(enum bt_config_component_dest dest, * component. */ name = get_component_auto_name(cur_name_prefix->str, - all_names); + bt_value_borrow_from_private(all_names)); append_name_opt = true; } else { /* * An explicit name was provided for the user * component. */ - if (bt_value_map_has_entry(all_names, + if (bt_value_map_has_entry( + bt_value_borrow_from_private(all_names), cur_name->str)) { printf_err("Duplicate component instance name:\n %s\n", cur_name->str); @@ -3224,7 +3250,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_entry(all_names, name->str, bt_value_null)) { + if (bt_private_value_map_insert_entry(all_names, name->str, bt_value_null)) { print_err_oom(); goto error; } @@ -3233,12 +3259,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_element(run_args, "--name")) { + if (bt_private_value_array_append_string_element(run_args, "--name")) { print_err_oom(); goto error; } - if (bt_value_array_append_string_element(run_args, name->str)) { + if (bt_private_value_array_append_string_element(run_args, name->str)) { print_err_oom(); goto error; } @@ -3306,7 +3332,7 @@ end: * function. */ static -int append_connect_arg(struct bt_value *run_args, +int append_connect_arg(struct bt_private_value *run_args, const char *upstream_name, const char *downstream_name) { int ret = 0; @@ -3320,7 +3346,7 @@ int append_connect_arg(struct bt_value *run_args, goto end; } - ret = bt_value_array_append_string_element(run_args, "--connect"); + ret = bt_private_value_array_append_string_element(run_args, "--connect"); if (ret) { print_err_oom(); ret = -1; @@ -3330,7 +3356,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_element(run_args, arg->str); + ret = bt_private_value_array_append_string_element(run_args, arg->str); if (ret) { print_err_oom(); ret = -1; @@ -3357,7 +3383,7 @@ end: * Appends the run command's --connect options for the convert command. */ static -int convert_auto_connect(struct bt_value *run_args, +int convert_auto_connect(struct bt_private_value *run_args, GList *source_names, GList *filter_names, GList *sink_names) { @@ -3541,7 +3567,8 @@ int fill_implicit_ctf_inputs_args(GPtrArray *implicit_ctf_inputs_args, */ BT_OBJECT_PUT_REF_AND_RESET(impl_args->extra_params); impl_args->extra_params = - bt_value_copy(base_implicit_ctf_input_args->extra_params); + bt_value_copy(bt_value_borrow_from_private( + base_implicit_ctf_input_args->extra_params)); if (!impl_args->extra_params) { print_err_oom(); destroy_implicit_component_args(impl_args); @@ -3578,7 +3605,7 @@ static struct bt_config *bt_config_convert_from_args(int argc, const char *argv[], int *retcode, bool force_omit_system_plugin_path, bool force_omit_home_plugin_path, - struct bt_value *initial_plugin_paths, char *log_level) + struct bt_private_value *initial_plugin_paths, char *log_level) { poptContext pc = NULL; char *arg = NULL; @@ -3597,8 +3624,8 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[], bool print_run_args = false; bool print_run_args_0 = false; bool print_ctf_metadata = false; - struct bt_value *run_args = NULL; - struct bt_value *all_names = NULL; + struct bt_private_value *run_args = NULL; + struct bt_private_value *all_names = NULL; GList *source_names = NULL; GList *filter_names = NULL; GList *sink_names = NULL; @@ -3612,7 +3639,8 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[], struct implicit_component_args implicit_debug_info_args = { 0 }; struct implicit_component_args implicit_muxer_args = { 0 }; struct implicit_component_args implicit_trimmer_args = { 0 }; - struct bt_value *plugin_paths = bt_object_get_ref(initial_plugin_paths); + struct bt_private_value *plugin_paths = + bt_object_get_ref(initial_plugin_paths); char error_buf[256] = { 0 }; size_t i; struct bt_common_lttng_live_url_parts lttng_live_url_parts = { 0 }; @@ -3673,13 +3701,13 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[], goto error; } - all_names = bt_value_map_create(); + all_names = bt_private_value_map_create(); if (!all_names) { print_err_oom(); goto error; } - run_args = bt_value_array_create(); + run_args = bt_private_value_array_create(); if (!run_args) { print_err_oom(); goto error; @@ -3776,13 +3804,13 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[], abort(); } - if (bt_value_array_append_string_element(run_args, + if (bt_private_value_array_append_string_element(run_args, "--component")) { print_err_oom(); goto error; } - if (bt_value_array_append_string_element(run_args, arg)) { + if (bt_private_value_array_append_string_element(run_args, arg)) { print_err_oom(); goto error; } @@ -3805,13 +3833,13 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[], goto error; } - if (bt_value_array_append_string_element(run_args, + if (bt_private_value_array_append_string_element(run_args, "--params")) { print_err_oom(); goto error; } - if (bt_value_array_append_string_element(run_args, arg)) { + if (bt_private_value_array_append_string_element(run_args, arg)) { print_err_oom(); goto error; } @@ -3823,22 +3851,22 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[], goto error; } - if (bt_value_array_append_string_element(run_args, "--key")) { + if (bt_private_value_array_append_string_element(run_args, "--key")) { print_err_oom(); goto error; } - if (bt_value_array_append_string_element(run_args, "path")) { + if (bt_private_value_array_append_string_element(run_args, "path")) { print_err_oom(); goto error; } - if (bt_value_array_append_string_element(run_args, "--value")) { + if (bt_private_value_array_append_string_element(run_args, "--value")) { print_err_oom(); goto error; } - if (bt_value_array_append_string_element(run_args, arg)) { + if (bt_private_value_array_append_string_element(run_args, arg)) { print_err_oom(); goto error; } @@ -3850,22 +3878,22 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[], goto error; } - if (bt_value_array_append_string_element(run_args, "--key")) { + if (bt_private_value_array_append_string_element(run_args, "--key")) { print_err_oom(); goto error; } - if (bt_value_array_append_string_element(run_args, "url")) { + if (bt_private_value_array_append_string_element(run_args, "url")) { print_err_oom(); goto error; } - if (bt_value_array_append_string_element(run_args, "--value")) { + if (bt_private_value_array_append_string_element(run_args, "--value")) { print_err_oom(); goto error; } - if (bt_value_array_append_string_element(run_args, arg)) { + if (bt_private_value_array_append_string_element(run_args, arg)) { print_err_oom(); goto error; } @@ -3877,12 +3905,12 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[], goto error; } - if (bt_value_array_append_string_element(run_args, "--name")) { + if (bt_private_value_array_append_string_element(run_args, "--name")) { print_err_oom(); goto error; } - if (bt_value_array_append_string_element(run_args, arg)) { + if (bt_private_value_array_append_string_element(run_args, arg)) { print_err_oom(); goto error; } @@ -3892,20 +3920,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_element(run_args, + if (bt_private_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_element(run_args, + if (bt_private_value_array_append_string_element(run_args, "--retry-duration")) { print_err_oom(); goto error; } - if (bt_value_array_append_string_element(run_args, arg)) { + if (bt_private_value_array_append_string_element(run_args, arg)) { print_err_oom(); goto error; } @@ -3913,7 +3941,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_element(run_args, + if (bt_private_value_array_append_string_element(run_args, "--omit-system-plugin-path")) { print_err_oom(); goto error; @@ -3925,13 +3953,13 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[], goto error; } - if (bt_value_array_append_string_element(run_args, + if (bt_private_value_array_append_string_element(run_args, "--plugin-path")) { print_err_oom(); goto error; } - if (bt_value_array_append_string_element(run_args, arg)) { + if (bt_private_value_array_append_string_element(run_args, arg)) { print_err_oom(); goto error; } @@ -4150,7 +4178,7 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[], break; case OPT_FIELDS: { - struct bt_value *fields = fields_from_arg(arg); + struct bt_private_value *fields = fields_from_arg(arg); if (!fields) { goto error; @@ -4159,7 +4187,7 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[], implicit_text_args.exists = true; ret = insert_flat_params_from_array( implicit_text_args.params_arg, - fields, "field"); + bt_value_borrow_from_private(fields), "field"); bt_object_put_ref(fields); if (ret) { goto error; @@ -4168,7 +4196,7 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[], } case OPT_NAMES: { - struct bt_value *names = names_from_arg(arg); + struct bt_private_value *names = names_from_arg(arg); if (!names) { goto error; @@ -4177,7 +4205,7 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[], implicit_text_args.exists = true; ret = insert_flat_params_from_array( implicit_text_args.params_arg, - names, "name"); + bt_value_borrow_from_private(names), "name"); bt_object_put_ref(names); if (ret) { goto error; @@ -4667,10 +4695,12 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[], goto error; } - for (i = 0; i < bt_value_array_get_size(run_args); i++) { + for (i = 0; i < bt_value_array_get_size( + bt_value_borrow_from_private(run_args)); i++) { struct bt_value *arg_value = bt_value_array_borrow_element_by_index( - run_args, i); + bt_value_borrow_from_private(run_args), + i); const char *arg; GString *quoted = NULL; const char *arg_to_print; @@ -4696,7 +4726,8 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[], g_string_free(quoted, TRUE); } - if (i < bt_value_array_get_size(run_args) - 1) { + if (i < bt_value_array_get_size( + bt_value_borrow_from_private(run_args)) - 1) { if (print_run_args) { putchar(' '); } else { @@ -4710,7 +4741,8 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[], goto end; } - cfg = bt_config_run_from_args_array(run_args, retcode, + cfg = bt_config_run_from_args_array( + bt_value_borrow_from_private(run_args), retcode, force_omit_system_plugin_path, force_omit_home_plugin_path, initial_plugin_paths); if (!cfg) { @@ -4826,7 +4858,7 @@ char log_level_from_arg(const char *arg) struct bt_config *bt_config_cli_args_create(int argc, const char *argv[], int *retcode, bool force_omit_system_plugin_path, bool force_omit_home_plugin_path, - struct bt_value *initial_plugin_paths) + struct bt_private_value *initial_plugin_paths) { struct bt_config *config = NULL; int i; @@ -4847,7 +4879,7 @@ struct bt_config *bt_config_cli_args_create(int argc, const char *argv[], *retcode = -1; if (!initial_plugin_paths) { - initial_plugin_paths = bt_value_array_create(); + initial_plugin_paths = bt_private_value_array_create(); if (!initial_plugin_paths) { *retcode = 1; goto end; diff --git a/cli/babeltrace-cfg-cli-args.h b/cli/babeltrace-cfg-cli-args.h index a82da00f..4878dcbb 100644 --- a/cli/babeltrace-cfg-cli-args.h +++ b/cli/babeltrace-cfg-cli-args.h @@ -37,6 +37,6 @@ struct bt_config *bt_config_cli_args_create(int argc, const char *argv[], int *retcode, bool force_omit_system_plugin_path, bool force_omit_home_plugin_path, - struct bt_value *initial_plugin_paths); + struct bt_private_value *initial_plugin_paths); #endif /* CLI_BABELTRACE_CFG_CLI_ARGS_H */ diff --git a/cli/babeltrace-cfg.c b/cli/babeltrace-cfg.c index 759ce377..ef8c12b7 100644 --- a/cli/babeltrace-cfg.c +++ b/cli/babeltrace-cfg.c @@ -24,6 +24,7 @@ #include #include +#include #include #include "babeltrace-cfg.h" @@ -38,7 +39,7 @@ void destroy_gstring(void *data) * and appends them to the array value object plugin_paths. */ enum bt_value_status bt_config_append_plugin_paths( - struct bt_value *plugin_paths, const char *arg) + struct bt_private_value *plugin_paths, const char *arg) { enum bt_value_status status = BT_VALUE_STATUS_OK; GPtrArray *dirs = g_ptr_array_new_with_free_func(destroy_gstring); @@ -59,7 +60,8 @@ 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_element(plugin_paths, dir->str); + status = bt_private_value_array_append_string_element( + plugin_paths, dir->str); if (status != BT_VALUE_STATUS_OK) { break; } diff --git a/cli/babeltrace-cfg.h b/cli/babeltrace-cfg.h index 55d5e857..d5559cae 100644 --- a/cli/babeltrace-cfg.h +++ b/cli/babeltrace-cfg.h @@ -49,7 +49,7 @@ struct bt_config_component { enum bt_component_class_type type; GString *plugin_name; GString *comp_cls_name; - struct bt_value *params; + struct bt_private_value *params; GString *instance_name; }; @@ -65,7 +65,7 @@ struct bt_config { struct bt_object base; bool debug; bool verbose; - struct bt_value *plugin_paths; + struct bt_private_value *plugin_paths; bool omit_system_plugin_path; bool omit_home_plugin_path; bool command_needs_plugins; @@ -133,7 +133,7 @@ struct bt_config_component *bt_config_get_component(GPtrArray *array, } enum bt_value_status bt_config_append_plugin_paths( - struct bt_value *plugin_paths, const char *arg); + struct bt_private_value *plugin_paths, const char *arg); void bt_config_connection_destroy(struct bt_config_connection *connection); diff --git a/cli/babeltrace.c b/cli/babeltrace.c index 514a934a..8e17c2a1 100644 --- a/cli/babeltrace.c +++ b/cli/babeltrace.c @@ -31,7 +31,6 @@ #include #include -#include #include #include #include @@ -552,7 +551,7 @@ void print_value_rec(FILE *fp, struct bt_value *value, size_t indent) error: BT_LOGE("Error printing value of type %s.", - bt_value_type_string(bt_value_get_type(value))); + bt_common_value_type_string(bt_value_get_type(value))); } static @@ -580,7 +579,8 @@ void print_bt_config_component(struct bt_config_component *bt_config_component) } fprintf(stderr, " Parameters:\n"); - print_value(stderr, bt_config_component->params, 8); + print_value(stderr, + bt_value_borrow_from_private(bt_config_component->params), 8); } static @@ -608,7 +608,7 @@ void print_cfg_run(struct bt_config *cfg) { size_t i; - print_plugin_paths(cfg->plugin_paths); + print_plugin_paths(bt_value_borrow_from_private(cfg->plugin_paths)); fprintf(stderr, " Source component instances:\n"); print_bt_config_components(cfg->cmd_data.run.sources); @@ -639,19 +639,19 @@ void print_cfg_run(struct bt_config *cfg) static void print_cfg_list_plugins(struct bt_config *cfg) { - print_plugin_paths(cfg->plugin_paths); + print_plugin_paths(bt_value_borrow_from_private(cfg->plugin_paths)); } static void print_cfg_help(struct bt_config *cfg) { - print_plugin_paths(cfg->plugin_paths); + print_plugin_paths(bt_value_borrow_from_private(cfg->plugin_paths)); } static void print_cfg_print_ctf_metadata(struct bt_config *cfg) { - print_plugin_paths(cfg->plugin_paths); + print_plugin_paths(bt_value_borrow_from_private(cfg->plugin_paths)); fprintf(stderr, " Path: %s\n", cfg->cmd_data.print_ctf_metadata.path->str); } @@ -659,7 +659,7 @@ void print_cfg_print_ctf_metadata(struct bt_config *cfg) static void print_cfg_print_lttng_live_sessions(struct bt_config *cfg) { - print_plugin_paths(cfg->plugin_paths); + print_plugin_paths(bt_value_borrow_from_private(cfg->plugin_paths)); fprintf(stderr, " URL: %s\n", cfg->cmd_data.print_lttng_live_sessions.url->str); } @@ -667,7 +667,7 @@ void print_cfg_print_lttng_live_sessions(struct bt_config *cfg) static void print_cfg_query(struct bt_config *cfg) { - print_plugin_paths(cfg->plugin_paths); + print_plugin_paths(bt_value_borrow_from_private(cfg->plugin_paths)); fprintf(stderr, " Object: `%s`\n", cfg->cmd_data.query.object->str); fprintf(stderr, " Component class:\n"); print_bt_config_component(cfg->cmd_data.query.cfg_component); @@ -920,8 +920,8 @@ int cmd_query(struct bt_config *cfg) } ret = query(comp_cls, cfg->cmd_data.query.object->str, - cfg->cmd_data.query.cfg_component->params, &results, - &fail_reason); + bt_value_borrow_from_private(cfg->cmd_data.query.cfg_component->params), + &results, &fail_reason); if (ret) { goto failed; } @@ -1069,7 +1069,7 @@ int cmd_list_plugins(struct bt_config *cfg) int plugins_count, component_classes_count = 0, i; printf("From the following plugin paths:\n\n"); - print_value(stdout, cfg->plugin_paths, 2); + print_value(stdout, bt_value_borrow_from_private(cfg->plugin_paths), 2); printf("\n"); plugins_count = loaded_plugins->len; if (plugins_count == 0) { @@ -1145,7 +1145,7 @@ int cmd_print_lttng_live_sessions(struct bt_config *cfg) int ret = 0; struct bt_component_class *comp_cls = NULL; struct bt_value *results = NULL; - struct bt_value *params = NULL; + struct bt_private_value *params = NULL; struct bt_value *map = NULL; struct bt_value *v = NULL; static const char * const plugin_name = "ctf"; @@ -1174,18 +1174,19 @@ int cmd_print_lttng_live_sessions(struct bt_config *cfg) goto error; } - params = bt_value_map_create(); + params = bt_private_value_map_create(); if (!params) { goto error; } - ret = bt_value_map_insert_string_entry(params, "url", + ret = bt_private_value_map_insert_string_entry(params, "url", cfg->cmd_data.print_lttng_live_sessions.url->str); if (ret) { goto error; } - ret = query(comp_cls, "sessions", params, &results, &fail_reason); + ret = query(comp_cls, "sessions", bt_value_borrow_from_private(params), + &results, &fail_reason); if (ret) { goto failed; } @@ -1300,7 +1301,7 @@ int cmd_print_ctf_metadata(struct bt_config *cfg) int ret = 0; struct bt_component_class *comp_cls = NULL; struct bt_value *results = NULL; - struct bt_value *params = NULL; + struct bt_private_value *params = NULL; struct bt_value *metadata_text_value = NULL; const char *metadata_text = NULL; static const char * const plugin_name = "ctf"; @@ -1329,20 +1330,21 @@ int cmd_print_ctf_metadata(struct bt_config *cfg) goto end; } - params = bt_value_map_create(); + params = bt_private_value_map_create(); if (!params) { ret = -1; goto end; } - ret = bt_value_map_insert_string_entry(params, "path", + ret = bt_private_value_map_insert_string_entry(params, "path", cfg->cmd_data.print_ctf_metadata.path->str); if (ret) { ret = -1; goto end; } - ret = query(comp_cls, "metadata-info", params, &results, &fail_reason); + ret = query(comp_cls, "metadata-info", + bt_value_borrow_from_private(params), &results, &fail_reason); if (ret) { goto failed; } @@ -1533,7 +1535,7 @@ int cmd_run_ctx_connect_upstream_port_to_downstream_component( struct bt_port *(*port_by_index_fn)(struct bt_component *, uint64_t); enum bt_graph_status status = BT_GRAPH_STATUS_ERROR; bool insert_trimmer = false; - struct bt_value *trimmer_params = NULL; + struct bt_private_value *trimmer_params = NULL; char *intersection_begin = NULL; char *intersection_end = NULL; struct bt_component *trimmer = NULL; @@ -1569,17 +1571,17 @@ int cmd_run_ctx_connect_upstream_port_to_downstream_component( } insert_trimmer = true; - trimmer_params = bt_value_map_create(); + trimmer_params = bt_private_value_map_create(); if (!trimmer_params) { goto error; } - status = bt_value_map_insert_string_entry( + status = bt_private_value_map_insert_string_entry( trimmer_params, "begin", intersection_begin); if (status != BT_VALUE_STATUS_OK) { goto error; } - status = bt_value_map_insert_string_entry( + status = bt_private_value_map_insert_string_entry( trimmer_params, "end", intersection_end); if (status != BT_VALUE_STATUS_OK) { @@ -1690,7 +1692,8 @@ int cmd_run_ctx_connect_upstream_port_to_downstream_component( ctx->connect_ports = false; graph_status = bt_graph_add_component(ctx->graph, - trimmer_class, trimmer_name, trimmer_params, + trimmer_class, trimmer_name, + bt_value_borrow_from_private(trimmer_params), &trimmer); free(trimmer_name); if (graph_status != BT_GRAPH_STATUS_OK) { @@ -2095,7 +2098,7 @@ int set_stream_intersections(struct cmd_run_ctx *ctx, enum bt_value_status value_status; const char *path = NULL; struct bt_value *component_path_value = NULL; - struct bt_value *query_params = NULL; + struct bt_private_value *query_params = NULL; struct bt_value *query_result = NULL; struct bt_value *trace_info = NULL; struct bt_value *intersection_range = NULL; @@ -2109,7 +2112,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_borrow_entry_value(cfg_comp->params, + component_path_value = bt_value_map_borrow_entry_value( + bt_value_borrow_from_private(cfg_comp->params), "path"); if (component_path_value && !bt_value_is_string(component_path_value)) { BT_LOGD("Cannot get path parameter: component-name=%s", @@ -2126,14 +2130,14 @@ int set_stream_intersections(struct cmd_run_ctx *ctx, goto error; } - query_params = bt_value_map_create(); + query_params = bt_private_value_map_create(); if (!query_params) { BT_LOGE_STR("Cannot create query parameters."); ret = -1; goto error; } - value_status = bt_value_map_insert_entry(query_params, "path", + value_status = bt_private_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."); @@ -2141,7 +2145,8 @@ int set_stream_intersections(struct cmd_run_ctx *ctx, goto error; } - ret = query(comp_cls, "trace-info", query_params, &query_result, + ret = query(comp_cls, "trace-info", + bt_value_borrow_from_private(query_params), &query_result, &fail_reason); if (ret) { BT_LOGD("Component class does not support the `trace-info` query: %s: " @@ -2378,7 +2383,8 @@ int cmd_run_ctx_create_components_from_config_components( } ret = bt_graph_add_component(ctx->graph, comp_cls, - cfg_comp->instance_name->str, cfg_comp->params, &comp); + cfg_comp->instance_name->str, + bt_value_borrow_from_private(cfg_comp->params), &comp); if (ret) { BT_LOGE("Cannot create component: plugin-name=\"%s\", " "comp-cls-name=\"%s\", comp-cls-type=%d, " @@ -2853,7 +2859,8 @@ int main(int argc, const char **argv) print_cfg(cfg); if (cfg->command_needs_plugins) { - ret = load_all_plugins(cfg->plugin_paths); + ret = load_all_plugins( + bt_value_borrow_from_private(cfg->plugin_paths)); if (ret) { BT_LOGE("Failed to load plugins: ret=%d", ret); retcode = 1; diff --git a/include/Makefile.am b/include/Makefile.am index 75ec755e..5af4a446 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -75,6 +75,7 @@ babeltraceinclude_HEADERS = \ babeltrace/logging.h \ babeltrace/object.h \ babeltrace/types.h \ + babeltrace/private-values.h \ babeltrace/values.h \ babeltrace/version.h diff --git a/include/babeltrace/babeltrace.h b/include/babeltrace/babeltrace.h index f75467e0..f1738a29 100644 --- a/include/babeltrace/babeltrace.h +++ b/include/babeltrace/babeltrace.h @@ -28,6 +28,7 @@ /* Core API */ #include #include +#include #include #include #include diff --git a/include/babeltrace/common-internal.h b/include/babeltrace/common-internal.h index 4e4baef1..c1215f5c 100644 --- a/include/babeltrace/common-internal.h +++ b/include/babeltrace/common-internal.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -387,6 +388,29 @@ const char *bt_common_event_class_log_level_string( } }; +static inline +const char *bt_common_value_type_string(enum bt_value_type type) +{ + switch (type) { + case BT_VALUE_TYPE_NULL: + return "BT_VALUE_TYPE_NULL"; + case BT_VALUE_TYPE_BOOL: + return "BT_VALUE_TYPE_BOOL"; + case BT_VALUE_TYPE_INTEGER: + return "BT_VALUE_TYPE_INTEGER"; + case BT_VALUE_TYPE_REAL: + return "BT_VALUE_TYPE_REAL"; + case BT_VALUE_TYPE_STRING: + return "BT_VALUE_TYPE_STRING"; + case BT_VALUE_TYPE_ARRAY: + return "BT_VALUE_TYPE_ARRAY"; + case BT_VALUE_TYPE_MAP: + return "BT_VALUE_TYPE_MAP"; + default: + return "(unknown)"; + } +}; + static inline GString *bt_field_path_string(struct bt_field_path *path) { diff --git a/include/babeltrace/ctf-writer/attributes-internal.h b/include/babeltrace/ctf-writer/attributes-internal.h index 2fc6c592..c7d859d1 100644 --- a/include/babeltrace/ctf-writer/attributes-internal.h +++ b/include/babeltrace/ctf-writer/attributes-internal.h @@ -34,35 +34,35 @@ extern "C" { #include #include -#include +#include BT_HIDDEN -struct bt_value *bt_ctf_attributes_create(void); +struct bt_private_value *bt_ctf_attributes_create(void); BT_HIDDEN -void bt_ctf_attributes_destroy(struct bt_value *attr_obj); +void bt_ctf_attributes_destroy(struct bt_private_value *attr_obj); BT_HIDDEN -int64_t bt_ctf_attributes_get_count(struct bt_value *attr_obj); +int64_t bt_ctf_attributes_get_count(struct bt_private_value *attr_obj); BT_HIDDEN -const char *bt_ctf_attributes_get_field_name(struct bt_value *attr_obj, +const char *bt_ctf_attributes_get_field_name(struct bt_private_value *attr_obj, uint64_t index); BT_HIDDEN -struct bt_value *bt_ctf_attributes_borrow_field_value(struct bt_value *attr_obj, +struct bt_private_value *bt_ctf_attributes_borrow_field_value(struct bt_private_value *attr_obj, uint64_t index); BT_HIDDEN -int bt_ctf_attributes_set_field_value(struct bt_value *attr_obj, - const char *name, struct bt_value *value_obj); +int bt_ctf_attributes_set_field_value(struct bt_private_value *attr_obj, + const char *name, struct bt_private_value *value_obj); BT_HIDDEN -struct bt_value *bt_ctf_attributes_borrow_field_value_by_name( - struct bt_value *attr_obj, const char *name); +struct bt_private_value *bt_ctf_attributes_borrow_field_value_by_name( + struct bt_private_value *attr_obj, const char *name); BT_HIDDEN -int bt_ctf_attributes_freeze(struct bt_value *attr_obj); +int bt_ctf_attributes_freeze(struct bt_private_value *attr_obj); #ifdef __cplusplus } diff --git a/include/babeltrace/ctf-writer/resolve-internal.h b/include/babeltrace/ctf-writer/resolve-internal.h index cd2b01f4..b456f22d 100644 --- a/include/babeltrace/ctf-writer/resolve-internal.h +++ b/include/babeltrace/ctf-writer/resolve-internal.h @@ -31,7 +31,7 @@ #include #include -#include +#include #include #include @@ -60,7 +60,7 @@ enum bt_ctf_resolve_flag { * All parameters are owned by the caller. */ BT_HIDDEN -int bt_ctf_resolve_types(struct bt_value *environment, +int bt_ctf_resolve_types(struct bt_private_value *environment, struct bt_ctf_field_type_common *packet_header_type, struct bt_ctf_field_type_common *packet_context_type, struct bt_ctf_field_type_common *event_header_type, diff --git a/include/babeltrace/ctf-writer/trace-internal.h b/include/babeltrace/ctf-writer/trace-internal.h index e3d73c18..79e3f08b 100644 --- a/include/babeltrace/ctf-writer/trace-internal.h +++ b/include/babeltrace/ctf-writer/trace-internal.h @@ -43,6 +43,7 @@ #include #include #include +#include #include #include @@ -53,7 +54,7 @@ struct bt_ctf_trace_common { unsigned char uuid[BABELTRACE_UUID_LEN]; bt_bool uuid_set; enum bt_ctf_byte_order native_byte_order; - struct bt_value *environment; + struct bt_private_value *environment; GPtrArray *clock_classes; /* Array of pointers to bt_ctf_clock_class */ GPtrArray *stream_classes; /* Array of ptrs to bt_ctf_stream_class_common */ GPtrArray *streams; /* Array of ptrs to bt_ctf_stream_common */ @@ -100,7 +101,7 @@ int bt_ctf_trace_common_set_uuid(struct bt_ctf_trace_common *trace, const unsign BT_HIDDEN int bt_ctf_trace_common_set_environment_field(struct bt_ctf_trace_common *trace, - const char *name, struct bt_value *value); + const char *name, struct bt_private_value *value); BT_HIDDEN int bt_ctf_trace_common_set_environment_field_string(struct bt_ctf_trace_common *trace, @@ -132,7 +133,8 @@ bt_ctf_trace_common_get_environment_field_name_by_index( } static inline -struct bt_value *bt_ctf_trace_common_borrow_environment_field_value_by_index( +struct bt_private_value * +bt_ctf_trace_common_borrow_environment_field_value_by_index( struct bt_ctf_trace_common *trace, uint64_t index) { BT_ASSERT_PRE_NON_NULL(trace, "Trace"); @@ -140,7 +142,8 @@ struct bt_value *bt_ctf_trace_common_borrow_environment_field_value_by_index( } static inline -struct bt_value *bt_ctf_trace_common_borrow_environment_field_value_by_name( +struct bt_private_value * +bt_ctf_trace_common_borrow_environment_field_value_by_name( struct bt_ctf_trace_common *trace, const char *name) { BT_ASSERT_PRE_NON_NULL(trace, "Trace"); diff --git a/include/babeltrace/ctf-writer/trace.h b/include/babeltrace/ctf-writer/trace.h index 68af9a8b..b83877a6 100644 --- a/include/babeltrace/ctf-writer/trace.h +++ b/include/babeltrace/ctf-writer/trace.h @@ -65,10 +65,6 @@ extern struct bt_value * bt_ctf_trace_get_environment_field_value_by_name( struct bt_ctf_trace *trace, const char *name); -extern int bt_ctf_trace_set_environment_field( - struct bt_ctf_trace *trace, const char *name, - struct bt_value *value); - extern int bt_ctf_trace_set_environment_field_integer( struct bt_ctf_trace *trace, const char *name, int64_t value); diff --git a/include/babeltrace/ctf-writer/validation-internal.h b/include/babeltrace/ctf-writer/validation-internal.h index 887b5a71..49533095 100644 --- a/include/babeltrace/ctf-writer/validation-internal.h +++ b/include/babeltrace/ctf-writer/validation-internal.h @@ -25,7 +25,7 @@ * SOFTWARE. */ -#include +#include #include struct bt_ctf_trace_common; @@ -82,7 +82,7 @@ struct bt_ctf_validation_output { * All parameters are owned by the caller. */ BT_HIDDEN -int bt_ctf_validate_class_types(struct bt_value *environment, +int bt_ctf_validate_class_types(struct bt_private_value *environment, struct bt_ctf_field_type_common *packet_header_type, struct bt_ctf_field_type_common *packet_context_type, struct bt_ctf_field_type_common *event_header_type, diff --git a/include/babeltrace/private-values.h b/include/babeltrace/private-values.h new file mode 100644 index 00000000..1b7dce82 --- /dev/null +++ b/include/babeltrace/private-values.h @@ -0,0 +1,142 @@ +#ifndef BABELTRACE_PRIVATE_VALUES_H +#define BABELTRACE_PRIVATE_VALUES_H + +/* + * Copyright (c) 2015-2016 EfficiOS Inc. and Linux Foundation + * Copyright (c) 2015-2018 Philippe Proulx + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include + +/* For enum bt_value_status */ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct bt_value; +struct bt_private_value; + +extern struct bt_private_value *bt_private_value_null; + +extern struct bt_value *bt_value_borrow_from_private( + struct bt_private_value *priv_value); + +extern struct bt_private_value *bt_private_value_bool_create(void); + + +extern struct bt_private_value *bt_private_value_bool_create_init(bt_bool val); + +extern enum bt_value_status bt_private_value_bool_set(struct bt_private_value *bool_obj, + bt_bool val); + +extern struct bt_private_value *bt_private_value_integer_create(void); + +extern struct bt_private_value *bt_private_value_integer_create_init(int64_t val); + +extern enum bt_value_status bt_private_integer_bool_set( + struct bt_private_value *integer_obj, int64_t val); + +extern struct bt_private_value *bt_private_value_real_create(void); + +extern struct bt_private_value *bt_private_value_real_create_init(double val); + +extern enum bt_value_status bt_private_value_real_set( + struct bt_private_value *real_obj, double val); + +extern struct bt_private_value *bt_private_value_string_create(void); + +extern struct bt_private_value *bt_private_value_string_create_init(const char *val); + +extern enum bt_value_status bt_private_value_string_set(struct bt_private_value *string_obj, + const char *val); + +extern struct bt_private_value *bt_private_value_array_create(void); + +extern struct bt_private_value *bt_private_value_array_borrow_element_by_index( + const struct bt_private_value *array_obj, uint64_t index); + +extern enum bt_value_status bt_private_value_array_append_element( + struct bt_private_value *array_obj, struct bt_value *element_obj); + +extern enum bt_value_status bt_private_value_array_append_bool_element( + struct bt_private_value *array_obj, bt_bool val); + +extern enum bt_value_status bt_private_value_array_append_integer_element( + struct bt_private_value *array_obj, int64_t val); + +extern enum bt_value_status bt_private_value_array_append_real_element( + struct bt_private_value *array_obj, double val); + +extern enum bt_value_status bt_private_value_array_append_string_element( + struct bt_private_value *array_obj, const char *val); + +extern enum bt_value_status bt_private_value_array_append_empty_array_element( + struct bt_private_value *array_obj); + +extern enum bt_value_status bt_private_value_array_append_empty_map_element( + struct bt_private_value *array_obj); + +extern enum bt_value_status bt_private_value_array_set_element_by_index( + struct bt_private_value *array_obj, uint64_t index, + struct bt_value *element_obj); + +extern struct bt_private_value *bt_private_value_map_create(void); + +extern struct bt_private_value *bt_private_value_map_borrow_entry_value( + const struct bt_private_value *map_obj, const char *key); + +typedef bt_bool (* bt_private_value_map_foreach_entry_cb)(const char *key, + struct bt_private_value *object, void *data); + +extern enum bt_value_status bt_private_value_map_foreach_entry( + const struct bt_private_value *map_obj, + bt_private_value_map_foreach_entry_cb cb, void *data); + +extern enum bt_value_status bt_private_value_map_insert_entry( + struct bt_private_value *map_obj, const char *key, + struct bt_value *element_obj); + +extern enum bt_value_status bt_private_value_map_insert_bool_entry( + struct bt_private_value *map_obj, const char *key, bt_bool val); + +extern enum bt_value_status bt_private_value_map_insert_integer_entry( + struct bt_private_value *map_obj, const char *key, int64_t val); + +extern enum bt_value_status bt_private_value_map_insert_real_entry( + struct bt_private_value *map_obj, const char *key, double val); + +extern enum bt_value_status bt_private_value_map_insert_string_entry( + struct bt_private_value *map_obj, const char *key, const char *val); + +extern enum bt_value_status bt_private_value_map_insert_empty_array_entry( + struct bt_private_value *map_obj, const char *key); + +extern enum bt_value_status bt_private_value_map_insert_empty_map_entry( + struct bt_private_value *map_obj, const char *key); + +#ifdef __cplusplus +} +#endif + +#endif /* BABELTRACE_PRIVATE_VALUES_H */ diff --git a/include/babeltrace/trace-ir/attributes-internal.h b/include/babeltrace/trace-ir/attributes-internal.h index 3820abd7..99d582dd 100644 --- a/include/babeltrace/trace-ir/attributes-internal.h +++ b/include/babeltrace/trace-ir/attributes-internal.h @@ -37,32 +37,33 @@ extern "C" { #include BT_HIDDEN -struct bt_value *bt_attributes_create(void); +struct bt_private_value *bt_attributes_create(void); BT_HIDDEN -void bt_attributes_destroy(struct bt_value *attr_obj); +void bt_attributes_destroy(struct bt_private_value *attr_obj); BT_HIDDEN -int64_t bt_attributes_get_count(struct bt_value *attr_obj); +int64_t bt_attributes_get_count(struct bt_private_value *attr_obj); BT_HIDDEN -const char *bt_attributes_get_field_name(struct bt_value *attr_obj, +const char *bt_attributes_get_field_name(struct bt_private_value *attr_obj, uint64_t index); BT_HIDDEN -struct bt_value *bt_attributes_borrow_field_value(struct bt_value *attr_obj, +struct bt_private_value *bt_attributes_borrow_field_value( + struct bt_private_value *attr_obj, uint64_t index); BT_HIDDEN -int bt_attributes_set_field_value(struct bt_value *attr_obj, - const char *name, struct bt_value *value_obj); +int bt_attributes_set_field_value(struct bt_private_value *attr_obj, + const char *name, struct bt_private_value *value_obj); BT_HIDDEN -struct bt_value *bt_attributes_borrow_field_value_by_name( - struct bt_value *attr_obj, const char *name); +struct bt_private_value *bt_attributes_borrow_field_value_by_name( + struct bt_private_value *attr_obj, const char *name); BT_HIDDEN -int bt_attributes_freeze(struct bt_value *attr_obj); +int bt_attributes_freeze(struct bt_private_value *attr_obj); #ifdef __cplusplus } diff --git a/include/babeltrace/trace-ir/trace-internal.h b/include/babeltrace/trace-ir/trace-internal.h index abf1d57f..4daac738 100644 --- a/include/babeltrace/trace-ir/trace-internal.h +++ b/include/babeltrace/trace-ir/trace-internal.h @@ -60,7 +60,7 @@ struct bt_trace { bt_uuid value; } uuid; - struct bt_value *environment; + struct bt_private_value *environment; /* Array of `struct bt_stream_class *` */ GPtrArray *stream_classes; diff --git a/include/babeltrace/values-internal.h b/include/babeltrace/values-internal.h index b19fcc87..c9c728c3 100644 --- a/include/babeltrace/values-internal.h +++ b/include/babeltrace/values-internal.h @@ -37,44 +37,4 @@ enum bt_value_status _bt_value_freeze(struct bt_value *object); # define bt_value_freeze(_value) #endif /* BT_DEV_MODE */ -static inline -const char *bt_value_status_string(enum bt_value_status status) -{ - switch (status) { - case BT_VALUE_STATUS_CANCELED: - return "BT_VALUE_STATUS_CANCELED"; - case BT_VALUE_STATUS_INVAL: - return "BT_VALUE_STATUS_INVAL"; - case BT_VALUE_STATUS_ERROR: - return "BT_VALUE_STATUS_ERROR"; - case BT_VALUE_STATUS_OK: - return "BT_VALUE_STATUS_OK"; - default: - return "(unknown)"; - } -}; - -static inline -const char *bt_value_type_string(enum bt_value_type type) -{ - switch (type) { - case BT_VALUE_TYPE_NULL: - return "BT_VALUE_TYPE_NULL"; - case BT_VALUE_TYPE_BOOL: - return "BT_VALUE_TYPE_BOOL"; - case BT_VALUE_TYPE_INTEGER: - return "BT_VALUE_TYPE_INTEGER"; - case BT_VALUE_TYPE_REAL: - return "BT_VALUE_TYPE_REAL"; - case BT_VALUE_TYPE_STRING: - return "BT_VALUE_TYPE_STRING"; - case BT_VALUE_TYPE_ARRAY: - return "BT_VALUE_TYPE_ARRAY"; - case BT_VALUE_TYPE_MAP: - return "BT_VALUE_TYPE_MAP"; - default: - return "(unknown)"; - } -}; - #endif /* BABELTRACE_VALUES_INTERNAL_H */ diff --git a/include/babeltrace/values.h b/include/babeltrace/values.h index 76ac6895..2f285cd5 100644 --- a/include/babeltrace/values.h +++ b/include/babeltrace/values.h @@ -32,140 +32,10 @@ /* For bt_bool */ #include -/* For bt_object_get_ref() */ -#include - #ifdef __cplusplus extern "C" { #endif -/** -@defgroup values Value objects -@ingroup apiref -@brief Value objects. - -@code -#include -@endcode - -This is a set of value objects. With the -functions documented here, you can create and modify: - -- \link bt_value_bool_create() Boolean value objects\endlink. -- \link bt_value_integer_create() Integer value objects\endlink. -- \link bt_value_float_create() Floating point number - value objects\endlink. -- \link bt_value_string_create() String value objects\endlink. -- \link bt_value_array_create() Array value objects\endlink, - containing zero or more value objects. -- \link bt_value_map_create() Map value objects\endlink, mapping - string keys to value objects. - -As with any Babeltrace object, value objects have -reference -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 -management of Babeltrace objects. - -Most functions of this API return a status code, one of the -values of #bt_value_status. - -You can create a deep copy of any value object with bt_value_copy(). You -can compare two value objects with bt_value_compare(). - -The following matrix shows some categorized value object functions -to use for each value object type: - - - - - - - - - - - - - - - - - - -
Function role →
- Value object type ↓ -
Create - Check type - Get value - Set value -
Null - Use the \ref bt_value_null variable - bt_value_is_null() - N/A - N/A -
Boolean - bt_value_bool_create()
- bt_value_bool_create_init() -
bt_value_is_bool() - bt_value_bool_get() - bt_value_bool_set() -
Integer - bt_value_integer_create()
- bt_value_integer_create_init() -
bt_value_is_integer() - bt_value_integer_get() - bt_value_integer_set() -
Floating point
number -
bt_value_float_create()
- bt_value_float_create_init() -
bt_value_is_float() - bt_value_float_get() - bt_value_float_set() -
String - bt_value_string_create()
- bt_value_string_create_init() -
bt_value_is_string() - bt_value_string_get() - bt_value_string_set() -
Array - bt_value_array_create() - bt_value_is_array() - bt_value_array_get() - 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 - bt_value_map_create()
- bt_value_map_extend() -
bt_value_is_map() - bt_value_map_get()
- 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() -
- -@file -@brief Value object types and functions. -@sa values - -@addtogroup values -@{ -*/ - /** @brief Status codes. */ @@ -173,10 +43,6 @@ enum bt_value_status { /// Operation canceled. BT_VALUE_STATUS_CANCELED = -3, - /* -22 for compatibility with -EINVAL */ - /// Invalid argument. - BT_VALUE_STATUS_INVAL = -22, - /// General error. BT_VALUE_STATUS_ERROR = -1, @@ -184,43 +50,11 @@ enum bt_value_status { BT_VALUE_STATUS_OK = 0, }; -/** -@struct bt_value -@brief A value object. -@sa values -*/ struct bt_value; +struct bt_private_value; -/** -@brief The null value object singleton. - -You \em must use this variable when you need the null value object. - -The null value object singleton has no reference count: there is only -one. You can compare any value object address to the null value object -singleton to check if it's the null value object, or otherwise with -bt_value_is_null(). - -You can pass \ref bt_value_null to bt_object_get_ref() or bt_object_put_ref(): it has -no effect. - -The null value object singleton is always frozen (see -bt_value_is_frozen()). - -The functions of this API return this variable when the value object -is actually the null value object (of type #BT_VALUE_TYPE_NULL), -whereas \c NULL means an error of some sort. -*/ extern struct bt_value *bt_value_null; -/** -@name Type information -@{ -*/ - -/** -@brief Value object type. -*/ enum bt_value_type { /// Null value object. BT_VALUE_TYPE_NULL = 0, @@ -244,1175 +78,95 @@ enum bt_value_type { BT_VALUE_TYPE_MAP = 6, }; -/** -@brief Returns the type of the value object \p object. - -@param[in] object Value object of which to get the type. -@returns Type of value object \p object, - or #BT_VALUE_TYPE_UNKNOWN on error. - -@prenotnull{object} -@postrefcountsame{object} - -@sa #bt_value_type: Value object types. -@sa bt_value_is_null(): Returns whether or not a given value object - is the null value object. -@sa bt_value_is_bool(): Returns whether or not a given value object - is a boolean value object. -@sa bt_value_is_integer(): Returns whether or not a given value - object is an integer value object. -@sa bt_value_is_float(): Returns whether or not a given value object - is a floating point number value object. -@sa bt_value_is_string(): Returns whether or not a given value object - is a string value object. -@sa bt_value_is_array(): Returns whether or not a given value object - is an array value object. -@sa bt_value_is_map(): Returns whether or not a given value object - is a map value object. -*/ extern enum bt_value_type bt_value_get_type(const struct bt_value *object); -/** -@brief Returns whether or not the value object \p object is the null - value object. - -The only valid null value object is \ref bt_value_null. - -An alternative to calling this function is to directly compare the value -object pointer to the \ref bt_value_null variable. - -@param[in] object Value object to check. -@returns #BT_TRUE if \p object is the null value object. - -@prenotnull{object} -@postrefcountsame{object} - -@sa bt_value_get_type(): Returns the type of a given value object. -*/ static inline bt_bool bt_value_is_null(const struct bt_value *object) { return bt_value_get_type(object) == BT_VALUE_TYPE_NULL; } -/** -@brief Returns whether or not the value object \p object is a boolean - value object. - -@param[in] object Value object to check. -@returns #BT_TRUE if \p object is a boolean value object. - -@prenotnull{object} -@postrefcountsame{object} - -@sa bt_value_get_type(): Returns the type of a given value object. -*/ static inline bt_bool bt_value_is_bool(const struct bt_value *object) { return bt_value_get_type(object) == BT_VALUE_TYPE_BOOL; } -/** -@brief Returns whether or not the value object \p object is an integer - value object. - -@param[in] object Value object to check. -@returns #BT_TRUE if \p object is an integer value object. - -@sa bt_value_get_type(): Returns the type of a given value object. -*/ static inline bt_bool bt_value_is_integer(const struct bt_value *object) { return bt_value_get_type(object) == BT_VALUE_TYPE_INTEGER; } -/** -@brief Returns whether or not the value object \p object is a floating - point number value object. - -@param[in] object Value object to check. -@returns #BT_TRUE if \p object is a floating point - number value object. - -@prenotnull{object} -@postrefcountsame{object} - -@sa bt_value_get_type(): Returns the type of a given value object. -*/ static inline bt_bool bt_value_is_real(const struct bt_value *object) { return bt_value_get_type(object) == BT_VALUE_TYPE_REAL; } -/** -@brief Returns whether or not the value object \p object is a string - value object. - -@param[in] object Value object to check. -@returns #BT_TRUE if \p object is a string value object. - -@prenotnull{object} -@postrefcountsame{object} - -@sa bt_value_get_type(): Returns the type of a given value object. -*/ static inline bt_bool bt_value_is_string(const struct bt_value *object) { return bt_value_get_type(object) == BT_VALUE_TYPE_STRING; } -/** -@brief Returns whether or not the value object \p object is an array - value object. - -@param[in] object Value object to check. -@returns #BT_TRUE if \p object is an array value object. - -@prenotnull{object} -@postrefcountsame{object} - -@sa bt_value_get_type(): Returns the type of a given value object. -*/ static inline bt_bool bt_value_is_array(const struct bt_value *object) { return bt_value_get_type(object) == BT_VALUE_TYPE_ARRAY; } -/** -@brief Returns whether or not the value object \p object is a map value - object. - -@param[in] object Value object to check. -@returns #BT_TRUE if \p object is a map value object. - -@prenotnull{object} -@postrefcountsame{object} - -@sa bt_value_get_type(): Returns the type of a given value object. -*/ static inline bt_bool bt_value_is_map(const struct bt_value *object) { return bt_value_get_type(object) == BT_VALUE_TYPE_MAP; } -/** @} */ - -/** -@name Common value object functions -@{ -*/ - -/** -@brief Creates a \em deep copy of the value object \p object. - -You can copy a frozen value object: the resulting copy is -not frozen. - -@param[in] object Value object to copy. -@returns Deep copy of \p object on success, or \c NULL - on error. - -@prenotnull{object} -@post On success, if the returned value object is not - \ref bt_value_null, its reference count is 1. -@postrefcountsame{object} -*/ -extern struct bt_value *bt_value_copy(const struct bt_value *object); - -/** -@brief Recursively compares the value objects \p object_a and - \p object_b and returns #BT_TRUE if they have the same - \em content (raw values). +extern struct bt_private_value *bt_value_copy(const struct bt_value *object); -@param[in] object_a Value object A to compare to \p object_b. -@param[in] object_b Value object B to compare to \p object_a. -@returns #BT_TRUE if \p object_a and \p object_b have the - same \em content, or #BT_FALSE if they differ - or on error. - -@postrefcountsame{object_a} -@postrefcountsame{object_b} -*/ extern bt_bool bt_value_compare(const struct bt_value *object_a, const struct bt_value *object_b); -/** @} */ - -/** -@name Boolean value object functions -@{ -*/ - -/** -@brief Creates a default boolean value object. - -The created boolean value object's initial raw value is #BT_FALSE. - -@returns Created boolean value object on success, or \c NULL - on error. - -@postsuccessrefcountret1 - -@sa bt_value_bool_create_init(): Creates an initialized boolean - value object. -*/ -extern struct bt_value *bt_value_bool_create(void); - -/** -@brief Creates a boolean value object with its initial raw value set to - \p val. - -@param[in] val Initial raw value. -@returns Created boolean value object on success, or - \c NULL on error. - -@postsuccessrefcountret1 - -@sa bt_value_bool_create(): Creates a default boolean value object. -*/ -extern struct bt_value *bt_value_bool_create_init(bt_bool val); - -/** -@brief Returns the boolean raw value of the boolean value object - \p bool_obj. - -@param[in] bool_obj Boolean value object of which to get the - raw value. -@param[out] val Returned boolean raw value. -@returns Status code. - -@prenotnull{bool_obj} -@prenotnull{val} -@pre \p bool_obj is a boolean value object. -@postrefcountsame{bool_obj} - -@sa bt_value_bool_set(): Sets the raw value of a boolean value object. -*/ extern enum bt_value_status bt_value_bool_get( const struct bt_value *bool_obj, bt_bool *val); -/** -@brief Sets the boolean raw value of the boolean value object - \p bool_obj to \p val. - -@param[in] bool_obj Boolean value object of which to set - the raw value. -@param[in] val New boolean raw value. -@returns Status code. - -@prenotnull{bool_obj} -@pre \p bool_obj is a boolean value object. -@prehot{bool_obj} -@postrefcountsame{bool_obj} - -@sa bt_value_bool_get(): Returns the raw value of a given boolean - value object. -*/ -extern enum bt_value_status bt_value_bool_set(struct bt_value *bool_obj, - bt_bool val); - -/** @} */ - -/** -@name Integer value object functions -@{ -*/ - -/** -@brief Creates a default integer value object. - -The created integer value object's initial raw value is 0. - -@returns Created integer value object on success, or \c NULL - on error. - -@postsuccessrefcountret1 - -@sa bt_value_integer_create_init(): Creates an initialized integer - value object. -*/ -extern struct bt_value *bt_value_integer_create(void); - -/** -@brief Creates an integer value object with its initial raw value set to - \p val. - -@param[in] val Initial raw value. -@returns Created integer value object on success, or - \c NULL on error. - -@postsuccessrefcountret1 - -@sa bt_value_integer_create(): Creates a default integer - value object. -*/ -extern struct bt_value *bt_value_integer_create_init(int64_t val); - -/** -@brief Returns the integer raw value of the integer value object - \p integer_obj. - -@param[in] integer_obj Integer value object of which to get the - raw value. -@param[out] val Returned integer raw value. -@returns Status code. - -@prenotnull{integer_obj} -@prenotnull{val} -@pre \p integer_obj is an integer value object. -@postrefcountsame{integer_obj} - -@sa bt_value_integer_set(): Sets the raw value of an integer value - object. -*/ extern enum bt_value_status bt_value_integer_get( const struct bt_value *integer_obj, int64_t *val); -/** -@brief Sets the integer raw value of the integer value object - \p integer_obj to \p val. - -@param[in] integer_obj Integer value object of which to set - the raw value. -@param[in] val New integer raw value. -@returns Status code. - -@prenotnull{integer_obj} -@pre \p integer_obj is an integer value object. -@prehot{integer_obj} -@postrefcountsame{integer_obj} - -@sa bt_value_integer_get(): Returns the raw value of a given integer - value object. -*/ -extern enum bt_value_status bt_value_integer_set( - struct bt_value *integer_obj, int64_t val); - -/** @} */ - -/** -@name Floating point number value object functions -@{ -*/ - -/** -@brief Creates a default floating point number value object. - -The created floating point number value object's initial raw value is 0. - -@returns Created floating point number value object on success, - or \c NULL on error. - -@postsuccessrefcountret1 - -@sa bt_value_float_create_init(): Creates an initialized floating - point number value object. -*/ -extern struct bt_value *bt_value_real_create(void); - -/** -@brief Creates a floating point number value object with its initial raw - value set to \p val. - -@param[in] val Initial raw value. -@returns Created floating point number value object on - success, or \c NULL on error. - -@postsuccessrefcountret1 - -@sa bt_value_float_create(): Creates a default floating point number - value object. -*/ -extern struct bt_value *bt_value_real_create_init(double val); - -/** -@brief Returns the floating point number raw value of the floating point - number value object \p float_obj. - -@param[in] float_obj Floating point number value object of which to - get the raw value. -@param[out] val Returned floating point number raw value -@returns Status code. - -@prenotnull{float_obj} -@prenotnull{val} -@pre \p float_obj is a floating point number value object. -@postrefcountsame{float_obj} - -@sa bt_value_float_set(): Sets the raw value of a given floating - point number value object. -*/ extern enum bt_value_status bt_value_real_get( const struct bt_value *real_obj, double *val); -/** -@brief Sets the floating point number raw value of the floating point - number value object \p float_obj to \p val. - -@param[in] float_obj Floating point number value object of which to set - the raw value. -@param[in] val New floating point number raw value. -@returns Status code. - -@prenotnull{float_obj} -@pre \p float_obj is a floating point number value object. -@prehot{float_obj} -@postrefcountsame{float_obj} - -@sa bt_value_float_get(): Returns the raw value of a floating point - number value object. -*/ -extern enum bt_value_status bt_value_real_set( - struct bt_value *real_obj, double val); - -/** @} */ - -/** -@name String value object functions -@{ -*/ - -/** -@brief Creates a default string value object. - -The string value object is initially empty. - -@returns Created string value object on success, or \c NULL - on error. - -@postsuccessrefcountret1 - -@sa bt_value_string_create_init(): Creates an initialized string - value object. -*/ -extern struct bt_value *bt_value_string_create(void); - -/** -@brief Creates a string value object with its initial raw value set to - \p val. - -On success, \p val is copied. - -@param[in] val Initial raw value (copied on success). -@returns Created string value object on success, or - \c NULL on error. - -@prenotnull{val} -@postsuccessrefcountret1 - -@sa bt_value_float_create(): Creates a default string value object. -*/ -extern struct bt_value *bt_value_string_create_init(const char *val); - -/** -@brief Returns the string raw value of the string value object - \p string_obj. - -The returned string is placed in \p *val. It is valid as long as this -value object exists and is \em not modified. The ownership of the -returned string is \em not transferred to the caller. - -@param[in] string_obj String value object of which to get the - raw value. -@param[out] val Returned string raw value. -@returns Status code. - -@prenotnull{string_obj} -@prenotnull{val} -@pre \p string_obj is a string value object. -@postrefcountsame{string_obj} - -@sa bt_value_string_set(): Sets the raw value of a string - value object. -*/ extern enum bt_value_status bt_value_string_get( const struct bt_value *string_obj, const char **val); -/** -@brief Sets the string raw value of the string value object - \p string_obj to \p val. - -On success, \p val is copied. - -@param[in] string_obj String value object of which to set - the raw value. -@param[in] val New string raw value (copied on success). -@returns Status code. - -@prenotnull{string_obj} -@prenotnull{val} -@pre \p string_obj is a string value object. -@prehot{string_obj} -@postrefcountsame{string_obj} - -@sa bt_value_string_get(): Returns the raw value of a given string - value object. -*/ -extern enum bt_value_status bt_value_string_set(struct bt_value *string_obj, - const char *val); - -/** - * @} - */ - -/** - * @name Array value object functions - * @{ - */ - -/** -@brief Creates an empty array value object. - -@returns Created array value object on success, or \c NULL - on error. - -@postsuccessrefcountret1 -*/ -extern struct bt_value *bt_value_array_create(void); - -/** -@brief Returns the size of the array value object \p array_obj, that is, - the number of value objects contained in \p array_obj. - -@param[in] array_obj Array value object of which to get the size. -@returns Number of value objects contained in - \p array_obj if the return value is 0 (empty) - or a positive value, or one of - #bt_value_status negative values otherwise. - -@prenotnull{array_obj} -@pre \p array_obj is an array value object. -@postrefcountsame{array_obj} - -@sa bt_value_array_is_empty(): Checks whether or not a given array - value object is empty. -*/ 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 - is empty. - -@param[in] array_obj Array value object to check. -@returns #BT_TRUE if \p array_obj is empty. - -@prenotnull{array_obj} -@pre \p array_obj is an array value object. -@postrefcountsame{array_obj} - -@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_element_by_index( const struct bt_value *array_obj, uint64_t index); -/** -@brief Appends the value object \p element_obj to the array value - object \p array_obj. - -@param[in] array_obj Array value object in which to append - \p element_obj. -@param[in] element_obj Value object to append. -@returns Status code. - -@prenotnull{array_obj} -@prenotnull{element_obj} -@pre \p array_obj is an array value object. -@prehot{array_obj} -@post On success, if \p element_obj is not - \ref bt_value_null, its reference count is incremented. -@postrefcountsame{array_obj} - -@sa bt_value_array_append_bool_element(): Appends a boolean raw value to a - given array value object. -@sa bt_value_array_append_integer_element(): Appends an integer raw value - to a given array value object. -@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_element(): Appends a string raw value to a - given array value object. -@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_element(): Appends an empty map value - object to a given array value object. -*/ -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 - \p array_obj. - -This is a convenience function which creates the underlying boolean -value object before appending it. - -@param[in] array_obj Array value object in which to append \p val. -@param[in] val Boolean raw value to append to \p array_obj. -@returns Status code. - -@prenotnull{array_obj} -@pre \p array_obj is an array value object. -@prehot{array_obj} -@postrefcountsame{array_obj} - -@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_element( - struct bt_value *array_obj, bt_bool val); - -/** -@brief Appends the integer raw value \p val to the array value object - \p array_obj. - -This is a convenience function which creates the underlying integer -value object before appending it. - -@param[in] array_obj Array value object in which to append \p val. -@param[in] val Integer raw value to append to \p array_obj. -@returns Status code. - -@prenotnull{array_obj} -@pre \p array_obj is an array value object. -@prehot{array_obj} -@postrefcountsame{array_obj} - -@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_element( - struct bt_value *array_obj, int64_t val); - -/** -@brief Appends the floating point number raw value \p val to the array - value object \p array_obj. - -This is a convenience function which creates the underlying floating -point number value object before appending it. - -@param[in] array_obj Array value object in which to append \p val. -@param[in] val Floating point number raw value to append - to \p array_obj. -@returns Status code. - -@prenotnull{array_obj} -@pre \p array_obj is an array value object. -@prehot{array_obj} -@postrefcountsame{array_obj} - -@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_element( - struct bt_value *array_obj, double val); - -/** -@brief Appends the string raw value \p val to the array value object - \p array_obj. - -This is a convenience function which creates the underlying string value -object before appending it. - -On success, \p val is copied. - -@param[in] array_obj Array value object in which to append \p val. -@param[in] val String raw value to append to \p array_obj - (copied on success). -@returns Status code. - -@prenotnull{array_obj} -@pre \p array_obj is an array value object. -@prenotnull{val} -@prehot{array_obj} -@postrefcountsame{array_obj} - -@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_element( - struct bt_value *array_obj, const char *val); - -/** -@brief Appends an empty array value object to the array value object - \p array_obj. - -This is a convenience function which creates the underlying array value -object before appending it. - -@param[in] array_obj Array value object in which to append an - empty array value object -@returns Status code. - -@prenotnull{array_obj} -@pre \p array_obj is an array value object. -@prehot{array_obj} -@postrefcountsame{array_obj} - -@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_element( - struct bt_value *array_obj); - -/** -@brief Appends an empty map value object to the array value object - \p array_obj. - -This is a convenience function which creates the underlying map value -object before appending it. - -@param[in] array_obj Array value object in which to append an empty - map value object. -@returns Status code. - -@prenotnull{array_obj} -@pre \p array_obj is an array value object. -@prehot{array_obj} -@postrefcountsame{array_obj} - -@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_element( - struct bt_value *array_obj); - -/** -@brief Replaces the value object contained in the array value object - \p array_obj at the index \p index by \p element_obj. - -@param[in] array_obj Array value object in which to replace - an element. -@param[in] index Index of value object to replace in - \p array_obj. -@param[in] element_obj New value object at position \p index of - \p array_obj. -@returns Status code. - -@prenotnull{array_obj} -@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_get_size()). -@prehot{array_obj} -@post On success, if the replaced value object is not - \ref bt_value_null, its reference count is decremented. -@post On success, if \p element_obj is not - \ref bt_value_null, its reference count is incremented. -@postrefcountsame{array_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); - -/** @} */ - -/** -@name Map value object functions -@{ -*/ - -/** -@brief Creates an empty map value object. - -@returns Created map value object on success, or \c NULL on error. - -@postsuccessrefcountret1 -*/ -extern struct bt_value *bt_value_map_create(void); - -/** -@brief Returns the size of the map value object \p map_obj, that is, the - number of entries contained in \p map_obj. - -@param[in] map_obj Map value object of which to get the size. -@returns Number of entries contained in \p map_obj if the - return value is 0 (empty) or a positive value, - or one of #bt_value_status negative values - otherwise. - -@prenotnull{map_obj} -@pre \p map_obj is a map value object. -@postrefcountsame{map_obj} - -@sa bt_value_map_is_empty(): Checks whether or not a given map value - object is empty. -*/ 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. - -@param[in] map_obj Map value object to check. -@returns #BT_TRUE if \p map_obj is empty. - -@prenotnull{map_obj} -@pre \p map_obj is a map value object. -@postrefcountsame{map_obj} - -@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_entry_value( const struct bt_value *map_obj, const char *key); -/** -@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_object_get_ref() -if you need to keep a reference after this function returns. - -This function \em must return #BT_TRUE to continue the map value object -traversal, or #BT_FALSE to break it. - -@param[in] key Key of map entry. -@param[in] object Value object of map entry (weak reference). -@param[in] data User data. -@returns #BT_TRUE to continue the loop, or #BT_FALSE to break it. - -@prenotnull{key} -@prenotnull{object} -@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_entry_cb)(const char *key, struct bt_value *object, void *data); -/** -@brief Calls a provided user function \p cb for each value object of the - map value object \p map_obj. - -The value object passed to the user function is a weak reference: -you \em must pass it to bt_object_get_ref() if you need to keep a persistent -reference after the user function returns. - -The key passed to the user function is only valid in the scope of -this user function call. - -The user function \em must return #BT_TRUE to continue the traversal of -\p map_obj, or #BT_FALSE to break it. - -@param[in] map_obj Map value object on which to iterate. -@param[in] cb User function to call back. -@param[in] data User data passed to the user function. -@returns Status code. More - specifically, #BT_VALUE_STATUS_CANCELED is - returned if the loop was canceled by the user - function. - -@prenotnull{map_obj} -@prenotnull{cb} -@pre \p map_obj is a map value object. -@postrefcountsame{map_obj} -*/ 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 - an entry mapped to the key \p key. - -@param[in] map_obj Map value object to check. -@param[in] key Key to check. -@returns #BT_TRUE if \p map_obj has an entry mapped to the - key \p key, or #BT_FALSE if it does not or - on error. - -@prenotnull{map_obj} -@prenotnull{key} -@pre \p map_obj is a map value object. -@postrefcountsame{map_obj} -*/ extern bt_bool bt_value_map_has_entry(const struct bt_value *map_obj, const char *key); -/** -@brief Inserts the value object \p element_obj mapped to the key - \p key into the map value object \p map_obj. - -If a value object is already mapped to \p key in \p map_obj, the -associated value object is first put, and then replaced by -\p element_obj. - -On success, \p key is copied. - -@param[in] map_obj Map value object in which to insert - \p element_obj. -@param[in] key Key (copied on success) to which the - value object to insert is mapped. -@param[in] element_obj Value object to insert, mapped to the - key \p key. -@returns Status code. - -@prenotnull{map_obj} -@prenotnull{key} -@prenotnull{element_obj} -@pre \p map_obj is a map value object. -@prehot{map_obj} -@post On success, if \p element_obj is not - \ref bt_value_null, its reference count is incremented. -@postrefcountsame{map_obj} - -@sa bt_value_map_insert_bool_entry(): Inserts a boolean raw value into a - given map value object. -@sa bt_value_map_insert_integer_entry(): Inserts an integer raw value into - a given map value object. -@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_entry(): Inserts a string raw value into a - given map value object. -@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_entry(): Inserts an empty map value - object into a given map value object. -*/ -extern enum bt_value_status bt_value_map_insert_entry( - struct bt_value *map_obj, const char *key, - struct bt_value *element_obj); - -/** -@brief Inserts the boolean raw value \p val mapped to the key \p key - into the map value object \p map_obj. - -This is a convenience function which creates the underlying boolean -value object before inserting it. - -On success, \p key is copied. - -@param[in] map_obj Map value object in which to insert \p val. -@param[in] key Key (copied on success) to which the boolean - value object to insert is mapped. -@param[in] val Boolean raw value to insert, mapped to - the key \p key. -@returns Status code. - -@prenotnull{map_obj} -@prenotnull{key} -@pre \p map_obj is a map value object. -@prehot{map_obj} -@postrefcountsame{map_obj} - -@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_entry( - struct bt_value *map_obj, const char *key, bt_bool val); - -/** -@brief Inserts the integer raw value \p val mapped to the key \p key - into the map value object \p map_obj. - -This is a convenience function which creates the underlying integer -value object before inserting it. - -On success, \p key is copied. - -@param[in] map_obj Map value object in which to insert \p val. -@param[in] key Key (copied on success) to which the integer - value object to insert is mapped. -@param[in] val Integer raw value to insert, mapped to - the key \p key. -@returns Status code. - -@prenotnull{map_obj} -@prenotnull{key} -@pre \p map_obj is a map value object. -@prehot{map_obj} -@postrefcountsame{map_obj} - -@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_entry( - struct bt_value *map_obj, const char *key, int64_t val); - -/** -@brief Inserts the floating point number raw value \p val mapped to - the key \p key into the map value object \p map_obj. - -This is a convenience function which creates the underlying floating -point number value object before inserting it. - -On success, \p key is copied. - -@param[in] map_obj Map value object in which to insert \p val. -@param[in] key Key (copied on success) to which the floating - point number value object to insert is mapped. -@param[in] val Floating point number raw value to insert, - mapped to the key \p key. -@returns Status code. - -@prenotnull{map_obj} -@prenotnull{key} -@pre \p map_obj is a map value object. -@prehot{map_obj} -@postrefcountsame{map_obj} - -@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_entry( - struct bt_value *map_obj, const char *key, double val); - -/** -@brief Inserts the string raw value \p val mapped to the key \p key - into the map value object \p map_obj. - -This is a convenience function which creates the underlying string value -object before inserting it. - -On success, \p val and \p key are copied. - -@param[in] map_obj Map value object in which to insert \p val. -@param[in] key Key (copied on success) to which the string - value object to insert is mapped. -@param[in] val String raw value to insert (copied on success), - mapped to the key \p key. -@returns Status code. - -@prenotnull{map_obj} -@prenotnull{key} -@prenotnull{val} -@pre \p map_obj is a map value object. -@prehot{map_obj} -@postrefcountsame{map_obj} - -@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_entry( - struct bt_value *map_obj, const char *key, const char *val); - -/** -@brief Inserts an empty array value object mapped to the key \p key - into the map value object \p map_obj. - -This is a convenience function which creates the underlying array value -object before inserting it. - -On success, \p key is copied. - -@param[in] map_obj Map value object in which to insert an empty - array value object. -@param[in] key Key (copied on success) to which the empty array - value object to insert is mapped. -@returns Status code. - -@prenotnull{map_obj} -@prenotnull{key} -@pre \p map_obj is a map value object. -@prehot{map_obj} -@postrefcountsame{map_obj} - -@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_entry( - struct bt_value *map_obj, const char *key); - -/** -@brief Inserts an empty map value object mapped to the key \p key into - the map value object \p map_obj. - -This is a convenience function which creates the underlying map value -object before inserting it. - -On success, \p key is copied. - -@param[in] map_obj Map value object in which to insert an empty - map object. -@param[in] key Key (copied on success) to which the empty map - value object to insert is mapped. -@returns Status code. - -@prenotnull{map_obj} -@prenotnull{key} -@pre \p map_obj is a map value object. -@prehot{map_obj} -@postrefcountsame{map_obj} - -@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_entry( - struct bt_value *map_obj, const char *key); - -/** -@brief Creates a copy of the base map value object \p base_map_obj - superficially extended with the entries of the extension map - value object \p extension_map_obj. - -This function creates a superficial extension of \p base_map_obj with -\p extension_map_obj by adding new entries to it and replacing the -ones that share the keys in the extension object. The extension is -\em superficial because it does not merge internal array and map -value objects. - -For example, consider the following \p base_map_obj (JSON representation): - -@verbatim -{ - "hello": 23, - "code": -17, - "em": false, - "return": [5, 6, null] -} -@endverbatim - -and the following \p extension_map_obj (JSON representation): - -@verbatim -{ - "comma": ",", - "code": 22, - "return": 17.88 -} -@endverbatim - -The extended object is (JSON representation): - -@verbatim -{ - "hello": 23, - "code": 22, - "em": false, - "return": 17.88, - "comma": "," -} -@endverbatim - -@param[in] base_map_obj Base map value object with initial - entries. -@param[in] extension_map_obj Extension map value object containing - the entries to add to or replace in - \p base_map_obj. -@returns Created extended map value object, or - \c NULL on error. - -@prenotnull{base_map_obj} -@prenotnull{extension_map_obj} -@pre \p base_map_obj is a map value object. -@pre \p extension_map_obj is a map value object. -@postrefcountsame{base_map_obj} -@postrefcountsame{extension_map_obj} -@postsuccessrefcountret1 -*/ -extern struct bt_value *bt_value_map_extend(struct bt_value *base_map_obj, +extern struct bt_private_value *bt_value_map_extend( + struct bt_value *base_map_obj, struct bt_value *extension_map_obj); -/** @} */ - -/** @} */ - #ifdef __cplusplus } #endif diff --git a/lib/ctf-writer/attributes.c b/lib/ctf-writer/attributes.c index ddec5c85..cbc778f7 100644 --- a/lib/ctf-writer/attributes.c +++ b/lib/ctf-writer/attributes.c @@ -34,15 +34,16 @@ #include #include #include +#include #include #define BT_CTF_ATTR_NAME_INDEX 0 #define BT_CTF_ATTR_VALUE_INDEX 1 BT_HIDDEN -struct bt_value *bt_ctf_attributes_create(void) +struct bt_private_value *bt_ctf_attributes_create(void) { - struct bt_value *attr_obj; + struct bt_private_value *attr_obj; /* * Attributes: array value object of array value objects, each one @@ -59,7 +60,7 @@ struct bt_value *bt_ctf_attributes_create(void) * ] */ BT_LOGD_STR("Creating attributes object."); - attr_obj = bt_value_array_create(); + attr_obj = bt_private_value_array_create(); if (!attr_obj) { BT_LOGE_STR("Failed to create array value."); } else { @@ -71,48 +72,50 @@ struct bt_value *bt_ctf_attributes_create(void) } BT_HIDDEN -void bt_ctf_attributes_destroy(struct bt_value *attr_obj) +void bt_ctf_attributes_destroy(struct bt_private_value *attr_obj) { BT_LOGD("Destroying attributes object: addr=%p", attr_obj); bt_object_put_ref(attr_obj); } BT_HIDDEN -int64_t bt_ctf_attributes_get_count(struct bt_value *attr_obj) +int64_t bt_ctf_attributes_get_count(struct bt_private_value *attr_obj) { - return bt_value_array_get_size(attr_obj); + return bt_value_array_get_size(bt_value_borrow_from_private(attr_obj)); } BT_HIDDEN -const char *bt_ctf_attributes_get_field_name(struct bt_value *attr_obj, +const char *bt_ctf_attributes_get_field_name(struct bt_private_value *attr_obj, uint64_t index) { int rc; const char *ret = NULL; - struct bt_value *attr_field_obj = NULL; - struct bt_value *attr_field_name_obj = NULL; + struct bt_private_value *attr_field_obj = NULL; + struct bt_private_value *attr_field_name_obj = NULL; if (!attr_obj) { BT_LOGW_STR("Invalid parameter: attributes object is NULL."); goto end; } - if (index >= bt_value_array_get_size(attr_obj)) { + if (index >= bt_value_array_get_size(bt_value_borrow_from_private(attr_obj))) { BT_LOGW("Invalid parameter: index is out of bounds: " "index=%" PRIu64 ", count=%" PRId64, - index, bt_value_array_get_size(attr_obj)); + index, bt_value_array_get_size(bt_value_borrow_from_private(attr_obj))); goto end; } - attr_field_obj = bt_value_array_borrow_element_by_index(attr_obj, index); + attr_field_obj = bt_private_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_element_by_index(attr_field_obj, - BT_CTF_ATTR_NAME_INDEX); + attr_field_name_obj = + bt_private_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: " "value-addr=%p, index=%" PRIu64, attr_field_obj, @@ -120,7 +123,8 @@ const char *bt_ctf_attributes_get_field_name(struct bt_value *attr_obj, goto end; } - rc = bt_value_string_get(attr_field_name_obj, &ret); + rc = bt_value_string_get( + bt_value_borrow_from_private(attr_field_name_obj), &ret); if (rc) { BT_LOGE("Cannot get raw value from string value: value-addr=%p", attr_field_name_obj); @@ -132,32 +136,33 @@ end: } BT_HIDDEN -struct bt_value *bt_ctf_attributes_borrow_field_value(struct bt_value *attr_obj, +struct bt_private_value *bt_ctf_attributes_borrow_field_value(struct bt_private_value *attr_obj, uint64_t index) { - struct bt_value *value_obj = NULL; - struct bt_value *attr_field_obj = NULL; + struct bt_private_value *value_obj = NULL; + struct bt_private_value *attr_field_obj = NULL; if (!attr_obj) { BT_LOGW_STR("Invalid parameter: attributes object is NULL."); goto end; } - if (index >= bt_value_array_get_size(attr_obj)) { + if (index >= bt_value_array_get_size(bt_value_borrow_from_private(attr_obj))) { BT_LOGW("Invalid parameter: index is out of bounds: " "index=%" PRIu64 ", count=%" PRId64, - index, bt_value_array_get_size(attr_obj)); + index, bt_value_array_get_size(bt_value_borrow_from_private(attr_obj))); goto end; } - attr_field_obj = bt_value_array_borrow_element_by_index(attr_obj, index); + attr_field_obj = bt_private_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_element_by_index(attr_field_obj, + value_obj = bt_private_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: " @@ -170,15 +175,15 @@ end: } static -struct bt_value *bt_ctf_attributes_borrow_field_by_name( - struct bt_value *attr_obj, const char *name) +struct bt_private_value *bt_ctf_attributes_borrow_field_by_name( + struct bt_private_value *attr_obj, const char *name) { uint64_t i; int64_t attr_size; - struct bt_value *value_obj = NULL; - struct bt_value *attr_field_name_obj = NULL; + struct bt_private_value *value_obj = NULL; + struct bt_private_value *attr_field_name_obj = NULL; - attr_size = bt_value_array_get_size(attr_obj); + attr_size = bt_value_array_get_size(bt_value_borrow_from_private(attr_obj)); if (attr_size < 0) { BT_LOGE("Cannot get array value's size: value-addr=%p", attr_obj); @@ -189,14 +194,14 @@ struct bt_value *bt_ctf_attributes_borrow_field_by_name( int ret; const char *field_name; - value_obj = bt_value_array_borrow_element_by_index(attr_obj, i); + value_obj = bt_private_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_element_by_index(value_obj, + attr_field_name_obj = bt_private_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: " @@ -205,7 +210,9 @@ struct bt_value *bt_ctf_attributes_borrow_field_by_name( goto error; } - ret = bt_value_string_get(attr_field_name_obj, &field_name); + ret = bt_value_string_get( + bt_value_borrow_from_private(attr_field_name_obj), + &field_name); if (ret) { BT_LOGE("Cannot get raw value from string value: value-addr=%p", attr_field_name_obj); @@ -227,11 +234,11 @@ error: } BT_HIDDEN -int bt_ctf_attributes_set_field_value(struct bt_value *attr_obj, - const char *name, struct bt_value *value_obj) +int bt_ctf_attributes_set_field_value(struct bt_private_value *attr_obj, + const char *name, struct bt_private_value *value_obj) { int ret = 0; - struct bt_value *attr_field_obj = NULL; + struct bt_private_value *attr_field_obj = NULL; if (!attr_obj || !name || !value_obj) { BT_LOGW("Invalid parameter: attributes object, name, or value object is NULL: " @@ -243,28 +250,31 @@ 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_element_by_index(attr_field_obj, - BT_CTF_ATTR_VALUE_INDEX, value_obj); + ret = bt_private_value_array_set_element_by_index( + attr_field_obj, BT_CTF_ATTR_VALUE_INDEX, + bt_value_borrow_from_private(value_obj)); attr_field_obj = NULL; goto end; } - attr_field_obj = bt_value_array_create(); + attr_field_obj = bt_private_value_array_create(); if (!attr_field_obj) { BT_LOGE_STR("Failed to create empty array value."); ret = -1; goto end; } - ret = bt_value_array_append_string_element(attr_field_obj, name); - ret |= bt_value_array_append_element(attr_field_obj, value_obj); + ret = bt_private_value_array_append_string_element(attr_field_obj, name); + ret |= bt_private_value_array_append_element(attr_field_obj, + bt_value_borrow_from_private(value_obj)); if (ret) { BT_LOGE("Cannot append elements to array value: addr=%p", attr_field_obj); goto end; } - ret = bt_value_array_append_element(attr_obj, attr_field_obj); + ret = bt_private_value_array_append_element(attr_obj, + bt_value_borrow_from_private(attr_field_obj)); if (ret) { BT_LOGE("Cannot append element to array value: " "array-value-addr=%p, element-value-addr=%p", @@ -277,11 +287,11 @@ end: } BT_HIDDEN -struct bt_value *bt_ctf_attributes_borrow_field_value_by_name( - struct bt_value *attr_obj, const char *name) +struct bt_private_value *bt_ctf_attributes_borrow_field_value_by_name( + struct bt_private_value *attr_obj, const char *name) { - struct bt_value *value_obj = NULL; - struct bt_value *attr_field_obj = NULL; + struct bt_private_value *value_obj = NULL; + struct bt_private_value *attr_field_obj = NULL; if (!attr_obj || !name) { BT_LOGW("Invalid parameter: attributes object or name is NULL: " @@ -296,7 +306,7 @@ struct bt_value *bt_ctf_attributes_borrow_field_value_by_name( goto end; } - value_obj = bt_value_array_borrow_element_by_index(attr_field_obj, + value_obj = bt_private_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: " @@ -309,7 +319,7 @@ end: } BT_HIDDEN -int bt_ctf_attributes_freeze(struct bt_value *attr_obj) +int bt_ctf_attributes_freeze(struct bt_private_value *attr_obj) { uint64_t i; int64_t count; @@ -322,7 +332,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_get_size(attr_obj); + count = bt_value_array_get_size(bt_value_borrow_from_private(attr_obj)); BT_ASSERT(count >= 0); /* @@ -331,7 +341,7 @@ int bt_ctf_attributes_freeze(struct bt_value *attr_obj) * attribute is frozen one by one. */ for (i = 0; i < count; ++i) { - struct bt_value *obj = NULL; + struct bt_private_value *obj = NULL; obj = bt_ctf_attributes_borrow_field_value(attr_obj, i); if (!obj) { @@ -342,7 +352,7 @@ int bt_ctf_attributes_freeze(struct bt_value *attr_obj) goto end; } - bt_value_freeze(obj); + bt_value_freeze(bt_value_borrow_from_private(obj)); } end: diff --git a/lib/ctf-writer/event.c b/lib/ctf-writer/event.c index e027880c..59ee3786 100644 --- a/lib/ctf-writer/event.c +++ b/lib/ctf-writer/event.c @@ -66,7 +66,7 @@ int bt_ctf_event_common_validate_types_for_create( struct bt_ctf_field_type_common *event_context_type = NULL; struct bt_ctf_field_type_common *event_payload_type = NULL; int trace_valid = 0; - struct bt_value *environment = NULL; + struct bt_private_value *environment = NULL; stream_class = bt_ctf_event_class_common_borrow_stream_class(event_class); BT_ASSERT(stream_class); diff --git a/lib/ctf-writer/resolve.c b/lib/ctf-writer/resolve.c index c0388cd7..eb9265d7 100644 --- a/lib/ctf-writer/resolve.c +++ b/lib/ctf-writer/resolve.c @@ -76,7 +76,7 @@ struct type_stack_frame { * * Event payload */ struct resolve_context { - struct bt_value *environment; + struct bt_private_value *environment; struct bt_ctf_field_type_common *scopes[6]; /* Root scope being visited */ @@ -1229,7 +1229,7 @@ int resolve_root_type(enum bt_ctf_scope root_scope, struct resolve_context *ctx) BT_HIDDEN int bt_ctf_resolve_types( - struct bt_value *environment, + struct bt_private_value *environment, struct bt_ctf_field_type_common *packet_header_type, struct bt_ctf_field_type_common *packet_context_type, struct bt_ctf_field_type_common *event_header_type, diff --git a/lib/ctf-writer/trace.c b/lib/ctf-writer/trace.c index 24842faa..98d79b97 100644 --- a/lib/ctf-writer/trace.c +++ b/lib/ctf-writer/trace.c @@ -230,7 +230,7 @@ end: BT_HIDDEN int bt_ctf_trace_common_set_environment_field(struct bt_ctf_trace_common *trace, - const char *name, struct bt_value *value) + const char *name, struct bt_private_value *value) { int ret = 0; @@ -261,12 +261,15 @@ int bt_ctf_trace_common_set_environment_field(struct bt_ctf_trace_common *trace, goto end; } - if (!bt_value_is_integer(value) && !bt_value_is_string(value)) { + if (!bt_value_is_integer(bt_value_borrow_from_private(value)) && + !bt_value_is_string(bt_value_borrow_from_private(value))) { BT_LOGW("Invalid parameter: environment field's value is not an integer or string value: " "trace-addr=%p, trace-name=\"%s\", " "env-name=\"%s\", env-value-type=%s", trace, bt_ctf_trace_common_get_name(trace), name, - bt_value_type_string(bt_value_get_type(value))); + bt_common_value_type_string( + bt_value_get_type( + bt_value_borrow_from_private(value)))); ret = -1; goto end; } @@ -278,7 +281,7 @@ int bt_ctf_trace_common_set_environment_field(struct bt_ctf_trace_common *trace, * * The object passed is frozen like all other attributes. */ - struct bt_value *attribute = + struct bt_private_value *attribute = bt_ctf_attributes_borrow_field_value_by_name( trace->environment, name); @@ -291,7 +294,7 @@ int bt_ctf_trace_common_set_environment_field(struct bt_ctf_trace_common *trace, goto end; } - bt_value_freeze(value); + bt_value_freeze(bt_value_borrow_from_private(value)); } ret = bt_ctf_attributes_set_field_value(trace->environment, name, @@ -317,7 +320,7 @@ int bt_ctf_trace_common_set_environment_field_string(struct bt_ctf_trace_common const char *name, const char *value) { int ret = 0; - struct bt_value *env_value_string_obj = NULL; + struct bt_private_value *env_value_string_obj = NULL; if (!value) { BT_LOGW_STR("Invalid parameter: value is NULL."); @@ -325,7 +328,7 @@ int bt_ctf_trace_common_set_environment_field_string(struct bt_ctf_trace_common goto end; } - env_value_string_obj = bt_value_string_create_init(value); + env_value_string_obj = bt_private_value_string_create_init(value); if (!env_value_string_obj) { BT_LOGE_STR("Cannot create string value object."); ret = -1; @@ -346,9 +349,9 @@ int bt_ctf_trace_common_set_environment_field_integer( struct bt_ctf_trace_common *trace, const char *name, int64_t value) { int ret = 0; - struct bt_value *env_value_integer_obj = NULL; + struct bt_private_value *env_value_integer_obj = NULL; - env_value_integer_obj = bt_value_integer_create_init(value); + env_value_integer_obj = bt_private_value_integer_create_init(value); if (!env_value_integer_obj) { BT_LOGE_STR("Cannot create integer value object."); ret = -1; @@ -1467,13 +1470,6 @@ int bt_ctf_trace_set_uuid(struct bt_ctf_trace *trace, return bt_ctf_trace_common_set_uuid(BT_CTF_TO_COMMON(trace), uuid); } -int bt_ctf_trace_set_environment_field(struct bt_ctf_trace *trace, - const char *name, struct bt_value *value) -{ - return bt_ctf_trace_common_set_environment_field(BT_CTF_TO_COMMON(trace), - name, value); -} - int bt_ctf_trace_set_environment_field_string(struct bt_ctf_trace *trace, const char *name, const char *value) { @@ -1752,7 +1748,7 @@ void append_env_metadata(struct bt_ctf_trace *trace, g_string_append(context->string, "env {\n"); for (i = 0; i < env_size; i++) { - struct bt_value *env_field_value_obj = NULL; + struct bt_private_value *env_field_value_obj = NULL; const char *entry_name; entry_name = bt_ctf_attributes_get_field_name( @@ -1763,14 +1759,16 @@ void append_env_metadata(struct bt_ctf_trace *trace, BT_ASSERT(entry_name); BT_ASSERT(env_field_value_obj); - switch (bt_value_get_type(env_field_value_obj)) { + switch (bt_value_get_type( + bt_value_borrow_from_private(env_field_value_obj))) { case BT_VALUE_TYPE_INTEGER: { int ret; int64_t int_value; - ret = bt_value_integer_get(env_field_value_obj, - &int_value); + ret = bt_value_integer_get( + bt_value_borrow_from_private( + env_field_value_obj), &int_value); BT_ASSERT(ret == 0); g_string_append_printf(context->string, "\t%s = %" PRId64 ";\n", entry_name, @@ -1783,8 +1781,9 @@ void append_env_metadata(struct bt_ctf_trace *trace, const char *str_value; char *escaped_str = NULL; - ret = bt_value_string_get(env_field_value_obj, - &str_value); + ret = bt_value_string_get( + bt_value_borrow_from_private( + env_field_value_obj), &str_value); BT_ASSERT(ret == 0); escaped_str = g_strescape(str_value, NULL); if (!escaped_str) { diff --git a/lib/ctf-writer/validation.c b/lib/ctf-writer/validation.c index 15309b2a..03ad36ff 100644 --- a/lib/ctf-writer/validation.c +++ b/lib/ctf-writer/validation.c @@ -48,7 +48,7 @@ * All parameters are owned by the caller. */ static -int validate_event_class_types(struct bt_value *environment, +int validate_event_class_types(struct bt_private_value *environment, struct bt_ctf_field_type_common *packet_header_type, struct bt_ctf_field_type_common *packet_context_type, struct bt_ctf_field_type_common *event_header_type, @@ -112,7 +112,7 @@ end: * All parameters are owned by the caller. */ static -int validate_stream_class_types(struct bt_value *environment, +int validate_stream_class_types(struct bt_private_value *environment, struct bt_ctf_field_type_common *packet_header_type, struct bt_ctf_field_type_common *packet_context_type, struct bt_ctf_field_type_common *event_header_type, @@ -180,7 +180,7 @@ end: * All parameters are owned by the caller. */ static -int validate_trace_types(struct bt_value *environment, +int validate_trace_types(struct bt_private_value *environment, struct bt_ctf_field_type_common *packet_header_type) { int ret = 0; @@ -262,7 +262,7 @@ end: } BT_HIDDEN -int bt_ctf_validate_class_types(struct bt_value *environment, +int bt_ctf_validate_class_types(struct bt_private_value *environment, struct bt_ctf_field_type_common *packet_header_type, struct bt_ctf_field_type_common *packet_context_type, struct bt_ctf_field_type_common *event_header_type, diff --git a/lib/graph/graph.c b/lib/graph/graph.c index b4350414..c01d0b5b 100644 --- a/lib/graph/graph.c +++ b/lib/graph/graph.c @@ -39,8 +39,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -1100,12 +1102,14 @@ enum bt_graph_status bt_graph_add_component_with_init_method_data( if (!bt_value_is_map(params)) { BT_LOGW("Invalid parameter: initialization parameters must be a map value: " "type=%s", - bt_value_type_string(bt_value_get_type(params))); + bt_common_value_type_string( + bt_value_get_type(params))); graph_status = BT_GRAPH_STATUS_INVALID; goto end; } } else { - params = bt_value_map_create(); + params = bt_value_borrow_from_private( + bt_private_value_map_create()); if (!params) { BT_LOGE_STR("Cannot create map value object."); graph_status = BT_GRAPH_STATUS_NOMEM; diff --git a/lib/lib-logging.c b/lib/lib-logging.c index 3207c3d0..9dd8ae7f 100644 --- a/lib/lib-logging.c +++ b/lib/lib-logging.c @@ -796,7 +796,7 @@ static inline void format_value(char **buf_ch, bool extended, const char *prefix, struct bt_value *value) { BUF_APPEND(", %stype=%s", - PRFIELD(bt_value_type_string(bt_value_get_type(value)))); + PRFIELD(bt_common_value_type_string(bt_value_get_type(value)))); if (!extended) { return; diff --git a/lib/trace-ir/attributes.c b/lib/trace-ir/attributes.c index c1c92032..0b321e2e 100644 --- a/lib/trace-ir/attributes.c +++ b/lib/trace-ir/attributes.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -40,9 +41,9 @@ #define BT_ATTR_VALUE_INDEX 1 BT_HIDDEN -struct bt_value *bt_attributes_create(void) +struct bt_private_value *bt_attributes_create(void) { - struct bt_value *attr_obj; + struct bt_private_value *attr_obj; /* * Attributes: array value object of array value objects, each one @@ -59,7 +60,7 @@ struct bt_value *bt_attributes_create(void) * ] */ BT_LOGD_STR("Creating attributes object."); - attr_obj = bt_value_array_create(); + attr_obj = bt_private_value_array_create(); if (!attr_obj) { BT_LOGE_STR("Failed to create array value."); } else { @@ -71,48 +72,52 @@ struct bt_value *bt_attributes_create(void) } BT_HIDDEN -void bt_attributes_destroy(struct bt_value *attr_obj) +void bt_attributes_destroy(struct bt_private_value *attr_obj) { BT_LOGD("Destroying attributes object: addr=%p", attr_obj); bt_object_put_ref(attr_obj); } BT_HIDDEN -int64_t bt_attributes_get_count(struct bt_value *attr_obj) +int64_t bt_attributes_get_count(struct bt_private_value *attr_obj) { - return bt_value_array_get_size(attr_obj); + return bt_value_array_get_size(bt_value_borrow_from_private(attr_obj)); } BT_HIDDEN -const char *bt_attributes_get_field_name(struct bt_value *attr_obj, +const char *bt_attributes_get_field_name(struct bt_private_value *attr_obj, uint64_t index) { int rc; const char *ret = NULL; - struct bt_value *attr_field_obj = NULL; - struct bt_value *attr_field_name_obj = NULL; + struct bt_private_value *attr_field_obj = NULL; + struct bt_private_value *attr_field_name_obj = NULL; if (!attr_obj) { BT_LOGW_STR("Invalid parameter: attributes object is NULL."); goto end; } - if (index >= bt_value_array_get_size(attr_obj)) { + if (index >= bt_value_array_get_size( + bt_value_borrow_from_private(attr_obj))) { BT_LOGW("Invalid parameter: index is out of bounds: " "index=%" PRIu64 ", count=%" PRId64, - index, bt_value_array_get_size(attr_obj)); + index, bt_value_array_get_size( + bt_value_borrow_from_private(attr_obj))); goto end; } - attr_field_obj = bt_value_array_borrow_element_by_index(attr_obj, index); + attr_field_obj = bt_private_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_element_by_index(attr_field_obj, - BT_ATTR_NAME_INDEX); + attr_field_name_obj = + bt_private_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: " "value-addr=%p, index=%" PRIu64, attr_field_obj, @@ -120,7 +125,8 @@ const char *bt_attributes_get_field_name(struct bt_value *attr_obj, goto end; } - rc = bt_value_string_get(attr_field_name_obj, &ret); + rc = bt_value_string_get( + bt_value_borrow_from_private(attr_field_name_obj), &ret); if (rc) { BT_LOGE("Cannot get raw value from string value: value-addr=%p", attr_field_name_obj); @@ -132,33 +138,35 @@ end: } BT_HIDDEN -struct bt_value *bt_attributes_borrow_field_value(struct bt_value *attr_obj, - uint64_t index) +struct bt_private_value *bt_attributes_borrow_field_value( + struct bt_private_value *attr_obj, uint64_t index) { - struct bt_value *value_obj = NULL; - struct bt_value *attr_field_obj = NULL; + struct bt_private_value *value_obj = NULL; + struct bt_private_value *attr_field_obj = NULL; if (!attr_obj) { BT_LOGW_STR("Invalid parameter: attributes object is NULL."); goto end; } - if (index >= bt_value_array_get_size(attr_obj)) { + if (index >= bt_value_array_get_size(bt_value_borrow_from_private(attr_obj))) { BT_LOGW("Invalid parameter: index is out of bounds: " "index=%" PRIu64 ", count=%" PRId64, - index, bt_value_array_get_size(attr_obj)); + index, bt_value_array_get_size( + bt_value_borrow_from_private(attr_obj))); goto end; } - attr_field_obj = bt_value_array_borrow_element_by_index(attr_obj, index); + attr_field_obj = + bt_private_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_element_by_index(attr_field_obj, - BT_ATTR_VALUE_INDEX); + value_obj = bt_private_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: " "value-addr=%p, index=%" PRIu64, attr_field_obj, @@ -170,15 +178,16 @@ end: } static -struct bt_value *bt_attributes_borrow_field_by_name( - struct bt_value *attr_obj, const char *name) +struct bt_private_value *bt_attributes_borrow_field_by_name( + struct bt_private_value *attr_obj, const char *name) { uint64_t i; int64_t attr_size; - struct bt_value *value_obj = NULL; - struct bt_value *attr_field_name_obj = NULL; + struct bt_private_value *value_obj = NULL; + struct bt_private_value *attr_field_name_obj = NULL; - attr_size = bt_value_array_get_size(attr_obj); + attr_size = bt_value_array_get_size( + bt_value_borrow_from_private(attr_obj)); if (attr_size < 0) { BT_LOGE("Cannot get array value's size: value-addr=%p", attr_obj); @@ -189,15 +198,17 @@ struct bt_value *bt_attributes_borrow_field_by_name( int ret; const char *field_name; - value_obj = bt_value_array_borrow_element_by_index(attr_obj, i); + value_obj = bt_private_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_element_by_index(value_obj, - BT_ATTR_NAME_INDEX); + attr_field_name_obj = + bt_private_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: " "value-addr=%p, index=%" PRIu64, @@ -205,7 +216,9 @@ struct bt_value *bt_attributes_borrow_field_by_name( goto error; } - ret = bt_value_string_get(attr_field_name_obj, &field_name); + ret = bt_value_string_get( + bt_value_borrow_from_private(attr_field_name_obj), + &field_name); if (ret) { BT_LOGE("Cannot get raw value from string value: value-addr=%p", attr_field_name_obj); @@ -227,11 +240,11 @@ error: } BT_HIDDEN -int bt_attributes_set_field_value(struct bt_value *attr_obj, - const char *name, struct bt_value *value_obj) +int bt_attributes_set_field_value(struct bt_private_value *attr_obj, + const char *name, struct bt_private_value *value_obj) { int ret = 0; - struct bt_value *attr_field_obj = NULL; + struct bt_private_value *attr_field_obj = NULL; if (!attr_obj || !name || !value_obj) { BT_LOGW("Invalid parameter: attributes object, name, or value object is NULL: " @@ -243,28 +256,32 @@ 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_element_by_index(attr_field_obj, - BT_ATTR_VALUE_INDEX, value_obj); + ret = bt_private_value_array_set_element_by_index( + attr_field_obj, BT_ATTR_VALUE_INDEX, + bt_value_borrow_from_private(value_obj)); attr_field_obj = NULL; goto end; } - attr_field_obj = bt_value_array_create(); + attr_field_obj = bt_private_value_array_create(); if (!attr_field_obj) { BT_LOGE_STR("Failed to create empty array value."); ret = -1; goto end; } - ret = bt_value_array_append_string_element(attr_field_obj, name); - ret |= bt_value_array_append_element(attr_field_obj, value_obj); + ret = bt_private_value_array_append_string_element(attr_field_obj, + name); + ret |= bt_private_value_array_append_element(attr_field_obj, + bt_value_borrow_from_private(value_obj)); if (ret) { BT_LOGE("Cannot append elements to array value: addr=%p", attr_field_obj); goto end; } - ret = bt_value_array_append_element(attr_obj, attr_field_obj); + ret = bt_private_value_array_append_element(attr_obj, + bt_value_borrow_from_private(attr_field_obj)); if (ret) { BT_LOGE("Cannot append element to array value: " "array-value-addr=%p, element-value-addr=%p", @@ -277,11 +294,11 @@ end: } BT_HIDDEN -struct bt_value *bt_attributes_borrow_field_value_by_name( - struct bt_value *attr_obj, const char *name) +struct bt_private_value *bt_attributes_borrow_field_value_by_name( + struct bt_private_value *attr_obj, const char *name) { - struct bt_value *value_obj = NULL; - struct bt_value *attr_field_obj = NULL; + struct bt_private_value *value_obj = NULL; + struct bt_private_value *attr_field_obj = NULL; if (!attr_obj || !name) { BT_LOGW("Invalid parameter: attributes object or name is NULL: " @@ -296,8 +313,8 @@ struct bt_value *bt_attributes_borrow_field_value_by_name( goto end; } - value_obj = bt_value_array_borrow_element_by_index(attr_field_obj, - BT_ATTR_VALUE_INDEX); + value_obj = bt_private_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: " "value-addr=%p, index=%" PRIu64, attr_field_obj, @@ -309,7 +326,7 @@ end: } BT_HIDDEN -int bt_attributes_freeze(struct bt_value *attr_obj) +int bt_attributes_freeze(struct bt_private_value *attr_obj) { uint64_t i; int64_t count; @@ -322,7 +339,7 @@ int bt_attributes_freeze(struct bt_value *attr_obj) } BT_LOGD("Freezing attributes object: value-addr=%p", attr_obj); - count = bt_value_array_get_size(attr_obj); + count = bt_value_array_get_size(bt_value_borrow_from_private(attr_obj)); BT_ASSERT(count >= 0); /* @@ -331,7 +348,7 @@ int bt_attributes_freeze(struct bt_value *attr_obj) * attribute is frozen one by one. */ for (i = 0; i < count; ++i) { - struct bt_value *obj = NULL; + struct bt_private_value *obj = NULL; obj = bt_attributes_borrow_field_value(attr_obj, i); if (!obj) { @@ -342,7 +359,7 @@ int bt_attributes_freeze(struct bt_value *attr_obj) goto end; } - bt_value_freeze(obj); + bt_value_freeze(bt_value_borrow_from_private(obj)); } end: diff --git a/lib/trace-ir/trace.c b/lib/trace-ir/trace.c index 02c18cc6..afc37d9c 100644 --- a/lib/trace-ir/trace.c +++ b/lib/trace-ir/trace.c @@ -46,6 +46,7 @@ #include #include #include +#include #include #include #include @@ -242,18 +243,15 @@ BT_ASSERT_FUNC static bool trace_has_environment_entry(struct bt_trace *trace, const char *name) { - struct bt_value *attribute; - BT_ASSERT(trace); - attribute = bt_attributes_borrow_field_value_by_name( - trace->environment, name); - return attribute != NULL; + return bt_attributes_borrow_field_value_by_name( + trace->environment, name) != NULL; } static int set_environment_entry(struct bt_trace *trace, const char *name, - struct bt_value *value) + struct bt_private_value *value) { int ret; @@ -266,7 +264,7 @@ int set_environment_entry(struct bt_trace *trace, const char *name, "%![trace-]+t, entry-name=\"%s\"", trace, name); ret = bt_attributes_set_field_value(trace->environment, name, value); - bt_value_freeze(value); + bt_value_freeze(bt_value_borrow_from_private(value)); if (ret) { BT_LIB_LOGE("Cannot set trace's environment entry: " "%![trace-]+t, entry-name=\"%s\"", trace, name); @@ -282,12 +280,12 @@ int bt_trace_set_environment_entry_string(struct bt_trace *trace, const char *name, const char *value) { int ret; - struct bt_value *value_obj; + struct bt_private_value *value_obj; BT_ASSERT_PRE_NON_NULL(trace, "Trace"); BT_ASSERT_PRE_NON_NULL(name, "Name"); BT_ASSERT_PRE_NON_NULL(value, "Value"); - value_obj = bt_value_string_create_init(value); + value_obj = bt_private_value_string_create_init(value); if (!value_obj) { BT_LOGE_STR("Cannot create a string value object."); ret = -1; @@ -306,11 +304,11 @@ int bt_trace_set_environment_entry_integer( struct bt_trace *trace, const char *name, int64_t value) { int ret; - struct bt_value *value_obj; + struct bt_private_value *value_obj; BT_ASSERT_PRE_NON_NULL(trace, "Trace"); BT_ASSERT_PRE_NON_NULL(name, "Name"); - value_obj = bt_value_integer_create_init(value); + value_obj = bt_private_value_integer_create_init(value); if (!value_obj) { BT_LOGE_STR("Cannot create an integer value object."); ret = -1; @@ -344,7 +342,8 @@ void bt_trace_borrow_environment_entry_by_index( BT_ASSERT_PRE_NON_NULL(value, "Value"); BT_ASSERT_PRE_VALID_INDEX(index, bt_attributes_get_count(trace->environment)); - *value = bt_attributes_borrow_field_value(trace->environment, index); + *value = bt_value_borrow_from_private( + bt_attributes_borrow_field_value(trace->environment, index)); BT_ASSERT(*value); *name = bt_attributes_get_field_name(trace->environment, index); BT_ASSERT(*name); @@ -355,8 +354,9 @@ struct bt_value *bt_trace_borrow_environment_entry_value_by_name( { BT_ASSERT_PRE_NON_NULL(trace, "Trace"); BT_ASSERT_PRE_NON_NULL(name, "Name"); - return bt_attributes_borrow_field_value_by_name(trace->environment, - name); + return bt_value_borrow_from_private( + bt_attributes_borrow_field_value_by_name(trace->environment, + name)); } uint64_t bt_trace_get_stream_count(struct bt_trace *trace) diff --git a/lib/values.c b/lib/values.c index a4393841..d437657c 100644 --- a/lib/values.c +++ b/lib/values.c @@ -33,8 +33,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -51,20 +53,20 @@ #define BT_VALUE_TO_MAP(_base) ((struct bt_value_map *) (_base)) #define BT_ASSERT_PRE_VALUE_IS_TYPE(_value, _type) \ - BT_ASSERT_PRE((_value)->type == (_type), \ + BT_ASSERT_PRE(((struct bt_value *) (_value))->type == (_type), \ "Value has the wrong type ID: expected-type=%s, " \ - "%![value-]+v", bt_value_type_string(_type), \ + "%![value-]+v", bt_common_value_type_string(_type), \ (_value)) #define BT_ASSERT_PRE_VALUE_HOT(_value, _name) \ - BT_ASSERT_PRE_HOT((_value), (_name), ": %!+v", (_value)) + BT_ASSERT_PRE_HOT(((struct bt_value *) (_value)), (_name), \ + ": %!+v", (_value)) #define BT_ASSERT_PRE_VALUE_INDEX_IN_BOUNDS(_index, _count) \ BT_ASSERT_PRE((_index) < (_count), \ "Index is out of bound: " \ "index=%" PRIu64 ", count=%u", (_index), (_count)); - struct bt_value { struct bt_object base; enum bt_value_type type; @@ -92,6 +94,7 @@ struct bt_value bt_value_null_instance = { }; struct bt_value *bt_value_null = &bt_value_null_instance; +struct bt_private_value *bt_private_value_null = (void *) &bt_value_null_instance; struct bt_value_bool { struct bt_value base; @@ -165,56 +168,57 @@ void (* const destroy_funcs[])(struct bt_value *) = { }; static -struct bt_value *bt_value_null_copy(const struct bt_value *null_obj) +struct bt_private_value *bt_value_null_copy(const struct bt_value *null_obj) { - return bt_value_null; + return (void *) bt_value_null; } static -struct bt_value *bt_value_bool_copy(const struct bt_value *bool_obj) +struct bt_private_value *bt_value_bool_copy(const struct bt_value *bool_obj) { - return bt_value_bool_create_init(BT_VALUE_TO_BOOL(bool_obj)->value); + return bt_private_value_bool_create_init(BT_VALUE_TO_BOOL(bool_obj)->value); } static -struct bt_value *bt_value_integer_copy(const struct bt_value *integer_obj) +struct bt_private_value *bt_value_integer_copy( + const struct bt_value *integer_obj) { - return bt_value_integer_create_init( + return bt_private_value_integer_create_init( BT_VALUE_TO_INTEGER(integer_obj)->value); } static -struct bt_value *bt_value_real_copy(const struct bt_value *real_obj) +struct bt_private_value *bt_value_real_copy(const struct bt_value *real_obj) { - return bt_value_real_create_init( + return bt_private_value_real_create_init( BT_VALUE_TO_REAL(real_obj)->value); } static -struct bt_value *bt_value_string_copy(const struct bt_value *string_obj) +struct bt_private_value *bt_value_string_copy(const struct bt_value *string_obj) { - return bt_value_string_create_init( + return bt_private_value_string_create_init( BT_VALUE_TO_STRING(string_obj)->gstr->str); } static -struct bt_value *bt_value_array_copy(const struct bt_value *array_obj) +struct bt_private_value *bt_value_array_copy(const struct bt_value *array_obj) { int i; int ret; - struct bt_value *copy_obj; + struct bt_private_value *copy_obj; struct bt_value_array *typed_array_obj; BT_LOGD("Copying array value: addr=%p", array_obj); typed_array_obj = BT_VALUE_TO_ARRAY(array_obj); - copy_obj = bt_value_array_create(); + copy_obj = bt_private_value_array_create(); if (!copy_obj) { BT_LOGE_STR("Cannot create empty array value."); goto end; } for (i = 0; i < typed_array_obj->garray->len; ++i) { - struct bt_value *element_obj_copy; + struct bt_private_value *element_obj_copy; struct bt_value *element_obj = bt_value_array_borrow_element_by_index( array_obj, i); @@ -230,7 +234,8 @@ struct bt_value *bt_value_array_copy(const struct bt_value *array_obj) goto end; } - ret = bt_value_array_append_element(copy_obj, element_obj_copy); + ret = bt_private_value_array_append_element(copy_obj, + (void *) element_obj_copy); BT_OBJECT_PUT_REF_AND_RESET(element_obj_copy); if (ret) { BT_LOGE("Cannot append to array value: addr=%p", @@ -248,18 +253,18 @@ end: } static -struct bt_value *bt_value_map_copy(const struct bt_value *map_obj) +struct bt_private_value *bt_value_map_copy(const struct bt_value *map_obj) { int ret; GHashTableIter iter; gpointer key, element_obj; - struct bt_value *copy_obj; - struct bt_value *element_obj_copy; + struct bt_private_value *copy_obj; + struct bt_private_value *element_obj_copy; struct bt_value_map *typed_map_obj; BT_LOGD("Copying map value: addr=%p", map_obj); typed_map_obj = BT_VALUE_TO_MAP(map_obj); - copy_obj = bt_value_map_create(); + copy_obj = bt_private_value_map_create(); if (!copy_obj) { goto end; } @@ -281,7 +286,8 @@ struct bt_value *bt_value_map_copy(const struct bt_value *map_obj) goto end; } - ret = bt_value_map_insert_entry(copy_obj, key_str, element_obj_copy); + ret = bt_private_value_map_insert_entry(copy_obj, key_str, + (void *) element_obj_copy); BT_OBJECT_PUT_REF_AND_RESET(element_obj_copy); if (ret) { BT_LOGE("Cannot insert into map value: addr=%p, key=\"%s\"", @@ -298,7 +304,7 @@ end: } static -struct bt_value *(* const copy_funcs[])(const struct bt_value *) = { +struct bt_private_value *(* const copy_funcs[])(const struct bt_value *) = { [BT_VALUE_TYPE_NULL] = bt_value_null_copy, [BT_VALUE_TYPE_BOOL] = bt_value_bool_copy, [BT_VALUE_TYPE_INTEGER] = bt_value_integer_copy, @@ -393,7 +399,8 @@ 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_get_size(object_a) != bt_value_array_get_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, @@ -408,8 +415,10 @@ 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_element_by_index(object_a, i); - element_obj_b = bt_value_array_borrow_element_by_index(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: " @@ -450,7 +459,8 @@ 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_entry_value(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: " @@ -584,7 +594,7 @@ struct bt_value bt_value_create_base(enum bt_value_type type) return value; } -struct bt_value *bt_value_bool_create_init(bt_bool val) +struct bt_private_value *bt_private_value_bool_create_init(bt_bool val) { struct bt_value_bool *bool_obj; @@ -600,15 +610,15 @@ struct bt_value *bt_value_bool_create_init(bt_bool val) BT_LOGD("Created boolean value object: addr=%p", bool_obj); end: - return BT_VALUE_FROM_CONCRETE(bool_obj); + return (void *) BT_VALUE_FROM_CONCRETE(bool_obj); } -struct bt_value *bt_value_bool_create(void) +struct bt_private_value *bt_private_value_bool_create(void) { - return bt_value_bool_create_init(BT_FALSE); + return bt_private_value_bool_create_init(BT_FALSE); } -struct bt_value *bt_value_integer_create_init(int64_t val) +struct bt_private_value *bt_private_value_integer_create_init(int64_t val) { struct bt_value_integer *integer_obj; @@ -625,15 +635,15 @@ struct bt_value *bt_value_integer_create_init(int64_t val) integer_obj); end: - return BT_VALUE_FROM_CONCRETE(integer_obj); + return (void *) BT_VALUE_FROM_CONCRETE(integer_obj); } -struct bt_value *bt_value_integer_create(void) +struct bt_private_value *bt_private_value_integer_create(void) { - return bt_value_integer_create_init(0); + return bt_private_value_integer_create_init(0); } -struct bt_value *bt_value_real_create_init(double val) +struct bt_private_value *bt_private_value_real_create_init(double val) { struct bt_value_real *real_obj; @@ -650,15 +660,15 @@ struct bt_value *bt_value_real_create_init(double val) real_obj); end: - return BT_VALUE_FROM_CONCRETE(real_obj); + return (void *) BT_VALUE_FROM_CONCRETE(real_obj); } -struct bt_value *bt_value_real_create(void) +struct bt_private_value *bt_private_value_real_create(void) { - return bt_value_real_create_init(0.); + return bt_private_value_real_create_init(0.); } -struct bt_value *bt_value_string_create_init(const char *val) +struct bt_private_value *bt_private_value_string_create_init(const char *val) { struct bt_value_string *string_obj = NULL; @@ -687,15 +697,15 @@ struct bt_value *bt_value_string_create_init(const char *val) string_obj); end: - return BT_VALUE_FROM_CONCRETE(string_obj); + return (void *) BT_VALUE_FROM_CONCRETE(string_obj); } -struct bt_value *bt_value_string_create(void) +struct bt_private_value *bt_private_value_string_create(void) { - return bt_value_string_create_init(""); + return bt_private_value_string_create_init(""); } -struct bt_value *bt_value_array_create(void) +struct bt_private_value *bt_private_value_array_create(void) { struct bt_value_array *array_obj; @@ -720,10 +730,10 @@ struct bt_value *bt_value_array_create(void) array_obj); end: - return BT_VALUE_FROM_CONCRETE(array_obj); + return (void *) BT_VALUE_FROM_CONCRETE(array_obj); } -struct bt_value *bt_value_map_create(void) +struct bt_private_value *bt_private_value_map_create(void) { struct bt_value_map *map_obj; @@ -748,7 +758,7 @@ struct bt_value *bt_value_map_create(void) map_obj); end: - return BT_VALUE_FROM_CONCRETE(map_obj); + return (void *) BT_VALUE_FROM_CONCRETE(map_obj); } enum bt_value_status bt_value_bool_get(const struct bt_value *bool_obj, @@ -761,7 +771,8 @@ enum bt_value_status bt_value_bool_get(const struct bt_value *bool_obj, return BT_VALUE_STATUS_OK; } -enum bt_value_status bt_value_bool_set(struct bt_value *bool_obj, bt_bool val) +enum bt_value_status bt_private_value_bool_set(struct bt_private_value *bool_obj, + bt_bool val) { BT_ASSERT_PRE_NON_NULL(bool_obj, "Value object"); BT_ASSERT_PRE_VALUE_IS_TYPE(bool_obj, BT_VALUE_TYPE_BOOL); @@ -782,7 +793,7 @@ enum bt_value_status bt_value_integer_get(const struct bt_value *integer_obj, return BT_VALUE_STATUS_OK; } -enum bt_value_status bt_value_integer_set(struct bt_value *integer_obj, +enum bt_value_status bt_private_integer_bool_set(struct bt_private_value *integer_obj, int64_t val) { BT_ASSERT_PRE_NON_NULL(integer_obj, "Value object"); @@ -804,7 +815,7 @@ enum bt_value_status bt_value_real_get(const struct bt_value *real_obj, return BT_VALUE_STATUS_OK; } -enum bt_value_status bt_value_real_set(struct bt_value *real_obj, +enum bt_value_status bt_private_value_real_set(struct bt_private_value *real_obj, double val) { BT_ASSERT_PRE_NON_NULL(real_obj, "Value object"); @@ -826,7 +837,7 @@ enum bt_value_status bt_value_string_get(const struct bt_value *string_obj, return BT_VALUE_STATUS_OK; } -enum bt_value_status bt_value_string_set(struct bt_value *string_obj, +enum bt_value_status bt_private_value_string_set(struct bt_private_value *string_obj, const char *val) { BT_ASSERT_PRE_NON_NULL(string_obj, "Value object"); @@ -851,7 +862,8 @@ bt_bool bt_value_array_is_empty(const struct bt_value *array_obj) return bt_value_array_get_size(array_obj) == 0; } -struct bt_value *bt_value_array_borrow_element_by_index(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 +876,16 @@ struct bt_value *bt_value_array_borrow_element_by_index(const struct bt_value *a return g_ptr_array_index(typed_array_obj->garray, index); } -enum bt_value_status bt_value_array_append_element(struct bt_value *array_obj, +struct bt_private_value *bt_private_value_array_borrow_element_by_index( + const struct bt_private_value *array_obj, + uint64_t index) +{ + return (void *) bt_value_array_borrow_element_by_index( + (void *) array_obj, index); +} + +enum bt_value_status bt_private_value_array_append_element( + struct bt_private_value *array_obj, struct bt_value *element_obj) { struct bt_value_array *typed_array_obj = @@ -882,79 +903,87 @@ enum bt_value_status bt_value_array_append_element(struct bt_value *array_obj, return BT_VALUE_STATUS_OK; } -enum bt_value_status bt_value_array_append_bool_element(struct bt_value *array_obj, - bt_bool val) +enum bt_value_status bt_private_value_array_append_bool_element( + struct bt_private_value *array_obj, bt_bool val) { enum bt_value_status ret; - struct bt_value *bool_obj = NULL; + struct bt_private_value *bool_obj = NULL; - bool_obj = bt_value_bool_create_init(val); - ret = bt_value_array_append_element(array_obj, bool_obj); + bool_obj = bt_private_value_bool_create_init(val); + ret = bt_private_value_array_append_element(array_obj, + (void *) bool_obj); bt_object_put_ref(bool_obj); return ret; } -enum bt_value_status bt_value_array_append_integer_element( - struct bt_value *array_obj, int64_t val) +enum bt_value_status bt_private_value_array_append_integer_element( + struct bt_private_value *array_obj, int64_t val) { enum bt_value_status ret; - struct bt_value *integer_obj = NULL; + struct bt_private_value *integer_obj = NULL; - integer_obj = bt_value_integer_create_init(val); - ret = bt_value_array_append_element(array_obj, integer_obj); + integer_obj = bt_private_value_integer_create_init(val); + ret = bt_private_value_array_append_element(array_obj, + (void *) integer_obj); bt_object_put_ref(integer_obj); return ret; } -enum bt_value_status bt_value_array_append_real_element(struct bt_value *array_obj, - double val) +enum bt_value_status bt_private_value_array_append_real_element( + struct bt_private_value *array_obj, double val) { enum bt_value_status ret; - struct bt_value *real_obj = NULL; + struct bt_private_value *real_obj = NULL; - real_obj = bt_value_real_create_init(val); - ret = bt_value_array_append_element(array_obj, real_obj); + real_obj = bt_private_value_real_create_init(val); + ret = bt_private_value_array_append_element(array_obj, + (void *) real_obj); bt_object_put_ref(real_obj); return ret; } -enum bt_value_status bt_value_array_append_string_element(struct bt_value *array_obj, - const char *val) +enum bt_value_status bt_private_value_array_append_string_element( + struct bt_private_value *array_obj, const char *val) { enum bt_value_status ret; - struct bt_value *string_obj = NULL; + struct bt_private_value *string_obj = NULL; - string_obj = bt_value_string_create_init(val); - ret = bt_value_array_append_element(array_obj, string_obj); + string_obj = bt_private_value_string_create_init(val); + ret = bt_private_value_array_append_element(array_obj, + (void *) string_obj); bt_object_put_ref(string_obj); return ret; } -enum bt_value_status bt_value_array_append_empty_array_element( - struct bt_value *array_obj) +enum bt_value_status bt_private_value_array_append_empty_array_element( + struct bt_private_value *array_obj) { enum bt_value_status ret; - struct bt_value *empty_array_obj = NULL; + struct bt_private_value *empty_array_obj = NULL; - empty_array_obj = bt_value_array_create(); - ret = bt_value_array_append_element(array_obj, empty_array_obj); + empty_array_obj = bt_private_value_array_create(); + ret = bt_private_value_array_append_element(array_obj, + (void *) empty_array_obj); bt_object_put_ref(empty_array_obj); return ret; } -enum bt_value_status bt_value_array_append_empty_map_element(struct bt_value *array_obj) +enum bt_value_status bt_private_value_array_append_empty_map_element( + struct bt_private_value *array_obj) { enum bt_value_status ret; - struct bt_value *map_obj = NULL; + struct bt_private_value *map_obj = NULL; - map_obj = bt_value_map_create(); - ret = bt_value_array_append_element(array_obj, map_obj); + map_obj = bt_private_value_map_create(); + ret = bt_private_value_array_append_element(array_obj, + (void *) map_obj); bt_object_put_ref(map_obj); return ret; } -enum bt_value_status bt_value_array_set_element_by_index(struct bt_value *array_obj, - uint64_t index, struct bt_value *element_obj) +enum bt_value_status bt_private_value_array_set_element_by_index( + struct bt_private_value *array_obj, uint64_t index, + struct bt_value *element_obj) { struct bt_value_array *typed_array_obj = BT_VALUE_TO_ARRAY(array_obj); @@ -996,6 +1025,12 @@ struct bt_value *bt_value_map_borrow_entry_value(const struct bt_value *map_obj, GUINT_TO_POINTER(g_quark_from_string(key))); } +struct bt_private_value *bt_private_value_map_borrow_entry_value( + const struct bt_private_value *map_obj, const char *key) +{ + return (void *) bt_value_map_borrow_entry_value((void *) map_obj, 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"); @@ -1005,7 +1040,8 @@ bt_bool bt_value_map_has_entry(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_entry(struct bt_value *map_obj, +enum bt_value_status bt_private_value_map_insert_entry( + struct bt_private_value *map_obj, const char *key, struct bt_value *element_obj) { BT_ASSERT_PRE_NON_NULL(map_obj, "Map value object"); @@ -1022,74 +1058,80 @@ enum bt_value_status bt_value_map_insert_entry(struct bt_value *map_obj, return BT_VALUE_STATUS_OK; } -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 bt_private_value_map_insert_bool_entry( + struct bt_private_value *map_obj, const char *key, bt_bool val) { enum bt_value_status ret; - struct bt_value *bool_obj = NULL; + struct bt_private_value *bool_obj = NULL; - bool_obj = bt_value_bool_create_init(val); - ret = bt_value_map_insert_entry(map_obj, key, bool_obj); + bool_obj = bt_private_value_bool_create_init(val); + ret = bt_private_value_map_insert_entry(map_obj, key, + (void *) bool_obj); bt_object_put_ref(bool_obj); return ret; } -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 bt_private_value_map_insert_integer_entry( + struct bt_private_value *map_obj, const char *key, int64_t val) { enum bt_value_status ret; - struct bt_value *integer_obj = NULL; + struct bt_private_value *integer_obj = NULL; - integer_obj = bt_value_integer_create_init(val); - ret = bt_value_map_insert_entry(map_obj, key, integer_obj); + integer_obj = bt_private_value_integer_create_init(val); + ret = bt_private_value_map_insert_entry(map_obj, key, + (void *) integer_obj); bt_object_put_ref(integer_obj); return ret; } -enum bt_value_status bt_value_map_insert_real_entry(struct bt_value *map_obj, - const char *key, double val) +enum bt_value_status bt_private_value_map_insert_real_entry( + struct bt_private_value *map_obj, const char *key, double val) { enum bt_value_status ret; - struct bt_value *real_obj = NULL; + struct bt_private_value *real_obj = NULL; - real_obj = bt_value_real_create_init(val); - ret = bt_value_map_insert_entry(map_obj, key, real_obj); + real_obj = bt_private_value_real_create_init(val); + ret = bt_private_value_map_insert_entry(map_obj, key, + (void *) real_obj); bt_object_put_ref(real_obj); return ret; } -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 bt_private_value_map_insert_string_entry( + struct bt_private_value *map_obj, const char *key, const char *val) { enum bt_value_status ret; - struct bt_value *string_obj = NULL; + struct bt_private_value *string_obj = NULL; - string_obj = bt_value_string_create_init(val); - ret = bt_value_map_insert_entry(map_obj, key, string_obj); + string_obj = bt_private_value_string_create_init(val); + ret = bt_private_value_map_insert_entry(map_obj, key, + (void *) string_obj); bt_object_put_ref(string_obj); return ret; } -enum bt_value_status bt_value_map_insert_empty_array_entry(struct bt_value *map_obj, - const char *key) +enum bt_value_status bt_private_value_map_insert_empty_array_entry( + struct bt_private_value *map_obj, const char *key) { enum bt_value_status ret; - struct bt_value *array_obj = NULL; + struct bt_private_value *array_obj = NULL; - array_obj = bt_value_array_create(); - ret = bt_value_map_insert_entry(map_obj, key, array_obj); + array_obj = bt_private_value_array_create(); + ret = bt_private_value_map_insert_entry(map_obj, key, + (void *) array_obj); bt_object_put_ref(array_obj); return ret; } -enum bt_value_status bt_value_map_insert_empty_map_entry(struct bt_value *map_obj, - const char *key) +enum bt_value_status bt_private_value_map_insert_empty_map_entry( + struct bt_private_value *map_obj, const char *key) { enum bt_value_status ret; - struct bt_value *empty_map_obj = NULL; + struct bt_private_value *empty_map_obj = NULL; - empty_map_obj = bt_value_map_create(); - ret = bt_value_map_insert_entry(map_obj, key, empty_map_obj); + empty_map_obj = bt_private_value_map_create(); + ret = bt_private_value_map_insert_entry(map_obj, key, + (void *) empty_map_obj); bt_object_put_ref(empty_map_obj); return ret; } @@ -1122,8 +1164,16 @@ enum bt_value_status bt_value_map_foreach_entry(const struct bt_value *map_obj, return ret; } +enum bt_value_status bt_private_value_map_foreach_entry( + const struct bt_private_value *map_obj, + bt_private_value_map_foreach_entry_cb cb, void *data) +{ + return bt_value_map_foreach_entry((void *) map_obj, + (bt_value_map_foreach_entry_cb) cb, data); +} + struct extend_map_element_data { - struct bt_value *extended_obj; + struct bt_private_value *extended_obj; bt_bool got_error; }; @@ -1136,12 +1186,12 @@ bt_bool extend_map_element(const char *key, struct extend_map_element_data *extend_data = data; /* Copy object which is to replace the current one */ - struct bt_value *extension_obj_elem_copy = + struct bt_private_value *extension_obj_elem_copy = bt_value_copy(extension_obj_elem); /* Replace in extended object */ - if (bt_value_map_insert_entry(extend_data->extended_obj, key, - extension_obj_elem_copy)) { + if (bt_private_value_map_insert_entry(extend_data->extended_obj, key, + (void *) extension_obj_elem_copy)) { BT_LOGE("Cannot replace value in extended value: key=\"%s\", " "extended-value-addr=%p, element-value-addr=%p", key, extend_data->extended_obj, @@ -1160,10 +1210,10 @@ end: return ret; } -struct bt_value *bt_value_map_extend(struct bt_value *base_map_obj, +struct bt_private_value *bt_value_map_extend(struct bt_value *base_map_obj, struct bt_value *extension_obj) { - struct bt_value *extended_obj = NULL; + struct bt_private_value *extended_obj = NULL; struct extend_map_element_data extend_data = { 0 }; BT_ASSERT_PRE_NON_NULL(base_map_obj, "Base value object"); @@ -1208,12 +1258,12 @@ error: BT_OBJECT_PUT_REF_AND_RESET(extended_obj); end: - return extended_obj; + return (void *) extended_obj; } -struct bt_value *bt_value_copy(const struct bt_value *object) +struct bt_private_value *bt_value_copy(const struct bt_value *object) { - struct bt_value *copy_obj = NULL; + struct bt_private_value *copy_obj = NULL; BT_ASSERT_PRE_NON_NULL(object, "Value object"); BT_LOGD("Copying value object: addr=%p", object); @@ -1225,7 +1275,7 @@ struct bt_value *bt_value_copy(const struct bt_value *object) BT_LOGE_STR("Failed to copy value object."); } - return copy_obj; + return (void *) copy_obj; } bt_bool bt_value_compare(const struct bt_value *object_a, @@ -1241,8 +1291,8 @@ bt_bool bt_value_compare(const struct bt_value *object_a, "value-a-addr=%p, value-b-addr=%p, " "value-a-type=%s, value-b-type=%s", object_a, object_b, - bt_value_type_string(object_a->type), - bt_value_type_string(object_b->type)); + bt_common_value_type_string(object_a->type), + bt_common_value_type_string(object_b->type)); goto end; } @@ -1251,3 +1301,9 @@ bt_bool bt_value_compare(const struct bt_value *object_a, end: return ret; } + +struct bt_value *bt_value_borrow_from_private( + struct bt_private_value *priv_value) +{ + return (void *) priv_value; +} diff --git a/plugins/ctf/fs-src/query.c b/plugins/ctf/fs-src/query.c index 775b071c..eef9e9ee 100644 --- a/plugins/ctf/fs-src/query.c +++ b/plugins/ctf/fs-src/query.c @@ -55,6 +55,7 @@ struct bt_component_class_query_method_return metadata_info_query( .status = BT_QUERY_STATUS_OK, }; + struct bt_private_value *result = NULL; struct bt_value *path_value = NULL; char *metadata_text = NULL; FILE *metadata_fp = NULL; @@ -64,12 +65,13 @@ struct bt_component_class_query_method_return metadata_info_query( const char *path; bool is_packetized; - query_ret.result = bt_value_map_create(); - if (!query_ret.result) { + result = bt_private_value_map_create(); + if (!result) { query_ret.status = BT_QUERY_STATUS_NOMEM; goto error; } + query_ret.result = bt_value_borrow_from_private(result); BT_ASSERT(params); if (!bt_value_is_map(params)) { @@ -148,14 +150,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_entry(query_ret.result, "text", + ret = bt_private_value_map_insert_string_entry(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_entry(query_ret.result, "is-packetized", + ret = bt_private_value_map_insert_bool_entry(result, "is-packetized", is_packetized); if (ret) { BT_LOGE_STR("Cannot insert \"is-packetized\" attribute into query result."); @@ -165,7 +167,8 @@ struct bt_component_class_query_method_return metadata_info_query( goto end; error: - BT_OBJECT_PUT_REF_AND_RESET(query_ret.result); + BT_OBJECT_PUT_REF_AND_RESET(result); + query_ret.result = NULL; if (query_ret.status >= 0) { query_ret.status = BT_QUERY_STATUS_ERROR; @@ -186,50 +189,52 @@ end: } static -int add_range(struct bt_value *info, struct range *range, +int add_range(struct bt_private_value *info, struct range *range, const char *range_name) { int ret = 0; enum bt_value_status status; - struct bt_value *range_map = NULL; + struct bt_private_value *range_map = NULL; if (!range->set) { /* Not an error. */ goto end; } - range_map = bt_value_map_create(); + range_map = bt_private_value_map_create(); if (!range_map) { ret = -1; goto end; } - status = bt_value_map_insert_integer_entry(range_map, "begin", + status = bt_private_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_entry(range_map, "end", + status = bt_private_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_entry(info, range_name, range_map); + status = bt_private_value_map_insert_entry(info, range_name, + bt_value_borrow_from_private(range_map)); if (status != BT_VALUE_STATUS_OK) { ret = -1; goto end; } + end: bt_object_put_ref(range_map); return ret; } static -int add_stream_ids(struct bt_value *info, struct bt_stream *stream) +int add_stream_ids(struct bt_private_value *info, struct bt_stream *stream) { int ret = 0; int64_t stream_class_id, stream_instance_id; @@ -238,7 +243,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_entry(info, "id", + status = bt_private_value_map_insert_integer_entry(info, "id", stream_instance_id); if (status != BT_VALUE_STATUS_OK) { ret = -1; @@ -258,7 +263,7 @@ int add_stream_ids(struct bt_value *info, struct bt_stream *stream) goto end; } - status = bt_value_map_insert_integer_entry(info, "class-id", stream_class_id); + status = bt_private_value_map_insert_integer_entry(info, "class-id", stream_class_id); if (status != BT_VALUE_STATUS_OK) { ret = -1; goto end; @@ -270,18 +275,18 @@ end: static int populate_stream_info(struct ctf_fs_ds_file_group *group, - struct bt_value *group_info, + struct bt_private_value *group_info, struct range *stream_range) { int ret = 0; size_t file_idx; enum bt_value_status status; - struct bt_value *file_paths; + struct bt_private_value *file_paths; stream_range->begin_ns = INT64_MAX; stream_range->end_ns = 0; - file_paths = bt_value_array_create(); + file_paths = bt_private_value_array_create(); if (!file_paths) { ret = -1; goto end; @@ -300,7 +305,7 @@ int populate_stream_info(struct ctf_fs_ds_file_group *group, goto end; } - status = bt_value_array_append_string_element(file_paths, + status = bt_private_value_array_append_string_element(file_paths, info->path->str); if (status != BT_VALUE_STATUS_OK) { ret = -1; @@ -328,7 +333,8 @@ int populate_stream_info(struct ctf_fs_ds_file_group *group, } } - status = bt_value_map_insert_entry(group_info, "paths", file_paths); + status = bt_private_value_map_insert_entry(group_info, "paths", + bt_value_borrow_from_private(file_paths)); if (status != BT_VALUE_STATUS_OK) { ret = -1; goto end; @@ -345,13 +351,13 @@ end: static int populate_trace_info(const char *trace_path, const char *trace_name, - struct bt_value *trace_info) + struct bt_private_value *trace_info) { int ret = 0; size_t group_idx; struct ctf_fs_trace *trace = NULL; enum bt_value_status status; - struct bt_value *file_groups; + struct bt_private_value *file_groups; struct range trace_range = { .begin_ns = INT64_MAX, .end_ns = 0, @@ -363,18 +369,18 @@ int populate_trace_info(const char *trace_path, const char *trace_name, .set = false, }; - file_groups = bt_value_array_create(); + file_groups = bt_private_value_array_create(); if (!file_groups) { goto end; } - status = bt_value_map_insert_string_entry(trace_info, "name", - trace_name); + status = bt_private_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_entry(trace_info, "path", + status = bt_private_value_map_insert_string_entry(trace_info, "path", trace_path); if (status != BT_VALUE_STATUS_OK) { ret = -1; @@ -398,12 +404,12 @@ int populate_trace_info(const char *trace_path, const char *trace_name, /* Find range of all stream groups, and of the trace. */ for (group_idx = 0; group_idx < trace->ds_file_groups->len; group_idx++) { - struct bt_value *group_info; + struct bt_private_value *group_info; struct range group_range = { .set = false }; struct ctf_fs_ds_file_group *group = g_ptr_array_index( trace->ds_file_groups, group_idx); - group_info = bt_value_map_create(); + group_info = bt_private_value_map_create(); if (!group_info) { ret = -1; goto end; @@ -427,7 +433,9 @@ 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_element(file_groups, group_info); + status = bt_private_value_array_append_element( + file_groups, + bt_value_borrow_from_private(group_info)); bt_object_put_ref(group_info); if (status != BT_VALUE_STATUS_OK) { goto end; @@ -448,7 +456,8 @@ int populate_trace_info(const char *trace_path, const char *trace_name, } } - status = bt_value_map_insert_entry(trace_info, "streams", file_groups); + status = bt_private_value_map_insert_entry(trace_info, "streams", + bt_value_borrow_from_private(file_groups)); BT_OBJECT_PUT_REF_AND_RESET(file_groups); if (status != BT_VALUE_STATUS_OK) { ret = -1; @@ -471,6 +480,7 @@ struct bt_component_class_query_method_return trace_info_query( .status = BT_QUERY_STATUS_OK, }; + struct bt_private_value *result = NULL; struct bt_value *path_value = NULL; int ret = 0; const char *path = NULL; @@ -515,12 +525,14 @@ struct bt_component_class_query_method_return trace_info_query( goto error; } - query_ret.result = bt_value_array_create(); - if (!query_ret.result) { + result = bt_private_value_array_create(); + if (!result) { query_ret.status = BT_QUERY_STATUS_NOMEM; goto error; } + query_ret.result = bt_value_borrow_from_private(result); + /* Iterates over both trace paths and names simultaneously. */ for (tp_node = trace_paths, tn_node = trace_names; tp_node; tp_node = g_list_next(tp_node), @@ -528,9 +540,9 @@ struct bt_component_class_query_method_return trace_info_query( GString *trace_path = tp_node->data; GString *trace_name = tn_node->data; enum bt_value_status status; - struct bt_value *trace_info; + struct bt_private_value *trace_info; - trace_info = bt_value_map_create(); + trace_info = bt_private_value_map_create(); if (!trace_info) { BT_LOGE("Failed to create trace info map."); goto error; @@ -543,7 +555,8 @@ struct bt_component_class_query_method_return trace_info_query( goto error; } - status = bt_value_array_append_element(query_ret.result, trace_info); + status = bt_private_value_array_append_element(result, + bt_value_borrow_from_private(trace_info)); bt_object_put_ref(trace_info); if (status != BT_VALUE_STATUS_OK) { goto error; @@ -553,7 +566,8 @@ struct bt_component_class_query_method_return trace_info_query( goto end; error: - BT_OBJECT_PUT_REF_AND_RESET(query_ret.result); + BT_OBJECT_PUT_REF_AND_RESET(result); + query_ret.result = NULL; if (query_ret.status >= 0) { query_ret.status = BT_QUERY_STATUS_ERROR; diff --git a/plugins/ctf/lttng-live/viewer-connection.c b/plugins/ctf/lttng-live/viewer-connection.c index bea4c2ca..79d2c31e 100644 --- a/plugins/ctf/lttng-live/viewer-connection.c +++ b/plugins/ctf/lttng-live/viewer-connection.c @@ -356,7 +356,7 @@ enum bt_value_status list_update_session(struct bt_value *results, } /* sum */ val += streams; - ret = bt_value_integer_set(btval, val); + ret = bt_private_integer_bool_set(btval, val); if (ret != BT_VALUE_STATUS_OK) { goto end; } @@ -373,7 +373,7 @@ enum bt_value_status list_update_session(struct bt_value *results, } /* max */ val = max_t(int64_t, clients, val); - ret = bt_value_integer_set(btval, val); + ret = bt_private_integer_bool_set(btval, val); if (ret != BT_VALUE_STATUS_OK) { goto end; } @@ -416,7 +416,7 @@ enum bt_value_status list_append_session(struct bt_value *results, goto end; } - map = bt_value_map_create(); + map = bt_private_value_map_create(); if (!map) { 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_entry(map, "url", url->str); + ret = bt_private_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_entry(map, "target-hostname", + ret = bt_private_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_entry(map, "session-name", + ret = bt_private_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_entry(map, "timer-us", + ret = bt_private_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_entry(map, "stream-count", + ret = bt_private_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_entry(map, "client-count", + ret = bt_private_value_map_insert_integer_entry(map, "client-count", clients); if (ret != BT_VALUE_STATUS_OK) { goto end; } } - ret = bt_value_array_append_element(results, map); + ret = bt_private_value_array_append_element(results, map); end: if (url) { g_string_free(url, TRUE); @@ -562,7 +562,7 @@ struct bt_value *bt_live_viewer_connection_list_sessions(struct bt_live_viewer_c goto error; } - results = bt_value_array_create(); + results = bt_private_value_array_create(); if (!results) { BT_LOGE("Error creating array"); goto error; diff --git a/plugins/text/dmesg/dmesg.c b/plugins/text/dmesg/dmesg.c index b34c2922..0edc2e61 100644 --- a/plugins/text/dmesg/dmesg.c +++ b/plugins/text/dmesg/dmesg.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -221,7 +222,7 @@ int handle_params(struct dmesg_component *dmesg_comp, struct bt_value *params) if (!bt_value_is_bool(no_timestamp)) { BT_LOGE("Expecting a boolean value for the `no-extract-timestamp` parameter: " "type=%s", - bt_value_type_string( + bt_common_value_type_string( bt_value_get_type(no_timestamp))); goto error; } @@ -241,7 +242,7 @@ int handle_params(struct dmesg_component *dmesg_comp, struct bt_value *params) if (!bt_value_is_string(path)) { BT_LOGE("Expecting a string value for the `path` parameter: " "type=%s", - bt_value_type_string( + bt_common_value_type_string( bt_value_get_type(path))); goto error; } diff --git a/plugins/text/pretty/pretty.c b/plugins/text/pretty/pretty.c index eb68093c..1d3e5ef7 100644 --- a/plugins/text/pretty/pretty.c +++ b/plugins/text/pretty/pretty.c @@ -227,7 +227,8 @@ end: } static -enum bt_component_status add_params_to_map(struct bt_value *plugin_opt_map) +enum bt_component_status add_params_to_map( + struct bt_private_value *plugin_opt_map) { enum bt_component_status ret = BT_COMPONENT_STATUS_OK; unsigned int i; @@ -236,7 +237,8 @@ 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_entry(plugin_opt_map, key, bt_value_null); + status = bt_private_value_map_insert_entry(plugin_opt_map, key, + bt_value_null); switch (status) { case BT_VALUE_STATUS_OK: break; @@ -253,9 +255,10 @@ static 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_entry(plugin_opt_map, key)) { + if (!bt_value_map_has_entry( + bt_value_borrow_from_private(pretty->plugin_opt_map), + key)) { fprintf(pretty->err, "[warning] Parameter \"%s\" unknown to \"text.pretty\" sink component\n", key); } @@ -362,7 +365,7 @@ enum bt_component_status apply_params(struct pretty_component *pretty, bool value, found; char *str = NULL; - pretty->plugin_opt_map = bt_value_map_create(); + pretty->plugin_opt_map = bt_private_value_map_create(); if (!pretty->plugin_opt_map) { ret = BT_COMPONENT_STATUS_ERROR; goto end; diff --git a/plugins/text/pretty/pretty.h b/plugins/text/pretty/pretty.h index d2753bf4..ff573e8b 100644 --- a/plugins/text/pretty/pretty.h +++ b/plugins/text/pretty/pretty.h @@ -80,7 +80,7 @@ struct pretty_component { bool start_line; GString *string; GString *tmp_string; - struct bt_value *plugin_opt_map; /* Temporary parameter map. */ + struct bt_private_value *plugin_opt_map; /* Temporary parameter map. */ bool use_colors; uint64_t last_cycles_timestamp; diff --git a/plugins/utils/muxer/muxer.c b/plugins/utils/muxer/muxer.c index 956e84f5..e146daad 100644 --- a/plugins/utils/muxer/muxer.c +++ b/plugins/utils/muxer/muxer.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -243,18 +244,18 @@ void destroy_muxer_comp(struct muxer_comp *muxer_comp) } static -struct bt_value *get_default_params(void) +struct bt_private_value *get_default_params(void) { - struct bt_value *params; + struct bt_private_value *params; int ret; - params = bt_value_map_create(); + params = bt_private_value_map_create(); if (!params) { BT_LOGE_STR("Cannot create a map value object."); goto error; } - ret = bt_value_map_insert_bool_entry(params, + ret = bt_private_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."); @@ -273,8 +274,8 @@ end: static int configure_muxer_comp(struct muxer_comp *muxer_comp, struct bt_value *params) { - struct bt_value *default_params = NULL; - struct bt_value *real_params = NULL; + struct bt_private_value *default_params = NULL; + struct bt_private_value *real_params = NULL; struct bt_value *assume_absolute_clock_classes = NULL; int ret = 0; bt_bool bool_val; @@ -286,7 +287,8 @@ int configure_muxer_comp(struct muxer_comp *muxer_comp, struct bt_value *params) goto error; } - real_params = bt_value_map_extend(default_params, params); + real_params = bt_value_map_extend( + bt_value_borrow_from_private(default_params), params); if (!real_params) { BT_LOGE("Cannot extend default parameters map value: " "muxer-comp-addr=%p, def-params-addr=%p, " @@ -295,14 +297,15 @@ int configure_muxer_comp(struct muxer_comp *muxer_comp, struct bt_value *params) goto error; } - assume_absolute_clock_classes = bt_value_map_borrow_entry_value(real_params, + assume_absolute_clock_classes = bt_value_map_borrow_entry_value( + bt_value_borrow_from_private(real_params), ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME); if (assume_absolute_clock_classes && !bt_value_is_bool(assume_absolute_clock_classes)) { BT_LOGE("Expecting a boolean value for the `%s` parameter: " "muxer-comp-addr=%p, value-type=%s", ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME, muxer_comp, - bt_value_type_string( + bt_common_value_type_string( bt_value_get_type(assume_absolute_clock_classes))); goto error; } diff --git a/tests/lib/test-plugin-plugins/sfs.c b/tests/lib/test-plugin-plugins/sfs.c index 3c9fbe2d..92ee2ca2 100644 --- a/tests/lib/test-plugin-plugins/sfs.c +++ b/tests/lib/test-plugin-plugins/sfs.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -53,16 +54,17 @@ static struct bt_component_class_query_method_return query_method( struct bt_query_executor *query_exec, const char *object, struct bt_value *params) { + struct bt_private_value *results = bt_private_value_array_create(); struct bt_component_class_query_method_return ret = { .status = BT_QUERY_STATUS_OK, - .result = bt_value_array_create(), + .result = bt_value_borrow_from_private(results), }; int iret; BT_ASSERT(ret.result); - iret = bt_value_array_append_string_element(ret.result, object); + iret = bt_private_value_array_append_string_element(results, object); BT_ASSERT(iret == 0); - iret = bt_value_array_append_element(ret.result, params); + iret = bt_private_value_array_append_element(results, params); BT_ASSERT(iret == 0); return ret; } diff --git a/tests/lib/test_bt_values.c b/tests/lib/test_bt_values.c index e001a7be..f047448b 100644 --- a/tests/lib/test_bt_values.c +++ b/tests/lib/test_bt_values.c @@ -22,6 +22,7 @@ #include #include +#include #include #include #include "tap/tap.h" @@ -45,34 +46,37 @@ void test_bool(void) { int ret; bt_bool value; + struct bt_private_value *priv_obj; struct bt_value *obj; - obj = bt_value_bool_create(); + priv_obj = bt_private_value_bool_create(); + obj = bt_value_borrow_from_private(priv_obj); ok(obj && bt_value_is_bool(obj), - "bt_value_bool_create() returns a boolean value object"); + "bt_private_value_bool_create() returns a boolean value object"); value = BT_TRUE; ret = bt_value_bool_get(obj, &value); ok(!ret && !value, "default boolean value object value is BT_FALSE"); - BT_ASSERT(!bt_value_bool_set(obj, BT_FALSE)); - ret = bt_value_bool_set(obj, BT_TRUE); - ok(!ret, "bt_value_bool_set() succeeds"); + BT_ASSERT(!bt_private_value_bool_set(priv_obj, BT_FALSE)); + ret = bt_private_value_bool_set(priv_obj, BT_TRUE); + ok(!ret, "bt_private_value_bool_set() succeeds"); ret = bt_value_bool_get(obj, &value); - ok(!ret && value, "bt_value_bool_set() works"); + ok(!ret && value, "bt_private_value_bool_set() works"); - BT_OBJECT_PUT_REF_AND_RESET(obj); + BT_OBJECT_PUT_REF_AND_RESET(priv_obj); pass("putting an existing boolean value object does not cause a crash") value = BT_FALSE; - obj = bt_value_bool_create_init(BT_TRUE); + priv_obj = bt_private_value_bool_create_init(BT_TRUE); + obj = bt_value_borrow_from_private(priv_obj); ok(obj && bt_value_is_bool(obj), - "bt_value_bool_create_init() returns a boolean value object"); + "bt_private_value_bool_create_init() returns a boolean value object"); ret = bt_value_bool_get(obj, &value); ok(!ret && value, - "bt_value_bool_create_init() sets the appropriate initial value"); + "bt_private_value_bool_create_init() sets the appropriate initial value"); - BT_OBJECT_PUT_REF_AND_RESET(obj); + BT_OBJECT_PUT_REF_AND_RESET(priv_obj); } static @@ -80,32 +84,35 @@ void test_integer(void) { int ret; int64_t value; + struct bt_private_value *priv_obj; struct bt_value *obj; - obj = bt_value_integer_create(); + priv_obj = bt_private_value_integer_create(); + obj = bt_value_borrow_from_private(priv_obj); ok(obj && bt_value_is_integer(obj), - "bt_value_integer_create() returns an integer value object"); + "bt_private_value_integer_create() returns an integer value object"); value = 1961; ret = bt_value_integer_get(obj, &value); ok(!ret && value == 0, "default integer value object value is 0"); - ret = bt_value_integer_set(obj, -98765); - ok(!ret, "bt_value_integer_set() succeeds"); + ret = bt_private_integer_bool_set(priv_obj, -98765); + ok(!ret, "bt_private_integer_bool_set() succeeds"); ret = bt_value_integer_get(obj, &value); - ok(!ret && value == -98765, "bt_value_integer_set() works"); + ok(!ret && value == -98765, "bt_private_integer_bool_set() works"); - BT_OBJECT_PUT_REF_AND_RESET(obj); + BT_OBJECT_PUT_REF_AND_RESET(priv_obj); pass("putting an existing integer value object does not cause a crash") - obj = bt_value_integer_create_init(321456987); + priv_obj = bt_private_value_integer_create_init(321456987); + obj = bt_value_borrow_from_private(priv_obj); ok(obj && bt_value_is_integer(obj), - "bt_value_integer_create_init() returns an integer value object"); + "bt_private_value_integer_create_init() returns an integer value object"); ret = bt_value_integer_get(obj, &value); ok(!ret && value == 321456987, - "bt_value_integer_create_init() sets the appropriate initial value"); + "bt_private_value_integer_create_init() sets the appropriate initial value"); - BT_OBJECT_PUT_REF_AND_RESET(obj); + BT_OBJECT_PUT_REF_AND_RESET(priv_obj); } static @@ -113,33 +120,36 @@ void test_real(void) { int ret; double value; + struct bt_private_value *priv_obj; struct bt_value *obj; - obj = bt_value_real_create(); + priv_obj = bt_private_value_real_create(); + obj = bt_value_borrow_from_private(priv_obj); ok(obj && bt_value_is_real(obj), - "bt_value_real_create() returns a real number value object"); + "bt_private_value_real_create() returns a real number value object"); value = 17.34; ret = bt_value_real_get(obj, &value); ok(!ret && value == 0., "default real number value object value is 0"); - ret = bt_value_real_set(obj, -3.1416); - ok(!ret, "bt_value_real_set() succeeds"); + ret = bt_private_value_real_set(priv_obj, -3.1416); + ok(!ret, "bt_private_value_real_set() succeeds"); ret = bt_value_real_get(obj, &value); - ok(!ret && value == -3.1416, "bt_value_real_set() works"); + ok(!ret && value == -3.1416, "bt_private_value_real_set() works"); - BT_OBJECT_PUT_REF_AND_RESET(obj); + BT_OBJECT_PUT_REF_AND_RESET(priv_obj); pass("putting an existing real number value object does not cause a crash") - obj = bt_value_real_create_init(33.1649758); + priv_obj = bt_private_value_real_create_init(33.1649758); + obj = bt_value_borrow_from_private(priv_obj); ok(obj && bt_value_is_real(obj), - "bt_value_real_create_init() returns a real number value object"); + "bt_private_value_real_create_init() returns a real number value object"); ret = bt_value_real_get(obj, &value); ok(!ret && value == 33.1649758, - "bt_value_real_create_init() sets the appropriate initial value"); + "bt_private_value_real_create_init() sets the appropriate initial value"); - BT_OBJECT_PUT_REF_AND_RESET(obj); + BT_OBJECT_PUT_REF_AND_RESET(priv_obj); } static @@ -147,33 +157,36 @@ void test_string(void) { int ret; const char *value; + struct bt_private_value *priv_obj; struct bt_value *obj; - obj = bt_value_string_create(); + priv_obj = bt_private_value_string_create(); + obj = bt_value_borrow_from_private(priv_obj); ok(obj && bt_value_is_string(obj), - "bt_value_string_create() returns a string value object"); + "bt_private_value_string_create() returns a string value object"); ret = bt_value_string_get(obj, &value); ok(!ret && value && !strcmp(value, ""), "default string value object value is \"\""); - ret = bt_value_string_set(obj, "hello worldz"); - ok(!ret, "bt_value_string_set() succeeds"); + ret = bt_private_value_string_set(priv_obj, "hello worldz"); + ok(!ret, "bt_private_value_string_set() succeeds"); ret = bt_value_string_get(obj, &value); ok(!ret && value && !strcmp(value, "hello worldz"), "bt_value_string_get() works"); - BT_OBJECT_PUT_REF_AND_RESET(obj); + BT_OBJECT_PUT_REF_AND_RESET(priv_obj); pass("putting an existing string value object does not cause a crash") - obj = bt_value_string_create_init("initial value"); + priv_obj = bt_private_value_string_create_init("initial value"); + obj = bt_value_borrow_from_private(priv_obj); ok(obj && bt_value_is_string(obj), - "bt_value_string_create_init() returns a string value object"); + "bt_private_value_string_create_init() returns a string value object"); ret = bt_value_string_get(obj, &value); ok(!ret && value && !strcmp(value, "initial value"), - "bt_value_string_create_init() sets the appropriate initial value"); + "bt_private_value_string_create_init() sets the appropriate initial value"); - BT_OBJECT_PUT_REF_AND_RESET(obj); + BT_OBJECT_PUT_REF_AND_RESET(priv_obj); } static @@ -183,27 +196,34 @@ void test_array(void) bt_bool bool_value; int64_t int_value; double real_value; + struct bt_private_value *priv_obj; struct bt_value *obj; const char *string_value; + struct bt_private_value *priv_array_obj; struct bt_value *array_obj; - array_obj = bt_value_array_create(); + priv_array_obj = bt_private_value_array_create(); + array_obj = bt_value_borrow_from_private(priv_array_obj); ok(array_obj && bt_value_is_array(array_obj), - "bt_value_array_create() returns an array value object"); + "bt_private_value_array_create() returns an array value object"); ok(bt_value_array_is_empty(array_obj), "initial array value object size is 0"); - obj = bt_value_integer_create_init(345); - ret = bt_value_array_append_element(array_obj, obj); - BT_OBJECT_PUT_REF_AND_RESET(obj); - obj = bt_value_real_create_init(-17.45); - ret |= bt_value_array_append_element(array_obj, obj); - BT_OBJECT_PUT_REF_AND_RESET(obj); - obj = bt_value_bool_create_init(BT_TRUE); - ret |= bt_value_array_append_element(array_obj, obj); - BT_OBJECT_PUT_REF_AND_RESET(obj); - ret |= bt_value_array_append_element(array_obj, bt_value_null); - ok(!ret, "bt_value_array_append_element() succeeds"); + priv_obj = bt_private_value_integer_create_init(345); + obj = bt_value_borrow_from_private(priv_obj); + ret = bt_private_value_array_append_element(priv_array_obj, obj); + BT_OBJECT_PUT_REF_AND_RESET(priv_obj); + priv_obj = bt_private_value_real_create_init(-17.45); + obj = bt_value_borrow_from_private(priv_obj); + ret |= bt_private_value_array_append_element(priv_array_obj, obj); + BT_OBJECT_PUT_REF_AND_RESET(priv_obj); + priv_obj = bt_private_value_bool_create_init(BT_TRUE); + obj = bt_value_borrow_from_private(priv_obj); + ret |= bt_private_value_array_append_element(priv_array_obj, obj); + BT_OBJECT_PUT_REF_AND_RESET(priv_obj); + ret |= bt_private_value_array_append_element(priv_array_obj, + bt_value_null); + ok(!ret, "bt_private_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"); @@ -229,11 +249,12 @@ void test_array(void) ok(obj == bt_value_null, "bt_value_array_borrow_element_by_index() returns an value object with the appropriate type (null)"); - obj = bt_value_integer_create_init(1001); + priv_obj = bt_private_value_integer_create_init(1001); + obj = bt_value_borrow_from_private(priv_obj); BT_ASSERT(obj); - ok(!bt_value_array_set_element_by_index(array_obj, 2, obj), + ok(!bt_private_value_array_set_element_by_index(priv_array_obj, 2, obj), "bt_value_array_set_element_by_index() succeeds"); - BT_OBJECT_PUT_REF_AND_RESET(obj); + BT_OBJECT_PUT_REF_AND_RESET(priv_obj); obj = bt_value_array_borrow_element_by_index(array_obj, 2); ok(obj && bt_value_is_integer(obj), "bt_value_array_set_element_by_index() inserts an value object with the appropriate type"); @@ -242,60 +263,64 @@ void test_array(void) ok(int_value == 1001, "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"); + ret = bt_private_value_array_append_bool_element(priv_array_obj, + BT_FALSE); + ok(!ret, "bt_private_value_array_append_bool_element() succeeds"); + ret = bt_private_value_array_append_integer_element(priv_array_obj, + 98765); + ok(!ret, "bt_private_value_array_append_integer_element() succeeds"); + ret = bt_private_value_array_append_real_element(priv_array_obj, + 2.49578); + ok(!ret, "bt_private_value_array_append_real_element() succeeds"); + ret = bt_private_value_array_append_string_element(priv_array_obj, + "bt_value"); + ok(!ret, "bt_private_value_array_append_string_element() succeeds"); + ret = bt_private_value_array_append_empty_array_element(priv_array_obj); + ok(!ret, "bt_private_value_array_append_empty_array_element() succeeds"); + ret = bt_private_value_array_append_empty_map_element(priv_array_obj); + ok(!ret, "bt_private_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"); + "the bt_private_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_borrow_element_by_index(array_obj, 4); ok(obj && bt_value_is_bool(obj), - "bt_value_array_append_bool_element() appends a boolean value object"); + "bt_private_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_element() appends the appropriate value"); + "bt_private_value_array_append_bool_element() appends the appropriate value"); obj = bt_value_array_borrow_element_by_index(array_obj, 5); ok(obj && bt_value_is_integer(obj), - "bt_value_array_append_integer_element() appends an integer value object"); + "bt_private_value_array_append_integer_element() appends an integer value object"); ret = bt_value_integer_get(obj, &int_value); ok(!ret && int_value == 98765, - "bt_value_array_append_integer_element() appends the appropriate value"); + "bt_private_value_array_append_integer_element() appends the appropriate value"); obj = bt_value_array_borrow_element_by_index(array_obj, 6); ok(obj && bt_value_is_real(obj), - "bt_value_array_append_real_element() appends a real number value object"); + "bt_private_value_array_append_real_element() appends a real number value object"); ret = bt_value_real_get(obj, &real_value); ok(!ret && real_value == 2.49578, - "bt_value_array_append_real_element() appends the appropriate value"); + "bt_private_value_array_append_real_element() appends the appropriate value"); obj = bt_value_array_borrow_element_by_index(array_obj, 7); ok(obj && bt_value_is_string(obj), - "bt_value_array_append_string_element() appends a string value object"); + "bt_private_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_element() appends the appropriate value"); + "bt_private_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_element() appends an array value object"); + "bt_private_value_array_append_empty_array_element() appends an array value object"); ok(bt_value_array_is_empty(obj), - "bt_value_array_append_empty_array_element() an empty array value object"); + "bt_private_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_element() appends a map value object"); + "bt_private_value_array_append_empty_map_element() appends a map value object"); ok(bt_value_map_is_empty(obj), - "bt_value_array_append_empty_map_element() an empty map value object"); + "bt_private_value_array_append_empty_map_element() an empty map value object"); - BT_OBJECT_PUT_REF_AND_RESET(array_obj); + BT_OBJECT_PUT_REF_AND_RESET(priv_array_obj); pass("putting an existing array value object does not cause a crash") } @@ -472,7 +497,8 @@ bt_bool test_map_foreach_cb_check(const char *key, struct bt_value *object, checklist->map2 = BT_TRUE; } } else { - fail("test_map_foreach_cb_check(): unknown map key \"%s\"", key); + fail("test_map_foreach_cb_check(): unknown map key \"%s\"", + key); } return BT_TRUE; @@ -486,34 +512,42 @@ void test_map(void) bt_bool bool_value; int64_t int_value; double real_value; + struct bt_private_value *priv_obj; struct bt_value *obj; + struct bt_private_value *priv_map_obj; struct bt_value *map_obj; struct map_foreach_checklist checklist; - map_obj = bt_value_map_create(); + priv_map_obj = bt_private_value_map_create(); + map_obj = bt_value_borrow_from_private(priv_map_obj); ok(map_obj && bt_value_is_map(map_obj), - "bt_value_map_create() returns a map value object"); + "bt_private_value_map_create() returns a map value object"); 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_entry(map_obj, "int", obj); - BT_OBJECT_PUT_REF_AND_RESET(obj); - obj = bt_value_real_create_init(5.444); - ret |= bt_value_map_insert_entry(map_obj, "real", obj); - BT_OBJECT_PUT_REF_AND_RESET(obj); - obj = bt_value_bool_create(); - ret |= bt_value_map_insert_entry(map_obj, "bt_bool", obj); - BT_OBJECT_PUT_REF_AND_RESET(obj); - ret |= bt_value_map_insert_entry(map_obj, "null", bt_value_null); - ok(!ret, "bt_value_map_insert_entry() succeeds"); + priv_obj = bt_private_value_integer_create_init(19457); + obj = bt_value_borrow_from_private(priv_obj); + ret = bt_private_value_map_insert_entry(priv_map_obj, "int", obj); + BT_OBJECT_PUT_REF_AND_RESET(priv_obj); + priv_obj = bt_private_value_real_create_init(5.444); + obj = bt_value_borrow_from_private(priv_obj); + ret |= bt_private_value_map_insert_entry(priv_map_obj, "real", obj); + BT_OBJECT_PUT_REF_AND_RESET(priv_obj); + priv_obj = bt_private_value_bool_create(); + obj = bt_value_borrow_from_private(priv_obj); + ret |= bt_private_value_map_insert_entry(priv_map_obj, "bt_bool", obj); + BT_OBJECT_PUT_REF_AND_RESET(priv_obj); + ret |= bt_private_value_map_insert_entry(priv_map_obj, "null", + bt_value_null); + ok(!ret, "bt_private_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_entry(map_obj, "bt_bool", obj); - BT_OBJECT_PUT_REF_AND_RESET(obj); - ok(!ret, "bt_value_map_insert_entry() accepts an existing key"); + priv_obj = bt_private_value_bool_create_init(BT_TRUE); + obj = bt_value_borrow_from_private(priv_obj); + ret = bt_private_value_map_insert_entry(priv_map_obj, "bt_bool", obj); + BT_OBJECT_PUT_REF_AND_RESET(priv_obj); + ok(!ret, "bt_private_value_map_insert_entry() accepts an existing key"); 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"); @@ -539,18 +573,23 @@ void test_map(void) ok(!ret && bool_value, "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"); + ret = bt_private_value_map_insert_bool_entry(priv_map_obj, "bool2", + BT_TRUE); + ok(!ret, "bt_private_value_map_insert_bool_entry() succeeds"); + ret = bt_private_value_map_insert_integer_entry(priv_map_obj, "int2", + 98765); + ok(!ret, "bt_private_value_map_insert_integer_entry() succeeds"); + ret = bt_private_value_map_insert_real_entry(priv_map_obj, "real2", + -49.0001); + ok(!ret, "bt_private_value_map_insert_real_entry() succeeds"); + ret = bt_private_value_map_insert_string_entry(priv_map_obj, "string2", + "bt_value"); + ok(!ret, "bt_private_value_map_insert_string_entry() succeeds"); + ret = bt_private_value_map_insert_empty_array_entry(priv_map_obj, + "array2"); + ok(!ret, "bt_private_value_map_insert_empty_array_entry() succeeds"); + ret = bt_private_value_map_insert_empty_map_entry(priv_map_obj, "map2"); + ok(!ret, "bt_private_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"); @@ -578,7 +617,8 @@ void test_map(void) ok(bt_value_map_has_entry(map_obj, "map2"), "map value object has key \"map2\""); - ret = bt_value_map_foreach_entry(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_entry() breaks the loop when the user function returns BT_FALSE"); @@ -593,7 +633,7 @@ void test_map(void) checklist.array2 && checklist.map2, "bt_value_map_foreach_entry() iterates over all the map value object's elements"); - BT_OBJECT_PUT_REF_AND_RESET(map_obj); + BT_OBJECT_PUT_REF_AND_RESET(priv_map_obj); pass("putting an existing map value object does not cause a crash") } @@ -619,16 +659,22 @@ void test_compare_null(void) static void test_compare_bool(void) { - struct bt_value *bool1 = bt_value_bool_create_init(BT_FALSE); - struct bt_value *bool2 = bt_value_bool_create_init(BT_TRUE); - struct bt_value *bool3 = bt_value_bool_create_init(BT_FALSE); + struct bt_private_value *bool1 = + bt_private_value_bool_create_init(BT_FALSE); + struct bt_private_value *bool2 = + bt_private_value_bool_create_init(BT_TRUE); + struct bt_private_value *bool3 = + bt_private_value_bool_create_init(BT_FALSE); BT_ASSERT(bool1 && bool2 && bool3); - ok(!bt_value_compare(bt_value_null, bool1), + ok(!bt_value_compare(bt_value_null, + bt_value_borrow_from_private(bool1)), "cannot compare null value object and bt_bool value object"); - ok(!bt_value_compare(bool1, bool2), + ok(!bt_value_compare(bt_value_borrow_from_private(bool1), + bt_value_borrow_from_private(bool2)), "boolean value objects are not equivalent (BT_FALSE and BT_TRUE)"); - ok(bt_value_compare(bool1, bool3), + ok(bt_value_compare(bt_value_borrow_from_private(bool1), + bt_value_borrow_from_private(bool3)), "boolean value objects are equivalent (BT_FALSE and BT_FALSE)"); BT_OBJECT_PUT_REF_AND_RESET(bool1); @@ -639,16 +685,22 @@ void test_compare_bool(void) static void test_compare_integer(void) { - struct bt_value *int1 = bt_value_integer_create_init(10); - struct bt_value *int2 = bt_value_integer_create_init(-23); - struct bt_value *int3 = bt_value_integer_create_init(10); + struct bt_private_value *int1 = + bt_private_value_integer_create_init(10); + struct bt_private_value *int2 = + bt_private_value_integer_create_init(-23); + struct bt_private_value *int3 = + bt_private_value_integer_create_init(10); BT_ASSERT(int1 && int2 && int3); - ok(!bt_value_compare(bt_value_null, int1), + ok(!bt_value_compare(bt_value_null, + bt_value_borrow_from_private(int1)), "cannot compare null value object and integer value object"); - ok(!bt_value_compare(int1, int2), + ok(!bt_value_compare(bt_value_borrow_from_private(int1), + bt_value_borrow_from_private(int2)), "integer value objects are not equivalent (10 and -23)"); - ok(bt_value_compare(int1, int3), + ok(bt_value_compare(bt_value_borrow_from_private(int1), + bt_value_borrow_from_private(int3)), "integer value objects are equivalent (10 and 10)"); BT_OBJECT_PUT_REF_AND_RESET(int1); @@ -659,17 +711,23 @@ void test_compare_integer(void) static void test_compare_real(void) { - struct bt_value *real1 = bt_value_real_create_init(17.38); - struct bt_value *real2 = bt_value_real_create_init(-14.23); - struct bt_value *real3 = bt_value_real_create_init(17.38); + struct bt_private_value *real1 = + bt_private_value_real_create_init(17.38); + struct bt_private_value *real2 = + bt_private_value_real_create_init(-14.23); + struct bt_private_value *real3 = + bt_private_value_real_create_init(17.38); BT_ASSERT(real1 && real2 && real3); - ok(!bt_value_compare(bt_value_null, real1), + ok(!bt_value_compare(bt_value_null, + bt_value_borrow_from_private(real1)), "cannot compare null value object and real number value object"); - ok(!bt_value_compare(real1, real2), + ok(!bt_value_compare(bt_value_borrow_from_private(real1), + bt_value_borrow_from_private(real2)), "real number value objects are not equivalent (17.38 and -14.23)"); - ok(bt_value_compare(real1, real3), + ok(bt_value_compare(bt_value_borrow_from_private(real1), + bt_value_borrow_from_private(real3)), "real number value objects are equivalent (17.38 and 17.38)"); BT_OBJECT_PUT_REF_AND_RESET(real1); @@ -680,17 +738,23 @@ void test_compare_real(void) static void test_compare_string(void) { - struct bt_value *string1 = bt_value_string_create_init("hello"); - struct bt_value *string2 = bt_value_string_create_init("bt_value"); - struct bt_value *string3 = bt_value_string_create_init("hello"); + struct bt_private_value *string1 = + bt_private_value_string_create_init("hello"); + struct bt_private_value *string2 = + bt_private_value_string_create_init("bt_value"); + struct bt_private_value *string3 = + bt_private_value_string_create_init("hello"); BT_ASSERT(string1 && string2 && string3); - ok(!bt_value_compare(bt_value_null, string1), + ok(!bt_value_compare(bt_value_null, + bt_value_borrow_from_private(string1)), "cannot compare null value object and string value object"); - ok(!bt_value_compare(string1, string2), + ok(!bt_value_compare(bt_value_borrow_from_private(string1), + bt_value_borrow_from_private(string2)), "string value objects are not equivalent (\"hello\" and \"bt_value\")"); - ok(bt_value_compare(string1, string3), + ok(bt_value_compare(bt_value_borrow_from_private(string1), + bt_value_borrow_from_private(string3)), "string value objects are equivalent (\"hello\" and \"hello\")"); BT_OBJECT_PUT_REF_AND_RESET(string1); @@ -701,33 +765,50 @@ void test_compare_string(void) static void test_compare_array(void) { - struct bt_value *array1 = bt_value_array_create(); - struct bt_value *array2 = bt_value_array_create(); - struct bt_value *array3 = bt_value_array_create(); + struct bt_private_value *array1 = bt_private_value_array_create(); + struct bt_private_value *array2 = bt_private_value_array_create(); + struct bt_private_value *array3 = bt_private_value_array_create(); + enum bt_value_status status; BT_ASSERT(array1 && array2 && array3); - ok(bt_value_compare(array1, array2), + ok(bt_value_compare(bt_value_borrow_from_private(array1), + bt_value_borrow_from_private(array2)), "empty array value objects are equivalent"); - 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), + status = bt_private_value_array_append_integer_element(array1, 23); + BT_ASSERT(status == BT_VALUE_STATUS_OK); + status = bt_private_value_array_append_real_element(array1, 14.2); + BT_ASSERT(status == BT_VALUE_STATUS_OK); + status = bt_private_value_array_append_bool_element(array1, BT_FALSE); + BT_ASSERT(status == BT_VALUE_STATUS_OK); + status = bt_private_value_array_append_real_element(array2, 14.2); + BT_ASSERT(status == BT_VALUE_STATUS_OK); + status = bt_private_value_array_append_integer_element(array2, 23); + BT_ASSERT(status == BT_VALUE_STATUS_OK); + status = bt_private_value_array_append_bool_element(array2, BT_FALSE); + BT_ASSERT(status == BT_VALUE_STATUS_OK); + status = bt_private_value_array_append_integer_element(array3, 23); + BT_ASSERT(status == BT_VALUE_STATUS_OK); + status = bt_private_value_array_append_real_element(array3, 14.2); + BT_ASSERT(status == BT_VALUE_STATUS_OK); + status = bt_private_value_array_append_bool_element(array3, BT_FALSE); + BT_ASSERT(status == BT_VALUE_STATUS_OK); + BT_ASSERT(bt_value_array_get_size( + bt_value_borrow_from_private(array1)) == 3); + BT_ASSERT(bt_value_array_get_size( + bt_value_borrow_from_private(array2)) == 3); + BT_ASSERT(bt_value_array_get_size( + bt_value_borrow_from_private(array3)) == 3); + + ok(!bt_value_compare(bt_value_null, + bt_value_borrow_from_private(array1)), "cannot compare null value object and array value object"); - ok(!bt_value_compare(array1, array2), + ok(!bt_value_compare(bt_value_borrow_from_private(array1), + bt_value_borrow_from_private(array2)), "array value objects are not equivalent ([23, 14.2, BT_FALSE] and [14.2, 23, BT_FALSE])"); - ok(bt_value_compare(array1, array3), + ok(bt_value_compare(bt_value_borrow_from_private(array1), + bt_value_borrow_from_private(array3)), "array value objects are equivalent ([23, 14.2, BT_FALSE] and [23, 14.2, BT_FALSE])"); BT_OBJECT_PUT_REF_AND_RESET(array1); @@ -738,33 +819,54 @@ void test_compare_array(void) static void test_compare_map(void) { - struct bt_value *map1 = bt_value_map_create(); - struct bt_value *map2 = bt_value_map_create(); - struct bt_value *map3 = bt_value_map_create(); + struct bt_private_value *map1 = bt_private_value_map_create(); + struct bt_private_value *map2 = bt_private_value_map_create(); + struct bt_private_value *map3 = bt_private_value_map_create(); + enum bt_value_status status; BT_ASSERT(map1 && map2 && map3); - ok(bt_value_compare(map1, map2), + ok(bt_value_compare(bt_value_borrow_from_private(map1), + bt_value_borrow_from_private(map2)), "empty map value objects are equivalent"); - 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), + + status = bt_private_value_map_insert_integer_entry(map1, "one", 23); + BT_ASSERT(status == BT_VALUE_STATUS_OK); + status = bt_private_value_map_insert_real_entry(map1, "two", 14.2); + BT_ASSERT(status == BT_VALUE_STATUS_OK); + status = bt_private_value_map_insert_bool_entry(map1, "three", + BT_FALSE); + BT_ASSERT(status == BT_VALUE_STATUS_OK); + status = bt_private_value_map_insert_real_entry(map2, "one", 14.2); + BT_ASSERT(status == BT_VALUE_STATUS_OK); + status = bt_private_value_map_insert_integer_entry(map2, "two", 23); + BT_ASSERT(status == BT_VALUE_STATUS_OK); + status = bt_private_value_map_insert_bool_entry(map2, "three", + BT_FALSE); + BT_ASSERT(status == BT_VALUE_STATUS_OK); + status = bt_private_value_map_insert_bool_entry(map3, "three", + BT_FALSE); + BT_ASSERT(status == BT_VALUE_STATUS_OK); + status = bt_private_value_map_insert_integer_entry(map3, "one", 23); + BT_ASSERT(status == BT_VALUE_STATUS_OK); + status = bt_private_value_map_insert_real_entry(map3, "two", 14.2); + BT_ASSERT(status == BT_VALUE_STATUS_OK); + BT_ASSERT(bt_value_map_get_size( + bt_value_borrow_from_private(map1)) == 3); + BT_ASSERT(bt_value_map_get_size( + bt_value_borrow_from_private(map2)) == 3); + BT_ASSERT(bt_value_map_get_size( + bt_value_borrow_from_private(map3)) == 3); + + ok(!bt_value_compare(bt_value_null, + bt_value_borrow_from_private(map1)), "cannot compare null value object and map value object"); - ok(!bt_value_compare(map1, map2), + ok(!bt_value_compare(bt_value_borrow_from_private(map1), + bt_value_borrow_from_private(map2)), "map value objects are not equivalent"); - ok(bt_value_compare(map1, map3), + ok(bt_value_compare(bt_value_borrow_from_private(map1), + bt_value_borrow_from_private(map3)), "map value objects are equivalent"); BT_OBJECT_PUT_REF_AND_RESET(map1); @@ -795,57 +897,77 @@ void test_copy(void) * bt_value_compare() elsewhere, then the deep copy is a * success. */ - struct bt_value *null_copy_obj; - struct bt_value *bool_obj, *bool_copy_obj; - struct bt_value *integer_obj, *integer_copy_obj; - struct bt_value *real_obj, *real_copy_obj; - struct bt_value *string_obj, *string_copy_obj; - struct bt_value *array_obj, *array_copy_obj; - struct bt_value *map_obj, *map_copy_obj; - - bool_obj = bt_value_bool_create_init(BT_TRUE); - integer_obj = bt_value_integer_create_init(23); - real_obj = bt_value_real_create_init(-3.1416); - string_obj = bt_value_string_create_init("test"); - array_obj = bt_value_array_create(); - map_obj = bt_value_map_create(); + struct bt_private_value *null_copy_obj; + struct bt_private_value *bool_obj, *bool_copy_obj; + struct bt_private_value *integer_obj, *integer_copy_obj; + struct bt_private_value *real_obj, *real_copy_obj; + struct bt_private_value *string_obj, *string_copy_obj; + struct bt_private_value *array_obj, *array_copy_obj; + struct bt_private_value *map_obj, *map_copy_obj; + enum bt_value_status status; + + bool_obj = bt_private_value_bool_create_init(BT_TRUE); + integer_obj = bt_private_value_integer_create_init(23); + real_obj = bt_private_value_real_create_init(-3.1416); + string_obj = bt_private_value_string_create_init("test"); + array_obj = bt_private_value_array_create(); + map_obj = bt_private_value_map_create(); BT_ASSERT(bool_obj && integer_obj && real_obj && string_obj && array_obj && map_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)); + status = bt_private_value_array_append_element(array_obj, + bt_value_borrow_from_private(bool_obj)); + BT_ASSERT(status == BT_VALUE_STATUS_OK); + status = bt_private_value_array_append_element(array_obj, + bt_value_borrow_from_private(integer_obj)); + BT_ASSERT(status == BT_VALUE_STATUS_OK); + status = bt_private_value_array_append_element(array_obj, + bt_value_borrow_from_private(real_obj)); + BT_ASSERT(status == BT_VALUE_STATUS_OK); + status = bt_private_value_array_append_element(array_obj, + bt_value_null); + BT_ASSERT(status == BT_VALUE_STATUS_OK); + status = bt_private_value_map_insert_entry(map_obj, "array", + bt_value_borrow_from_private(array_obj)); + BT_ASSERT(status == BT_VALUE_STATUS_OK); + status = bt_private_value_map_insert_entry(map_obj, "string", + bt_value_borrow_from_private(string_obj)); + BT_ASSERT(status == BT_VALUE_STATUS_OK); - map_copy_obj = bt_value_copy(map_obj); + map_copy_obj = bt_value_copy(bt_value_borrow_from_private(map_obj)); ok(map_copy_obj, "bt_value_copy() succeeds"); ok(map_obj != map_copy_obj, "bt_value_copy() returns a different pointer (map)"); - string_copy_obj = bt_value_map_borrow_entry_value(map_copy_obj, "string"); + string_copy_obj = bt_private_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_borrow_entry_value(map_copy_obj, "array"); + array_copy_obj = bt_private_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_borrow_element_by_index(array_copy_obj, 0); + bool_copy_obj = bt_private_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_borrow_element_by_index(array_copy_obj, 1); + integer_copy_obj = bt_private_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_borrow_element_by_index(array_copy_obj, 2); + real_copy_obj = bt_private_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_borrow_element_by_index(array_copy_obj, 3); - ok(null_copy_obj == bt_value_null, + null_copy_obj = bt_private_value_array_borrow_element_by_index( + array_copy_obj, 3); + ok(bt_value_borrow_from_private(null_copy_obj) == bt_value_null, "bt_value_copy() returns the same pointer (null)"); - ok(bt_value_compare(map_obj, map_copy_obj), + ok(bt_value_compare(bt_value_borrow_from_private(map_obj), + bt_value_borrow_from_private(map_copy_obj)), "source and destination value objects have the same content"); BT_OBJECT_PUT_REF_AND_RESET(map_copy_obj); @@ -874,42 +996,57 @@ bt_bool compare_map_elements(struct bt_value *map_a, struct bt_value *map_b, static void test_extend(void) { - struct bt_value *base_map = bt_value_map_create(); - struct bt_value *extension_map = bt_value_map_create(); - struct bt_value *extended_map = NULL; - struct bt_value *array = bt_value_array_create(); + struct bt_private_value *base_map = bt_private_value_map_create(); + struct bt_private_value *extension_map = bt_private_value_map_create(); + struct bt_private_value *extended_map = NULL; + struct bt_private_value *array = bt_private_value_array_create(); enum bt_value_status status; BT_ASSERT(base_map); BT_ASSERT(extension_map); BT_ASSERT(array); - status = bt_value_map_insert_bool_entry(base_map, "file", BT_TRUE); + status = bt_private_value_map_insert_bool_entry(base_map, "file", + BT_TRUE); BT_ASSERT(status == BT_VALUE_STATUS_OK); - status = bt_value_map_insert_bool_entry(base_map, "edit", BT_FALSE); + status = bt_private_value_map_insert_bool_entry(base_map, "edit", + BT_FALSE); BT_ASSERT(status == BT_VALUE_STATUS_OK); - status = bt_value_map_insert_integer_entry(base_map, "selection", 17); + status = bt_private_value_map_insert_integer_entry(base_map, + "selection", 17); BT_ASSERT(status == BT_VALUE_STATUS_OK); - status = bt_value_map_insert_integer_entry(base_map, "find", -34); + status = bt_private_value_map_insert_integer_entry(base_map, "find", + -34); BT_ASSERT(status == BT_VALUE_STATUS_OK); - status = bt_value_map_insert_bool_entry(extension_map, "edit", BT_TRUE); + status = bt_private_value_map_insert_bool_entry(extension_map, "edit", + BT_TRUE); BT_ASSERT(status == BT_VALUE_STATUS_OK); - status = bt_value_map_insert_integer_entry(extension_map, "find", 101); + status = bt_private_value_map_insert_integer_entry(extension_map, + "find", 101); BT_ASSERT(status == BT_VALUE_STATUS_OK); - status = bt_value_map_insert_real_entry(extension_map, "project", -404); + status = bt_private_value_map_insert_real_entry(extension_map, + "project", -404); BT_ASSERT(status == BT_VALUE_STATUS_OK); - extended_map = bt_value_map_extend(base_map, extension_map); + extended_map = bt_value_map_extend( + bt_value_borrow_from_private(base_map), + bt_value_borrow_from_private(extension_map)); ok(extended_map, "bt_value_map_extend() succeeds"); - ok(bt_value_map_get_size(extended_map) == 5, + ok(bt_value_map_get_size( + bt_value_borrow_from_private(extended_map)) == 5, "bt_value_map_extend() returns a map object with the correct size"); - ok(compare_map_elements(base_map, extended_map, "file"), + ok(compare_map_elements(bt_value_borrow_from_private(base_map), + bt_value_borrow_from_private(extended_map), "file"), "bt_value_map_extend() picks the appropriate element (file)"); - ok(compare_map_elements(extension_map, extended_map, "edit"), + ok(compare_map_elements(bt_value_borrow_from_private(extension_map), + bt_value_borrow_from_private(extended_map), "edit"), "bt_value_map_extend() picks the appropriate element (edit)"); - ok(compare_map_elements(base_map, extended_map, "selection"), + ok(compare_map_elements(bt_value_borrow_from_private(base_map), + bt_value_borrow_from_private(extended_map), "selection"), "bt_value_map_extend() picks the appropriate element (selection)"); - ok(compare_map_elements(extension_map, extended_map, "find"), + ok(compare_map_elements(bt_value_borrow_from_private(extension_map), + bt_value_borrow_from_private(extended_map), "find"), "bt_value_map_extend() picks the appropriate element (find)"); - ok(compare_map_elements(extension_map, extended_map, "project"), + ok(compare_map_elements(bt_value_borrow_from_private(extension_map), + bt_value_borrow_from_private(extended_map), "project"), "bt_value_map_extend() picks the appropriate element (project)"); BT_OBJECT_PUT_REF_AND_RESET(array); diff --git a/tests/lib/test_ctf_writer.c b/tests/lib/test_ctf_writer.c index 39cc888e..8be17894 100644 --- a/tests/lib/test_ctf_writer.c +++ b/tests/lib/test_ctf_writer.c @@ -57,7 +57,7 @@ #define DEFAULT_CLOCK_TIME 0 #define DEFAULT_CLOCK_VALUE 0 -#define NR_TESTS 342 +#define NR_TESTS 335 struct bt_utsname { char sysname[BABELTRACE_HOST_NAME_MAX]; @@ -1667,26 +1667,6 @@ int main(int argc, char **argv) NULL), "bt_ctf_writer_add_environment_field error with NULL field value"); - /* Test bt_ctf_trace_set_environment_field with an integer object */ - obj = bt_value_integer_create_init(23); - BT_ASSERT(obj); - ok(bt_ctf_trace_set_environment_field(NULL, "test_env_int_obj", obj), - "bt_ctf_trace_set_environment_field handles a NULL trace correctly"); - ok(bt_ctf_trace_set_environment_field(trace, NULL, obj), - "bt_ctf_trace_set_environment_field handles a NULL name correctly"); - ok(bt_ctf_trace_set_environment_field(trace, "test_env_int_obj", NULL), - "bt_ctf_trace_set_environment_field handles a NULL value correctly"); - ok(!bt_ctf_trace_set_environment_field(trace, "test_env_int_obj", obj), - "bt_ctf_trace_set_environment_field succeeds in adding an integer object"); - BT_OBJECT_PUT_REF_AND_RESET(obj); - - /* Test bt_ctf_trace_set_environment_field with a string object */ - obj = bt_value_string_create_init("the value"); - BT_ASSERT(obj); - ok(!bt_ctf_trace_set_environment_field(trace, "test_env_str_obj", obj), - "bt_ctf_trace_set_environment_field succeeds in adding a string object"); - BT_OBJECT_PUT_REF_AND_RESET(obj); - /* Test bt_ctf_trace_set_environment_field_integer */ ok(bt_ctf_trace_set_environment_field_integer(NULL, "test_env_int", -194875), @@ -1711,7 +1691,7 @@ int main(int argc, char **argv) "bt_ctf_trace_set_environment_field_string succeeds"); /* Test bt_ctf_trace_get_environment_field_count */ - ok(bt_ctf_trace_get_environment_field_count(trace) == 5, + ok(bt_ctf_trace_get_environment_field_count(trace) == 3, "bt_ctf_trace_get_environment_field_count returns a correct number of environment fields"); /* Test bt_ctf_trace_get_environment_field_name */ @@ -1719,27 +1699,21 @@ int main(int argc, char **argv) ok(ret_string && !strcmp(ret_string, "host"), "bt_ctf_trace_get_environment_field_name returns a correct field name"); ret_string = bt_ctf_trace_get_environment_field_name_by_index(trace, 1); - ok(ret_string && !strcmp(ret_string, "test_env_int_obj"), - "bt_ctf_trace_get_environment_field_name returns a correct field name"); - ret_string = bt_ctf_trace_get_environment_field_name_by_index(trace, 2); - ok(ret_string && !strcmp(ret_string, "test_env_str_obj"), - "bt_ctf_trace_get_environment_field_name returns a correct field name"); - ret_string = bt_ctf_trace_get_environment_field_name_by_index(trace, 3); ok(ret_string && !strcmp(ret_string, "test_env_int"), "bt_ctf_trace_get_environment_field_name returns a correct field name"); - ret_string = bt_ctf_trace_get_environment_field_name_by_index(trace, 4); + ret_string = bt_ctf_trace_get_environment_field_name_by_index(trace, 2); ok(ret_string && !strcmp(ret_string, "test_env_str"), "bt_ctf_trace_get_environment_field_name returns a correct field name"); /* Test bt_ctf_trace_get_environment_field_value */ obj = bt_ctf_trace_get_environment_field_value_by_index(trace, 1); ret = bt_value_integer_get(obj, &ret_int64_t); - ok(!ret && ret_int64_t == 23, + ok(!ret && ret_int64_t == -164973, "bt_ctf_trace_get_environment_field_value succeeds in getting an integer value"); BT_OBJECT_PUT_REF_AND_RESET(obj); obj = bt_ctf_trace_get_environment_field_value_by_index(trace, 2); ret = bt_value_string_get(obj, &ret_string); - ok(!ret && ret_string && !strcmp(ret_string, "the value"), + ok(!ret && ret_string && !strcmp(ret_string, "oh yeah"), "bt_ctf_trace_get_environment_field_value succeeds in getting a string value"); BT_OBJECT_PUT_REF_AND_RESET(obj); @@ -1757,9 +1731,9 @@ int main(int argc, char **argv) ok(!bt_ctf_trace_set_environment_field_integer(trace, "test_env_int", 654321), "bt_ctf_trace_set_environment_field_integer succeeds with an existing name"); - ok(bt_ctf_trace_get_environment_field_count(trace) == 5, + ok(bt_ctf_trace_get_environment_field_count(trace) == 3, "bt_ctf_trace_set_environment_field_integer with an existing key does not increase the environment size"); - obj = bt_ctf_trace_get_environment_field_value_by_index(trace, 3); + obj = bt_ctf_trace_get_environment_field_value_by_index(trace, 1); ret = bt_value_integer_get(obj, &ret_int64_t); ok(!ret && ret_int64_t == 654321, "bt_ctf_trace_get_environment_field_value successfully replaces an existing field"); diff --git a/tests/lib/test_plugin.c b/tests/lib/test_plugin.c index 1bcc4db0..5e57232b 100644 --- a/tests/lib/test_plugin.c +++ b/tests/lib/test_plugin.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -161,7 +162,7 @@ static void test_sfs(const char *plugin_dir) char *sfs_path = get_test_plugin_path(plugin_dir, "sfs"); unsigned int major, minor, patch; const char *extra; - struct bt_value *params; + struct bt_private_value *params; struct bt_value *results; struct bt_value *object; struct bt_value *res_params; @@ -216,19 +217,20 @@ static void test_sfs(const char *plugin_dir) ok(!bt_plugin_get_component_class_by_name_and_type(plugin, "filter", BT_COMPONENT_CLASS_TYPE_SOURCE), "bt_plugin_get_component_class_by_name_and_type() does not find a component class given the wrong type"); - params = bt_value_integer_create_init(23); + params = bt_private_value_integer_create_init(23); BT_ASSERT(params); ret = bt_query_executor_query(NULL, filter_comp_class, "object", - params, &results); + bt_value_borrow_from_private(params), &results); ok (ret, "bt_query_executor_query() handles NULL (query executor)"); ret = bt_query_executor_query(query_exec, NULL, "object", - params, &results); + bt_value_borrow_from_private(params), &results); ok (ret, "bt_query_executor_query() handles NULL (component class)"); ret = bt_query_executor_query(query_exec, filter_comp_class, NULL, - params, &results); + bt_value_borrow_from_private(params), &results); ok (ret, "bt_query_executor_query() handles NULL (object)"); ret = bt_query_executor_query(query_exec, filter_comp_class, - "get-something", params, &results); + "get-something", bt_value_borrow_from_private(params), + &results); ok(ret == 0 && results, "bt_query_executor_query() succeeds"); BT_ASSERT(bt_value_is_array(results) && bt_value_array_get_size(results) == 2); object = bt_value_array_borrow_element_by_index(results, 0); @@ -238,7 +240,7 @@ static void test_sfs(const char *plugin_dir) ok(strcmp(object_str, "get-something") == 0, "bt_component_class_query() receives the expected object name"); res_params = bt_value_array_borrow_element_by_index(results, 1); - ok(res_params == params, + ok(res_params == bt_value_borrow_from_private(params), "bt_component_class_query() receives the expected parameters"); diag("> putting the plugin object here"); -- 2.34.1