summaryrefslogtreecommitdiffstats
path: root/hash.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-06-09 07:04:59 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-06-09 07:04:59 -0700
commit268ad25b4a88a50b83c1f2e8c2eb4a4436e52b3d (patch)
treebf31f34f0cf961e8bf3d5a02e47484e48da9e41a /hash.c
parent5bdf9fbeb0a6714158535e5aec0619df49b687c6 (diff)
downloadtxr-268ad25b4a88a50b83c1f2e8c2eb4a4436e52b3d.tar.gz
txr-268ad25b4a88a50b83c1f2e8c2eb4a4436e52b3d.tar.bz2
txr-268ad25b4a88a50b83c1f2e8c2eb4a4436e52b3d.zip
ffi: earnest implementation of FFI struct elements.
This commit tries to address a flaw in our use of libffi. When we construct a structure type, we do not fill in the "elements" array of the libffi type to describe every element. Instead we calculate the size and alignment ourselves. This breaks when passing small structures by value on some platforms. There are some areas where we are still winging it. We allow passing of arrays by value, which are simulated using FFI structure types. To allocate the descriptor earnestly for such an object means allocating an array of ffi_type pointers as large as the array, which is wasteful. So we cap it to 20. This 20 comes form the idea that anything bigger than a 16 byte structure is passed on the stack rather than in registers. For unions, we choose the largest member and inform libffi of its type. * ffi.c (struct txr_ffi_type): elements member changes to from array of 1 to pointer. (ffi_type_struct_destroy_op): Consolidate HAVE_LIBFFI code. Don't bother setting tft->ft->elements to null. Free tft->elements. (ffi_struct_clone): Clone the elements array. (ffi_union_clonse): New static function. Unions need their own clone function now because their elements array has a size not related to the number of members. It contains two pointers, including the null terminating one. (make_ffi_type_struct): Allocate the elements array, and fill it. We wing it around bitfields, which libffi doesn't support. This will be revisited, but it's likely a bad idea to be passing bitfield-endowed structures by value. (make_ffi_type_union): Allocate the elements array to a fixed size of two pointers. Fill it in with the largest member's type. (ffi_array_clone): Clone the elements array, which is up two 20 pointers plus a null terminator. (make_ffi_type_array): Allocate the elements array up to 20 elements plus null pointer, and fill it with repetitions of the element libffi type.
Diffstat (limited to 'hash.c')
0 files changed, 0 insertions, 0 deletions