Skip to content
Open
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
40 changes: 21 additions & 19 deletions src/lang/nfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,21 @@

ray_t* ray_nfo_create(const char* filename, size_t fname_len,
const char* source, size_t src_len) {
/* A part that fails to allocate: no nfo (NULL), the parts made freed.
* An error object here would be kept by callers, which take the nfo as
* optional and release it (a no-op on an error), and read as a list. */
ray_t* fname = ray_str(filename, fname_len);
if (RAY_IS_ERR(fname)) return fname;

ray_t* src = ray_str(source, src_len);
if (RAY_IS_ERR(src)) { ray_release(fname); return src; }

ray_t* keys = ray_vec_new(RAY_I64, 0);
if (RAY_IS_ERR(keys)) { ray_release(fname); ray_release(src); return keys; }

ray_t* vals = ray_vec_new(RAY_I64, 0);
if (RAY_IS_ERR(vals)) { ray_release(fname); ray_release(src); ray_release(keys); return vals; }

/* Build the nfo list: alloc 4-slot list, set elements directly. */
ray_t* nfo = ray_alloc(4 * sizeof(ray_t*));
ray_t* src = fname && !RAY_IS_ERR(fname) ? ray_str(source, src_len) : NULL;
ray_t* keys = src && !RAY_IS_ERR(src) ? ray_vec_new(RAY_I64, 0) : NULL;
ray_t* vals = keys && !RAY_IS_ERR(keys) ? ray_vec_new(RAY_I64, 0) : NULL;
ray_t* nfo = vals && !RAY_IS_ERR(vals) ? ray_alloc(4 * sizeof(ray_t*)) : NULL;
if (!nfo || RAY_IS_ERR(nfo)) {
ray_release(fname); ray_release(src); ray_release(keys); ray_release(vals);
return ray_error("oom", NULL);
ray_t* parts[5] = { fname, src, keys, vals, nfo };
for (int i = 0; i < 5; i++) {
if (parts[i] && RAY_IS_ERR(parts[i])) ray_error_free(parts[i]);
else if (parts[i]) ray_release(parts[i]);
}
return NULL;
}
nfo->type = RAY_LIST;
nfo->len = 4;
Expand All @@ -63,15 +61,19 @@ void ray_nfo_insert(ray_t* nfo, ray_t* node, ray_span_t span) {
ray_t* vals = NFO_VALS(nfo);
if (!keys || !vals) return;

ray_t* new_keys = ray_vec_append(keys, &key);
ray_t* new_vals = ray_vec_append(vals, &val);

/* If vec_append reallocated, update the nfo list slots directly.
* ray_vec_append already transferred ownership (the old pointer is
* invalid), so we just swap the slot pointer; no retain/release needed
* since the list already owns one ref from the original append. */
* since the list already owns one ref from the original append. An
* append that fails to grow leaves its vector as it was: the span goes
* unrecorded, its key taken back if only the value failed, and the
* error is freed, never kept in a slot. */
ray_t** slots = (ray_t**)ray_data(nfo);
ray_t* new_keys = ray_vec_append(keys, &key);
if (!new_keys || RAY_IS_ERR(new_keys)) { ray_error_free(new_keys); return; }
if (new_keys != keys) slots[2] = new_keys;
ray_t* new_vals = ray_vec_append(vals, &val);
if (!new_vals || RAY_IS_ERR(new_vals)) { ray_error_free(new_vals); new_keys->len--; return; }
if (new_vals != vals) slots[3] = new_vals;
}

Expand Down
3 changes: 2 additions & 1 deletion src/lang/nfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ typedef union ray_span_t {
#define NFO_VALS(nfo) ray_list_get((nfo), 3)

/* Create a new nfo object for the given source file.
* Returns a RAY_LIST or ray_error() on failure. */
* Returns a RAY_LIST, or NULL (no nfo: the source goes without spans) when
* a part fails to allocate. */
ray_t* ray_nfo_create(const char* filename, size_t fname_len,
const char* source, size_t src_len);

Expand Down
6 changes: 3 additions & 3 deletions src/ops/agg_engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -13633,7 +13633,7 @@ static ray_t* exec_group_v2_run_keys(ray_graph_t* g, ray_op_t* op, ray_t* tbl,
if (grp_rc != 0) { agg_dense_plan_free(&dp); return agg_keys_error(grp_rc); }

ray_t* result = ray_table_new(ext->n_keys + ext->n_aggs);
if (!result || RAY_IS_ERR(result)) { agg_dense_plan_free(&dp); agg_groups_free(&groups); return ray_error("oom", NULL); }
if (!result || RAY_IS_ERR(result)) { agg_dense_plan_free(&dp); agg_groups_free(&groups); return result ? result : ray_error("oom", NULL); }

for (uint32_t k = 0; k < ext->n_keys; k++) {
ray_t* kc = ray_group_gather(key_cols[k], groups.first_row, groups.ngroups);
Expand Down Expand Up @@ -13882,7 +13882,7 @@ ray_t* agg_run_one(const agg_vtable_t* vt, ray_t* val_col,
if (vt->destroy)
for (int64_t gi = 0; gi < ngroups; gi++)
vt->destroy(states + (size_t)gi * vt->state_size);
ray_free_raw(states); return ray_error("oom", NULL);
ray_free_raw(states); return out ? out : ray_error("oom", NULL);
}
out->len = ngroups;
for (int64_t gi = 0; gi < ngroups; gi++) {
Expand Down Expand Up @@ -13923,7 +13923,7 @@ ray_t* agg_run_one_bin(const agg_vtable_t* vt, ray_t* x_col, ray_t* y_col,
if (vt->destroy)
for (int64_t gi = 0; gi < ngroups; gi++)
vt->destroy(states + (size_t)gi * vt->state_size);
ray_free_raw(states); return ray_error("oom", NULL);
ray_free_raw(states); return out ? out : ray_error("oom", NULL);
}
out->len = ngroups;
for (int64_t gi = 0; gi < ngroups; gi++) {
Expand Down
11 changes: 10 additions & 1 deletion src/ops/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -7742,7 +7742,16 @@ ray_t* exec_flatten_parted_table(ray_t* tbl) {

static ray_t* ray_execute_inner(ray_graph_t* g, ray_op_t* root, bool reset_cancel) {
ray_enc_note_exec_start();
if (!g || !root) return ray_error("nyi", NULL);
if (!g || !root) {
/* A node that failed to allocate leaves a NULL root and its failure
* (oom) in compile_err: answer that, not "not implemented". */
if (g && g->compile_err) {
ray_t* e = g->compile_err;
g->compile_err = NULL;
return e;
}
return ray_error("nyi", NULL);
}

/* Lazy-init the global thread pool on first call */
ray_pool_t* pool = ray_pool_get();
Expand Down
4 changes: 3 additions & 1 deletion src/ops/fused_topk.c
Original file line number Diff line number Diff line change
Expand Up @@ -1341,7 +1341,9 @@ ray_t* ray_fused_topk_select(ray_t* tbl,
if (gerr) { build_ok = 0; break; }
col = gather_by_idx(src, global_idx, global_n);
}
if (!col || RAY_IS_ERR(col)) { build_ok = 0; break; }
/* a gather that failed to allocate: declined, the unfused path
* runs; its error goes, it is not refcounted */
if (!col || RAY_IS_ERR(col)) { ray_error_free(col); build_ok = 0; break; }
result = ray_table_add_col(result, alias, col);
ray_release(col);
}
Expand Down
Loading
Loading