Commit 878007c9

878007c9e39bMerged

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

Description

Merge pull request #117 from sacckey/fix/gc-save-dup-in-constructor

fix(codegen): avoid duplicate SP_GC_SAVE in constructor initialize path

Details

Commit
878007c9e39b
Parent
f26cd7ee8cee
Merge parent
dd98bebebd7d

spinel_codegen.rbmodifiedView file

@@ -10598,6 +10598,7 @@
1059810598 end
1059910599
1060010600 def emit_constructor(ci)
10601+ saved_gc_scope = @in_gc_scope
1060110602 cname = @cls_names[ci]
1060210603 init_idx = cls_find_method_direct(ci, "initialize")
1060310604 if @cls_is_value_type[ci] == 1
@@ -10606,6 +10607,7 @@
1060610607 else
1060710608 emit_raw("static inline sp_" + cname + " *sp_" + cname + "_new(" + constructor_params_decl(ci) + ") {")
1060810609 emit_raw(" SP_GC_SAVE();")
10610+ @in_gc_scope = 1
1060910611 scan_fn = "NULL"
1061010612 if class_has_ptr_ivars(ci) == 1
1061110613 scan_fn = "sp_" + cname + "_gc_scan"
@@ -10758,6 +10760,7 @@
1075810760 emit_raw(" return self;")
1075910761 emit_raw("}")
1076010762 emit_raw("")
10763+ @in_gc_scope = saved_gc_scope
1076110764
1076210765 # Initialize function (for super calls) - always uses *self (pointer)
1076310766 if init_idx >= 0
@@ -11141,7 +11144,7 @@
1114111144 j = j + 1
1114211145 end
1114311146 if has_gc_locals == 1
11144- if @needs_gc == 1
11147+ if @needs_gc == 1 && @in_gc_scope == 0
1114511148 emit(" SP_GC_SAVE();")
1114611149 @in_gc_scope = 1
1114711150 end