diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2021-06-10 06:50:06 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2021-06-10 06:50:06 -0700 |
commit | c56d041f3d598c92374b50a74add435efddc8ee8 (patch) | |
tree | 4f633ec3ac35dd1bf69327da89084a6016246555 /vm.h | |
parent | 00b6397408934f95c16f3fa33959fb17e34f63c9 (diff) | |
download | txr-c56d041f3d598c92374b50a74add435efddc8ee8.tar.gz txr-c56d041f3d598c92374b50a74add435efddc8ee8.tar.bz2 txr-c56d041f3d598c92374b50a74add435efddc8ee8.zip |
ffi: lazily calculate libffi type descriptors.
I think this is a nicer treatment of the libffi situation.
We only need the type descriptors for arrays, structs and
unions if they are ever used as return values or arguments in
a libffi call descriptor. We don't have to waste time and
memory allocating them otherwise, and in the case of arrays,
we can allocate the full descriptor that includes every
member, when that is needed.
Structures that are involved in calls, but are passed and
returned by pointer, not directly, will not have this
cruft instantiated at all.
* ffi.c (struct txr_ffi_type): New function pointer member calcft.
This specifies the lazy initialization funtion for the libffi
stuff. Only arrays, structs and unions have a non-null pointer
here. If the pointer is null, it indicates that the type
doesn't require lazy initialization: either because it was
initialized eagerly, or because lazy initialization was
already done.
(ffi_get_type): If the type has a calcft, then call it and
null it out, to ensure tffi->ft.
(ffi_struct_clone): Do not deal with ft and elements here at
all.
(ffi_union_clone): Short-lived static function removed,
because it is identical to ffi_struct_clone again.
(ffi_struct_calcft, ffi_union_calcft, ffi_array_calcft): New
static functions, implementing different strategies for
calculating the libffi elements array. For unions, I invented
this strategy: we pretend that a union is atually a structure
made of repetitions of the type which has the strictest
alignment. This is uncharted territory because libffi doesn't
support unions at all.
(make_ffi_type_struct, make_ffi_type_union,
make_ffi_type_array): Do not deal with tf or elems, except for
deleting them if we are re-initializing the object. Leave
these pointers null. Install the appropriate calcft function.
(ffi_array_clone): Function removed; the array type can use
ffi_simple_clone, since the clone function doesn't deal with
the libffi stuff. Why was that needed until several commits
ago? Because, subject to HAVE_FFI, it performed the assignment
ft->elements = copy->elements.
Diffstat (limited to 'vm.h')
0 files changed, 0 insertions, 0 deletions