From: Bruno Haible <bruno@clisp.org>
To: "Kaz Kylheku (libffi)" <382-725-6798@kylheku.com>
Cc: libffi-discuss@sourceware.org
Subject: Re: small return types
Date: Sun, 22 Oct 2017 20:33:00 -0000 [thread overview]
Message-ID: <5182570.xx5xnuqjYz@omega> (raw)
In-Reply-To: <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
next prev parent reply other threads:[~2017-10-22 20:33 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-21 18:31 test results on many platforms Bruno Haible
2017-10-22 8:12 ` Matthias Klose
2017-10-22 14:58 ` Bruno Haible
2017-10-22 18:28 ` Kaz Kylheku (libffi)
2017-10-22 20:33 ` Bruno Haible [this message]
2017-10-22 21:38 ` small return types Kaz Kylheku (libffi)
2017-10-25 5:18 ` Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5182570.xx5xnuqjYz@omega \
--to=bruno@clisp.org \
--cc=382-725-6798@kylheku.com \
--cc=libffi-discuss@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).