Skip to content

Commit 4641801

Browse files
committed
fix cython metaclass Sage_PyType_Ready
1 parent 0e2164e commit 4641801

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/sage/cpython/cython_metaclass.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ static CYTHON_INLINE int Sage_PyType_Ready(PyTypeObject* t)
5252
if (r < 0)
5353
return r;
5454

55+
#if PY_VERSION_HEX >= 0x03050000
56+
// Cython 3 sets Py_TPFLAGS_HEAPSIZE before calling PyType_Ready,
57+
// and resets just after the call. We need to do the same, or it may
58+
// end up with illegal memory accesses.
59+
// See also:
60+
// https://github.com/cython/cython/issues/3603
61+
t->tp_flags &= ~Py_TPFLAGS_HEAPTYPE;
62+
#endif
63+
5564
/* Set or get metaclass (the type of t) */
5665
PyTypeObject* metaclass;
5766

0 commit comments

Comments
 (0)