summaryrefslogtreecommitdiff
path: root/libguile/read.c
AgeCommit message (Collapse)AuthorFilesLines
2019-06-18Rename 'scm_c_make_char' to 'scm_i_make_char'.Mark H Weaver1-1/+1
* libguile/chars.c, libguile/chars.h, libguile/ports.c, libguile/print.c, libguile/read.c, libguile/srfi-13.c, libguile/strings.c, libguile/vm-engine.c: Rename 'scm_c_make_char' to 'scm_i_make_char'.
2019-05-07Add 'scm_c_make_char' and use it where appropriate.Mark H Weaver1-2/+2
This reverts the change to SCM_MAKE_CHAR made in the previous commit 63818453ad226cd3c2d1fd8ade12e3d7c1d43c05, which used an arithmetic trick to avoid evaluating its argument more than once. Here, we restore the previous implementation of SCM_MAKE_CHAR, which evaluates its argument twice. Instead, we introduce a new inlinable function 'scm_c_make_char' and replace uses of SCM_MAKE_CHAR with calls to 'scm_c_make_char' where appropriate. * libguile/chars.h (scm_c_make_char): New inline function. * libguile/inline.c: Include chars.h. * libguile/srfi-13.c (REF_IN_CHARSET, scm_string_any, scm_string_every) (scm_string_trim, scm_string_trim_right, scm_string_trim_both) (scm_string_index, scm_string_index_right, scm_string_skip) (scm_string_skip_right, scm_string_count, string_titlecase_x) (string_reverse_x, scm_string_fold, scm_string_fold_right) (scm_string_for_each, scm_string_filter, scm_string_delete): Use 'scm_c_make_char' instead of 'SCM_MAKE_CHAR' in cases where the argument calls a function. * libguile/chars.c (scm_char_upcase, scm_char_downcase, scm_char_titlecase), libguile/ports.c (scm_port_decode_char), libguile/print.c (scm_simple_format), libguile/read.c (scm_read_character), libguile/strings.c (scm_string_ref, scm_c_string_ref), libguile/vm-engine.c ("string-ref"): Ditto.
2018-10-17Use 'scm_from_utf8_{string,symbol,keyword}' for C string literals.Mark H Weaver1-7/+10
Partial fix for <https://bugs.gnu.org/33044>. Reported by Tom de Vries <tdevries@suse.de>. Fix several instances of the mistake of using 'scm_from_locale_*' for C strings that originally came from a C string literal. Change several uses of 'scm_from_latin1_*' as well, to promote the practice of writing code that works for arbitrary C string literals. Also add missing years to the copyright notices of changed files, based on the git history. * libguile/debug-malloc.c, libguile/deprecation.c, libguile/error.c, libguile/eval.c, libguile/expand.c, libguile/extensions.c, libguile/filesys.c, libguile/init.c, libguile/load.c, libguile/modules.c, libguile/pairs.c, libguile/posix.c, libguile/print.c, libguile/random.c, libguile/read.c, libguile/regex-posix.c, libguile/snarf.h, libguile/srfi-13.c, libguile/stacks.c, libguile/stime.c, libguile/strports.c, libguile/values.c: Use 'scm_from_utf8_*' where appropriate.
2017-02-16Remove unnecessary scm_i_string_start_writing callsAndy Wingo1-4/+2
* libguile/strings.c (scm_string, scm_c_make_string): * libguile/srfi-13.c (scm_reverse_list_to_string, scm_string_map) (scm_string_unfold, scm_string_unfold_right, scm_xsubstring) (scm_string_filter, scm_string_delete): Remove scm_i_string_start_writing / scm_i_string_stop_writing calls around fresh strings that aren't visible to other threads.
2017-02-14Elide syscalls in fdes->portAndy Wingo1-10/+6
* libguile/fports.h (scm_t_fport): Add options field. (SCM_FDES_RANDOM_P): Deprecate. (scm_i_fdes_to_port): Add options argument. * libguile/fports.c (scm_i_fdes_to_port): Add options argument. Only verify FD if SCM_FPORT_OPTION_VERIFY is there. (scm_fdes_to_port, scm_open_file_with_encoding): Adapt to scm_i_fdes_to_port changes. (fport_random_access_p): Don't try to seek if NOT_SEEKABLE option is set. * libguile/deprecated.h: * libguile/deprecated.c (SCM_FDES_RANDOM_P): Deprecate. * NEWS: Add deprecation. * libguile/filesys.c: * libguile/ioext.c: * libguile/posix.c: * libguile/read.c: * libguile/socket.c: Adapt callers.
2017-02-08Prevent TOCTTOU bugs in C portsAndy Wingo1-5/+4
* libguile/ports-internal.h (scm_port_buffer_can_take): (scm_port_buffer_can_put): Add cur/end output arguments so that when a caller asks the buffer room, it can be relative to a fixed point in the buffer and not whatever point it's at when we go to fill it. (scm_port_buffer_did_take, scm_port_buffer_did_put): Similarly, require that the caller knows where they took/put data in the buffer. Prevents overflow. (scm_port_buffer_take_pointer, scm_port_buffer_put_pointer): Likewise, require that the caller has already checked and knows a position in the buffer and therefore how much data is available. (scm_port_buffer_take, scm_port_buffer_put, scm_port_buffer_putback): Adapt. * libguile/ports.h (scm_fill_input): Add cur/avail output arguments. * libguile/filesys.c: * libguile/poll.c: * libguile/ports.c: * libguile/r6rs-ports.c: * libguile/read.c: * libguile/rw.c: Adapt all callers. Gnarly work!
2016-11-21Deprecate dynamic rootsAndy Wingo1-1/+0
* libguile/root.h: * libguile/root.c: Remove these files. * libguile/deprecated.h: * libguile/deprecated.c (scm_internal_cwdr, scm_call_with_dynamic_root) (scm_dynamic_root, scm_apply_with_dynamic_root): Deprecate. Remove all root.h usage, which was vestigial. * module/ice-9/serialize.scm: Use (current-thread) instead of (dynamic-root).
2016-07-25Avoid compilation warnings about alloca in read.cEli Zaretskii1-0/+1
* libguile/read.c: Include alloca.h.
2016-05-22Heed the reader settings implied by #!r6rsAndreas Rottmann1-2/+38
When encountering the #!r6rs directive, apply the appropriate reader settings to the port. * libguile/read.scm (read-string-as-list): New helper procedure. (scm_read_shebang): Set reader options implied by the R6RS syntax upon encountering the #!r6rs directive. * test-suite/tests/reader.test (per-port-read-options): Add tests for the #!r6rs directive.
2016-05-22Speed up port position access from SchemeAndy Wingo1-25/+33
* libguile/ports-internal.h (scm_port_buffer_position): (scm_port_position_line, scm_port_position_set_line): (scm_port_position_column, scm_port_position_set_column): New helpers. (scm_t_port): Ports now hold position as a pair, so that Scheme can access it easily. (SCM_LINUM, SCM_COL, SCM_INCLINE, SCM_ZEROCOL, SCM_INCCOL) (SCM_DECCOL, SCM_TABCOL): Remove. * libguile/ports.c (make_port_buffer): Rename from scm_c_make_port_buffer, make static, and take port as an argument so we can initialize the position field. (initialize_port_buffers): Adapt make_port_buffer change. (scm_c_make_port_with_encoding): Initialize position. (update_port_position): Rename from update_port_lf, and operate on port position objects. (scm_ungetc): Operate on port position objects. (scm_setvbuf, scm_expand_port_read_buffer_x): Adapt to make_port_buffer change. (scm_lfwrite): Adapt to call update_port_position. (scm_port_line, scm_set_port_line_x, scm_port_column) (scm_set_port_column_x): Adapt to use port positions. * libguile/ports.h (scm_c_make_port_buffer): Remove internal decl. * libguile/read.c: Adapt to use scm_port_line / scm_port_column instead of SCM_LINUM et al. * module/ice-9/ports.scm (port-buffer-position, port-position-line) (port-position-column, set-port-position-line!) (set-port-position-column!): New accessors for the internals module. * module/ice-9/sports.scm (advance-port-position!): Rename from port-advance-position! and use the new accessors. (read-char, port-fold-chars/iso-8859-1): Adapt to use advance-port-position!.
2016-05-13Remove scm_t_port_internalAndy Wingo1-5/+5
* libguile/ports-internal.h (SCM_PORT): Rename from SCM_PTAB_ENTRY. (scm_t_port_internal, SCM_PORT_GET_INTERNAL): Remove. (SCM_FILENAME, SCM_SET_FILENAME, SCM_LINUM, SCM_COL): Adapt. * libguile/ports.c: * libguile/poll.c: * libguile/ioext.c: * libguile/fports.c: * libguile/filesys.c: * libguile/print.c: * libguile/read.c: * libguile/rw.c: * libguile/strings.c: Adapt.
2016-05-13Make port buffering fields privateAndy Wingo1-4/+4
* libguile/ports-internal.h (enum scm_port_buffer_field) (scm_t_port_internal): Make port buffering fields private. * libguile/ports.h (scm_t_port): Adapt. * libguile/filesys.c (set_element): * libguile/ioext.c (scm_redirect_port): * libguile/poll.c (scm_primitive_poll): * libguile/ports.c: * libguile/read.c (scm_i_scan_for_encoding): * libguile/rw.c (scm_write_string_partial): Adapt users.
2016-05-03Port encoding internally represented as symbolAndy Wingo1-3/+4
* libguile/ports-internal.h (scm_t_port_internal): Remove encoding_mode member. * libguile/ports.h (scm_t_port): "encoding" member is now a SCM symbol. * libguile/ports.c (scm_init_ports): Define symbols for the encodings that we handle explicitly. (encoding_matches): Adapt to check against an encoding as a symbol. (canonicalize_encoding): Return an encoding as a symbol. (scm_c_make_port_with_encoding, scm_i_set_default_port_encoding) (decide_utf16_encoding, decide_utf32_encoding) (scm_i_port_iconv_descriptors, scm_i_set_port_encoding_x) (scm_port_encoding, peek_codepoint, scm_ungetc): Adapt to encoding change. * libguile/print.c (display_string_using_iconv, display_string): * libguile/read.c (scm_read_character): * libguile/strings.c (scm_from_port_stringn, scm_to_port_stringn): Adapt to port encoding change.
2016-05-01scm_fill_input can guarantee a minimum fill amountAndy Wingo1-1/+1
* libguile/ports.h (scm_fill_input): Add "minimum_size" argument. Adapt all callers to pass 0 as this argument. * libguile/ports.c (scm_i_read): Inline into scm_fill_input. (scm_fill_input): "minimum_size" argument ensures that there are a certain number of bytes available, or EOF. Instead of shrinking the read buffer, only fill by the read_buffering amount, or the minimum_size, whichever is larger. * libguile/r6rs-ports.c: * libguile/read.c: Adapt scm_fill_input callers.
2016-04-28Remove port locking around write, displayAndy Wingo1-5/+0
* libguile/print.c (scm_write, scm_display): * libguile/read.c (set_port_read_option): Remove port locking. Reading and writing to the same port from multiple threads just must not crash; it doesn't have to make sense.
2016-04-26Remove scm_fill_input_unlockedAndy Wingo1-1/+1
* libguile/ports.h (scm_fill_input_unlocked): Remove. * libguile/ports.c (scm_fill_input): Rename from scm_fill_input_unlocked. Adapt callers. * libguile/r6rs-ports.c (scm_get_bytevector_some): Adapt. * libguile/read.c (scm_i_scan_for_encoding): Adapt.
2016-04-23scm_ungetc, scm_ungets instead of _unlocked variantsAndy Wingo1-21/+21
* libguile/ports.h (scm_ungetc_unlocked, scm_ungets_unlocked): Remove; replace with scm_ungetc, scm_ungets. * libguile/ports.c (scm_ungetc, scm_ungets, scm_unread_char) (scm_unread_string): Adapt. * libguile/rdelim.c (scm_read_delimited_x): Use scm_ungetc. * libguile/read.c: Unread characers with scm_ungetc, not scm_ungetc_unlocked.
2016-04-23Remove scm_unget_{byte,bytes}_unlockedAndy Wingo1-1/+1
* libguile/ports.h (scm_unget_bytes_unlocked, scm_unget_byte_unlocked): Remove. * libguile/ports.c (looking_at_bytes): Use scm_unget_bytes instead of scm_i_unget_bytes_unlocked (scm_unget_bytes): Rename from scm_i_unget_bytes_unlocked. Remove other implementations of this function. (scm_unget_byte): Likewise. (scm_ungetc_unlocked, scm_peek_char): Use scm_unget_byte. * libguile/read.c (read_token): Use scm_unget_byte.
2016-04-23Replace scm_getc with scm_getc_unlockedAndy Wingo1-31/+31
* libguile/ports.h (scm_getc_unlocked): Remove, or rather rename to scm_getc. This probably introduces some thread-related bugs but we'll fix them in a different way. * libguile/ports.c (scm_getc): Rename from scm_getc_unlocked, replacing the locky implementation. (scm_read_char): Use scm_getc. * libguile/r6rs-ports.c (scm_get_string_n_x): Use scm_getc. * libguile/rdelim.c (scm_read_delimited_x, scm_read_line): Use scm_getc. * libguile/read.c: Use scm_getc.
2016-04-23Remove scm_flush_unlocked / scm_end_input_unlockedAndy Wingo1-1/+1
* libguile/ports.h (scm_flush_unlocked, scm_end_input_unlocked): Remove. * libguile/ports.c (scm_c_read_bytes_unlocked): (scm_i_unget_bytes_unlocked, scm_setvbuf, scm_force_output) (scm_fill_input_unlocked, scm_c_write_bytes_unlocked) (scm_c_write_unlocked, scm_lfwrite_unlocked, scm_seek) (scm_truncate_file, flush_output_port): Call scm_flush / scm_end_input instead of the _unlocked variants. (scm_end_input): Lock while discarding the input buffer but not while calling out to the seek function. * libguile/filesys.c (scm_fsync): * libguile/ioext.c (scm_redirect_port): * libguile/read.c (scm_i_scan_for_encoding): * libguile/rw.c (scm_write_string_partial): Use scm_flush, not scm_flush_unlocked.
2016-04-22Remove port rw_active fieldAndy Wingo1-5/+1
* libguile/ports.h (scm_t_port_rw_active): Move type definition to ports-internal.h. (scm_t_port): Remove rw_active field. It's sufficient to check the port buffer cursors. * libguile/read.c (scm_i_scan_for_encoding): Just call scm_flush_unlocked; it's idempotent. * libguile/ports.c (scm_c_make_port_with_encoding): Remove rw_active field. (scm_c_read_bytes_unlocked, scm_c_read, scm_i_unget_bytes_unlocked) (scm_end_input_unlocked, scm_flush_unlocked, scm_fill_input_unlocked) (scm_port_write_buffer, scm_port_read_buffer) (scm_c_write_bytes_unlocked, scm_c_write_unlocked, scm_seek): Remove management of rw_active field.
2016-04-22scm_c_read instead of scm_c_read_unlockAndy Wingo1-1/+1
* libguile/ports.h (scm_c_read_unlocked): Remove. * libguile/ports.c (scm_c_read): Rename from scm_c_read_unlocked. Remove old scm_c_read. Lock around access to the rw_active flag, and call scm_flush instead of scm_flush_unlocked, and scm_fill_input instead of scm_fill_input_unlocked. * libguile/read.c (scm_i_scan_for_encoding): Use scm_c_read instead of the _unlocked function.
2016-04-22Refactor to internal get/peek-byte functionsAndy Wingo1-3/+3
* libguile/ports.h (scm_get_byte_or_eof_unlocked) (scm_peek_byte_or_eof_unlocked): Remove inline functions. The important uses are in ports.c anyway and we will use a static function there. (scm_slow_get_byte_or_eof_unlocked) (scm_slow_peek_byte_or_eof_unlocked): Remove declarations without definitions. * libguile/ports.c (looking_at_bytes): Use scm_peek_byte_or_eof instead of the _unlocked variant. (get_byte_or_eof, peek_byte_or_eof): New static functions. (scm_get_byte_or_eof, scm_peek_byte_or_eof): Don't lock: the port buffer mechanism means that we won't crash. More comments to come. (get_utf8_codepoint, get_latin1_codepoint, get_iconv_codepoint): Use new static functions. * libguile/read.c (read_token, scm_read_semicolon_comment): Use scm_get_byte_or_eof, not scm_get_byte_or_eof_unlocked.
2016-04-20Port buffers are Scheme valuesAndy Wingo1-1/+1
* libguile/ports-internal.h (scm_port_buffer_bytevector) (scm_port_buffer_cur, scm_port_buffer_set_cur) (scm_port_buffer_end, scm_port_buffer_set_end) (scm_port_buffer_has_eof_p, scm_port_buffer_set_has_eof_p): New helpers. * libguile/ports-internal.h (scm_port_buffer_size) (scm_port_buffer_reset, scm_port_buffer_reset_end) (scm_port_buffer_can_take, scm_port_buffer_can_put) (scm_port_buffer_can_putback, scm_port_buffer_did_take) (scm_port_buffer_did_put, scm_port_buffer_take_pointer) (scm_port_buffer_put_pointer, scm_port_buffer_take) (scm_port_buffer_put, scm_port_buffer_putback): Adapt to treat port buffers as SCM values and use helpers to access them. * libguile/ports.c (scm_i_clear_pending_eof, scm_i_set_pending_eof) (scm_c_make_port_buffer, scm_i_read_unlocked) (scm_c_read_bytes_unlocked, scm_i_unget_bytes_unlocked) (scm_setvbuf, scm_fill_input, scm_take_from_input_buffers) (scm_drain_input, scm_end_input_unlocked, scm_flush_unlocked) (scm_fill_input_unlocked, scm_i_write_unlocked) (scm_c_write_bytes_unlocked, scm_c_write_unlocked) (scm_char_ready_p): Adapt to treat port buffers as SCM values and use helpers to access them. (scm_port_read_buffer, scm_port_write_buffer): New functions, allowing (ice-9 ports) to access port buffers. * libguile/ports.h: Update comments on port buffers. Replace scm_t_port_buffer structure with a Scheme vector whose fields are enumerated by "enum scm_port_buffer_field". (scm_get_byte_or_eof_unlocked, scm_peek_byte_or_eof_unlocked): Adapt these implementations to port buffer representation change. * libguile/r6rs-ports.c (scm_get_bytevector_some): * libguile/read.c (scm_i_scan_for_encoding): * libguile/rw.c (scm_write_string_partial): Port buffers are Scheme objects.
2016-04-19Port buffer cur/next pointers are Scheme valuesAndy Wingo1-2/+2
* libguile/ports.h (scm_t_port_buffer): Change "cur" and "end" members to be SCM values, in preparation for changing port buffers to be Scheme vectors. (scm_get_byte_or_eof_unlocked, scm_peek_byte_or_eof_unlocked): Adapt. * libguile/ports.c (scm_c_make_port_buffer): Initialize cur and end members. (looking_at_bytes): Use helper instead of incrementing cur. (scm_i_read_unlocked): Adapt to end type change. (CONSUME_PEEKED_BYTE): Use helper instead of incrementing cur. (scm_i_unget_bytes_unlocked): Use helper instead of comparing cur. (scm_i_write_unlocked): Fix for changing end/cur types. * libguile/read.c (scm_i_scan_for_encoding): Use helpers instead of addressing cursors directly. * libguile/rw.c (scm_write_string_partial): Likewise. * libguile/ports-internal.h (scm_port_buffer_reset): (scm_port_buffer_reset_end, scm_port_buffer_can_take): (scm_port_buffer_can_put, scm_port_buffer_can_putback): (scm_port_buffer_did_take, scm_port_buffer_did_put): (scm_port_buffer_take_pointer, scm_port_buffer_put_pointer): (scm_port_buffer_putback): Adapt to data types.
2016-04-18Remove "buf" field from port buffersAndy Wingo1-1/+1
* libguile/ports-internal.h (scm_port_buffer_reset_end): New helper. (scm_port_buffer_putback): New helper. * libguile/ports.h (scm_t_port_buffer): Remove "buf" field. (scm_get_byte_or_eof_unlocked, scm_peek_byte_or_eof_unlocked): Adapt. * libguile/ports.c (scm_c_make_port_buffer): No more "buf" field. (scm_i_unget_bytes_unlocked): Use helper. * libguile/read.c (scm_i_scan_for_encoding): No more "buf" field.
2016-04-06Generic port facility provides buffering uniformlyAndy Wingo1-6/+6
* libguile/ports.h (struct scm_t_port_buffer): New data type. (struct scm_t_port): Refactor to use port buffers instead of implementation-managed read and write pointers. Add "read_buffering" member. (SCM_INITIAL_PUTBACK_BUF_SIZE, SCM_READ_BUFFER_EMPTY_P): Remove. (scm_t_ptob_descriptor): Rename "fill_input" function to "read", and take a port buffer, returning void. Likewise "write" takes a port buffer and returns void. Remove "end_input"; instead if there is buffered input and rw_random is true, then there must be a seek function, so just seek back if needed. Remove "flush"; instead all calls to the "write" function implicitly include a "flush", since the buffering happens in the generic port code now. Remove "setvbuf", but add "get_natural_buffer_sizes"; instead the generic port code can buffer any port. (scm_make_port_type): Adapt to read and write prototype changes. (scm_set_port_flush, scm_set_port_end_input, scm_set_port_setvbuf): Remove. (scm_slow_get_byte_or_eof_unlocked) (scm_slow_get_peek_or_eof_unlocked): Remove; the slow path is to call scm_fill_input. (scm_set_port_get_natural_buffer_sizes): New function. (scm_c_make_port_buffer): New internal function. (scm_port_non_buffer): Remove. This was a function for implementations that is no longer needed. Instead open with BUF0 or use (setvbuf port 'none). (scm_fill_input, scm_fill_input_unlocked): Return the filled port buffer. (scm_get_byte_or_eof_unlocked, scm_peek_byte_or_eof_unlocked): Adapt to changes in buffering and EOF management. * libguile/ports.c: Adapt to port interface changes. (initialize_port_buffers): New function, using the port mode flags to set up appropriate initial buffering for all ports. (scm_c_make_port_with_encoding): Create port buffers here instead of delegating to implementations. (scm_close_port): Flush the port if needed instead of delegating to the implementation. * libguile/filesys.c (set_element): Adapt to buffering changes. * libguile/fports.c (fport_get_natural_buffer_sizes): New function, replacing scm_fport_buffer_add. (fport_write, fport_read): Update to let the generic ports code do the buffering. (fport_flush, fport_end_input): Remove. (fport_close): Don't flush in a dynwind; that's the core ports' job. (scm_make_fptob): Adapt. * libguile/ioext.c (scm_redirect_port): Adapt to buffering changes. * libguile/poll.c (scm_primitive_poll): Adapt to buffering changes. * libguile/ports-internal.h (struct scm_port_internal): Remove pending_eof flag; this is now set on the read buffer. * libguile/r6rs-ports.c (struct bytevector_input_port): New type. The new buffering arrangement means that there's now an intermediate buffer between the bytevector and the user of the port; this could lead to a perf degradation, but on the other hand there are some other speedups enabled by the buffering refactor, so probably the memcpy cost is dwarfed by the cost of the other parts of the ports machinery. (make_bytevector_input_port, bytevector_input_port_read): (bytevector_input_port_seek, initialize_bytevector_input_ports): Adapt to new buffering arrangement. (struct custom_binary_port): Remove read buffer, as Guile handles that now. (custom_binary_input_port_setvbuf): Remove; now handled by Guile. (make_custom_binary_input_port, custom_binary_input_port_read) (initialize_custom_binary_input_ports): Adapt. (scm_get_bytevector_some): Adapt to new EOF management. (scm_t_bytevector_output_port_buffer): Hold on to the underlying port, so we can flush it if it's open. (make_bytevector_output_port, bytevector_output_port_write): (bytevector_output_port_seek): Adapt. (bytevector_output_port_procedure): Flush the port as appropriate, so that we get all the bytes. (make_custom_binary_output_port, custom_binary_output_port_write): Adapt. (make_transcoded_port): Don't muck with buffering. (transcoded_port_write): Simply forward the write to the underlying port. (transcoded_port_read): Likewise. (transcoded_port_close): No need to flush. (initialize_transcoded_ports): Adapt. * libguile/read.c (scm_i_scan_for_encoding): Adapt to buffering changes. * libguile/rw.c (scm_write_string_partial): Adapt to buffering changes. * libguile/strports.c: Adapt to the fact that we don't manage the buffer. Probably room for speed improvements here... * libguile/vports.c (soft_port_get_natural_buffer_sizes): New function. Adapt the rest of the file for the new buffering regime. * test-suite/tests/r6rs-ports.test ("8.2.10 Output ports"): Custom binary output ports need to be flushed before you can rely on the write! procedure having been called. Add necessary flush-port invocations. ("8.2.6 Input and output ports"): Transcoded ports now have an internal buffer by default. This test checks that the characters are transcoded one at a time, so to do that, call setvbuf on the transcoded port to remove the buffer. * test-suite/tests/web-client.test (run-with-http-transcript): Fix for different flushing regime on soft ports. (The vestigial flush procedure is now called after each write, which is not what the test was expecting.) * test-suite/standalone/test-scm-c-read.c: Update for changes to the C interface for defining port types. * doc/ref/api-io.texi (Ports): Update to discuss buffering in a generic way, and to remove a hand-wavey paragraph describing string ports as "interesting and powerful". (Reading, Writing): Remove placeholder comments. Document `scm_lfwrite'. (Buffering): New section. (File Ports): Link to buffering. (I/O Extensions): Join subnodes into parent and describe new API, including buffering API. * doc/ref/posix.texi (Ports and File Descriptors): Link to buffering. Remove unread-char etc, as they are documented elsewhere. (Pipes, Network Sockets and Communication): Link to buffering.
2016-04-04Refactor to rw_random / rw_active port flagsAndy Wingo1-4/+5
* libguile/fports.c (fport_flush, fport_end_input): Move rw_active handling to ports.c. * libguile/ioext.c (scm_redirect_port): Use scm_flush_unlocked instead of calling the flush function directly. * libguile/ports.c (scm_c_make_port_with_encoding): Ports default to "rw_random" mode when they have a seek function. (scm_c_read_unlocked, scm_i_unget_bytes_unlocked) (scm_slow_get_byte_or_eof_unlocked) (scm_slow_peek_byte_or_eof_unlocked): Flush write buffer and set rw_active always in the same way, and only if rw_random is true. (scm_end_input_unlocked, scm_flush_unlocked): Clear rw_active here unconditionally. (scm_c_write_unlocked): Flush read buffer and set rw_active always in the same way, but only if rw_random is true. (scm_c_write, scm_lfwrite): Whitespace fixes. (scm_lfwrite_substr): Don't flush read buffer; lower-level code will do this. (scm_truncate_file): Use scm_flush_unlocked instead of calling the flush function directly. * libguile/r6rs-ports.c (transcoded_port_flush): Don't muck with rw_active. * libguile/read.c (scm_i_scan_for_encoding): Flush write buffer if needed in same way as ports.c. * libguile/strports.c (st_end_input): Don't muck with rw_active. (scm_mkstrport): rw_random defaults to 1 now.
2015-01-22Merge commit '5af307de43e4b65eec7f235b48a8908f2a00f134'Andy Wingo1-2/+5
Conflicts: test-suite/tests/reader.test
2014-10-01read: Accept "\(" in string literals.Mark H Weaver1-2/+5
Suggested by David Kastrup <dak@gnu.org> in <http://bugs.gnu.org/13644>. * libguile/read.c (scm_read_string_like_syntax): Accept "\(" as equivalent to "(". * doc/ref/api-data.texi (String Syntax): Document it. * test-suite/tests/reader.test ("reading"): Add test.
2014-07-21maybe_annotate_source does not annotate negative positionsAndy Wingo1-0/+5
* libguile/read.c (maybe_annotate_source): Don't annotate with negative lines or columns.
2014-01-21Merge branch 'stable-2.0'Mark H Weaver1-8/+24
Conflicts: libguile/read.c test-suite/tests/web-response.test
2014-01-17Arrange so that 'file-encoding' does not truncate the encoding name.Ludovic Courtès1-7/+23
Fixes <http://bugs.gnu.org/16463>. Reported by Sree Harsha Totakura <sreeharsha@totakura.in>. * libguile/read.c (ENCODING_NAME_MAX_SIZE): New macro. (SCM_ENCODING_SEARCH_SIZE): Change to 500 + ENCODING_NAME_MAX_SIZE. (scm_i_scan_for_encoding): Return NULL if there's less than ENCODING_NAME_MAX_SIZE bytes once "coding: *" has been read. * test-suite/tests/coding.test ("line comment")["http://bugs.gnu.org/16463"]: New test.
2014-01-14Merge branch 'stable-2.0'Mark H Weaver1-6/+34
Conflicts: libguile/print.c libguile/read.c test-suite/tests/print.test
2014-01-14read: Support R7RS |...| symbol notation.Mark H Weaver1-6/+34
* libguile/private-options.h (SCM_R7RS_SYMBOLS_P): New macro. (SCM_N_READ_OPTIONS): Increment. * libguile/read.c (scm_read_opts): Add entry for 'r7rs-symbols'. (t_read_opts): Add field for 'r7rs_symbols_p'. (scm_read_string_like_syntax): New function based on earlier 'scm_read_string' that handles either string literals or R7RS quoted symbols (delimited by vertical bars), depending on the value of 'chr'. (scm_read_string): Reimplement based on 'scm_read_string_like_syntax'. (scm_read_r7rs_symbol): New static function. * doc/ref/api-data.texi (Symbol Read Syntax): Briefly describe the R7RS symbol syntax, mention the 'r7rs-symbols' read option, and give some examples. * doc/ref/api-evaluation.texi (Scheme Read): Mention the 'r7rs-symbols' read option. * test-suite/tests/reader.test ("reading"): Add test.
2014-01-14Merge branch 'stable-2.0'Mark H Weaver1-3/+46
Conflicts: libguile/chars.c libguile/read.c test-suite/tests/reader.test
2014-01-14read: use 'c_tolower' instead of 'tolower' in 'try_read_ci_chars'.Mark H Weaver1-1/+2
* libguile/read.c: Include <c-ctype.h>. (try_read_ci_chars): Use 'c_tolower' instead of 'tolower'.
2014-01-14read: Accept "\|" in string literals.Mark H Weaver1-0/+1
* libguile/read.c (scm_read_string): Accept "\|" in string literals. * doc/ref/api-data.texi (String Syntax): Add "\|" to the list of supported backslash escapes. * test-suite/tests/reader.test ("reading"): Add test.
2014-01-14read: Support R7RS '#true' and '#false' syntax for booleans.Mark H Weaver1-3/+44
* libguile/read.c (try_read_ci_chars): New static function. (scm_read_boolean, scm_read_array): Use 'try_read_ci_chars'. * doc/ref/api-data.texi (Booleans): Update docs. * test-suite/tests/reader.test ("reading"): Add tests.
2014-01-09Merge branch 'stable-2.0'Mark H Weaver1-0/+3
Conflicts: module/system/vm/traps.scm test-suite/tests/peval.test
2014-01-08read: Avoid signed integer overflow in 'read_decimal_integer'.Mark H Weaver1-0/+3
* libguile/read.c (read_decimal_integer): Avoid overflow.
2013-12-01Thread safe port properties.Mark H Weaver1-0/+6
* libguile/ports.c (scm_i_port_property, scm_i_set_port_property_x): Lock the port mutex while accessing the port alist. * libguile/read.c (set_port_read_option): Lock the port mutex while modifying port read options.
2013-11-28Merge commit 'a38024baaa32d1a6d91fdc81388c88bbb926c3ae'Andy Wingo1-13/+10
Conflicts: libguile/ports.h
2013-11-23Make port properties accessible from Scheme.Mark H Weaver1-13/+10
* libguile/ports.c (scm_i_port_alist, scm_i_set_port_alist_x): Removed. (scm_i_port_property, scm_i_set_port_property_x): New procedures, available from Scheme as '%port-property' and '%set-port-property!'. * libguile/ports.h (scm_i_port_alist, scm_i_set_port_alist_x): Removed. (scm_i_port_property, scm_i_set_port_property_x): New prototypes. * libguile/read.c (set_port_read_option, init_read_options): Adapt to use scm_i_port_property and scm_i_set_port_property_x.
2013-04-14Merge remote-tracking branch 'origin/stable-2.0'Mark H Weaver1-25/+17
Conflicts: GUILE-VERSION libguile/array-map.c libguile/fports.h libguile/gc.h libguile/inline.h libguile/ports.c libguile/ports.h libguile/print.c libguile/r6rs-ports.c libguile/read.c test-suite/tests/00-socket.test
2013-04-07Remove byte-order mark check from 'scm_i_scan_for_encoding'.Mark H Weaver1-10/+0
* libguile/read.c (scm_i_scan_for_encoding): Remove byte-order mark check.
2013-04-05Use 'c_strcasecmp' instead of 'strcasecmp'.Mark H Weaver1-1/+2
* libguile/ports.c (scm_new_port_table_entry, get_codepoint, scm_i_set_default_port_encoding, scm_i_port_iconv_descriptors, scm_i_set_port_encoding_x): * libguile/print.c (display_string_using_iconv): * libguile/read.c (scm_i_scan_for_encoding): Use 'c_strcasecmp'.
2013-04-03Use 'strcasecmp' to compare encoding names.Mark H Weaver1-1/+1
Reported by Ludovic Courtès <ludo@gnu.org>. * libguile/ports.c (scm_new_port_table_entry, scm_i_set_default_port_encoding, scm_i_set_port_encoding_x): libguile/read.c (scm_i_scan_for_encoding): Use 'strcasecmp' to compare encoding names.
2013-04-01Move the port alist from the hash table to the internal port structure.Mark H Weaver1-10/+6
* libguile/ports-internal.h (struct scm_port_internal): Add 'alist' member. * libguile/ports.c (scm_i_port_alist, scm_i_set_port_alist_x): New internal functions. (scm_i_port_weak_hash): Update comment: the hash table is no longer used to store the port's alist. (scm_new_port_table_entry): Initialize 'alist'. Store SCM_BOOL_F in the port weak hash, not SCM_EOL. * libguile/ports.h (scm_i_port_alist, scm_i_set_port_alist_x): Add protoypes. * libguile/read.c (set_port_read_option, init_read_options): Access the port's alist via 'scm_i_port_alist' and 'scm_i_set_port_alist_x'.
2013-01-30Revert "detect and consume byte-order marks for textual ports"Andy Wingo1-2/+12
This reverts commit b2cb557d75e4daf8c7c8cd43313f4cc51d9a3f1b, which was pushed accidentally.