summaryrefslogtreecommitdiffstats
path: root/buf.c
Commit message (Collapse)AuthorAgeFilesLines
* bugfix: buf-get-* not allowing last byte of buffer.Kaz Kylheku2018-02-281-1/+1
| | | | | | | * buf.c (buf_get_bytes): Fix off-by-one test for reading past end of buffer. This prevents, e.g. a buf-get-u32 from the last four bytes of a buffer (or from a four-byte-long buffer, period).
* 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.
* bugfix: fixnum crackdown.Kaz Kylheku2017-09-131-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* buffers: fix infinite loop in buf_grow.Kaz Kylheku2017-08-221-6/+8
| | | | | | | * buf.c (buf_grow): When size is zero and len is nonzero, the loop doesn't terminate. Replace silly loop with straightforward calculation: grow buffer by 25%, capped at INT_PTR_MAX, or grow to the length, whichever is larger.
* buf: provide way to work with on-stack buffers.Kaz Kylheku2017-08-161-3/+6
| | | | | | | | * buf.c (init_borrowed_buf): New function. (make_borrowed_buf): Reduced to wrapper around init_borrowed_buf. * buf.h (init_borrowed_buf): Declared.
* buf: new buffer stream.Kaz Kylheku2017-08-141-0/+263
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * buf.c (struct buf_strm): New struct type. (buf_strm_mark, int buf_strm_put_byte_callback, buf_strm_put_string, buf_strm_put_char, buf_strm_put_byte, buf_strm_get_byte_callback, buf_strm_get_char, buf_strm_get_byte, buf_strm_unget_char, buf_strm_unget_byte, buf_strm_seek, buf_strm_truncate, buf_strm_get_prop, buf_strm_set_prop, buf_strm_get_error, buf_strm_get_error_str): New static functions. (buf_strm_ops): New static struct. (buf_strm): New static function. (make_buf_stream, get_buf_from_stream): New functions. (buf_init): Register new intrinsic functiions make-buf-stream and get-buf-from-stream. Call fill_stream_ops on new buf_strm_ops to fill default operations in place of function pointers that have been left null. * buf.h (make_buf_stream, get_buf_from_stream): Declared. * lisplib.c (with_stream_set_entries): Add with-out-buf-stream and with-in-buf-stream to auto-load symbols for with-stream.tl module. * share/txr/stdlib/with-stream.tl (with-out-buf-stream, with-in-buf-stream): New macros. * txr.1: New section about buffer streams.
* buf: tiny code improvement.Kaz Kylheku2017-08-141-1/+1
| | | | | * buf.c (buf_grow): Use the previously calculated delta value, rather than re-evaluating the equivalent expression.
* bugfix: buf-put-ucharKaz Kylheku2017-08-141-1/+1
| | | | | * buf.c (buf_put_uchar): Fix wrong conversion that is causing this function to reject values in the 128-255 range.
* buf: new bufp function.Kaz Kylheku2017-06-121-0/+6
| | | | | | | | | * buf.c (bufp): New function. (buf_init): Registered bufp intrisic. * buf.h (bufp): Declared. * txr.1: Documented.
* c++ maintenance: eliminate old-style casts.Kaz Kylheku2017-06-061-4/+4
| | | | | | | | | | | | | | | | | | | | 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.
* ffi and buf porting: stdarg.h needed.Kaz Kylheku2017-05-111-0/+1
| | | | * buf.c, ffi.c: Must include <stdarg.h> for va_list.
* buffers: correct length check in buf-put- functions.Kaz Kylheku2017-05-081-2/+3
| | | | | | | * buf.c (buf_put_bytes): We must extend the buffer based on looking at the end position of the data transfer, not the start position, so the buffer is large enough to old the entire transfer.
* buffers: don't let a buffer shrink to zero.Kaz Kylheku2017-05-081-4/+6
| | | | | | | * buf.c (buf_shrink): If a buffer has zero length, don't shrink the allocation size all the way down to zero, because that value indicates a non-resizeable buffer.
* ffi: rethink passing and alloc scheme for bufs.Kaz Kylheku2017-05-071-6/+0
| | | | | | | | | | | | | | | | | Backing out of the scheme of (ptr buf) passing the address of the internal pointer within buf objects. Also giving buf in handlers, to prevent the fallback on get. * buf.c (buf_addr_of): Function removed. * buf.h (buf_addr_of): Declaration removed. * ffi.c (ffi_buf_in, ffi_buf_d_in): New functions. (ffi_buf_alloc): Function removed. (ffi_type_compile, ffi_init_types): Remove specialty alloc and free functions from buffers, so the regular fixed allocator is used. Give buffers the new in functions.
* buf: fix memory leak.Kaz Kylheku2017-04-301-1/+1
| | | | | | * buf.c (make_duplicate_buf): A duplicated buf is dynamic, so the size must not be nil, which indicates a static or borrowed one. Set the size properly, so finalize will free it.
* ffi: correct treatment of (ptr buf).Kaz Kylheku2017-04-291-0/+6
| | | | | | | | | | | | | | The buf FFI type's alloc virtual should return a pointer to the buffer's pointer, not the buffer itself. What's currently going on is something silly, whereby the pointer to the buffer is stored into the buffer itself. * buf.c (buf_addr_of): New function. * buf.c (buf_addr_of): Declared. * ffi.c (ffi_buf_alloc): Use buf_addr_of instead of buf_get.
* ffi: support buf objects.Kaz Kylheku2017-04-261-0/+24
| | | | | | | | | | | | | | | | * buf.c (make_duplicate_buf, buf_get, buf_fill): New functions. * buf.h (make_duplicate_buf, buf_get, buf_fill): Declared. * ffi.c (struct txr_ffi_type): New member, nelem. Keeps track of number of elements, for types that are FFI pointers. This lets us support the get method so that a buf can be a C function return value, if its size is declared in our FFI type system. (ffi_buf_put, ffi_buf_get, ffi_buf_fill): New functions. (ffi_type_compile): Handle two new cases of syntax for buffers: (buf <size>) and buf.
* Buffers: missing float and cptr.Kaz Kylheku2017-04-241-0/+42
| | | | | | | | | | | | | * buf.c (buf_put_float, buf_put_cptr, buf_get_float, buf_get_cptr, align_float, align_cptr, size_float, size_cptr): New functions. (buf_init): Registered intrinsics buf-put-float, buf-put-cptr, buf-get-float, buf-get-cptr, align-float, align-cptr, size-float, size_cptr. * buf.h (buf_put_float, buf_put_cptr, buf_get_float, buf_get_cptr, align_float, align_cptr, size_float, size_cptr): Declared.
* Buffers implementation, part three: get functions.Kaz Kylheku2017-04-211-17/+117
| | | | | | | | | | | | | * arith.c (unum): New function. * arith.h (unum): Declared. * buf.c (buf_get_bytes): New static function. (buf_get_i8, buf_get_u8, buf_get_i16, buf_get_u16, buf_get_i32, buf_get_u32, buf_get_i64, buf_get_u64, buf_get_char, buf_get_uchar, buf_get_short, buf_get_ushort, buf_get_int, buf_get_uint, buf_get_long, buf_get_ulong, buf_get_double): Stubs implemented.
* Continuing implementation of buffers.Kaz Kylheku2017-04-211-0/+544
* Makefile (OBJS): New objects itypes.o and buf.o. * buf.c, buf.h: New files. * itypes.c, itypes.h: New files. * lib.c (obj_print_impl): Handle BUF via buf_print and buf_pprint. (init): Call itypes_init and buf_init. * parser.h (end_of_buflit): Declared. * parser.l (BUFLIT): New exclusive state. (grammar): New rules for recognizing start of buffer literal and its interior. (end_of_buflit): New function. * parser.y (HASH_B_QUOTE): New token. (buflit, buflit_items, buflit_item): New nonterminals and corresponding grammar rules. (i_expr, n_expr): These symbols now generate a buflit; a buffer literal is a kind of expression. (yybadtoken): Handle HASH_B_QUOTE case.