public inbox for libffi-discuss@sourceware.org
 help / color / mirror / Atom feed
From: "Sergei Trofimovich via libffi-discuss" <libffi-discuss@sourceware.org>
To: "Kaz Kylheku (libffi)" <382-725-6798@kylheku.com>
Cc: libffi-discuss@sourceware.org
Subject: Re: Also: problem with return value in ffi_call on PPC64.
Date: Sun, 28 May 2017 18:23:00 -0000	[thread overview]
Message-ID: <20170528192241.464e7ebe@sf> (raw)
In-Reply-To: <3b9c322ddca2e20fa30c7eba0e5ebda2@mail.kylheku.com>

[-- Attachment #1: Type: text/plain, Size: 916 bytes --]

On Sat, 27 May 2017 19:15:35 -0700
"Kaz Kylheku (libffi)" <382-725-6798@kylheku.com> wrote:

> > Are users supposed to assume that the return value has been widened to
> > a register-wide (8 byte) value regardless of its declared FFI type?  
> 
> Indeed, it seems yes.

Confusingly yes. But only for integral types smaller that ffi_arg.

TL;DR: 
   Instead of just reading out result as *(result_type*)r for any FFI
   type you need to use either *(ffi_arg*)r or *(result_type*)r depending
   on the type of the result.

A bit vague libffi thread:
    https://sourceware.org/ml/libffi-discuss/2010/msg00063.html

I discovered the same a few years ago debugging similar issue on GHC side
    https://ghc.haskell.org/trac/ghc/ticket/3516

The awkward fix on GHC side:
    https://git.haskell.org/ghc.git/commitdiff/3891512c4c770dadd0372ad84d2dec72b34652d2

Hope that helps.

-- 

  Sergei

[-- Attachment #2: Цифровая подпись OpenPGP --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

  reply	other threads:[~2017-05-28 18:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-28  2:16 Kaz Kylheku (libffi)
2017-05-28 18:23 ` Sergei Trofimovich via libffi-discuss [this message]
2017-05-30  1:24   ` Kaz Kylheku (libffi)
  -- strict thread matches above, loose matches on Subject: below --
2017-05-28  1:36 Kaz Kylheku (libffi)
2017-05-30  8:27 ` Andrew Haley

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=20170528192241.464e7ebe@sf \
    --to=libffi-discuss@sourceware.org \
    --cc=382-725-6798@kylheku.com \
    --cc=slyfox@inbox.ru \
    /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).