summaryrefslogtreecommitdiff
path: root/ext/ffi_c/StructLayout.c
diff options
context:
space:
mode:
authorWayne Meissner <wmeissner@gmail.com>2012-11-10 17:00:47 +1000
committerWayne Meissner <wmeissner@gmail.com>2012-11-10 17:00:47 +1000
commit8193194445be526d64ec3b8a514b3b884da877b4 (patch)
treeebb1099759a907a9f144ce869183cf825f7e542a /ext/ffi_c/StructLayout.c
parent07f89b91342f3526cfa1f4928e45069db7f10307 (diff)
downloadffi-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.c5
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);