public inbox for libffi-discuss@sourceware.org
 help / color / mirror / Atom feed
From: Kaz Kylheku <kaz@kylheku.com>
To: libffi-discuss@sourceware.org
Subject: Help: correct way to handle struct return values.
Date: Sun, 28 May 2017 03:14:00 -0000	[thread overview]
Message-ID: <ec6e2212f16df6ba23cc4c4d1fc78cfd@mail.kylheku.com> (raw)

Hi all,

In the current texinfo doc, the callback stub does this to
return a value of type int:

   /* Acts like puts with the file given at time of enclosure. */
   void puts_binding(ffi_cif *cif, void *ret, void* args[],
                   void *stream)
   {
     *(ffi_arg *)ret = fputs(*(char **)args[0], (FILE *)stream);
   }

Can someone show what the code would look like for a function
that returns the following type, and work everywhere: all
supported platforms, big or little endian:

   struct little { char a, b };

Obvously, this can't be used:

    *(ffi_arg *)ret = fun_returning_struct_little(...);

After everything, I'm not confident that this is correct, either:

    *(struct little *)ret = fun_returning_struct_little(...);

Also, can someone show how to extract "struct little" in after
a ffi down call? If the type is int, we can do this:

    ffi_arg rc_buf;
    int rc;
    ffi_call(&cif, puts, &rc_buf, values);
    rc = rc_buf;

But what if rc is of type "little struct"? Again, we can't just use a 
cast.

Lastly, how does any of this change for  struct bigger_struct { long x, 
y, z; }?

Thanks.

             reply	other threads:[~2017-05-28  3:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-28  3:14 Kaz Kylheku [this message]
2017-05-28  4:13 ` Kaz Kylheku

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