From e7dd67cbaf3f7c9a22694e5945a73174b884831d Mon Sep 17 00:00:00 2001 From: Jukka Lehtosalo Date: Mon, 19 May 2025 11:46:27 -0400 Subject: [PATCH] [mypyc] Fix incref/decref on free-threaded builds 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. --- mypyc/lib-rt/mypyc_util.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/mypyc/lib-rt/mypyc_util.h b/mypyc/lib-rt/mypyc_util.h index 80019d23bb06..64bf025aec27 100644 --- a/mypyc/lib-rt/mypyc_util.h +++ b/mypyc/lib-rt/mypyc_util.h @@ -31,6 +31,8 @@ // Here just for consistency #define CPy_XDECREF(p) Py_XDECREF(p) +#ifndef Py_GIL_DISABLED + // The *_NO_IMM operations below perform refcount manipulation for // non-immortal objects (Python 3.12 and later). // @@ -60,6 +62,14 @@ static inline void CPy_XDECREF_NO_IMM(PyObject *op) #define CPy_DECREF_NO_IMM(op) CPy_DECREF_NO_IMM((PyObject *)(op)) #define CPy_XDECREF_NO_IMM(op) CPy_XDECREF_NO_IMM((PyObject *)(op)) +#else + +#define CPy_INCREF_NO_IMM(op) CPy_INCREF(op) +#define CPy_DECREF_NO_IMM(op) CPy_DECREF(op) +#define CPy_XDECREF_NO_IMM(op) CPy_XDECREF(op) + +#endif + // Tagged integer -- our representation of Python 'int' objects. // Small enough integers are represented as unboxed integers (shifted // left by 1); larger integers (larger than 63 bits on a 64-bit