| Commit message (Collapse) | Author | Age | Files | Lines |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* ffi.c (ffi_alignof, ffi_offsetof, ffi_arraysize,
ffi_elemsize, ffi_elemtype): New functions.
(ffi_init): Registered intrinsics ffi-alignof, ffi-offsetof,
ffi-arraysize, ffi-elemsize, ffi-elemtype.
* ffi.h (ffi_alignof, ffi_offsetof, ffi_arraysize,
ffi_elemsize, ffi_elemtype): Declared.
* lisplib.c (ffi_set_entries): New autoload entries alignof,
offsetof, arraysize, elemsize, elemtype.
* share/txr/stdlib/ffi.tl (alignof, offsetof, arraysize,
elemsize, elemtype): New macros.
* txr.1: Documented new functions and macros.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* ffi.c (enum_s): New symbol variable.
(struct txr_ffi_type): New member, sym_num, num_sym.
(ffi_enum_type_mark): New static function.
(ffi_type_enum_ops): New static structure.
(ffi_enum_put, ffi_enum_get, ffi_enum_rput, ffi_enum_rget):
New static functions.
(make_ffi_type_enum): New static function.
(ffi_type_compile): Extend with enum syntax.
(ffi_init): Initialize enum_s with new interned symbol.
* ffi.c (enum_s): Declared.
* txr.1: Documented.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* ffi.c (sbit_s, ubit_s): New symbol variables.
(struct txr_ffi_type): New members, shift and mask.
(ffi_sbit_put, ffi_sbit_get, ffi_ubit_put, ffi_ubit_get,
bitfield_syntax_p): New static functions.
(make_ffi_type_pointer): Disallow pointers to bitfields.
(make_ffi_type_struct): Process bitfield members and
set up shifts and masks accordingly. Recently introduced
bug fixed here at the same time: the alignment calculation
for each member must be done top-of-loop.
(ffi_struct_compile): Exclude bitfields from the check
against members with zero type. Compile the bitfield syntax.
(ffi_typedef): Do not allow typedefs of bitfield type.
Not only doesn't this make sense, but bitfield types
are destructively modified in make_ffi_type_struct: they
are imbued with a mask and offset tied to their position in
a particular struct.
* ffi.h (sbit_s, ubit_s): Delared.
* txr.1: Documented bitfields.
|
|
|
|
|
|
|
|
|
|
|
| |
* ffi.c (val_s): New symbol variable.
(ffi_val_put, ffi_val_get): New functions.
(ffi_init_types): Register val type.
(ffi_init): Initialize val_s.
* ffi.h (val_s): Declared.
* txr.1: Documented.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* ffi.c (ffi_call_wrap): Take struct args * parameters
rather than a list. Check that number of arguments
matches required number from call desc. No need
to build argument array any more; we just refer to
the one in args. Also, the first two parameters
are reversed for consistency with other functions.
(ffi_init): Update registration of ffi-call to
reflect type change.
* ffi.h (ffi_call_wrap): Declaration updated.
* txr.1: Documented ffi-call.
|
|
|
|
|
|
|
|
|
| |
* ffi.c (carray_buf_sync): New function.
(ffi_init): carray-buf-sync intrinsic registered.
* ffi.h (carray_buf_sync): Declared.
* txr.1: Documented.
|
|
|
|
|
|
|
|
|
| |
* ffi.c (carray_cptr): New function.
(ffi_init): Registered intrinsic.
* ffi.h (carray_cptr): Declared.
* txr.1: Documented.
|
|
|
|
|
|
|
|
|
| |
Treat a buffer through a carray view.
* ffi.c (carray_buf): New function.
(ffi_init): Register carray-buf intrinsic.
* ffi.h (carray_buf): Declared.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The idea here is that carrays can have a pointer to some area
that is owned by another object. So that the area doesn't
disappear when the other object becomes garbage, a carray
which does this maintains a pointer to that other object.
* ffi.c (ffi_carray_get): Pass new parameter to make_carray.
(struct carray): New member, ref.
(carray_mark_op): Mark new ref member.
(make_carray): New parameter: the object which is stored in
the structure as ref.
(carray_dup): Null out the ref member. When a carray
is duplicated, it owns its own buffer, and henceforth mustn't
prevent the original object from being reclaimed.
(carray_own): Don't allow a carray to claim ownership
of the pointer if it references another object; we have
no protocol to inform that other object.
* ffi.h (make_carray): Declaration updated.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The carray type deals with C array passing conventions
as a pointer to the first element of an array of
unknown size. It fills in the functionality gap not
covered by array and varray.
* ffi.c (carray_s): New symbol variable.
(ffi_carray_get, ffi_carray_put): New static functions.
(ffi_type_compile): Handle (carray <type>) syntax.
(struct carray): New struct type.
(carray_struct, carray_struct_checked, carray_print_op,
carray_mark_op, carray_destroy_op): New static functions.
(carray_borrowed_ops, carray_owned_ops): New static structs.
(make_carray, carray_set_length, carray_dup, carray_own,
carray_free, carray_type, length_carray, carray_get,
carray_vec, carray_blank, vec_carray, list_carray, carray_ref,
carray_refset): New functions.
(ffi_init): Initialize carray_s. Register
carray-set_length, carray_dup, carray_own,
carray-free, carray_type, length_carray,
carray-vec, array_blank, vec_carray, list_carray, carray_ref
and carray-refset intrinsics.
* ffi.h (carray_s): Declared.
(make_carray, carray_set_length, carray_dup, carray_own,
carray_free, carray_type, length_carray, carray_get,
carray_vec, carray_blank, vec_carray, list_carray, carray_ref,
carray_refset): Declared.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* ffi.c (stuct txr_ffi_closure): New member, abort_retval.
(ffi_closure_mark_op): Mark the new member.
(ffi_closure_dispatch_safe): Implement the abort_retval.
If it is not nil, use put to place the value into the
return buffer. There is a risk that this could also throw
an exception, which is no longer protected: programer's
problem.
(ffi_make_closure): New abort_ret_in argument, which is
defaulted and stored.
(ffi_init): Update registration of ffi-make-closure to
reflect new argument.
* ffi.h (ffi_make_closure): Declaration updated.
* share/txr/stdlib/ffi.tl (sys:deffi-cb-expander):
Add abort-retval parameter; insert into ffi-make-closure
call.
(deffi-cb): Take optional abort-retval expression;
pass it down to the expander function.
(deffi-cb-unsafe): Pass nil as abort-retval down to expander.
* txr.1: Documented.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
We don't want, by default, for callbacks to capture delimited
continuations across foreign code, or perpetrate non-local
transfers across foreign code. Here, we take an approach
similar for what was done in ftw_wrap.
* ffi.c (s_exit_point): New global variable with internal
linkage.
(ffi_call_wrap): If s_exit_point isn't nil, then it means that
the callback intercepted a nonlocal transfer and stored its
exit point. We resume the transfer to that exit point instead
of returning normally.
(ffi_closure_dispatch_safe): New static function.
(ffi_make_closure): Support a new argument which indicates
whether to make a closure which uses
ffi_closure_dispatch_safe, or ffi_closure_dispatch.
(ffi_init): Update registration of ffi-make-closure intrinsic.
* ffi.h (ffi_make_closure): Declaration updated.
* share/txr/stdlib/ffi.tl (sys:deffi-cb-expander): New
function.
(deffi-cb): Macro internals replaced by call to new
function.
(deffi-cb-safe): New macro.
* txr.1: Documentation of ffi-make-closure updated.
New deffi-cb-unsafe macro documented.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* ffi.c (ffi_ptr_out_in, ffi_ptr_out_s_in): If the target type
has no in handler, fall back on its get. Here, it is without
regard for the copy flag, because a zero value of that flag
just indicates that the ptr-out itself is passed by-value.
The target object is never by value
(ffi_in): Add copy flag parameter, so the full interface
is exposed, like in ffi_out. Fall back on get, if there is
no in and the copy flag is true. Just return the original
object if the type has no in, and copy is false.
(ffi_init): Registration of ffi-in adjusted to four
parameters.
* ffi.h (ffi_in): Declaration updated.
|
|
|
|
|
|
|
|
|
| |
This will support a sizeof macro.
* ffi.c (ffi_size): New function.
(ffi_init): Register ffi-size intrinsic.
* ffi.h (ffi_size): Declared.
|
|
|
|
|
|
|
|
|
|
| |
* ffi.c (ffi_put_into, ffi_put, ffi_in, ffi_get, ffi_out):
New functions.
(ffi_init): ffi-put-into, ffi-put, ffi-in, ffi-get, ffi-out:
intrinsics registered.
* ffi.h (ffi_put_into, ffi_put, ffi_in, ffi_get, ffi_out):
Declared.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The bstr type is like str, but doesn't perform UTF-8
conversion. The C data is assumed to be null terminated byte
strings representing code points U+0000 through U+00FF.
* ffi.c (bstr_s, bstr_d_s): New symbol variables.
(ffi_bstr_put, ffi_bstr_get, ffi_bstr_d_get): New static
functions.
(ffi_init_types): Register bstr and bstr-d types.
(ffi_init): Initialize bstr_s and bstr_d_s.
* ffi.h (bstr_s, bstr_d_s): Declared.
* lib.c (chk_strdup_8bit, string_8bit): New function.
* lib.h (chk_strdup_8bit, string_8bit): Declared.
|
|
|
|
|
|
|
|
|
|
|
|
| |
bchar is like uchar, except that in the decode direction,
it produces character objects rather than integers.
* ffi.c (bchar_s): New symbol variable.
(ffi_bchar_get): New static function.
(ffi_init_types): Register bchar type.
(ffi_init): Initialize bchar_s.
* ffi.h (bchar_s): Declared.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
One more ptr type is useful. This type is for objects returned via
pointers embedded in arrays or structures, whereby the callee
establishes both the pointer and the data.
This is similar to ptr-out-d; the difference is that the
data has an indefinite lifetime ("s" denotes "static")
and so the pointer is not freed after the call takes place
and the data is extracted into Lisp objects.
* ffi.c (ptr_out_s_s): New symbol variable.
(ffi_ptr_out_s_in): New function.
(ffi_type_compile): Handle new ptr_out_s_s.
(ffi_init): Initialize ptr_out_s.
* ffi.h (ptr_out_s_s): Declared.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
We don't need type copying because the need for this
was driven by the rtvec implementation, which assigned
a unique rtidx to the nodes in a type tree, requiring
like types to be separately instantiated.
* ffi.c (struct txr_ffi_type): Remove member dup.
(ffi_struct_dup, ffi_ptr_dup): Function removed.
(make_ffi_type_builtin, make_ffi_type_struct,
make_ffi_type_array): Don't initialize dup.
(ffi_copy_type): Function removed.
(ffi_type_compile): don't call ffi_copy_type.
(ffi_init): ffi-copy-type intrinsic removed.
* ffi.h (ffi_copy_type): Declaration removed.
|
|
|
|
|
|
|
|
|
|
|
|
| |
* ffi.c (ffi_typedef_hash): New static variable.
(ffi_type_compile): Handle undefined atom case by trying
through typedef hash.
(ffi_typedef): New function.
(ffi_init): gc-protect ffi_type_compile variable and
initialize it with a hash table. Register ffi-typedef
intrinsic.
* ffi.h (ffi_typedef): Declared
|
|
|
|
|
|
|
|
|
|
|
|
| |
* ffi.c (struct txr_ffi_type): New member, dup.
(ffi_struct_dup, ffi_ptr_dup): New static functions.
(make_ffi_type_pointer, make_ffi_type_struct,
make_ffi_type_array): Set up dup virtual function for these
types.
(ffi_copy_type): New function.
(ffi_init): Register ffi-copy-type intrinsic.
* ffi.h (ffi_copy_type): Declared.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* ffi.c (closure_s, ffi_closure_s): New symbol vars.
(struct txr_ffi_closure): New type.
(ffi_closure_struct, ffi_closure_struct_checked,
ffi_closure_print_op, ffi_closure_destroy_op,
ffi_closure_mark_op): New static functions.
(ffi_closure_ops): New static struct.
(ffi_closure_put): New static function.
(ffi_type_compile): Handle closure_s to support closure type
specifier.
(ffi_closure_dispatch): New static function.
(ffi_make_closure, ffi_closure_get_fptr): New function.
(ffi_init): Initialize closure_ and ffi_closure_s.
Register ffi-make-closure intrinsic.
* ffi.c (closure_s, ffi_closure_s, ffi_make_closure,
ffi_closure_get_fptr): Likewise.
|
|
|
|
|
|
|
|
|
|
|
|
| |
* ffi.c: Move declarations of array_s and zarray_s
after void_s, to keep built-in FFI types together.
Eliminate some blank lines.
(ffi_init): Move initialization of void_s to
to match declaration order.
* ffi.h: Update declarations of type symbol variables
to match ffi.c.
(struct_s): Now declared.
|
|
|
|
|
|
|
|
|
|
|
|
| |
We have wstr strings already but no wchar type.
* ffi.c (wchar_s): New symbol variable.
(ffi_type_wchar): New macro.
(ffi_wchar_put, ffi_wchar_get): New static functions.
(ffi_type_compile): Handle wchar_s.
(ffi_init): Initialize wchar_s.
* ffi.h (wchar_s): Declared.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
A zarray is null terminated when we convert from Lisp
to C representation. The last element of the Lisp vector
is ignored and all zero bits are written to the destination
buffer in the size of the element.
* ffi.c (zarray_s): New symbol variable.
(struct txr_ffi_type): New bitfield member, null_term.
(ffi_array_in): If the array's null_term flag is set,
then don't process the last element, since the corresponding
put call wasn't done for that element in ffi_array_put.
(ffi_array_put): If the array's null_term flag is set,
then when processing the last element, just memset the
output element to zero and don't call put.
(ffi_type_compile): Recognize zarray_s and set up the
flag accordingly.
(ffi_init): Initialize zarray_s.
* ffi.h (zarray_s): Declared.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
ptr-in-d means we pass a buffer to the foreign function,
which it owns and must free. We don't touch it.
ptr-out-d is meaningful for returned values. It means
that the function returned the object in a malloced
buffer which the caller owns. It will be freed.
* ffi.c (ptr_in_d_s, ptr_out_d_s): New symbol variables.
(ffi_ptr_in_d_put, ffi_ptr_out_d_get): New static functions.
(make_ffi_type_pointer): Don't set rtsize unconditionally
to 1. If we are passed a null pointer for the in function,
set it to zero. ptr-in-d does this: it has no need to free
the buffer since the called function owns it and so
there is no in function for that type.
(ffi_type_compile): Handle ptr_in_d_s and ptr_out_d_s.
(ffi_init): Initialize ptr_in_d_s and ptr_out_d_s.
* ffi.h (ptr_in_d_s, ptr_out_d_s): Declared.
|
|
|
|
|
|
|
|
|
|
|
|
| |
Why have this verbose naming for the most basic case.
Rather, ptr-in and ptr-out are optimizations of ptr which
just avoid copying the object in one direction.
* ffi.c (ptr_in_out_s): Renamed to ptr_s.
(ffi_ptr_in_out_put): Renamed to ffi_ptr_put.
(ffi_type_compile, ffi_init): Follow rename.
* ffi.h (ptr_in_out_s): Declaration updated
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The FFI types str-d, wstr-d and buf-d are like their
unsuffixed counterparts, but indicate that ownership of a
dynamically allocated object is being passed which the
receiver is responsible for freeing.
If we pass a str, wstr or buf into a foreign function, we are
generally only guaranteeing the lifetime of the buffer over
the function call. If we pass a str-d or buf-d, then the
callee keeps the pointer indefinitely, and must free it.
If we get str or buf return value from a function, it
is assumed that the pointer is static or something borrowed
with some limited lifetime. A copy of it is made.
If we get a str-d, wstr-d or buf-d, it is assumed that
the pointer has been malloc-ed for us. The object is
either duplicated, and the original one immediately
freed, or else the pointer is retained directly in the
Lisp object and freed if that object becomes garbage.
* ffi.c (str_d_s, wstr_d_s, buf_d_s): New symbol variables.
(ffi_str_get): Coalesce assignment with declaration.
(ffi_str_d_get, ffi_str_d_put): New static functions.
(ffi_buf_d_get, ffi_buf_d_put): New static functions.
(ffi_type_compile): Handle buf_d_s, str_d_s and wstr_d_s.
(ffi_init): Initialize str_d_s, wstr_d_s and buf_d_s.
* ffi.c (str_d_s, wstr_d_s, buf_d_s): Declared.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* ffi.c (float_s): Variable removed. This is a duplicate
definition; we already have this symbol in lib.c.
(ffi_type_s): Duplicate definition removed; it is
repeated two lines below.
(ffi_str_put): Remove pointless const qualifier on u8s
variable.
(ffi_call_wrap): Cast return value of alloca. Also,
rc pointer needs to be cast to mem_t *.
(ffi_init): Remove initialization of float_s.
* ffi.h (float_s): Declaration removed.
|
|
|
|
|
|
|
|
|
|
|
| |
* ffi.c (array_s): New symbol variable.
(ffi_array_put, ffi_array_get, ffi_array_fill,
make_ffi_type_array): New static functions.
(ffi_type_compile): Support (array <dim> <type>)
syntax.
(ffi_init): Initialize array_s.
* ffi.h (array_s): Declared.
|
|
* Makefile (OBJS): Add ffi.o.
* configure (have_libffi): New variable.
(gen_config_make): Generate have_libffi make variable.
New check for availability of libffi.
* ffi.c, ffi.h: New files.
* lib.c (init): Call ffi_init.
|