Commit c82a5f6d
c82a5f6dfd4fMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 4 files · +2 added · ~2 modified
Description
fix(codegen,runtime): Array#pop on int_array_ptr_array
Array<Array<Int>> lowers to spinel-side int_array_ptr_array,
which is a sp_PtrArray* of sp_IntArray* elements. The dispatch
table only had push, get, set, length, and delete_at
arms for <X>_ptr_array; pop fell through to the unresolved-
call warning and emitted 0, leaving the array intact.
Add an sp_PtrArray_pop runtime helper (returns NULL on empty,
matching CRuby's nil since typed-element ptr arrays can't carry
nil) plus a pop arm in the is_ptr_array_type branch that casts
the result back to the element pointer type.
Closes #520
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- c82a5f6dfd4f
- Parent
- 155b5e4c75ab
lib/sp_runtime.hmodifiedView file
header itself is still GC-tracked. */static sp_PtrArray*sp_PtrArray_new_noscan(void){return sp_PtrArray_new_scan(NULL);}static inline void sp_PtrArray_push(sp_PtrArray*a,void*v){if(a->len>=a->cap){sp_gc_hdr*h=(sp_gc_hdr*)((char*)a-sizeof(sp_gc_hdr));sp_gc_bytes-=sizeof(void*)*a->cap;h->size-=sizeof(void*)*a->cap;a->cap=a->cap*2+1;a->data=(void**)realloc(a->data,sizeof(void*)*a->cap);h->size+=sizeof(void*)*a->cap;sp_gc_bytes+=sizeof(void*)*a->cap;}a->data[a->len++]=v;}/* Array#pop on a `<X>_ptr_array`. Returns NULL when empty (matches CRuby's nil for typed-element arrays since the slot can't carry nil). Issue #520: previously the dispatch on `int_array_ptr_array.pop` warned "cannot resolve call to 'pop'" and emitted 0, silently leaving the array intact. */static inline void *sp_PtrArray_pop(sp_PtrArray*a){if(a->len==0)return NULL;return a->data[--a->len];}static inline void*sp_PtrArray_get(sp_PtrArray*a,mrb_int i){if(i<0)i+=a->len;return a->data[i];}static inline void sp_PtrArray_set(sp_PtrArray*a,mrb_int i,void*v){if(i<0)i+=a->len;a->data[i]=v;}static inline mrb_int sp_PtrArray_length(sp_PtrArray*a){return a->len;}spinel_codegen.rbmodifiedView file
Loading diff…
test/ptr_array_pop.rbaddedView file
Loading diff…
test/ptr_array_pop.rb.expectedaddedView file
Loading diff…