@@ -109,6 +109,14 @@ extern PyTypeObject PyGreenlet_Type;
109
109
#define GREENLET_USE_TRACING 1
110
110
#endif
111
111
112
+ #if PY_VERSION_HEX >= 0x030900A4
113
+ /* Py_REFCNT and Py_SIZE macros are converted to functions
114
+ https://bugs.python.org/issue39573 */
115
+ #define __Py_SET_REFCNT (obj , refcnt ) Py_SET_REFCNT(obj, refcnt)
116
+ #else
117
+ #define __Py_SET_REFCNT (obj , refcnt ) Py_REFCNT(obj) = (refcnt)
118
+ #endif
119
+
112
120
#ifndef _Py_DEC_REFTOTAL
113
121
/* _Py_DEC_REFTOTAL macro has been removed from Python 3.9 by:
114
122
https://github.com/python/cpython/commit/49932fec62c616ec88da52642339d83ae719e924 */
@@ -1015,7 +1023,7 @@ static void green_dealloc(PyGreenlet* self)
1015
1023
/* Hacks hacks hacks copied from instance_dealloc() */
1016
1024
/* Temporarily resurrect the greenlet. */
1017
1025
assert (Py_REFCNT (self ) == 0 );
1018
- Py_REFCNT (self ) = 1 ;
1026
+ __Py_SET_REFCNT (self , 1 ) ;
1019
1027
/* Save the current exception, if any. */
1020
1028
PyErr_Fetch (& error_type , & error_value , & error_traceback );
1021
1029
if (kill_greenlet (self ) < 0 ) {
@@ -1044,11 +1052,11 @@ static void green_dealloc(PyGreenlet* self)
1044
1052
* it would cause a recursive call.
1045
1053
*/
1046
1054
assert (Py_REFCNT (self ) > 0 );
1047
- if (-- Py_REFCNT ( self ) != 0 ) {
1055
+ if (-- (( PyObject * )( self )) -> ob_refcnt != 0 ) {
1048
1056
/* Resurrected! */
1049
1057
Py_ssize_t refcnt = Py_REFCNT (self );
1050
1058
_Py_NewReference ((PyObject * ) self );
1051
- Py_REFCNT (self ) = refcnt ;
1059
+ __Py_SET_REFCNT (self , refcnt ) ;
1052
1060
#if GREENLET_USE_GC
1053
1061
PyObject_GC_Track ((PyObject * )self );
1054
1062
#endif
0 commit comments