summaryrefslogtreecommitdiff
path: root/libguile/fports.c
Commit message (Collapse)AuthorAgeFilesLines
* Presume ISO C90 headers are always availableMike Gran2022-10-141-3/+0
| | | | | | | | | | | | | | | | | | | | | | | | This includes <assert.h>, <ctype.h>, <errno.h>, <float.h>, <iso646.h>, <limits.h>, <locale.h>, <math.h>, <setjmp.h>, <signal.h>, <stdarg.h>, <stddef.h>, <stdio.h>, <stdlib.h>, <string.h>, <time.h>, <wchar.h>, and <wctype.h>. * configure.ac: don't check for <limits.h>, <string.h>, <time.h>, <assert.h>. Remove AC_INCLUDES_DEFAULT macro * libguile/bytevectors.c: include <limits.h>, remove HAVE_LIMITS_H * libguile/filesys.c: include <string.h>, remove HAVE_STRING_H * libguile/fports.c: include <string.h>, remove HAVE_STRING_H * libguile/gen-scmconfig.c: remove HAVE_LIMITS_H, HAVE_TIME_H, STDC_HEADERS Remove SCM_HAVE_STDC_HEADERS * libguile/hash.c: include <wchar.h>, remove HAVE_WCHAR_H * libguile/net_db.c: include <string.h>, remove HAVE_STRING_H * libguile/numbers.h: remove SCM_HAVE_STDC_HEADERS * libguile/regex-posix.c: include <wchar.h>, remove HAVE_WCHAR_H (fixup_multibyte_match): always defined (scm_regexp_exec): use fixup_multibyte_match * libguile/scmsigs.c: remove STDC_HEADERS * libguile/socket.c: include <string.h>, remove HAVE_STRING_H * test-suite/standalone/test-unwind.c: include <string.h>, remove HAVE_STRING_H
* Add support for "e" flag (O_CLOEXEC) to 'open-file'.Ludovic Courtès2022-09-071-1/+7
| | | | | | | | | * libguile/fports.c (scm_i_mode_to_open_flags): Add 'e' case. (scm_open_file_with_encoding): Document it. * test-suite/standalone/test-close-on-exec: New file. * test-suite/standalone/Makefile.am (check_SCRIPTS, TESTS): Add it. * doc/ref/api-io.texi (File Ports): Document it. * NEWS: Update.
* Zero the initial file port revealed count.Ludovic Courtès2020-05-121-1/+2
| | | | | | | | | | | | | | Fixes <https://bugs.gnu.org/41204>. Reported by Caleb Ristvedt <caleb.ristvedt@cune.org>. Until now, Guile would leak the file descriptors of all the file ports not explicitly closed. * libguile/fports.c (scm_i_fdes_to_port): Initialize fp->revealed. * test-suite/tests/ports.test ("initial revealed count") ("non-revealed port is closed"): New tests. ("close-port & revealed port"): Check (port-revealed port). ("revealed port fdes not closed"): Likewise.
* Avoid throwing exceptions during early boot if stdin is closedAndy Wingo2019-12-131-17/+27
| | | | | | | | * libguile/fports.c (scm_i_fdes_is_valid): New internal helper. (scm_i_fdes_to_port): Use new helper. * libguile/fports.h: Declare new helper. * libguile/init.c (scm_standard_stream_to_port): Refactor to use scm_i_fdes_is_valid.
* Merge from stable-2.2Andy Wingo2019-08-021-7/+2
|\
| * fport_seek: Eliminate a fruitless use of 'off_t_or_off64_t'.Mark H Weaver2019-06-181-7/+2
| | | | | | | | | | | | | | | | | | This is a followup to commit 91ba73b397fcc2a36ae7e434522a924c7a8887d0. * libguile/fports.c (fport_seek): Use 'lseek' instead of 'lseek_or_lseek64', and use 'scm_t_off' uniformly. That's the type used in the function signature, and there's no benefit to using a wider type internally. Remove the overflow check, which is no longer needed.
* | Merge from stable-2.2Andy Wingo2019-08-021-1/+6
|\ \ | |/
| * Improve overflow checks in bytevector, string, and I/O operations.Mark H Weaver2019-06-181-3/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * libguile/bytevectors.c (INTEGER_ACCESSOR_PROLOGUE) (scm_bytevector_copy_x, bytevector_large_set): Rewrite checks to reliably detect overflows. (make_bytevector): Constrain the bytevector length to avoid later overflows during allocation. (make_bytevector_from_buffer): Fix indentation. (scm_bytevector_length): Use 'scm_from_size_t' to convert a 'size_t', not 'scm_from_uint'. * libguile/fports.c (fport_seek): Check for overflow before the implicit conversion of the return value. * libguile/guardians.c (guardian_print): Use 'scm_from_ulong' to convert an 'unsigned long', not 'scm_from_uint'. * libguile/ports.c (scm_unread_string): Change a variable to type 'size_t'. (scm_seek, scm_truncate_file): Use 'scm_t_off' instead of 'off_t_or_off64_t' to avoid implicit type conversions that could overflow, because 'ptob->seek' and 'ptob->truncate' use 'scm_t_off'. * libguile/r6rs-ports.c (bytevector_input_port_seek) (custom_binary_port_seek, bytevector_output_port_seek): Rewrite offset calculations to reliably detect overflows. Use 'scm_from_off_t' to convert a 'scm_t_off', not 'scm_from_long' nor 'scm_from_int'. (scm_get_bytevector_n_x, scm_get_bytevector_all, scm_unget_bytevector) (bytevector_output_port_write): Rewrite checks to reliably detect overflows. Use 'size_t' where appropriate. (bytevector_output_port_buffer_grow): Rewrite size calculations to reliably detect overflows. Minor change in the calculation of the new size: now it is max(min_size, 2*current_size), whereas previously it would multiply current_size by the smallest power of 2 needed to surpass min_size. * libguile/strings.c (make_stringbuf): Constrain the stringbuf length to avoid later overflows during allocation. (scm_string_append): Change overflow check to use INT_ADD_OVERFLOW. * libguile/strports.c (string_port_write): Rewrite size calculations to reliably detect overflows. (string_port_seek): Rewrite offset calculations to reliably detect overflows. Use 'scm_from_off_t' to convert a 'scm_t_off', not 'scm_from_long'. (string_port_truncate): Use 'scm_from_off_t' to convert a 'scm_t_off', not 'scm_from_off_t_or_off64_t'. * libguile/vectors.c (scm_c_make_vector): Change a variable to type 'size_t'.
* | Fix use of uninstalled header by installed headersAndy Wingo2018-10-071-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * libguile/Makefile.am (libpath.h): Remove definition of SCM_EFFECTIVE_VERSION, which is defined in version.h. * libguile/extensions.h: Remove libpath.h inclusion, as it's not installed. * libguile/atomic.c: * libguile/bytevectors.c: * libguile/control.c: * libguile/fdes-finalizers.c: * libguile/foreign-object.c: * libguile/foreign.c: * libguile/fports.c: * libguile/frames.c: * libguile/goops.c: * libguile/i18n.c: * libguile/instructions.c: * libguile/intrinsics.c: * libguile/ioext.c: * libguile/load.c: * libguile/loader.c: * libguile/poll.c: * libguile/ports.c: * libguile/posix.c: * libguile/programs.c: * libguile/r6rs-ports.c: * libguile/srfi-1.c: * libguile/srfi-60.c: * libguile/threads.c: * libguile/unicode.c: * libguile/vm.c: * libguile/weak-vector.c: Include version.h for the SCM_EFFECTIVE_VERSION definition.
* | Update license notices in all C filesAndy Wingo2018-06-201-17/+17
| | | | | | | | | | Update to newest recommended license notices from the FSF. Everything stays LGPLv3+ except guile-readline which is GPLv3+.
* | Remove (C) from copyright statementsAndy Wingo2018-06-201-1/+1
| | | | | | | | | | | | As the FSF advises, 'There is no legal significance to using the three-character sequence “(C)”, but it does no harm.' It does take up space though! For that reason, we remove it here from our C files.
* | Rationalize include order in C filesAndy Wingo2018-06-201-7/+9
| | | | | | | | | | Include config.h first, then system includes, then libguile includes, in alphabetical order, then the include for the file in question.
* | Make libguile header inclusion consistent within libguile c filesAndy Wingo2018-06-201-23/+23
| | | | | | | | | | Change from '#include "libguile/foo.h"' and '#include <libguile/foo.h>' to '#include "foo.h"'.
* | Remove Emacs local variables comments in Guile sourceAndy Wingo2018-06-201-6/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The .dir-locals.el file in the repository is sufficient for Emacs users. * libguile/__scm.h: * libguile/alist.c: * libguile/alist.h: * libguile/array-handle.c: * libguile/array-handle.h: * libguile/array-map.c: * libguile/array-map.h: * libguile/arrays.c: * libguile/arrays.h: * libguile/async.c: * libguile/async.h: * libguile/backtrace.c: * libguile/backtrace.h: * libguile/bitvectors.c: * libguile/bitvectors.h: * libguile/boolean.c: * libguile/boolean.h: * libguile/chars.c: * libguile/chars.h: * libguile/chooks.c: * libguile/chooks.h: * libguile/continuations.c: * libguile/continuations.h: * libguile/control.c: * libguile/conv-integer.i.c: * libguile/debug-malloc.h: * libguile/debug.c: * libguile/debug.h: * libguile/deprecation.c: * libguile/deprecation.h: * libguile/dynl.c: * libguile/dynl.h: * libguile/dynstack.c: * libguile/dynstack.h: * libguile/dynwind.c: * libguile/dynwind.h: * libguile/eq.c: * libguile/eq.h: * libguile/error.c: * libguile/error.h: * libguile/eval.c: * libguile/eval.h: * libguile/evalext.c: * libguile/evalext.h: * libguile/expand.c: * libguile/expand.h: * libguile/extensions.c: * libguile/extensions.h: * libguile/feature.c: * libguile/feature.h: * libguile/filesys.c: * libguile/filesys.h: * libguile/fluids.c: * libguile/fluids.h: * libguile/foreign.c: * libguile/fports.c: * libguile/fports.h: * libguile/frames.c: * libguile/frames.h: * libguile/gc-inline.h: * libguile/gc.c: * libguile/gc.h: * libguile/generalized-arrays.c: * libguile/generalized-arrays.h: * libguile/generalized-vectors.c: * libguile/generalized-vectors.h: * libguile/gettext.c: * libguile/gettext.h: * libguile/goops.c: * libguile/goops.h: * libguile/gsubr.c: * libguile/gsubr.h: * libguile/guardians.c: * libguile/guardians.h: * libguile/guile.c: * libguile/hash.c: * libguile/hash.h: * libguile/hashtab.c: * libguile/hashtab.h: * libguile/hooks.c: * libguile/hooks.h: * libguile/i18n.c: * libguile/i18n.h: * libguile/init.c: * libguile/init.h: * libguile/instructions.c: * libguile/instructions.h: * libguile/intrinsics.c: * libguile/intrinsics.h: * libguile/ioext.c: * libguile/ioext.h: * libguile/iselect.h: * libguile/keywords.c: * libguile/keywords.h: * libguile/list.c: * libguile/list.h: * libguile/load.c: * libguile/load.h: * libguile/loader.c: * libguile/loader.h: * libguile/macros.c: * libguile/macros.h: * libguile/mallocs.c: * libguile/mallocs.h: * libguile/memmove.c: * libguile/memoize.c: * libguile/memoize.h: * libguile/modules.c: * libguile/modules.h: * libguile/net_db.c: * libguile/net_db.h: * libguile/null-threads.c: * libguile/null-threads.h: * libguile/numbers.c: * libguile/numbers.h: * libguile/objprop.c: * libguile/objprop.h: * libguile/options.c: * libguile/options.h: * libguile/pairs.c: * libguile/pairs.h: * libguile/poll.c: * libguile/poll.h: * libguile/ports.c: * libguile/ports.h: * libguile/posix.c: * libguile/posix.h: * libguile/print.c: * libguile/print.h: * libguile/procprop.c: * libguile/procprop.h: * libguile/procs.c: * libguile/procs.h: * libguile/programs.c: * libguile/programs.h: * libguile/promises.c: * libguile/promises.h: * libguile/pthread-threads.h: * libguile/random.c: * libguile/random.h: * libguile/rdelim.c: * libguile/rdelim.h: * libguile/read.c: * libguile/read.h: * libguile/regex-posix.c: * libguile/regex-posix.h: * libguile/rw.c: * libguile/rw.h: * libguile/scmsigs.c: * libguile/scmsigs.h: * libguile/script.c: * libguile/script.h: * libguile/simpos.c: * libguile/simpos.h: * libguile/smob.c: * libguile/smob.h: * libguile/snarf.h: * libguile/socket.c: * libguile/socket.h: * libguile/sort.c: * libguile/sort.h: * libguile/srcprop.c: * libguile/srcprop.h: * libguile/stackchk.c: * libguile/stackchk.h: * libguile/stacks.c: * libguile/stacks.h: * libguile/stime.c: * libguile/stime.h: * libguile/strerror.c: * libguile/strings.c: * libguile/strings.h: * libguile/strorder.c: * libguile/strorder.h: * libguile/strports.c: * libguile/strports.h: * libguile/struct.c: * libguile/struct.h: * libguile/symbols.c: * libguile/symbols.h: * libguile/syntax.c: * libguile/syscalls.h: * libguile/tags.h: * libguile/threads.c: * libguile/threads.h: * libguile/throw.c: * libguile/throw.h: * libguile/trees.h: * libguile/unicode.c: * libguile/unicode.h: * libguile/uniform.c: * libguile/uniform.h: * libguile/values.c: * libguile/values.h: * libguile/variable.c: * libguile/variable.h: * libguile/vectors.c: * libguile/vectors.h: * libguile/version.c: * libguile/vm-engine.c: * libguile/vm-expand.h: * libguile/vm.c: * libguile/vm.h: * libguile/vports.c: * libguile/vports.h: * libguile/weak-list.h: * libguile/weak-set.c: * libguile/weak-set.h: * libguile/weak-table.c: * libguile/weak-table.h: * libguile/weak-vector.c: * libguile/weak-vector.h: Remove needless trailing comments.
* | Remove _scm.hAndy Wingo2018-06-201-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * libguile/_scm.h: Remove. An internal header, never installed. * libguile/__scm.h: Remove horrible documentation. * libguile/Makefile.am (EXTRA_libguile_@GUILE_EFFECTIVE_VERSION@_la_SOURCES): Remove _scm.h. * libguile/alist.c: * libguile/array-handle.c: * libguile/array-map.c: * libguile/arrays.c: * libguile/async.c: * libguile/atomic.c: * libguile/backtrace.c: * libguile/bitvectors.c: * libguile/boolean.c: * libguile/bytevectors.c: * libguile/chars.c: * libguile/continuations.c: * libguile/control.c: * libguile/debug-malloc.c: * libguile/debug.c: * libguile/deprecated.c: * libguile/deprecation.c: * libguile/dynl.c: * libguile/dynstack.c: * libguile/dynwind.c: * libguile/eq.c: * libguile/error.c: * libguile/eval.c: * libguile/evalext.c: * libguile/expand.c: * libguile/extensions.c: * libguile/fdes-finalizers.c: * libguile/feature.c: * libguile/filesys.c: * libguile/finalizers.c: * libguile/fluids.c: * libguile/foreign-object.c: * libguile/foreign.c: * libguile/fports.c: * libguile/frames.c: * libguile/gc-malloc.c: * libguile/gc.c: * libguile/gen-scmconfig.c: * libguile/generalized-arrays.c: * libguile/generalized-vectors.c: * libguile/gettext.c: * libguile/goops.c: * libguile/gsubr.c: * libguile/guardians.c: * libguile/hash.c: * libguile/hashtab.c: * libguile/hooks.c: * libguile/i18n.c: * libguile/init.c: * libguile/instructions.c: * libguile/intrinsics.c: * libguile/ioext.c: * libguile/keywords.c: * libguile/list.c: * libguile/load.c: * libguile/loader.c: * libguile/macros.c: * libguile/mallocs.c: * libguile/memoize.c: * libguile/modules.c: * libguile/net_db.c: * libguile/null-threads.c: * libguile/numbers.c: * libguile/objprop.c: * libguile/options.c: * libguile/pairs.c: * libguile/poll.c: * libguile/ports-internal.h: * libguile/ports.c: * libguile/posix.c: * libguile/print.c: * libguile/procprop.c: * libguile/procs.c: * libguile/programs.c: * libguile/promises.c: * libguile/r6rs-ports.c: * libguile/random.c: * libguile/rdelim.c: * libguile/read.c: * libguile/regex-posix.c: * libguile/rw.c: * libguile/scmsigs.c: * libguile/script.c: * libguile/simpos.c: * libguile/smob.c: * libguile/socket.c: * libguile/sort.c: * libguile/srcprop.c: * libguile/srfi-1.c: * libguile/srfi-13.c: * libguile/srfi-14.c: * libguile/srfi-4.c: * libguile/srfi-60.c: * libguile/stackchk.c: * libguile/stacks.c: * libguile/stime.c: * libguile/strings.c: * libguile/strorder.c: * libguile/strports.c: * libguile/struct.c: * libguile/symbols.c: * libguile/syntax.c: * libguile/threads.c: * libguile/throw.c: * libguile/trees.c: * libguile/unicode.c: * libguile/uniform.c: * libguile/values.c: * libguile/variable.c: * libguile/vectors.c: * libguile/version.c: * libguile/vm.c: * libguile/vports.c: * libguile/weak-set.c: * libguile/weak-table.c: * libguile/weak-vector.c: Remove _scm.h includes.
* | Devolve symbols.h from _scm.hAndy Wingo2018-06-201-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * libguile/_scm.h: Remove symbols.h. * libguile/array-handle.c: * libguile/array-map.c: * libguile/backtrace.c: * libguile/bytevectors.c: * libguile/chars.c: * libguile/continuations.c: * libguile/error.c: * libguile/eval.c: * libguile/evalext.c: * libguile/expand.c: * libguile/feature.c: * libguile/filesys.c: * libguile/foreign.c: * libguile/fports.c: * libguile/frames.c: * libguile/gc.c: * libguile/goops.c: * libguile/gsubr.c: * libguile/i18n.c: * libguile/instructions.c: * libguile/intrinsics.c: * libguile/keywords.c: * libguile/load.c: * libguile/macros.c: * libguile/memoize.c: * libguile/modules.c: * libguile/net_db.c: * libguile/options.c: * libguile/ports.c: * libguile/posix.c: * libguile/print.c: * libguile/procprop.c: * libguile/procs.c: * libguile/r6rs-ports.c: * libguile/random.c: * libguile/read.c: * libguile/socket.c: * libguile/srcprop.c: * libguile/srfi-13.c: * libguile/srfi-14.c: * libguile/stacks.c: * libguile/strings.c: * libguile/strports.c: * libguile/struct.c: * libguile/threads.c: * libguile/throw.c: * libguile/vm.c: Add symbols.h.
* | Remove modules.h from _scm.h.Andy Wingo2018-06-201-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * libguile/_scm.h: Remove modules.h. * libguile/arrays.c: * libguile/backtrace.c: * libguile/feature.c: * libguile/filesys.c: * libguile/foreign-object.c: * libguile/foreign.c: * libguile/fports.c: * libguile/frames.c: * libguile/gc.c: * libguile/gsubr.c: * libguile/i18n.c: * libguile/intrinsics.c: * libguile/macros.c: * libguile/numbers.c: * libguile/poll.c: * libguile/ports.c: * libguile/posix.c: * libguile/random.c: * libguile/read.c: * libguile/regex-posix.c: * libguile/scmsigs.c: * libguile/script.c: * libguile/socket.c: * libguile/srcprop.c: * libguile/srfi-14.c: * libguile/srfi-4.c: * libguile/stime.c: * libguile/struct.c: * libguile/syntax.c: * libguile/threads.c: * libguile/throw.c: Add modules.h.
* | Devolve variable.h from _scm.h.Andy Wingo2018-06-201-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * libguile/_scm.h: Remove variable.h. * libguile/backtrace.c: * libguile/debug.c: * libguile/dynstack.c: * libguile/dynwind.c: * libguile/eval.c: * libguile/evalext.c: * libguile/expand.c: * libguile/feature.c: * libguile/fluids.c: * libguile/foreign-object.c: * libguile/fports.c: * libguile/frames.c: * libguile/goops.c: * libguile/i18n.c: * libguile/load.c: * libguile/macros.c: * libguile/memoize.c: * libguile/ports.c: * libguile/print.c: * libguile/programs.c: * libguile/random.c: * libguile/read.c: * libguile/scmsigs.c: * libguile/srfi-4.c: * libguile/strports.c: * libguile/syntax.c: * libguile/threads.c: * libguile/throw.c: Add variable.h.
* | Move subr snarfing macros to gsubr.h.Andy Wingo2018-06-201-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * libguile/snarf.h: Remove gsubr include and subr snarfers. * libguile/gsubr.h (SCM_DEFINE_GSUBR, SCM_DEFINE, SCM_PRIMITIVE_GENERIC): (SCM_DEFINE_PUBLIC, SCM_PROC, SCM_REGISTER_PROC, SCM_GPROC): Move here. * libguile/alist.c: * libguile/array-map.c: * libguile/arrays.c: * libguile/async.c: * libguile/atomic.c: * libguile/backtrace.c: * libguile/bitvectors.c: * libguile/boolean.c: * libguile/bytevectors.c: * libguile/chars.c: * libguile/continuations.c: * libguile/control.c: * libguile/debug-malloc.c: * libguile/debug.c: * libguile/deprecation.c: * libguile/dynl.c: * libguile/eq.c: * libguile/error.c: * libguile/error.h: * libguile/eval.c: * libguile/evalext.c: * libguile/expand.c: * libguile/extensions.c: * libguile/fdes-finalizers.c: * libguile/feature.c: * libguile/filesys.c: * libguile/finalizers.c: * libguile/fluids.c: * libguile/foreign-object.c: * libguile/foreign.c: * libguile/fports.c: * libguile/frames.c: * libguile/gc.c: * libguile/generalized-arrays.c: * libguile/generalized-vectors.c: * libguile/gettext.c: * libguile/guardians.c: * libguile/hash.c: * libguile/hashtab.c: * libguile/hooks.c: * libguile/i18n.c: * libguile/instructions.c: * libguile/intrinsics.c: * libguile/ioext.c: * libguile/keywords.c: * libguile/list.c: * libguile/load.c: * libguile/loader.c: * libguile/macros.c: * libguile/memoize.c: * libguile/modules.c: * libguile/net_db.c: * libguile/numbers.c: * libguile/objprop.c: * libguile/pairs.c: * libguile/poll.c: * libguile/ports.c: * libguile/posix.c: * libguile/print.c: * libguile/procs.c: * libguile/programs.c: * libguile/promises.c: * libguile/r6rs-ports.c: * libguile/random.c: * libguile/rdelim.c: * libguile/read.c: * libguile/regex-posix.c: * libguile/rw.c: * libguile/scmsigs.c: * libguile/simpos.c: * libguile/smob.c: * libguile/socket.c: * libguile/sort.c: * libguile/srcprop.c: * libguile/srfi-1.c: * libguile/srfi-13.c: * libguile/srfi-14.c: * libguile/srfi-4.c: * libguile/srfi-60.c: * libguile/stackchk.c: * libguile/stacks.c: * libguile/stime.c: * libguile/strings.c: * libguile/strorder.c: * libguile/strports.c: * libguile/struct.c: * libguile/symbols.c: * libguile/syntax.c: * libguile/threads.c: * libguile/throw.c: * libguile/trees.c: * libguile/unicode.c: * libguile/values.c: * libguile/variable.c: * libguile/vectors.c: * libguile/version.c: * libguile/vm.c: * libguile/vports.c: * libguile/weak-table.c: * libguile/weak-vector.c: Add gsubr includes.
* | Devolve numbers.h from _scm.h.Andy Wingo2018-06-191-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * libguile/_scm.h: Remove numbers.h. * libguile/array-handle.c: * libguile/array-map.c: * libguile/arrays.c: * libguile/backtrace.c: * libguile/bitvectors.c: * libguile/bytevectors.c: * libguile/chars.c: * libguile/continuations.c: * libguile/debug-malloc.c: * libguile/error.c: * libguile/eval.c: * libguile/filesys.c: * libguile/foreign-object.c: * libguile/foreign.c: * libguile/fports.c: * libguile/frames.c: * libguile/gc.c: * libguile/generalized-arrays.c: * libguile/gettext.c: * libguile/goops.c: * libguile/gsubr.c: * libguile/guardians.c: * libguile/hash.c: * libguile/hashtab.c: * libguile/hooks.c: * libguile/i18n.c: * libguile/instructions.c: * libguile/intrinsics.c: * libguile/ioext.c: * libguile/list.c: * libguile/memoize.c: * libguile/net_db.c: * libguile/options.c: * libguile/ports.c: * libguile/posix-w32.c: * libguile/posix.c: * libguile/procprop.c: * libguile/programs.c: * libguile/r6rs-ports.c: * libguile/random.c: * libguile/rdelim.c: * libguile/read.c: * libguile/regex-posix.c: * libguile/rw.c: * libguile/scmsigs.c: * libguile/simpos.c: * libguile/smob.c: * libguile/socket.c: * libguile/srcprop.c: * libguile/srfi-13.c: * libguile/srfi-14.c: * libguile/srfi-4.c: * libguile/stackchk.c: * libguile/stacks.c: * libguile/stime.c: * libguile/strings.c: * libguile/struct.c: * libguile/symbols.c: * libguile/threads.c: * libguile/throw.c: * libguile/vectors.c: * libguile/version.c: * libguile/vm.c: * libguile/vports.c: * libguile/weak-table.c: Add numbers.h.
* | Devolve pairs.hAndy Wingo2018-06-181-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * libguile/_scm.h: Remove pairs.h. * libguile/alist.c: * libguile/array-handle.c: * libguile/array-map.c: * libguile/arrays.c: * libguile/async.c: * libguile/bitvectors.c: * libguile/bytevectors.c: * libguile/chars.c: * libguile/continuations.c: * libguile/control.c: * libguile/debug.c: * libguile/deprecation.c: * libguile/dynwind.c: * libguile/eq.c: * libguile/eval.c: * libguile/evalext.c: * libguile/expand.c: * libguile/fdes-finalizers.c: * libguile/feature.c: * libguile/filesys.c: * libguile/fluids.c: * libguile/foreign.c: * libguile/fports.c: * libguile/gc.c: * libguile/generalized-arrays.c: * libguile/goops.c: * libguile/guardians.c: * libguile/hash.c: * libguile/hashtab.c: * libguile/hooks.c: * libguile/i18n.c: * libguile/instructions.c: * libguile/ioext.c: * libguile/keywords.c: * libguile/list.c: * libguile/load.c: * libguile/loader.c: * libguile/memoize.c: * libguile/modules.c: * libguile/net_db.c: * libguile/numbers.c: * libguile/objprop.c: * libguile/options.c: * libguile/ports-internal.h: * libguile/ports.c: * libguile/posix.c: * libguile/print.c: * libguile/print.h: * libguile/procprop.c: * libguile/programs.c: * libguile/random.c: * libguile/rdelim.c: * libguile/read.c: * libguile/regex-posix.c: * libguile/scmsigs.c: * libguile/script.c: * libguile/socket.c: * libguile/sort.c: * libguile/srcprop.c: * libguile/srfi-1.c: * libguile/srfi-13.c: * libguile/srfi-14.c: * libguile/srfi-60.c: * libguile/stacks.c: * libguile/stime.c: * libguile/strings.c: * libguile/strorder.c: * libguile/struct.c: * libguile/symbols.c: * libguile/threads.c: * libguile/throw.c: * libguile/trees.c: * libguile/values.c: * libguile/vectors.c: * libguile/vm.c: * libguile/weak-list.h: * libguile/weak-set.c: * libguile/weak-table.c: * libguile/weak-vector.c: Add pairs.h.
* | Devolve boolean.h include.Andy Wingo2018-06-181-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * libguile/_scm.h: Remove boolean.h include. * libguile/alist.c: * libguile/array-map.c: * libguile/arrays.c: * libguile/backtrace.c: * libguile/bitvectors.c: * libguile/chars.c: * libguile/continuations.c: * libguile/dynwind.c: * libguile/eq.c: * libguile/eval.c: * libguile/expand.c: * libguile/fdes-finalizers.c: * libguile/filesys.c: * libguile/foreign.c: * libguile/fports.c: * libguile/frames.c: * libguile/generalized-arrays.h: * libguile/goops.c: * libguile/goops.h: * libguile/guardians.c: * libguile/hooks.c: * libguile/i18n.c: * libguile/intrinsics.c: * libguile/list.c: * libguile/load.c: * libguile/loader.c: * libguile/macros.c: * libguile/memoize.c: * libguile/modules.c: * libguile/net_db.c: * libguile/numbers.c: * libguile/options.c: * libguile/ports.c: * libguile/print.c: * libguile/procprop.c: * libguile/procs.h: * libguile/programs.c: * libguile/r6rs-ports.c: * libguile/read.c: * libguile/scmsigs.c: * libguile/sort.c: * libguile/srcprop.h: * libguile/srfi-1.c: * libguile/srfi-13.c: * libguile/srfi-14.c: * libguile/srfi-14.h: * libguile/srfi-4.c: * libguile/stacks.c: * libguile/stime.c: * libguile/strorder.c: * libguile/struct.c: * libguile/struct.h: * libguile/symbols.c: * libguile/threads.c: * libguile/throw.c: * libguile/vports.c: Add boolean.h includes.
* | Remove includes of validate.h.Andy Wingo2018-06-181-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * guile-readline/readline.c: * libguile/alist.c: * libguile/array-map.c: * libguile/arrays.c: * libguile/async.c: * libguile/atomic.c: * libguile/backtrace.c: * libguile/boolean.c: * libguile/bytevectors.c: * libguile/chars.c: * libguile/continuations.c: * libguile/debug.c: * libguile/dynl.c: * libguile/eq.c: * libguile/error.c: * libguile/eval.c: * libguile/evalext.c: * libguile/expand.c: * libguile/feature.c: * libguile/filesys.c: * libguile/fluids.c: * libguile/fports.c: * libguile/gc-malloc.c: * libguile/gc.c: * libguile/goops.c: * libguile/goops.h: * libguile/guardians.c: * libguile/hash.c: * libguile/hashtab.c: * libguile/hashtab.h: * libguile/hooks.c: * libguile/i18n.c: * libguile/ioext.c: * libguile/keywords.c: * libguile/list.c: * libguile/load.c: * libguile/macros.c: * libguile/memoize.c: * libguile/modules.h: * libguile/net_db.c: * libguile/numbers.c: * libguile/pairs.c: * libguile/poll.c: * libguile/ports.c: * libguile/posix.c: * libguile/print.c: * libguile/procprop.c: * libguile/procs.c: * libguile/promises.c: * libguile/r6rs-ports.c: * libguile/random.c: * libguile/rdelim.c: * libguile/read.c: * libguile/regex-posix.c: * libguile/rw.c: * libguile/scmsigs.c: * libguile/script.c: * libguile/simpos.c: * libguile/socket.c: * libguile/sort.c: * libguile/srcprop.c: * libguile/srfi-1.c: * libguile/srfi-4.c: * libguile/srfi-60.c: * libguile/stacks.c: * libguile/stime.c: * libguile/strings.c: * libguile/strorder.c: * libguile/strports.c: * libguile/struct.c: * libguile/symbols.c: * libguile/syntax.c: * libguile/threads.c: * libguile/throw.c: * libguile/trees.c: * libguile/unicode.c: * libguile/values.c: * libguile/variable.c: * libguile/vectors.c: * libguile/vports.c: * libguile/weak-set.c: * libguile/weak-table.c: * libguile/weak-vector.c: * libguile.h: Remove validate.h include.
* | Move syscall-related private defines to their own headerAndy Wingo2018-06-171-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * libguile/syscalls.h: New private header. * libguile/Makefile.am (EXTRA_libguile_@GUILE_EFFECTIVE_VERSION@_la_SOURCES): Add syscalls.h. * libguile/_scm.h: Remove SCM_SYSCALL and all the bits relating to e.g. stat versus stat64. * libguile/filesys.c: * libguile/fports.c: * libguile/i18n.c: * libguile/ioext.c: * libguile/poll.c: * libguile/ports.c: * libguile/posix.c: * libguile/rw.c: * libguile/scmsigs.c: * libguile/script.c: * libguile/socket.c: * libguile/strports.c: Include syscalls.h.
* | Fix libguile subcomponent headers not to include <libguile.h>Andy Wingo2018-06-141-9/+12
|/ | | | | | | | | | | | | | | | | | | * libguile/bytevectors.h: Include uniform.h, for use in the macros. * libguile/extensions.h: Include libpath.h, for the SCM_EFFECTIVE_VERSION, which is almost always used with these routines. * libguile/frames.h: * libguile/instructions.h: * libguile/intrinsics.h: * libguile/loader.h: * libguile/programs.h: * libguile/vm.h: Include <libguile/__scm.h> instead of <libguile.h>. Cuts a circular include, but also precipitates a lot of maintenance in the .c files. * libguile/*.c: Update C files to add needed all needed includes that before were getting automatically pulled in by the indirect inclusion of libguile.h.
* Allow garbage collection of revealed file ports.Ludovic Courtès2017-10-251-33/+8
| | | | | | | | | | | | | | | | | | | | | | Reported at <https://bugs.gnu.org/28784>. Discussed at <https://lists.gnu.org/archive/html/guile-devel/2017-10/msg00003.html>. * libguile/fports.c (revealed_ports, revealed_lock): Remove. (scm_revealed_count): Just return 'SCM_REVEALED (port)'. (scm_set_port_revealed_x, scm_adjust_port_revealed_x): Remove REVEALED_PORTS manipulation. (fport_close): Do nothing when SCM_REVEALED (port) > 0. * libguile/fports.h (scm_t_fport): Adjust comment; make 'revealed' unsigned. * libguile/ports.c (do_close): Call 'close_port' instead of 'scm_close_port'. (scm_close_port): Rename to... (close_port): ... this. Add 'explicit' parameter. Clear 'revealed' field when PORT is a file port and EXPLICIT is true. (scm_close_port): Call 'close_port'. * test-suite/tests/ports.test ("close-port & revealed port") ("revealed port fdes not closed"): New tests.
* Fix open-file mode misinterpretationAndy Wingo2017-03-011-0/+3
| | | | | * libguile/fports.c (scm_i_mode_to_open_flags): Validate that argument is string. Fixes #25498.
* Elide syscalls in fdes->portAndy Wingo2017-02-141-20/+36
| | | | | | | | | | | | | | | | | | | | * 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.
* Use atomics for async interruptsAndy Wingo2016-10-261-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | * libguile/__scm.h (SCM_TICK): Always define as scm_async_tick(). * libguile/error.c (scm_syserror, scm_syserror_msg): * libguile/fports.c (fport_read, fport_write): * libguile/_scm.h (SCM_SYSCALL): Replace SCM_ASYNC_TICK with scm_async_tick (). (SCM_ASYNC_TICK, SCM_ASYNC_TICK_WITH_CODE) (SCM_ASYNC_TICK_WITH_GUARD_CODE): Remove internal definitions. We inline into vm-engine.c, the only place where it matters. * libguile/async.h: * libguile/async.c (scm_async_tick, scm_i_setup_sleep): (scm_i_reset_sleep, scm_system_async_mark_for_thread): * libguile/threads.h (struct scm_thread_wake_data): * libguile/threads.h (scm_i_thread): * libguile/threads.c (block_self, guilify_self_1, scm_std_select): Rewrite to use sequentially-consistent atomic references. * libguile/atomics-internal.h (scm_atomic_set_pointer): (scm_atomic_ref_pointer): New definitions. * libguile/finalizers.c (queue_finalizer_async): We can allocate, so just use scm_system_async_mark_for_thread instead of the set-cdr! shenanigans. * libguile/scmsigs.c (take_signal): * libguile/gc.c (queue_after_gc_hook): Adapt to new asyncs mechanism. Can't allocate but we're just manipulating the current thread when no other threads are running so we should be good. * libguile/vm-engine.c (VM_HANDLE_INTERRUPTS): Inline the async_tick business.
* Add file descriptor finalizersAndy Wingo2016-08-301-0/+2
| | | | | | | | | | | | | | | | | | * doc/ref/posix.texi (Ports and File Descriptors): Document new interfaces. * libguile/filesys.c (scm_close, scm_close_fdes) * libguile/fports.c (fport_close): * libguile/ioext.c (scm_primitive_move_to_fdes): Call scm_run_fdes_finalizers. * module/ice-9/fdes-finalizers.scm: * test-suite/tests/fdes-finalizers.test: * libguile/fdes-finalizers.h: * libguile/fdes-finalizers.c: New files. * module/Makefile.am: * test-suite/Makefile.am: * libguile/Makefile.am: * libguile.h: * libguile/init.c: Wire up new files.
* Allow mkstemp! to have optional "mode" argumentAndy Wingo2016-07-251-33/+44
| | | | | | | | | | | | | | | | | | | | | | | | | * m4/mkstemp.m4: Remove. * lib/mkstemp.c: Remove. * lib/mkostemp.c: New file. * m4/mkostemp.m4: New file. * lib/Makefile.am: * m4/gnulib-cache.m4: * m4/gnulib-comp.m4: Remove mkstemp module, replace with mkostemp. * libguile/fports.h: * libguile/fports.c (scm_i_mode_to_open_flags): Factor out helper to parse mode string to open flags. (scm_open_file_with_encoding): Use the new helper. * libguile/filesys.c: (scm_i_mkstemp): Adapt to take optional second argument, being a mode string. Use mkostemp. (scm_mkstemp): Backwards compatible shim that calls scm_i_mkstemp. * doc/ref/posix.texi: * NEWS: Update. * module/system/base/compile.scm (call-with-output-file/atomic): Pass "wb" as mode, to cause O_BINARY to be added on MinGW.
* Support for non-blocking I/OAndy Wingo2016-05-201-8/+38
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * doc/ref/api-io.texi (I/O Extensions): Document read_wait_fd / write_wait_fd members. (Non-Blocking I/O): New section. * libguile/fports.c (fport_read, fport_write): Return -1 if the operation would block. (fport_wait_fd, scm_make_fptob): Add read/write wait-fd implementation. * libguile/ports-internal.h (scm_t_port_type): Add read_wait_fd / write_wait_fd. * libguile/ports.c (default_read_wait_fd, default_write_wait_fd): New functions. (scm_make_port_type): Initialize default read/write wait fd impls. (trampoline_to_c_read, trampoline_to_scm_read) (trampoline_to_c_write, trampoline_to_scm_write): To Scheme, a return of #f indicates EWOULDBLOCk. (scm_set_port_read_wait_fd, scm_set_port_write_wait_fd): New functions. (port_read_wait_fd, port_write_wait_fd, scm_port_read_wait_fd) (scm_port_write_wait_fd, port_poll, scm_port_poll): New functions. (scm_i_read_bytes, scm_i_write_bytes): Poll if the read or write would block. * libguile/ports.h (scm_set_port_read_wait_fd) (scm_set_port_write_wait_fd): Add declarations. * module/ice-9/ports.scm: Shunt port-poll and port-{read,write}-wait-fd to the internals module. * module/ice-9/sports.scm (current-write-waiter): (current-read-waiter): Implement. * test-suite/tests/ports.test: Adapt non-blocking test to new behavior. * NEWS: Add entry.
* Use heap-allocated port types instead of ptobnumsAndy Wingo2016-05-131-18/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Remove scm_t_port_internalAndy Wingo2016-05-131-1/+1
| | | | | | | | | | | | | | | * 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.
* Make scm_t_port privateAndy Wingo2016-05-131-9/+2
| | | | | | | | | | | | | | | | | * libguile/ports-internal.h (enum scm_port_encoding_mode): Remove unused enum. (scm_t_port_internal, scm_t_port): Make encoding and conversion_strategy private. Instead of scm_t_port_internal containing scm_t_port, now that all members are private, we can store the user's "stream" in a word in the port object itself and make the whole of scm_t_port private. The next commit will remove scm_t_port_internal. (SCM_PTAB_ENTRY, SCM_PORT_DESCRIPTOR): Make private. * libguile/ports.c (scm_c_make_port_with_encoding): Adapt to new port layout. (scm_port_print): Use SCM_PTAB_ENTRY when printing. * libguile/ports.h: Remove scm_t_port definition. * libguile/ioext.c (get_matching_port): Simplify. * libguile/fports.c (scm_i_evict_port): Simplify.
* Add random_access_p port type methodAndy Wingo2016-05-131-1/+7
| | | | | | | | | | | | | * doc/ref/api-io.texi (I/O Extensions): Update documentation on implementing port types. Document get_natural_buffer_sizes. Document the new random_access_p. * libguile/fports.c (scm_i_fdes_to_port, fport_random_access_p): (scm_make_fptob): Instead of frobbing rw_random manually, implement a random_access_p function. * libguile/ports.c (default_random_access_p) (scm_set_port_random_access_p): New functions. scm_make_port_type, scm_c_make_port_with_encoding): Arrange for random_access_p to work.
* Remove scm_puts_unlocked.Andy Wingo2016-04-261-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * libguile/ports.h (scm_puts_unlocked): Remove. * libguile/ports.c (scm_puts): Replace implementation with scm_puts_unlocked's implementation. * libguile/arbiters.c: * libguile/backtrace.c: * libguile/bitvectors.c: * libguile/continuations.c: * libguile/deprecation.c: * libguile/dynl.c: * libguile/eval.c: * libguile/filesys.c: * libguile/fluids.c: * libguile/foreign.c: * libguile/fports.c: * libguile/frames.c: * libguile/guardians.c: * libguile/hashtab.c: * libguile/hooks.c: * libguile/load.c: * libguile/macros.c: * libguile/mallocs.c: * libguile/print.c: * libguile/programs.c: * libguile/promises.c: * libguile/smob.c: * libguile/srcprop.c: * libguile/srfi-14.c: * libguile/stackchk.c: * libguile/struct.c: * libguile/threads.c: * libguile/throw.c: * libguile/values.c: * libguile/variable.c: * libguile/vm.c: * libguile/weak-set.c: * libguile/weak-table.c: Use scm_puts instead of scm_puts_unlocked.
* Remove scm_putc_unlocked.Andy Wingo2016-04-261-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * libguile/ports.h (scm_putc_unlocked): Remove. * libguile/ports.c (scm_putc): Replace implementation with scm_putc_unlocked's implementation. (scm_port_print): Use scm_putc. * libguile/arbiters.c: * libguile/arrays.c: * libguile/bitvectors.c: * libguile/bytevectors.c: * libguile/continuations.c: * libguile/dynl.c: * libguile/eval.c: * libguile/filesys.c: * libguile/fluids.c: * libguile/foreign.c: * libguile/fports.c: * libguile/frames.c: * libguile/hashtab.c: * libguile/hooks.c: * libguile/macros.c: * libguile/mallocs.c: * libguile/print.c: * libguile/programs.c: * libguile/promises.c: * libguile/r6rs-ports.c: * libguile/smob.c: * libguile/srcprop.c: * libguile/struct.c: * libguile/variable.c: * libguile/weak-set.c: * libguile/weak-table.c: Use scm_putc instead of scm_putc_unlocked.
* Load port bindings in separate (ice-9 ports) moduleAndy Wingo2016-04-151-4/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | * module/ice-9/ports.scm: New file. * am/bootstrap.am (SOURCES): Add ice-9/ports.scm. * libguile/fports.c (scm_init_ice_9_fports): New function. (scm_init_fports): Arrange for scm_init_ice_9_fports to be called via load-extension, and load snarfed things there. Move open-file definition early, to allow ports to bootstrap. * libguile/ioext.c (scm_init_ice_9_ioext): New function. (scm_init_ioext): Similarly, register scm_init_ice_9_ioext as an extension. * libguile/ports.c (scm_set_current_input_port) (scm_set_current_output_port, scm_set_current_error_port): Don't define Scheme bindings; do that in Scheme. * libguile/ports.c (scm_i_set_default_port_encoding): (scm_i_default_port_encoding, scm_i_default_port_conversion_handler): (scm_i_set_default_port_conversion_handler): Since we now init encoding early, remove the "init" flags on these encoding/strategy vars. (scm_init_ice_9_ports): New function. (scm_init_ports): Register scm_init_ice_9_ports extension, and define some bindings needed by the bootstrap. * module/Makefile.am (SOURCES): Add ice-9/ports.scm. * module/ice-9/boot-9.scm: Remove code that's not on the boot path, moving it to ice-9/ports.scm. At the end, load (ice-9 ports). * module/ice-9/psyntax.scm (include): Use close-port instead of close-input-port. * module/ice-9/psyntax-pp.scm (include): Regenerate.
* Port read/write functions take bytevectorsAndy Wingo2016-04-111-13/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Generic port facility provides buffering uniformlyAndy Wingo2016-04-061-204/+40
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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.
* Port close functions return voidAndy Wingo2016-04-051-6/+2
| | | | | | | | | | | | | | | * libguile/ports.h (scm_t_ptob_descriptor): The port close function now returns void. (scm_set_port_close): Adapt prototype. * libguile/ports.c (scm_close_port): Always return true if we managed to call the close function. There's no other sensible result; exceptions are handled, well, exceptionally. * libguile/fports.c (fport_close) * libguile/r6rs-ports.c (custom_binary_port_close, transcoded_port_close): * libguile/vports.c (soft_port_close): Adapt. * doc/ref/api-io.texi (Port Implementation): Update.
* Flush buffered reads / writes before seekingAndy Wingo2016-04-041-40/+2
| | | | | | | | | | | * 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.
* Refactor to rw_random / rw_active port flagsAndy Wingo2016-04-041-2/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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.
* Remove port free functions; just close insteadAndy Wingo2016-04-041-8/+1
| | | | | | | | | | | | | | | | | | | | | * libguile/ports.h (scm_t_port_type_flags): Replace SCM_PORT_TYPE_HAS_FLUSH with SCM_PORT_TYPE_NEEDS_CLOSE_ON_GC. (scm_t_ptob_descriptor): Remove free function. * libguile/ports.c (scm_set_port_needs_close_on_gc): New function. (scm_set_port_flush): Don't set flags. (scm_c_make_port_with_encoding, scm_close_port): Use the new flag to determine when to add a finalizer and also when to include the port in the weak set. (scm_set_port_free): Remove. (do_close, finalize_port): Close port instead of calling free function. * libguile/r6rs-ports.c (initialize_transcoded_ports): * libguile/vports.c (scm_make_sfptob): * libguile/fports.c (scm_make_fptob): Mark these ports as needing close on GC. * libguile/fports.c (fport_free): Remove. * NEWS: Update. * doc/ref/api-io.texi (Port Implementation): Update.
* Move line-buffing machinery to ports.cAndy Wingo2016-04-041-4/+0
| | | | | | * libguile/ports.c (scm_lfwrite_unlocked): * libguile/fports.c (fport_write): Move line-buffering from fport_write to scm_lfwrite_unlocked.
* Move setvbuf impl to ports.[ch]Andy Wingo2016-04-041-103/+0
| | | | | | | | * libguile/fports.h (scm_setbuf0): Remove extraneous declaration. * libguile/fports.c: * libguile/ports.c: * libguile/ports.c (scm_setvbuf): Move setvbuf to ports.[ch]. (scm_init_ports): Move _IONBF, _IOLBF, _IOFBF definitions here.
* Merge commit '37b1453032488de582175270d1b3a1653ea81457'Andy Wingo2015-01-221-4/+7
|\
| * Avoid converting the 'mode' argument of 'open-file'.Ludovic Courtès2015-01-111-4/+7
| | | | | | | | | | | | | | | | | | * libguile/fports.c (scm_open_file_with_encoding): const-qualify 'md' and 'ptr'. Add call to 'scm_i_try_narrow_string'. Use 'scm_i_string_chars' instead of 'scm_to_locale_string' plus ' scm_dynwind_free'. * test-suite/tests/ports.test ("invalid wide mode string", "valid wide mode string"): New tests.
* | Merge branch 'stable-2.0'Mark H Weaver2014-09-301-1/+1
|\ \ | |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: benchmark-suite/benchmarks/ports.bm libguile/async.h libguile/bytevectors.c libguile/foreign.c libguile/gsubr.c libguile/srfi-1.c libguile/vm-engine.h libguile/vm-i-scheme.c module/Makefile.am module/language/tree-il/analyze.scm module/language/tree-il/peval.scm module/scripts/compile.scm module/scripts/disassemble.scm test-suite/tests/asm-to-bytecode.test test-suite/tests/peval.test test-suite/tests/rdelim.test