Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/internal/1665-container-accessors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Internal refactor, no behaviour change: list elements and dict values go through the ownership-explicit accessors in src/container.h, ahead of NaN-boxed container storage (#1665 arm D).
408 changes: 204 additions & 204 deletions src/builtins.c

Large diffs are not rendered by default.

120 changes: 60 additions & 60 deletions src/builtins_buf.c

Large diffs are not rendered by default.

86 changes: 43 additions & 43 deletions src/builtins_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@
rt_error(EK_TYPE, 0, "regex_match requires [string, pattern]");
return make_list(0);
}
if (arg->data.list.items[0]->type != VAL_STR || arg->data.list.items[1]->type != VAL_STR) {
if (list_get_borrow(arg, 0)->type != VAL_STR || list_get_borrow(arg, 1)->type != VAL_STR) {
rt_error(EK_TYPE, 0, "regex_match: string and pattern must be strings");
return make_list(0);
}
const char *str = arg->data.list.items[0]->data.str;
const char *pattern = arg->data.list.items[1]->data.str;
const char *str = list_get_borrow(arg, 0)->data.str;
const char *pattern = list_get_borrow(arg, 1)->data.str;

regex_t re;
/* #500: an invalid pattern used to return [] — indistinguishable from a
Expand Down Expand Up @@ -100,12 +100,12 @@
rt_error(EK_TYPE, 0, "regex_find requires [string, pattern]");
return make_list(0);
}
if (arg->data.list.items[0]->type != VAL_STR || arg->data.list.items[1]->type != VAL_STR) {
if (list_get_borrow(arg, 0)->type != VAL_STR || list_get_borrow(arg, 1)->type != VAL_STR) {
rt_error(EK_TYPE, 0, "regex_find: string and pattern must be strings");
return make_list(0);
}
const char *str = arg->data.list.items[0]->data.str;
const char *pattern = arg->data.list.items[1]->data.str;
const char *str = list_get_borrow(arg, 0)->data.str;
const char *pattern = list_get_borrow(arg, 1)->data.str;

regex_t re;
if (regcomp(&re, pattern, REG_EXTENDED) != 0) { /* #500 */
Expand Down Expand Up @@ -143,18 +143,18 @@
* discards it at the CHECK_ERROR seam. */
return make_str("");
}
if (arg->data.list.items[0]->type != VAL_STR ||
arg->data.list.items[1]->type != VAL_STR ||
arg->data.list.items[2]->type != VAL_STR) {
if (list_get_borrow(arg, 0)->type != VAL_STR ||
list_get_borrow(arg, 1)->type != VAL_STR ||
list_get_borrow(arg, 2)->type != VAL_STR) {
rt_error(EK_TYPE, 0, "regex_replace: string, pattern and replacement must be strings");
/* fs:CHANNEL same as above — the unconditional rt_error is the error
* channel; converting to ARG_GUARD would make this site quieter with
* strict OFF, not louder. */
return make_str("");
}
const char *str = arg->data.list.items[0]->data.str;
const char *pattern = arg->data.list.items[1]->data.str;
const char *replacement = arg->data.list.items[2]->data.str;
const char *str = list_get_borrow(arg, 0)->data.str;
const char *pattern = list_get_borrow(arg, 1)->data.str;
const char *replacement = list_get_borrow(arg, 2)->data.str;

regex_t re;
/* #500: an invalid pattern used to return the input unchanged — a silent
Expand Down Expand Up @@ -211,8 +211,8 @@
STRICT_LIST_MAX(arg, 2, "stream_open");
ARG_GUARD(!arg || arg->type != VAL_LIST || arg->data.list.count < 2,
"stream_open", "[path, count]", make_bool(0));
Value *path_val = arg->data.list.items[0];
Value *count_val = arg->data.list.items[1];
Value *path_val = list_get_borrow(arg, 0);
Value *count_val = list_get_borrow(arg, 1);
ARG_GUARD(!path_val || path_val->type != VAL_STR || !count_val || count_val->type != VAL_NUM,
"stream_open", "[a string path, a number count]", make_bool(0));
if (eigs_num_arg(count_val, __func__) < 1 ||
Expand Down Expand Up @@ -331,7 +331,7 @@
list_append_owned(list, make_str(entry->d_name));
}
closedir(d);
qsort(list->data.list.items, list->data.list.count, sizeof(Value*),
qsort(list_values_storage(list), list->data.list.count, sizeof(Value*),
ls_entry_cmp);
TRACE_NONDET_RECORD("ls", list);
}
Expand Down Expand Up @@ -397,10 +397,10 @@
if (!arg || arg->type != VAL_LIST || arg->data.list.count < 4)
return make_null();

Value *file_list = arg->data.list.items[0];
Value *topn_val = arg->data.list.items[1];
Value *stream_path_val = arg->data.list.items[2];
Value *vocab_path_val = arg->data.list.items[3];
Value *file_list = list_get_borrow(arg, 0);
Value *topn_val = list_get_borrow(arg, 1);
Value *stream_path_val = list_get_borrow(arg, 2);
Value *vocab_path_val = list_get_borrow(arg, 3);

if (!file_list || file_list->type != VAL_LIST) return make_null();
BOOL_REFUSE(topn_val, "build_corpus");
Expand Down Expand Up @@ -437,7 +437,7 @@
* been re-measured on the full corpus.) */
int slot_count = 0;
if (arg->data.list.count >= 6) {
Value *sv = arg->data.list.items[5];
Value *sv = list_get_borrow(arg, 5);
double d = 0;
if (eigs_opt_num(sv, &d, "build_corpus")) slot_count = (int)d; /* #1637: a bool raises */
if (g_has_error) return make_null();
Expand Down Expand Up @@ -465,7 +465,7 @@
* high-frequency collision is. Opt-in: 0 leaves the stream byte-identical. */
int int_count = 0;
if (arg->data.list.count >= 7) {
Value *iv = arg->data.list.items[6];
Value *iv = list_get_borrow(arg, 6);
double d = 0;
if (eigs_opt_num(iv, &d, "build_corpus")) int_count = (int)d; /* #1637: a bool raises */
if (g_has_error) return make_null();
Expand All @@ -487,7 +487,7 @@
int files_found = 0;

for (int fi = 0; fi < n_files; fi++) {
Value *path_val = file_list->data.list.items[fi];
Value *path_val = list_get_borrow(file_list, fi);
if (!path_val || path_val->type != VAL_STR) { file_tok_counts[fi] = 0; continue; }
const char *path = path_val->data.str;

Expand Down Expand Up @@ -643,7 +643,7 @@
for (int fi = 0; fi < n_files; fi++) {
if (file_tok_counts[fi] <= 0) continue;

Value *path_val = file_list->data.list.items[fi];
Value *path_val = list_get_borrow(file_list, fi);

Check failure

Code scanning / CodeQL

Inconsistent nullness check Error

The result of this call to list_get_borrow is not checked for null, but 70% of calls to list_get_borrow check for null.
long fsize = 0;
char *source = read_file_util(path_val->data.str, &fsize);
if (!source) continue;
Expand Down Expand Up @@ -752,7 +752,7 @@
* Sorted by count descending. Enables exact coverage(top_n) curves
* without re-running the full corpus build. */
if (arg->data.list.count >= 5) {
Value *idents_path_val = arg->data.list.items[4];
Value *idents_path_val = list_get_borrow(arg, 4);
if (idents_path_val && idents_path_val->type == VAL_STR && n_idents > 0) {
/* Build index array, sort descending by count via simple sort */
int *order = xmalloc_array(n_idents, sizeof(int));
Expand Down Expand Up @@ -1003,8 +1003,8 @@
STRICT_LIST_MAX(arg, 2, "rename");
ARG_GUARD(!arg || arg->type != VAL_LIST || arg->data.list.count < 2,
"rename", "[old_path, new_path]", make_bool(0));
Value *from = arg->data.list.items[0];
Value *to = arg->data.list.items[1];
Value *from = list_get_borrow(arg, 0);
Value *to = list_get_borrow(arg, 1);
ARG_GUARD(!from || from->type != VAL_STR || !to || to->type != VAL_STR,
"rename", "two string paths", make_bool(0));
return make_bool(rename(from->data.str, to->data.str) == 0);
Expand Down Expand Up @@ -1085,9 +1085,9 @@
"read_bytes_buf of path, or read_bytes_buf of [path, max_bytes]");
return make_null();
}
path = arg->data.list.items[0];
path = list_get_borrow(arg, 0);
if (arg->data.list.count >= 2) {
Value *mv = arg->data.list.items[1];
Value *mv = list_get_borrow(arg, 1);
if (!mv || mv->type != VAL_NUM) {
rt_error(EK_VALUE, 0, "read_bytes_buf: max_bytes must be a number");
return make_null();
Expand Down Expand Up @@ -1212,8 +1212,8 @@
STRICT_LIST_MAX(arg, 2, "write_text");
ARG_GUARD(!arg || arg->type != VAL_LIST || arg->data.list.count < 2,
"write_text", "[path, text]", make_bool(0));
Value *path_val = arg->data.list.items[0];
Value *text_val = arg->data.list.items[1];
Value *path_val = list_get_borrow(arg, 0);
Value *text_val = list_get_borrow(arg, 1);
ARG_GUARD(!path_val || path_val->type != VAL_STR ||
!text_val || text_val->type != VAL_STR,
"write_text", "two strings", make_bool(0));
Expand Down Expand Up @@ -1243,8 +1243,8 @@

static Value* exec_capture_result(int code, const char *text) {
Value *result = make_list(2);
result->data.list.items[0] = make_num(code);
result->data.list.items[1] = make_str(text);
list_set_owned(result, 0, make_num(code));
list_set_owned(result, 1, make_str(text));
result->data.list.count = 2;
return result;
}
Expand All @@ -1270,9 +1270,9 @@
double timeout_sec = -1;
Value *cmd_list = arg;
if (arg->data.list.count == 2
&& arg->data.list.items[0] && arg->data.list.items[0]->type == VAL_LIST
&& arg->data.list.items[1] && arg->data.list.items[1]->type == VAL_NUM) {
cmd_list = arg->data.list.items[0];
&& list_get_borrow(arg, 0) && list_get_borrow(arg, 0)->type == VAL_LIST
&& list_get_borrow(arg, 1) && list_get_borrow(arg, 1)->type == VAL_NUM) {
cmd_list = list_get_borrow(arg, 0);
timeout_sec = eigs_list_num(arg, 1, __func__);
ARG_GUARD(cmd_list->data.list.count < 1,
"exec_capture", "a non-empty command list", exec_capture_result(-1, ""));
Expand All @@ -1286,7 +1286,7 @@
* outcome, not an argument the caller got wrong. */
if (!argv) return exec_capture_result(-1, "");
for (int i = 0; i < total; i++) {
Value *v = cmd_list->data.list.items[i];
Value *v = list_get_borrow(cmd_list, i);
if (!v || v->type != VAL_STR) {
free(argv);
ARG_GUARD(1, "exec_capture", "a list of strings", exec_capture_result(-1, ""));
Expand Down Expand Up @@ -1417,8 +1417,8 @@
if (replay_blocks("proc_read_buf")) return make_null();
if (!arg || arg->type != VAL_LIST || arg->data.list.count != 2)
return make_null();
Value *fd_v = arg->data.list.items[0];
Value *max_v = arg->data.list.items[1];
Value *fd_v = list_get_borrow(arg, 0);
Value *max_v = list_get_borrow(arg, 1);
if (!fd_v || fd_v->type != VAL_NUM || !max_v || max_v->type != VAL_NUM)
return make_null();
int fd = (int)eigs_num_arg(fd_v, __func__);
Expand Down Expand Up @@ -1481,15 +1481,15 @@
STRICT_LIST_MAX(arg, 3, "write_bytes");
ARG_GUARD(!arg || arg->type != VAL_LIST || arg->data.list.count < 2,
"write_bytes", "[path, data] (optionally [path, data, append])", make_num(0));
Value *path_val = arg->data.list.items[0];
Value *data = arg->data.list.items[1];
Value *path_val = list_get_borrow(arg, 0);
Value *data = list_get_borrow(arg, 1);
ARG_GUARD(!path_val || path_val->type != VAL_STR,
"write_bytes", "a string path as its first argument", make_num(0));
/* #1637: append is a flag -- a bool, or the older nonzero number. Any
* other value raises rather than silently meaning "truncate". */
int append = 0;
if (arg->data.list.count >= 3 && arg->data.list.items[2]) {
Value *fl = arg->data.list.items[2];
if (arg->data.list.count >= 3 && list_get_borrow(arg, 2)) {
Value *fl = list_get_borrow(arg, 2);
if (fl->type == VAL_BOOL) append = fl->data.boolean;
else if (fl->type != VAL_NULL) append = (eigs_num_arg(fl, "write_bytes") != 0.0);
if (g_has_error) return make_num(0);
Expand All @@ -1499,7 +1499,7 @@
Value **items = NULL;
if (data && data->type == VAL_LIST) {
n = data->data.list.count;
items = data->data.list.items;
items = list_values_storage(data);
} else if (data && data->type == VAL_BUFFER) {
n = data->data.buffer.count;
} else {
Expand Down
Loading
Loading