diff options
author | tromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4> | 2000-02-01 17:36:05 +0000 |
---|---|---|
committer | tromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4> | 2000-02-01 17:36:05 +0000 |
commit | aba6d200cfa0ff2d73155a1db0abe92e4824fac0 (patch) | |
tree | 1d07bd7858af523a73c4b6acc2cd121afc2c7b69 /libjava | |
parent | a602a54fa428e7a8ccec5b534a1afbb45f8e82dd (diff) | |
download | gcc-aba6d200cfa0ff2d73155a1db0abe92e4824fac0.tar.gz |
* jni.cc (_Jv_JNI_PopLocalFrame): Leave loop when `n == NULL'.
(_Jv_JNI_conversion_call): _Jv_JNI_PopLocalFrame will never leave
`locals == NULL'.
(wrap_value): New function.
(_Jv_JNI_CallAnyMethodV): Use it.
(_Jv_JNI_CallAnyMethodA): Likewise.
(_Jv_JNI_GetField): Use wrap_value; removed specialized version.
(_Jv_JNI_GetStaticField): Likewise.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@31736 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava')
-rw-r--r-- | libjava/ChangeLog | 9 | ||||
-rw-r--r-- | libjava/jni.cc | 78 |
2 files changed, 43 insertions, 44 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 4690c3c2c81..906db9d7803 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,5 +1,14 @@ 2000-02-01 Tom Tromey <tromey@cygnus.com> + * jni.cc (_Jv_JNI_PopLocalFrame): Leave loop when `n == NULL'. + (_Jv_JNI_conversion_call): _Jv_JNI_PopLocalFrame will never leave + `locals == NULL'. + (wrap_value): New function. + (_Jv_JNI_CallAnyMethodV): Use it. + (_Jv_JNI_CallAnyMethodA): Likewise. + (_Jv_JNI_GetField): Use wrap_value; removed specialized version. + (_Jv_JNI_GetStaticField): Likewise. + * jni.cc (_Jv_JNI_GetField): Specialize for jobject. (_Jv_JNI_GetStaticField): Likewise. diff --git a/libjava/jni.cc b/libjava/jni.cc index ff8f9a23fb2..1d8ee556014 100644 --- a/libjava/jni.cc +++ b/libjava/jni.cc @@ -255,15 +255,35 @@ _Jv_JNI_PopLocalFrame (JNIEnv *env, jobject result) // must not free it. However, we must be sure to clear all its // elements, since we might conceivably reuse it. if (n == NULL) - memset (&rf->vec[0], 0, rf->size * sizeof (jobject)); - else - _Jv_Free (rf); + { + memset (&rf->vec[0], 0, rf->size * sizeof (jobject)); + break; + } + + _Jv_Free (rf); rf = n; } return result == NULL ? NULL : _Jv_JNI_NewLocalRef (env, result); } +// This function is used from other template functions. It wraps the +// return value appropriately; we specialize it so that object returns +// are turned into local references. +template<typename T> +static T +wrap_value (JNIEnv *, T value) +{ + return value; +} + +template<> +static jobject +wrap_value (JNIEnv *env, jobject value) +{ + return _Jv_JNI_NewLocalRef (env, value); +} + static jint @@ -533,16 +553,8 @@ _Jv_JNI_CallAnyMethodV (JNIEnv *env, jobject obj, jclass klass, if (ex != NULL) env->ex = ex; - if (! return_type->isPrimitive ()) - { - // Make sure we create a local reference. The cast hackery is - // to avoid problems for template instantations we know won't be - // used. - return (T) (long long) _Jv_JNI_NewLocalRef (env, result.l); - } - // We cheat a little here. FIXME. - return * (T *) &result; + return wrap_value (env, * (T *) &result); } template<typename T, invocation_type style> @@ -585,16 +597,8 @@ _Jv_JNI_CallAnyMethodA (JNIEnv *env, jobject obj, jclass klass, if (ex != NULL) env->ex = ex; - if (! return_type->isPrimitive ()) - { - // Make sure we create a local reference. The cast hackery is - // to avoid problems for template instantations we know won't be - // used. - return (T) (long long) _Jv_JNI_NewLocalRef (env, result.l); - } - // We cheat a little here. FIXME. - return * (T *) &result; + return wrap_value (env, * (T *) &result); } template<invocation_type style> @@ -813,18 +817,10 @@ _Jv_JNI_NewObjectA (JNIEnv *env, jclass klass, jmethodID id, template<typename T> static T -_Jv_JNI_GetField (JNIEnv *, jobject obj, jfieldID field) +_Jv_JNI_GetField (JNIEnv *env, jobject obj, jfieldID field) { T *ptr = (T *) ((char *) obj + field->getOffset ()); - return *ptr; -} - -template<> -static jobject -_Jv_JNI_GetField<jobject> (JNIEnv *env, jobject obj, jfieldID field) -{ - jobject *ptr = (jobject *) ((char *) obj + field->getOffset ()); - return _Jv_JNI_NewLocalRef (env, *ptr); + return wrap_value (env, *ptr); } template<typename T> @@ -886,21 +882,12 @@ _Jv_JNI_GetAnyFieldID (JNIEnv *env, jclass clazz, return NULL; } -// FIXME: local reference template<typename T> static T -_Jv_JNI_GetStaticField (JNIEnv *, jclass, jfieldID field) +_Jv_JNI_GetStaticField (JNIEnv *env, jclass, jfieldID field) { T *ptr = (T *) field->u.addr; - return *ptr; -} - -template<> -static jobject -_Jv_JNI_GetStaticField<jobject> (JNIEnv *env, jclass, jfieldID field) -{ - jobject *ptr = (jobject *) field->u.addr; - return _Jv_JNI_NewLocalRef (env, *ptr); + return wrap_value (env, *ptr); } template<typename T> @@ -1240,8 +1227,11 @@ _Jv_JNI_conversion_call (fixme) T result = FIXME_ffi_call (args); - while (env.locals != NULL) - _Jv_JNI_PopLocalFrame (&env, result); + do + { + _Jv_JNI_PopLocalFrame (&env, result); + } + while (env.locals != frame); if (env.ex) JvThrow (env.ex); |