Commit d1954cab
d1954cab98d6Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 2 files · +1 added · ~1 modified
Description
Merge pull request #263 from mame/pr/poly-array-slot-sized-default
fix(codegen): poly_array slot consumes sized-empty default via PolyArray
Details
- Commit
- d1954cab98d6
- Parent
- 58a4b5bfd49e
- Merge parent
- b126003a2465
spinel_codegen.rbmodifiedView file
@@ -15049,16 +15049,23 @@
1504915049
if iv_ctor != ""1505015050
@needs_gc = 11505115051
emit_raw(" " + self_arrow + ivar + " = " + iv_ctor + ";")15052-
elsif is_ptr_array_type(ivt) == 1 && is_sized_empty_array_default(expr_id_iv) == 115052+
elsif (ivt == "poly_array" || is_ptr_array_type(ivt) == 1) && is_sized_empty_array_default(expr_id_iv) == 11505315053
# `@arr = [nil] * N` with @arr already widened to15054-
# ptr_array via writer-scan. The default `*` codegen15055-
# produces an sp_IntArray that mismatches the slot15056-
# type; emit a sized PtrArray of NULLs inline.15054+
# poly_array (or ptr_array) via writer-scan. The15055+
# default `*` codegen produces an sp_IntArray that15056+
# mismatches the slot type; emit a sized PolyArray15057+
# of sp_box_nil() (or PtrArray of NULLs) inline.1505715058
@needs_gc = 11505815059
cnt_e_iv = compile_arg0(expr_id_iv)1505915060
tmp_iv = new_temp15060-
emit_raw(" sp_PtrArray *" + tmp_iv + " = sp_PtrArray_new();")15061-
emit_raw(" { mrb_int _n = " + cnt_e_iv + "; for (mrb_int _i = 0; _i < _n; _i++) sp_PtrArray_push(" + tmp_iv + ", NULL); }")15061+
if ivt == "poly_array"15062+
@needs_rb_value = 115063+
emit_raw(" sp_PolyArray *" + tmp_iv + " = sp_PolyArray_new();")15064+
emit_raw(" { mrb_int _n = " + cnt_e_iv + "; for (mrb_int _i = 0; _i < _n; _i++) sp_PolyArray_push(" + tmp_iv + ", sp_box_nil()); }")15065+
else15066+
emit_raw(" sp_PtrArray *" + tmp_iv + " = sp_PtrArray_new();")15067+
emit_raw(" { mrb_int _n = " + cnt_e_iv + "; for (mrb_int _i = 0; _i < _n; _i++) sp_PtrArray_push(" + tmp_iv + ", NULL); }")15068+
end1506215069
emit_raw(" " + self_arrow + ivar + " = " + tmp_iv + ";")1506315070
elsif ivt == "poly_array" && @nd_type[expr_id_iv] == "ArrayNode"1506415071
# Non-empty array literal `[a, b, ...]` going into a@@ -24756,17 +24763,24 @@
2475624763
return2475724764
end2475824765
end24759-
# `@arr = [nil] * N` where @arr is a ptr_array slot. The24760-
# default `*` codegen produces an sp_IntArray, which mismatches24761-
# the slot type and corrupts later sp_PtrArray_set calls. Emit24762-
# a sized PtrArray pre-filled with NULLs inline so the slot24766+
# `@arr = [nil] * N` where @arr is a poly_array (or ptr_array)24767+
# slot. The default `*` codegen produces an sp_IntArray, which24768+
# mismatches the slot type and corrupts later24769+
# `sp_PolyArray_set(@arr, ...)` calls. Emit a sized PolyArray24770+
# of sp_box_nil() (or PtrArray of NULLs) inline so the slot2476324771
# holds the matching storage.24764-
if is_ptr_array_type(ivt) == 1 && is_sized_empty_array_default(expr_id) == 124772+
if (ivt == "poly_array" || is_ptr_array_type(ivt) == 1) && is_sized_empty_array_default(expr_id) == 12476524773
@needs_gc = 12476624774
cnt_e = compile_arg0(expr_id)2476724775
tmp_arr = new_temp24768-
emit(" sp_PtrArray *" + tmp_arr + " = sp_PtrArray_new();")24769-
emit(" { mrb_int _n = " + cnt_e + "; for (mrb_int _i = 0; _i < _n; _i++) sp_PtrArray_push(" + tmp_arr + ", NULL); }")24776+
if ivt == "poly_array"24777+
@needs_rb_value = 124778+
emit(" sp_PolyArray *" + tmp_arr + " = sp_PolyArray_new();")24779+
emit(" { mrb_int _n = " + cnt_e + "; for (mrb_int _i = 0; _i < _n; _i++) sp_PolyArray_push(" + tmp_arr + ", sp_box_nil()); }")24780+
else24781+
emit(" sp_PtrArray *" + tmp_arr + " = sp_PtrArray_new();")24782+
emit(" { mrb_int _n = " + cnt_e + "; for (mrb_int _i = 0; _i < _n; _i++) sp_PtrArray_push(" + tmp_arr + ", NULL); }")24783+
end2477024784
emit(" " + self_arrow + sanitize_ivar(iname) + " = " + tmp_arr + ";")2477124785
return2477224786
endtest/poly_array_slot_sized_default.rbaddedView file
Loading diff…