From ca4011782b8a732e635af574c30014f927010f82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Wed, 30 Jul 2025 13:11:22 +0200 Subject: [PATCH] Redefine `_Py_DEC_REFTOTAL` as a private macro to fix py3.14 build Redefine `_Py_DEC_REFTOTAL` as a private `GREENLET_Py_DEC_REFTOTAL` macro rather than under the original name, to fix conflicts with CPython's private macro that cause the build to fail with Python 3.14. Fixes #458 --- src/greenlet/PyGreenlet.cpp | 2 +- src/greenlet/greenlet_cpython_compat.hpp | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/greenlet/PyGreenlet.cpp b/src/greenlet/PyGreenlet.cpp index 29c0bba0..67a9a728 100644 --- a/src/greenlet/PyGreenlet.cpp +++ b/src/greenlet/PyGreenlet.cpp @@ -249,7 +249,7 @@ _green_dealloc_kill_started_non_main_greenlet(BorrowedGreenlet self) PyObject_GC_Track((PyObject*)self); - _Py_DEC_REFTOTAL; + GREENLET_Py_DEC_REFTOTAL; #ifdef COUNT_ALLOCS --Py_TYPE(self)->tp_frees; --Py_TYPE(self)->tp_allocs; diff --git a/src/greenlet/greenlet_cpython_compat.hpp b/src/greenlet/greenlet_cpython_compat.hpp index 979d6f94..a3b3850e 100644 --- a/src/greenlet/greenlet_cpython_compat.hpp +++ b/src/greenlet/greenlet_cpython_compat.hpp @@ -73,7 +73,9 @@ Greenlet won't compile on anything older than Python 3.11 alpha 4 (see # define Py_SET_REFCNT(obj, refcnt) Py_REFCNT(obj) = (refcnt) #endif -#ifndef _Py_DEC_REFTOTAL +#ifdef _Py_DEC_REFTOTAL +# define GREENLET_Py_DEC_REFTOTAL _Py_DEC_REFTOTAL +#else /* _Py_DEC_REFTOTAL macro has been removed from Python 3.9 by: https://github.com/python/cpython/commit/49932fec62c616ec88da52642339d83ae719e924 @@ -81,12 +83,12 @@ Greenlet won't compile on anything older than Python 3.11 alpha 4 (see */ # ifdef Py_REF_DEBUG # if GREENLET_PY312 -# define _Py_DEC_REFTOTAL +# define GREENLET_Py_DEC_REFTOTAL # else -# define _Py_DEC_REFTOTAL _Py_RefTotal-- +# define GREENLET_Py_DEC_REFTOTAL _Py_RefTotal-- # endif # else -# define _Py_DEC_REFTOTAL +# define GREENLET_Py_DEC_REFTOTAL # endif #endif // Define these flags like Cython does if we're on an old version.