summaryrefslogtreecommitdiffstats
Commit message (Collapse)AuthorAgeFilesLines
...
* ffi and buf porting: stdarg.h needed.Kaz Kylheku2017-05-112-0/+2
| | | | * buf.c, ffi.c: Must include <stdarg.h> for va_list.
* dlopen: broken dlvsym configure test.Kaz Kylheku2017-05-111-3/+3
| | | | | | | * configure: the dlvsym test relies on a nonexistent make variable EXTRA_CFLAGS. The correct one is EXTRA_FLAGS. The function name is misspelled in the test code and the test message.
* ffi: support programmable abort return value.Kaz Kylheku2017-05-114-15/+44
| | | | | | | | | | | | | | | | | | | | | | | | | * 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.
* ffi: a measure of safety for callbacks.Kaz Kylheku2017-05-114-19/+147
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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: encode-side character array specializations.Kaz Kylheku2017-05-111-2/+65
| | | | | | | | | | | | If the object being encoded is a string, and the array element type is char, wchar or bchar, then encode a string, honoring null termination flag. Unused space in the destination array is filled with zeros. * ffi.c (ffi_char_array_put, ffi_wchar_array_put, ffi_bchar_array_put): New functions. (ffi_array_put, ffi_array_out): Use new functions under the right conditions.
* ffi: split varray behavior into separate virtuals.Kaz Kylheku2017-05-101-21/+26
| | | | | | | | | | | | | | * ffi.c (struct txr_ffi_type): is_varray flag removed. We no longer need to test this and adjust behavior. (ffi_array_in, ffi_array_out): Don't calculate nelem differently based on flag; just pass down tft->nelem. Code cleaned up. (ffi_varray_put, ffi_varray_in): New functions. (ffi_type_compile): Use ffi_varray_put and ffi_varray_in for variable array type instead of setting flag. Also, specify the out function as null; it never made sense to have one, since there is no get. Finally, set the size of the type to zero, since it has no pass by value semantics.
* ffi: bugfix: wrong type in allocation of varrays.Kaz Kylheku2017-05-101-2/+4
| | | | | | * ffi.c (ffi_varray_alloc): We must use the element type's size, not the array's size. Also, cosmetic issue in error message fixed.
* ffi: refactor array transfers.Kaz Kylheku2017-05-101-28/+58
| | | | | | | | | | | | | | This anticipates a redesign of variable arrays. Variable arrays will have their own put, in, get and out functions, which will share some implementation. * ffi.c (ffi_array_in_common): New function. (ffi_array_in): Bulk of code replaced by call to ffi_array_in_common. (ffi_array_put_common, ffi_array_out_common, ffi_array_get_common): New functions. (ffi_array_put, ffi_array_out, ffi_array_get): Reduced to thin wrappers.
* ffi: check against types that can't pass by value.Kaz Kylheku2017-05-101-2/+15
| | | | | | * ffi.c (ffi_make_call_desc): Throw if any argument type is something with zero size. Throw if the return type has zero size and isn't the type void.
* ffi: reduce char array code repetition.Kaz Kylheku2017-05-101-70/+53
| | | | | | | * ffi.c (ffi_char_array_get, ffi_wchar_array_get, ffi_bchar_array_get): New static functions. (ffi_array_in, ffi_array_get): Replace common code with calls to code moved out into functons.
* ffi: bugfix: use nelem, not size, in array in and get.Kaz Kylheku2017-05-101-4/+4
| | | | | | | | | Arrays can be varray, whose size is just pointer size. The string extraction operations shouldn't be referring to the size. * ffi.c (ffi_array_in, ffi_array_et): Use nelem instead of tft->size.
* ffi: do arg in semantics /after/ getting return val.Kaz Kylheku2017-05-101-1/+4
| | | | | | | | | | | | What this allows is for situations when a foreign function returns the pointer that it has been passed. If that pointer is temporary storage allocated by FFI, then it is no longer valid after performing the in pass on the args. Therefore, we should decode the return value first, while the returned pointer is valid. * ffi.c (ffi_call_wrap): Move the return value get before the argument post-processing in pass.
* ffi: adjust semantics of zarray of characters.Kaz Kylheku2017-05-102-14/+34
| | | | | | | | | | | | | We want to be able to extract null-terminated UTF-8 strings from arrays, without trailing junk, yet retain the ability to extract the entire array including embedded nulls. The natural way is to use the array/zarray distinction. * ffi.c (ffi_array_in, ffi_array_get): Don't try to guess whether the array is null terminated; just rely on the null_term flag, and treat accordingly. * txr.1: Doc updated.
* doc: cptr.Kaz Kylheku2017-05-101-0/+149
| | | | * txr.1: The cptr type is now documented.
* doc: relocate and rewrite buffer literal description.Kaz Kylheku2017-05-091-12/+25
| | | | | | * txr.1: Buffer literals are now described much earlier in the document under Additional Syntax rather than in the Buffers section.
* doc: add buf and cptr to type diagram.Kaz Kylheku2017-05-091-1/+5
| | | | * txr.1: Update ASCII diagram in Object Types section.
* doc: dlopen added.Kaz Kylheku2017-05-091-0/+166
| | | | | * txr.1: Documented dlopen, dlclose and friends, plus the rtld-* variables.
* cptr: new functions.Kaz Kylheku2017-05-093-0/+35
| | | | | | | | | | * eval.c (eval_init): Register cptr-int, ctpr-obj, cptr-zap and cptr-free functions and cptr-null variable. * lib.c (cptr_int, cptr_obj, cptr_zap, cptr_free): New functions. * lib.c (cptr_int, cptr_obj, cptr_zap, cptr_free): Declared.
* ffi: remove cptr stuff.Kaz Kylheku2017-05-091-7/+0
| | | | | * ffi.c (cptr_make): Function removed. (ffi_init): Registration of cptr and cptr-null removed.
* ffi: integers and chars may convert to C float.Kaz Kylheku2017-05-092-7/+33
| | | | | | | | | * ffi.c (ffi_float_put, ffi_double_put): Support a useful type looseness by allowing integers and character Lisp values to pair with FFI floating-point types, imitating the conversion which happens in C function calls. * txr.1: Updated.
* doc: FFI module documented.Kaz Kylheku2017-05-091-0/+1618
|
* ffi: eliminate memcpy in basic gets and puts.Kaz Kylheku2017-05-081-52/+36
| | | | | | | | | | | | | | * ffi.c (ffi_i8_put, ffi_u8_put, ffi_i16_put, ffi_i16_get, ffi_u16_put, ffi_u16_get, ffi_i32_put, ffi_i32_get, ffi_u32_put, ffi_u32_get, ffi_i64_put, ffi_i64_get, ffi_u64_put, ffi_u64_get, ffi_char_put, ffi_char_get, ffi_uchar_get, ffi_short_get, ffi_ushort_put, ffi_ushort_get, ffi_int_put, ffi_int_get, ffi_uint_put, ffi_uint_get, ffi_long_put, ffi_long_get, ffi_ulong_put, ffi_ulong_get, ffi_float_put, ffi_float_get, ffi_double_put, ffi_double_get, ffi_wchar_put, ffi_wchar_get, ffi_cptr_put, ffi_cptr_get): memcpy operations replaced by by assignments through pointer casts.
* ffi: improve printed representation of closures.Kaz Kylheku2017-05-081-1/+2
| | | | | | * ffi.c (ffi_closure_print_op): Add information to the printed representation: the Lisp function, and call desc. Eliminate spurious # character before closing angle bracket.
* ffi: don't zero out anonymous struct padding.Kaz Kylheku2017-05-081-4/+0
| | | | | | | | | | * ffi.c (ffi_struct_put, ffi_struct_out): Just skip the space corresponding to the anonymous padding member; don't memset with zeros. Doing this is inconsistent because we are not zero-filling the ordinary alignment padding between members and at the end of the struct. If the uninitialized garbage is a problem in some uses, we can provide a variation of the struct type which is zero initialized.
* doc: documenting buffers.Kaz Kylheku2017-05-081-0/+739
|
* buffers: correct length check in buf-put- functions.Kaz Kylheku2017-05-081-2/+3
| | | | | | | * buf.c (buf_put_bytes): We must extend the buffer based on looking at the end position of the data transfer, not the start position, so the buffer is large enough to old the entire transfer.
* buffers: don't let a buffer shrink to zero.Kaz Kylheku2017-05-081-4/+6
| | | | | | | * buf.c (buf_shrink): If a buffer has zero length, don't shrink the allocation size all the way down to zero, because that value indicates a non-resizeable buffer.
* ffi: varray: write out all elements of Lisp seq.Kaz Kylheku2017-05-071-2/+2
| | | | | | | * ffi.c (ffi_array_put, ffi_array_out): If dealign with a variable array that is null terminated, let's add one to nelem, so that all elements of the Lisp sequence are converted, and then a null.
* ffi: rethink passing and alloc scheme for bufs.Kaz Kylheku2017-05-073-23/+34
| | | | | | | | | | | | | | | | | Backing out of the scheme of (ptr buf) passing the address of the internal pointer within buf objects. Also giving buf in handlers, to prevent the fallback on get. * buf.c (buf_addr_of): Function removed. * buf.h (buf_addr_of): Declaration removed. * ffi.c (ffi_buf_in, ffi_buf_d_in): New functions. (ffi_buf_alloc): Function removed. (ffi_type_compile, ffi_init_types): Remove specialty alloc and free functions from buffers, so the regular fixed allocator is used. Give buffers the new in functions.
* ffi: semantics: ptr-in should recurse on in.Kaz Kylheku2017-05-071-1/+14
| | | | | | | | | | * ffi.c (ffi_ptr_in_in): Don't just free the buffer for the pointer itself, but call the in handler of the target type if it has one. Pass a false copy flag to it, so that that a ptr-in pass semantically resembles a by-value pass. (ffi_ptr_in_d_in): New static function. (ffi_type_compile): Give ptr-in-d type the ffi_ptr_in_d_in function.
* ffi: bugfix: all in calls must fall back on get.Kaz Kylheku2017-05-072-4/+12
| | | | | | | | | | | | | | | | * 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.
* ffi: bufix: elide get if copy flag is false.Kaz Kylheku2017-05-071-2/+2
| | | | | | | | | | * ffi.c (ffi_struct_in, ffi_array_in): Only fall back on get if the copy flag is true. If the copy flag is false, we must not extract. That's not ony as an optimization (no point in extracting back from by-value objects). We also avoid extracting from pointers we don't own, like in the case of str-d, where the pointer is owned by the foreign function and may have been freed.
* ffi: bugfix: all out calls must fall back on put.Kaz Kylheku2017-05-071-4/+10
| | | | | | | * ffi.c (ffi_struct_out, ffi_array_out): For any element which has no out function, do a put if the copy flag is true. Otherwise callbacks cannot update members in aggregates passed by pointer.
* ffi: bugfix: bstr needs in operation, like str.Kaz Kylheku2017-05-071-3/+20
| | | | | | * ffi.c (ffi_bstr_in): New function. (ffi_init_types): Give bstr type ffi_bstr_in as the in function.
* ffi: bugfixes: out pointer must be checked.Kaz Kylheku2017-05-061-2/+6
| | | | | | | | | * ffi.c (ffi_closure_dispatch): Only call out on those arguments which have a non-null out pointer, otherwise we will crash. Those non-null values are the reason we even execute that loop at all. (ffi_out): Do a put for basic types (which have no out handler).
* ffi: reduce (array void t) syntax to (array t).Kaz Kylheku2017-05-061-28/+33
| | | | | | | | | | Omission of the dimension will be expressed by actual omission rather than the void placeholder. It's just a harmless bit of parsing providing a reasonably intuitive syntax that doesn't leave readers wondering what void is doing there. * ffi.c (ffi_type_compile): Rearrange array parsing code. Also diagnose if the form has more than thre elements.
* ffi: add macro language.Kaz Kylheku2017-05-062-0/+110
| | | | | | | | * lisplib.c (ffi_set_entries, ffi_instantiate): New static functions. (lisplib_init): Register auto-loading of ffi.tl. * share/txr/stdlib/ffi.tl: New file.
* ffi: handle copy flag in str type's in virtual.Kaz Kylheku2017-05-061-4/+6
| | | | | | | | | | | | | | | This solves the second issue described in parent commit. When a str type is passed in-out using (ptr str) in a struct or array, the struct or array is not picking up the new string. The pointer is freed, but the old object persists. * ffi.c (ffi_str_in): Function renamed to ffi_str_in. If the copy flag is true, retrieves a string from the pointer and that string is returned instead of the incoming one, mapping a null pointer to nil. Either way, the pointer is freed. Since ffi_ptr_out_in passes 1 for the copy flag, that ensures we extract the new string and plant it into the array.
* ffi: in function copy flag: fixes two issues.Kaz Kylheku2017-05-061-21/+21
| | | | | | | | | | | | | | | | | | | | | We have two problems. Firstly, the in handler is being called on by-value struct and array arguments, and is wastefully updating the members in the Lisp object. The second issue is opposite the str type fails to retrieve the updated string because ffi_freeing_in just frees. We don't address this issue here, but the groundwork is laid to fix it in the next commit. * ffi.c (struct txr_ffi_type *): Add a copy flag argument to the in virtual function. (ffi_freeing_in, ffi_ptr_in_in, ffi_ptr_out_in, (ffi_ptr_out_in, ffi_ptr_out_s_in): Take new copy argument. Don't pass it down to the recursive in; pass 1. (ffi_struct_in, ffi_array_in): Take copy argument and pass it down. (make_ffi_type_pointer): Type of in parameter updated. (ffi_call_wrap): Pass 0 to top level in functions. (ffi_in): Pass to in, so new object is returned.
* ffi: varray featureKaz Kylheku2017-05-061-3/+27
| | | | | | | | | | | | | | | | | If an array dimension is void, it is a varray. The C representation is pointer. The size is inferred from the length of the object. Doesn't support get method. * ffi.c (struct txr_ffi_type): New bitfield flag, is_varray. (ffi_varray_alloc): New function. (ffi_array_in, ffi_array_put, ffi_array_out): Check is_varray flag and use dynamic array size from object. (ffi_type_compile): If the array dimension is the symbol void, create a varray: a mongrel created using make_ffi_type_pointer, but using the array functions, plus alloc and free handlers, and the is_varray flag being set.
* ffi: remove unchanging param from make_ffi_pointer.Kaz Kylheku2017-05-061-9/+2
| | | | | | | | * ffi.c (make_ffi_type_pointer): The underlying ffi type is always ffi_type_pointer, so the parameter for specifying it is removed, and it is hard-coded. (ffi_type_compile): Remove &ffi_type_pointer argument from a half dozen calls.
* ffi: ffi-size function.Kaz Kylheku2017-05-062-0/+8
| | | | | | | | | This will support a sizeof macro. * ffi.c (ffi_size): New function. (ffi_init): Register ffi-size intrinsic. * ffi.h (ffi_size): Declared.
* Fix broken quasilist print notation.Kaz Kylheku2017-05-051-1/+0
| | | | | | * lib.c (obj_print_impl): Remove spurious output statement from quasi word list literal printing code. The spurious output completely ruins the printed representation.
* ffi: functions for type-system-driven buffer coding.Kaz Kylheku2017-05-042-0/+66
| | | | | | | | | | * 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.
* itypes: fix wrong error messages.Kaz Kylheku2017-05-041-5/+5
| | | | | * itypes.c (c_u8, c_u16, c_u32, c_u64, c_uint): Fix messages referring to signed version of type.
* length: support buffer objects.Kaz Kylheku2017-05-041-0/+2
| | | | * lib.c (length): Handle BUF case via length_buf.
* Disallow negative bits in two logical operations.Kaz Kylheku2017-05-041-0/+12
| | | | | * arith.c (comp_trunc, logtrunc): Check for a negative bits value and throw.
* Detect negative length in string, vec construction.Kaz Kylheku2017-05-041-3/+16
| | | | | * lib.c (mkstring, mkustring, vector, vec_set_length): Reject negative length.
* ffi: reject negative buf size.Kaz Kylheku2017-05-041-0/+5
| | | | | * ffi.c (ffi_type_compile): Check for a negative buffer size and throw.
* ffi: check array dimensions.Kaz Kylheku2017-05-041-1/+11
| | | | | | * ffi.c (ffi_type_compile): Throw error if the dimension is negative in any array operator, or also if it is zero in a zarray operator.