Commit a3130caf

a3130caf9141Merged

Yusuke Endoh <[email protected]> · 6 months ago · 3 files · +1 added · ~2 modified

Description

fix(codegen): box value when filling poly_array via Array#fill

arr.fill(val) codegen emitted sp_PolyArray_set(arr, i, val) with the raw scalar val, but the storage is sp_RbVal — passing an unboxed int / str / float fails to compile with "incompatible type for argument 3 of sp_PolyArray_set".

Fix: wrap the value via box_value_to_poly first when the receiver is poly_array. Other typed-array fills (int / float / str / sym / ptr) keep their raw scalar path.

Also adds sp_PolyArray_set to lib/sp_runtime.h (parallel to the existing sp_PolyArray_get / sp_PolyArray_push helpers).

Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]

Details

Commit
a3130caf9141
Parent
fea5369dddb0

lib/sp_runtime.hmodifiedView file

@@ -832,6 +832,7 @@
832832 static void sp_PolyArray_push(sp_PolyArray *a, sp_RbVal v) { if (a->len >= a->cap) { sp_gc_hdr *h = (sp_gc_hdr *)((char *)a - sizeof(sp_gc_hdr)); sp_gc_bytes -= sizeof(sp_RbVal) * a->cap; h->size -= sizeof(sp_RbVal) * a->cap; a->cap = a->cap * 2 + 1; a->data = (sp_RbVal *)realloc(a->data, sizeof(sp_RbVal) * a->cap); h->size += sizeof(sp_RbVal) * a->cap; sp_gc_bytes += sizeof(sp_RbVal) * a->cap; } a->data[a->len++] = v; }
833833 static mrb_int sp_PolyArray_length(sp_PolyArray *a) { return a->len; }
834834 static sp_RbVal sp_PolyArray_get(sp_PolyArray *a, mrb_int i) { if (i < 0) i += a->len; return a->data[i]; }
835+static void sp_PolyArray_set(sp_PolyArray *a, mrb_int i, sp_RbVal v) { if (i < 0) i += a->len; a->data[i] = v; }
835836 static sp_PolyArray *sp_PolyArray_slice(sp_PolyArray *a, mrb_int start, mrb_int len) { if (start < 0) start += a->len; if (start < 0) start = 0; sp_PolyArray *b = sp_PolyArray_new(); if (start >= a->len || len <= 0) return b; if (start + len > a->len) len = a->len - start; for (mrb_int i = 0; i < len; i++) sp_PolyArray_push(b, a->data[start + i]); return b; }
836837 static sp_PolyArray *sp_PolyArray_slice_bang(sp_PolyArray *a, mrb_int from, mrb_int n) {
837838 if (from < 0) from += a->len;