Skip to content

Commit cbec4ee

Browse files
committed
oh make some stuff conditional
1 parent 94759b2 commit cbec4ee

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

mypyc/codegen/emitclass.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,10 +627,10 @@ def generate_dealloc_for_class(cl: ClassIR,
627627
emitter.emit_line('{}({} *self)'.format(dealloc_func_name, cl.struct_name(emitter.names)))
628628
emitter.emit_line('{')
629629
emitter.emit_line('PyObject_GC_UnTrack(self);')
630-
emitter.emit_line('Py_TRASHCAN_BEGIN(self, {})'.format(dealloc_func_name))
630+
emitter.emit_line('CPy_TRASHCAN_BEGIN(self, {})'.format(dealloc_func_name))
631631
emitter.emit_line('{}(self);'.format(clear_func_name))
632632
emitter.emit_line('Py_TYPE(self)->tp_free((PyObject *)self);')
633-
emitter.emit_line('Py_TRASHCAN_END')
633+
emitter.emit_line('CPy_TRASHCAN_END')
634634
emitter.emit_line('}')
635635

636636

mypyc/lib-rt/CPy.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,14 @@ void CPy_AddTraceback(const char *filename, const char *funcname, int line, PyOb
453453

454454
// Misc operations
455455

456+
#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 8
457+
#define CPy_TRASHCAN_BEGIN(op, dealloc) Py_TRASHCAN_BEGIN(op, dealloc)
458+
#define CPy_TRASHCAN_END Py_TRASHCAN_END
459+
#else
460+
#define CPy_TRASHCAN_BEGIN(op, dealloc) Py_TRASHCAN_SAFE_BEGIN(op)
461+
#define CPy_TRASHCAN_END Py_TRASHCAN_SAFE_END
462+
#endif
463+
456464

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

0 commit comments

Comments
 (0)