1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 11:50:28 +02:00
Commit graph

213 commits

Author SHA1 Message Date
Mark H Weaver
a38024baaa Make port properties accessible from Scheme.
* libguile/ports.c (scm_i_port_alist, scm_i_set_port_alist_x): Removed.
  (scm_i_port_property, scm_i_set_port_property_x): New procedures,
  available from Scheme as '%port-property' and '%set-port-property!'.

* libguile/ports.h (scm_i_port_alist, scm_i_set_port_alist_x): Removed.
  (scm_i_port_property, scm_i_set_port_property_x): New prototypes.

* libguile/read.c (set_port_read_option, init_read_options): Adapt to
  use scm_i_port_property and scm_i_set_port_property_x.
2013-11-23 15:47:31 -05:00
Mark H Weaver
f6f4feb0a2 Merge remote-tracking branch 'origin/stable-2.0'
Conflicts:
	GUILE-VERSION
	libguile/array-map.c
	libguile/fports.h
	libguile/gc.h
	libguile/inline.h
	libguile/ports.c
	libguile/ports.h
	libguile/print.c
	libguile/r6rs-ports.c
	libguile/read.c
	test-suite/tests/00-socket.test
2013-04-14 02:48:33 -04:00
Mark H Weaver
7f6c3f8f00 Implement efficient 'scm_unget_bytes' and 'unget-bytevector'.
* libguile/ports.c (scm_i_unget_bytes): New static function.
  (scm_unget_bytes): New API function.
  (scm_unget_byte): Rewrite to simply call 'scm_i_unget_bytes'.
  (scm_ungetc, scm_peek_char, looking_at_bytes): Use 'scm_i_unget_bytes'.

* libguile/ports.h: Add prototype for 'scm_unget_bytes'.

* libguile/fports.c (scm_setvbuf): Use 'scm_unget_bytes'.

* libguile/r6rs-ports.c (scm_unget_bytevector): New procedure.

* module/ice-9/binary-ports.scm (unget-bytevector): New export.

* doc/ref/api-io.texi (R6RS Binary Input): Add documentation.
  (R6RS I/O Ports): Update brief description of (ice-9 binary-ports) to
  reflect the new reality: it is no longer a subset of (rnrs io ports).

* test-suite/tests/ports.test ("unget-bytevector"): Add test.
2013-04-07 10:14:44 -04:00
Mark H Weaver
e00793d7a9 Rename 'scm_i_get_byte_or_eof' et al; mark them as SCM_API.
* libguile/ports.c (scm_i_get_byte_or_eof, scm_i_peek_byte_or_eof):
  Rename to 'scm_slow_get_byte_or_eof' and 'scm_slow_peek_byte_or_eof',
  respectively.

* libguile/ports.h (scm_i_get_byte_or_eof, scm_i_peek_byte_or_eof):
  Rename to 'scm_slow_get_byte_or_eof' and 'scm_slow_peek_byte_or_eof',
  respectively, and mark them as SCM_API.

* libguile/inline.h (scm_get_byte_or_eof, scm_peek_byte_or_eof): Adjust
  to use the new names.
2013-04-02 19:35:43 -04:00
Mark H Weaver
8a2b596579 Move slow path out of 'scm_get_byte_or_eof' et al.
Suggested by Andy Wingo.

* libguile/inline.h (scm_get_byte_or_eof, scm_peek_byte_or_eof): Keep
  only the fast path here, with fallback to 'scm_i_get_byte_or_eof' and
  'scm_i_peek_byte_or_eof'.

* libguile/ports.c (scm_i_get_byte_or_eof, scm_i_peek_byte_or_eof):
  New internal functions.

* libguile/ports.h (scm_i_get_byte_or_eof, scm_i_peek_byte_or_eof): Add
  prototypes.
2013-04-02 13:43:20 -04:00
Mark H Weaver
05d7f76296 Move the port alist from the hash table to the internal port structure.
* libguile/ports-internal.h (struct scm_port_internal): Add 'alist'
  member.

* libguile/ports.c (scm_i_port_alist, scm_i_set_port_alist_x): New
  internal functions.
  (scm_i_port_weak_hash): Update comment: the hash table is no longer
  used to store the port's alist.
  (scm_new_port_table_entry): Initialize 'alist'.  Store SCM_BOOL_F in
  the port weak hash, not SCM_EOL.

* libguile/ports.h (scm_i_port_alist, scm_i_set_port_alist_x): Add
  protoypes.

* libguile/read.c (set_port_read_option, init_read_options): Access the
  port's alist via 'scm_i_port_alist' and 'scm_i_set_port_alist_x'.
2013-04-01 17:09:17 -04:00
Mark H Weaver
e459855936 Add internal-only port structure and move iconv descriptors there.
* libguile/ports-internal.h: New file.

* libguile/Makefile.am (noinst_HEADERS): Add ports-internal.h.

* libguile/ports.h (scm_t_port): Add a comment mentioning that the
  'input_cd' and 'output_cd' fields of the public structure are no
  longer what they seem to be.

* libguile/ports.c: Include ports-internal.h.

  (finalize_port, scm_i_remove_port, get_iconv_codepoint, get_codepoint,
  scm_i_set_port_encoding_x): Access 'input_cd' and 'output_cd' via the
  new internal port structure.

  (scm_new_port_table_entry): Allocate and initialize the internal port
  structure.

* libguile/print.c: Include ports-internal.h.

  (display_string_using_iconv, display_string): Access 'input_cd' and
  'output_cd' via 'internal' pointer.
2013-04-01 16:13:47 -04:00
Andy Wingo
419c873624 Revert "detect and consume byte-order marks for textual ports"
This reverts commit b2cb557d75, which was
pushed accidentally.
2013-01-30 15:30:31 +01:00
Andy Wingo
b2cb557d75 detect and consume byte-order marks for textual ports
* libguile/ports.h:
* libguile/ports.c (scm_consume_byte_order_mark): New procedure.

* libguile/fports.c (scm_open_file): Call consume-byte-order-mark if we
  are opening a file in "r" mode.

* libguile/read.c (scm_i_scan_for_encoding): Don't do anything about
  byte-order marks.

* libguile/load.c (scm_primitive_load): Add a note about the duplicate
  encoding scan.

* test-suite/tests/filesys.test: Add tests for UTF-8, UTF-16BE, and
  UTF-16LE BOM handling.
2013-01-30 13:52:01 +01:00
Mark H Weaver
fa980bcc0f Merge remote-tracking branch 'origin/stable-2.0'
Moved scm_i_struct_hash from struct.c to hash.c and made it static.

The port's alist is now a field of 'scm_t_port'.

Conflicts:
	libguile/arrays.c
	libguile/hash.c
	libguile/ports.c
	libguile/print.h
	libguile/read.c
2012-10-30 23:46:31 -04:00
Andy Wingo
0dd7c54075 Merge remote-tracking branch 'origin/stable-2.0'
Conflicts:
	libguile/deprecated.c
	libguile/ports.c
	libguile/ports.h
	libguile/strports.c
	test-suite/tests/cse.test
2012-06-22 13:18:02 +02:00
Ludovic Courtès
b22e94db7c Add the `%default-port-conversion-strategy' fluid.
Fixes <http://bugs.gnu.org/11468>.

* libguile/ports.c (scm_conversion_strategy): Remove.
  (default_conversion_strategy_var, sym_error, sym_substitute,
  sym_escape): New variables.
  (scm_i_get_conversion_strategy, scm_i_set_conversion_strategy_x):
  Remove.
  (scm_i_default_port_conversion_handler,
  scm_i_set_default_port_conversion_handler): New functions.
  (scm_port_conversion_strategy): Use
  `scm_i_default_port_conversion_handler' when PORT is #f.
  (scm_set_port_conversion_strategy_x): Use SYM_ERROR, SYM_SUBSTITUTE,
  and SYM_ESCAPE.  Use `scm_i_set_default_port_conversion_handler' when
  PORT is #f.
  (scm_init_ports): Initialize DEFAULT_CONVERSION_STRATEGY_VAR.

* libguile/ports.h: Update declarations accordingly.

* libguile/foreign.c: Change
  `scm_i_get_conversion_strategy (SCM_BOOL_F)' to
  `scm_i_default_port_conversion_handler ()'.
* libguile/strings.c: Likewise.

* test-suite/tests/ports.test ("%default-port-conversion-strategy"): New
  test prefix.

* test-suite/tests/foreign.test ("pointer<->string")["%default-port-conversion-strategy
  is error", "%default-port-conversion-strategy is soft"]: New tests.

* test-suite/test-suite/lib.scm (exception:encoding-error): Allow the
  regexp to match `scm_to_stringn' error messages.

* doc/ref/api-io.texi (Ports): Document `%default-port-conversion-strategy'.
2012-05-31 00:50:36 +02:00
Andy Wingo
a3ded46520 Merge remote-tracking branch 'origin/stable-2.0'
Conflicts:
	libguile/ports.c
	libguile/ports.h
	libguile/read.c
	libguile/vm-i-system.c
2012-05-08 22:43:04 +02:00
Ludovic Courtès
33672b0711 Add missing SCM_API' for scm_take_from_input_buffers'.
* libguile/ports.h (scm_take_from_input_buffers): Add `SCM_API'.
2012-05-08 16:11:13 +02:00
Ludovic Courtès
5bbd632fc3 Make `scm_unget_byte' public.
* libguile/ports.h (scm_unget_byte): Make `SCM_API' instead of
  `SCM_INTERNAL'.
2012-05-06 22:24:47 +02:00
Andy Wingo
79eb47ea47 port i/o optimizations for iso-8859-1
* libguile/ports.h (scm_t_port_encoding_mode):
* libguile/ports.c (scm_c_make_port_with_encoding):
  (scm_i_set_port_encoding_x): Add special treatment for latin1
  encoding.
  (get_latin1_codepoint, get_codepoint): Add latin1 fast-path.

* libguile/print.c (display_string_as_latin1): Add latin1 fastpath.
2012-02-24 23:05:34 +01:00
Andy Wingo
3753e22736 move revealed-count mechanism to fports.c
* libguile/fports.c (scm_revealed_count, scm_port_revealed)
  (scm_set_port_revealed_x, scm_adjust_port_revealed_x): Move these APIs
  here, and only operate on fports.  To keep revealed ports alive, now
  we will just keep them in a data structure that the GC knows about --
  a static list.

* libguile/fports.h: Add revealed count to scm_t_fport, and move decls
  of revealed-count functions here.

* libguile/ports.h:
* libguile/ports.c: Adapt to change.  Remove SCM_REVEALED and
  SCM_SETREVEALED; since they only apply to fports now, keeping them
  around would be inviting type errors.
  (finalize_port): We don't need to worry about resuscitating ports
  here.

* libguile/init.c: Use the scm_set_port_revealed_x function to set the
  revealed counts on stream ports.
2012-02-19 13:30:30 +01:00
Andy Wingo
03a2eeb0cc ports: avoid adding port table entries and finalizers if possible
* libguile/ports.h (scm_t_port_type_flags, scm_t_ptob_descriptor): Add
  flags to ptob descriptors.

* libguile/ports.c (scm_set_port_flush): Set the SCM_PORT_TYPE_HAS_FLUSH
  flag here.
  (scm_c_make_port_with_encoding): Only add ports to the table if
  SCM_PORT_TYPE_HAS_FLUSH is set.  Only add finalizers to ports if there
  is a free function.
  (scm_close_port): Inline scm_i_remove_port here.  Only remove from the
  weak set if SCM_PORT_TYPE_HAS_FLUSH is set.
  (scm_set_port_revealed_x): Add a comment.
2012-02-14 14:10:53 +01:00
Andy Wingo
6c98257f2e refactor port encoding modes: utf-8 and iconv
* libguile/ports.h (struct scm_t_port): Add a flag for the port encoding
  mode: UTF8 or iconv.  The iconv descriptors are now in a separate
  structure so that we can avoid attaching finalizers to the ports
  themselves, in some cases.

* libguile/ports.c (scm_c_make_port_with_encoding): Init the encoding
  mode.
  (scm_i_remove_port): Adapt to call close_iconv_descriptors.
  (finalize_iconv_descriptors, open_iconv_descriptors):
  (close_iconv_descriptors): New infrastructure to manage iconv
  descriptors.
  (scm_i_port_iconv_descriptors): New internal helper.
  (scm_i_set_port_encoding_x): Use open_iconv_descriptors, if needed.
  (get_iconv_codepoint): Use pt->iconv_descriptors.
  (get_codepoint): Check the port encoding mode flags.

* libguile/print.c (display_string_using_iconv): Use
  scm_i_port_iconv_descriptors.
  (display_string): Use pt->encoding_mode flag.
2012-02-14 14:10:53 +01:00
Andy Wingo
04ec290f8b Merge remote-tracking branch 'origin/stable-2.0'
Conflicts:
	libguile/deprecation.c
	libguile/load.c
	libguile/print.c
2011-12-06 19:14:50 +01:00
Andy Wingo
92c0ebac90 port locking refactor
* libguile/ports.h (struct scm_t_port): Make the lock into a pointer
  field instead of an inline field.  It should be possible to make
  unlocked ports by having a NULL lock field.
  (scm_c_lock_port, scm_c_try_lock_port): Return the mutex if the port
  was actually locked.
  (scm_c_unlock_port): Remove.

* libguile/ports.c (scm_c_make_port_with_encoding): For now, leave
  `lock' set to 0.
  Change scm_c_lock_port callers to pay attention to the new API.

* libguile/print.c (scm_write, scm_display): Fix call to
  dynwind-lock-port for ports-with-print-states.
2011-12-06 18:01:45 +01:00
Andy Wingo
3972de7675 add current-warning-port
* libguile/ports.h:
* libguile/ports.c (scm_current_warning_port)
  (scm_set_current_warning_port): New functions, wrapping the Scheme
  parameter.

* module/ice-9/boot-9.scm (current-warning-port): New parameter,
  defining a port for warnings.
2011-12-05 18:07:06 +01:00
Andy Wingo
b86b70fece disable port locking
* libguile/ports.h (scm_c_lock_port, scm_c_try_lock_port)
  (scm_c_unlock_port): Disable port locking until I have time to sort
  out the bugs that are coming up.
2011-11-09 23:02:02 +01:00
Andy Wingo
14dcb5ccd2 add scm_dynwind_lock_port
* libguile/ports.h:
* libguile/ports.c (scm_dynwind_lock_port): New function.
2011-11-08 19:16:33 +01:00
Andy Wingo
f209aeee9f locking for write, lfwrite
* libguile/ports.c (scm_c_write_unlocked, scm_c_write)
  (scm_lfwrite_unlocked, scm_lfwrite): Add locking and _unlocked
  variants.  Change uses to _unlocked.
2011-11-08 00:55:06 +01:00
Andy Wingo
0607ebbfcf locking for putc, puts
* libguile/ports.c (scm_putc, scm_puts):
* libguile/ports.h (scm_putc_unlocked, scm_puts_unlocked): Separate into
  _unlocked and locked variants.  Change all callers to use the
  _unlocked versions.
2011-11-08 00:55:05 +01:00
Andy Wingo
4251ae2e28 locking on port buffering operations
* libguile/ports.c (scm_fill_input_unlocked, scm_fill_input)
  (scm_end_input, scm_end_input_unlocked, scm_flush)
  (scm_flush_unlocked): Add locking and _unlocked variants.

* libguile/filesys.c:
* libguile/fports.c:
* libguile/gdbint.c:
* libguile/r6rs-ports.c:
* libguile/read.c:
* libguile/rw.c: Adapt callers to use _unlocked variants.
2011-11-08 00:55:01 +01:00
Andy Wingo
c932ce0b55 locking on unget_byte, ungetc, ungets
* libguile/ports.h:
* libguile/ports.c (scm_unget_byte_unlocked, scm_unget_byte)
  (scm_ungetc_unlocked, scm_ungetc, scm_ungets_unlocked, scm_ungets):
  Add locking and _unlocked variants.

* libguile/arrays.c:
* libguile/rdelim.c:
* libguile/read.c:
* libguile/vports.c: Adapt callers to use the _unlocked variants.
2011-11-08 00:54:58 +01:00
Andy Wingo
be632904ca locking on scm_c_read, scm_getc
* libguile/ports.c (scm_c_read_unlocked, scm_c_read, scm_getc_unlocked)
  (scm_getc): Split getc and read operations into locked and unlocked
  variants.  Change most uses to use the _unlocked version.
2011-11-08 00:54:58 +01:00
Andy Wingo
0d959103f9 threadsafe get-byte-or-eof, peek-byte-or-eof
* libguile/ports.h (scm_get_byte_or_eof_unlocked):
  (scm_peek_byte_or_eof_unlocked): Rename, adding _unlocked.
* libguile/ports.c (scm_get_byte_or_eof, scm_peek_byte_or_eof): Add
  locking implementations.  Adapt callers to use _unlocked variants;
  they will do locking.

* libguile/read.c (read_token, scm_read_semicolon_comment)
  (scm_read_shebang): Use unlocked variants.  We will add locking
  later.
2011-11-08 00:54:57 +01:00
Andy Wingo
b262d3065c threadsafe port revealed counts
* libguile/ports.h:
* libguile/ports.c (scm_revealed_count, scm_set_port_revealed_x): Make
  threadsafe.
  (scm_adjust_port_revealed_x): New function, to adjust a port's
  revealed count in a threadsafe way.
2011-11-08 00:54:52 +01:00
Andy Wingo
285ac79b1a scm_c_lock_port takes a port
* libguile/ports.h (scm_c_lock_port, scm_c_try_lock_port)
  (scm_c_unlock_port): Take a port instead of an entry.
2011-11-08 00:53:57 +01:00
Andy Wingo
19b8d12b16 ports implementation reordering
* libguile/ports.h: Slight reorder.
* libguile/ports.c: Reorder ports implementation to match the header
  file.  This will make it easier to add locking and _unlocked
  variants.
2011-11-07 19:48:50 +01:00
Andy Wingo
62bd5d66cb threadsafe access to scm_ptobs
* libguile/ports.h (SCM_PORT_DESCRIPTOR): New macro, to get at a port
  descriptor in the third word of a port instead of looking it up in a
  table.
  (scm_c_port_type_ref, scm_c_port_type_add_x): New API for working with
  numbered ptob descriptors.
  (SCM_PTOBNAME): Implement in terms of scm_c_port_type_ref.
  (scm_get_byte_or_eof, scm_peek_byte_or_eof): Use SCM_PORT_DESCRIPTOR.

* libguile/ports.c (scm_c_num_port_types, scm_c_port_type_ref)
  (scm_c_port_type_add_x, scm_make_port_type): Protect scm_ptobs access
  with a mutex.  Have it be an array of pointers instead of an array of
  structures.  Adapt users to the new APIs.
  (scm_c_make_port_with_encoding): Allocate ports with three words.  The
  third word is the ptob descriptor.

* libguile/backtrace.c:
* libguile/goops.c:
* libguile/ioext.c:
* libguile/print.c: Adapt to use scm_c_port_type_ref and
  SCM_PORT_DESCRIPTOR.
2011-11-07 18:58:01 +01:00
Andy Wingo
a535e9f54c reorder ports.h declarations
* libguile/ports.h: Reorder declarations.
2011-11-07 17:08:31 +01:00
Andy Wingo
422866a7c6 remove scm_markstream
* libguile/ports.h:
* libguile/ports.c (scm_markstream): Remove obsolete definition.  Moved
  around a couple of other declarations.
2011-11-07 16:25:37 +01:00
Andy Wingo
891702eaef ports.h: remove unimplemented declarations
* libguile/ports.h (scm_grow_port_cbuf, scm_pt_size, scm_pt_member):
  Remove declarations of unimplemented functions.  Move a couple of
  other definitions around.
2011-11-07 16:22:55 +01:00
Andy Wingo
fca1414908 inlined port functions to ports.h
* libguile/inline.h:
* libguile/ports.h (scm_get_byte_or_eof, scm_peek_byte_or_eof)
  (scm_putc, scm_puts): Move definitions here, from inline.h.
2011-11-07 16:14:15 +01:00
Andy Wingo
30b126d2ba add lock to scm_t_port
* libguile/ports.h (scm_c_lock_port, scm_c_try_lock_port)
  (scm_c_unlock_port): New inline functions.
  (scm_t_port): Add a lock field, if threads are enabled.  This is a
  first step towards threadsafe ports.

* libguile/ports.c (scm_c_make_port_with_encoding): Init the port's
  lock.

* libguile/inline.c: Residualize the inline functions from ports.h.
2011-11-07 16:01:01 +01:00
Andy Wingo
dc7da0be90 refactor tc7 and tc16 checks
* libguile/tags.h (SCM_HAS_TYP7, SCM_HAS_TYP7S, SCM_HAS_TYP16): New
  macros.

* libguile/bytevectors.h (SCM_BYTEVECTOR_P):
* libguile/control.h (SCM_PROMPT_P):
* libguile/filesys.h (SCM_DIRP):
* libguile/fluids.h (SCM_WITH_FLUIDS_P, SCM_FLUID_P)
  (SCM_I_DYNAMIC_STATE_P):
* libguile/foreign.h (SCM_POINTER_P):
* libguile/fports.h (SCM_FPORTP):
* libguile/frames.h (SCM_VM_FRAME_P):
* libguile/hashtab.h (SCM_HASHTABLE_P):
* libguile/inline.h (scm_get_byte_or_eof):
* libguile/numbers.h (SCM_REALP, SCM_BIGP, SCM_COMPLEXP, SCM_FRACTIONP):
* libguile/objcodes.h (SCM_OBJCODE_P):
* libguile/ports.h (SCM_OUTPUT_PORT_P):
* libguile/programs.h (SCM_PROGRAM_P):
* libguile/smob.h (SCM_SMOB_PREDICATE):
* libguile/srfi-14.h (SCM_CHARSETP):
* libguile/strings.c (IS_STRING):
* libguile/strports.h (SCM_STRPORTP):
* libguile/symbols.h (scm_is_symbol):
* libguile/variable.h (SCM_VARIABLEP):
* libguile/vectors.h (SCM_I_IS_VECTOR, SCM_I_IS_NONWEAK_VECTOR):
* libguile/vm-i-system.c (call, tail-call, mv-call)
* libguile/vm.h (SCM_VM_P, SCM_VM_CONT_P):
* libguile/weak-set.c (SCM_WEAK_SET_P):
* libguile/weak-table.c (SCM_WEAK_TABLE_P):
* libguile/weak-vector.h (SCM_I_WVECTP): Use them.
2011-10-24 18:54:01 +02:00
Andy Wingo
2721f9182d add scm_c_make_port; the port table is now a weak set
* libguile/ports.c (scm_c_make_port_with_encoding, scm_c_make_port): New
  functions, to replace scm_new_port_table_entry.  Use a weak set
  instead of a weak table.
  (scm_i_remove_port):
  (scm_c_port_for_each, scm_port_for_each): Adapt to use weak set.
  (scm_i_void_port): Use scm_c_make_port.
  (scm_init_ports): Make a weak set.

* libguile/fports.c:
* libguile/ioext.c:
* libguile/r6rs-ports.c:
* libguile/strports.c:
* libguile/vports.c: Adapt to use the new scm_c_make_port API.
2011-10-23 20:52:29 +02:00
Andy Wingo
fc7bd367ab remove all deprecated code
* libguile/async.c:
* libguile/async.h:
* libguile/debug.h:
* libguile/deprecated.c:
* libguile/deprecated.h:
* libguile/evalext.h:
* libguile/gc-malloc.c:
* libguile/gc.h:
* libguile/gen-scmconfig.c:
* libguile/numbers.c:
* libguile/ports.c:
* libguile/ports.h:
* libguile/procprop.c:
* libguile/procprop.h:
* libguile/read.c:
* libguile/socket.c:
* libguile/srfi-4.h:
* libguile/strings.c:
* libguile/strings.h:
* libguile/tags.h:
* module/ice-9/boot-9.scm:
* module/ice-9/deprecated.scm: Remove all deprecated code.  CPP defines
  that were not previously issuing warnings were changed so that their
  expansions would indicate the replacement forms to use,
  e.g. scm_sizet__GONE__REPLACE_WITH__size_t.

  The two exceptions were SCM_LISTN, which did not produce warnings
  before, and the string-filter argument order stuff.

  Drops the initial dirty memory usage of Guile down to 2.8 MB on my
  machine, from 4.4 MB.
2011-05-12 14:01:26 +02:00
Andy Wingo
8269ba5b2c ports.c safely accesses the port weak hash table
* libguile/ports.h (scm_i_remove_port): Remove declaration, as it was
  SCM_INTERNAL.
* libguile/ports.c (scm_add_to_port_table): Issue a deprecation
  warning if this function is called.  Remove needless SCM_API
  declaration, it was already declared as such in ports.h.  Safely
  access the port table.
  (scm_i_remove_port): Remove bogus comment about lack of need for
  threadsafety.  Take the port table mutex.
  (scm_close_port): No need to take port table mutex around calling
  scm_i_remove_port.
2011-02-10 23:16:52 +01:00
Andy Wingo
fcfbe5f96a pre-deprecate scm_ptobs
* libguile/ports.h (scm_t_ptob_descriptor): Add comment about impending
  ptob deprecation.
2011-02-10 23:16:52 +01:00
Ludovic Courtès
9d9c66ba82 Add scm_i_set_default_port_encoding' and scm_i_default_port_encoding'.
* libguile/ports.c (scm_i_set_default_port_encoding,
  scm_i_default_port_encoding): New function.  Replace
  `scm_i_set_port_encoding_x' and `scm_i_get_port_encoding' with
  PORT == SCM_BOOL_F.
  (scm_i_set_port_encoding_x): Assume PORT is a port.
  (scm_i_get_port_encoding): Remove.
  (scm_port_encoding): Adjust accordingly.
  (scm_new_port_table_entry): Use `scm_i_default_port_encoding'.

* libguile/ports.h (scm_i_get_port_encoding): Remove declarations.
  (scm_i_default_port_encoding, scm_i_set_default_port_encoding): New
  declarations.

* libguile/posix.c (setlocale): Use `scm_i_set_default_port_encoding'.
2011-02-10 23:04:43 +01:00
Ludovic Courtès
0c247c332b Add missing include for MinGW.
* libguile/ports.h: Include <unistd.h>.
2011-01-29 22:28:48 +01:00
Ludovic Courtès
a917871527 Remove `scm_lfwrite_str'.
* libguile/ports.c (scm_lfwrite_str): Remove.

* libguile/ports.h (scm_lfwrite_str): Remove declaration.

* libguile/numbers.c (scm_i_print_fraction): Use `scm_display' instead
  of `scm_lfwrite_str'.
2011-01-23 01:14:51 +01:00
Ludovic Courtès
f4bc4e5934 Rewrite read-char', display', etc. using iconv calls instead of libunistring.
Thanks to Bruno Haible for his suggestions.  See
<http://lists.gnu.org/archive/html/bug-libunistring/2010-09/msg00007.html>,
for details.

* libguile/ports.c (register_finalizer_for_port): Always register a
  finalizer for PORT.
  (finalize_port): Close ENTRY->input_cd and ENTRY->output_cd.
  (scm_new_port_table_entry): Initialize the `input_cd' and `output_cd'
  fields.
  (utf8_to_codepoint): New function.
  (get_codepoint): Rewrite to use `iconv' instead of libunistring.
  (scm_i_set_port_encoding_x): Initialize the `input_cd' and `output_cd'
  fields.
  (update_port_lf): Move upward.  Use `switch' instead of `if's.

* libguile/ports.h (scm_t_port)[input_cd, output_cd]: New fields.

* libguile/print.c (codepoint_to_utf8, display_string): New functions.
  (display_character): Use `display_string'.
  (write_combining_character): Likewise.
  (iprin1): Use `display_string' instead of `scm_lfwrite_str', and
  `display_character' instead of `scm_putc'.
  (write_character): Likewise.
  (write_character_escaped): New function.

* test-suite/tests/encoding-escapes.test ("display output
  escapes")["Rashomon"]: Use lower-case escapes.
  ["fake escape"]: New test.
2011-01-23 00:37:25 +01:00
Andy Wingo
dd3a26f3da remove scm_ports_prehistory
* libguile/ports.h:
* libguile/ports.c (scm_ports_prehistory): Remove this function. Just
  initialize global vars to NULL/0 instead of needing a prehistory
  function.
2009-12-05 11:10:11 +01:00
Ludovic Courtès
0eb934f1f0 Use `SCM_DEPRECATED' in declarations of deprecated functions/variables.
* libguile/deprecated.c (SCM_BUILDING_DEPRECATED_CODE): New macro.

* libguile/async.c (SCM_BUILDING_DEPRECATED_CODE): Likewise.

* libguile/macros.c (SCM_BUILDING_DEPRECATED_CODE): Likewise.

* libguile/async.h, libguile/deprecated.h, libguile/eval.h,
  libguile/gc.h, libguile/gc.h, libguile/macros.h, libguile/ports.h,
  libguile/srfi-4.h, libguile/strings.h: Change declarations of
  deprecated functions and variables to use `SCM_DEPRECATED' instead of
  `SCM_API'.
2009-10-02 14:48:22 +02:00