public inbox for libffi-discuss@sourceware.org
 help / color / mirror / Atom feed
From: Kaz Kylheku <kaz@kylheku.com>
To: libffi-discuss@sourceware.org
Subject: Does a FFI_STRUCT type really need the elements array?
Date: Thu, 22 Jun 2017 02:34:00 -0000	[thread overview]
Message-ID: <dee1e6313f95bacb4762ca254434a22c@mail.kylheku.com> (raw)

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  2:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-22  2:34 Kaz Kylheku [this message]
2017-06-22 12:01 ` Anthony Green
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=dee1e6313f95bacb4762ca254434a22c@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).