Skip to content

Commit c942ddb

Browse files
committed
Adding NULL check for del_str.
1 parent 0ee7f61 commit c942ddb

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

mypyc/codegen/emitclass.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,9 @@ def generate_finalize_for_class(
812812
)
813813
emitter.emit_line("if (PyErr_Occurred() != NULL) {")
814814
emitter.emit_line('PyObject *del_str = PyUnicode_FromString("__del__");')
815-
emitter.emit_line("PyObject *del_method = _PyType_Lookup(Py_TYPE(self), del_str);")
815+
emitter.emit_line(
816+
"PyObject *del_method = (del_str == NULL) ? NULL : _PyType_Lookup(Py_TYPE(self), del_str);"
817+
)
816818
# CPython interpreter uses PyErr_WriteUnraisable: https://docs.python.org/3/c-api/exceptions.html#c.PyErr_WriteUnraisable
817819
# However, the message is slightly different due to the way mypyc compiles classes.
818820
# CPython interpreter prints: Exception ignored in: <function F.__del__ at 0x100aed940>

0 commit comments

Comments
 (0)