From a7261b2da02de7d8adc2640bb7751706d5cfeb53 Mon Sep 17 00:00:00 2001 From: Jeff Sturm Date: Sun, 24 Feb 2002 17:55:44 +0000 Subject: natMethod.cc (_Jv_CallAnyMethodA): Define ffi_result union for ffi_call result. * java/lang/reflect/natMethod.cc (_Jv_CallAnyMethodA): Define ffi_result union for ffi_call result. Cast ffi_result members to jvalue. From-SVN: r50007 --- libjava/ChangeLog | 6 +++++ libjava/java/lang/reflect/natMethod.cc | 43 +++++++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) (limited to 'libjava') diff --git a/libjava/ChangeLog b/libjava/ChangeLog index fdcf21c..c6561ab 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,9 @@ +2002-02-24 Jeff Sturm + + * java/lang/reflect/natMethod.cc (_Jv_CallAnyMethodA): + Define ffi_result union for ffi_call result. Cast + ffi_result members to jvalue. + 2002-02-23 Alexandre Oliva * Makefile.in, gcj/Makefile.in, include/Makefile.in: Rebuilt. diff --git a/libjava/java/lang/reflect/natMethod.cc b/libjava/java/lang/reflect/natMethod.cc index 1fab48a..e11e5c36 100644 --- a/libjava/java/lang/reflect/natMethod.cc +++ b/libjava/java/lang/reflect/natMethod.cc @@ -423,9 +423,17 @@ _Jv_CallAnyMethodA (jobject obj, Throwable *ex = NULL; + union + { + ffi_arg i; + jlong l; + jfloat f; + jdouble d; + } ffi_result; + try { - ffi_call (&cif, (void (*)()) meth->ncode, result, values); + ffi_call (&cif, (void (*)()) meth->ncode, &ffi_result, values); } catch (Throwable *ex2) { @@ -436,6 +444,39 @@ _Jv_CallAnyMethodA (jobject obj, ex = new InvocationTargetException (ex2); } + // Since ffi_call returns integer values promoted to a word, use + // a narrowing conversion for jbyte, jchar, etc. results. + // Note that boolean is handled either by the FFI_TYPE_SINT8 or + // FFI_TYPE_SINT32 case. + switch (rtype->type) + { + case FFI_TYPE_VOID: + break; + case FFI_TYPE_SINT8: + result->b = (jbyte)ffi_result.i; + break; + case FFI_TYPE_SINT16: + result->s = (jshort)ffi_result.i; + break; + case FFI_TYPE_UINT16: + result->c = (jchar)ffi_result.i; + break; + case FFI_TYPE_SINT32: + result->i = (jint)ffi_result.i; + break; + case FFI_TYPE_SINT64: + result->j = (jlong)ffi_result.l; + break; + case FFI_TYPE_FLOAT: + result->f = (jfloat)ffi_result.f; + break; + case FFI_TYPE_DOUBLE: + result->d = (jdouble)ffi_result.d; + break; + default: + JvFail ("Unknown ffi_call return type"); + break; + } if (is_constructor) result->l = obj; -- cgit v1.1