Skip to content

Commit

Permalink
Made getCurrentLocals/Globals work in py3.13
Browse files Browse the repository at this point in the history
  • Loading branch information
jmao-denver committed Aug 30, 2024
1 parent 429c7b0 commit 321c553
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/main/c/jni/org_jpy_PyLib.c
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,11 @@ JNIEXPORT jobject JNICALL Java_org_jpy_PyLib_getCurrentGlobals

JPy_BEGIN_GIL_STATE

#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION > 12
globals = PyEval_GetFrameGlobals(); // new ref
#else
globals = PyEval_GetGlobals(); // borrowed ref
#endif

if (globals == NULL) {
goto error;
Expand All @@ -567,8 +571,11 @@ JNIEXPORT jobject JNICALL Java_org_jpy_PyLib_getCurrentGlobals
}

error:
JPy_END_GIL_STATE
#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION > 12
JPy_XDECREF(globals);
#endif

JPy_END_GIL_STATE
return objectRef;
}

Expand All @@ -579,7 +586,12 @@ JNIEXPORT jobject JNICALL Java_org_jpy_PyLib_getCurrentLocals

JPy_BEGIN_GIL_STATE

locals = PyEval_GetLocals(); // borrowed ref
#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION > 12
locals = PyEval_GetFrameLocals(); // new ref
#else
locals = PyEval_GetLocals(); // borrowed ref
#endif

if (locals == NULL) {
goto error;
}
Expand All @@ -590,8 +602,11 @@ JNIEXPORT jobject JNICALL Java_org_jpy_PyLib_getCurrentLocals
}

error:
JPy_END_GIL_STATE
#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION > 12
JPy_XDECREF(locals);
#endif

JPy_END_GIL_STATE
return objectRef;
}

Expand Down

0 comments on commit 321c553

Please sign in to comment.