public inbox for libffi-discuss@sourceware.org
 help / color / mirror / Atom feed
* [Question]pass structure by reference
@ 2011-02-04  8:55 ivo f
  2011-02-04 16:21 ` Anthony Green
  0 siblings, 1 reply; 4+ messages in thread
From: ivo f @ 2011-02-04  8:55 UTC (permalink / raw)
  To: libffi-discuss


Hello,

I hope this question isn't too noobish, but I'm kind of stuck with libffi. I
was trying around passing structures with libffi, which works perfectly
well, but I couldn't figure out if and especially how I can pass pointers to
structures. The only way i see to pass a pointer is to use the
FFI_TYPE_POINTER definition which specifies exactly one argument. The
structure definition allows me to wrap any number of arguments into a
structure and pass them as such, but is there a way to combine both? So to
pass a structure using libffi by reference?

Thanks in advance for your help!
-- 
View this message in context: http://old.nabble.com/-Question-pass-structure-by-reference-tp30842627p30842627.html
Sent from the Sourceware - libffi-discuss mailing list archive at Nabble.com.

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

* Re: [Question]pass structure by reference
  2011-02-04  8:55 [Question]pass structure by reference ivo f
@ 2011-02-04 16:21 ` Anthony Green
  2011-03-20 11:05   ` ivo f
  0 siblings, 1 reply; 4+ messages in thread
From: Anthony Green @ 2011-02-04 16:21 UTC (permalink / raw)
  To: ivo f; +Cc: libffi-discuss

ivo f <ivo.fried@gmx.net> writes:

> Hello,
>
> I hope this question isn't too noobish, but I'm kind of stuck with libffi. I
> was trying around passing structures with libffi, which works perfectly
> well, but I couldn't figure out if and especially how I can pass pointers to
> structures. The only way i see to pass a pointer is to use the
> FFI_TYPE_POINTER definition which specifies exactly one argument. The
> structure definition allows me to wrap any number of arguments into a
> structure and pass them as such, but is there a way to combine both? So to
> pass a structure using libffi by reference?

libffi doesn't distinguish between different pointer types, since none
of the supported ABIs require this.  They are all just pointers.

AG


>
> Thanks in advance for your help!

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

* Re: [Question]pass structure by reference
  2011-02-04 16:21 ` Anthony Green
@ 2011-03-20 11:05   ` ivo f
  2011-03-30 17:37     ` Anthony Green
  0 siblings, 1 reply; 4+ messages in thread
From: ivo f @ 2011-03-20 11:05 UTC (permalink / raw)
  To: libffi-discuss



> libffi doesn't distinguish between different pointer types, since none
> of the supported ABIs require this.  They are all just pointers.

I figured that out. But with libffi I can pass a structure for example:

struct teststruct {
  int a;
  char b;
}

by telling the ffi_prep_cif function that I pass one struct which consist of
an int and a char, and then I pass the ffi_call function two fitting values
and what ffi does (in my understanding) is taking care or the padding and
this stuff!
But in order to let  libffi take care of the padding and so on, I have to
specify an ffi_type_struct and so I can't define an ffi_type_pointer to be
passed. But what I want to do is letting libffi take care of the correct
ordering of my attributes of the struct and pass everything as a pointer
which would need me to specify the type in the ffi_prep_cif function as both
or am I completely wrong?

kind regards
-- 
View this message in context: http://old.nabble.com/-Question-pass-structure-by-reference-tp30842627p31193407.html
Sent from the Sourceware - libffi-discuss mailing list archive at Nabble.com.

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

* Re: [Question]pass structure by reference
  2011-03-20 11:05   ` ivo f
@ 2011-03-30 17:37     ` Anthony Green
  0 siblings, 0 replies; 4+ messages in thread
From: Anthony Green @ 2011-03-30 17:37 UTC (permalink / raw)
  To: ivo f; +Cc: libffi-discuss

ivo f <ivo.fried@gmx.net> writes:

>> libffi doesn't distinguish between different pointer types, since none
>> of the supported ABIs require this.  They are all just pointers.
>
> I figured that out. But with libffi I can pass a structure for example:
>
> struct teststruct {
>   int a;
>   char b;
> }
>
> by telling the ffi_prep_cif function that I pass one struct which consist of
> an int and a char, and then I pass the ffi_call function two fitting values
> and what ffi does (in my understanding) is taking care or the padding and
> this stuff!

That's not quite right.  ffi_call is expecting a pointer to a fully
populated teststruct.  Look at struct1.c in the testsuite to see what I
mean.

AG



> But in order to let  libffi take care of the padding and so on, I have to
> specify an ffi_type_struct and so I can't define an ffi_type_pointer to be
> passed. But what I want to do is letting libffi take care of the correct
> ordering of my attributes of the struct and pass everything as a pointer
> which would need me to specify the type in the ffi_prep_cif function as both
> or am I completely wrong?
>
> kind regards

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

end of thread, other threads:[~2011-03-30 17:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-04  8:55 [Question]pass structure by reference ivo f
2011-02-04 16:21 ` Anthony Green
2011-03-20 11:05   ` ivo f
2011-03-30 17:37     ` Anthony Green

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