Commit b4ef1d70
b4ef1d7089f0Merged
Chris Hasiński <[email protected]> · 7 months ago · 1 file · ~1 modified
Description
fix(codegen): root the Array.new(N){block} buffer before the loop
Pushing poly/string values inside the block can trigger a GC cycle
while the freshly allocated sp_IntArray * lives only in a C local.
Add an explicit SP_GC_ROOT after the allocation. Also tighten
indentation: increment @indent before emitting the block-param
assignment so all inner statements share the same indent level.
Addresses Gemini review on #30.
Details
- Commit
- b4ef1d7089f0
- Parent
- b59ea876f10f
spinel_codegen.rbmodifiedView file
@@ -13290,11 +13290,15 @@
1329013290
arrnew_iv = new_temp1329113291
@needs_int_array = 11329213292
emit(" sp_IntArray *" + arrnew_tmp + " = sp_IntArray_new();")13293+
# Root the new array before running the block body — pushing13294+
# poly/string values inside the loop can trigger a GC cycle13295+
# that would otherwise sweep the local pointer.13296+
emit(" SP_GC_ROOT(" + arrnew_tmp + ");")1329313297
emit(" for (mrb_int " + arrnew_iv + " = 0; " + arrnew_iv + " < " + arrnew_count + "; " + arrnew_iv + "++) {")13298+
@indent = @indent + 11329413299
if arrnew_bp != ""13295-
emit(" lv_" + arrnew_bp + " = " + arrnew_iv + ";")13300+
emit(" lv_" + arrnew_bp + " = " + arrnew_iv + ";")1329613301
end13297-
@indent = @indent + 11329813302
if arrnew_body >= 01329913303
arrnew_stmts2 = get_stmts(arrnew_body)1330013304
if arrnew_stmts2.length > 0