This is the mail archive of the
libffi-discuss@sourceware.org
mailing list for the libffi project.
Re: small return types
- From: Bruno Haible <bruno at clisp dot org>
- To: "Kaz Kylheku (libffi)" <382-725-6798 at kylheku dot com>
- Cc: libffi-discuss at sourceware dot org
- Date: Sun, 22 Oct 2017 22:33:04 +0200
- Subject: Re: small return types
- Authentication-results: sourceware.org; auth=none
- References: <2437301.0N14NqkuRT@omega> <d0041aa4ade72ea0f4e1d6693b283385@mail.kylheku.com>
Hi Kaz,
Changing the subject, since we're talking about
https://github.com/libffi/libffi/issues/361
https://github.com/libffi/libffi/issues/362
https://github.com/libffi/libffi/issues/368
https://github.com/libffi/libffi/issues/369
> I suspect that some of your ffi_call bug reports on 64 bits may be
> invalid.
>
> The return value on 64 bits, of small types, requires special treatment
> due to known quirk/design flaw in the API. It was originally not
> documented,
> and then it was just documented as is. The way your code is doing it
> is how it *should* be, but isn't.
The 3.2.1 documentation says:
-- Function: ffi_status ffi_prep_cif (ffi_cif *CIF, ffi_abi ABI,
unsigned int NARGS, ffi_type *RTYPE, ffi_type **ARGTYPES)
This initializes CIF according to the given parameters.
...
RTYPE is a pointer to an 'ffi_type' structure that describes the
return type of the function. *Note Types::.
Types:
'Libffi' provides a number of built-in type descriptors that can be used
to describe argument and return types:
...
The new documentation says:
+That is, in most cases, @var{ret} points to an object of exactly the
+size of the type specified when @var{cif} was constructed. However,
+integral types narrower than the system register size are widened.
Which is not useful, because the point of using a library such as libffi
is to NOT NEED TO KNOW about the ABI, about the width of system registers
etc.
> This situation bears some resemblance to promotion in the C language!
But this resemblance is not a justification for libffi's behaviour,
because
1) 'char'. 'unsigned char' etc. are considered as valid return types
of functions (and different from 'int') since ANSI C, 1989/1990.
2) C does not do promotion from 32-bit integer types to 64-bit integer
types.
> Naively written code will appear to work fine on little endian 64 bit,
No, the bug https://github.com/libffi/libffi/issues/368 also affect
some little-endian platforms.
Bruno