Prev: miniruby
Next: Test your ruby skill
From: daniel åkerud on 28 Oct 2009 03:55 (I dind't find an official Ruby FFI mailing-list so I try here) I have a char array baked into a struct (not a pointer), and I have problems describing it in a layout. struct { uint8 Value; uint8 String[SIZE_OF_ARRAY]; } MyArray_t; The only thing I've come up with is to have a dummy variable at the end. class MyArray_t < FFI::Struct layout :Value, :uint8, :String, :char_array, :Dummy, :uint8, SIZE_OF_ARRAY+1 # TODO TODO end And I use it something like this: arr = MyArray_t.new c_function(arr.pointer) # calls a c function that fills the string str_ptr = arr.pointer + arr.offset_of(:String) puts str_ptr.read_string() I need the dummy otherwise there wont be enough bytes allocated and c_function overwrites the heap. Any and all help appreciated. (Note that it's a legacy API, redesigning the C-interface is not possible.) /D
From: Luis Lavena on 28 Oct 2009 09:26 On Oct 28, 4:55 am, daniel åkerud <daniel.ake...(a)gmail.com> wrote: > (I dind't find an official Ruby FFI mailing-list so I try here) > http://groups.google.com/group/ruby-ffi -- Luis Lavena
|
Pages: 1 Prev: miniruby Next: Test your ruby skill |