| Commit message (Collapse) | Author | Age | Files | Lines |
... | |
|
|
|
|
| |
* lib.c (lastcons): Don't wastefully call cdr on an object
after called cdr_l; just dereference the cdr_l loc.
|
|
|
|
|
|
|
|
|
|
|
| |
* lib.c (tail): This low-level function is used by the
list accumulation routines. Because it doesn't handle
improper lists, looking for a null terminator, certain
things don't work, like the associativity of append.
For instance (append '(1 2) #(3) 4) works but not
(append (append '(1 2) #(3)) 4). Fixing tail so that it
terminates on any atom, rather than failing trying to
cdr through it.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Two bugs in these functions, both attributable to
the lazy_appendv implementation:
They destructively catenate the input lists,
much like nconc, even though documented as
non-destructive.
If any input list is infinite, other than the
last input list, that list is forced, resulting
in an infinite loop.
* lib.c (lazy_appendv_func): Rewritten to use a
different algorithm which earnestly allocates a
new lazy cons for each element of the output
sequence, except for the tail part corresponding
to the last list.
(lazy_appendv): Set up the lazy cons according
to the new representation and just return it.
No searching for the tail of the nonempty list,
and no destructive manipulation.
|
|
|
|
|
|
|
|
|
|
|
| |
* lib.c (find, rfind, find_max, find_if, rfind_if, pos, rpos,
pos_if, rpos_if, pos_max): Consistently fixnum indices for
iterating over vector. In some functions, a cnum is already
used, but could be out of fixnum range; we switch to using
c_fixnum for extracting the length and then num_fast on the
index. Some functions are converted from using a val index.
In the case of rfind_if, a bug is fixed: it was using plusp,
which now becomes the correct >= 0.
|
|
|
|
| |
* lib.c (pos_max): Rewrite using seq_info.
|
|
|
|
|
|
| |
* lib.c (find_max): Fix a regression introduced
in recent work: only execute the loop when the vector isn't
empty.
|
|
|
|
| |
* lib.c (pos_if, rpos_if): Rewrite using seq_info.
|
|
|
|
|
|
|
| |
* lib.c (posq, posql, posqual, rposq, rposql, rposqual): These
functions are reduced to wrappers around pos and rpos,
respectively, so they generalize properly and efficiently
to sequences of all kinds.
|
|
|
|
|
|
|
| |
* lib.c (pos, rpos): Functions rewritten to use the seq_info
sequence classification mechanism. The rpos function is
thereby optimized to work with vectors. Both functions support
vector-like struct objects now.
|
|
|
|
|
|
|
|
|
|
| |
* lib.c (rfind_if): Function rewritten to use the seq_info
sequence classification mechanism, for much better
performance on vector-like objects. Also, supports hash
tables just like find_if.
* txr.1: Documentation updated regarding hash support
of rfind-if.
|
|
|
|
|
|
|
|
|
|
| |
* lib.c (find_if): Function rewritten to use the seq_info
sequence classification mechanism, for much better
performance on vector-like objects. Also, supports hash
tables just like find_max.
* txr.1: Documentation updated regarding hash support
of find-if.
|
|
|
|
|
|
| |
* lib.c (find_max): The vector case must loop from
index one, not zero, so as not to wastefully compare the
initial max element to itself.
|
|
|
|
|
|
|
| |
* lib.c (find_max): Sequence classification rewritten to use
seq_info. The cases are almost the same, but refer to si.obj
rather than seq. Some care is taken in the list case to not
hold a reference to the list head.
|
|
|
|
|
|
| |
* lib.c (rfind): Instead of treating the sequence as a list,
classify with seq_info just like find. Basically the whole
function is replaced with an altered copy of find.
|
|
|
|
|
|
|
| |
* lib.c (find): Convert switch statement to use the seq_info
function to classify the sequence. For SEQ_VECLIKE,
we still check whether the original object is a literal
or regular string to treat it specially.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Bunch of issues here: broken pre-171 compatibility,
non-termination on lazy infinite lists of indices,
doc issues.
* lib.c (partition_func, split_func, split_star_func): Do the
check for negative index values here, with the compat handling
for 170 or older.
(partition_split_common): Remove code that tries to adjust
negative indices, and delete zeros or indices that are still
negative after adjustment. The code consumes the entire list
of prefixes, so chokes on lazy lists. Also in the compat case,
there is complete breakage: the loop doesn't execute, and so
out is just nil, and it is taken as the index list.
(partition_star_func): Similar change like in partition_func.
(partition_star): Similarly to partition_split_common, take
out the bogus loop. Also take out loop that tries to remove
leading negatives: we cannot do that because we haven't
normalized them.
* txr.1: Revised doc. Condensed by describing index-list
argument in detail under partition. For the other functions,
we refer to that one. Conditions for safely handling infinite
list of indices spelled out.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The purpose of this commit is to address certain situations in
which code is wrongly relying on a cnum value being in the
fixnum range (NUM_MIN to NUM_MAX), so that num_fast can safely
be used on it.
One wrong pattern is that c_num is applied to some Lisp value,
and that value (or one derived from it arithmetically) is then
passed to num_fast. The problem is that c_num succeeds on
integers outside of the fixnum range. Some bignum values
convert to a cnum successfully. Thus either num has to be used
instead of num_fast, or else the original c_num attempt must
be replaced with something that will fail if the original
value isn't a fixnum. (In the latter case, any arithmetic on
the fixnum cannot produce value outside of that range).
* buf.c (buf_put_bytes): The size argument here is not
guaranteed to be in fixnum range: use num.
* combi.c (perm_init_common): Throw if the sequence length
isn't a fixnum. Thus the num_fast in perm_while_fun is
correct, since the ci value is bounded by k, which is bounded
by n.
* hash.c (hash_grow): Remove dubious assertion which aborts
the run-time if the hash table doubling overflows. Simply
don't allow the modulus to grow beyond NUM_MAX. If doubling
it makes it larger than NUM_MAX, then just don't grow the
table. We need the modulus to be in fixnum range, so that
uses of num_fast on the modulus value elsewhere are correct.
(group_by, group_reduce): Use c_fixnum rather than c_num to
extract a value that is later assumed to be a fixnum.
* lib.c (c_fixnum): New function.
(nreverse, reverse, remove_if, less, window_map_list,
sort_vec, unique): Use c_fixnum rather than c_num to extract a
value that is later assumed to be a fixnum.
(string_extend): Use c_fixnum rather than c_num to extract a
value that is later assumed to be a fixnum. Cap the string
allocation size to fixnum range rather than INT_PTR_MAX.
(cmp_str): The wcscmp function could return values outside
of the fixnum range, so we must use num, not num_fast.
* lib.h (c_fixnum): Declared.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
One test case for this is that (append "ABC" "DEF")
returns an "ABCDEF" string whose length reports as 9
instead of the correct 6. This will wreak various havoc.
The bug was introduced in the very first version of
replace_str, in commit d011fda9b6b078f09027eb65d500c8beffc99414
on January 26, 2012.
In the same commit, the string_extend behavior is
introduced of supporting an integer value specifying the
number of characters by which to extend the string.
This feature of string_extend is used in replace_str,
but wrongly.
* lib.c (replace_str): Pass just the size delta
to string_extend; do not add the old length to the
delta such that the total size is wrongly passed.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
We don't want to be aborting on OOM, but throwing an
exception.
* lib.c (alloc_error_s): New symbol variable.
(oom_realloc): Global variable removed.
(oom): New static function.
(chk_malloc, chk_malloc_gc_more, chk_calloc, chk_realloc):
Call oom instead of removed oom_realloc handler.
(env): Throw alloc-error rather than error by calling oom.
(obj_init): Initialize alloc_error_s.
(init): Drop function pointer argument; do not
initialize removed oom_realloc.
* lib.h (alloc_error_s): Declared.
(oom_realloc): Declaration removed.
(init): Declaration updated.
* txr.1: Type tree diagram includes alloc-error.
|
|
|
|
|
|
|
| |
* lib.c (vec_set_length): Check new length against INT_PTR_MAX
rather than size_t limit. We want to keep the length a fixnum.
If the allocation needs to increase, grow it by 25%, not by
doubling it.
|
|
|
|
|
|
|
|
|
|
| |
* lib.c (string_extend): Restructure internals with these
goals: no loop: calculate needed space in one step; if the
allocation needs to grow, then grow it by 25% or step it
up to exactly the needed size, whichever of the two is
larger. Overflow check against INT_PTR_MAX, since len and alloc
fields of string are not fixnums but integers extracted
with c_num.
|
|
|
|
|
|
|
|
| |
* eval.c (eval_init): Register spl and tok intrinsics.
* lib.c (spl, tok): New functions.
* txr.1: Documented.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
We are allowing calls like (* "a") and (+ "a")
without diagnosing that the argument isn't of a valid
type. Note that (max "a") is fine beacause min and
max use the less function; they are not strictly numeric.
* lib.c (nary_op): Beef up function with additional argument
for type checking the unary case.
(unary_num, unary_arith, unary_int): New static functions.
(plusv, mulv, logandv, logiorv): Use new nary_op interface.
(gtv, ltv, gev, lev, numeqv, numneq): Check the
first number.
* lib.c (nary_op): Declaration updated.
|
|
|
|
|
|
|
|
|
|
| |
* eval.c (eval_init): prod and sum intrinsics registered.
* lib.c (sum, prod): New functions.
* lib.h (sum, prod): Declared.
* txr.1: Documented.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* eval.c (eval_init): Register set-diff under two
names: set-diff and diff. Register new isec and uni
intrinsics.
* lib.c (isec, uni): New functions.
* lib.h (isec, uni): Declared.
* txr.1: Documented new uni and isec functions, new diff
function name, and the deprecation of set-diff and its order
guarantee w.r.t the left sequence.
|
|
|
|
|
|
|
|
|
|
|
| |
* lib.c (find, pos): Provide specialized behavior based
on type and test and key functions. Lists and list-like
objects are treated by marching down with cdr. Vectors are
traversed with numeric index, as are vector-like objects which
exhibit a length function. A special optimization is put in
for non-lazy strings which use identity as their key function,
and one of the built-in equality operators for the test
function: wcschr is used on the underlying C string.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Just the ANSI CL nth for lists.
* eval.c (eval_init): Register nth intrinsic.
* lib.c (nth): New function.
* lib.h (nth): Declared.
* share/txr/stdlib/place.tl (nth): New place macro,
trivially takes care of making nth an accessor.
Place macros are terrific!
* txr.1: Documented.
|
|
|
|
|
|
|
|
|
|
|
| |
* eval.c (eval_init): Register new intrinsic relate.
* lib.c (do_relate, do_relate_dfl): New static functions.
(relate): New function.
* lib.h (relate): Declared.
* txr.1: Documented.
|
|
|
|
|
|
|
|
|
|
|
|
| |
For convenience, we allow a cptr to be converted to foreign
representation even if its tag doesn't match the FFI type
being used for the conversion. This is allowed only in the
case that the cptr is a null pointer, and its tag is nil.
* lib.c (cptr_handle): Defeat the type check if the pointer
is null, and its tag is nil. Thus, the FFI variable cptr-null
will conveniently convert to any cptr type in the ffi_cptr_put
operation and others.
|
|
|
|
|
|
|
|
|
|
|
| |
* eval.c (eval_init): Register new intrinsics cptr-cast and
int-cptr.
* lib.c (cptr_cast, int_cptr): New functions.
* lib.h (cptr_cast, int_cptr): Declared.
* txr.1: Documented.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* eval.c (eval_init): Update registration of cptr-int and
cptr-obj with one optional argument.
* lib.c (cptr_int): New type symbol argument, defaulting
to nil. Also, don't bother defaulting the integer argument;
the function isn't registered for that being optional.
(cptr_obj): New type symbol argument, defaulting to nil.
* lib.h (cptr_int, cptr_obj): Declarations updated.
* txr.1: Documented cptr-int and cptr-obj function changes.
Added discussion of type tag to introductory paragraph.
Also added neglected documentation of the FFI cptr type,
both unparametrized and parametrized.
|
|
|
|
|
|
| |
* lib.c (toseq, reverse, nreverse): Classify the
sequence with seq_info, and simplify the code by
just dealing with the sequence kinds.
|
|
|
|
|
|
|
|
|
|
|
|
| |
This will help simplify writing generic sequence code, while
allowing lists and vectors to be handled specially.
* lib.h (enum seq_kind, seq_kind_t): New enum and typedef.
(struct seq_info, seq_info_t): New struct and typedef.
(seq_kind_tab, seq_info): Declared.
* lib.c (seq_kind_tab): New global array.
(seq_info): New function.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
With this change, nreverse is possible on a struct,
if it has lambda, lambda-set and length methods.
* lib.c (length_s): New symbol variable.
(length): Check for length method and call it,
in preference to checking for car method and falling
back on cdr-based length.
(empty): If object has a length method, call it and
compare result to zero.
(obj_init): Initialize length_s.
* txr.1: Documented. We now have the concepts of structs
being vector-like sequences or list-like sequences.
|
|
|
|
|
|
|
|
|
|
|
| |
* lib.c (ref, refset): Check for lambda and lambda-set,
respectively, and use it.
* txr.1: Documented.
* tests/012/aseq.tl (add lambda): Fix previously unused
broken method which now causes test to go into infinite
recursion.
|
|
|
|
|
|
|
|
| |
* lib.c (reverse): Support COBJ via list
operations, but handle carray via vector case.
(nreverse): Support COBJ via vector case.
This will work for carray. Fixes are needed in
ref and refset to work with structs.
|
|
|
|
|
|
|
|
|
|
|
|
| |
* ffi.c (copy_carray): New function
(ffi_init): Register copy-carray intrinsic.
* ffi.h (copy_carray): Declared.
* lib.c (copy): Call copy_array for carray objects.
* txr.1: Documented copy-carray and updated
copy description.
|
|
|
|
|
|
|
|
|
| |
* ffi.c (ffi_generic_sbit_put, fi_generic_sbit_get,
ffi_generic_ubit_put, fi_generic_ubit_get): Add needed
coerce from zalloca to mem_t *.
(make_ffi_type_struct): Fix signed/unsigned comparison.
* lib.c (vector): Fix signed/unsigned comparison.
|
|
|
|
|
|
|
|
|
| |
* lib.c (int_str): Support #\c base, recognizing
0x as hex and leading 0 as octal. We don't rely on
the wcstol function's ability to do this conversion,
but scan it ourselves.
* txr.1: Documented.
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* lib.c (vector): Bugfix: we are checking whether
length + 2 is negative, not length. Check the original
value, and simplify everything using check_mulloc.
(list_vec, sub_vec): Use chk_xalloc just in case. There
shouldn't be any overflow if the vector was constructed and
manipulated properly.
(replace_vec): Replace division-based oveflow check with
a simple test that total + 2 doesn't overflow; then
rely on chk_xalloc to do the multiplication overflow
check.
|
|
|
|
|
| |
* lib.c (chk_wmalloc): Drop the incorrect multiplication
overflow test, and just call chk_xalloc.
|
|
|
|
|
|
|
|
|
| |
This will simplify code that allocates an array-like
object whose size is the product of two numbers.
* lib.c (chk_xalloc): New function.
* lib.h (chk_xalloc): Declared.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Thanks to this (set [ca from..to] list) works.
* ffi.c (carray_replace): New function.
(ffi_init): Register carray-replace intrinsic.
* ffi.h (carray_replace): Declared.
* ffi.c (replace): Hook in carray_replace.
* txr.1: Mention carray under replace, and document
carray-replace.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Thus, [ca 3..5] syntax works for slice extraction.
However, this works referentially, not by making a copy.
The extracted subarray points to the original memory,
until carray-dup is invoked on it.
* ffi.c (carray_sub): New function.
(ffi_init): carray-sub intrinsic registered.
* ffi.h (carray_sub): Declared.
* lib.c (sub): Handle carray via carray_sub.
* txr.1: Documented changes in sub.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Thus (select ca '(0 3 4 ...)) works and so does the
sytnax [ca '(0 3 4 ...)]. This is inefficiently implemented.
The selected elements are extracted to a list which is then
converted to a carray of the same kind agan.
* ffi.c (carray_list): New function.
(ffi_init): Register carray-list intrinsic.
* ffi.h (carray_list): Declared.
* lib.c (make_like): Add carray case, so we can turn
a list into a carray based on an example carray.
This uses carray_list, with the type pulled from the
original carray. The target isn't null terminated.
(sel): Handle carray via vector case.
* txr.1: Document changes in select and make-like.
|
|
|
|
| |
* lib.c (generic_funcall, ref, refset): Handle BUF.
|
|
|
|
|
|
| |
* lib.c (length): Handle COBJ of carray type.
* txr.1: Documented.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The FFI module is more than just foreign calls and callbacks;
it provides a type system and operations for working with
binary data. None of it depends on libffi being present and so
shouldn't be disabled if libffi is not available.
* Makefile (ffi.o): Unconditionally link this object file,
not subject to the have_libffi variable.
* configure (have_libffi): Variable removed.
(gen_config_make): Do not generate a have_libffi
variable into config.make, since nothing needs it.
* ffi.c (ffi_type): Fake ffi_type defined if libffi is
missing.
(FFI_TYPE_STRUCT): Fake macro.
(ffi_type ffi_type_void, ffi_type_pointer, ffi_type_sint,
ffi_type ffi_type_schar, ffi_type_uchar, ffi_type
ffi_type_sshort, ffi_type_ushort, ffi_type ffi_type_sint,
ffi_type_uint, ffi_type ffi_type_slong, ffi_type_ulong,
ffi_type ffi_type_sint8, ffi_type_uint8, ffi_type
ffi_type_sint16, ffi_type_uint16, ffi_type ffi_type_sint32,
ffi_type_uint32, ffi_type ffi_type_sint64, ffi_type_uint64,
ffi_type ffi_type_float, ffi_type_double): Fake libffi type
objects, so that code which references these things will
build without modification.
(ffi_get_type): Function only defined if we have libffi.
(ffi_type_struct_destroy_op, ffi_struct_clone,
make_ffi_type_struct, ffi_array_clone, make_ffi_type_array):
Don't work with ffi_type's element array if we don't have
libffi; our fake ffi_type doesn't have such an array.
(struct txr_ffi_closure): Type only defined if we have libffi.
(ffi_closure_struct, ffi_closure_struct_checked,
ffi_closure_print_op, ffi_closure_destroy_op,
ffi_closure_mark_op, ffi_closure_put): Functions only defined
if we have libffi.
(ffi_closure_ops): Static structure only defined if we have
libffi.
(ffi_init_types): Don't register a closure type if we don't
have libffi.
(struct txr_ffi_call_desc): Don't define type if we don't have
libffi.
(ffi_call_desc, ffi_call_desc_checked, ffi_call_desc_print_op,
ffi_call_desc_destroy_op, ffi_call_desc_mark_op,
ffi_make_call_desc, ffi_call_wrap, ffi_closure_dispatch,
ffi_closure_dispatch_safe, ffi_make_closure,
ffi_closure_get_fptr): Functions only defined if we have
libffi.
(ffi_call_desc_ops): Static structure only defined if we have
libffi.
(ffi_init): Only register ffi-make-call-desc, ffi-call, and
ffi-make-closure if we have libffi.
* lib.c: Include "ffi.h" header unconditionally.
(generic_funcall, ref, refset, int): Remove #if HAVE_LIBFFI.
|
|
|
|
|
|
|
|
|
| |
* lib.c (generic_funcall): Handle carray object via
the same cas that handles vectors, lists and strings.
That in turn works via ref and other lower-level
functions (not all of which support carray yet).
(ref): Handle carray object via carray_ref.
(refset): Handle carray_object via carray_refset.
|
|
|
|
|
|
|
| |
* lib.c (string_8bit_size): This function must allocate an
extra wchar_t and null-terminate. That is the semantics
expected by ffi_bchar_array_get which uses it, and of
course string_own requires a null-terminated string.
|