diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2017-04-27 06:36:09 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2017-04-27 06:36:09 -0700 |
commit | c489ea71dd23c4108bad92bba463cd153fc9135c (patch) | |
tree | eb99beed5624645ec5f8299dda9753ed878f345b /ffi.h | |
parent | 8b0fdf4d546dac440af65909eb81ecb2f7d767e9 (diff) | |
download | txr-c489ea71dd23c4108bad92bba463cd153fc9135c.tar.gz txr-c489ea71dd23c4108bad92bba463cd153fc9135c.tar.bz2 txr-c489ea71dd23c4108bad92bba463cd153fc9135c.zip |
ffi: sane in/out protocol; buffers work directly.
Fix incorrect memory allocation in (ptr-in buf)
and (ptr-in-out buf) passing.
Buffer arguments passed to a function as
(ptr-in buf) or (ptr-in-out buf) now pass the buffer
directly without allocating another copy, as in the
case of arrays or structs.
* ffi.c (struct txr_ffi_type): New members alloc, free.
The pointer types use these functions, together with fill,
for the management of the buffering of their target type.
(ffi_fixed_alloc, ffi_noop_free, ffi_buf_alloc,
ffi_ptr_in_in): New static functions.
(ffi_ptr_in_put): Use target type's alloc function,
rather than chk_malloc. A struct or array will actually
allocate the buffer needed for their C version. A buffer
will not; it will just return its internal pointer,
just like what the wstr type does with strings.
This function now sets up ffi_ptr_in_in as the in handler
for this pointer type, rather than ffi_freeing_in,
because the freeing has to go through the target type
interface, and not directly to free. Buffers use the
no-op free function.
(ffi_ptr_out_in): Use the target type's free function
rathr than free.
(ffi_ptr_out_put, ffi_ptr_in_out_put): Use the target type's
allocator instead of chk_malloc.
(make_ffi_type_pointer, make_ffi_type_struct,
make_ffi_type_array): Initialize the alloc and free function
pointer members of the txr_ffi_type struct.
(ffi_type_compile): Set up alloc and free for buffers.
Diffstat (limited to 'ffi.h')
0 files changed, 0 insertions, 0 deletions