| Commit message (Collapse) | Author | Age | Files | Lines |
|
|
|
|
|
|
| |
* 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.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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.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.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.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.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.c (ffi_bstr_in): New function.
(ffi_init_types): Give bstr type ffi_bstr_in as the in
function.
|
|
|
|
|
|
|
|
|
| |
* 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).
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
|
| |
* 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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.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.
|
|
|
|
|
|
|
|
|
| |
This will support a sizeof macro.
* ffi.c (ffi_size): New function.
(ffi_init): Register ffi-size intrinsic.
* ffi.h (ffi_size): Declared.
|
|
|
|
|
|
| |
* 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.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.c (c_u8, c_u16, c_u32, c_u64, c_uint): Fix messages
referring to signed version of type.
|
|
|
|
| |
* lib.c (length): Handle BUF case via length_buf.
|
|
|
|
|
| |
* arith.c (comp_trunc, logtrunc): Check for a negative
bits value and throw.
|
|
|
|
|
| |
* lib.c (mkstring, mkustring, vector, vec_set_length): Reject
negative length.
|
|
|
|
|
| |
* ffi.c (ffi_type_compile): Check for a negative buffer
size and throw.
|
|
|
|
|
|
| |
* 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.
|
|
|
|
|
|
| |
* utf8.c (utf8_dup_from): Eliminate double call to
utf8_from wrapper, which calls strlen. Call the
lower level utf8_from_buf directly.
|
|
|
|
|
|
|
|
|
|
| |
* ffi.c (struct txr_ffi_type): New bitfield flag, bchar_conv.
(ffi_array_in, ffi_array_get): Handle bchar_conv.
(ffi_type_compile): Set bchar_conv flag for array of bchar.
* lib.c (string_8bit_size): New function.
* lib.h (string_8bit_size): Declared.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
A zarray of length N is requiring the Lisp vector to be
of length N.
* ffi.c (ffi_array_put): Reorder logic in the loop so that
when we are putting out the terminating null element of a
zarray, we do not access the corresponding element of the Lisp
vector. Thus if the zarray is N elements wide, the Lisp
vector need only be at least N-1 elements wide, not N.
(ffi_array_in): Copy the null element of a zarray to the
vector only if the vector object at least N elements.
If the vector is nil so that we have to construct one,
construct a vector of N-1 for a zarray.
(ffi_array_get): For a zarray, construct a vector of N-1
elements. Do not even fetch the null.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
| |
* ffi.c (ffi_str_d_put): Function removed. It is identical to
ffi_str_put.
(ffi_init_types): Use ffi_str_put for the str-d type.
|
|
|
|
|
|
| |
* ffi.c (ffi_char_get): Get a char object as a Lisp character,
rather than number. Users who want a byte to convert to a
an integer can use one of the types int8 or uint8 instead.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The obj printer is ignoring the pretty flag when rendering
floating-point numbers, and just formatting them using
*print-flo-format*.
To address this issue, we introduce an additional
*pprint-flo-format* variable.
* lib.c (obj_print_impl): In the FLNUM case, use either
the value of *print-flo-format* or *pprint-flo-format* based
on the value of the pretty flag.
* stream.c (pprint_flo_format_s): New symbol variable.
(stream_init): Initialize pprint_flo_format_s with interned
symbol *pprint-flo-format* and register this as a special
variable.
* stream.c (pprint_flo_format_s): Declared.
* txr.1: Documented *pprint-flo-format*. Also put in a
note in the description of the various print functions
that the equivalences based on ~s and ~a only apply
to floats when the special variables have their original
values.
|
|
|
|
|
|
| |
* txr.1: Adding a paragraph under unwind-protect clarifying
that exit points are removed during unwinding, not during the
search for an exit point.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This achieves two objectives. The obvious one is that we get
a diagnostic for new expressions that name a nonexistent type,
due to a typo, before those expressions are executed.
However, this also fixes an annoying issue: spurious warnings
about nonexistent slots, related to structs which have not
yet been autoloaded. A test case for this is an expression
like (let ((b (new list-builder))) b.(add 42)). Because
list-builder is auto-loaded, the add slot doesn't exist.
But (new list-builder) doesn't trigger that auto-load; so
the deferred warning about the nonexistent slot isn't
suppressed. With this change, the existence check in
(new list-builder) will trigger the auto-load for the module
which defines list-builder, causing the add slot to exist
before the b.(add 42) expression is visited by the expander.
* share/txr/stdlib/struct.tl (sys:check-struct): New function.
(new, lnew): Issue warning if the type doesn't exist.
|
|
|
|
|
|
|
|
|
|
| |
* sysif.c (dlopen_wrap): Call dlerror() to clear the error
string. Then if the call returns null, call dlerror() again
and use the string in the exception if available.
(dlsym_error): New static function.
(dlsym_checked, dlvsym_checked): Clear error string by
calling dlerror(). Afer the call, if the pointer is null
call dlsym_error to report.
|
|
|
|
|
|
|
|
|
| |
* sysif.c (dlopen_wrap): Allow the name to be null or missing,
in which case a null pointer is passed to dlopen to access
the program image itself. Default the flags argument to
RTLD_LAZY.
(sysif_init): Re-regiser dlopen intrinsic such that both
arguments are optional.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Since the callee allocates the buffer for a ptr-out-d, the FFI
mechanism should not also be allocating a buffer to receive
the object. The buffer pointer will just be overwritten by the
callee with its own dynamic pointer. We should pass a null
pointer which the callee fills in (making a ptr-out-d not
suitable as a by-value parameter).
Initially, ptr-out-d was envisioned for return values only
and for use in callbacks, which is why I neglected this
aspect.
* ffi.c (ffi_ptr_out_null_put): New static function.
(ffi_type_compile): Use ffi_ptr_out_null_put for the
ffi_ptr_out_d case, so caller places a null pointer, then
frees the pointer that the callee places there.
|
|
|
|
|
|
| |
* ffi.c (ffi_ptr_put): Rnamed to ffi_ptr_in_put.
(ffi_type_compile): All uses of ffi_ptr_put replaced with
ffi_ptr_in_put.
|
|
|
|
|
|
|
|
|
|
| |
* ffi.c (ffi_ptr_in_put): Static function removed. It was
functionally identical to ffi_ptr_put, plus a memory leak bug
in the nil object case.
(ffi_ptr_in_d_put): Static function removed, also identical to
ffi_ptr_put.
(ffi_type_compile): Replace references to removed functions
with ffi_ptr_put.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The problem is as follows. When an aggregate is being passed
by pointer, the C code can update its elements. If any of
those elements are declared arrays or structs to FFI, but the
actual Lips object has nil slot values for those elements,
then things don't work, because nil cannot be mutated in
place to become a filled vector or struct.
The solution is to alter the in virtual function so that it
can return a value, just like the get virtual function. When
the in function for an array or struct finds it is working
with a nil Lisp object, it can construct a representative
instance and fill in that one, then return it.
* ffi.c (struct txr_ffi_type): Change return type of in
function to val.
(ffi_freeing_in, ffi_ptr_in_in, ffi_ptr_out_in): Return type
changes to val, obj that is passed in is returned.
(ffi_struct_in): Return type changes to val. If the Lisp
structure passed in is nil, then construct a default instance
of the structure by invoking make_struct on the type, with no
arguments, and then operate on that structure. In either
case, return the structure.
(ffi_array_in): Similar change to ffi_struct_in. In the cases
when we are converting character arrays to strings, if the
Lisp object is nil, we just take the decoded string as
the array and return that. In the regular array case, we
check for the object being nil, and if so, construct an empty
vector in the right size, then fill it.
(make_ffi_type_pointer): in parameter's return type
changes to val.
|
|
|
|
|
|
| |
* ffi.c (ffi_type_lookup, ffi_init_extra_types): New
functions.
(ffi_init): Call ffi_init_extra_types.
|
|
|
|
|
|
|
|
|
|
|
| |
* configure (have_sys_types): New variable. Set to "y" in
various tests which prove that the <sys/types.h>
header is available.
(HAVE_SYS_TYPES_H): Add to config.h in the dependent
variale generation section, if have_sys_types is true.
* sysif.c: Use HAVE_SYS_TYPES_H instead of relying on
HAVE_MAKEDEV.
|
|
|
|
|
|
|
|
|
| |
* ffi.c (ffi_type_compile): All cases where the syntax is an
atom just go through the ffi_typedef_hash lookup to retrieve a
single type instance.
(ffi_init_types): New function. Populates typedefs using
construction code that was previously in ffi_type_compile.
(ffi_init): Call ffi_init_types.
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Since we don't have the rtidx members in the txr_ffi_type
structure, there is no need to instantiate a type for
each element of an array. All elements can now share the
one type.
* ffi.c (ffi_array_in, ffi_array_put, ffi_array_out,
ffi_array_get, make_ffi_type_array): Refactor according to
tft->mtypes no longer being a list but a single type.
(ffi_type_compile): Do not recompile the syntax n times
for each element.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Remove features related to the supporting the removed
rtvec mechanism.
* ffi.c (struct txr_ffi_type): Member rtidx, rtsize and walk
removed.
(ffi_ptr_walk, ffi_struct_walk, ffi_type_walk,
assign_rtindices_visit, ffi_type_assign_rtindices,
ffi_compile_toplevel): Functions removed.
(make_ffi_type_pointer, make_ffi_type_struct,
make_ffi_type_array): Don't initialize rtsize and walk.
(ffi_type_compile): Don't initialize a type's rtsize.
(ffi_init): ffi-type-compile registereed to ffi_type_compile
rather than ffi_type_compile_toplevel, as was originally
the case.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Removing the rtvec[] mechanism for tracking temporary
allocations. The tft->in() calls are already walking the
object layout and so pointers can just be retrieved from the
object memory. This changes the semantics: for the better, I
think.
For example if a struct contains a (ptr str) and is passed as
(ptr (struct ...)), the C string is temporarily allocated and
stored in the C structure before the call, then freed after
the call. Now the freeing action retrieves the char * pointer
from the structure itself rather than rtvec. The semantics
change is that the pointer may have been altered by the C
function. We may be freeing a pointer other than the one we
allocated. C code which replaces the pointer must malloc it,
and free the original.
* ffi.c (struct txr_ffi_type): put and in virtual function
pointers lose the rtvec parameter.
(ffi_void_put ffi_i8_put, ffi_u8_put, ffi_i16_put,
ffi_u16_put, ffi_i32_put, ffi_u32_put, ffi_i64_put,
ffi_u64_put, ffi_char_put, ffi_uchar_put, ffi_short_put,
ffi_ushort_put, ffi_int_put, ffi_uint_put, ffi_long_put,
ffi_ulong_put, ffi_float_put, ffi_double_put, ffi_wchar_put,
ffi_cptr_put, ffi_str_d_put, ffi_wstr_put, ffi_wstr_d_put,
ffi_buf_put, ffi_buf_d_put, ffi_closure_put): Drop unused
rtvec parameter.
(freeing_in, ffi_ptr_in_in, ffi_ptr_out_in): Drop rtvec
parameter. Obtain pointer from src buffer instead.
(ffi_str_put, ffi_ptr_in_put, ffi_ptr_out_put, ffi_ptr_put):
Drop rtvec parameter and remove code which stored into rtvec.
(ffi_ptr_in_d_put, ffi_struct_put, ffi_array_put): Drop rtvec
parameter; don't pass to recursive put call.
(ffi_struct_in, ffi_array_in): Drop rtvec parameter; don't
pass to recursive in call.
(make_ffi_type_builtin, make_ffi_type_pointer): Adjust pointer
parameter declarators for put and in parameters.
(ffi_call_wrap): Remove allocation and use of rtvec.
Pass the values[i] pointer as the src parameter in the
to level in call.
(ffi_closure_dispatch): Don't pass rtvec parameter to
put call.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* ffi.c (ffi_void_put, ffi_fixed_alloc, ffi_noop_free,
ffi_void_get, ffi_i8_put, ffi_i8_get, ffi_u8_put, ffi_u8_get,
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_put, ffi_uchar_get,
ffi_short_put, 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,
ffi_cptr_alloc, ffi_freeing_in, ffi_str_d_put, ffi_str_get,
ffi_str_d_get, ffi_wstr_put, ffi_wstr_get, ffi_wstr_d_put,
ffi_wstr_d_get, ffi_buf_put, ffi_buf_get, ffi_buf_d_put,
ffi_buf_d_get, ffi_buf_alloc, ffi_ptr_in_d_put): Removed
void casts from these functions.
|
|
|
|
|
|
|
|
| |
* sysif.c (dlopen_wrap): Throw instead of returning null cptr
if the dlopen fails.
(dlsym_checked, dlvsym_checked): New static functions.
(sysif_init): Register dlsym-checked, dlvsym-checked
intrinsics.
|