@@ -526,6 +526,9 @@ def emit_inc_ref(self, dest: str, rtype: RType, *, rare: bool = False) -> None:
526526 elif isinstance (rtype , RTuple ):
527527 for i , item_type in enumerate (rtype .types ):
528528 self .emit_inc_ref (f"{ dest } .f{ i } " , item_type )
529+ elif isinstance (rtype , RInstanceValue ):
530+ for i , (attr , attr_type ) in enumerate (rtype .class_ir .all_attributes ().items ()):
531+ self .emit_inc_ref (f"{ dest } .{ self .attr (attr )} " , attr_type )
529532 elif not rtype .is_unboxed :
530533 # Always inline, since this is a simple op
531534 self .emit_line ("CPy_INCREF(%s);" % dest )
@@ -1089,7 +1092,7 @@ def emit_box(
10891092 attr_name = self .attr (attr )
10901093 self .emit_line (f"{ temp_dest } ->{ attr_name } = { src } .{ attr_name } ;" , ann = "box" )
10911094 if attr_type .is_refcounted :
1092- self .emit_inc_ref (temp_dest , attr_type )
1095+ self .emit_inc_ref (f" { temp_dest } -> { attr_name } " , attr_type )
10931096
10941097 self .emit_line (f"{ declaration } { dest } = (PyObject *){ temp_dest } ;" )
10951098 else :
@@ -1131,6 +1134,9 @@ def emit_gc_visit(self, target: str, rtype: RType) -> None:
11311134 elif isinstance (rtype , RTuple ):
11321135 for i , item_type in enumerate (rtype .types ):
11331136 self .emit_gc_visit (f"{ target } .f{ i } " , item_type )
1137+ elif isinstance (rtype , RInstanceValue ):
1138+ for i , (attr , attr_type ) in enumerate (rtype .class_ir .all_attributes ().items ()):
1139+ self .emit_gc_visit (f"{ target } .{ self .attr (attr )} " , attr_type )
11341140 elif self .ctype (rtype ) == "PyObject *" :
11351141 # The simplest case.
11361142 self .emit_line (f"Py_VISIT({ target } );" )
@@ -1155,6 +1161,9 @@ def emit_gc_clear(self, target: str, rtype: RType) -> None:
11551161 elif isinstance (rtype , RTuple ):
11561162 for i , item_type in enumerate (rtype .types ):
11571163 self .emit_gc_clear (f"{ target } .f{ i } " , item_type )
1164+ elif isinstance (rtype , RInstanceValue ):
1165+ for i , (attr , attr_type ) in enumerate (rtype .class_ir .all_attributes ().items ()):
1166+ self .emit_gc_clear (f"{ target } .{ self .attr (attr )} " , attr_type )
11581167 elif self .ctype (rtype ) == "PyObject *" and self .c_undefined_value (rtype ) == "NULL" :
11591168 # The simplest case.
11601169 self .emit_line (f"Py_CLEAR({ target } );" )
0 commit comments