public inbox for libffi-discuss@sourceware.org
 help / color / mirror / Atom feed
* Arrays and unions
@ 2011-08-20 18:40 Eli Barzilay
  2011-08-23 10:08 ` Andrew Haley
  0 siblings, 1 reply; 2+ messages in thread
From: Eli Barzilay @ 2011-08-20 18:40 UTC (permalink / raw)
  To: libffi-discuss

An issue that we had open for a long time is a lack of support for
arrays and unions.  We've finally implemented them, both in a similar
way:

  libffi_type = malloc(sizeof(ffi_type));
  libffi_type->size      = sz;
  libffi_type->alignment = align;
  libffi_type->type      = FFI_TYPE_STRUCT;
  libffi_type->elements  = elements;

The question is -- is FFI_TYPE_STRUCT the right choice here?

(The full code is at
  https://github.com/plt/racket/blob/master/src/foreign/foreign.c#L1172)

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Arrays and unions
  2011-08-20 18:40 Arrays and unions Eli Barzilay
@ 2011-08-23 10:08 ` Andrew Haley
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew Haley @ 2011-08-23 10:08 UTC (permalink / raw)
  To: libffi-discuss

On 08/20/2011 07:40 PM, Eli Barzilay wrote:
> An issue that we had open for a long time is a lack of support for
> arrays and unions.  We've finally implemented them, both in a similar
> way:
> 
>   libffi_type = malloc(sizeof(ffi_type));
>   libffi_type->size      = sz;
>   libffi_type->alignment = align;
>   libffi_type->type      = FFI_TYPE_STRUCT;
>   libffi_type->elements  = elements;
> 
> The question is -- is FFI_TYPE_STRUCT the right choice here?

For unions, yes.  They must be laid out in the same way as structs.

There's no way to pass an array by value in C, so no C ABI can support
passing arrays, and AFAICS there's nothing that libffi can do with
them.  If you want to wrap arrays in structs in your native code
that'll be fine.

Andrew.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-08-23 10:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-20 18:40 Arrays and unions Eli Barzilay
2011-08-23 10:08 ` Andrew Haley

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).