summaryrefslogtreecommitdiff
path: root/libguile/ports.h
Commit message (Collapse)AuthorAgeFilesLines
* Replace uses of scm_t_int8, scm_t_uintmax, etc with stdint typesAndy Wingo2018-06-211-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * libguile/bitvectors.c: * libguile/bitvectors.h: * libguile/bytevectors.c: * libguile/bytevectors.h: * libguile/chars.c: * libguile/continuations.c: * libguile/control.c: * libguile/conv-integer.i.c: * libguile/conv-uinteger.i.c: * libguile/dynstack.c: * libguile/dynstack.h: * libguile/foreign.c: * libguile/frames.c: * libguile/frames.h: * libguile/gc-inline.h: * libguile/gc.h: * libguile/gsubr.c: * libguile/gsubr.h: * libguile/hash.c: * libguile/i18n.c: * libguile/instructions.c: * libguile/intrinsics.c: * libguile/intrinsics.h: * libguile/loader.c: * libguile/loader.h: * libguile/numbers.c: * libguile/numbers.h: * libguile/pairs.c: * libguile/ports-internal.h: * libguile/ports.c: * libguile/ports.h: * libguile/posix.c: * libguile/print.c: * libguile/print.h: * libguile/programs.c: * libguile/programs.h: * libguile/r6rs-ports.c: * libguile/random.c: * libguile/random.h: * libguile/scm.h: * libguile/socket.c: * libguile/srfi-4.c: * libguile/srfi-4.h: * libguile/stacks.c: * libguile/stime.c: * libguile/strings.c: * libguile/struct.c: * libguile/struct.h: * libguile/symbols.c: * libguile/threads.c: * libguile/threads.h: * libguile/uniform.c: * libguile/vm-engine.c: * libguile/vm.c: * libguile/vm.h: * libguile/vports.c: * test-suite/standalone/test-conversion.c: * test-suite/standalone/test-ffi-lib.c: * test-suite/standalone/test-scm-take-u8vector.c: * test-suite/standalone/test-srfi-4.c: Replace e.g. scm_t_uint8 with uint8_t.
* 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.
* Rename __scm.h to scm.hAndy Wingo2018-06-201-2/+0
| | | | * libguile/scm.h: Rename. Update all includers.
* Inline tags.h into __scm.hAndy Wingo2018-06-201-1/+0
| | | | | | | | | | | | | | | | | * libguile/__scm.h: Inline tags.h, and reformat comments. Before, these files used to include each other! * libguile.h: * libguile/atomic.h: * libguile/boolean.c: * libguile/eq.h: * libguile/gc-malloc.c: * libguile/gc.c: * libguile/pairs.c: * libguile/pairs.h: * libguile/ports.h: * libguile/print.c: * libguile/snarf.h: * libguile/tags.h: Remove tags.h includes.
* 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 useless "classes: h_files" from Guile headers.Andy Wingo2018-06-201-2/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * libguile/__scm.h: * libguile/alist.h: * libguile/array-handle.h: * libguile/array-map.h: * libguile/arrays.h: * libguile/async.h: * libguile/backtrace.h: * libguile/bitvectors.h: * libguile/boolean.h: * libguile/chars.h: * libguile/chooks.h: * libguile/continuations.h: * libguile/debug-malloc.h: * libguile/debug.h: * libguile/deprecation.h: * libguile/dynl.h: * libguile/dynstack.h: * libguile/dynwind.h: * libguile/eq.h: * libguile/error.h: * libguile/eval.h: * libguile/evalext.h: * libguile/expand.h: * libguile/extensions.h: * libguile/feature.h: * libguile/filesys.h: * libguile/fluids.h: * libguile/fports.h: * libguile/gc-inline.h: * libguile/gc.h: * libguile/generalized-arrays.h: * libguile/generalized-vectors.h: * libguile/gettext.h: * libguile/goops.h: * libguile/gsubr.h: * libguile/guardians.h: * libguile/hash.h: * libguile/hashtab.h: * libguile/hooks.h: * libguile/i18n.h: * libguile/init.h: * libguile/inline.h: * libguile/ioext.h: * libguile/iselect.h: * libguile/keywords.h: * libguile/list.h: * libguile/load.h: * libguile/macros.h: * libguile/mallocs.c: * libguile/mallocs.h: * libguile/memoize.h: * libguile/modules.h: * libguile/net_db.h: * libguile/null-threads.h: * libguile/numbers.h: * libguile/objprop.h: * libguile/options.h: * libguile/pairs.h: * libguile/poll.h: * libguile/ports.h: * libguile/posix-w32.h: * libguile/posix.h: * libguile/print.h: * libguile/procprop.h: * libguile/procs.h: * libguile/promises.h: * libguile/pthread-threads.h: * libguile/random.h: * libguile/rdelim.h: * libguile/read.h: * libguile/regex-posix.h: * libguile/rw.h: * libguile/scmsigs.h: * libguile/script.h: * libguile/simpos.h: * libguile/smob.h: * libguile/snarf.h: * libguile/socket.h: * libguile/sort.h: * libguile/srcprop.h: * libguile/stackchk.h: * libguile/stacks.h: * libguile/stime.h: * libguile/strings.h: * libguile/strorder.h: * libguile/strports.h: * libguile/struct.h: * libguile/symbols.h: * libguile/syscalls.h: * libguile/tags.h: * libguile/threads.h: * libguile/throw.h: * libguile/trees.h: * libguile/unicode.h: * libguile/uniform.h: * libguile/values.h: * libguile/variable.h: * libguile/vectors.h: * libguile/vports.h: * libguile/weak-list.h: * libguile/weak-set.h: * libguile/weak-table.h: * libguile/weak-vector.h: Remove "classes: h_files". Reformat copyrights if needed.
* Remove <unistd.h> from ports.hAndy Wingo2018-06-191-1/+0
| | | | * libguile/ports.h: Remove <unistd.h>
* Remove <stdio.h> from ports.hAndy Wingo2018-06-191-1/+0
| | | | | | | | | | * libguile/ports.h: Remove <stdio.h>. * libguile/finalizers.c: * libguile/guile.c: * libguile/memoize.c: * libguile/srfi-14.c: * libguile/vm.c: Add <stdio.h>. * libguile/struct.c: Add <stdarg.h>.
* Remove <string.h> include from ports.h.Andy Wingo2018-06-191-1/+0
| | | | | | | | | | | | | | | * libguile/ports.h: Remove <string.h>. * libguile/array-handle.c: * libguile/array-map.c: * libguile/chars.c: * libguile/hash.c: * libguile/memoize.c: * libguile/ports-internal.h: * libguile/regex-posix.c: * libguile/srfi-4.c: * libguile/unicode.c: * libguile/weak-set.c: * libguile/weak-vector.c: Add string.h.
* Devolve vectors.h include from ports.hAndy Wingo2018-06-191-1/+0
| | | | | | | | | | | | * libguile/ports.h: Remove vectors.h include. * libguile/array-handle.c: * libguile/expand.c: * libguile/memoize.c: * libguile/poll.c: * libguile/ports-internal.h: * libguile/srfi-1.c: * libguile/vm.c: * libguile/weak-vector.c: Add vectors.h includes.
* Remove threads.h include from ports.hAndy Wingo2018-06-191-1/+0
|
* Move struct.h include out of ports.hAndy Wingo2018-06-191-1/+0
| | | | | | | * libguile/ports.h: Remove struct.h include. * libguile/expand.h: * libguile/hash.c: * libguile/procs.c: Add struct.h includes.
* Remove bytevectors.h include form ports.hAndy Wingo2018-06-191-1/+0
| | | | | | | | * libguile/ports.h: Remove bytevectors.h include. * libguile/array-handle.c: * libguile/loader.c: * libguile/ports-internal.h: * libguile/socket.c: Add bytevectors.h include.
* Devolve more validate macrosAndy Wingo2018-06-181-2/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * libguile.h: Add chooks.h. * libguile/Makefile.am: Add chooks.h and chooks.c. * libguile/chooks.c: * libguile/chooks.h: New files, for the C implementation of hooks. Broken out to avoid cycles in gc.h includes. * libguile/gc.h: * libguile/gc.c (scm_i_gc_admin_mutex, scm_i_sweep_mutex): Remove unused mutexes. Include chooks instead of hooks in the main header. * libguile/deprecated.h (scm_gc_running_p): Deprecate this macro always defined to 0. (SCM_VALIDATE_VECTOR_OR_DVECTOR): Deprecate this weird one too. * libguile/array-map.c: Add procs.h include. * libguile/threads.h: * libguile/vm.c: * libguile/r6rs-ports.c: Add smob.h include. * libguile/atomic.h (SCM_VALIDATE_ATOMIC_BOX): Devolve. * libguile/deprecation.c (scm_c_issue_deprecation_warning): Remove use of scm_gc_running_p. * libguile/error.c (scm_error_scm): Remove use of scm_gc_running_p. * libguile/filesys.h (SCM_VALIDATE_DIR) * libguile/fluids.h (SCM_VALIDATE_FLUID) * libguile/fports.h (SCM_VALIDATE_FPORT, SCM_VALIDATE_OPFPORT) * libguile/generalized-arrays.h (SCM_VALIDATE_ARRAY) * libguile/hooks.h (SCM_VALIDATE_HOOK) * libguile/keywords.h (SCM_VALIDATE_KEYWORD) * libguile/ports.h (SCM_VALIDATE_PORT, SCM_VALIDATE_INPUT_PORT) (SCM_VALIDATE_OUTPUT_PORT, SCM_VALIDATE_OPINPORT) (SCM_VALIDATE_OPENPORT, SCM_VALIDATE_OPPORT, SCM_VALIDATE_OPOUTPORT) * libguile/procs.h (SCM_VALIDATE_PROC) * libguile/random.h (SCM_VALIDATE_RSTATE) * libguile/regex-posix.h (SCM_VALIDATE_RGXP) * libguile/stacks.h (SCM_VALIDATE_STACK, SCM_VALIDATE_FRAME) * libguile/strports.h (SCM_VALIDATE_OPOUTSTRPORT) * libguile/struct.h (SCM_VALIDATE_STRUCT SCM_VALIDATE_VTABLE) * libguile/symbols.h (SCM_VALIDATE_SYMBOL) * libguile/variable.h (SCM_VALIDATE_VARIABLE) * libguile/vectors.h (SCM_VALIDATE_VECTOR SCM_VALIDATE_VECTOR_LEN): Devolve. * libguile/validate.h: It's empty now! hooks squish
* Prevent TOCTTOU bugs in C portsAndy Wingo2017-02-081-1/+2
| | | | | | | | | | | | | | | | | | | | | | * libguile/ports-internal.h (scm_port_buffer_can_take): (scm_port_buffer_can_put): Add cur/end output arguments so that when a caller asks the buffer room, it can be relative to a fixed point in the buffer and not whatever point it's at when we go to fill it. (scm_port_buffer_did_take, scm_port_buffer_did_put): Similarly, require that the caller knows where they took/put data in the buffer. Prevents overflow. (scm_port_buffer_take_pointer, scm_port_buffer_put_pointer): Likewise, require that the caller has already checked and knows a position in the buffer and therefore how much data is available. (scm_port_buffer_take, scm_port_buffer_put, scm_port_buffer_putback): Adapt. * libguile/ports.h (scm_fill_input): Add cur/avail output arguments. * libguile/filesys.c: * libguile/poll.c: * libguile/ports.c: * libguile/r6rs-ports.c: * libguile/read.c: * libguile/rw.c: Adapt all callers. Gnarly work!
* GC of non-blocking port does not blockAndy Wingo2016-08-311-5/+14
| | | | | | | | | * libguile/ports.h (SCM_F_PORT_FINALIZING) (SCM_PORT_FINALIZING_P, SCM_SET_PORT_FINALIZING): New private definitions. * libguile/ports.c (finalize_port): Set the port-finalizing flag. (scm_i_write_bytes): If the port is finalizing but output returned EWOULDBLOCK, warn and discard the output.
* Remove SCM_I_MAX_PORT_TYPE_COUNTAndy Wingo2016-08-281-3/+0
| | | | | * libguile/ports.h (SCM_I_MAX_PORT_TYPE_COUNT): Remove unused CPP definition.
* put-char, put-string in (ice-9 ports internals)Andy Wingo2016-06-081-0/+1
| | | | | | | | | * libguile/ports.h (scm_put_char): * libguile/ports.c (scm_put_char): New function. (scm_put_string): Add docstrings, and expose to the internal ports module. * module/ice-9/ports.scm (put-char, put-string): Expose these bindings only through the internals module.
* Add scm_c_put_escaped_char, scm_c_can_put_charAndy Wingo2016-05-301-0/+2
| | | | | | * libguile/ports.h: * libguile/ports.c (scm_c_put_escaped_char, scm_c_can_put_char): New helpers.
* Beginnings of supporting encoding text in ports.cAndy Wingo2016-05-301-2/+9
| | | | | | | | | | | | | | | | | | | | | | * libguile/ports.h (scm_c_put_latin1_chars, scm_c_put_utf32_chars) (scm_c_put_char, scm_c_put_string, scm_print_string): New public functions. The plan is to move encoding to ports.c and out of print.c. * libguile/ports.c (UTF8_BUFFER_SIZE, ESCAPE_BUFFER_SIZE): New internal defines. (update_port_position): Take a position instead of a port. Update callers. (utf8_to_codepoint): Allow lengths that are larger than necessary. (port_clear_stream_start_for_bom_write): Require that io_mode be BOM_IO_TEXT to write a BOM. (scm_fill_input): Add a related comment about BOM handling. (scm_i_write): use BOM_IO_TEXT, at least for now. (encode_escape_sequence, codepoint_to_utf8, utf8_to_codepoint) (put_utf8_chars_to_iconv_port, put_latin1_chars_to_utf8_port) (put_latin1_chars_to_iconv_port, put_utf32_chars_to_latin1_port) (put_utf32_chars_to_utf8_port, put_utf32_chars_to_iconv_port): New helpers. (scm_putc, scm_puts): Use scm_c_put_char and scm_put_latin1_chars.
* Speed up scm_c_write / scm_lfwriteAndy Wingo2016-05-241-0/+1
| | | | | | | | | | | | * libguile/ports-internal.h (scm_t_port): Add write_buf_aux field. * libguile/ports.h (scm_port_auxiliary_write_buffer): New internal decl. * libguile/ports.c (AUXILIARY_WRITE_BUFFER_SIZE): New constant. (initialize_port_buffers): Init aux write buf. (scm_port_auxiliary_write_buffer): Lazily allocate an aux write buffer. (scm_c_write): Arrange to write through an aux buffer if the port is unbuffered.
* Speed up port position access from SchemeAndy Wingo2016-05-221-3/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * libguile/ports-internal.h (scm_port_buffer_position): (scm_port_position_line, scm_port_position_set_line): (scm_port_position_column, scm_port_position_set_column): New helpers. (scm_t_port): Ports now hold position as a pair, so that Scheme can access it easily. (SCM_LINUM, SCM_COL, SCM_INCLINE, SCM_ZEROCOL, SCM_INCCOL) (SCM_DECCOL, SCM_TABCOL): Remove. * libguile/ports.c (make_port_buffer): Rename from scm_c_make_port_buffer, make static, and take port as an argument so we can initialize the position field. (initialize_port_buffers): Adapt make_port_buffer change. (scm_c_make_port_with_encoding): Initialize position. (update_port_position): Rename from update_port_lf, and operate on port position objects. (scm_ungetc): Operate on port position objects. (scm_setvbuf, scm_expand_port_read_buffer_x): Adapt to make_port_buffer change. (scm_lfwrite): Adapt to call update_port_position. (scm_port_line, scm_set_port_line_x, scm_port_column) (scm_set_port_column_x): Adapt to use port positions. * libguile/ports.h (scm_c_make_port_buffer): Remove internal decl. * libguile/read.c: Adapt to use scm_port_line / scm_port_column instead of SCM_LINUM et al. * module/ice-9/ports.scm (port-buffer-position, port-position-line) (port-position-column, set-port-position-line!) (set-port-position-column!): New accessors for the internals module. * module/ice-9/sports.scm (advance-port-position!): Rename from port-advance-position! and use the new accessors. (read-char, port-fold-chars/iso-8859-1): Adapt to use advance-port-position!.
* Support for non-blocking I/OAndy Wingo2016-05-201-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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.
* Update port mode bits documentation.Andy Wingo2016-05-141-10/+9
| | | | * libguile/ports.h: Update documentation of port mode bits.
* Use heap-allocated port types instead of ptobnumsAndy Wingo2016-05-131-24/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Make scm_t_ptob_descriptor private.Andy Wingo2016-05-131-30/+1
| | | | | | | * libguile/goops.c: Use port internals header. * libguile/ports-internal.h (scm_t_port_type_flags) (struct scm_t_ptob_descriptor): Make private. * libguile/ports.h: Adapt.
* Make scm_t_port privateAndy Wingo2016-05-131-21/+3
| | | | | | | | | | | | | | | | | * 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.
* Make port buffering fields privateAndy Wingo2016-05-131-51/+0
| | | | | | | | | | | | * libguile/ports-internal.h (enum scm_port_buffer_field) (scm_t_port_internal): Make port buffering fields private. * libguile/ports.h (scm_t_port): Adapt. * libguile/filesys.c (set_element): * libguile/ioext.c (scm_redirect_port): * libguile/poll.c (scm_primitive_poll): * libguile/ports.c: * libguile/read.c (scm_i_scan_for_encoding): * libguile/rw.c (scm_write_string_partial): Adapt users.
* Make file/line/column fields of ports privateAndy Wingo2016-05-131-16/+0
| | | | | | | | | * libguile/ports-internal.h (scm_t_port_internal): Move file_name, line_number, and column_number here. (SCM_FILENAME, SCM_SET_FILENAME, SCM_LINUM, SCM_COL, SCM_INCLINE): (SCM_ZEROCOL, SCM_INCCOL, SCM_DECCOL, SCM_TABCOL): Make internal. * libguile/ports.c (scm_c_make_port_with_encoding) (scm_set_port_line_x, scm_set_port_column_x): Adapt to change.
* Embed scm_t_port in scm_t_port_internalAndy Wingo2016-05-131-3/+0
| | | | | | | | | * libguile/ports-internal.h (scm_t_port_internal) * libguile/ports.h (scm_t_port): Embed scm_t_port in scm_t_port_internal so that we have just one allocation. * libguile/ports-internal.h (SCM_PORT_GET_INTERNAL): Adapt. * libguile/ports.c (scm_i_port_property, scm_i_set_port_property_x) (scm_c_make_port_with_encoding): Adapt.
* Remove SCM backlink in port structureAndy Wingo2016-05-131-3/+0
| | | | | | * libguile/ports.h (scm_t_port): Remove port backlink. * libguile/ports.c (scm_c_make_port_with_encoding, scm_fill_input) (scm_seek): Adapt.
* Add random_access_p port type methodAndy Wingo2016-05-131-0/+3
| | | | | | | | | | | | | * 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.
* Beginnings of shunting ports-in-scheme off to a moduleAndy Wingo2016-05-131-1/+2
| | | | | | | | | | | | | | | | * libguile/ports.c (scm_specialize_port_encoding_x): Add some sanity checks. (scm_unget_bytes): Use scm_expand_port_read_buffer_x. (port_clear_stream_start_for_bom_read): Use scm_specialize_port_encoding_x. (scm_fill_input): Use scm_expand_port_read_buffer_x. (scm_expand_port_read_buffer_x): Rename from scm_set_port_read_buffer_x and actually expand the buffer. * libguile/ports.h: Adapt to scm_expand_port_read_buffer_x change. * module/ice-9/ports.scm: Remove ports-in-scheme stuff, and instead expose the ports internals via an auxiliary module. This will let ports-in-scheme live in a module during Guile 2.2.
* Port refactors to help Scheme peek-charAndy Wingo2016-05-041-0/+3
| | | | | | | | | | | | | | * libguile/ports.h (scm_sys_port_encoding, scm_sys_set_port_encoding): New functions, to expose port encodings as symbols directly to (ice-9 ports). (scm_port_maybe_consume_initial_byte_order_mark): New function. * libguile/ports.c (scm_port_encoding): Dispatch to %port-encoding. (scm_set_port_encoding_x): Dispatch to %set-port-encoding!. (port_maybe_consume_initial_byte_order_mark): New helper, factored out of peek_codepoint. (scm_port_maybe_consume_initial_byte_order_mark, peek_codepoint): Call port_maybe_consume_initial_byte_order_mark. * module/ice-9/ports.scm (port-encoding): Implement in Scheme.
* Port conversion strategies internally are symbolsAndy Wingo2016-05-041-12/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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.
* Port encoding internally represented as symbolAndy Wingo2016-05-031-1/+1
| | | | | | | | | | | | | | | | | | | | * libguile/ports-internal.h (scm_t_port_internal): Remove encoding_mode member. * libguile/ports.h (scm_t_port): "encoding" member is now a SCM symbol. * libguile/ports.c (scm_init_ports): Define symbols for the encodings that we handle explicitly. (encoding_matches): Adapt to check against an encoding as a symbol. (canonicalize_encoding): Return an encoding as a symbol. (scm_c_make_port_with_encoding, scm_i_set_default_port_encoding) (decide_utf16_encoding, decide_utf32_encoding) (scm_i_port_iconv_descriptors, scm_i_set_port_encoding_x) (scm_port_encoding, peek_codepoint, scm_ungetc): Adapt to encoding change. * libguile/print.c (display_string_using_iconv, display_string): * libguile/read.c (scm_read_character): * libguile/strings.c (scm_from_port_stringn, scm_to_port_stringn): Adapt to port encoding change.
* scm_fill_input can guarantee a minimum fill amountAndy Wingo2016-05-011-1/+1
| | | | | | | | | | | | * libguile/ports.h (scm_fill_input): Add "minimum_size" argument. Adapt all callers to pass 0 as this argument. * libguile/ports.c (scm_i_read): Inline into scm_fill_input. (scm_fill_input): "minimum_size" argument ensures that there are a certain number of bytes available, or EOF. Instead of shrinking the read buffer, only fill by the read_buffering amount, or the minimum_size, whichever is larger. * libguile/r6rs-ports.c: * libguile/read.c: Adapt scm_fill_input callers.
* peek-byte in SchemeAndy Wingo2016-04-301-0/+6
| | | | | | | | | | | | | * libguile/ports.c (trampoline_to_c_read, trampoline_to_c_write): Since C might assume that the indices are within bounds of the bytevector, verify them more here. (scm_port_random_access_p, scm_port_read_buffering) (scm_set_port_read_buffer, scm_port_read, scm_port_write): New helpers exposed to (ice-9 ports). (scm_port_read_buffer, scm_port_write_buffer): Don't flush or validate port mode; we do that in Scheme. * module/ice-9/ports.scm: Implement enough of port machinery to implement peek-byte in Scheme. Not yet exported.
* Add SCM port read/write functionsAndy Wingo2016-04-301-2/+7
| | | | | | | | | | | | | | | | | * libguile/ports.h (scm_t_ptob_descriptor): Add "scm_read" and "scm_write" members, for calling from Scheme. (scm_set_port_scm_read, scm_set_port_scm_write): New procedures. * libguile/ports.c (trampoline_to_c_read_subr) (trampoline_to_c_write_subr): New static variables. * libguile/ports.c (scm_make_port_type): Initialize scm_read and scm_write members to trampoline to C. (trampoline_to_c_read, trampoline_to_scm_read) (trampoline_to_c_write, trampoline_to_scm_write): New helpers. (scm_set_port_scm_read, scm_set_port_scm_write): New functions. (default_buffer_size): Move definition down. (scm_i_read_bytes, scm_i_write_bytes): Use new names for read and write procedures. (scm_init_ports): Initialize trampolines.
* Remove port locksAndy Wingo2016-04-281-38/+0
| | | | | | | | | | | * libguile/ports.h (scm_t_port): Remove lock field. (scm_dynwind_lock_port, scm_c_lock_port, scm_c_try_lock_port): Remove. * libguile/ports.c (scm_i_port_property, scm_i_set_port_property_x): Remove locking. * libguile/ports.c (scm_c_make_port_with_encoding): Remove lock. (scm_i_read_bytes, scm_i_read, scm_i_write_bytes, scm_i_write): Remove "_unlocked" from names and adapt callers.
* scm_lfwrite, not scm_lfwrite_unlockedAndy Wingo2016-04-261-1/+0
| | | | | | | * libguile/ports.h (scm_lfwrite_unlocked): Remove. * libguile/ports.c (scm_lfwrite): Rename from scm_lfwrite_unlocked. * libguile/numbers.c: * libguile/print.c: Adapt to call scm_lfwrite.
* Remove scm_c_write_unlockedAndy Wingo2016-04-261-1/+0
| | | | | | | | | | * libguile/ports.h (scm_c_write_bytes_unlocked): Remove. * libguile/ports.c (scm_c_write_bytes): Rename from scm_c_write_bytes_unlocked, make public, and return void. (scm_c_write): Rename from scm_c_write_unlocked. Remove locked variant. (scm_lfwrite_unlocked): Call scm_c_write. * libguile/rw.c (scm_write_string_partial): Call scm_c_write.
* Remove scm_puts_unlocked.Andy Wingo2016-04-261-8/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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-8/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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.
* Remove scm_fill_input_unlockedAndy Wingo2016-04-261-1/+0
| | | | | | | | * libguile/ports.h (scm_fill_input_unlocked): Remove. * libguile/ports.c (scm_fill_input): Rename from scm_fill_input_unlocked. Adapt callers. * libguile/r6rs-ports.c (scm_get_bytevector_some): Adapt. * libguile/read.c (scm_i_scan_for_encoding): Adapt.
* scm_ungetc, scm_ungets instead of _unlocked variantsAndy Wingo2016-04-231-2/+0
| | | | | | | | | | * libguile/ports.h (scm_ungetc_unlocked, scm_ungets_unlocked): Remove; replace with scm_ungetc, scm_ungets. * libguile/ports.c (scm_ungetc, scm_ungets, scm_unread_char) (scm_unread_string): Adapt. * libguile/rdelim.c (scm_read_delimited_x): Use scm_ungetc. * libguile/read.c: Unread characers with scm_ungetc, not scm_ungetc_unlocked.
* Remove scm_unget_{byte,bytes}_unlockedAndy Wingo2016-04-231-2/+0
| | | | | | | | | | | | * libguile/ports.h (scm_unget_bytes_unlocked, scm_unget_byte_unlocked): Remove. * libguile/ports.c (looking_at_bytes): Use scm_unget_bytes instead of scm_i_unget_bytes_unlocked (scm_unget_bytes): Rename from scm_i_unget_bytes_unlocked. Remove other implementations of this function. (scm_unget_byte): Likewise. (scm_ungetc_unlocked, scm_peek_char): Use scm_unget_byte. * libguile/read.c (read_token): Use scm_unget_byte.
* Replace scm_getc with scm_getc_unlockedAndy Wingo2016-04-231-1/+0
| | | | | | | | | | | | | * libguile/ports.h (scm_getc_unlocked): Remove, or rather rename to scm_getc. This probably introduces some thread-related bugs but we'll fix them in a different way. * libguile/ports.c (scm_getc): Rename from scm_getc_unlocked, replacing the locky implementation. (scm_read_char): Use scm_getc. * libguile/r6rs-ports.c (scm_get_string_n_x): Use scm_getc. * libguile/rdelim.c (scm_read_delimited_x, scm_read_line): Use scm_getc. * libguile/read.c: Use scm_getc.
* Remove scm_flush_unlocked / scm_end_input_unlockedAndy Wingo2016-04-231-2/+0
| | | | | | | | | | | | | | | | | | * libguile/ports.h (scm_flush_unlocked, scm_end_input_unlocked): Remove. * libguile/ports.c (scm_c_read_bytes_unlocked): (scm_i_unget_bytes_unlocked, scm_setvbuf, scm_force_output) (scm_fill_input_unlocked, scm_c_write_bytes_unlocked) (scm_c_write_unlocked, scm_lfwrite_unlocked, scm_seek) (scm_truncate_file, flush_output_port): Call scm_flush / scm_end_input instead of the _unlocked variants. (scm_end_input): Lock while discarding the input buffer but not while calling out to the seek function. * libguile/filesys.c (scm_fsync): * libguile/ioext.c (scm_redirect_port): * libguile/read.c (scm_i_scan_for_encoding): * libguile/rw.c (scm_write_string_partial): Use scm_flush, not scm_flush_unlocked.