diff options
author | Graydon Hoare <graydon@redhat.com> | 2003-08-20 19:37:21 +0000 |
---|---|---|
committer | Graydon Hoare <graydon@gcc.gnu.org> | 2003-08-20 19:37:21 +0000 |
commit | 4d6a988ac5c6d79f131575cc3ed431a4229bde0e (patch) | |
tree | 334a8c10542371fe374eecea1486866cffe5bc21 /libjava/jni.cc | |
parent | 13bef471ea25553d663543a3d9534a8f1ef10a1b (diff) | |
download | gcc-4d6a988ac5c6d79f131575cc3ed431a4229bde0e.tar.gz |
jni.cc: Replace "cheating" pointer-casting code with extract_from_jvalue<> template.
2003-08-20 Graydon Hoare <graydon@redhat.com>
* jni.cc: Replace "cheating" pointer-casting code with
extract_from_jvalue<> template.
From-SVN: r70613
Diffstat (limited to 'libjava/jni.cc')
-rw-r--r-- | libjava/jni.cc | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/libjava/jni.cc b/libjava/jni.cc index 47017dc8c18..49779078639 100644 --- a/libjava/jni.cc +++ b/libjava/jni.cc @@ -418,6 +418,18 @@ _Jv_JNI_PopSystemFrame (JNIEnv *env) } } +template<typename T> T extract_from_jvalue(jvalue const & t); +template<> jboolean extract_from_jvalue(jvalue const & jv) { return jv.z; } +template<> jbyte extract_from_jvalue(jvalue const & jv) { return jv.b; } +template<> jchar extract_from_jvalue(jvalue const & jv) { return jv.c; } +template<> jshort extract_from_jvalue(jvalue const & jv) { return jv.s; } +template<> jint extract_from_jvalue(jvalue const & jv) { return jv.i; } +template<> jlong extract_from_jvalue(jvalue const & jv) { return jv.j; } +template<> jfloat extract_from_jvalue(jvalue const & jv) { return jv.f; } +template<> jdouble extract_from_jvalue(jvalue const & jv) { return jv.d; } +template<> jobject extract_from_jvalue(jvalue const & jv) { return jv.l; } + + // 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. @@ -430,7 +442,7 @@ wrap_value (JNIEnv *, T value) // This specialization is used for jobject, jclass, jstring, jarray, // etc. -template<typename T> +template<typename R, typename T> static T * wrap_value (JNIEnv *env, T *value) { @@ -781,8 +793,7 @@ static T style == constructor, arg_types, args, &result); - // We cheat a little here. FIXME. - return wrap_value (env, * (T *) &result); + return wrap_value (env, extract_from_jvalue<T>(result)); } catch (jthrowable t) { @@ -848,8 +859,7 @@ static T style == constructor, arg_types, arg_copy, &result); - // We cheat a little here. FIXME. - return wrap_value (env, * (T *) &result); + return wrap_value (env, extract_from_jvalue<T>(result)); } catch (jthrowable t) { |