neelance / ffi_gen

A generator for Ruby FFI bindings, directly from header files via LLVM's Clang compiler
MIT License
88 stars 26 forks source link

flexible arrays (char x[]) incorrectly translate as :pointer #35

Open ghazel opened 9 years ago

ghazel commented 9 years ago
struct foo {
  int length;
  char data[];
}

Translates as:

  class Foo < FFI::Struct
    layout :length, :int,
           :data, :pointer
  end

However, this is incorrect. Data is not a pointer in the sense that memcpy(&f->data, bad, sizeof(void*)) would populate bad with the pointer value. It would instead copy the first sizeof(void*) bytes of the array. Thus, ffi gets a pointer with the first few bytes of the array as the value, which is invalid to dereference.