Commit 9204f7a1
9204f7a13dfbMerged
Richard Ramsden <[email protected]> · 6 months ago · 1 file · ~1 modified
Description
fix(runtime): revert bogus a->start indexing in Float/Str array inspect
ab4590f ("honor start offset in Float/Str array inspect") tried to
mirror the pattern used by sp_IntArray_inspect / sp_SymArray_inspect,
but sp_FloatArray and sp_StrArray do not have a start field — only
sp_IntArray does (line 178):
typedef struct{mrb_int*data;mrb_int start;mrb_int len;mrb_int cap;}sp_IntArray;
typedef struct{mrb_float*data;mrb_int len;mrb_int cap;}sp_FloatArray;
typedef struct{const char**data;mrb_int len;mrb_int cap;...}sp_StrArray;
Float/Str arrays have no shared-backing slice model: sp_FloatArray_slice
memcpy's into a fresh buffer, sp_StrArray_slice push-copies element by
element, and every accessor (get/set/push/pop/reverse/sort/etc.) indexes
with plain a->data[i]. There is no offset to honor.
The "fix" therefore introduced a->data[a->start+i] against a
nonexistent member, which broke gen1 compilation outright:
lib/sp_runtime.h:432: error: 'sp_FloatArray' has no member named 'start'
lib/sp_runtime.h:433: error: 'sp_StrArray' has no member named 'start'
Restore the original a->data[i] indexing. The IntArray and SymArray
inspect helpers (which do have a real start field) are left untouched.
Verified:
make bootstrapreaches gen3 fixed point- test/bm_inspect.rb (exercises FloatArray / StrArray / poly-array inspect paths) passes
- full suite: 108 tests pass, 56 benches pass
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 9204f7a13dfb
- Parent
- 056f2ebd1fc8
lib/sp_runtime.hmodifiedView file
element rendered via its own primitive inspect. Matches CRuby's Array#inspect output byte-for-byte. Returns a GC-managed C string. */static const char*sp_IntArray_inspect(sp_IntArray*a){sp_String*s=sp_String_new("[");for(mrb_int i=0;i<a->len;i++){if(i>0)sp_String_append(s,", ");sp_String_append(s,sp_int_to_s(a->data[a->start+i]));}sp_String_append(s,"]");return s->data;}static const char*sp_FloatArray_inspect(sp_FloatArray*a){sp_String*s=sp_String_new("[");for(mrb_int i=0;i<a->len;i++){if(i>0)sp_String_append(s,", ");sp_String_append(s,sp_float_inspect(a->data[a->start+i]));}sp_String_append(s,"]");return s->data;}static const char*sp_StrArray_inspect(sp_StrArray*a){sp_String*s=sp_String_new("[");for(mrb_int i=0;i<a->len;i++){if(i>0)sp_String_append(s,", ");sp_String_append(s,sp_str_inspect(a->data[a->start+i]));}sp_String_append(s,"]");return s->data;}static const char*sp_FloatArray_inspect(sp_FloatArray*a){sp_String*s=sp_String_new("[");for(mrb_int i=0;i<a->len;i++){if(i>0)sp_String_append(s,", ");sp_String_append(s,sp_float_inspect(a->data[i]));}sp_String_append(s,"]");return s->data;}static const char*sp_StrArray_inspect(sp_StrArray*a){sp_String*s=sp_String_new("[");for(mrb_int i=0;i<a->len;i++){if(i>0)sp_String_append(s,", ");sp_String_append(s,sp_str_inspect(a->data[i]));}sp_String_append(s,"]");return s->data;}/* Symbol arrays share the IntArray representation (sp_sym = mrb_int), but each element is rendered as ":name" via sp_sym_to_s. */static const char*sp_SymArray_inspect(sp_IntArray*a){sp_String*s=sp_String_new("[");for(mrb_int i=0;i<a->len;i++){if(i>0)sp_String_append(s,", ");sp_String_append(s,":");sp_String_append(s,sp_sym_to_s((sp_sym)a->data[a->start+i]));}sp_String_append(s,"]");return s->data;}