This is the mail archive of the libffi-discuss@sourceware.org mailing list for the libffi project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Does a FFI_STRUCT type really need the elements array?


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?


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]