Commit 45fae0a0

45fae0a0846aMerged

fc-anjos <[email protected]> · 6 months ago · 5 files · +4 added · ~1 modified

Description

fix value-type GC tracing

Co-Authored-By: OpenAI Codex 5.5

Details

Commit
45fae0a0846a
Parent
234e29dfa690

spinel_codegen.rbmodifiedView file

@@ -8508,13 +8508,27 @@
85088508 0
85098509 end
85108510
8511+ def ivar_needs_gc_mark(t)
8512+ if ivar_is_gc_ptr(t) == 1
8513+ return 1
8514+ end
8515+ if is_value_type_obj(t) == 1
8516+ cname = t[4, t.length - 4]
8517+ ci = find_class_idx(cname)
8518+ if ci >= 0 && class_has_ptr_ivars(ci) == 1
8519+ return 1
8520+ end
8521+ end
8522+ 0
8523+ end
8524+
85118525 def class_has_ptr_ivars(ci)
85128526 names = @cls_ivar_names[ci].split(";")
85138527 types = @cls_ivar_types[ci].split(";")
85148528 j = 0
85158529 while j < names.length
85168530 if j < types.length
8517- if ivar_is_gc_ptr(types[j]) == 1
8531+ if ivar_needs_gc_mark(types[j]) == 1
85188532 return 1
85198533 end
85208534 end
@@ -8568,12 +8582,28 @@
85688582 def emit_gc_mark_ivar(field, t)
85698583 if t == "poly"
85708584 emit_raw(" sp_mark_rbval(" + field + ");")
8585+ elsif is_value_type_obj(t) == 1
8586+ cname = t[4, t.length - 4]
8587+ emit_raw(" sp_" + cname + "_gc_scan(&" + field + ");")
85718588 else
85728589 emit_raw(" if (" + field + ") sp_gc_mark((void *)" + field + ");")
85738590 end
85748591 end
85758592
85768593 def emit_gc_scan_functions
8594+ emitted_proto = 0
8595+ i = 0
8596+ while i < @cls_names.length
8597+ if cls_emit_skipped(i) == 0 && class_has_ptr_ivars(i) == 1
8598+ emit_raw("static void sp_" + @cls_names[i] + "_gc_scan(void *p);")
8599+ emitted_proto = 1
8600+ end
8601+ i = i + 1
8602+ end
8603+ if emitted_proto == 1
8604+ emit_raw("")
8605+ end
8606+
85778607 i = 0
85788608 while i < @cls_names.length
85798609 if cls_emit_skipped(i) == 1
@@ -8605,7 +8635,7 @@
86058635 end
86068636 end
86078637 end
8608- if skip_inherited == 0 && ivar_is_gc_ptr(types[j]) == 1
8638+ if skip_inherited == 0 && ivar_needs_gc_mark(types[j]) == 1
86098639 emit_gc_mark_ivar("self->" + sanitize_ivar(names[j]), types[j])
86108640 end
86118641 end
@@ -8620,7 +8650,7 @@
86208650 pj = 0
86218651 while pj < pnames.length
86228652 if pj < ptypes.length
8623- if ivar_is_gc_ptr(ptypes[pj]) == 1
8653+ if ivar_needs_gc_mark(ptypes[pj]) == 1
86248654 emit_gc_mark_ivar("self->" + sanitize_ivar(pnames[pj]), ptypes[pj])
86258655 end
86268656 end
@@ -24908,7 +24938,7 @@
2490824938 def constructor_arg_needs_root(arg_type)
2490924939 bt = base_type(arg_type)
2491024940 if is_obj_type(bt) == 1
24911- return 1
24941+ return type_is_pointer(bt)
2491224942 end
2491324943 if is_array_type(bt) == 1 || is_ptr_array_type(bt) == 1 || is_tuple_type(bt) == 1
2491424944 return 1