| Commit message (Collapse) | Author | Age | Files | Lines |
... | |
|
|
|
|
|
|
|
|
|
| |
* ffi.c (pad_retval): Define same way regardless of
big or little endian. For instance, we don't want to
call alloca(1) for a char return value. It could be
the case on little endian targets that libffi prepares
an entire ffi_arg return value. Even though we just read
the low order byte, we still have to prepare enough space
for the whole thing.
|
|
|
|
|
|
|
| |
* ffi.c (ffi_closure_dispatch_safe): In the abort case
when we put zeros in the return value, we must overwrite
the entire ffi_arg cell, in adherence with the special
return value quirk of libffi.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This change gets TXR FFI working on Power PC 64,
big endian. Many thanks to the GCC Compile Farm.
Turns out, the libffi API has changed some years ago,
with outdated documentation lingering. Return values
for the basic integral types must all be handled with
a buffer of type ffi_arg and casting. This is true in
both ffi_call and closures: in both directions.
For instance, if a foreign function returns char, we
must retrieve a ffi_arg value (which might be as
large as 64 bits). Then we must cast this value to
char. In actual fact, on a big endian system with an
8 byte ffi_arg, the char value may be located in byte
7 of the 8 byte buffer, not in byte 0.
FFI's own test suite got this wrong and had to
be patched back in 2013: it was doing things the way
we are doing them:
https://sourceware.org/ml/libffi-discuss/2013/msg00199.html
The doc was updated at the same time to tell the truth:
https://sourceware.org/ml/libffi-discuss/2013/msg00200.html
Luckily, we can fix TXR's ffi module without damaging its
framework. The object model is flexible enough to absorb the
change. Basically, we add two new methods to the txr_ffi_type
objects: virtual functions rget and rput. We only add these
when targetting big endian. These have the same type
signature as get and put, but are specialized for handling
return values. For all integer types smaller than 64 bits,
these functions are separately implemented with distinct
semanics which handle the FFI API requirements with ffi_arg
and casting and all. For all other types, rget and rput
are identical to get and put.
* ffi.c (pad_retval, ifbe, ifbe2): New macros, conditionally
defined for big and little endian.
(struct txr_ffi_type): New members rput and rget.
(ffi_i8_rput, ffi_i8_rget, ffi_u8_rput, ffi_u8_rget,
ffi_i16_rput, ffi_i16_rget, ffi_u16_rput, ffi_u16_rget,
ffi_i32_rput, ffi_i32_rget, ffi_u32_rput, ffi_u32_rget,
ffi_char_rput, ffi_char_rget, ffi_uchar_rput, ffi_uchar_rget,
ffi_bchar_rget, ffi_short_rput, ffi_short_rget,
ffi_ushort_rput, ffi_ushort_rget, ffi_int_rput, ffi_int_rget,
ffi_uint_rput, ffi_uint_rget, ffi_long_rput, ffi_long_rget,
ffi_ulong_rput, ffi_ulong_rget, ffi_wchar_rput): New
functions.
(make_ffi_type_builtin): Take rput and rget arguments,
regardless of platform. On big endian, store these in the
corresponding members. If they are null, duplicate get and put
instead.
(ffi_type_compile, ffi_init_types): Specify the rput and rget
functions for the basic types, using the ifbe macro which
nullifies the references to functions when they don't exist on
little endian. For all other types, pass the new arguments as
null.
(ffi_call_wrap): Pad the return vaue buffer size to a minimum
size on big endian; it must be at least sizeof (ffi_alloc).
Use the rget method for the return value on big endian.
(ffi_closure_dispatch, ffi_closure_dispatch_safe): Use rput on
big endian for storing return value.
|
|
|
|
|
|
|
|
| |
* Makefile (%.ok): If the .out file differs from .expected,
don't just fail this rule. Remove the .out file also, so
that when "make tests" is repeated, the test is re-run to
regenerate it. Otherwise "make tests" will only run diff
again on the previously generated .out file.
|
|
|
|
|
|
| |
* ffi.c (ffi_call_wrap): Don't calculate in_pass_needed
in put loop, since we already calculated it in the argument
buffer allocation loop.
|
|
|
|
| |
* txr.1: Smattering of grammar fixes in ffi section.
|
|
|
|
| |
* txr.1: buf and buf-d are "types" not "parts".
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* 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.
|
|
|
|
|
|
| |
* configure: New test for endianness of the compile
target. Produces HAVE_LITTLE_ENDIAN in config.h with
a value of either 1 or 0.
|
|
|
|
|
|
|
|
|
| |
* ffi.c (ffi_type_compile): In the case when a struct type
is compiled and the Lisp struct doesn't exist, the function
creates the struct type. However, the FFI struct type syntax
allows nil as a slot name, indicating a padding field.
These nils must be scrubbed from the slot list when making
the Lisp struct type, or else an error occurs.
|
|
|
|
|
|
|
|
|
|
| |
* ffi.c (make_ffi_type_struct): Use calloc for allocating
memb, so all the Lisp objects in it are initially nil. Then
install it into the structure upfront. Afterward, as we
iterate over the slots and types and install them into the
array, we lose references to them. But now since the array is
now wired into the FFI struct type structure, these objects
are now visible to GC.
|
|
|
|
|
|
| |
* ffi.c (ffi_struct_compile): Eliminate redundant call
to ffi_type_compile, replacing it with the compiled type
we already have.
|
|
|
|
|
| |
* ffi.c (ffi_put_into, ffi_in, ffi_get, ffi_out): Add missing
error symbol argument in uw_throwf calls.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This change will make bitfield support easier.
* ffi.c (struct smemb): New member, offs.
(ffi_struct_in, ffi_struct_put, ffi_struct_out,
ffi_struct_get, ffi_struct_release): For each member, refer to
the offset in the memb array, rather than calculating it
on-the-fly.
(make_ffi_type_struct): Calculate the offset for each member.
This is exactly the same as the total_size calculation before;
just the name is changed to offs, and bit operations are used
for the alignment calculations.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* ffi.c (struct smemb): New struct type.
(struct txr_ffi_type): Removed members mnames and mtypes. New
member memb.
(ffi_type_struct_destroy_op): Free the new memb descriptor
array, and overwrite with null pointer.
(ffi_struct_type_mark): Mark eltype only if not nil.
If memb pointer is not nil, walk the array and mark it.
Remove marking of removed mtypes and mnames members.
(ffi_ptr_in_release, ffi_struct_in, ffi_struct_put,
ffi_struct_out, ffi_struct_get, ffi_struct_release): Walk the
struct members using the new array descriptor.
(make_ffi_type_struct): Allocate the memb array, and
initialize it. Remove initialization of mnames and mtypes.
(make_ffi_type_array): Remove initialization of mnames.
|
|
|
|
|
|
|
|
|
| |
* ffi.c (ffi_type_compile): The problem here is using
make_ffi_type_builtin and then installing an eltype. That type
has no gc function that will mark tft->eltype, exposing
the eltype to premature reclamation. We must change these
to use make_ffi_type_pointer. That constructor takes the
element type too, so the code gets simplified.
|
|
|
|
|
|
|
|
|
|
|
|
| |
For pointers, the code still reflects the wrong assumption
that the size and alignment are the same.
* ffi.c (make_ffi_type_pointer): Remove the size argument;
it's always passed as sizeof (mem_t *), which is pointless.
Just initialize the size and align members in a fixed way.
Use sizeof and alignof to do this right.
(ffi_type_compile): Remove size argument from all
make_ffi_type_pointer calls.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* ffi.c (struct txr_ffi_type): New member, eltype. Represents
element type of arrays and target type of pointers, so
that the mtypes member isn't overloaded for this purpose,
and will only represent the list of types of a struct.
(ffi_struct_type_mark): Mark eltype, since this function is
used by arrays also.
(ffi_ptr_type_mark): Mark eltype. Do not mark mtypes,
since the ptr types don't use it any more.
(ffi_varray_alloc, ffi_wchar_get, ffi_cptr_get,
ffi_cptr_alloc, ffi_ptr_in_in, ffi_ptr_in_d_in,
ffi_ptr_in_out, ffi_ptr_out_in, ffi_ptr_out_put,
ffi_ptr_out_out, ffi_ptr_get, ffi_ptr_d_get, ffi_ptr_in_put,
ffi_ptr_out_s_in, ffi_ptr_in_release, ffi_array_in_common,
ffi_array_put_common, ffi_array_out_common,
ffi_array_get_common, ffi_array_release_comon,
ffi_array_null_term_in, ffi_array_null_term_get,
ffi_varray_release, ffi_carray_get, ffi_carray_put): Access
eltype instead of mtypes.
(make_ffi_type_builtin): Don't initialize mnames and mtypes to
nil, since we are using calloc.
(make_ffi_type_pointer): Don't initialize mnames or mtypes to
nil. Do initialize eltype to the target type.
(make_ffi_type_array): Initialize eltype instead of mtypes.
(ffi_type_compile): For cptr and carray, initialize eltype
instead of mtypes.
|
|
|
|
|
|
|
|
| |
* txr.1: Fix false, contradictory text claiming that an
underscore may be part of a bident but not sident. (Reported
by user "death" on Reddit). Add clarifying text explaining
that only the slash character may be in a lident but not
bident, and improve some surrounding text.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* ffi.c (ffi_val_get): Throw an exception if the object
doesn't appear valid.
* gc.c (valid_object_p): New function. Invalid objects are
those that are pointers, but either not into a heap, or else
to a freed object or to an object that is marked by the
garbage collector (should only be seen while GC is running).
All others are valid. There can be false positives here: a
value with the LIT tag is in fact a pointer, but we don't
check whether that is valid.
* gc.c (valid_object_p): Declared.
* txr.1: Remarks added to documentation of FFI val type.
|
|
|
|
|
|
|
| |
* arith.c (bits): Change the linkage from
internal to external.
* arith.h (bits): Declared.
|
|
|
|
|
| |
* txr.1: Under callf, give equivalence to juxt.
Also refer to callf from juxt.
|
|
|
|
|
| |
* txr.1: typeset couple of example printf calls
properly in discussion of variadic FFI call descriptors.
|
|
|
|
|
|
|
|
|
|
|
| |
* 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.
|
|
|
|
|
|
|
|
|
|
| |
* RELNOTES: Updated.
* configure, txr.1: Bumped version and date.
* share/txr/stdlib/ver.tl: Likewise.
* txr.vim, tl.vim, protsym.c: Regenerated.
|
|
|
|
|
|
|
|
|
| |
* tests/017/glob-carray.tl (glob-t): Restructure
to case statement. Add padding to struct based on
looking at the glibc definition. Add FFI definition
based on Cygwin header.
* tests/017/glob-zarray.tl (glob-t): Likewise.
|
|
|
|
|
|
|
|
|
|
|
|
| |
Replace the incorrect alignment assumption for the basic types
(size == alignment) with the true calculation obtained from the
compiler.
* ffi.c (alignof): New macro.
(make_ffi_type_builtin): Take alignment as separate argument.
(ffi_type_compile, ffi_init_types): Using alignof macro,
calculate alignment of each type that is created using
make_ffi_type_builtin, and pass to that function.
|
|
|
|
|
|
|
|
|
| |
* tests/017/glob-carray.tl (glob-t): Initialize reserve
member to 0. Since it doesn't exist on Darwin, it will
stay nil, and change the the test output. A Darwin variant
of the corresponding FFI type is provided.
* tests/017/glob-zarray.tl (glob-t): Likewise.
|
|
|
|
|
|
|
|
|
| |
* configure: New test for realpath.
* sysif.c (realpath_wrap): New static function.
(sysif_init): Registered realpath intrinsic.
* txr.1: Documented.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* stream.c (path_sep_chars): New global variable.
(detect_path_separators): New static function.
(base_name, dir_name): New functions.
(stream_init): Call detect_path_separators. Register base-name
and dir-name intrinsic functions, and path-sep-chars variable.
* stream.h (path_sep_chars, base_name, dir_name): Declared.
* txr.c (dirname): Static function removed.
(sysroot_init): Use dir_name instead of dirname.
* txr.1: Documented dir-name, base-name and path-sep-chars.
|
|
|
|
|
|
| |
* txr.1: Adding text to abs-path-p description which
emphasizes that the definition of absolute path it uses
is platform-agnostic.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The realpath function is called using FFI. One approach
passes a null pointer, so that the function dynamically
allocates. The return value is str-d, causing FFI to take
ownership of the pointer, freeing it. The other approach
is to pass a pointer to a large null-terminated character
array, marked for ownership transfer to the function. FFI
allocates it and puts the argument into it, which is just
a dummy empty string. The function fills that buffer and
returns it. The return is captured as a str-d, so FFI takes
ownership back, and frees the buffer.
* tests/017/realpath.tl: New function.
* tests/017/realpath.expected: Likewise.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
One approach captures the paths as a carray of
strings, and explicitly frees it with globfree.
The other approach uses a zarray, taking advantage
of null termination. globfree is elided because TXR FFI
does the freeing; the types used declare to it that it
is taking ownership of a dynamically allocated vector of
dynamically allocated strings, and so it performs the
equivalent of globfree.
* tests/017/glob-carray.expected: New file.
* tests/017/glob-carray.tl: Likewise.
* tests/017/glob-zarray.expected: Likewise.
* tests/017/glob-zarray.tl: Likewise.
|
|
|
|
|
|
|
|
| |
Materials specific to distribution building and packaging
systems should be maintained by distributions; they
don't belong in the projects themselves.
* txr.spec: File removed.
|
|
|
|
|
|
|
|
| |
* lisplib.c (ffi_set_entries): Autload entry for "deffi-var".
* share/txr/stdlib/ffi.tl (deffi-var): New macro.
* txr.1: Documented.
|
|
|
|
|
| |
* txr.1: typedef moved below deffi-cb, so it it is together
with sizeof.
|
|
|
|
|
|
|
| |
* share/txr/stdlib/ffi.tl (deffi): Since the arity of
a foreign function is fixed, generate a fixed-argument
defun. This provides a better check on the number of
arguments than letting ffi-call detect it.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* 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.
|
|
|
|
|
|
|
|
|
|
| |
* lisplib.c (ffi_set_entries): Add carray-ref to list of
autoload names.
* share/txr/stdlib/ffi.tl (carray-ref, carray-refset):
Registered function pair as a simple accessor.
* txr.1: Updated carray-ref doc.
|
|
|
|
|
|
|
|
| |
* ffi.c (ffi_varray_null_term_in): New static function.
(ffi_type_compile): Wire in new function as in operation
of variable length zarray.
* txr.1: Documented.
|
|
|
|
|
|
|
|
|
| |
* 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_buf): Do not allow an element type with
zero size; throw an exception.
|
|
|
|
|
|
|
| |
* ffi.c (carray_buf): Do the buf_get first, then
length_buf, since buf_get takes a self argument.
This way the diagnostic is better if the object
isn't a buf.
|
|
|
|
|
|
|
|
|
| |
* ffi.c (carray_cptr): New function.
(ffi_init): Registered intrinsic.
* ffi.h (carray_cptr): Declared.
* txr.1: Documented.
|
|
|
|
|
|
|
| |
* txr.1: Fix misleading text which says that variable
arrays correspond to pointers. They do not; they must
be wrapped in expicit (ptr ...). Also documenting
new get operation of variable zarray.
|
|
|
|
|
|
| |
* ffi.c (ffi_varray_null_term_get): New static function.
(ffi_type_compile): Install the new get function for
variable length zarray.
|
|
|
|
|
|
|
|
|
| |
Ban types like (struct foo (bar void)) or
(array 3 (array int)).
* ffi.c (ffi_struct_compile): Check every element type for
zero size and diagnose.
(ffi_type_compile): Likewise, for arrays.
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* share/txr/stdlib/awk.tl (sys:awk-state loop):
Wrap a loop around around the two forms that
split the record into fields and dispatch the main
rule function. The loop repeats if the named
block returns :awk-again.
(sys:awk-mac-let): New local macro (again)
which bails out of the :awk-rec block just like (next) does,
but specifies :awk-again as the return value.
* txr.1: Documented.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Continuing on the topic of the previous commit, what if in a
callback an error occurs in the put operation that produces
the return value? In that case we end up clobbering with
the abort_retval or nulling out with zero bytes, either way
potentially leaking memory.
* ffi.c (ffi_closure_dispatch_safe): If the return value type
has release semantics, then as the very first thing, null out
the return value buffer. Then later if a dynamic control
transfer is intercepted, invoke the release semantics before
doing anything to the return value buffer.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The problem is that the argument conversions in a FFI call can
bail due to an exception, leaving the argument space partially
initialized, and containing pointers to temporary buffers that
have been allocated with malloc.
In this change, we take care of this problem.
We introduce a new virtual function called release to the FFI
type hieararchy. Most types do not implement this: only types
that have something to free, or aggregates which have to
iterate over element types.
The release virtual relies on pointers being null if nothing
has been allocated. For this reason, we allocate the argument
space and all temporar areas with zero filling.
* ffi.c (zalloca): New macro.
(struct txr_ffi_type): New member function pointer, release.
(ffi_fixed_alloc): Use chk_calloc instead of chk_malloc,
so that any pointers in the area are null.
(ffi_varray_alloc): Use chk_calloc, which simplifies the
code.
(ffi_simple_release, ffi_ptr_in_release, ffi_struct_release):
New static functions.
(ffi_array_release_common, ffi_array_release,
ffi_varray_release): New static functions.
(make_ffi_type_pointer): New argument for specifying release
function.
(make_ffi_type_struct): Initialize release member of type
structure to ffi_struct_release.
(make_ffi_type_array): Initialize release member of type
structure to ffi_array_release.
(ffi_type_compile): Set up release function for varray,
several ptr variants and buf-d.
(ffi_init_types): Set up release function for string types.
(ffi_call_wrap): Internals restructured. Instead of repeatedly
processing type and arg lists, we now store them into arrays
allocated with alloca. We allocate the argument space with
zalloca instead of alloca. Allocating the arguments is
separated from the put conversions into two loops, because
the alloca calls must be outside of the unwind catching
block. This is because the unwind control transfer will roll
back the alloca allocation done since the establishment of
the catch block! A new unwind block now iterates over the
arguments and calls release on each one which has a release
function.
|