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) == 12425924259
tmp = new_temp2426024260
emit(" sp_PtrArray *" + tmp + " = sp_PtrArray_new();")24261+
# Root the freshly-allocated PtrArray before compiling element24262+
# expressions. Each element is typically Klass.new(...), and that24263+
# call allocates → may trigger GC. Without this, GC sees `tmp` as24264+
# unreachable and frees it, leaving a dangling pointer that the24265+
# subsequent push (and the eventual ivar assignment) writes through.24266+
emit(" SP_GC_ROOT(" + tmp + ");")2426124267
k = 02426224268
while k < elems.length2426324269
emit(" sp_PtrArray_push(" + tmp + ", " + compile_expr(elems[k]) + ");")test/gc_root_ptr_array_literal.rbaddedView file
Loading diff…
test/gc_root_ptr_array_literal.rb.expectedaddedView file
Loading diff…