summaryrefslogtreecommitdiffstats
path: root/stream.c
Commit message (Collapse)AuthorAgeFilesLines
* Better identify functions that misuse COBJ-s and hashes.Kaz Kylheku2018-11-071-53/+112
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In this patch, the cobj_handle, cobj_ops and variants of gethash get an additional argument to identify the caller. Many functions are updated to pass this down. * buf.c (buf_strm): Pass self name to cobj_handle. * eval.c (env_fbind, env_vbind, rt_defvarl, me_case): Pass self name to gethash_c or gethash_e. (load): Pass self name to read_eval_stream and read_compiled_file. (reg_symacro): Pass situation-identifying string to gethash_c. * ffi.c (ffi_type_struct_checked, ffi_closure_struct_checked, ffi_call_desc_checked, uni_struct_checked): Take self name parameter, and pass down to cobj_handle. (ffi_get_type, ffi_get_lisp_type): Take self name and pass down to ffi_type_struct_checked. (union_get_ptr): Take self name and pass to uni_struct_checked. (ffi_union_in, ffi_union_put): Pass self name to union_get_ptr. (ffi_type_compile): Pass self name to ffi_get_lisp_type. (ffi_make_call_desc): Pass self name to ffi_type_struct_checked, ffi_get_type and ffi_call_desc_checked. (ffi_make_closure): Pass self name to ffi_call_desc_checked. (ffi_closure_get_fptr): Take self name, pass to ffi_closure_struct_checked. (ffi_typedef, ffi_size, ffi_alignof, ffi_offsetof, ffi_arraysize, ffi_elemsize, ffi_elemtype, ffi_put_into, ffi_put, ffi_in, ffi_get, ffi_out, make_carray): Pass self name to ffi_closure_struct_checked. (carray_struct_checked): Take self name, pass to cobj_handle. (carray_set_length, carray_dup, carray_own, carray_free, carray_type, length_carray, copy_carray, carray_ptr, buf_carray, vec_carray, list_carray, carray_ref, carray_refset, carray_sub, carray_replace, carray_get_common, carray_put_common, unum_carray, num_carray, put_carray, fill_carray): Pass self name to carray_struct_checked. (carray_blank, carray_buf, carray_cptr): Pass self name ffi_type_struct_checked. (carray_pun): Pass self name to carray_struct_checked and ffi_type_struct_checked. (make_union): Pass self name to ffi_type_struct_checked. (union_members, union_get, union_put, union_in, union_out): Pass self name to uni_struct_checked. (make_zstruct, zero_fill, put_obj, get_obj, fill_obj): Pass self-name to ffi_type_struct_checked. * ffi.h (ffi_closure_get_fptr, union_get_ptr): Declarations updated. * filter.c (trie_add): Pass self-name to gethash_l. * hash.c (make_similar_hash, copy_hash, hash_count, get_hash_userdata, set_hash_userdata, hash_begin, hash_next, hash_uni, hash_diff, hash_isec): Pass self name to cobj_handle. (gethash_c, gethash_e): Take self name parameter and pass down to cobj_handle. (gethash_f): Take self parameter and pass down to gethash_e. (gethash, inhash, gethash_n, sethash, pushhash, remhash, clearhash, hash_update_1): Pass self name to gethash_e or gethash_c. * hash.h (gethash_c, gethash_e, gethash_f): Declarations updated. (gethash_l): Take self name, and pass down to gethash_c. * lib.c (class_check): Take self name parameter and use in type mismatch diagnostic. (use_sym, unuse_sym, symbol_needs_prefix, find_symbol, intern, unintern, intern_fallback, unique, in, sel, obj_print_impl, populate_obj_hash, obj_hash_merge): Pass self name to gethash_f or gethash_l. (symbol_visible, obj_init): Pass situation-identifying string to gethash_e. (cobj_handle, cobj_ops): Take self name parameter and pass down to class_check. * lib.h (class_check, cobj_handle, cobj_ops): Declarations updated. * match.c (v_load): Pass self name to read_compiled_file and read_eval_stream. * parser.c (get_parser_impl): Take self name and pass to cobj_handle. (ensure_parser): Pass situation-identifying string to gethash_c. (parser_circ_def): Pass self-name to gethash_c. (lisp_parser_impl): Pass self name to get_parser_impl and class_check. (lisp_parse, nread, iread): Pass self-name to lisp_parser_impl. (read_file_common): Take self name parameter and pass down to get_parser_impl. (read_eval_stream, read_compiled_file): Take self name and pass down to read_file_common. (load_rcfile): Pass situation-identifying string to read_eval_streem. (get_visible_syms): Pass situation-identifying string to gethash_c. (parser_errors, parser_eof): Pass self name to cobj_handle. * parser.h (read_eval_stream, read_compiled_file): Declarations updated. * parser.y (rlset): Pass self name to gethash_c. * rand.c (make_random_state, random_state_get_vec,l random_fixnum, random_float): Pass self name to cobj_handle. * regex.c (regex_source, regex_print, regex_run): Pass self-name to cobj_handle. (regex_machine_init): Take self name param and pass to cobj_handle. (search_regex, match_regex, match_regex_right, regex_prefix_match, read_until_match): Pass self-name to regex_machine_init. * stream.c (stdio_get_fd): Pass self name to cobj_handle. (generic_get_line): Get COBJ operations via unsafe, diret object access rather than cobj_ops. (set_mode_props): Get object handle via unsafe, direct object access. (stream_fd, sock_family, sock_type, sock_peer, set_sock_peer, get_string_from_stream, get_list_from_stream, stream_set_prop, stream_get_prop, close_stream, get_error, get_error_str, clear_error, get_line, get_char, get_byte, unget_char, unget_byte, put_buf, fill_buf, put_string, put_char, put_byte, flush_stream, seek_stream, truncate_stream, get_indent_mode, test_set_indent_mode, set_indent_mode, get_indent, set_indent, inc_indent, width_check, force_break, get_set_ctx, get_ctx): Pass self name to cobj_ops. (make_delegate_stream): Take self name parameter, pass down to cobj_ops. (record_adapter): Pass self name down to make_delegate_stream. (format): Pass self name to class_check. * struct.c (stype_handle): Pass self name to cobj_handle. (make_struct_type): Pass self name to class_check. * txr.c (read_eval_stream_noerr): Take self name parameter, pass to read_eval_stream. (txr_main): Pass istuation-identifying string to read_compiled_file and read_eval_stream_noerr. * unwind.c (revive_cont): Pass self-name to cobj_handle. * vm.c (vm_desc_struct): Take self name parameter, pass to cobj_handle. (vm_desc_nlevels, vm_desc_nregs, vm_desc_bytecode, vm_desc_datavec, vm_desc_symvec, vm_execute_toplevel, vm_execute_closure, vm_closure_entry): Pass self name to vm_desc_struct. (vm_closure_struct): Take self name parameter, pass to cobj_handle.
* Fix wrong uses of ~s for function name string.Kaz Kylheku2018-11-071-3/+3
| | | | | | | | | | | | * ffi.c (make_ffi_type_enum): Use ~a for function name rather than ~s because it's a string which is quoted under ~s. * lib.c (chk_xalloc, string_extend, find_symbol, intern_fallback): Likewise. * stream.c (open_process, run): Likewise. * sysif.c (exec_wrap, setgroups_wrap, dlclose_wrap): Likewise.
* math: improve error diagnosis.Kaz Kylheku2018-11-071-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | More streamlined code, better identification of functions. * arith.c (not_number, not_integer, invalid_ops, invalid_op, divzero): New static functions. (num_to_buffer, bugnum_len, plus, minus, neg, abso, signum, mul, trunc1, mod, floordiv, round1, roundiv, divi, zerop, plusp, minusp, evenp, oddp, gt, lt, ge, le, numeq, expt, exptmod, floorf, ceili, sine, cosi, tang, asine, acosi, atang, loga, logten, logtwo, expo, sqroot, int_flo, flo_int, cum_norm_dist, inv_cum_norm): Establish function's Lisp name as self variable. Use new static functions for reporting common errors. Pass function name to new argument of c_flo function. * buf.c (buf_put_float, buf_put_double): Pass function's Lisp name to c_flo function. * ffi.c (ffi_float_put, ffi_double_put): Likewise. * lib.c (c_flo): Takes new argument, name of calling function. * lib.h (c_flo): Declaration updated. * stream.c (formatv): Pass function name to c_flo.
* repl: bugfix: slow paste into terminal window.Kaz Kylheku2018-11-011-1/+3
| | | | | | | | | | * stream.c (stream_init): When stdin is a TTY, we make it unbuffered. This affects the parenthesis matching and incomplete line warning flash in the listener, in the following way. The listener uses the poll function to execute delays which is canceled by the presence of TTY input. This logic breaks when data is pasted into the terminal, because the stdin stream buffers the input.
* printer: improve object formatting.Kaz Kylheku2018-04-051-3/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There is an issue with the printer in that it produces output whereby objects continue on the same line after a multi-line object, e.g: (foo (foobly bar xyzzy quux) (oops same line)) rather than: (foo (foobly bar xyzzy quux) (oops same line)) There is a simple fix for this: set a flag to force a line break on the next width-check operation whenever an object has been broken into multiple lines. width-check can return a Boolean indication whether it generated a line break, and so aggregate object printing routines can tell whether their object has been broken into lines, and set the flag. * stream.h (struct strm_base): New member, force_break. (force_break): Declared. * stream.c (strm_base_init): Extent initializer to cover force_break flag. (put_string, put_char): Clear the force_break flag whenever we hit column zero. (width_check): If indent mode is on, and force_break is true, generate a break. Clear force_break. (force_break): New function. (stream_init): Register force-break intrinsic. * buf.c (buf_print): Set the force break flag if the buffer was broken into multiple lines. * hash.c (hash_print_op): Set the force break flag if the hash was broken into multiple lines. * lib.c (obj_print_impl): Same logic for lists. * struct.c (struct_inst_print): Same logic for structs. * tests/009/json.expected, tests/011/macros-2.expected, tests/012/struct.tl, tests/017/glob-zarray.expected: Update expected textual output to reflect new formatting.
* string output streams: null pointer deref.Kaz Kylheku2018-03-301-4/+10
| | | | | | | | | | | | | | | Originally, string output streams would null out their handle when the string was extracted. This changed in commit e44c113ee17c7cf15e8b1891f4d51ec03b16bc24 [Jul 2015], so that just the string buffer was nulled out. Unfortunately, two places in the code were not updated, still checking for a null handle, which is always false, and not defending against the null handle. * stream.c (string_out_extracted_error): New static function. (string_out_put_string, string_out_put_byte): Check the buffer for null, not the handle, which doesn't go null while the object is live. Throw an exception rather than returning nil.
* Copyright year bump 2018.Kaz Kylheku2018-02-151-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * LICENSE, LICENSE-CYG, METALICENSE, Makefile, args.c, args.h, arith.c, arith.h, buf.c, buf.h, cadr.c, cadr.h, combi.c, combi.h, configure, debug.c, debug.h, eval.c, eval.h, ffi.c, ffi.h, filter.c, filter.h, ftw.c, ftw.h, gc.c, gc.h, glob.c, glob.h, hash.c, hash.h, itypes.c, itypes.h, jmp.S, lib.c, lib.h, lisplib.c, lisplib.h, match.c, match.h, parser.c, parser.h, parser.l, parser.y, protsym.c, rand.c, rand.h, regex.c, regex.h, share/txr/stdlib/awk.tl, share/txr/stdlib/build.tl, share/txr/stdlib/cadr.tl, share/txr/stdlib/conv.tl, share/txr/stdlib/doloop.tl, share/txr/stdlib/error.tl, share/txr/stdlib/except.tl, share/txr/stdlib/ffi.tl, share/txr/stdlib/getopts.tl, share/txr/stdlib/getput.tl, share/txr/stdlib/hash.tl, share/txr/stdlib/ifa.tl, share/txr/stdlib/keyparams.tl, share/txr/stdlib/op.tl, share/txr/stdlib/package.tl, share/txr/stdlib/path-test.tl, share/txr/stdlib/place.tl, share/txr/stdlib/pmac.tl, share/txr/stdlib/socket.tl, share/txr/stdlib/stream-wrap.tl, share/txr/stdlib/struct.tl, share/txr/stdlib/tagbody.tl, share/txr/stdlib/termios.tl, share/txr/stdlib/txr-case.tl, share/txr/stdlib/type.tl, share/txr/stdlib/with-resources.tl, share/txr/stdlib/with-stream.tl, share/txr/stdlib/yield.tl, signal.c, signal.h, socket.c, socket.h, stream.c, stream.h, struct.c, struct.h, strudel.c, strudel.h, sysif.c, sysif.h, syslog.c, syslog.h, termios.c, termios.h, txr.1, txr.c, txr.h, unwind.c, unwind.h, utf8.c, utf8.h, win/cleansvg.txr: Extended Copyright line to 2018.
* New feature: structure delegate streams.Kaz Kylheku2017-12-081-13/+39
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A new kind of stream object which redirects its operations to the methods of a structure. * Makefile (OBJS): New object file, strudel.o. * lib.c (init): Call new strudel_init function. * lisplib.c (stream_wrap_set_entries, stream_wrap_instantiate): New static functions. (lisplib_init): Arrange for autloading of new stream-wrap.tl. * share/txr/stdlib/stream-wrap.tl: New file. * stream.c (put_string_s, put_char_s, put_byte_s, get_line_s, get_char_s, get_byte_s, unget_char_s, unget_byte_s, put_buf_s, fill_buf_s, flush_s, seek_s, truncate_s, get_prop_s, set_prop_s, get_error_s, get_error_str_s, clear_error_s, get_fd_s): New symbol variables. (stream_init): New symbol variables initialized. Numerous functions registered via these variables now rather than intern(...) expressions. * stream.h (put_string_s, put_char_s, put_byte_s, get_line_s, get_char_s, get_byte_s, unget_char_s, unget_byte_s, put_buf_s, fill_buf_s, flush_s, seek_s, truncate_s, get_prop_s, set_prop_s, get_error_s, get_error_str_s, clear_error_s, get_fd_s): Declared. * strudel.c, strudel.h: New files.
* streams: allow "b" flag on open-command.Kaz Kylheku2017-10-301-1/+17
| | | | | | | | | | | | | | | | | | | Currently, using "rb" in open-command reports an error on GNU/Linux, due to popen not liking the "b" mode. On Cygwin, the "b" flag is useful with popen. * stream.c (normalize_mode_no_bin): New function. (open_command): Use normalize_mode_no_bin instead of normalize_mode to strip out the binary flag. This doesn't happen on Cygwin, though. * stream.h (normalize_mode_no_bin): Declared. * share/txr/stdlib/getput.tl (command-get-buf): Since we are getting binary data, pass the "rb" mode to open-command, now that it works. (command-put-buf): Add "b" flag to mode passed to open-command.
* Default the length argument of truncate-stream.Kaz Kylheku2017-08-211-1/+3
| | | | | | | | | | * stream.c (truncate_stream): If the len argument is missing, default to the current position, obtained by using the seek operation. (stream_init): Fix up registration of truncate-stream for one optional argument. * txr.1: Documentation of truncate-stream updated.
* new function: path-catKaz Kylheku2017-07-181-0/+40
| | | | | | | | | * stream.c (path_cat): New function. (stream_init): Registered path_cat. * stream.h (path_cat): Declared. * txr.1: Documented.
* remove-path: exception semantics adjusted.Kaz Kylheku2017-07-171-1/+1
| | | | | | | | | | | | * stream.c (remove_path): The second argument now defaults to false rather than true, and controls only whether an exception is thrown in the non-existence case. Thus, the function throws errors by default, as before, but doesn't throw by default if the failure reason is that the path doesn't exist. Previously it threw by default in all situations, and the flag turned all errors into a nil return. * txr.1: Documented.
* format: support leading zero printing for floats.Kaz Kylheku2017-07-161-2/+2
| | | | | | | | | | | | | | | For a floating-point argument, the following behavior is supported by the ~a, ~s and ~f format directives: if the precision has a leading zero, then leading zeros are added, up to one less than the field width. * stream.c (formatv): Set the precision to one less than the field width when rendering floats, rather than to zero. The output_num code takes the precision as the cue for padding zeros. * txr.1: Updated format documentation, and clarified a few things also.
* streams: add overflow checks.Kaz Kylheku2017-06-121-4/+17
| | | | | | | | | * stream.c (open_process): Check that manipulations of nargs do not overflow int type. Use chk_xalloc. Allocation is done before pipe so we have no file descriptors to clean up if chk_xalloc throws. (run): In both versions of run, check that manipulations of nargs don't overflow int and use chk_xalloc.
* c++ maintenance: eliminate old-style casts.Kaz Kylheku2017-06-061-2/+2
| | | | | | | | | | | | | | | | | | | | Old style casts have crept into the code base. * buf.c (make_buf, buf_grow, buf_get_i8, buf_get_u8): Replace old style cast with macro. * ffi.c (align_sw_get, align_sw_put, ffi_be_i32_get, ffi_be_u32_get, ffi_le_i32_put, ffi_le_i32_get, ffi_le_u32_get, ffi_be_i64_put, ffi_be_i64_get, ffi_be_u64_get, ffi_le_i64_put, ffi_le_i64_get, ffi_le_u64_get, ffi_sbit_put, ffi_sbit_get, ffi_init_extra_types): Likewise. * hash.c (hash_buf): Likewise. * itypes.c (c_i32, c_i64, c_u64): Likewise. * stream.c (stdio_put_buf, stdio_fill_buf): Likewise.
* c++ maintenance: signed/unsigned comparisons.Kaz Kylheku2017-06-061-4/+4
| | | | | | | | * ffi.c (ffi_sbit_put, make_ffi_type_struct): Fix signed/unsigned comparison warning from g++. (pad_retval): Likewise. * stream.c (stdio_put_buf, stdio_fill_buf): Likewise.
* buffers: improve put-buf and fill-buf.Kaz Kylheku2017-06-051-27/+48
| | | | | | | | | | | | | | | | | | | | * stream.h (struct strm_ops): put_buf and fill_buf function pointers get third argument to indicate starting position of read and write. (put_buf, fill_buf): Declarations updated. * stream.c (unimpl_put_buf, unimpl_fill_buf): Third argument added. (generic_put_buf, generic_fill_buf, stdio_put_buf, stdio_fill_buf): Implement position argument. (delegate_put_buf, delegate_fill_buf): Take third argument, pass it down. (put_buf, fill_buf): New position argument in second position. Defaulted to zero. Passed down. (stream_init): Updated registration of put-buf and fill-buf. * txr.1: Updated documentation.
* streams: put-buf and fill-buf functions.Kaz Kylheku2017-06-041-7/+120
| | | | | | | | | | | | | | | | | | | | | | | | | | | | * stream.h (struct strm_ops): New function pointer members, put_buf and fill_buf. (strm_ops_init): Two new parameters in macro. (put_buf, fill_buf): Declared. * stream.c (unimpl_put_buf, unimpl_fill_buf, generic_put_buf, generic_fill_buf): New static functions. (fill_stream_ops): Default new fill_buf and fill_buf virtual functions intelligently based on whether get_byte and put_byte are available. (stdio_put_buf, stdio_fill_buf): New static functions. (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): Add arguments to strm_ops_init macro for get_buf and fill_buf. (delegate_put_buf, delegate_fill_buf): New static functions. (record_adapter_ops): Add arguments to strm_ops_init macro for get_buf and fill_buf. (put_buf, fill_buf): New functions. (stream_init): Register put-buf and fill-buf intrinsics. * socket.c (dgram_strm_ops): Add arguments to strm_ops_init macro call. * syslog.c (syslog_strm_ops): Likewise.
* Adding base-name and dir-name functions.Kaz Kylheku2017-05-211-1/+82
| | | | | | | | | | | | | | | * 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.
* doc: emphasize platform-independence of abs-path-p.Kaz Kylheku2017-05-211-0/+3
| | | | | | * txr.1: Adding text to abs-path-p description which emphasizes that the definition of absolute path it uses is platform-agnostic.
* cobj: rename poorly named default operation.Kaz Kylheku2017-05-151-12/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* bugfix: gc-incorrect creation of catenated stream.Kaz Kylheku2017-05-131-1/+4
| | | | | | | | | | | | * stream.c (make_catenated_stream): Fix incorrect order of operations: list of streams stored into a structure that is not yet visible to the garbage collector. (Rules for coding this properly are explained in HACKING.) This was found by running a test with --gc-debug on 64 bit Darwin. The read_eval_stream function calls make_catenated_stream with an argument that is freshly constructed in the argument expression itself, triggering the issue.
* bugfix: tostringp not behaving right for floats.Kaz Kylheku2017-05-041-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Rename badly named default_bool_argKaz Kylheku2017-03-171-9/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * lib.h (default_bool_arg): Inline function renamed to default_null_arg. * eval.c (if_fun, pad, ginterate, giterate, range_star, range, constantp, macroexpand_1, macro_form_p, expand_with_free_refs, do_expand, eval_intrinsic, func_get_name, make_env_intrinsic): Follow rename. * arith.c (lognot): Likewise. * gc.c (gc_finalize): Likewise. * glob.c (glob_wrap): Likewise. * hash.c (group_reduce, gethash_n): Likewise. * lib.c (print, multi_sort, lazy_str, vector, iff, tok_str, split_str_keep, search_str, remove_if, val): Likewise. * match.c (match_fun): Likewise. * parser.c (lisp_parse_impl, regex_parse): Likewise. * rand.c (make_random_state): Likewise. * regex.c (read_until_match, search_regex, regex_compile): Likewise. * socket.c (sock_accept, sock_connect): Likewise. * stream.c (open_files_star, open_files, run, open_process, open_tail, get_string, record_adapter): Likewise. * struct.c (static_slot_ensure, static_slot_ens_rec, clear_struct, make_struct_type): Likewise. * sysif.c (exec_wrap, errno_wrap, cobj_ops_init): Likewise. * unwind.c (uw_capture_cont, uw_find_frames_impl): Likewise.
* Bump copyright year to 2017.Kaz Kylheku2017-01-231-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | * LICENSE, LICENSE-CYG, METALICENSE, Makefile, args.c, args.h, arith.c, arith.h, cadr.c, cadr.h, combi.c, combi.h, configure, debug.c, debug.h, eval.c, eval.h, filter.c, filter.h, ftw.c, ftw.h, gc.c, gc.h, glob.c, glob.h, hash.c, hash.h, jmp.S, lib.c, lib.h, lisplib.c, lisplib.h, match.c, match.h, parser.c, parser.h, parser.l, parser.y, rand.c, rand.h, regex.c, regex.h, signal.c, signal.h, stream.c, stream.h, struct.c, struct.h, sysif.c, sysif.h, syslog.c, syslog.h, termios.c, termios.h, txr.1, txr.c, txr.h, unwind.c, unwind.h, utf8.c, utf8.h, share/txr/stdlib/awk.tl, share/txr/stdlib/build.tl, share/txr/stdlib/cadr.tl, share/txr/stdlib/conv.tl, share/txr/stdlib/except.tl, share/txr/stdlib/getopts.tl, share/txr/stdlib/getput.tl, share/txr/stdlib/hash.tl, share/txr/stdlib/ifa.tl, share/txr/stdlib/package.tl, share/txr/stdlib/path-test.tl, share/txr/stdlib/place.tl, share/txr/stdlib/socket.tl, share/txr/stdlib/struct.tl, share/txr/stdlib/tagbody.tl, share/txr/stdlib/termios.tl, share/txr/stdlib/txr-case.tl, share/txr/stdlib/type.tl, share/txr/stdlib/with-resources.tl, share/txr/stdlib/with-stream.tl, share/txr/stdlib/yield.tl: Add 2017 to all copyright headers and strings.
* Changes to the printing framework.Kaz Kylheku2016-10-201-4/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The print function now takes an optional boolean for pretty printing. The print method is also called with a third argument; hence structures can customize both standard printing and pretty printing. * lib.c (obj_print): Take pretty argument, and pass it down to obj_print_impl. This makes obj_pprint redundant. (obj_pprint): Function removed: it was identical to obj_print except for passing t down to obj_print_impl for the pretty argument. These two wrappers had started small and got bigger with identical changes done in parallel. (pprint): New function. (tostring, dump): Pass nil for pretty argument of obj_print. (tostringp): Use pprint instead of obj_pprint. * lib.h (obj_print): Declaration updated. (obj_pprint): Declaration removed. (print, pprint): Declared. * eval.c (prinl): Pass nil for pretty_p argument of obj_print. Do the stream defaulting here; obj_print doesn't do it. (pprinl): Pass t for pretty_p argument of obj_print, and do stream argument defaulting. (eval_init): Register print to new print function rather than directly to obj_print. Register pprint to new pprint function rather than obj_pprint. * hash.c (hash_print_op): Call obj_print_impl to print the :equal-based keyword, rather than obj_print. Pass down the pretty flag. All the other keywords are treated this way; this fixes an inconsistency. * match.c (dump_var): Call pprint instead of obj_pprint. * stream.c (formatv): Call obj_print, with a calculated pretty argument instead of switching between obj_pprint and obj_print. * struct.c (struct_inst_print): Except when in backward compatibility mode, call the object's print method in both pretty and regular printing mode, passing the mode as a third argument. * tests/012/oop.tl (defstruct animal): Support third argument in print method. Make it optional because there are some explicit calls which don't pass the argument. * txr.1: Documentation updated for print method and the print function. Revised text for some of the related functions. Added compat notes.
* A few volatile fixes related to setjmp.Kaz Kylheku2016-10-201-4/+4
| | | | | | | | | | | | * socket.c (dgram_get_byte_callback): nbytes must be volatile because we assign to it after setting up the catch, and then access it in the unwind code. (sock_accept): Likewise. * stream.c (generic_get_line): buf variable must be volatile. (struct save_fds): The members of this structure must be volatile; it's used as a local variable in a number of functions in a way that requires volatile.
* Add stream printing context.Kaz Kylheku2016-10-201-5/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is some infrastructure which will support *print-circle*. * lib.h (struct strm_ctx): Forward declared. (struct cobj_ops): Add context parameter to print function pointer. (cobj_print_op, obj_print_impl): Add context parameter to declarations. * hash.c (hash_print_op): Take context argument and pass it down in obj_print_impl calls. * lib.c (cobj_print_op, out_quasi_str): Likewise (obj_print_impl): Likewise, and also pass to COBJ print method. (obj_print, obj_pprint): Pass null pointer as context argument to obj_print_impl. * regex.c (regex_print): Take context parameter and ignore it. * socket.c (dgram_print): Likewise. * stream.h (struct strm_ctx): New struct type. (struct strm_base): New ctx member, pointer to struct strm_ctx. (stream_print_op): Add context parameter to declaration. (get_set_ctx, get_ctx): Declared. * stream.c (strm_base_init): Add null pointer to initializer. (strm_base_cleanup): Add assertion against context pointer being non-null: that indicates that some stream operation installed a context pointer and neglected to restore it to null before returning, which is bad because context will be stack allocated. (stream_print_op, stdio_stream_print, cat_stream_print): Take context parameter and ignore it. (get_set_ctx, get_ctx): New functions. * struct.c (struct_type_print): Take context parameter and ignore it. (struct_inst_print): Take context parameter and pass down to obj_print_impl.
* Add *print-circle* special variable.Kaz Kylheku2016-10-191-1/+2
| | | | | | | | * stream.c (print_circle_s): New symbol variable. (stream_init): Initialize print_circle_s as symbol named *print-circle*; register as special var. * stream.h (print_circle_s): Declared.
* nuke trailing newlines from exception messages.Kaz Kylheku2016-10-071-5/+5
| | | | | | | | | * signal.c (set_signal_handler, get_sign_handler): Eliminate newline in exception messages. * stream.c (unimpl, formatv): Likewise. * unwind.c (uw_block_abscond): Likewise.
* small bug in format: handle missing format char.Kaz Kylheku2016-10-071-0/+2
| | | | | | | | * stream.c (formatv): When the format string ends at the point where the format character is expected to occur, do not emit an error about #\nul being an unknown format directive character; emit an error that the character is missing.
* Synchronize license comments with LICENSE.Kaz Kylheku2016-10-011-16/+17
| | | | | | | | | | | | | | | | | | | | * Makefile, args.c, args.h, arith.c, arith.h, cadr.c, cadr.h, combi.c, combi.h, configure, debug.c, debug.h, eval.c, eval.h, filter.c, filter.h, ftw.c, ftw.h, gc.c, gc.h, glob.c, glob.h, hash.c, hash.h, jmp.S, lib.c, lib.h, lisplib.c, lisplib.h, match.c, match.h, parser.c, parser.h, parser.l, parser.y, rand.c, rand.h, regex.c, regex.h, share/txr/stdlib/awk.tl, share/txr/stdlib/build.tl, share/txr/stdlib/cadr.tl, share/txr/stdlib/conv.tl, share/txr/stdlib/except.tl, share/txr/stdlib/hash.tl, share/txr/stdlib/ifa.tl, share/txr/stdlib/path-test.tl, share/txr/stdlib/place.tl, share/txr/stdlib/socket.tl, share/txr/stdlib/struct.tl, share/txr/stdlib/termios.tl, share/txr/stdlib/txr-case.tl, share/txr/stdlib/type.tl, share/txr/stdlib/with-resources.tl, share/txr/stdlib/with-stream.tl, share/txr/stdlib/yield.tl, signal.c, signal.h, socket.c, socket.h, stream.c, stream.h, struct.c, struct.h, sysif.c, sysif.h, syslog.c, syslog.h, termios.c, termios.h, txr.1, txr.c, txr.h, unwind.c, unwind.h, utf8.c, utf8.h: Revert to verbatim 2-Clause BSD.
* New function pure-rel-path-p.Kaz Kylheku2016-09-271-0/+31
| | | | | | | | | * stream.c (plp_regex): New static variable. (pure_rel_path_p): New function. (stream_init): gc-protect plp_regex. Register pure-rel-path-p intrinsic. * txr.1: Document pure-rel-path-p and slightly revise abs-path-p.
* New strlist list input stream type.Kaz Kylheku2016-09-241-0/+137
| | | | | | | | | | | | | | | | | | * stream.c (struct strlist_in): New struct type. (strlist_in_stream_mark, strlist_in_get_line, strlist_in_get_char, strlist_in_unget_char, strlist_in_get_prop, strlist_in_get_error_str): New static functions. (strlist_in_ops): New static struct. (make_strlist_input_stream): New function. (stream_init): Register make-strlist-input-stream intrinsic. * stream.h (make_strlist_input_stream): Declared. * txr.1: Documented make-strlist-input-stream. Call fill_stream_ops on new strlist_in_ops struct to fill in common default stream operations.
* Don't open text files using "t" mode on Cygwin.Kaz Kylheku2016-07-121-1/+1
| | | | | | | | | | | | | | | | | Retracting the recent change to add the "t" mode when opening non-binary streams on Cygwin, which arranges for line ending conversion. This restores the Unix-like treatment of text files on Cygwin, which is expected of programs. The Windows native version of TXR will do line ending conversion thanks to the behavior of text streams in the Cygnal fork of Cygwin. * stream.c (format_mode): Only add the "t" option on Cygwin if compatibility with 144 and 145 is selected. * txr.1: Updated compatibility notes.
* Dynamically determine whether shell is cmd.exe.Kaz Kylheku2016-06-301-1/+18
| | | | | | | | | | | * stream.c (shell, shell_arg): New variables. (sh): Use shell and shell_arg, rather than hard-coded "/bin/sh" and "-c". (stream_init): Initialize shell and shell_arg to POSIX values. On Cygwin, call getusershell, and if it reports cmd.exe, use that instead, and adjust shell_arg to "/c". This will happen if the Cygwin DLL being used is the Cygnal version.
* We would like the Windows port of TXR to open files in textKaz Kylheku2016-06-281-0/+5
| | | | | | | | | | | | | | | | mode by default, such that "\r\n" is converted to "\n". Cygwin's stdio streams aren't doing this. This is fine when working in the Cygwin world, but not fine when we are making a "native" Windows program with the help of the Cygwin DLL. However, Cygwin supports the "t" mode letter in fopen, and that forces a text mode which does the conversion. * stream.c (format_mode): On Cygwin, if the mode isn't binary, add the 't' letter to the normalized mode string, unless compatibility <= 143 is requested. * txr.1: Added compat notes.
* Turn flags in struct stdio_handle into bitfields.Kaz Kylheku2016-05-291-3/+3
| | | | | * stream.c (struct stdio_handle): Members is_rotated, is_real_time and is_byte_oriented become bitfields.
* Support ISO C stream direction switching rules.Kaz Kylheku2016-05-281-0/+58
| | | | | | | | | | | | | | | | * stream.c (CONFIG_STDIO_STRICT): New preprocessor symbol. (enum stdio_op): New enum. (struct stdio_handle): New member, last_op. (stdio_switch): New static function, or macro. (stdio_put_string, stdio_put_char, stdio_put_byte): Indicate possible switch to write mode via stdio_switch. (stdio_flush): If the last direction wasn't write, don't bother doing anything. (stdio_get_char, stdio_get_byte): Indicate possible switch to read mode. (tail_strategy): Set last mode to stdio_none whenever new FILE * stream is installed. (make_stdio_stream_common): Initialize last_op member.
* Add a byte mode to stdio streams.Kaz Kylheku2016-05-281-4/+22
| | | | | | | | | | | | | | | | | * stream.c (byte_oriented_k): New keyword symbol variable. (struct stdio_handle): New member, is_byte_oriented. (stdio_get_prop): Retrieve the value of is_byte_oriented when the :byte-oriented property is inquired. (stdio_set_prop): Map :byte-oriented to the is_byte_oriented flag. (stdio_get_char): Do not decode UTF-8 if is_byte_oriented is set; just read one character. (make_stdio_stream_common): Initialize is_byte_oriented to 0. (stream_init): Initialize byte_oriented_k. * txr.1: Document :byte-oriented property, along with some clean-up and clarification in the description of properties.
* Don't use sleep function in tail streams.Kaz Kylheku2016-05-231-19/+7
| | | | | | | | | | | | | | | Let's use our usleep_wrap function which uses nanosleep. The old sleep can interact with SIGALRM. * stream.c (tail_calc): Calculate microseconds instead of seconds. (sleep): Wrapper for Windows gone. (tail_strategy): Rename sec variable to usec. Use usleep_wrap instead of sleep. * sysif.c (usleep_wrap): Change to extern. * sysif.h (usleep_wrap): Declaration updated.
* Optional argument on remove-path.Kaz Kylheku2016-05-231-5/+9
| | | | | | | | | | * stream.c (remove_path): New parameter, throw_on_error. (stream_init): Update registratino of remove_path intrinsic. * stream.h (remove_path): Declaration updated. * txr.1: Updated remove-path documentation to describe throw-on-error-p parameter.
* Wrong argument defaulting in record-adapter.Kaz Kylheku2016-05-091-1/+1
| | | | | | | | * stream.c (record_adapter): Use default_bool_arg rather than tnil. Since rb->include_match ends up passed directly to read_until_match, which deals with argument defaulting, we could just store the argument value into the structure.
* Argument of flush-stream now optional.Kaz Kylheku2016-05-071-2/+3
| | | | | | | | | * stream.c (flush_stream): Default the argument to std_output. (stream_init): Register flush-stream as having one optional arg. * txr.1: Updated flush-stream description.
* Redundant addr in printed rep of string-input-stream.Kaz Kylheku2016-05-071-1/+1
| | | | | * stream.c (string_in_get_prop): Do not format stream address into name; the general stream_print_op already adds that.
* New: standard stream redirection for subprocesses.Kaz Kylheku2016-05-071-11/+141
| | | | | | | | | | | | | | | | | | | When subprocesses are created using open-command, open-process, run or sh, any streams not bound by those functions are obtained from *stdin*, *stdout* or *stderr*, as appropriate. Thus manipulating these variables has the effect of redirecting not only local output within the program but over coprocesses as well. * stream.c (struct save_fds): New type. (FDS_IN, FDS_OUT, FDS_ERR): New macros. (fds_init, fds_subst, fds_swizzle, fds_restore): New static functions. (open_command, open_process, run): "Swizzle" and restore the standard file descriptors. * txr.1: Updated documentation of affected function.
* Strengthen against resource leaks upon exceptions.Kaz Kylheku2016-04-211-1/+2
| | | | | | | | | | | | | | | | | | | | | | | * glob.c (glob_wrap): Perform argument conversions that might throw before allocating UTF-8 string. * parser.y (text): In the action for SPACE, the lexeme is not needed so free($1) right away. If regex_compile were to throw an exception, that lexeme will leak. * socket.c (getaddrinfo_wrap): Harden against leakage of node_u8 and service_u8 strings with an unwind block. For instance, the hints structure could contain bad values which cause addrinfo_in to throw. * stream.c (make_string_byte_input_stream): Perform possibly throwing argument conversions before allocating resources. * sysif.c (mkdir_wrap, mknod_wrap, chmod_wrap, symlink_wrap, link_wrap, setenv_wrap, crypt_wrap): Likewise. * syslog.c (openlog_wrap, syslog_wrapv): Likewise.
* Recycle conses in unget-char and read-until-match.Kaz Kylheku2016-04-201-1/+1
| | | | | | | | | | | | * regex.c (ead_until_match): Use rcyc_pop instead of pop to move the conses to the recycle list. We know these are not shared with anything. Adding additional logic to completely recycle the stack. * socket.c (dgram_get_char): Use rcyc_pop to get the character from the push-back list. * stream.c (stdio_get_char): Likewise.
* Bugfix: optional arg defaulting in get-string.Kaz Kylheku2016-04-201-1/+2
| | | | | * stream.c (get_string): The optional stream argument must be treated accordingly.
* read-until-match can optionally keep matched text.Kaz Kylheku2016-04-201-3/+5
| | | | | | | | | | | | | | | | | | | | * regex.c (read_until_match): New argument, include_match. Three times repeated termination code refactored into block reached by forward goto. (regex_init): Registration of read-until-match updated. * regex.h (read_until_match): Declaration updated. * stream.c (struct record_adapter_base): New member, include_match. (record_adapter_get_line): Pass match to read_until_match as new argument. (record_adapater): New argument, include_match. (stream_init): Update registration of record-adapter. * stream.h (record_adapter): Declaration updated. * txr.1: Updated.