summaryrefslogtreecommitdiffstats
path: root/lib.c
Commit message (Collapse)AuthorAgeFilesLines
* find_max: convert to use seq_info.Kaz Kylheku2017-10-131-20/+17
| | | | | | | * 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.
* rfind: rewrite to be like find.Kaz Kylheku2017-10-131-11/+48
| | | | | | * 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.
* find: convert to seq_info classification.Kaz Kylheku2017-10-131-44/+36
| | | | | | | * 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.
* Fixes in partition, partition*, split and split*.Kaz Kylheku2017-09-291-42/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* bugfix: fixnum crackdown.Kaz Kylheku2017-09-131-21/+39
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* bugfix: replace_str uses string_extend incorrectly.Kaz Kylheku2017-08-241-1/+1
| | | | | | | | | | | | | | | | | | | | 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.
* Revising out-of-memory handling.Kaz Kylheku2017-08-181-13/+14
| | | | | | | | | | | | | | | | | | | | | 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.
* vec-set-length maintenance.Kaz Kylheku2017-08-171-4/+13
| | | | | | | * 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.
* Rewriting string-extend.Kaz Kylheku2017-08-171-26/+25
| | | | | | | | | | * 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.
* New spl and tok: variants of tok-str and split-str.Kaz Kylheku2017-08-071-0/+14
| | | | | | | | * eval.c (eval_init): Register spl and tok intrinsics. * lib.c (spl, tok): New functions. * txr.1: Documented.
* bugfix: n-ary arith functions must check single arg.Kaz Kylheku2017-08-051-8/+57
| | | | | | | | | | | | | | | | 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.
* Add sum and prod convenience functions.Kaz Kylheku2017-08-051-0/+12
| | | | | | | | | | * eval.c (eval_init): prod and sum intrinsics registered. * lib.c (sum, prod): New functions. * lib.h (sum, prod): Declared. * txr.1: Documented.
* lib: deprecate set-diff; extend set operations.Kaz Kylheku2017-07-261-0/+59
| | | | | | | | | | | | | | * 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.
* find, pos: optimize and support objects properly.Kaz Kylheku2017-07-181-21/+114
| | | | | | | | | | | * 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.
* new function: nthKaz Kylheku2017-07-181-0/+5
| | | | | | | | | | | | | | | | 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.
* lib: new function, relate.Kaz Kylheku2017-07-171-0/+25
| | | | | | | | | | | * 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.
* ffi: relaxation in cptr put semantics.Kaz Kylheku2017-07-021-5/+10
| | | | | | | | | | | | 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.
* New cptr functions cptr-cast and int-cptr.Kaz Kylheku2017-06-261-0/+11
| | | | | | | | | | | * 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.
* cptr-int and cptr-obj can make typed cptr objects.Kaz Kylheku2017-06-191-4/+6
| | | | | | | | | | | | | | | | | * 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.
* simplify toseq, reverse and nerverse.Kaz Kylheku2017-06-161-39/+28
| | | | | | * lib.c (toseq, reverse, nreverse): Classify the sequence with seq_info, and simplify the code by just dealing with the sequence kinds.
* New sequence classification system.Kaz Kylheku2017-06-161-0/+60
| | | | | | | | | | | | 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.
* New length method on structures.Kaz Kylheku2017-06-161-4/+17
| | | | | | | | | | | | | | | | 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.
* Support ref, refset on structs via lambda, lambda-set.Kaz Kylheku2017-06-161-0/+11
| | | | | | | | | | | * 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.
* reverse, nreverse: do generalized sequences and carray.Kaz Kylheku2017-06-151-2/+10
| | | | | | | | * 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: copy-carray, hooked into copy.Kaz Kylheku2017-06-151-0/+2
| | | | | | | | | | | | * 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.
* Follow up on C++ diagnostics.Kaz Kylheku2017-06-121-1/+1
| | | | | | | | | * 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.
* int-str: allow radix to be #\c for C conventions.Kaz Kylheku2017-06-121-18/+42
| | | | | | | | | * 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: revamp overflow checks in vec operations.Kaz Kylheku2017-06-121-16/+11
| | | | | | | | | | | | | * 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: reimplement chk_wmalloc using chk_xalloc.Kaz Kylheku2017-06-121-4/+2
| | | | | * lib.c (chk_wmalloc): Drop the incorrect multiplication overflow test, and just call chk_xalloc.
* lib: new chk_xalloc, with mult overflow check.Kaz Kylheku2017-06-121-0/+12
| | | | | | | | | 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.
* ffi: new carray-replace function.Kaz Kylheku2017-06-111-0/+4
| | | | | | | | | | | | | | 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.
* ffi: handle sub operation in carray.Kaz Kylheku2017-06-111-0/+2
| | | | | | | | | | | | | | | | 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.
* ffi: support sel operation on carray.Kaz Kylheku2017-06-111-0/+5
| | | | | | | | | | | | | | | | | | | | 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.
* buf: support ref, refset and indexing.Kaz Kylheku2017-06-111-0/+5
| | | | * lib.c (generic_funcall, ref, refset): Handle BUF.
* length function supports carray.Kaz Kylheku2017-06-111-0/+2
| | | | | | * lib.c (length): Handle COBJ of carray type. * txr.1: Documented.
* ffi: retain some functionality if libffi missing.Kaz Kylheku2017-06-101-10/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* ffi: support ref, refset and indexing on carray.Kaz Kylheku2017-06-091-0/+13
| | | | | | | | | * 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.
* ffi: fix broken bchar array get.Kaz Kylheku2017-06-051-1/+2
| | | | | | | * 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.
* mkstring char argument is optional.Kaz Kylheku2017-06-011-1/+2
| | | | | | | | | * eval.c (eval_init): Update registration of mkstring intrinsic to make second argument optional. * lib.c (mkstring): Default second argument to space. * txr.1: Documentation of mkstring updated.
* Splitting cptr object into separate CPTR tag.Kaz Kylheku2017-05-151-7/+54
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | CPTR shares representation and a lot of implementation with COBJ. The COBJ class symbol is the CPTR type tag. There is no hierarchy among CPTR tags. The nil tag is used for a modicum of type looseness, so that we don't straitjacket ourselves too much into this tag-based typing scheme. All existing cptr objects are becoming CPTR, and all get a nil tag, except for dlopen library handles, and dlsym symbols, which are tagged as dlhandle and dlsym. The FFI framework will support tag-declared cptr's. This will help with safety. For instance, suppose an API has half a dozen different kinds of opaque handles. If they are all just cptr on the TXR Lisp side, it's easy to mix them up, passing the wrong one to the wrong C function. * lib.h (enum type): New enum member, CPTR. (cptr_print_op, cptr_typed, cptrp, cptr_type, cptr_handle): Declared. (cptr_addr_of): Parameters added. * lib.c (code2type): Map CPTR type code to cptr_s. (equal): Handle CPTR objects. They are only equal to other CPTR objects which have the same operations, and are equal under the equal function of those operations. (cptr_print_op): New function. (cptr_ops): Use cptr_print_op rather than cobj_print_op. (cptr_typed): New function. (cptr): Use cptr_typed to make a cptr with tag nil, rather than using cobj. (cptrp, cptr_handle, cptr_type): New functions. (cptr_get): Go through cptr_handle rather than cobj_handle. (cptr_addr_of, cptr_zap, cptr_free): Use call to cptr_handle rather than cobj_handle for the type checking side effect. New parameters for type and parent function name. (obj_print_impl): Handle CPTR with same case as COBJ. * gc.c (finalize, mark_obj): Handle CPTR cases using common code with COBJ. * hash.c (equal_hash): Handle CPTR just like COBJ. * eval.c (eval_init): Register cptrp and cptr-type intrinsic functions. * ffi.c (ffi_cptr_put, ffi_cptr_get, ffi_cptr_alloc): Use the potentially type-safe cptr_handle, instead of cptr_get. However, for an untagged cptr, there is no type safety because tft->mtypes is nil. The argument can be any kind of cptr. * sysif.c (dlhandle_s, dlsym_s): New symbol variables. (cptr_dl_ops): Use cptr_print_op. (dlopen_wrap, dlclose_wrap): Use typed cptr with dlhandle as the type. (dlsym_wrap, dlsym_checked, dlvsym_wrap, dlvsym_checked): Recognize only a cptr of type dlhandle for the library. Construct a typed cptr of type dlsym. (sysif_init): Initialize dlhandle_s and dlsym_s. Register dlsym function using dlsym_s.
* less table robust against type renumbering.Kaz Kylheku2017-05-151-19/+14
| | | | | | | | | | * lib.c (less_tab_init): The type_prec table initialization will become incorrect if new type enums are added other than at the end. Let's switch to assignments. Anything not mentioned is zero. * lib.h: Add more advice to comment about extending type_t: consider all places where MAX_TYPE is used.
* bugfix: use proper hashing for cptr.Kaz Kylheku2017-05-151-1/+7
| | | | | | | | | | | | | | | Since cptr objects are equal if their handles are equal, they must have a hashing function over the handle rather than over their own address. * lib.c (cobj_handle_hash_op): New function. (cptr_ops): Use cobj_handle_hash_op instead of cobj_eq_hash_op. * lib.h (cobj_handle_hash_op): Declared. * sysif.c (cptr_dl_ops): Use cobj_handle_hash_op instead of cobj_eq_hash_op.
* cobj: rename poorly named default operation.Kaz Kylheku2017-05-151-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Renaming cobj_hash_op to cobj_eq_hash_op. This function is only appropriate to use with COBJ objects which use eq as their equal funtion. I've spotted one instance of an inappropriate use which have to be addressed by a different commit: the equal function is other than eq, but cobj_hash_op is used for the equal hash. * lib.h (cobj_hash_op): Declaration renamed to cobj_eq_hash_op. * hash.c (cobj_hash_op): Renamed to cobj_eq_hash_op. (hash_iter_ops): Refer to renamed cobj_hash_eq_op. * ffi.c (ffi_type_builtin_ops, ffi_type_struct_ops, ffi_type_ptr_ops, ffi-closure_ops, ffi_call_desc_ops): Likewise. * lib.c (cptr_ops): Likewise. * parser.c (parser_ops): Likewise. * rand.c (random_state_ops): Likewise. * regex.c (char_set_ops, regex_obj_ops): Likewise. * socket.c (dgram_strm_ops): Likewise. * stream.c (null_ops, stdio_ops, tail_ops, pipe_ops, dir_ops, string_in_ops, byte_in_ops, strlist_in_ops, string_out_ops, strlist_out_ops, cat_stream_ops, record_adapter_ops): Likewise. * struct.c (struct_type_ops): Likewise. * sysif.c (cptr_dl_ops): Likewise. * syslog.c (syslog_strm_ops): Likewise. * unwind.c (cont_ops): Likewise.
* cptr: new functions.Kaz Kylheku2017-05-091-0/+25
| | | | | | | | | | * 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.
* 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.
* length: support buffer objects.Kaz Kylheku2017-05-041-0/+2
| | | | * lib.c (length): Handle BUF case via length_buf.
* 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: map (array n bchar) to Lisp string.Kaz Kylheku2017-05-041-0/+9
| | | | | | | | | | * 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.
* ffi: new bstr type.Kaz Kylheku2017-05-041-0/+24
| | | | | | | | | | | | | | | | | | 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.
* bugfix: tostringp not behaving right for floats.Kaz Kylheku2017-05-041-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | 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.