summaryrefslogtreecommitdiff
path: root/libguile/strports.c
Commit message (Expand)AuthorAgeFilesLines
* String ports can be truncated...* libguile/strports.c (string_port_truncate): (scm_make_string_port_type): Support truncate-file on string ports. * test-suite/tests/ports.test ("string ports"): Add tests. Andy Wingo2017-03-011-0/+13
* Deprecate dynamic roots...* 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). Andy Wingo2016-11-211-1/+0
* Add SCM_OPN to mode bits when making ports...* libguile/ports.c (scm_c_make_port_with_encoding): Add SCM_OPN to mode bits, so that users don't have to. (scm_i_mode_bits_n): * libguile/print.c (scm_simple_format) * libguile/r6rs-ports.c (make_bytevector_input_port) (make_custom_binary_input_port, make_bytevector_output_port) (make_custom_binary_output_port, make_transcoded_port) * libguile/strports.c (scm_object_to_string, scm_open_input_string) (scm_open_output_string, scm_c_read_string): Remove now-unneeded SCM_OPN mentions. Andy Wingo2016-05-141-16/+7
* Use heap-allocated port types instead of ptobnums...This removes a limitation on the number of port types, simplifies the API, and removes a central point of coordination. * libguile/ports-internal.h (struct scm_t_port_type): Rename from scm_t_ptob_descriptor, now that it's private. Add GOOPS class fields. (struct scm_t_port): Rename from struct scm_port, especially considering that deprecated.h redefines scm_port using the preprocessor :(. * libguile/ports.h: Add definitions of SCM_PORT and SCM_PORT_TYPE, though the scm_t_port and scm_t_port_type types are incomplete. (SCM_TC2PTOBNUM, SCM_PTOBNUM, SCM_PTOBNAME): Remove, as there are no more typecodes for port types. (scm_c_num_port_types, scm_c_port_type_ref, scm_c_port_type_add_x): Remove. (scm_make_port_type): Return a scm_t_port_type*. All methods adapted to take a scm_t_port_type* instead of a ptobnum. (scm_c_make_port_with_encoding, scm_c_make_port): Take a port type pointer instead of a tag. (scm_new_port_table_entry): Remove; not useful. * libguile/ports.c: Remove things related to the port kind table. Adapt uses of SCM_PORT_DESCRIPTOR / scm_t_ptob_descriptor to use SCM_PORT_TYPE and scm_t_port_type. * libguile/deprecated.c: * libguile/deprecated.h: * libguile/filesys.c: * libguile/fports.c: * libguile/fports.h: * libguile/print.c: * libguile/r6rs-ports.c: * libguile/strports.c: * libguile/strports.h: * libguile/tags.h: * libguile/vports.c: * test-suite/standalone/test-scm-c-read.c: Adapt to change. * libguile/goops.c (scm_class_of, make_port_classes) (scm_make_port_classes, create_port_classes): Adapt to store the classes in the ptob. Andy Wingo2016-05-131-9/+9
* Port conversion strategies internally are symbols...* libguile/ports.h (scm_t_port): Represent the conversion strategy as a symbol, to make things easier for Scheme. Rename to "conversion_strategy". (scm_c_make_port_with_encoding): Change to take encoding and conversion_strategy arguments as symbols. (scm_i_string_failed_conversion_handler): New internal helper, to turn a symbol to a scm_t_string_failed_conversion_handler. (scm_i_default_port_encoding): Return the default port encoding as a symbol. (scm_i_default_port_conversion_strategy) (scm_i_set_default_port_conversion_strategy): Rename from scm_i_default_port_conversion_handler et al. Take and return Scheme symbols. * libguile/foreign.c (scm_string_to_pointer, scm_pointer_to_string): Use scm_i_default_string_failed_conversion_handler instead of scm_i_default_port_conversion_handler. * libguile/print.c (PORT_CONVERSION_HANDLER): Update definition. (print_normal_symbol): Use PORT_CONVERSION_HANDLER. * libguile/r6rs-ports.c (make_bytevector_input_port): (make_custom_binary_input_port, make_bytevector_output_port): Adapt to changes in scm_c_make_port_with_encoding. * libguile/strings.h: * libguile/strings.c (scm_i_default_string_failed_conversion_handler): New helper. (scm_from_locale_stringn, scm_from_port_stringn): (scm_to_locale_stringn, scm_to_port_stringn): Adapt to interface changes. * libguile/strports.c (scm_mkstrport): Adapt to scm_c_make_port_with_encoding change. * libguile/ports.c (scm_c_make_port): Adapt to scm_c_make_port_with_encoding change. (ascii_toupper, encoding_matches, canonicalize_encoding): Move down in the file. (peek_codepoint, get_codepoint, scm_ungetc): Adapt to port conversion strategy change. Remove duplicate case in get_codepoint. (scm_init_ports): Move symbol initializations to the same place. Andy Wingo2016-05-041-4/+6
* Port read/write functions take bytevectors...This will allow better Scheme integration for ports. * libguile/ports.h (scm_t_port_buffer): Change "holder" member to be a bytevector defined to have "buf" as its starting point. (scm_t_ptob_descriptor): Change read and write functions to take bytevectors as arguments and to return the number of octets read or written. (scm_make_port_type): Adapt accordingly. (scm_c_read_bytes, scm_c_write_bytes): New functions that take bytevectors. * libguile/ports.c (scm_make_port_type): Adapt to read/write function prototype change. (scm_c_make_port_buffer): Arrange to populate the "bytevector" field. (scm_i_read_bytes_unlocked): New function. (scm_i_read_unlocked): Use scm_i_read_bytes_unlocked. (scm_c_read_bytes_unlocked): New function. (scm_c_read_unlocked): Update comment, and always go through the buffer. (scm_c_read_bytes): New function. (scm_flush_unlocked): Use scm_i_write_unlocked instead of the port's write function. (scm_i_write_bytes_unlocked): New function. (scm_i_write_unlocked): Use scm_i_write_bytes_unlocked. (scm_c_write_bytes_unlocked): New function. (scm_c_write_unlocked): Always write through the buffer. (scm_c_write_bytes): New function. (scm_truncate_file): Remove unused variable. (void_port_read, void_port_write): Adapt to read/write prototype change. * libguile/fports.c (fport_read, fport_write): * libguile/r6rs-ports.c (bytevector_input_port_read) (custom_binary_input_port_read, bytevector_output_port_write) (custom_binary_output_port_write, transcoded_port_write) (transcoded_port_read): Adapt to read/write prototype change. (scm_get_bytevector_n, scm_get_bytevector_n_x) (scm_get_bytevector_all): Use scm_c_read_bytes. (scm_put_bytevector): Use scm_c_write_bytes. * libguile/strports.c (string_port_read, string_port_write): * libguile/vports.c (soft_port_write, soft_port_read): Adapt to read/write prototype change. * test-suite/standalone/test-scm-c-read.c (custom_port_read): Fix for read API change. Andy Wingo2016-04-111-14/+13
* Generic port facility provides buffering uniformly...* 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. Andy Wingo2016-04-061-187/+88
* Flush buffered reads / writes before seeking...* libguile/ports.c (scm_seek): Flush before seeking on a buffered port. * libguile/fports.c (fport_seek): * libguile/strports.c (st_seek): Remove code to flush buffers. * test-suite/tests/ports.test: Update test expectations that the putback buffer is flushed on a seek. Previously there was a special case for SEEK_CUR with an offset of 0 to avoid flushing buffers, but that's an arbitrary choice that differs from all other combinations of OFFSET and WHENCE. Andy Wingo2016-04-041-54/+34
* Refactor to rw_random / rw_active port flags...* 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. Andy Wingo2016-04-041-2/+0
* Merge branch 'stable-2.0'...Conflicts: GUILE-VERSION NEWS guile-readline/ice-9/readline.scm libguile/async.c libguile/backtrace.c libguile/deprecated.h libguile/gc-malloc.c libguile/gdbint.c libguile/init.c libguile/ioext.c libguile/mallocs.c libguile/print.c libguile/rw.c libguile/scmsigs.c libguile/script.c libguile/simpos.c libguile/snarf.h libguile/strports.c libguile/threads.c libguile/vm-i-scheme.c libguile/vm-i-system.c module/srfi/srfi-18.scm test-suite/Makefile.am test-suite/standalone/test-num2integral.c Mark H Weaver2014-04-251-3/+1
|\
| * Rely on Gnulib for <unistd.h>....* libguile/async.c: * libguile/backtrace.c: * libguile/error.c: * libguile/filesys.c: * libguile/fports.c: * libguile/gc-malloc.c: * libguile/gc.c: * libguile/gdbint.c: * libguile/init.c: * libguile/ioext.c: * libguile/load.c: * libguile/mallocs.c: * libguile/mkstemp.c: * libguile/ports.c: * libguile/posix.c: * libguile/r6rs-ports.c: * libguile/random.c: * libguile/rw.c: * libguile/scmsigs.c: * libguile/script.c: * libguile/simpos.c: * libguile/socket.c: * libguile/stime.c: * libguile/strports.c: * libguile/threads.c: Unconditionally include <unistd.h>. Mark H Weaver2014-02-271-3/+1
* | Merge commit '60617d819d77a1b92ed6c557a0b49b8e9a8e97b9'...Conflicts: libguile/continuations.c libguile/eval.c libguile/goops.c libguile/instructions.c Andy Wingo2014-02-071-11/+14
|\|
| * Fix thread-unsafe lazy initializations....* libguile/backtrace.c (print_exception_var): New static variable. (init_print_exception_var): New static function. (scm_print_exception): Remove thread-unsafe lazy initialization. Call 'init_print_exception_var' using 'scm_i_pthread_once'. Use 'print_exception_var'. * libguile/continuations.c (call_cc): New static variable. (init_call_cc): New static function. (scm_i_call_with_current_continuation): Remove thread-unsafe lazy initialization. Call 'init_call_cc' using 'scm_i_pthread_once'. * libguile/debug.c (local_eval_var): New static variable. (init_local_eval_var): New static function. (scm_local_eval): Remove lazy initialization using mutexes. Call 'init_local_eval_var' using 'scm_i_pthread_once'. Use 'scm_variable_ref' instead of 'SCM_VARIABLE_REF'. * libguile/eval.c (map_var, for_each_var): New static variables. (init_map_var, init_for_each_var): New static functions. (scm_map, scm_for_each): Remove thread-unsafe lazy initializations. Call 'init_map_var' (or 'init_for_each_var') using 'scm_i_pthread_once'. Use 'map_var' (or 'for_each_var'). * libguile/frames.c (frame_arguments_var): New static variable. (init_frame_arguments_var): New static function. (scm_frame_arguments): Remove thread-unsafe lazy initialization. Call 'init_frame_arguments_var' using 'scm_i_pthread_once'. Use 'frame_arguments_var'. Use 'scm_variable_ref' instead of 'SCM_VARIABLE_REF'. * libguile/goops.c (delayed_compile_var): New static variable. (init_delayed_compile_var): New static function. (make_dispatch_procedure): Remove thread-unsafe lazy initialization. Call 'init_delayed_compile_var' using 'scm_i_pthread_once'. Use 'delayed_compile_var'. Use 'scm_variable_ref' instead of 'SCM_VARIABLE_REF'. * libguile/instructions.c (instructions_by_name): New static variable. (init_instructions_by_name): New static function. (scm_lookup_instruction_by_name): Remove thread-unsafe lazy initialization. Call 'init_instructions_by_name' using 'scm_i_pthread_once'. * libguile/ports.c (current_warning_port_var) (current_warning_port_once): New static variables. (init_current_warning_port_var): New static function. (scm_current_warning_port): Remove lazy initialization using mutexes. Call 'init_current_warning_port_var' using 'scm_i_pthread_once'. Use 'current_warning_port_var'. (scm_set_current_warning_port): Remove thread-unsafe lazy initialization. Call 'init_current_warning_port_var' using 'scm_i_pthread_once'. Use 'current_warning_port_var'. * libguile/strings.c (null_stringbuf): New static variable. (init_null_stringbuf): New static function. (scm_i_make_string): Remove thread-unsafe lazy initialization. Call 'init_null_stringbuf' using 'scm_i_pthread_once'. * libguile/strports.c (eval_string_var, k_module): New static variables. (init_eval_string_var_and_k_module): New static function. (scm_eval_string_in_module): Remove lazy initialization using mutexes. Call 'init_eval_string_var_and_k_module' using 'scm_i_pthread_once'. Use 'eval_string_var'. * libguile/throw.c (CACHE_VAR): Remove incorrect macro. (catch_var, throw_var, with_throw_handler_var): New static variables. (scm_catch, scm_catch_with_pre_unwind_handler): Remove thread-unsafe lazy initialization. Use 'catch_var'. (init_with_throw_handler_var): New static function. (scm_with_throw_handler): Remove thread-unsafe lazy initialization. Call 'init_with_throw_handler_var' using 'scm_i_pthread_once'. Use 'with_throw_handler_var'. (scm_throw): Remove thread-unsafe lazy initialization. Use 'throw_var'. (scm_init_throw): Initialize 'catch_var' and 'throw_var'. Mark H Weaver2014-01-231-11/+14
* | Fix --without-threads and SCM_DEBUG_TYPING_STRICTNESS==2 builds....* libguile/hashtab.c (scm_hashv_ref, scm_hashv_set_x, scm_hashv_remove_x, scm_hash_ref, scm_hash_set_x, scm_hash_remove_x): * libguile/strports.c (scm_mkstrport): * libguile/weak-vector.c (weak_vector_ref): Add missing SCM_UNPACK. * libguile/ports.c (lock_port, unlock_port): Cast MUTEX to the expected type. Mark H Weaver2013-08-081-1/+1
* | String ports use UTF-8; ignore %default-port-encoding....* libguile/strports.c (scm_mkstrport): Use UTF-8; ignore %default-port-encoding. Rename 'str_len' and 'c_pos' to 'num_bytes' and 'c_byte_pos'. Interpret 'pos' argument as a character index instead of a byte index. * module/ice-9/boot-9.scm (%cond-expand-features): Add srfi-6 to the list of core features. * module/srfi/srfi-6.scm (open-input-string, open-output-string): Simply re-export these, since the core versions are now compliant. * doc/ref/api-io.texi (String Ports): Remove text that describes non-compliant behavior of string ports with regard to encoding. * doc/ref/srfi-modules.texi (SRFI-0): Add srfi-6 to the list of core features. (SRFI-6): Remove text that mentions non-compliant behavior of core string ports. * module/ice-9/format.scm (format): * module/ice-9/pretty-print.scm (truncated-print): * module/rnrs/io/ports.scm (open-string-input-port, open-string-output-port): * test-suite/test-suite/lib.scm (format-test-name): * test-suite/tests/chars.test ("combining accent is pretty-printed", "combining X is pretty-printed"): * test-suite/tests/ecmascript.test (eread, eread/1): * test-suite/tests/rdelim.test: * test-suite/tests/reader.test (read-string): * test-suite/tests/regexp.test: * test-suite/tests/srfi-105.test (read-string): Don't set %default-port-encoding before creating string ports. * benchmark-suite/benchmarks/ports.bm (%latin1-port): Use 'set-port-encoding!' to set the string port encoding. (%utf8/ascii-port, %utf8/wide-port, "rdelim"): Don't set %default-port-encoding before creating string ports. * test-suite/tests/r6rs-ports.test ("lookahead-u8 non-ASCII"): Don't set %default-port-encoding before creating string ports. ("put-bytevector with UTF-16 string port", "put-bytevector with wrong-encoding string port"): Use 'set-port-encoding!' to set the string port encoding. * test-suite/tests/print.test (tprint): Use 'set-port-encoding!' to set the string port encoding. ("truncated-print"): Use 'pass-if-equal'. * test-suite/tests/ports.test ("encoding failure leads to exception", "%default-port-encoding is honored", "peek-char [latin-1]", "peek-char [utf-8]", "peek-char [utf-16]"): Remove tests. ("%default-port-encoding is ignored", "peek-char"): Add tests. ("suitable encoding [latin-1]", "suitable encoding [latin-3]", "wrong encoding, error", "wrong encoding, substitute", "wrong encoding, escape"): Use 'set-port-encoding!' to set the string port encoding. ("%default-port-encoding, wrong encoding"): Rewrite to use a file port instead of a string port. Mark H Weaver2013-08-071-18/+21
* | Merge remote-tracking branch 'origin/stable-2.0'...Conflicts: configure.ac libguile/deprecated.c libguile/deprecated.h libguile/filesys.h libguile/fluids.c libguile/fports.c libguile/gc.c libguile/guile.c libguile/numbers.c libguile/objcodes.c libguile/r6rs-ports.c libguile/smob.c libguile/socket.c libguile/threads.h module/language/scheme/decompile-tree-il.scm module/language/tree-il/peval.scm test-suite/tests/syncase.test Mark H Weaver2013-03-281-3/+6
|\|
| * Fix thread-unsafe lazy initializations....* libguile/debug.c (scm_local_eval): libguile/ports.c (scm_current_warning_port): libguile/strports.c (scm_eval_string_in_module): Perform lazy-initialization while holding a mutex. Use SCM_UNDEFINED as the uninitialized value. Use 'scm_c_*_variable'. * doc/ref/api-modules.texi (Accessing Modules from C): Fix 'my_eval_string' example to be thread-safe. Mark H Weaver2013-03-051-3/+6
* | add scm_from_port_string and friends...* doc/ref/api-data.texi (Conversion to/from C): * libguile/strings.h: * libguile/strings.c (scm_from_port_string, scm_from_port_stringn): (scm_to_port_string, scm_to_port_stringn): New functions. * guile-readline/readline.c (internal_readline): * libguile/strports.c (scm_strport_to_string): * libguile/read.c (scm_read_number, scm_read_mixed_case_symbol): (scm_read_number_and_radix, scm_read_character): Use the new functions. Andy Wingo2013-01-151-3/+2
* | Merge remote-tracking branch 'origin/stable-2.0'...Conflicts: libguile/deprecated.c libguile/ports.c libguile/ports.h libguile/strports.c test-suite/tests/cse.test Andy Wingo2012-06-221-3/+5
|\|
| * Fix possible deadlock upon `encoding-error' in `open-input-string'....Partly addresses <http://bugs.gnu.org/11197>. * libguile/strports.c (scm_mkstrport): Call `scm_port_non_buffer', set Z's cell type and stream, and release `scm_i_port_table_mutex' early. Reacquire `scm_i_port_table_mutex' once BUF, C_BUF, and STR_LEN are initialized. * test-suite/tests/ports.test ("string ports")["encoding failure leads to exception"]: New test. Ludovic Courtès2012-06-201-7/+23
| * Have string ports honor `%default-port-conversion-strategy'....* libguile/strports.c (scm_mkstrport): Remove initialization of `pt->ilseq_handler'. * module/ice-9/pretty-print.scm (truncated-print)[ellipsis]: Set %DEFAULT-PORT-CONVERSION-STRATEGY to 'error. * test-suite/tests/ports.test ("string ports")["%default-port-conversion-strategy is honored"]: New test. ["wrong encoding"]: Rename to... ["wrong encoding, error"]: ... this. Explicitly set %DEFAULT-PORT-CONVERSION-STRATEGY to 'error. Return #f when no exception is raised. Ludovic Courtès2012-05-311-1/+0
| * Access `pt->ilseq_handler' directly when needed....* libguile/print.c (PORT_CONVERSION_HANDLER): New macro. (print_extended_symbol, iprin1, write_character, scm_write_char): Use it instead of `scm_i_get_conversion_strategy'. * libguile/strports.c (scm_mkstrport): Assign `pt->ilseq_handler' directly instead of via `scm_i_set_conversion_strategy_x'. Ludovic Courtès2012-05-311-3/+4
* | call-with-{input,output}-string implemented in scheme...* module/ice-9/boot-9.scm (call-with-input-string) (call-with-output-string): Implement in Scheme. * libguile/strports.c (scm_call_with_output_string): (scm_call_with_input_string): Dispatch to Scheme. Andy Wingo2012-03-071-22/+14
* | string ports simplification...* libguile/strports.c (st_fill_input): Rename from stfill_buffer, and remove an unneeded scm_return_first_int. (st_resize_port): Minor variable renaming. (st_write): Keep read_pos updated to be the same as write_pos. If we need to resize, do so only once. (st_seek): No more need to flush. (st_truncate): Update read_pos here too. (scm_mkstrport): No need to flush here. (scm_strport_to_string): Just call scm_from_stringn; rely on it to detect the latin1 case. (scm_make_stptob): No more flush function. Andy Wingo2012-02-141-65/+20
* | locking on port buffering operations...* libguile/ports.c (scm_fill_input_unlocked, scm_fill_input) (scm_end_input, scm_end_input_unlocked, scm_flush) (scm_flush_unlocked): Add locking and _unlocked variants. * libguile/filesys.c: * libguile/fports.c: * libguile/gdbint.c: * libguile/r6rs-ports.c: * libguile/read.c: * libguile/rw.c: Adapt callers to use _unlocked variants. Andy Wingo2011-11-081-1/+1
* | add scm_c_make_port; the port table is now a weak set...* libguile/ports.c (scm_c_make_port_with_encoding, scm_c_make_port): New functions, to replace scm_new_port_table_entry. Use a weak set instead of a weak table. (scm_i_remove_port): (scm_c_port_for_each, scm_port_for_each): Adapt to use weak set. (scm_i_void_port): Use scm_c_make_port. (scm_init_ports): Make a weak set. * libguile/fports.c: * libguile/ioext.c: * libguile/r6rs-ports.c: * libguile/strports.c: * libguile/vports.c: Adapt to use the new scm_c_make_port API. Andy Wingo2011-10-231-17/+14
|/
* Make VM string literals immutable....* libguile/strings.c (scm_i_make_string, scm_i_make_wide_string): Add `read_only_p' parameter. All callers updated. * libguile/vm-i-loader.c (load_string, load_wide_string): Push read-only strings. * test-suite/tests/strings.test ("literals"): New test prefix. Ludovic Courtès2011-03-201-1/+1
* core eval-string uses (ice-9 eval-string)...* libguile/strports.c (scm_eval_string_in_module): Use eval-string from (ice-9 eval-string). Andy Wingo2011-03-081-23/+10
* Make `object->string' explicitly close its string output port....* libguile/strports.c (scm_object_to_string): Close PORT before returning the resulting string. Ludovic Courtès2011-03-061-2/+12
* Simply grow string port buffers geometrically....* libguile/strports.c (SCM_WRITE_BLOCK): Remove. (st_flush): Multiply `pt->write_buf_size' by 2. (st_seek): Likewise when TARGET == PT->write_buf_size. Ludovic Courtès2011-03-061-21/+7
* Let `scm_mkstrport' allocate buffers on the caller's behalf....* libguile/strports.c (INITIAL_BUFFER_SIZE): New macro. (scm_mkstrport): If STR is false, allocate a bytevector on the caller's behalf. (scm_object_to_string, scm_call_with_output_string, scm_open_output_string): Pass SCM_BOOL_F as the STR argument of `scm_mkstrport'. * libguile/backtrace.c (scm_display_application, display_backtrace_body): Likewise. * libguile/gdbint.c (scm_init_gdbint): Likewise. * libguile/print.c (scm_simple_format): Likewise. Ludovic Courtès2011-03-061-23/+38
* Use a bytevector as the backing buffer of string ports....* libguile/strports.c (st_resize_port): Adjust to deal with OLD_STREAM and NEW_STREAM as bytevectors. (scm_mkstrport): Store a bytevector in the port's stream rather than a string. Ludovic Courtès2011-03-061-35/+35
* remove obsolete comments...* libguile/eval.c (scm_nconc2last): * libguile/strports.c (scm_c_read_string): Remove some obsolete comments. Andy Wingo2011-03-051-1/+0
* pointerless backing buffers for string ports...* libguile/strports.c (scm_mkstrport): String port string buffer allocated atomically. Andy Wingo2011-02-241-2/+2
* Have string ports honor `%default-port-encoding'....* libguile/strports.c (scm_i_mkstrport): Remove. (scm_mkstrport): Don't change the port's encoding to UTF-8; convert STR to the default port encoding. (scm_strport_to_string): Fix documentation & indentation. * libguile/strports.h (scm_i_mkstrport): Remove. * test-suite/lib.scm (exception:encoding-error): New variable. (format-test-name): Set `%default-port-encoding' to "UTF-8". * test-suite/tests/ports.test ("string ports")["%default-port-encoding is honored", "suitable encoding [latin-1]", "suitable encoding [latin-3]", "wrong encoding"]: New tests. * test-suite/tests/r6rs-ports.test ("7.2.11 Binary Output")["put-bytevector with UTF-16 string port", "put-bytevector with wrong-encoding string port"]: New tests. * test-suite/tests/reader.test (read-string): Set `%default-port-encoding' to `#f'. ("reading")["unprintable symbol"]: Use a string that doesn't contain zeros. * doc/ref/api-io.texi (String Ports): Document encoding issues with `call-with-output-string' and `with-output-to-string'. Ludovic Courtès2010-01-071-54/+30
* Remove unneeded SMOB/port mark/free procedures....* libguile/arrays.c (array_mark, array_free): Remove. (scm_init_arrays): Adjust accordingly. * libguile/bitvectors.c (bitvector_free): Remove. (scm_c_make_bitvector): Use `scm_gc_malloc_pointerless ()'. (scm_init_bitvectors): Adjust accordingly. * libguile/strports.c (scm_make_stptob): Remove `scm_set_port_mark ()' call. * libguile/vports.c (scm_make_sfptob): Likewise. Ludovic Courtès2009-09-281-1/+0
* Make scm_i_from_stringn into API for use with libguilereadline...* libguile/strings.c (scm_i_from_stringn): renamed to scm_from_stringn. All callers changed. * libguile/strings.h: change declaration of scm_i_from_stringn to scm_from_stringn * libguile/strports.c (scm_strport_to_string): scm_i_from_stringn -> scm_from_stringn * guile-readline/readline.c (internal_readline): scm_i_from_stringn -> scm_from_stringn Michael Gran2009-09-091-2/+2
* Remove locale u8vector functions...Locale u8vector functions deemed harmful. * libguile/strports.c (scm_strport_to_locale_u8vector) (scm_call_with_output_locale_u8vector, scm_open_input_locale_u8vector) (scm_get_output_locale_u8vector): removed * libguile/strports.h: removed declarations for scm_strport_to_locale_u8vector, scm_call_with_output_u8vector, scm_input_locale_u8vector, scm_get_output_locale_u8vector * test-suite/tests/encoding-iso88591.test: display tests removed * test-suite/tests/encoding-iso88597.test: display tests removed Michael Gran2009-09-041-71/+0
* Initialize string ports with UTF-8 encoding...String ports should be able to accept any string characters, regardless of the current locale. Setting it to UTF-8 achieves that. * libguile/strports.c (scm_i_mkstrport): set port's locale to UTF-8 (scm_mkstrport): convert input string to UTF-8 Michael Gran2009-09-041-6/+8
* Fix encoding errors with strings returned by string ports...String ports, being 8-bit, store strings using the character encoding of the port. This fixes a bug where the default character encoding, and not the port's encoding, was being used to convert the string port data back to a string. * libguile/strports.c: extra comments (scm_strport_to_string): use port's encoding when converting port data to a string * libguile/strings.c (scm_i_from_stringn): renamed from scm_from_stringn and made internal. All callers changed. (scm_from_stringn): renamed to scm_i_from_stringn. * libguile/strings.h: declaration for scm_i_from_stringn Michael Gran2009-08-301-5/+21
* Merge commit 'origin/master'...Conflicts: libguile/unif.c Andy Wingo2009-08-251-26/+111
|\
| * Add full Unicode capability to ports and the default reader...Ports are given two additional properties: a character encoding and a conversion failure strategy. These properties have getters and setters. The new properties are used to convert any locale text to/from the internal representation of strings. If unspecified, ports use a default value. The default value of these properties is held in a fluid. The default character encoding can be modified by calling setlocale. ISO-8859-1 is treated specially. Since it is a native encoding of strings, it can be processed more quickly. Source code is assumed to be ISO-8859-1 unless otherwise specified. The encoding of a source code file can be given as 'coding: XXXXX' in a magic comment at the top of a file. The C functions that deal with encoding often use a null pointer as shorthand for the native Latin-1 encoding, for efficiency's sake. * test-suite/tests/encoding-iso88591.test: new tests * test-suite/tests/encoding-iso88597.test: new tests * test-suite/tests/encoding-utf8.test: new tests * test-suite/tests/encoding-escapes.test: new tests * test-suite/tests/numbers.test: declare 'binary' encoding * test-suite/tests/ports.test: declare 'binary' encoding * test-suite/tests/r6rs-ports.test: declare 'binary' encoding * module/system/base/compile.scm (compile-file): use source-code file's self-declared encoding when compiling files * libguile/strports.c: store string ports in locale encoding (scm_strport_to_locale_u8vector, scm_call_with_output_locale_u8vector) (scm_open_input_locale_u8vector, scm_get_output_locale_u8vector): new functions * libguile/strings.h: new declaration for scm_i_string_contains_char * libguile/strings.c (scm_i_string_contains_char): new function (scm_from_stringn, scm_to_stringn): use NULL for Latin-1 (scm_from_locale_stringn, scm_to_locale_stringn): respect character encoding of input and output ports * libguile/read.h: declaration for scm_scan_for_encoding * libguile/read.c: (read_token): now takes scheme string instead of C string/length (read_complete_token): new function (scm_read_sexp, scm_read_number, scm_read_mixed_case_symbol) (scm_read_number_and_radix, scm_read_quote, scm_read_semicolon_comment) (scm_read_srfi4_vector, scm_read_bytevector, scm_read_guile_bit_vector) (scm_read_scsh_block_comment, scm_read_commented_expression) (scm_read_extended_symbol, scm_read_sharp_extension, scm_read_shart) (scm_read_expression): use scm_t_wchar for char type, use read_complete_token (scm_scan_for_encoding): new function to find a file's character encoding (scm_file_encoding): new function to find a port's character encoding * libguile/rdelim.c: don't unpack strings * libguile/print.h: declaration for modified function scm_i_charprint * libguile/print.c: use locale when printing characters and strings (scm_i_charprint): input parameter is now scm_t_wchar (scm_simple_format): don't unpack strings * libguile/posix.h: new declaration for scm_setbinary. * libguile/posix.c (scm_setlocale): set default and stdio port encodings based on the locale's character encoding (scm_setbinary): new function * libguile/ports.h (scm_t_port): add encoding and failed conversion handler to port type. Declarations for new or modified functions scm_getc, scm_unget_byte, scm_ungetc, scm_i_get_port_encoding, scm_i_set_port_encoding_x, scm_port_encoding, scm_set_port_encoding_x, scm_i_get_conversion_strategy, scm_i_set_conversion_strategy_x, scm_port_conversion_strategy, scm_set_port_conversion_strategy_x. * libguile/ports.c: assign the current ports to zero on startup so we can see if they've been set. (scm_current_input_port, scm_current_output_port, scm_current_error_port): return #f if the port is not yet initialized (scm_new_port_table_entry): set up a new port's encoding and illegal sequence handler based on the thread's current defaults (scm_i_remove_port): free port encoding name when port is removed (scm_i_mode_bits_n): now takes a scheme string instead of a c string and length. All callers changed. (SCM_MBCHAR_BUF_SIZE): new const (scm_getc): new function, since the scm_getc in inline.h is now scm_get_byte_or_eof. This pulls one codepoint from a port. (scm_lfwrite_substr, scm_lfwrite_str): now uses port's encoding (scm_unget_byte): new function, incorportaing the low-level functionality of scm_ungetc (scm_ungetc): uses scm_unget_byte * libguile/numbers.h (scm_t_wchar): compilation order problem with scm_t_wchar being use in functions in multiple headers. Forward declare scm_t_wchar. * libguile/load.c (scm_primitive_load): scan for file encoding at top of file and use it to set the load port's encoding * libguile/inline.h (scm_get_byte_or_eof): new function incorporating most of the functionality of scm_getc. * libguile/fports.c (fport_fill_input): now returns scm_t_wchar * libguile/chars.h (scm_t_wchar): avoid compilation order problem with declaration of scm_t_wchar Michael Gran2009-08-251-26/+111
* | rename unif.[ch] to arrays.[ch]...* libguile/Makefile.am: * libguile/unif.c: * libguile/unif.h: * libguile/arrays.c: * libguile/arrays.h: Rename unif.[ch] to arrays.[ch]. * libguile.h: * libguile/array-handle.c: * libguile/array-map.c: * libguile/bitvectors.c: * libguile/bytevectors.c: * libguile/eq.c: * libguile/gc-card.c: * libguile/gc-malloc.c: * libguile/gc-mark.c: * libguile/gc.c: * libguile/init.c: * libguile/inline.h: * libguile/print.c: * libguile/random.c: * libguile/read.c: * libguile/socket.c: * libguile/sort.c: * libguile/srfi-4.c: * libguile/srfi-4.h: * libguile/strports.c: * libguile/vectors.c: * libguile/vectors.h: Update includers. Andy Wingo2009-07-191-1/+1
|/
* Add `scm_t_off' type so that `scm_t_port' has a fixed layout....* libguile/gen-scmconfig.c (main): Produce a definition for `scm_t_off'. * libguile/ports.h (scm_t_port)[read_buf_size, saved_read_buf_size, write_buf_size, seek, truncate]: Use `scm_t_off' instead of `off_t' so that the layout and size of the structure does not depend on the application's `_FILE_OFFSET_BITS' value. Reported by Bill Schottstaedt, see http://lists.gnu.org/archive/html/bug-guile/2009-06/msg00018.html. (scm_set_port_seek, scm_set_port_truncate): Update. * libguile/ports.c (scm_set_port_seek, scm_set_port_truncate): Use `scm_t_off' and `off_t_or_off64_t'. * libguile/fports.c (fport_seek, fport_truncate): Use `scm_t_off' instead of `off_t'. * libguile/r6rs-ports.c (bip_seek, cbp_seek, bop_seek): Use `scm_t_off' instead of `off_t'. * libguile/rw.c (scm_write_string_partial): Likewise. * libguile/strports.c (st_resize_port, st_seek, st_truncate): Likewise. * doc/ref/api-io.texi (Port Implementation): Update prototype of `scm_set_port_seek ()' and `scm_set_port_truncate ()'. * NEWS: Update. Ludovic Courtès2009-06-251-7/+7
* Change Guile license to LGPLv3+...(Not quite finished, the following will be done tomorrow. module/srfi/*.scm module/rnrs/*.scm module/scripts/*.scm testsuite/*.scm guile-readline/* ) Neil Jerram2009-06-171-6/+7
* Include <config.h> in all C files; use `#ifdef HAVE_CONFIG_H' rather than `#if'.Ludovic Courtès2008-09-131-1/+1
* merge from 1.8 branchKevin Ryde2006-04-171-1/+1
* (st_flush): Increase buffer by 1.5x when growing, to...avoid lots of copying where previoulsy growing by only 80 bytes at a time. Kevin Ryde2005-08-021-4/+34
* The FSF has a new address.Marius Vollmer2005-05-231-1/+1
* * unif.c (scm_i_read_array): Declare rank as ssize_t, to guarantee...that it is signed. * strports.c (st_resize_port): Add unsigned char cast. (scm_mkstrport): Make read/write_buf cast unsigned. * srfi-13.c (string_titlecase_x): Add unsigned char cast. * rdelim.c (scm_read_line): Initialize slen. * load.c (scm_search_path): Remove weird >=1, and add parentheses to clarify conditions. * hash.c (scm_hasher): Add const unsigned char cast. * gh_data.c (gh_chars2byvect): Add scm_t_int8 cast. Neil Jerram2005-05-121-2/+2