Skip to content

Commit 750a579

Browse files
authored
[mypyc] Fix incref/decref on free-threaded builds (#19127)
Fix C compile errors on free-threaded builds. We can't (easily) access the reference count value directly, so always use the C API functions when on a free-threaded build. Work on mypyc/mypyc#1038.
1 parent 50734e9 commit 750a579

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

mypyc/lib-rt/mypyc_util.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
// Here just for consistency
3232
#define CPy_XDECREF(p) Py_XDECREF(p)
3333

34+
#ifndef Py_GIL_DISABLED
35+
3436
// The *_NO_IMM operations below perform refcount manipulation for
3537
// non-immortal objects (Python 3.12 and later).
3638
//
@@ -60,6 +62,14 @@ static inline void CPy_XDECREF_NO_IMM(PyObject *op)
6062
#define CPy_DECREF_NO_IMM(op) CPy_DECREF_NO_IMM((PyObject *)(op))
6163
#define CPy_XDECREF_NO_IMM(op) CPy_XDECREF_NO_IMM((PyObject *)(op))
6264

65+
#else
66+
67+
#define CPy_INCREF_NO_IMM(op) CPy_INCREF(op)
68+
#define CPy_DECREF_NO_IMM(op) CPy_DECREF(op)
69+
#define CPy_XDECREF_NO_IMM(op) CPy_XDECREF(op)
70+
71+
#endif
72+
6373
// Tagged integer -- our representation of Python 'int' objects.
6474
// Small enough integers are represented as unboxed integers (shifted
6575
// left by 1); larger integers (larger than 63 bits on a 64-bit

0 commit comments

Comments
 (0)