Skip to content

Commit c43a915

Browse files
author
1.v3m
committed
Resolves #169
1 parent 89c5524 commit c43a915

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

greenlet.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,14 @@ extern PyTypeObject PyGreenlet_Type;
109109
#define GREENLET_USE_TRACING 1
110110
#endif
111111

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+
112120
#ifndef _Py_DEC_REFTOTAL
113121
/* _Py_DEC_REFTOTAL macro has been removed from Python 3.9 by:
114122
https://github.com/python/cpython/commit/49932fec62c616ec88da52642339d83ae719e924 */
@@ -1015,7 +1023,7 @@ static void green_dealloc(PyGreenlet* self)
10151023
/* Hacks hacks hacks copied from instance_dealloc() */
10161024
/* Temporarily resurrect the greenlet. */
10171025
assert(Py_REFCNT(self) == 0);
1018-
Py_REFCNT(self) = 1;
1026+
__Py_SET_REFCNT(self, 1);
10191027
/* Save the current exception, if any. */
10201028
PyErr_Fetch(&error_type, &error_value, &error_traceback);
10211029
if (kill_greenlet(self) < 0) {
@@ -1044,11 +1052,11 @@ static void green_dealloc(PyGreenlet* self)
10441052
* it would cause a recursive call.
10451053
*/
10461054
assert(Py_REFCNT(self) > 0);
1047-
if (--Py_REFCNT(self) != 0) {
1055+
if (--((PyObject*)(self))->ob_refcnt != 0) {
10481056
/* Resurrected! */
10491057
Py_ssize_t refcnt = Py_REFCNT(self);
10501058
_Py_NewReference((PyObject*) self);
1051-
Py_REFCNT(self) = refcnt;
1059+
__Py_SET_REFCNT(self, refcnt);
10521060
#if GREENLET_USE_GC
10531061
PyObject_GC_Track((PyObject *)self);
10541062
#endif

0 commit comments

Comments
 (0)