Commit 0572b4e1

0572b4e1d164Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified

Description

Merge pull request #258 from OriPekelman/fix/gc-root-ptr-array-literal

fix(codegen): root PtrArray temp in array-of-objects literal

Details

Commit
0572b4e1d164
Parent
0def5fc1ff38
Merge parent
e94b60bc2cc6

spinel_codegen.rbmodifiedView file

@@ -24258,6 +24258,12 @@
2425824258 if is_ptr_array_type(arr_type) == 1
2425924259 tmp = new_temp
2426024260 emit(" sp_PtrArray *" + tmp + " = sp_PtrArray_new();")
24261+ # Root the freshly-allocated PtrArray before compiling element
24262+ # expressions. Each element is typically Klass.new(...), and that
24263+ # call allocates → may trigger GC. Without this, GC sees `tmp` as
24264+ # unreachable and frees it, leaving a dangling pointer that the
24265+ # subsequent push (and the eventual ivar assignment) writes through.
24266+ emit(" SP_GC_ROOT(" + tmp + ");")
2426124267 k = 0
2426224268 while k < elems.length
2426324269 emit(" sp_PtrArray_push(" + tmp + ", " + compile_expr(elems[k]) + ");")