Skip to content

Commit ebe20ed

Browse files
committed
Improve handling of other final types in cleanup
Improve the handling of final values for types other than python objects and tagged integers by using emit_dec_ref and c_undefined_value. In particular, this should handle tuples correctly and make sure to clear tagged integers correctly.
1 parent ff8d287 commit ebe20ed

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

mypyc/codegen/emitmodule.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
generate_legacy_wrapper_function, legacy_wrapper_function_header,
3737
)
3838
from mypyc.ir.ops import DeserMaps, LoadLiteral
39-
from mypyc.ir.rtypes import RType, RTuple, is_tagged
39+
from mypyc.ir.rtypes import RType, RTuple
4040
from mypyc.ir.func_ir import FuncIR
4141
from mypyc.ir.class_ir import ClassIR
4242
from mypyc.ir.module_ir import ModuleIR, ModuleIRs, deserialize_modules
@@ -925,10 +925,9 @@ def generate_module_def(self, emitter: Emitter, module_name: str, module: Module
925925
'Py_CLEAR(modname);')
926926
for name, typ in module.final_names:
927927
static_name = emitter.static_name(name, module_name)
928-
if emitter.ctype(typ) == 'PyObject *':
929-
emitter.emit_line('Py_CLEAR({});'.format(static_name))
930-
elif is_tagged(typ):
931-
emitter.emit_line('CPyTagged_XDecRef({});'.format(static_name))
928+
emitter.emit_dec_ref(static_name, typ, is_xdec=True)
929+
undef = emitter.c_undefined_value(typ)
930+
emitter.emit_line('{} = {};'.format(static_name, undef))
932931
# the type objects returned from CPyType_FromTemplate are all new references
933932
# so we have to decref them
934933
for t in type_structs:

0 commit comments

Comments
 (0)