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
18 changes: 15 additions & 3 deletions src/core/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ uint64_t ray_vm_willneed_bytes(void) {
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h> /* the failing call's errno, kept by ray_vm_map_file (#1886) */
#include <stdatomic.h> /* the lazily read page size and read-ahead step */
#if defined(RAY_OS_MACOS)
#include <sys/sysctl.h> /* sysctlbyname — hw.physicalcpu */
Expand Down Expand Up @@ -104,9 +105,13 @@ void* ray_vm_map_file_id(const char* path, size_t* out_size, ray_file_id_t* id)
int fd = open(path, O_RDONLY);
if (fd < 0) return NULL;

/* A failure leaves errno as the failing call set it (close keeps it),
* and an empty file leaves it 0, so a caller can name the reason (#1886). */
struct stat st;
if (fstat(fd, &st) != 0) {
int e = errno;
close(fd);
errno = e;
return NULL;
}
if (id) {
Expand All @@ -125,14 +130,16 @@ void* ray_vm_map_file_id(const char* path, size_t* out_size, ray_file_id_t* id)
if (st.st_size <= 0) {
close(fd);
if (out_size) *out_size = 0;
errno = 0;
return NULL;
}

size_t len = (size_t)st.st_size;
void* p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
int map_errno = errno;
close(fd);

if (p == MAP_FAILED) return NULL;
if (p == MAP_FAILED) { errno = map_errno; return NULL; }

ray_sys_track_file_add((int64_t)len); /* file-backed mapping */
if (out_size) *out_size = len;
Expand Down Expand Up @@ -1697,6 +1704,7 @@ void ray_sem_signal(ray_sem_t* s) {
#include <string.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <errno.h> /* the failing call's errno, kept by ray_vm_map_file (#1886) */
#include <fcntl.h>
#include <unistd.h>
#include "mem/sys.h"
Expand Down Expand Up @@ -1736,17 +1744,21 @@ void* ray_vm_map_file(const char* path, size_t* out_size) {
if (fd < 0) return NULL;

struct stat st;
if (fstat(fd, &st) != 0 || st.st_size <= 0) {
int st_rc = fstat(fd, &st);
if (st_rc != 0 || st.st_size <= 0) {
int e = st_rc != 0 ? errno : 0;
close(fd);
if (out_size) *out_size = 0;
errno = e; /* the failing call's, or 0 for an empty file (#1886) */
return NULL;
}

size_t len = (size_t)st.st_size;
void* p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
int map_errno = errno;
close(fd);

if (p == MAP_FAILED) return NULL;
if (p == MAP_FAILED) { errno = map_errno; return NULL; }
ray_sys_track_file_add((int64_t)len);
if (out_size) *out_size = len;
return p;
Expand Down
4 changes: 2 additions & 2 deletions src/lang/env.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ static __attribute__((noinline, cold)) ray_t* env_frame_force(ray_scope_frame_t*
* (RAY_LAZY_G_FAILED): the bindings keep it too, so a later read
* raises the value's own error again, not an undefined name. */
ray_retain(lazy);
return concrete ? concrete : ray_error("type", NULL);
return concrete ? concrete : ray_error("type", "lazy local: materializing answered no value");
}
f->vals[i] = ok ? concrete : NULL;
if (f->slot_values)
Expand All @@ -175,7 +175,7 @@ static __attribute__((noinline, cold)) ray_t* env_frame_force(ray_scope_frame_t*
if (ok) ray_retain(concrete);
f->slot_values[j] = ok ? concrete : NULL;
}
return ok ? concrete : (concrete ? concrete : ray_error("type", NULL));
return ok ? concrete : (concrete ? concrete : ray_error("type", "lazy local: materializing answered no value"));
}

/* A frame's value at `i`, as a read sees it: a lazy handle forced. */
Expand Down
98 changes: 49 additions & 49 deletions src/lang/eval.c

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/lang/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ static inline ray_t* collection_elem(ray_t* coll, int64_t i, int *allocated) {
const char* sp = ray_str_vec_get(coll, i, &slen);
return ray_str(sp ? sp : "", sp ? slen : 0);
}
default: *allocated = 0; return ray_error("type", NULL);
default: *allocated = 0; return ray_error("type", "element: a %s value has no elements", ray_type_name(coll->type));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/lang/syscmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ ray_t* ray_syscmd_string_dispatch_fn(ray_t* x) {
* straight to the named handler, no string parsing. */
static ray_t* invoke_by_name(const char* name, ray_t* arg) {
const ray_syscmd_t* e = ray_syscmd_lookup(name, strlen(name));
if (!e || !e->fn) return ray_error("nyi", NULL);
if (!e || !e->fn) return ray_error("nyi", "command: :%s is not a known command", name);
if (e->flags & RAY_SYSCMD_REPL_ONLY)
return ray_error("domain", "command is REPL-only");
ray_syscmd_ctx_t ctx = { NULL, false };
Expand Down
4 changes: 2 additions & 2 deletions src/ops/agg_engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -13773,7 +13773,7 @@ static ray_t* agg_build_compact(ray_graph_t* g, ray_op_t* op, ray_t* tbl,
}
ray_t* src = ray_table_col(tbl, want[i]);
if (src && RAY_IS_ERR(src)) { ray_release(compact); scratch_free(want_hdr); return src; }
if (!src) { ray_release(compact); scratch_free(want_hdr); return ray_error("nyi", NULL); }
if (!src) { ray_release(compact); scratch_free(want_hdr); return ray_error("nyi", "group: a column the aggregate reads is not in the table"); }
assert(!RAY_IS_PARTED(src->type));
gcol = gather_by_idx(src, idx, n_sel); /* fresh, no alias */
if (!gcol || RAY_IS_ERR(gcol)) {
Expand Down Expand Up @@ -13842,7 +13842,7 @@ static ray_t* exec_group_v2_once(ray_graph_t* g, ray_op_t* op, ray_t* tbl,
const ray_group_emit_filter_t* efp = ef.enabled ? &ef : NULL;
/* exec_group_v2_run reads g's op extensions unconditionally; a NULL
* graph is an error here, not a request for an unfiltered run. */
if (!g) return ray_error("nyi", NULL);
if (!g) return ray_error("nyi", "group: no plan to run");
if (!g->selection)
return exec_group_v2_run(g, op, tbl, ray_table_nrows(tbl), NULL, NULL, 0,
group_limit, efp);
Expand Down
4 changes: 2 additions & 2 deletions src/ops/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -1964,7 +1964,7 @@ ray_t* ray_cast_fn(ray_t* type_sym, ray_t* val) {
/* Nullable targets preserve nulls; BOOL/U8 produce ordinary values. */
if (ray_is_atom(val) && RAY_ATOM_IS_NULL(val)) {
ray_t* s2 = ray_sym_str(type_sym->i64);
if (!s2) return ray_error("domain", NULL);
if (!s2) return ray_error("domain", "as: the target type symbol has no text");
const char* tn = ray_str_ptr(s2);
size_t tl = ray_str_len(s2);
int8_t tt = 0;
Expand Down Expand Up @@ -1998,7 +1998,7 @@ ray_t* ray_cast_fn(ray_t* type_sym, ray_t* val) {
return ray_error("domain", "as: unknown target type name");
}
ray_t* s = ray_sym_str(type_sym->i64);
if (!s) return ray_error("domain", NULL);
if (!s) return ray_error("domain", "as: the target type symbol has no text");
const char* tname = ray_str_ptr(s);
size_t tlen = ray_str_len(s);

Expand Down
2 changes: 1 addition & 1 deletion src/ops/cmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ static ray_t* logic_map_c(ray_binary_fn fn, const char* name, ray_t* a, ray_t* b
ray_t* ea = ac ? collection_elem(a, i, &la) : a;
ray_t* eb = bc ? collection_elem(b, i, &lb) : b;
ray_t* r = (RAY_IS_ERR(ea) || RAY_IS_ERR(eb))
? ray_error("type", NULL) : fn(ea, eb);
? ray_error("type", "logic: a cell could not be read") : fn(ea, eb);
if (la) ray_release(ea);
if (lb) ray_release(eb);
if (!r || RAY_IS_ERR(r)) { ray_release(out); return r ? r : ray_error("oom", NULL); }
Expand Down
10 changes: 5 additions & 5 deletions src/ops/collection.c
Original file line number Diff line number Diff line change
Expand Up @@ -3224,7 +3224,7 @@ ray_t* distinct_vec_eager(ray_t* x) {
* when the column is met on its own): a NULL segment, a partition without
* the column, then yields its rows as the type's null. */
static ray_t* parted_to_flat_vec_c(ray_t* x, const int64_t* cnt, int64_t ncnt) {
if (!x || !RAY_IS_PARTED(x->type)) return ray_error("type", NULL);
if (!x || !RAY_IS_PARTED(x->type)) return ray_error("type", "parted: the value is not a parted column");
int8_t base = (int8_t)RAY_PARTED_BASETYPE(x->type);
ray_t** segs = (ray_t**)ray_data(x);
int64_t total = parted_rows_counted(x, cnt, ncnt);
Expand Down Expand Up @@ -3297,7 +3297,7 @@ static ray_t* parted_to_flat_vec_c(ray_t* x, const int64_t* cnt, int64_t ncnt) {
if (!elem || RAY_IS_ERR(elem) || store_typed_elem(out, pos, elem) != 0) {
if (allocated && elem && !RAY_IS_ERR(elem)) ray_release(elem);
ray_release(out);
return elem && RAY_IS_ERR(elem) ? elem : ray_error("type", NULL);
return elem && RAY_IS_ERR(elem) ? elem : ray_error("type", "parted: a cell could not be read");
}
if (allocated) ray_release(elem);
}
Expand Down Expand Up @@ -5166,7 +5166,7 @@ ray_t* ray_cut_fn(ray_t* vec, ray_t* idxs) {
}
int alloc = 0;
ray_t* ie = collection_elem(idxs, i, &alloc);
if (!ie || RAY_IS_ERR(ie)) { ray_release(out); return ie ? ie : ray_error("type", NULL); }
if (!ie || RAY_IS_ERR(ie)) { ray_release(out); return ie ? ie : ray_error("type", "cut: an index answered no value"); }
if (!ray_is_atom(ie) ||
(ie->type != -RAY_I64 && ie->type != -RAY_I32 &&
ie->type != -RAY_I16 && ie->type != -RAY_U8)) {
Expand Down Expand Up @@ -5234,14 +5234,14 @@ ray_t* ray_cross_fn(ray_t* a, ray_t* b) {
}
int alloc_a = 0;
ray_t* ae = cross_elem(a, i, &alloc_a);
if (!ae || RAY_IS_ERR(ae)) { ray_release(out); return ae ? ae : ray_error("type", NULL); }
if (!ae || RAY_IS_ERR(ae)) { ray_release(out); return ae ? ae : ray_error("type", "cross: an element answered no value"); }
for (int64_t j = 0; j < nb; j++) {
int alloc_b = 0;
ray_t* be = cross_elem(b, j, &alloc_b);
if (!be || RAY_IS_ERR(be)) {
if (alloc_a) ray_release(ae);
ray_release(out);
return be ? be : ray_error("type", NULL);
return be ? be : ray_error("type", "cross: an element answered no value");
}
ray_t* pair = ray_list_new(2);
if (!pair || RAY_IS_ERR(pair)) {
Expand Down
5 changes: 4 additions & 1 deletion src/ops/embedding.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
#include "store/embmodel.h"
#include "core/pool.h"
#include <stdatomic.h>
#include "core/errpath.h"
/* a path as messages show it: a long one by its tail (#1886) */
#define EPATH(p) ray_err_path((p), (char[RAY_ERR_PATH_MAX + 1]){0})

/* ==========================================================================
* Rayfall builtins — direct metrics, exact KNN, HNSW lifecycle/query
Expand Down Expand Up @@ -741,7 +744,7 @@ ray_t* ray_hnsw_save_fn(ray_t* path, ray_t* h) {
memcpy(buf, p, len);
buf[len] = '\0';
ray_err_t err = ray_hnsw_save(idx, buf);
if (err != RAY_OK) return ray_error("io", NULL);
if (err != RAY_OK) return ray_error("io", ".emb.hnsw.set \"%s\": saving the index failed (%s)", EPATH(buf), ray_err_code_str(err));
return RAY_NULL_OBJ;
}

Expand Down
Loading
Loading