libffi limitation causes bad behavior in JNI on Sparc
Mon Aug 13 17:23:00 GMT 2001
Going back to some old mail...
On 12 May 2001, Marcus G. Daniels wrote:
> On Sparc, libffi doesn't handle integer return types of size 8 or 16.
> This causes problems for JNI calls like CallBooleanMethod because the
> return value is in the wrong bits of the returned integer.
I noticed this today while testing our application on SPARC.
It seems to be an endianness problem.
> For example, a hack that worked for me was to change ffi_call in
> libffi/src/sparc/ffi.c to check for FFI_TYPE_UINT8 and FFI_TYPE_SINT8
> and do a *(unsigned *)rvalue << = 24 in that case.
I don't think that's the right fix. Did the ffitest program still run
The way other programs use libffi, it appears that arguments and return
values smaller than a machine word are always sign-extended to fill one
word. Libgcj however passes its arguments to ffi_call in the jvalue
union, which may be wrong, but happens to work on little endian
Other big endian targets in libffi (m68k) seem to be handled the same as
SPARC. The libffi README suggests that return types smaller than int
should work though. Either the code or documentation is probably wrong.
I'm testing a patch which I'll post shortly.
More information about the Java