java_raw_api.c (ffi_java_raw_to_ptrarray): Interpret raw data as _Jv_word values...
authorUlrich Weigand <uweigand@de.ibm.com>
Tue, 8 Oct 2002 14:55:03 +0000 (14:55 +0000)
committerUlrich Weigand <uweigand@gcc.gnu.org>
Tue, 8 Oct 2002 14:55:03 +0000 (14:55 +0000)
* src/java_raw_api.c (ffi_java_raw_to_ptrarray): Interpret
raw data as _Jv_word values, not ffi_raw.
(ffi_java_ptrarray_to_raw): Likewise.
(ffi_java_rvalue_to_raw): New function.
(ffi_java_raw_call): Call it.
(ffi_java_raw_to_rvalue): New function.
(ffi_java_translate_args): Call it.
* src/ffitest.c (closure_test_fn): Interpret return value
as ffi_arg, not int.
* src/s390/ffi.c (ffi_prep_cif_machdep): Add missing
FFI_TYPE_POINTER case.
(ffi_closure_helper_SYSV): Likewise.  Also, assume return
values extended to word size.

From-SVN: r57926

libffi/ChangeLog
libffi/src/ffitest.c
libffi/src/java_raw_api.c
libffi/src/s390/ffi.c

index 2155dfc7f8eab92d8ce0f964993ae937e4426d4c..adfa3885e7d8a29fc1de2132b416b5d1c1033cd3 100644 (file)
@@ -1,3 +1,19 @@
+2002-10-08  Ulrich Weigand  <uweigand@de.ibm.com>
+
+       * src/java_raw_api.c (ffi_java_raw_to_ptrarray): Interpret
+       raw data as _Jv_word values, not ffi_raw.
+       (ffi_java_ptrarray_to_raw): Likewise.
+       (ffi_java_rvalue_to_raw): New function.
+       (ffi_java_raw_call): Call it.
+       (ffi_java_raw_to_rvalue): New function.
+       (ffi_java_translate_args): Call it.
+       * src/ffitest.c (closure_test_fn): Interpret return value
+       as ffi_arg, not int.
+       * src/s390/ffi.c (ffi_prep_cif_machdep): Add missing
+       FFI_TYPE_POINTER case.
+       (ffi_closure_helper_SYSV): Likewise.  Also, assume return
+       values extended to word size.
+
 2002-10-02  Andreas Jaeger  <aj@suse.de>
 
        * src/x86/ffi64.c (ffi_prep_cif_machdep): Remove debug output.
index 8d72df1cc031c2e95740733392e629bc9d5a75fe..163c4a8c36e3f9dd794e6f95b4213c83190073cf 100644 (file)
@@ -262,7 +262,7 @@ static test_structure_9 struct9 (test_structure_9 ts)
 static void
 closure_test_fn(ffi_cif* cif,void* resp,void** args, void* userdata)
 {
-  *(int*)resp = *(int*)args[0] + (int)(*(float*)args[1]) + (int)(long)userdata;
+  *(ffi_arg*)resp = *(int*)args[0] + (int)(*(float*)args[1]) + (int)(long)userdata;
 }
 
 typedef int (*closure_test_type)(int, float);
index 55c3d132d5339254ad9bfa142d220001ccd09ced..cb5dd67a78edcf7909c5dc3a90ce72adda81eac4 100644 (file)
@@ -81,21 +81,14 @@ ffi_java_raw_to_ptrarray (ffi_cif *cif, ffi_raw *raw, void **args)
        {
        case FFI_TYPE_UINT8:
        case FFI_TYPE_SINT8:
-         *args = (void*) ((char*)(raw++) + SIZEOF_ARG - 1);
+         *args = (void*) ((char*)(raw++) + 3);
          break;
          
        case FFI_TYPE_UINT16:
        case FFI_TYPE_SINT16:
-         *args = (void*) ((char*)(raw++) + SIZEOF_ARG - 2);
+         *args = (void*) ((char*)(raw++) + 2);
          break;
 
-#if SIZEOF_ARG >= 4      
-       case FFI_TYPE_UINT32:
-       case FFI_TYPE_SINT32:
-         *args = (void*) ((char*)(raw++) + SIZEOF_ARG - 4);
-         break;
-#endif
-       
 #if SIZEOF_ARG == 8      
        case FFI_TYPE_UINT64:
        case FFI_TYPE_SINT64:
@@ -157,31 +150,54 @@ ffi_java_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_raw *raw)
       switch ((*tp)->type)
        {
        case FFI_TYPE_UINT8:
+#if WORDS_BIGENDIAN
+         *(UINT32*)(raw++) = *(UINT8*) (*args);
+#else
          (raw++)->uint = *(UINT8*) (*args);
+#endif
          break;
 
        case FFI_TYPE_SINT8:
+#if WORDS_BIGENDIAN
+         *(SINT32*)(raw++) = *(SINT8*) (*args);
+#else
          (raw++)->sint = *(SINT8*) (*args);
+#endif
          break;
 
        case FFI_TYPE_UINT16:
+#if WORDS_BIGENDIAN
+         *(UINT32*)(raw++) = *(UINT16*) (*args);
+#else
          (raw++)->uint = *(UINT16*) (*args);
+#endif
          break;
 
        case FFI_TYPE_SINT16:
+#if WORDS_BIGENDIAN
+         *(SINT32*)(raw++) = *(SINT16*) (*args);
+#else
          (raw++)->sint = *(SINT16*) (*args);
+#endif
          break;
 
-#if SIZEOF_ARG >= 4
        case FFI_TYPE_UINT32:
+#if WORDS_BIGENDIAN
+         *(UINT32*)(raw++) = *(UINT32*) (*args);
+#else
          (raw++)->uint = *(UINT32*) (*args);
+#endif
          break;
 
        case FFI_TYPE_SINT32:
+#if WORDS_BIGENDIAN
+         *(SINT32*)(raw++) = *(SINT32*) (*args);
+#else
          (raw++)->sint = *(SINT32*) (*args);
-         break;
 #endif
-        case FFI_TYPE_FLOAT:
+         break;
+
+       case FFI_TYPE_FLOAT:
          (raw++)->flt = *(FLOAT32*) (*args);
          break;
 
@@ -211,6 +227,55 @@ ffi_java_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_raw *raw)
 
 #if !FFI_NATIVE_RAW_API
 
+static void
+ffi_java_rvalue_to_raw (ffi_cif *cif, void *rvalue)
+{
+#if WORDS_BIGENDIAN && SIZEOF_ARG == 8
+  switch (cif->rtype->type)
+    {
+    case FFI_TYPE_UINT8:
+    case FFI_TYPE_UINT16:
+    case FFI_TYPE_UINT32:
+      *(UINT64 *)rvalue <<= 32;
+      break;
+
+    case FFI_TYPE_SINT8:
+    case FFI_TYPE_SINT16:
+    case FFI_TYPE_SINT32:
+    case FFI_TYPE_INT:
+      *(SINT64 *)rvalue <<= 32;
+      break;
+
+    default:
+      break;
+    }
+#endif
+}
+
+static void
+ffi_java_raw_to_rvalue (ffi_cif *cif, void *rvalue)
+{
+#if WORDS_BIGENDIAN && SIZEOF_ARG == 8
+  switch (cif->rtype->type)
+    {
+    case FFI_TYPE_UINT8:
+    case FFI_TYPE_UINT16:
+    case FFI_TYPE_UINT32:
+      *(UINT64 *)rvalue >>= 32;
+      break;
+
+    case FFI_TYPE_SINT8:
+    case FFI_TYPE_SINT16:
+    case FFI_TYPE_SINT32:
+    case FFI_TYPE_INT:
+      *(SINT64 *)rvalue >>= 32;
+      break;
+
+    default:
+      break;
+    }
+#endif
+}
 
 /* This is a generic definition of ffi_raw_call, to be used if the
  * native system does not provide a machine-specific implementation.
@@ -227,6 +292,7 @@ void ffi_java_raw_call (/*@dependent@*/ ffi_cif *cif,
   void **avalue = (void**) alloca (cif->nargs * sizeof (void*));
   ffi_java_raw_to_ptrarray (cif, raw, avalue);
   ffi_call (cif, fn, rvalue, avalue);
+  ffi_java_rvalue_to_raw (cif, rvalue);
 }
 
 #if FFI_CLOSURES               /* base system provides closures */
@@ -240,6 +306,7 @@ ffi_java_translate_args (ffi_cif *cif, void *rvalue,
 
   ffi_java_ptrarray_to_raw (cif, avalue, raw);
   (*cl->fun) (cif, rvalue, raw, cl->user_data);
+  ffi_java_raw_to_rvalue (cif, rvalue);
 }
 
 /* Again, here is the generic version of ffi_prep_raw_closure, which
index b40bdd43fc972c29301bd26252a850ffbdb393e1..9e7d16954f62ca93844bcb0331a366a743c74a83 100644 (file)
@@ -369,6 +369,7 @@ ffi_prep_cif_machdep(ffi_cif *cif)
        cif->flags = FFI390_RET_INT64;
        break;
 
+      case FFI_TYPE_POINTER:
       case FFI_TYPE_INT:
       case FFI_TYPE_UINT32:
       case FFI_TYPE_SINT32:
@@ -682,29 +683,18 @@ ffi_closure_helper_SYSV (ffi_closure *closure,
 #endif
        break;
 
+      case FFI_TYPE_POINTER:
       case FFI_TYPE_UINT32:
-       p_gpr[0] = *(unsigned int *) rvalue;
+      case FFI_TYPE_UINT16:
+      case FFI_TYPE_UINT8:
+       p_gpr[0] = *(unsigned long *) rvalue;
        break;
 
       case FFI_TYPE_INT:
       case FFI_TYPE_SINT32:
-       p_gpr[0] = *(signed int *) rvalue;
-       break;
-
-      case FFI_TYPE_UINT16:
-       p_gpr[0] = *(unsigned short *) rvalue;
-       break;
-
       case FFI_TYPE_SINT16:
-       p_gpr[0] = *(signed short *) rvalue;
-       break;
-
-      case FFI_TYPE_UINT8:
-       p_gpr[0] = *(unsigned char *) rvalue;
-       break;
-
       case FFI_TYPE_SINT8:
-       p_gpr[0] = *(signed char *) rvalue;
+       p_gpr[0] = *(signed long *) rvalue;
        break;
 
       default: