(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