public inbox for libffi-discuss@sourceware.org
 help / color / mirror / Atom feed
From: Anthony Green <green@moxielogic.com>
To: Kaz Kylheku <kaz@kylheku.com>
Cc: "libffi-discuss@sourceware.org" <libffi-discuss@sourceware.org>
Subject: Re: Does a FFI_STRUCT type really need the elements array?
Date: Thu, 22 Jun 2017 12:01:00 -0000	[thread overview]
Message-ID: <CACxje58ApCsLLskh=keo0Ak3ymVQfC07tzH2Uqp4E-FB9zro7w@mail.gmail.com> (raw)
In-Reply-To: <dee1e6313f95bacb4762ca254434a22c@mail.kylheku.com>

Hi Kaz,

There are complexities around dealing with structs with nested struct elements.

It sounds like yours is a special case, where you are doing a lot of
work that is normally done by libffi, which is too bad.

The libffi API is far from perfect, but this is one area where there
have been few complaints.  That being said, it would be interesting to
hear a more fully formed proposal that could be considered prior to a
major API breaking release.

AG


On Wed, Jun 21, 2017 at 10:34 PM, Kaz Kylheku <kaz@kylheku.com> wrote:
> Hi libffi users,
>
> Here is the thing. Suppose I have a sophisticated FFI implementation
> which uses libffi.  Of course I've done all the struct layout calculations
> yourself: the offset of every member, taking into account its alignment to
> generate any padding in between them and at the end. (I need this in
> situations
> not involving libffi!)
>
> Yet, I have to mirror this information in the libffi data structure:
> a FFI_STRUCT type has to have an elements[] array of types. Presumably
> libffi just walks these, redundantly doing the same calculations to get
> the offset of every member, total size with padding and alignment.
>
> Can't we dispense with the elements[] array and just punch in the size
> and alignment values into the struct type (that are supposed to be left
> zero?)
>
> Or is there some compromise: a one-element elements[] array (well two, with
> null termination), where a single element indicates the size and
> alignment somehow.
>
> Or how about a one-element array whose one and only pointer is the
> null terminator; with the size and alignment punched in: would that
> work?
>
> It's wasteful to allocate, initialize and free these arrays and to have
> libffi walking over them.
>
> Any words of wisdom?
>

  reply	other threads:[~2017-06-22 12:01 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-22  2:34 Kaz Kylheku
2017-06-22 12:01 ` Anthony Green [this message]
2017-06-22 17:12   ` 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='CACxje58ApCsLLskh=keo0Ak3ymVQfC07tzH2Uqp4E-FB9zro7w@mail.gmail.com' \
    --to=green@moxielogic.com \
    --cc=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).