libffi: new typedef for return value

Jeff Sturm jsturm@one-point.com
Sat Feb 23 08:23:00 GMT 2002


On 22 Feb 2002, Tom Tromey wrote:
> Anthony told me today he'd have some hacking time this weekend, so
> hopefully this issue will get resolved soon.  This is one of the two
> "must fix" bugs I have listed for 3.1.

Here's what I'm testing now.  It depends on the ffi_arg patch and is
considerably shorter than what I posted before.

Tested on alphaev56-linux.  (I'll see what I can do to get on a sparc this
weekend.)

2002-02-23  Jeff Sturm  <jsturm@one-point.com>

	* java/lang/reflect/natMethod.cc (_Jv_CallAnyMethodA):
	Define ffi_result union for ffi_call result.  Cast
	ffi_result members to jvalue.

Index: natMethod.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/reflect/natMethod.cc,v
retrieving revision 1.25
diff -u -p -r1.25 natMethod.cc
--- natMethod.cc	2002/01/08 20:00:50	1.25
+++ natMethod.cc	2002/02/23 14:05:20
@@ -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;
 



More information about the Java-patches mailing list