c_record::set_fields() was populating the ffi_type.elements with
[uint32_t, uint8_t *], which gives an incorrect structure size of 16
(4 bytes for uint32_t, 4 bytes for padding, 8 bytes for uint_t *)
after being prepared by ffi_prep_cif().
this commit modifies c_record::set_fields() to expand fixed size array
types into separate elements in ffi_type.elements, e.g. [uint32_t,
uint8_t, uint8_t, uint8_t, uint8_t], as described in "2.3.4.1
Arrays" of the libffi documentation, so libffi can correctly calculate
the padding and size in ffi_prep_cif().
it also updates the union size logic to use the total size of a fixed
size array field instead of the size of a pointer to the array base
type.
factor out struct and union fields assignment
this commit factors out the common ffi_type.elements assignment logic
from the union and struct code paths in c_record::set_fields().
fix fixed size array fields in structs and unions
for a struct like:
c_record::set_fields()
was populating theffi_type.elements
with[uint32_t, uint8_t *]
, which gives an incorrect structure size of 16 (4 bytes foruint32_t
, 4 bytes for padding, 8 bytes foruint_t *
) after being prepared byffi_prep_cif()
.this commit modifies
c_record::set_fields()
to expand fixed size array types into separate elements inffi_type.elements
, e.g. [uint32_t
,uint8_t
,uint8_t
,uint8_t
,uint8_t
], as described in "2.3.4.1 Arrays" of the libffi documentation, so libffi can correctly calculate the padding and size inffi_prep_cif()
.it also updates the union size logic to use the total size of a fixed size array field instead of the size of a pointer to the array base type.
factor out struct and union fields assignment
this commit factors out the common
ffi_type.elements
assignment logic from the union and struct code paths inc_record::set_fields()
.