Commit 8177895b by Ulrich Weigand Committed by Ulrich Weigand

java_raw_api.c (ffi_java_raw_to_ptrarray): Interpret raw data as _Jv_word values, not ffi_raw.

	* 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
parent 4fdbcfb2
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> 2002-10-02 Andreas Jaeger <aj@suse.de>
* src/x86/ffi64.c (ffi_prep_cif_machdep): Remove debug output. * src/x86/ffi64.c (ffi_prep_cif_machdep): Remove debug output.
......
...@@ -262,7 +262,7 @@ static test_structure_9 struct9 (test_structure_9 ts) ...@@ -262,7 +262,7 @@ static test_structure_9 struct9 (test_structure_9 ts)
static void static void
closure_test_fn(ffi_cif* cif,void* resp,void** args, void* userdata) 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); typedef int (*closure_test_type)(int, float);
......
...@@ -81,21 +81,14 @@ ffi_java_raw_to_ptrarray (ffi_cif *cif, ffi_raw *raw, void **args) ...@@ -81,21 +81,14 @@ ffi_java_raw_to_ptrarray (ffi_cif *cif, ffi_raw *raw, void **args)
{ {
case FFI_TYPE_UINT8: case FFI_TYPE_UINT8:
case FFI_TYPE_SINT8: case FFI_TYPE_SINT8:
*args = (void*) ((char*)(raw++) + SIZEOF_ARG - 1); *args = (void*) ((char*)(raw++) + 3);
break; break;
case FFI_TYPE_UINT16: case FFI_TYPE_UINT16:
case FFI_TYPE_SINT16: case FFI_TYPE_SINT16:
*args = (void*) ((char*)(raw++) + SIZEOF_ARG - 2); *args = (void*) ((char*)(raw++) + 2);
break; 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 #if SIZEOF_ARG == 8
case FFI_TYPE_UINT64: case FFI_TYPE_UINT64:
case FFI_TYPE_SINT64: case FFI_TYPE_SINT64:
...@@ -157,30 +150,53 @@ ffi_java_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_raw *raw) ...@@ -157,30 +150,53 @@ ffi_java_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_raw *raw)
switch ((*tp)->type) switch ((*tp)->type)
{ {
case FFI_TYPE_UINT8: case FFI_TYPE_UINT8:
#if WORDS_BIGENDIAN
*(UINT32*)(raw++) = *(UINT8*) (*args);
#else
(raw++)->uint = *(UINT8*) (*args); (raw++)->uint = *(UINT8*) (*args);
#endif
break; break;
case FFI_TYPE_SINT8: case FFI_TYPE_SINT8:
#if WORDS_BIGENDIAN
*(SINT32*)(raw++) = *(SINT8*) (*args);
#else
(raw++)->sint = *(SINT8*) (*args); (raw++)->sint = *(SINT8*) (*args);
#endif
break; break;
case FFI_TYPE_UINT16: case FFI_TYPE_UINT16:
#if WORDS_BIGENDIAN
*(UINT32*)(raw++) = *(UINT16*) (*args);
#else
(raw++)->uint = *(UINT16*) (*args); (raw++)->uint = *(UINT16*) (*args);
#endif
break; break;
case FFI_TYPE_SINT16: case FFI_TYPE_SINT16:
#if WORDS_BIGENDIAN
*(SINT32*)(raw++) = *(SINT16*) (*args);
#else
(raw++)->sint = *(SINT16*) (*args); (raw++)->sint = *(SINT16*) (*args);
#endif
break; break;
#if SIZEOF_ARG >= 4
case FFI_TYPE_UINT32: case FFI_TYPE_UINT32:
#if WORDS_BIGENDIAN
*(UINT32*)(raw++) = *(UINT32*) (*args);
#else
(raw++)->uint = *(UINT32*) (*args); (raw++)->uint = *(UINT32*) (*args);
#endif
break; break;
case FFI_TYPE_SINT32: case FFI_TYPE_SINT32:
#if WORDS_BIGENDIAN
*(SINT32*)(raw++) = *(SINT32*) (*args);
#else
(raw++)->sint = *(SINT32*) (*args); (raw++)->sint = *(SINT32*) (*args);
break;
#endif #endif
break;
case FFI_TYPE_FLOAT: case FFI_TYPE_FLOAT:
(raw++)->flt = *(FLOAT32*) (*args); (raw++)->flt = *(FLOAT32*) (*args);
break; break;
...@@ -211,6 +227,55 @@ ffi_java_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_raw *raw) ...@@ -211,6 +227,55 @@ ffi_java_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_raw *raw)
#if !FFI_NATIVE_RAW_API #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 /* This is a generic definition of ffi_raw_call, to be used if the
* native system does not provide a machine-specific implementation. * native system does not provide a machine-specific implementation.
...@@ -227,6 +292,7 @@ void ffi_java_raw_call (/*@dependent@*/ ffi_cif *cif, ...@@ -227,6 +292,7 @@ void ffi_java_raw_call (/*@dependent@*/ ffi_cif *cif,
void **avalue = (void**) alloca (cif->nargs * sizeof (void*)); void **avalue = (void**) alloca (cif->nargs * sizeof (void*));
ffi_java_raw_to_ptrarray (cif, raw, avalue); ffi_java_raw_to_ptrarray (cif, raw, avalue);
ffi_call (cif, fn, rvalue, avalue); ffi_call (cif, fn, rvalue, avalue);
ffi_java_rvalue_to_raw (cif, rvalue);
} }
#if FFI_CLOSURES /* base system provides closures */ #if FFI_CLOSURES /* base system provides closures */
...@@ -240,6 +306,7 @@ ffi_java_translate_args (ffi_cif *cif, void *rvalue, ...@@ -240,6 +306,7 @@ ffi_java_translate_args (ffi_cif *cif, void *rvalue,
ffi_java_ptrarray_to_raw (cif, avalue, raw); ffi_java_ptrarray_to_raw (cif, avalue, raw);
(*cl->fun) (cif, rvalue, raw, cl->user_data); (*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 /* Again, here is the generic version of ffi_prep_raw_closure, which
......
...@@ -369,6 +369,7 @@ ffi_prep_cif_machdep(ffi_cif *cif) ...@@ -369,6 +369,7 @@ ffi_prep_cif_machdep(ffi_cif *cif)
cif->flags = FFI390_RET_INT64; cif->flags = FFI390_RET_INT64;
break; break;
case FFI_TYPE_POINTER:
case FFI_TYPE_INT: case FFI_TYPE_INT:
case FFI_TYPE_UINT32: case FFI_TYPE_UINT32:
case FFI_TYPE_SINT32: case FFI_TYPE_SINT32:
...@@ -682,29 +683,18 @@ ffi_closure_helper_SYSV (ffi_closure *closure, ...@@ -682,29 +683,18 @@ ffi_closure_helper_SYSV (ffi_closure *closure,
#endif #endif
break; break;
case FFI_TYPE_POINTER:
case FFI_TYPE_UINT32: 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; break;
case FFI_TYPE_INT: case FFI_TYPE_INT:
case FFI_TYPE_SINT32: 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: 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: case FFI_TYPE_SINT8:
p_gpr[0] = *(signed char *) rvalue; p_gpr[0] = *(signed long *) rvalue;
break; break;
default: default:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment