From 4d6a988ac5c6d79f131575cc3ed431a4229bde0e Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Wed, 20 Aug 2003 19:37:21 +0000 Subject: [PATCH] jni.cc: Replace "cheating" pointer-casting code with extract_from_jvalue<> template. 2003-08-20 Graydon Hoare * jni.cc: Replace "cheating" pointer-casting code with extract_from_jvalue<> template. From-SVN: r70613 --- libjava/ChangeLog | 5 +++++ libjava/jni.cc | 20 +++++++++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 892e2c148ca4..2ce212138bcf 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,8 @@ +2003-08-20 Graydon Hoare + + * jni.cc: Replace "cheating" pointer-casting code with + extract_from_jvalue<> template. + 2003-08-20 Andrew Haley * gnu/gcj/runtime/StackTrace.java (getClass): New method. diff --git a/libjava/jni.cc b/libjava/jni.cc index 47017dc8c185..497790786392 100644 --- a/libjava/jni.cc +++ b/libjava/jni.cc @@ -418,6 +418,18 @@ _Jv_JNI_PopSystemFrame (JNIEnv *env) } } +template 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 +template 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(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(result)); } catch (jthrowable t) {