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

Check for exception in getInt/Long/DoubleValue() #99

Merged
Merged
Changes from all commits
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
14 changes: 13 additions & 1 deletion src/main/c/jni/org_jpy_PyLib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1196,6 +1196,11 @@ JNIEXPORT jint JNICALL Java_org_jpy_PyLib_getIntValue

pyObject = (PyObject*) objId;
value = (jint) JPy_AS_CLONG(pyObject);
// Note: we are not handling the overflow case, but there might be a need to have getIntValueSafe() in the future
if (value == -1 && PyErr_Occurred()) {
JPy_DIAG_PRINT(JPy_DIAG_F_ALL, "Java_org_jpy_PyLib_getIntValue: error: failed to convert Python object to Java int\n");
PyLib_HandlePythonException(jenv);
}

JPy_END_GIL_STATE

Expand All @@ -1217,7 +1222,10 @@ JNIEXPORT jlong JNICALL Java_org_jpy_PyLib_getLongValue

pyObject = (PyObject*) objId;
value = JPy_AS_CLONG(pyObject);

if (value == -1 && PyErr_Occurred()) {
JPy_DIAG_PRINT(JPy_DIAG_F_ALL, "Java_org_jpy_PyLib_getLongValue: error: failed to convert Python object to Java long\n");
PyLib_HandlePythonException(jenv);
}
jmao-denver marked this conversation as resolved.
Show resolved Hide resolved
JPy_END_GIL_STATE

return value;
Expand Down Expand Up @@ -1262,6 +1270,10 @@ JNIEXPORT jdouble JNICALL Java_org_jpy_PyLib_getDoubleValue

pyObject = (PyObject*) objId;
value = (jdouble) PyFloat_AsDouble(pyObject);
if (value == -1.0 && PyErr_Occurred()) {
JPy_DIAG_PRINT(JPy_DIAG_F_ALL, "Java_org_jpy_PyLib_getDoubleValue: error: failed to convert Python object to Java double\n");
PyLib_HandlePythonException(jenv);
}

JPy_END_GIL_STATE

Expand Down