Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Make org.jpy.PyLib.getCurrentLocals/Globals work for Python 3.13 #164

Merged
merged 3 commits into from
Sep 23, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
jmao-denver marked this conversation as resolved.
Show resolved Hide resolved
#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);
jmao-denver marked this conversation as resolved.
Show resolved Hide resolved
#endif

JPy_END_GIL_STATE
return objectRef;
}

Expand Down
Loading