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 | |
parent | 07f89b91342f3526cfa1f4928e45069db7f10307 (diff) | |
download | ffi-8193194445be526d64ec3b8a514b3b884da877b4.tar.gz |
Allow zero-length arrays as the last element in a FFI::Struct
-rw-r--r-- | ext/ffi_c/Struct.c | 2 | ||||
-rw-r--r-- | ext/ffi_c/StructLayout.c | 5 |
2 files changed, 4 insertions, 3 deletions
diff --git a/ext/ffi_c/Struct.c b/ext/ffi_c/Struct.c index c18c566..5fb3a82 100644 --- a/ext/ffi_c/Struct.c +++ b/ext/ffi_c/Struct.c @@ -493,7 +493,7 @@ inline_array_size(VALUE self) static int inline_array_offset(InlineArray* array, int index) { - if (index < 0 || index >= array->length) { + if (index < 0 || (index >= array->length && array->length > 0)) { rb_raise(rb_eIndexError, "index %d out of bounds", index); } 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); |