Skip to content

Commit

Permalink
Guard Py_SET_REFCNT to Python 3.9+ (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
devinrsmith authored May 19, 2022
1 parent e86b5f8 commit c6443fd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/main/c/jpy_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/main/c/jpy_jobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down

0 comments on commit c6443fd

Please sign in to comment.