public inbox for libffi-discuss@sourceware.org
 help / color / mirror / Atom feed
From: "Kaz Kylheku (libffi)" <382-725-6798@kylheku.com>
To: libffi-discuss@sourceware.org
Subject: Also: problem with return value in ffi_call on PPC64.
Date: Sun, 28 May 2017 01:36:00 -0000	[thread overview]
Message-ID: <a1bda55849470c990b5c319c92351cf7@mail.kylheku.com> (raw)

Hi all,

It turns out that return values from foreign calls are also not working 
in the way I expect.

For instance, the int return value of dup comes out as zero if a file 
descriptor is returned.
The -1 value emerges properly due to sign extension:

1> (with-dyn-lib nil (deffi dup-fd "dup" int (int)))
#:lib-0175
2> (dup-fd 0)
0
3> (dup-fd 4)
-1
4> (dup-fd 3)
0
5> (dup-fd 4)
0
6> (dup-fd 5)
0
7> (dup-fd 7)
-1
8> (dup-fd 7)
-1

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?

Why doesn't that convention apply to the arguments, then? When dup is 
being called above, the int value is being written at the bottom of the 
argument buffer, not displaced by four bytes.

             reply	other threads:[~2017-05-28  1:36 UTC|newest]

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

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=a1bda55849470c990b5c319c92351cf7@mail.kylheku.com \
    --to=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).