-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify and improve error message for the object case of convert_pya…
…rg_jvalue.
- Loading branch information
1 parent
52ef441
commit c53e591
Showing
1 changed file
with
27 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1172,59 +1172,37 @@ jvalue convert_pyarg_jvalue(JNIEnv *env, | |
} | ||
|
||
case JOBJECT_ID: { | ||
jobject obj = NULL; | ||
// none is okay, we'll translate to null | ||
if (param == Py_None) { | ||
; | ||
} else if (PyString_Check(param)) { | ||
char *val; | ||
|
||
// strings count as objects here | ||
if (!(*env)->IsAssignableFrom(env, | ||
JSTRING_TYPE, | ||
paramType)) { | ||
PyErr_Format( | ||
PyExc_TypeError, | ||
"Tried to set a string on an incomparable parameter %i.", | ||
pos + 1); | ||
return ret; | ||
} | ||
|
||
val = PyString_AsString(param); | ||
obj = (*env)->NewStringUTF(env, (const char *) val); | ||
} | ||
#if JEP_NUMPY_ENABLED | ||
else if (npy_array_check(param)) { | ||
ret.l = convert_pyndarray_jndarray(env, param); | ||
return ret; | ||
} | ||
#endif | ||
else { | ||
if (!pyjobject_check(param)) { | ||
obj = pyembed_box_py(env, param); | ||
if ((*env)->IsInstanceOf(env, obj, paramType)){ | ||
ret.l = obj; | ||
}else{ | ||
PyErr_Format(PyExc_TypeError, | ||
"Expected object parameter at %i.", | ||
pos + 1); | ||
} | ||
return ret; | ||
jobject obj = pyembed_box_py(env, param); | ||
if (obj != NULL && !(*env)->IsInstanceOf(env, obj, paramType)) { | ||
jmethodID getName; | ||
jstring expTypeJavaName, actTypeJavaName = NULL; | ||
const char *expTypeName, *actTypeName; | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
|
||
getName = (*env)->GetMethodID(env, JCLASS_TYPE, "getName", | ||
"()Ljava/lang/String;"); | ||
This comment has been minimized.
Sorry, something went wrong.
ndjensen
Member
|
||
expTypeJavaName = (*env)->CallObjectMethod(env, paramType, getName); | ||
expTypeName = (*env)->GetStringUTFChars(env, expTypeJavaName, 0); | ||
if (pyjclass_check(param)) { | ||
actTypeJavaName = (*env)->CallObjectMethod(env, JCLASS_TYPE, getName); | ||
actTypeName = (*env)->GetStringUTFChars(env, actTypeJavaName, 0); | ||
} else if (pyjobject_check(param)) { | ||
actTypeJavaName = (*env)->CallObjectMethod(env, ((PyJObject *) param)->clazz, | ||
getName); | ||
actTypeName = (*env)->GetStringUTFChars(env, actTypeJavaName, 0); | ||
} else { | ||
actTypeName = param->ob_type->tp_name; | ||
} | ||
|
||
// check object itself is assignable to that type. | ||
if (!(*env)->IsAssignableFrom(env, | ||
((PyJObject *) param)->clazz, | ||
paramType)) { | ||
PyErr_Format(PyExc_TypeError, | ||
"Incorrect object type at %i.", | ||
pos + 1); | ||
return ret; | ||
PyErr_Format(PyExc_TypeError, | ||
"Expected %s at parameter %i but received a %s.", | ||
expTypeName, pos + 1, actTypeName); | ||
(*env)->ReleaseStringUTFChars(env, expTypeJavaName, expTypeName); | ||
if (actTypeJavaName) { | ||
(*env)->ReleaseStringUTFChars(env, actTypeJavaName, actTypeName); | ||
} | ||
|
||
obj = ((PyJObject *) param)->object; | ||
obj = NULL; | ||
} | ||
|
||
ret.l = obj; | ||
return ret; | ||
} | ||
|
Two blank lines is weird.