This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: libffi problem
- From: Jeff Sturm <jsturm at one-point dot com>
- To: Bo Thorsen <bo at sonofthor dot dk>
- Cc: gcc at gcc dot gnu dot org
- Date: Wed, 17 Jul 2002 10:09:24 -0400 (EDT)
- Subject: Re: libffi problem
On Mon, 15 Jul 2002, Bo Thorsen wrote:
> I have a problem in the port of libffi.
On what platform?
> In the testsuite, there is a test that calls a function with a signed char.
> This function simply returns the signed char, and the testsuite checks that
> the returned number is equal to the one given.
>
> The problem here is that the testcase is giving a long long to fill the return
> value in. I wanted to do a memcpy(&rvalue, &value, size), but size here is 1,
> so when giving a negative number to return, this writes the - flag in the
> wrong position (actually returns 129 instead of -127).
For integer return values, ffi_call promotes to word size (ffi_arg). From
libffi/README:
RVALUE is a pointer to a chunk of memory that is to hold the
result of the function call. Currently, it must be
at least one word in size (except for the n32 version
under Irix 6.x, which must be a pointer to an 8 byte
aligned value (a long long). It must also be at least
word aligned (depending on the return type, and the
system's alignment requirements). If RTYPE is
&ffi_type_void, this is ignored. If RVALUE is NULL,
the return value is discarded.
See e.g. ffi_prep_cif_machdep in src/x86/ffi.c for special handling of
rtype.
> What is wrong here? Does libffi always assume that there is a word of
> pointersize to write numbers into? Or is the testsuite wrong?
Not always pointersize, e.g. MIPS n32. (That's why I introduced the
ffi_arg typedef, to reduce the need for conditional compilation in
portable code.)
Jeff