Skip to content
This repository was archived by the owner on Aug 5, 2021. It is now read-only.

Commit e5b6e05

Browse files
authored
Merge pull request #120 from sbarnoud/patch-1
Corrected Java reference count of complex PyObject passed back and forth to methods
2 parents 4f9aacc + 2adb8fe commit e5b6e05

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/main/c/jni/org_jpy_PyLib.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,14 @@ PyObject* PyLib_CallAndReturnObject(JNIEnv *jenv, PyObject* pyObject, jboolean i
929929
(*jenv)->DeleteLocalRef(jenv, jParamClass);
930930
} else {
931931
pyArg = JPy_FromJObject(jenv, jArg);
932+
// We must keep unchanged the reference counter when calling a Python method
933+
// with a complex Python object as parameter.
934+
// Per example:
935+
// PyObject x = pymodule.call("create_dataFrame");
936+
// String[] columns = pymodule.call("list",x.columns.values).getObjectArrayValue(String.class);
937+
if (paramType->componentType == NULL && paramType == JPy_JPyObject) {
938+
Py_INCREF(pyArg);
939+
}
932940
}
933941

934942
(*jenv)->DeleteLocalRef(jenv, jArg);

0 commit comments

Comments
 (0)