Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions mypyc/codegen/emitclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,8 +627,11 @@ def generate_dealloc_for_class(cl: ClassIR,
emitter.emit_line('{}({} *self)'.format(dealloc_func_name, cl.struct_name(emitter.names)))
emitter.emit_line('{')
emitter.emit_line('PyObject_GC_UnTrack(self);')
# The trashcan is needed to handle deep recursive deallocations
emitter.emit_line('CPy_TRASHCAN_BEGIN(self, {})'.format(dealloc_func_name))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add short description of why we need to do this.

emitter.emit_line('{}(self);'.format(clear_func_name))
emitter.emit_line('Py_TYPE(self)->tp_free((PyObject *)self);')
emitter.emit_line('CPy_TRASHCAN_END(self)')
emitter.emit_line('}')


Expand Down
8 changes: 8 additions & 0 deletions mypyc/lib-rt/CPy.h
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,14 @@ void CPy_AddTraceback(const char *filename, const char *funcname, int line, PyOb

// Misc operations

#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 8
#define CPy_TRASHCAN_BEGIN(op, dealloc) Py_TRASHCAN_BEGIN(op, dealloc)
#define CPy_TRASHCAN_END(op) Py_TRASHCAN_END
#else
#define CPy_TRASHCAN_BEGIN(op, dealloc) Py_TRASHCAN_SAFE_BEGIN(op)
#define CPy_TRASHCAN_END(op) Py_TRASHCAN_SAFE_END(op)
#endif


// mypy lets ints silently coerce to floats, so a mypyc runtime float
// might be an int also
Expand Down