lib: rename transforming bt_X_borrow_Y() -> bt_X_as_Y()
[babeltrace.git] / cli / babeltrace-cfg-cli-args.c
index b844b4e429bcab1e1be1c7eedac2cb46b3829955..80802fbedf022b6a04d009e2bae2048ec965fa92 100644 (file)
@@ -243,7 +243,7 @@ int ini_handle_state(struct ini_parsing_state *state)
                }
 
                if (bt_value_map_has_entry(
-                               bt_value_borrow_from_private(state->params),
+                               bt_private_value_as_value(state->params),
                                state->last_map_key)) {
                        g_string_append_printf(state->ini_error,
                                "Duplicate parameter key: `%s`\n",
@@ -295,20 +295,20 @@ int ini_handle_state(struct ini_parsing_state *state)
                                goto error;
                        }
 
-                       value = bt_value_borrow_from_private(
+                       value = bt_private_value_as_value(
                                bt_private_value_integer_create_init(
                                        (int64_t) int_val));
                        break;
                }
                case G_TOKEN_FLOAT:
                        /* Positive floating point number */
-                       value = bt_value_borrow_from_private(
+                       value = bt_private_value_as_value(
                                bt_private_value_real_create_init(
                                        state->scanner->value.v_float));
                        break;
                case G_TOKEN_STRING:
                        /* Quoted string */
-                       value = bt_value_borrow_from_private(
+                       value = bt_private_value_as_value(
                                bt_private_value_string_create_init(
                                        state->scanner->value.v_string));
                        break;
@@ -332,16 +332,16 @@ 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_borrow_from_private(
+                               value = bt_private_value_as_value(
                                        bt_private_value_bool_create_init(true));
                        } else if (!strcmp(id, "false") ||
                                        !strcmp(id, "FALSE") ||
                                        !strcmp(id, "no") ||
                                        !strcmp(id, "NO")) {
-                               value = bt_value_borrow_from_private(
+                               value = bt_private_value_as_value(
                                        bt_private_value_bool_create_init(false));
                        } else {
-                               value = bt_value_borrow_from_private(
+                               value = bt_private_value_as_value(
                                        bt_private_value_string_create_init(id));
                        }
                        break;
@@ -375,14 +375,14 @@ int ini_handle_state(struct ini_parsing_state *state)
                                goto error;
                        }
 
-                       value = bt_value_borrow_from_private(
+                       value = bt_private_value_as_value(
                                bt_private_value_integer_create_init(
                                        -((int64_t) int_val)));
                        break;
                }
                case G_TOKEN_FLOAT:
                        /* Negative floating point number */
-                       value = bt_value_borrow_from_private(
+                       value = bt_private_value_as_value(
                                bt_private_value_real_create_init(
                                        -state->scanner->value.v_float));
                        break;
@@ -1265,11 +1265,7 @@ int insert_flat_params_from_array(GString *params_arg,
                        goto end;
                }
 
-               ret = bt_value_string_get(str_obj, &suffix);
-               if (ret) {
-                       printf_err("Unexpected error\n");
-                       goto end;
-               }
+               suffix = bt_value_string_get(str_obj);
 
                g_string_assign(tmpstr, prefix);
                g_string_append(tmpstr, "-");
@@ -1408,7 +1404,7 @@ int add_run_cfg_comp_check_name(struct bt_config *cfg,
                goto end;
        }
 
-       if (bt_value_map_has_entry(bt_value_borrow_from_private(instance_names),
+       if (bt_value_map_has_entry(bt_private_value_as_value(instance_names),
                        cfg_comp->instance_name->str)) {
                printf_err("Duplicate component instance name:\n    %s\n",
                        cfg_comp->instance_name->str);
@@ -1624,8 +1620,7 @@ struct bt_config *bt_config_help_create(
        }
 
        cfg->cmd_data.help.cfg_component =
-               bt_config_component_create(BT_COMPONENT_CLASS_TYPE_UNKNOWN,
-                       NULL, NULL);
+               bt_config_component_create(-1, NULL, NULL);
        if (!cfg->cmd_data.help.cfg_component) {
                goto error;
        }
@@ -1925,8 +1920,6 @@ struct bt_config *bt_config_help_from_args(int argc, const char *argv[],
                                comp_cls_name);
                } else {
                        /* Fall back to plugin help */
-                       cfg->cmd_data.help.cfg_component->type =
-                               BT_COMPONENT_CLASS_TYPE_UNKNOWN;
                        g_string_assign(
                                cfg->cmd_data.help.cfg_component->plugin_name,
                                leftover);
@@ -2397,6 +2390,7 @@ struct bt_config *bt_config_run_from_args(int argc, const char *argv[],
        GString *cur_param_key = NULL;
        char error_buf[256] = { 0 };
        long retry_duration = -1;
+       enum bt_value_status status;
        struct poptOption run_long_options[] = {
                { "base-params", 'b', POPT_ARG_STRING, NULL, OPT_BASE_PARAMS, NULL, NULL },
                { "component", 'c', POPT_ARG_STRING, NULL, OPT_COMPONENT, NULL, NULL },
@@ -2521,9 +2515,10 @@ struct bt_config *bt_config_run_from_args(int argc, const char *argv[],
 
                        BT_ASSERT(cur_base_params);
                        bt_object_put_ref(cur_cfg_comp->params);
-                       cur_cfg_comp->params = bt_value_copy(
-                               bt_value_borrow_from_private(cur_base_params));
-                       if (!cur_cfg_comp->params) {
+                       status = bt_value_copy(
+                               &cur_cfg_comp->params,
+                               bt_private_value_as_value(cur_base_params));
+                       if (status != BT_VALUE_STATUS_OK) {
                                print_err_oom();
                                goto error;
                        }
@@ -2549,11 +2544,11 @@ struct bt_config *bt_config_run_from_args(int argc, const char *argv[],
                                goto error;
                        }
 
-                       params_to_set = bt_value_map_extend(
-                               bt_value_borrow_from_private(cur_cfg_comp->params),
-                               bt_value_borrow_from_private(params));
+                       status = bt_value_map_extend(&params_to_set,
+                               bt_private_value_as_value(cur_cfg_comp->params),
+                               bt_private_value_as_value(params));
                        BT_OBJECT_PUT_REF_AND_RESET(params);
-                       if (!params_to_set) {
+                       if (status != BT_VALUE_STATUS_OK) {
                                printf_err("Cannot extend current component parameters with --params option's argument:\n    %s\n",
                                        arg);
                                goto error;
@@ -2690,7 +2685,7 @@ struct bt_config *bt_config_run_from_args(int argc, const char *argv[],
        }
 
        ret = bt_config_cli_args_create_connections(cfg,
-               bt_value_borrow_from_private(connection_args),
+               bt_private_value_as_value(connection_args),
                error_buf, 256);
        if (ret) {
                printf_err("Cannot creation connections:\n%s", error_buf);
@@ -2745,14 +2740,12 @@ struct bt_config *bt_config_run_from_args_array(struct bt_value *run_args,
                goto end;
        }
        for (i = 0; i < len; i++) {
-               int ret;
                struct bt_value *arg_value =
                        bt_value_array_borrow_element_by_index(run_args, i);
                const char *arg;
 
                BT_ASSERT(arg_value);
-               ret = bt_value_string_get(arg_value, &arg);
-               BT_ASSERT(ret == 0);
+               arg = bt_value_string_get(arg_value);
                BT_ASSERT(arg);
                argv[i + 1] = arg;
        }
@@ -2991,7 +2984,7 @@ int assign_name_to_implicit_component(struct implicit_component_args *args,
        }
 
        name = get_component_auto_name(prefix,
-               bt_value_borrow_from_private(existing_names));
+               bt_private_value_as_value(existing_names));
 
        if (!name) {
                ret = -1;
@@ -3066,23 +3059,20 @@ int append_run_args_for_implicit_component(
        }
 
        for (i = 0; i < bt_value_array_get_size(
-                       bt_value_borrow_from_private(impl_args->extra_params));
+                       bt_private_value_as_value(impl_args->extra_params));
                        i++) {
                struct bt_value *elem;
                const char *arg;
 
                elem = bt_value_array_borrow_element_by_index(
-                       bt_value_borrow_from_private(impl_args->extra_params),
+                       bt_private_value_as_value(impl_args->extra_params),
                        i);
                if (!elem) {
                        goto error;
                }
 
                BT_ASSERT(bt_value_is_string(elem));
-               if (bt_value_string_get(elem, &arg)) {
-                       goto error;
-               }
-
+               arg = bt_value_string_get(elem);
                ret = bt_private_value_array_append_string_element(run_args, arg);
                if (ret) {
                        print_err_oom();
@@ -3223,7 +3213,7 @@ int convert_append_name_param(enum bt_config_component_dest dest,
                         * component.
                         */
                        name = get_component_auto_name(cur_name_prefix->str,
-                               bt_value_borrow_from_private(all_names));
+                               bt_private_value_as_value(all_names));
                        append_name_opt = true;
                } else {
                        /*
@@ -3231,7 +3221,7 @@ int convert_append_name_param(enum bt_config_component_dest dest,
                         * component.
                         */
                        if (bt_value_map_has_entry(
-                                       bt_value_borrow_from_private(all_names),
+                                       bt_private_value_as_value(all_names),
                                        cur_name->str)) {
                                printf_err("Duplicate component instance name:\n    %s\n",
                                        cur_name->str);
@@ -3543,6 +3533,7 @@ int fill_implicit_ctf_inputs_args(GPtrArray *implicit_ctf_inputs_args,
 {
        int ret = 0;
        GList *leftover;
+       enum bt_value_status status;
 
        for (leftover = leftovers; leftover != NULL;
                        leftover = g_list_next(leftover)) {
@@ -3566,10 +3557,10 @@ int fill_implicit_ctf_inputs_args(GPtrArray *implicit_ctf_inputs_args,
                 * this is where the unique path goes.
                 */
                BT_OBJECT_PUT_REF_AND_RESET(impl_args->extra_params);
-               impl_args->extra_params =
-                       bt_value_copy(bt_value_borrow_from_private(
+               status = bt_value_copy(&impl_args->extra_params,
+                               bt_private_value_as_value(
                                base_implicit_ctf_input_args->extra_params));
-               if (!impl_args->extra_params) {
+               if (status != BT_VALUE_STATUS_OK) {
                        print_err_oom();
                        destroy_implicit_component_args(impl_args);
                        goto error;
@@ -4187,7 +4178,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,
-                               bt_value_borrow_from_private(fields), "field");
+                               bt_private_value_as_value(fields), "field");
                        bt_object_put_ref(fields);
                        if (ret) {
                                goto error;
@@ -4205,7 +4196,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,
-                               bt_value_borrow_from_private(names), "name");
+                               bt_private_value_as_value(names), "name");
                        bt_object_put_ref(names);
                        if (ret) {
                                goto error;
@@ -4696,18 +4687,17 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
                }
 
                for (i = 0; i < bt_value_array_get_size(
-                               bt_value_borrow_from_private(run_args)); i++) {
+                               bt_private_value_as_value(run_args)); i++) {
                        struct bt_value *arg_value =
                                bt_value_array_borrow_element_by_index(
-                                       bt_value_borrow_from_private(run_args),
+                                       bt_private_value_as_value(run_args),
                                        i);
                        const char *arg;
                        GString *quoted = NULL;
                        const char *arg_to_print;
 
                        BT_ASSERT(arg_value);
-                       ret = bt_value_string_get(arg_value, &arg);
-                       BT_ASSERT(ret == 0);
+                       arg = bt_value_string_get(arg_value);
 
                        if (print_run_args) {
                                quoted = bt_common_shell_quote(arg, true);
@@ -4727,7 +4717,7 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
                        }
 
                        if (i < bt_value_array_get_size(
-                                       bt_value_borrow_from_private(run_args)) - 1) {
+                                       bt_private_value_as_value(run_args)) - 1) {
                                if (print_run_args) {
                                        putchar(' ');
                                } else {
@@ -4742,7 +4732,7 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
        }
 
        cfg = bt_config_run_from_args_array(
-               bt_value_borrow_from_private(run_args), retcode,
+               bt_private_value_as_value(run_args), retcode,
                force_omit_system_plugin_path, force_omit_home_plugin_path,
                initial_plugin_paths);
        if (!cfg) {
This page took 0.042495 seconds and 4 git commands to generate.