Subject:
Re: [ruby-ffi] struct questions
From:
Wayne Meissner
Date:
12/19/09 6:04 PM
To:
ruby-ffi@googlegroups.com

2009/12/19 Evan Phoenix <evan@fallingsnow.net>:
>
> On Dec 18, 2009, at 5:00 PM, rogerdpack wrote:

>> is there an easier way than ss[:title][0] = 33; ss[:title][1] = 34; //
>> one at a time?
>
> If this works, it should not. The return value should not be references the memory of the array itself in the struct, thats not safe.

Can you elaborate on the "not safe"?

To make sure we're all on the same page, Roger was talking about
something like this:

struct S {
  char title[20];
}

Which in ruby-ffi is:

class S < FFI::Struct
  layout :title, [ :char, 20 ]
end

>
> Because char_array is an explicit type, #put could support it since the size of the char_array should be known by #put.

:char_array isn't supported in ruby-ffi currently.  Although it could
possibly be made to work, it would be complicated in the absence of
offsets on the fields in auto-layout mode, and really does not offer
anything over the ruby-ffi array field syntax.