From 1f11fa4c69836bb4dc157b0e54188b964a46384e Mon Sep 17 00:00:00 2001 From: Devin Smith Date: Thu, 19 May 2022 10:06:53 -0700 Subject: [PATCH] Guard Py_SET_REFCNT to Python 3.9+ --- src/main/c/jpy_compat.h | 3 +++ src/main/c/jpy_jobj.c | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/c/jpy_compat.h b/src/main/c/jpy_compat.h index 62f969bc..3be3ec6b 100644 --- a/src/main/c/jpy_compat.h +++ b/src/main/c/jpy_compat.h @@ -33,6 +33,9 @@ extern "C" { #if PY_MINOR_VERSION >= 5 #define JPY_COMPAT_35P 1 #endif +#if PY_MINOR_VERSION >= 9 +#define JPY_COMPAT_39P 1 +#endif #undef JPY_COMPAT_27 #else #error JPY_VERSION_ERROR diff --git a/src/main/c/jpy_jobj.c b/src/main/c/jpy_jobj.c index 8a439420..af76def0 100644 --- a/src/main/c/jpy_jobj.c +++ b/src/main/c/jpy_jobj.c @@ -713,7 +713,11 @@ int JType_InitSlots(JPy_JType* type) typeObj = JTYPE_AS_PYTYPE(type); - Py_SET_REFCNT(typeObj, 1); + #if defined(JPY_COMPAT_39P) + Py_SET_REFCNT(typeObj, 1); + #else + Py_REFCNT(typeObj) = 1; + #endif Py_TYPE(typeObj) = NULL; Py_SIZE(typeObj) = 0; // todo: The following lines are actually correct, but setting Py_TYPE(type) = &JType_Type results in an interpreter crash. Why?