diff options
author | Wayne Meissner <wmeissner@gmail.com> | 2012-11-10 17:00:47 +1000 |
---|---|---|
committer | Wayne Meissner <wmeissner@gmail.com> | 2012-11-10 17:00:47 +1000 |
commit | 8193194445be526d64ec3b8a514b3b884da877b4 (patch) | |
tree | ebb1099759a907a9f144ce869183cf825f7e542a /ext/ffi_c/StructLayout.c | |
parent | 07f89b91342f3526cfa1f4928e45069db7f10307 (diff) | |
download | ffi-8193194445be526d64ec3b8a514b3b884da877b4.tar.gz |
Allow zero-length arrays as the last element in a FFI::Struct
Diffstat (limited to 'ext/ffi_c/StructLayout.c')
-rw-r--r-- | ext/ffi_c/StructLayout.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/ext/ffi_c/StructLayout.c b/ext/ffi_c/StructLayout.c index 7a431a7..1561830 100644 --- a/ext/ffi_c/StructLayout.c +++ b/ext/ffi_c/StructLayout.c @@ -388,7 +388,7 @@ struct_layout_initialize(VALUE self, VALUE fields, VALUE size, VALUE align) } ftype = field->type->ffiType; - if (ftype->size == 0) { + if (ftype->size == 0 && i < ((int) layout->fieldCount - 1)) { rb_raise(rb_eTypeError, "type of field %d has zero size", i); } @@ -396,7 +396,8 @@ struct_layout_initialize(VALUE self, VALUE fields, VALUE size, VALUE align) field->referenceIndex = layout->referenceFieldCount++; } - layout->ffiTypes[i] = ftype; + + layout->ffiTypes[i] = ftype->size > 0 ? ftype : NULL; st_insert(layout->fieldSymbolTable, rbName, rbField); rb_hash_aset(layout->rbFieldMap, rbName, rbField); rb_ary_push(layout->rbFields, rbField); |