Skip to content

Commit ea8b1b2

Browse files
committed
Clean up final types in the case of an error
Make sure we clean up finals if we run into an error while running the initialization code.
1 parent ff3d717 commit ea8b1b2

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

mypyc/codegen/emitmodule.py

Lines changed: 7 additions & 1 deletion
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
39+
from mypyc.ir.rtypes import RType, RTuple, is_tagged
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,6 +925,12 @@ def generate_module_def(self, emitter: Emitter, module_name: str, module: Module
925925
'Py_XDECREF(modname);')
926926
# the type objects returned from CPyType_FromTemplate are all new references
927927
# so we have to decref them
928+
for name, typ in module.final_names:
929+
static_name = emitter.static_name(name, module_name)
930+
if emitter.ctype(typ) == 'PyObject *':
931+
emitter.emit_line('Py_CLEAR({});'.format(static_name))
932+
elif is_tagged(typ):
933+
emitter.emit_line('CPyTagged_XDecRef({});'.format(static_name))
928934
for t in type_structs:
929935
emitter.emit_line('Py_XDECREF({});'.format(t))
930936
emitter.emit_line('return NULL;')

0 commit comments

Comments
 (0)