diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2017-06-06 20:11:31 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2017-06-06 20:11:31 -0700 |
commit | 6399a4cb2acc7eac30a8140dc1462269680f378a (patch) | |
tree | 7e45db6609288915a24ed4d49336e2fccf71869a /ffi.h | |
parent | 0fdebafd382cee1f29ec1674f946941c036f4a4f (diff) | |
download | txr-6399a4cb2acc7eac30a8140dc1462269680f378a.tar.gz txr-6399a4cb2acc7eac30a8140dc1462269680f378a.tar.bz2 txr-6399a4cb2acc7eac30a8140dc1462269680f378a.zip |
ffi: support bitfields on types narrower than int.
* ffi.c (bit_s): New symbol variable.
(ffi_generic_sbit_put, ffi_generic_sbit_get,
ffi_generic_ubit_put, ffi_generic_ubit_get): New static
functions.
(bitfield_syntax_p): Include bit symbol in the check.
(make_ffi_type_pointer): Zero size is no longer an early
rejection test for bitfields; don't rely on it.
(make_ffi_type_struct): Revise the member calculating loop
to handle bitfields of various sizes. If a bitfield
follows one of a different size, it starts a new cell
even if the previous one has room, et cetera.
The masking and shifting is set up to work on cells of
int size; however, the new ffi_generic_s?bit_{put,get}
functions use a temporary buffer and transfer just the
right number of bytes to and from the actual buffer.
(ffi_struct_compile): The check against incomplete type
members only needs to test size zero; bitfields have nonzero
size now, which is the true size of the underlying storage
unit. They also have true alignment, which is used in
make_ffi_type_struct rather than hard-coding to alignof (int).
New syntax (bit width type) is now handled, where type can
be any of the signed and unsigned integral types up to int32
and int. The endian types are not supported for now.
(ffi_typedef, ffi_size, ffi_alignof): Zero size is no longer
an early rejection test for bitfields; don't rely on it.
(ffi_init): Initialize bit_s.
* ffi.h (bit_s): Declared.
* txr.1: Documented.
Diffstat (limited to 'ffi.h')
-rw-r--r-- | ffi.h | 2 |
1 files changed, 1 insertions, 1 deletions
@@ -61,7 +61,7 @@ extern val ptr_in_s, ptr_out_s, ptr_in_d_s, ptr_out_d_s, ptr_out_s_s, ptr_s; extern val closure_s; -extern val sbit_s, ubit_s; +extern val sbit_s, ubit_s, bit_s; extern val enum_s; |