Skip to content

Commit

Permalink
obj_array_index: use return not outvar
Browse files Browse the repository at this point in the history
  • Loading branch information
annacrombie committed Feb 17, 2025
1 parent 5f41675 commit 4d9a150
Show file tree
Hide file tree
Showing 33 changed files with 90 additions and 108 deletions.
2 changes: 1 addition & 1 deletion include/lang/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ bool obj_array_foreach_flat(struct workspace *wk, obj arr, void *usr_ctx, obj_ar
bool obj_array_in(struct workspace *wk, obj arr, obj val);
bool obj_array_index_of(struct workspace *wk, obj arr, obj val, uint32_t *idx);
obj *obj_array_index_pointer(struct workspace *wk, obj arr, int64_t i);
void obj_array_index(struct workspace *wk, obj arr, int64_t i, obj *res);
obj obj_array_index(struct workspace *wk, obj arr, int64_t i);
void obj_array_extend(struct workspace *wk, obj arr, obj arr2);
void obj_array_extend_nodup(struct workspace *wk, obj arr, obj arr2);
void obj_array_dup(struct workspace *wk, obj arr, obj *res);
Expand Down
4 changes: 2 additions & 2 deletions src/backend/ninja/build_target.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ write_tgt_source(struct workspace *wk, struct write_tgt_source_ctx *ctx, enum co
UNREACHABLE;
}

obj_array_index(wk, rule_name_arr, 0, &rule_name);
obj_array_index(wk, rule_name_arr, 1, &specialized_rule);
rule_name = obj_array_index(wk, rule_name_arr, 0);
specialized_rule = obj_array_index(wk, rule_name_arr, 1);
}

TSTR(esc_dest_path);
Expand Down
6 changes: 2 additions & 4 deletions src/backend/ninja/custom_target.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,15 @@ ninja_write_custom_tgt(struct workspace *wk, obj tgt_id, struct write_tgt_ctx *c
if (tgt->flags & custom_target_capture) {
obj_array_push(wk, cmdline, make_str(wk, "-c"));

obj elem;
obj_array_index(wk, tgt->output, 0, &elem);
obj elem = obj_array_index(wk, tgt->output, 0);

ca_relativize_path_push(wk, elem, cmdline);
}

if (tgt->flags & custom_target_feed) {
obj_array_push(wk, cmdline, make_str(wk, "-f"));

obj elem;
obj_array_index(wk, tgt->input, 0, &elem);
obj elem = obj_array_index(wk, tgt->input, 0);

ca_relativize_path_push(wk, elem, cmdline);
}
Expand Down
4 changes: 2 additions & 2 deletions src/backend/ninja/rules.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ write_compiler_rule_iter(struct workspace *wk, void *_ctx, obj k, obj comp_id)
}

obj specialized_rule;
obj_array_index(wk, rule_name_arr, 0, &rule_name);
obj_array_index(wk, rule_name_arr, 1, &specialized_rule);
rule_name = obj_array_index(wk, rule_name_arr, 0);
specialized_rule = obj_array_index(wk, rule_name_arr, 1);

if (!specialized_rule) {
return ir_cont;
Expand Down
3 changes: 1 addition & 2 deletions src/backend/xcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ struct pbx_item {
static enum obj_type
xc_pbx_type(struct xc_ctx *ctx, obj pbx)
{
obj o;
obj_array_index(ctx->wk, pbx, 0, &o);
obj o = obj_array_index(ctx->wk, pbx, 0);
return (enum obj_type)o;
}

Expand Down
14 changes: 7 additions & 7 deletions src/cmd_install.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,9 @@ install_scripts_iter(struct workspace *wk, void *_ctx, obj install_script)
struct install_ctx *ctx = _ctx;

obj install_script_skip_if_destdir, install_script_dry_run, install_script_cmdline;
obj_array_index(wk, install_script, 0, &install_script_skip_if_destdir);
obj_array_index(wk, install_script, 1, &install_script_dry_run);
obj_array_index(wk, install_script, 2, &install_script_cmdline);
install_script_skip_if_destdir = obj_array_index(wk, install_script, 0);
install_script_dry_run = obj_array_index(wk, install_script, 1);
install_script_cmdline = obj_array_index(wk, install_script, 2);

bool script_skip_if_destdir = get_obj_bool(wk, install_script_skip_if_destdir);
bool script_can_dry_run = get_obj_bool(wk, install_script_dry_run);
Expand Down Expand Up @@ -293,10 +293,10 @@ install_run(struct install_options *opts)
};

obj install_targets, install_scripts, source_root;
obj_array_index(&wk, install, 0, &install_targets);
obj_array_index(&wk, install, 1, &install_scripts);
obj_array_index(&wk, install, 2, &source_root);
obj_array_index(&wk, install, 3, &ctx.prefix);
install_targets = obj_array_index(&wk, install, 0);
install_scripts = obj_array_index(&wk, install, 1);
source_root = obj_array_index(&wk, install, 2);
ctx.prefix = obj_array_index(&wk, install, 3);

TSTR(build_root);
path_copy_cwd(&wk, &build_root);
Expand Down
20 changes: 10 additions & 10 deletions src/cmd_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ test_suites_label(struct workspace *wk, const struct test_result *res)
suites_len = get_obj_array(wk, res->test->suites)->len;
if (suites_len == 1) {
obj s;
obj_array_index(wk, res->test->suites, 0, &s);
s = obj_array_index(wk, res->test->suites, 0);
suite_str = get_cstr(wk, s);
} else if (suites_len > 1) {
obj s;
Expand Down Expand Up @@ -503,12 +503,12 @@ find_test_setup_iter(struct workspace *wk, void *_ctx, obj arr)
/* [name, env, exclude_suites, exe_wrapper, is_default, timeout_multiplier] */
obj name, env, exclude_suites, exe_wrapper, is_default, timeout_multiplier;

obj_array_index(wk, arr, 0, &name);
obj_array_index(wk, arr, 1, &env);
obj_array_index(wk, arr, 2, &exclude_suites);
obj_array_index(wk, arr, 3, &exe_wrapper);
obj_array_index(wk, arr, 4, &is_default);
obj_array_index(wk, arr, 5, &timeout_multiplier);
name = obj_array_index(wk, arr, 0);
env = obj_array_index(wk, arr, 1);
exclude_suites = obj_array_index(wk, arr, 2);
exe_wrapper = obj_array_index(wk, arr, 3);
is_default = obj_array_index(wk, arr, 4);
timeout_multiplier = obj_array_index(wk, arr, 5);

if (ctx->rtctx->opts->setup) {
if (!project_namespaced_name_matches(ctx->rtctx->opts->setup,
Expand Down Expand Up @@ -542,7 +542,7 @@ find_test_setup_project_iter(struct workspace *wk, void *_ctx, obj project_name,
ctx->rtctx->proj_name = project_name;

obj setups;
obj_array_index(wk, arr, 1, &setups);
setups = obj_array_index(wk, arr, 1);

if (!setups) {
return ir_cont;
Expand Down Expand Up @@ -940,7 +940,7 @@ static enum iteration_result
run_project_tests(struct workspace *wk, void *_ctx, obj proj_name, obj arr)
{
obj unfiltered_tests, tests;
obj_array_index(wk, arr, 0, &unfiltered_tests);
unfiltered_tests = obj_array_index(wk, arr, 0);

struct run_test_ctx *ctx = _ctx;
ctx->deps = make_obj(wk, obj_array);
Expand Down Expand Up @@ -1174,7 +1174,7 @@ tests_run(struct test_options *opts, const char *argv0)
if (!serial_load_from_private_dir(&wk, &option_info, output_path.option_info)) {
goto ret;
}
obj_array_index(&wk, option_info, 0, &wk.global_opts);
wk.global_opts = obj_array_index(&wk, option_info, 0);
}

{
Expand Down
2 changes: 1 addition & 1 deletion src/coerce.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ coerce_executable(struct workspace *wk, uint32_t node, obj val, obj *res, obj *a
return ir_err;
}

obj_array_index(wk, o->cmd_array, 0, &str);
str = obj_array_index(wk, o->cmd_array, 0);
uint32_t cmd_array_len = get_obj_array(wk, o->cmd_array)->len;
if (cmd_array_len > 1) {
*args = obj_array_slice(wk, o->cmd_array, 1, cmd_array_len);
Expand Down
10 changes: 5 additions & 5 deletions src/compilers.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ compiler_check_cache_get(struct workspace *wk, obj key, struct compiler_check_ca
obj arr;
if (obj_dict_index(wk, wk->compiler_check_cache, key, &arr)) {
obj cache_res;
obj_array_index(wk, arr, 0, &cache_res);
cache_res = obj_array_index(wk, arr, 0);
val->success = get_obj_bool(wk, cache_res);
obj_array_index(wk, arr, 1, &val->value);
val->value = obj_array_index(wk, arr, 1);
return true;
} else {
return false;
Expand Down Expand Up @@ -322,9 +322,9 @@ run_cmd_arr(struct workspace *wk, struct run_cmd_ctx *cmd_ctx, obj cmd_arr, cons
}

obj status, err, out;
obj_array_index(wk, cache_val.value, 0, &status);
obj_array_index(wk, cache_val.value, 1, &out);
obj_array_index(wk, cache_val.value, 2, &err);
status = obj_array_index(wk, cache_val.value, 0);
out = obj_array_index(wk, cache_val.value, 1);
err = obj_array_index(wk, cache_val.value, 2);

cmd_ctx->status = get_obj_number(wk, status);

Expand Down
2 changes: 1 addition & 1 deletion src/functions/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func_array_get(struct workspace *wk, obj self, obj *res)
return false;
}
} else {
obj_array_index(wk, self, i, res);
*res = obj_array_index(wk, self, i);
}

return true;
Expand Down
3 changes: 1 addition & 2 deletions src/functions/custom_target.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ custom_target_is_linkable(struct workspace *wk, obj ct)
struct obj_custom_target *tgt = get_obj_custom_target(wk, ct);

if (get_obj_array(wk, tgt->output)->len == 1) {
obj out;
obj_array_index(wk, tgt->output, 0, &out);
obj out = obj_array_index(wk, tgt->output, 0);

return file_is_linkable(wk, out);
}
Expand Down
4 changes: 2 additions & 2 deletions src/functions/dependency.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ dep_pkgconfig_define(struct workspace *wk, obj dep, uint32_t node, obj var)

for (int64_t idx = 0; idx < arraylen; idx += 2) {
obj key, val;
obj_array_index(wk, var, idx, &key);
obj_array_index(wk, var, idx + 1, &val);
key = obj_array_index(wk, var, idx);
val = obj_array_index(wk, var, idx + 1);

const char *ckey = get_cstr(wk, key);
const char *cval = get_cstr(wk, val);
Expand Down
15 changes: 5 additions & 10 deletions src/functions/environment.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ evironment_to_dict_iter(struct workspace *wk, void *_ctx, obj action)
{
obj env = *(obj *)_ctx, mode_num, key, val, sep;

obj_array_index(wk, action, 0, &mode_num);
obj_array_index(wk, action, 1, &key);
obj_array_index(wk, action, 2, &val);
obj_array_index(wk, action, 3, &sep);
mode_num = obj_array_index(wk, action, 0);
key = obj_array_index(wk, action, 1);
val = obj_array_index(wk, action, 2);
sep = obj_array_index(wk, action, 3);

enum environment_set_mode mode = get_obj_number(wk, mode_num);

Expand Down Expand Up @@ -188,17 +188,12 @@ func_environment_unset(struct workspace *wk, obj self, obj *res)
return false;
}

obj to_delete, action, key, actions = get_obj_environment(wk, self)->actions;
obj to_delete, action, actions = get_obj_environment(wk, self)->actions;

to_delete = make_obj(wk, obj_array);

uint32_t i = 0;
obj_array_for(wk, actions, action) {
/* obj_array_index(wk, action, 0, &mode_num); */
obj_array_index(wk, action, 1, &key);
/* obj_array_index(wk, action, 2, &val); */
/* obj_array_index(wk, action, 3, &sep); */

if (obj_equal(wk, action, an[0].val)) {
obj_array_push(wk, to_delete, i + 1);
}
Expand Down
2 changes: 1 addition & 1 deletion src/functions/external_program.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func_external_program_path(struct workspace *wk, obj self, obj *res)
return false;
}

obj_array_index(wk, get_obj_external_program(wk, self)->cmd_array, 0, res);
*res = obj_array_index(wk, get_obj_external_program(wk, self)->cmd_array, 0);
return true;
}

Expand Down
6 changes: 3 additions & 3 deletions src/functions/kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -593,8 +593,8 @@ find_program_check_override(struct workspace *wk, struct find_program_iter_ctx *
obj over = 0, op;
switch (get_obj_type(wk, override)) {
case obj_array:
obj_array_index(wk, override, 0, &op);
obj_array_index(wk, override, 1, &over);
op = obj_array_index(wk, override, 0);
over = obj_array_index(wk, override, 1);
break;
case obj_python_installation:
case obj_external_program:
Expand Down Expand Up @@ -1151,7 +1151,7 @@ func_run_command(struct workspace *wk, obj _, obj *res)
return false;
}

obj_array_index(wk, an[0].val, 0, &arg0);
arg0 = obj_array_index(wk, an[0].val, 0);

if (get_obj_type(wk, arg0) == obj_compiler) {
obj cmd_arr = get_obj_compiler(wk, arg0)->cmd_arr[toolchain_component_compiler];
Expand Down
4 changes: 2 additions & 2 deletions src/functions/kernel/build_target.c
Original file line number Diff line number Diff line change
Expand Up @@ -1094,8 +1094,8 @@ tgt_common(struct workspace *wk, obj *res, enum tgt_type type, enum tgt_type arg
obj val;
val = make_obj(wk, obj_both_libs);
struct obj_both_libs *both = get_obj_both_libs(wk, val);
obj_array_index(wk, *res, 0, &both->static_lib);
obj_array_index(wk, *res, 1, &both->dynamic_lib);
both->static_lib = obj_array_index(wk, *res, 0);
both->dynamic_lib = obj_array_index(wk, *res, 1);
*res = val;

assert(get_obj_build_target(wk, both->static_lib)->type == tgt_static_library);
Expand Down
2 changes: 1 addition & 1 deletion src/functions/kernel/configure_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ array_to_elem_or_err(struct workspace *wk, uint32_t node, uint32_t arr, uint32_t
return false;
}

obj_array_index(wk, arr, 0, res);
*res = obj_array_index(wk, arr, 0);
return true;
}

Expand Down
13 changes: 6 additions & 7 deletions src/functions/kernel/custom_target.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ format_cmd_arg_cb(struct workspace *wk, uint32_t node, void *_ctx, const struct
if (!boundscheck(wk, ctx->opts->err_node, get_obj_array(wk, arr)->len, &index)) {
return format_cb_error;
}
obj_array_index(wk, arr, 0, &e);
e = obj_array_index(wk, arr, 0);

str_relative_to_build_root(wk, ctx, get_file_path(wk, e), elem);
return format_cb_found;
Expand Down Expand Up @@ -202,8 +202,7 @@ format_cmd_arg_cb(struct workspace *wk, uint32_t node, void *_ctx, const struct
return format_cb_error;
}

obj in0;
obj_array_index(wk, ctx->opts->input, 0, &in0);
obj in0 = obj_array_index(wk, ctx->opts->input, 0);
const struct str *orig_str = get_str(wk, *get_obj_file(wk, in0));

TSTR(plainname);
Expand Down Expand Up @@ -244,7 +243,7 @@ format_cmd_arg_cb(struct workspace *wk, uint32_t node, void *_ctx, const struct
return format_cb_error;
}

obj_array_index(wk, arr, index, &e);
e = obj_array_index(wk, arr, index);

str_relative_to_build_root(wk, ctx, get_file_path(wk, e), elem);
return format_cb_found;
Expand Down Expand Up @@ -397,7 +396,7 @@ format_cmd_output_cb(struct workspace *wk, uint32_t node, void *_ctx, const stru
}

obj in0;
obj_array_index(wk, ctx->opts->input, 0, &in0);
in0 = obj_array_index(wk, ctx->opts->input, 0);
const struct str *ss = get_str(wk, *get_obj_file(wk, in0));
TSTR(buf);

Expand Down Expand Up @@ -619,7 +618,7 @@ install_custom_target(struct workspace *wk,

if (get_obj_array(wk, install_dir)->len == 1) {
obj i0;
obj_array_index(wk, install_dir, 0, &i0);
i0 = obj_array_index(wk, install_dir, 0);
install_dir = i0;
}

Expand Down Expand Up @@ -684,7 +683,7 @@ func_custom_target(struct workspace *wk, obj _, obj *res)
}

obj v;
obj_array_index(wk, akw[kw_output].val, 0, &v);
v = obj_array_index(wk, akw[kw_output].val, 0);
name = v;
}

Expand Down
8 changes: 4 additions & 4 deletions src/functions/kernel/dependency.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,9 @@ handle_dependency_fallback(struct workspace *wk, struct dep_lookup_ctx *ctx, boo
obj subproj_name, subproj_dep = 0, subproj;

switch (get_obj_array(wk, ctx->fallback)->len) {
case 2: obj_array_index(wk, ctx->fallback, 1, &subproj_dep);
case 2: subproj_dep = obj_array_index(wk, ctx->fallback, 1);
/* FALLTHROUGH */
case 1: obj_array_index(wk, ctx->fallback, 0, &subproj_name); break;
case 1: subproj_name = obj_array_index(wk, ctx->fallback, 0); break;
default: vm_error_at(wk, ctx->err_node, "expected array of length 1-2 for fallback"); return false;
}

Expand Down Expand Up @@ -540,7 +540,7 @@ is_dependency_fallback_forced(struct workspace *wk, struct dep_lookup_ctx *ctx)
obj force_fallback_for, subproj_name;

get_option_value(wk, current_project(wk), "force_fallback_for", &force_fallback_for);
obj_array_index(wk, get_dependency_fallback_name(wk, ctx), 0, &subproj_name);
subproj_name = obj_array_index(wk, get_dependency_fallback_name(wk, ctx), 0);

enum wrap_mode wrap_mode = get_option_wrap_mode(wk);

Expand Down Expand Up @@ -739,7 +739,7 @@ func_dependency(struct workspace *wk, obj self, obj *res)
if (requirement == requirement_skip) {
*res = make_obj(wk, obj_dependency);
struct obj_dependency *dep = get_obj_dependency(wk, *res);
obj_array_index(wk, an[0].val, 0, &dep->name);
dep->name = obj_array_index(wk, an[0].val, 0);
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/functions/kernel/install.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ install_data_rename_iter(struct workspace *wk, void *_ctx, obj val)
obj dest;

obj rename;
obj_array_index(wk, ctx->rename, ctx->i, &rename);
rename = obj_array_index(wk, ctx->rename, ctx->i);

TSTR(d);
path_join(wk, &d, get_cstr(wk, ctx->dest), get_cstr(wk, rename));
Expand Down
2 changes: 1 addition & 1 deletion src/functions/kernel/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func_option(struct workspace *wk, obj self, obj *res)
return false;
}

obj_array_index(wk, akw[kw_choices].val, 0, &val);
val = obj_array_index(wk, akw[kw_choices].val, 0);
break;
case op_array:
if (akw[kw_choices].set) {
Expand Down
Loading

0 comments on commit 4d9a150

Please sign in to comment.