summaryrefslogtreecommitdiff
path: root/libguile
AgeCommit message (Collapse)AuthorFilesLines
2013-04-07Change `sendfile' to loop until everything has been sent.Ludovic Courtès1-13/+34
* libguile/filesys.c (scm_sendfile)[HAVE_SYS_SENDFILE_H && HAVE_SENDFILE]: Compare RESULT with C_COUNT. Loop until C_COUNT bytes have been sent. * doc/ref/posix.texi (File System): Update the description. Explain the new semantics. * test-suite/tests/filesys.test ("sendfile"): Rewrite using `pass-if-equal'. Check the return value for all the tests. ["file with offset past the end", "file with offset near the end"]: New tests.
2013-04-07Add keyword arguments to file opening procedures.Mark H Weaver3-54/+141
* libguile/fports.c (scm_open_file_with_encoding): New API function, containing the code previously found in 'scm_open_file', but modified to accept the new 'guess_encoding' and 'encoding' arguments. (scm_open_file): Now just a simple wrapper that calls 'scm_open_file_with_encoding'. (scm_i_open_file): New implementation of 'open-file' that accepts keyword arguments '#:guess-encoding' and '#:encoding', and calls 'scm_open_file_with_encoding'. (scm_init_fports_keywords): New initialization function that gets called after keywords are initialized. * libguile/fports.h (scm_open_file_with_encoding, scm_init_fports_keywords): Add prototypes. * libguile/init.c (scm_i_init_guile): Call 'scm_init_fports_keywords'. * module/ice-9/boot-9.scm: Add enhanced versions of 'open-input-file', 'open-output-file', 'call-with-input-file', 'call-with-output-file', 'with-input-from-file', 'with-output-to-file', and 'with-error-to-file', that accept keyword arguments '#:binary', '#:encoding', and (for input port constructors) '#:guess-encoding'. * doc/ref/api-io.texi (File Ports): Update documentation. * test-suite/tests/ports.test ("keyword arguments for file openers"): Add tests.
2013-04-07Implement efficient 'scm_unget_bytes' and 'unget-bytevector'.Mark H Weaver4-54/+123
* libguile/ports.c (scm_i_unget_bytes): New static function. (scm_unget_bytes): New API function. (scm_unget_byte): Rewrite to simply call 'scm_i_unget_bytes'. (scm_ungetc, scm_peek_char, looking_at_bytes): Use 'scm_i_unget_bytes'. * libguile/ports.h: Add prototype for 'scm_unget_bytes'. * libguile/fports.c (scm_setvbuf): Use 'scm_unget_bytes'. * libguile/r6rs-ports.c (scm_unget_bytevector): New procedure. * module/ice-9/binary-ports.scm (unget-bytevector): New export. * doc/ref/api-io.texi (R6RS Binary Input): Add documentation. (R6RS I/O Ports): Update brief description of (ice-9 binary-ports) to reflect the new reality: it is no longer a subset of (rnrs io ports). * test-suite/tests/ports.test ("unget-bytevector"): Add 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-07Do not scan for coding declarations in open-file.Mark H Weaver1-23/+5
* libguile/fports.c (scm_open_file): Do not scan for coding declarations. Replace 'use_encoding' local variable with 'binary'. Update documentation string. * module/ice-9/psyntax.scm (include): Add the same file-encoding logic that's used in compile-file and scm_primitive_load. * module/ice-9/psyntax-pp.scm: Regenerate. * doc/ref/api-io.texi (File Ports): Update docs. * test-suite/tests/ports.test: Change "open-file HONORS file coding declarations" test to "open-file IGNORES file coding declaration". * test-suite/tests/coding.test (scan-coding): Use 'file-encoding' to scan for the encoding, since 'open-input-file' no longer does so.
2013-04-07Don't use scm_generalized_vector_get_handle() in array-map.cDaniel Llorens1-6/+6
* libguile/array-map.c: (rafill, racp, ramap, rafe): use scm_array_get_handle() instead of scm_generalized_get_vector_handle(). Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2013-04-06Implement 'scm_c_bind_keyword_arguments'.Mark H Weaver2-0/+79
* libguile/keywords.c (scm_keyword_argument_error): New variable. (scm_c_bind_keyword_arguments): New API function. * libguile/keywords.h (enum scm_keyword_arguments_flags): New enum. (scm_t_keyword_arguments_flags): New typedef. (scm_c_bind_keyword_arguments): New prototype. * doc/ref/api-data.texi (Coding With Keywords, Keyword Procedures): Add documentation. * test-suite/standalone/test-scm-c-bind-keyword-arguments.c: New file. * test-suite/standalone/Makefile.am: Add test-scm-c-bind-keyword-arguments test.
2013-04-05Deprecate scm_array_fill_int()Daniel Llorens2-22/+21
* libguile/array-map.h, libgule/array-map.c: move scm_array_fill_int to the deprecated section. Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2013-04-05Remove double indirection in array-fill!Daniel Llorens1-2/+19
* libguile/array-map.c: new function rafill, like scm_array_fill_int, but factors GVSET out of the loop. Use it in scm_array_fill_x instead of scm_array_fill_int. * test-suite/tests/arrays.test: add test for array-fill! with stride != 1. Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2013-04-05Use 'c_strcasecmp' instead of 'strcasecmp'.Mark H Weaver3-12/+15
* 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-04Improve handling of Unicode byte-order marks (BOMs).Mark H Weaver3-28/+152
* libguile/ports-internal.h (struct scm_port_internal): Add new members 'at_stream_start_for_bom_read' and 'at_stream_start_for_bom_write'. (SCM_UNICODE_BOM): New macro. (scm_i_port_iconv_descriptors): Add 'mode' parameter to prototype. * libguile/ports.c (scm_new_port_table_entry): Initialize 'at_stream_start_for_bom_read' and 'at_stream_start_for_bom_write'. (get_iconv_codepoint): Pass new 'mode' parameter to 'scm_i_port_iconv_descriptors'. (get_codepoint): After reading a codepoint at stream start, record that we're no longer at stream start, and consume a BOM where appropriate. (scm_seek): Set the stream start flags according to the new position. (looking_at_bytes): New static function. (scm_utf8_bom, scm_utf16be_bom, scm_utf16le_bom, scm_utf32be_bom, scm_utf32le_bom): New static const arrays. (decide_utf16_encoding, decide_utf32_encoding): New static functions. (scm_i_port_iconv_descriptors): Add new 'mode' parameter. If the specified encoding is UTF-16 or UTF-32, make that precise by deciding what byte order to use, and construct iconv descriptors based on the precise encoding. (scm_i_set_port_encoding_x): Record that we are now at stream start. Do not open the new iconv descriptors immediately; let them be initialized lazily. * libguile/print.c (display_string_using_iconv): Record that we're no longer at stream start. Write a BOM if appropriate. * doc/ref/api-io.texi (BOM Handling): New node. * test-suite/tests/ports.test ("set-port-encoding!, wrong encoding"): Adapt test to cope with the fact that 'set-port-encoding!' does not immediately open the iconv descriptors. (bv-read-test): New procedure. ("unicode byte-order marks (BOMs)"): New test prefix.
2013-04-04Peeks do not consume EOFs.Mark H Weaver2-7/+44
Fixes <http://bugs.gnu.org/12216>. * libguile/ports-internal.h (struct scm_port_internal): Add 'pending_eof' flag. * libguile/ports.c (scm_i_set_pending_eof, scm_i_clear_pending_eof): New static functions. (scm_new_port_table_entry): Initialize 'pending_eof'. (scm_i_fill_input): Check for 'pending_eof'. (scm_i_peek_byte_or_eof): Set 'pending_eof' flag before returning EOF. (scm_end_input, scm_unget_byte, scm_seek, scm_truncate): Clear 'pending_eof'. (scm_peek_char): Set 'pending_eof' flag before returning EOF. * test-suite/tests/ports.test ("pending EOF behavior"): Add tests.
2013-04-03Preserve the case of the user-specified port encoding string.Mark H Weaver1-2/+1
* libguile/ports.c (scm_i_set_port_encoding_x): Always copy the user-provided port encoding string, so that its case will be preserved and returned exactly by subsequent calls to 'port-encoding'.
2013-04-03Remove double indirection for 1st arg of array-for-eachDaniel Llorens1-23/+22
* libguile/array-map.c: (rafe): factor GVREF out of rank-1 loop for ra0.
2013-04-03Remove double indirection in array-map! with <2 argsDaniel Llorens1-12/+20
* libguile/array-map.c: (ramap): factor GVSET/GVREF out of rank-1 loop for ra0 and the first element of ras.
2013-04-03Avoid per-element cons for 1-arg case of array-map!Daniel Llorens1-19/+26
* libguile/array-map.c: (ramap): special case when ras is a 1-element list.
2013-04-03Deprecate dead code in array-map.cDaniel Llorens2-13/+19
* libguile/array-map.c, libguile/array-map.h: deprecate scm_ra_eqp, scm_ra_lessp, scm_ra_leqp, scm_ra_grp, scm_ra_greqp, scm_ra_sum, scm_ra_product, scm_ra_difference, scm_ra_divide, scm_array_identity. Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2013-04-03Use 'strcasecmp' to compare encoding names.Mark H Weaver2-6/+6
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-03Remove double indirection in element access in array-copy!Daniel Llorens1-11/+20
* libguile/array-map.c: (racp): factor scm_generalized_vector_ref, scm_generalized_vector_set_x out of the rank-1 loop. Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2013-04-02Rename 'scm_i_get_byte_or_eof' et al; mark them as SCM_API.Mark H Weaver3-6/+6
* libguile/ports.c (scm_i_get_byte_or_eof, scm_i_peek_byte_or_eof): Rename to 'scm_slow_get_byte_or_eof' and 'scm_slow_peek_byte_or_eof', respectively. * libguile/ports.h (scm_i_get_byte_or_eof, scm_i_peek_byte_or_eof): Rename to 'scm_slow_get_byte_or_eof' and 'scm_slow_peek_byte_or_eof', respectively, and mark them as SCM_API. * libguile/inline.h (scm_get_byte_or_eof, scm_peek_byte_or_eof): Adjust to use the new names.
2013-04-02Remove uses of GC_PTR in 'finalize_iconv_descriptors'.Mark H Weaver1-1/+1
* libguile/ports.c (finalize_iconv_descriptors): Change GC_PTR to (void *) in parameter types.
2013-04-02Rewrite get_iconv_codepoint to fix a bug involving byte-order marks.Mark H Weaver1-40/+48
* libguile/ports.c (get_iconv_codepoint): Rewrite to fix a bug and improve efficiency and clarity. Previously, it incorrectly assumed that iconv would never consume input without producing output, which led to a buffer overrun and subsequent assertion failure. This happens when a byte-order mark is consumed by iconv at the beginning of the stream when using the UTF-16 or UTF-32 encodings. * test-suite/tests/ports.test (unicode byte-order marks (BOMs)): Add tests.
2013-04-02Move slow path out of 'scm_get_byte_or_eof' et al.Mark H Weaver3-34/+54
Suggested by Andy Wingo. * libguile/inline.h (scm_get_byte_or_eof, scm_peek_byte_or_eof): Keep only the fast path here, with fallback to 'scm_i_get_byte_or_eof' and 'scm_i_peek_byte_or_eof'. * libguile/ports.c (scm_i_get_byte_or_eof, scm_i_peek_byte_or_eof): New internal functions. * libguile/ports.h (scm_i_get_byte_or_eof, scm_i_peek_byte_or_eof): Add prototypes.
2013-04-02Add a static version of 'scm_fill_input' to ports.c.Mark H Weaver1-9/+15
* libguile/ports.c (scm_i_fill_input): New static function, containing the code that was previously in 'scm_fill_input'. (scm_fill_input): Simply call 'scm_i_fill_input'. (scm_c_read): Use 'scm_i_fill_input'.
2013-04-01Move the port alist from the hash table to the internal port structure.Mark H Weaver4-13/+25
* 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-04-01Optimize 'get-bytevector-some'; it may now read less than possible.Mark H Weaver1-54/+24
* libguile/r6rs-ports.c (scm_get_bytevector_some): Rewrite to efficiently take the contents of the read/putback buffers. In the docstring, clarify that it might not return all available bytes. * doc/ref/api-io.texi (R6RS Binary Input): Clarify that 'get-bytevector-some' might not return all available bytes. * test-suite/tests/r6rs-ports.test ("get-bytevector-some [only-some]"): Remove bogus test, which requires more than the R6RS requires.
2013-04-01Refactor port encoding modes: utf-8 and iconvMark H Weaver3-99/+163
Based on 6c98257f2ead0855f218369ea7f9a823cdb9727e by Andy Wingo. * libguile/ports-internal.h (struct scm_port_internal): Add a flag for the port encoding mode: UTF8 or iconv. The iconv descriptors are now in a separate structure so that we can avoid attaching finalizers to the ports themselves in the future. (enum scm_port_encoding_mode): New enum. (struct scm_iconv_descriptors): New struct. (scm_i_port_iconv_descriptors): Add prototype. * libguile/ports.c (finalize_port): Don't close iconv descriptors here. (scm_new_port_table_entry): Adapt to the iconv descriptors being moved. Initialize 'encoding_mode'. (scm_i_remove_port): Adapt to call 'close_iconv_descriptors'. (close_iconv_descriptors): New static function. (get_iconv_codepoint): Use 'scm_i_port_iconv_descriptors'. (get_codepoint): Check the port 'encoding_mode'. (finalize_iconv_descriptors, open_iconv_descriptors, close_iconv_descriptors, scm_i_port_iconv_descriptors): New static functions. (scm_i_set_port_encoding_x): Adapt to iconv descriptors being moved to separate structure, to set the 'encoding_mode' flag, and to use 'open_iconv_descriptors' and 'close_iconv_descriptors'. * libguile/print.c (display_string_using_iconv): Use 'scm_i_port_iconv_descriptors'. (display_string): Use 'encoding_mode' flag.
2013-04-01Add internal-only port structure and move iconv descriptors there.Mark H Weaver5-42/+112
* libguile/ports-internal.h: New file. * libguile/Makefile.am (noinst_HEADERS): Add ports-internal.h. * libguile/ports.h (scm_t_port): Add a comment mentioning that the 'input_cd' and 'output_cd' fields of the public structure are no longer what they seem to be. * libguile/ports.c: Include ports-internal.h. (finalize_port, scm_i_remove_port, get_iconv_codepoint, get_codepoint, scm_i_set_port_encoding_x): Access 'input_cd' and 'output_cd' via the new internal port structure. (scm_new_port_table_entry): Allocate and initialize the internal port structure. * libguile/print.c: Include ports-internal.h. (display_string_using_iconv, display_string): Access 'input_cd' and 'output_cd' via 'internal' pointer.
2013-04-01Add 'scm_gc_typed_calloc' macro.Mark H Weaver1-1/+3
* libguile/gc.h (scm_gc_typed_calloc): New macro.
2013-04-01Merge remote-tracking branch 'origin/stable-2.0'Mark H Weaver3-89/+84
Conflicts: libguile/r6rs-ports.c
2013-04-01scm_string_join: properly sequence operations in ADD_TO_APPEND_LISTMark H Weaver1-2/+3
* libguile/srfi-13.c (scm_string_join): Properly sequence operations in ADD_TO_APPEND_LIST macro.
2013-04-01Optimize 'string-join'.Mark H Weaver1-64/+57
* libguile/srfi-13.c (string-join): Rewrite to call 'scm_string_append' only once.
2013-04-01Make 'string-append' more efficient and robust.Mark H Weaver1-6/+16
* libguile/strings.c (scm_string_append): Check for numerical overflow while computing the length of the result. Double-check that we don't overflow the result string, and that it is the correct length in the end (in case another thread changed the list). When copying a narrow string to a wide result, avoid calling 'scm_i_string_length' and 'scm_i_string_chars' on each character.
2013-04-01Fix typos in 'string-join' docs: 'string-infix' -> 'strict-infix'.Mark H Weaver1-1/+1
* doc/ref/api-data.texi (String Constructors): In definition of 'string-join', change 'string-infix' -> 'strict-infix'. * libguile/srfi-13.c (scm_string_join): In docstring, change 'string-infix' -> 'strict-infix'.
2013-03-31Avoid unnecessary peeks for EOF in r6rs-ports.Mark H Weaver1-18/+9
* libguile/r6rs-ports.c (scm_get_bytevector_n, scm_get_bytevector_n_x, scm_get_bytevector_some, scm_get_bytevector_all): Avoid peeking for EOF when we already know.
2013-03-30Merge remote-tracking branch 'origin/stable-2.0'Mark H Weaver1-0/+1
2013-03-29build: Build and check (ice-9 popen) only when --enable-posix and HAVE_FORK.Ludovic Courtès1-0/+1
Fixes <http://bugs.gnu.org/13848>. Reported by Jan Schukat <shookie@email.de>. * configure.ac: Rename `HAVE_FORK' conditional to `BUILD_ICE_9_POPEN'. Set it when both $enable_posix and $ac_cv_func_fork are true. * libguile/posix.c (scm_init_posix): Add the `fork' feature. * doc/ref/api-options.texi (Common Feature Symbols): Add `fork'. * doc/ref/posix.texi (Pipes): Add footnote mentioning the `fork' feature. * module/Makefile.am (SCRIPTS_SOURCES): Make `scripts/autofrisk.scm' and `scripts/scan-api.scm' conditional on `BUILD_ICE_9_POPEN'. * test-suite/tests/popen.test (if-supported): New macro. Wrap body in `if-supported'.
2013-03-28Merge remote-tracking branch 'origin/stable-2.0'Mark H Weaver2-2/+31
2013-03-28Allow compilation with GMP < 5.0.0.Ludovic Courtès1-1/+30
* libguile/numbers.c (VARARG_MPZ_ITERATOR)[!HAVE_DECL_MPZ_INITS]: New macro. (mpz_inits, mpz_clears)[!HAVE_DECL_MPZ_INITS]: New functions. * configure.ac: Check for the declaration of `mpz_inits'.
2013-03-28Fix erroneous `FUNC_NAME' for `scm_array_length'.Ludovic Courtès1-1/+1
* libguile/generalized-arrays.c (scm_array_length): Fix `FUNC_NAME'.
2013-03-28Merge remote-tracking branch 'origin/stable-2.0'Mark H Weaver45-1905/+1782
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
2013-03-25getaddrinfo: Document the missing errno value for EAI_SYSTEM.Ludovic Courtès1-2/+4
In response to <http://bugs.gnu.org/13958>. Reported by Lluís Batlle i Rossell <viric@viric.name>. * doc/ref/posix.texi (Network Databases): Document the missing errno value for EAI_SYSTEM. * libguile/net_db.c (scm_getaddrinfo): Likewise.
2013-03-25sendfile: Make sure we have a Linux-style `sendfile'.Ludovic Courtès1-1/+3
* libguile/filesys.c (scm_sendfile): Change conditional to HAVE_SYS_SENDFILE_H && HAVE_SENDFILE.
2013-03-25sendfile: Check return value of `lseek'.Ludovic Courtès1-1/+4
* libguile/filesys.c (scm_sendfile): Check return value of `lseek_or_lseek64', and use `SCM_SYSERROR' upon error.
2013-03-22Add bindings for `sendfile'.Ludovic Courtès2-1/+94
* configure.ac: Check for <sys/sendfile.h> and `sendfile'. * libguile/filesys.c (scm_sendfile): New function. * libguile/filesys.h (scm_sendfile): New declaration. * test-suite/tests/filesys.test ("sendfile"): New test prefix. * doc/ref/posix.texi (File System): Document `sendfile'.
2013-03-22build: Adjust makefiles for `guile-procedures.txt'.Ludovic Courtès1-0/+4
* libguile/Makefile.am (all-local): New target. * Makefile.am (libguile/guile-procedures.txt): Output to $@.tmp first. (CLEANFILES): New variable.
2013-03-21Build `guile-procedures.txt' using (texinfo) instead of `makeinfo'.Ludovic Courtès2-16/+55
* Makefile.am (schemelibdir, schemelib_DATA): New variables. (libguile/guile-procedures.txt): New target. (EXTRA_DIST): Add libguile/texi-fragments-to-docstrings. * libguile/Makefile.am (guile-procedures.txt): Remove target. (schemelibdir, schemelib_DATA): Remove. * libguile/texi-fragments-to-docstrings: New file.
2013-03-20Improve sqrt handling of large integers and large and small rationals.Mark H Weaver1-21/+112
* libguile/numbers.c (exact_integer_is_perfect_square, exact_integer_floor_square_root): New static functions. (scm_sqrt): Use SCM_LIKELY. Add 'scm_t_inum' variable in inum case to reduce the number of uses of SCM_I_INUM. Rename 'mpz_t' variable. Remove unneeded sign check. Handle bignums too large to fit in a double. Handle fractions too large or too small to fit in a normalized double. * test-suite/tests/numbers.test ("sqrt"): Add tests.
2013-03-20Optimize inum case of exact-integer-sqrt.Mark H Weaver1-16/+8
* libguile/numbers.c (scm_exact_integer_sqrt): Use GMP for inum case. It is faster than what we had before.
2013-03-20Sqrt returns exact results when possible.Mark H Weaver1-5/+64
* libguile/numbers.c (scm_sqrt): Handle exact integers and rationals in such a way that exact results are returned whenever possible. * test-suite/tests/numbers.test ("sqrt"): Add tests.