scm_string_join: properly sequence operations in ADD_TO_APPEND_LIST

* libguile/srfi-13.c (scm_string_join): Properly sequence operations in
  ADD_TO_APPEND_LIST macro.
Fix broken texinfo markup in (ice-9 iconv) docs.

* doc/ref/api-data.texi (Representing Strings as Bytes): Fix broken
  @deffn syntax.
Add 'scm_gc_typed_calloc' macro.

* libguile/gc.h (scm_gc_typed_calloc): New macro.
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.
Refactor port encoding modes: utf-8 and iconv

Based on 6c98257f2ead0855f218369ea7f9a823cdb9727e by Andy Wingo.

* libguile/ports-internal.h (struct scm_port_internal): Add a flag
  for the port encoding mode: UTF8 or iconv.  The iconv descriptors
  are now in a separate structure so that we can avoid attaching
  finalizers to the ports themselves in the future.
  (enum scm_port_encoding_mode): New enum.
  (struct scm_iconv_descriptors): New struct.
  (scm_i_port_iconv_descriptors): Add prototype.

* libguile/ports.c (finalize_port): Don't close iconv descriptors here.
  (scm_new_port_table_entry): Adapt to the iconv descriptors being
  moved.  Initialize 'encoding_mode'.
  (scm_i_remove_port): Adapt to call 'close_iconv_descriptors'.
  (close_iconv_descriptors): New static function.
  (get_iconv_codepoint): Use 'scm_i_port_iconv_descriptors'.
  (get_codepoint): Check the port 'encoding_mode'.
  (finalize_iconv_descriptors, open_iconv_descriptors,
  close_iconv_descriptors, scm_i_port_iconv_descriptors): New static
  functions.
  (scm_i_set_port_encoding_x): Adapt to iconv descriptors being moved
  to separate structure, to set the 'encoding_mode' flag, and to use
  'open_iconv_descriptors' and 'close_iconv_descriptors'.

* libguile/print.c (display_string_using_iconv): Use
  'scm_i_port_iconv_descriptors'.
  (display_string): Use 'encoding_mode' flag.
Optimize 'get-bytevector-some'; it may now read less than possible.

* libguile/r6rs-ports.c (scm_get_bytevector_some): Rewrite to
  efficiently take the contents of the read/putback buffers.  In the
  docstring, clarify that it might not return all available bytes.

* doc/ref/api-io.texi (R6RS Binary Input): Clarify that
  'get-bytevector-some' might not return all available bytes.

* test-suite/tests/r6rs-ports.test ("get-bytevector-some [only-some]"):
  Remove bogus test, which requires more than the R6RS requires.
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'.
Add a static version of 'scm_fill_input' to ports.c.

* libguile/ports.c (scm_i_fill_input): New static function, containing
  the code that was previously in 'scm_fill_input'.
  (scm_fill_input): Simply call 'scm_i_fill_input'.
  (scm_c_read): Use 'scm_i_fill_input'.
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.
Rewrite get_iconv_codepoint to fix a bug involving byte-order marks.

* libguile/ports.c (get_iconv_codepoint): Rewrite to fix a bug and
  improve efficiency and clarity.  Previously, it incorrectly assumed
  that iconv would never consume input without producing output, which
  led to a buffer overrun and subsequent assertion failure.  This
  happens when a byte-order mark is consumed by iconv at the beginning
  of the stream when using the UTF-16 or UTF-32 encodings.

* test-suite/tests/ports.test (unicode byte-order marks (BOMs)):
  Add tests.
Remove uses of GC_PTR in 'finalize_iconv_descriptors'.

* libguile/ports.c (finalize_iconv_descriptors): Change GC_PTR to
  (void *) in parameter types.
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.
Remove BOM tests that depend on GNU iconv behavior.

* test-suite/tests/ports.test ("unicode byte-order marks (BOMs)"):
  Remove tests that depend on GNU iconv behavior.  We will add them back
  when we have portable BOM support.
Remove double indirection in element access in array-copy!

* libguile/array-map.c: (racp): factor scm_generalized_vector_ref,
  scm_generalized_vector_set_x out of the rank-1 loop.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
Use 'strcasecmp' to compare encoding names.

Reported by Ludovic Courtès <ludo@gnu.org>.

* libguile/ports.c (scm_new_port_table_entry,
  scm_i_set_default_port_encoding, scm_i_set_port_encoding_x):
  libguile/read.c (scm_i_scan_for_encoding): Use 'strcasecmp' to compare
  encoding names.
Deprecate dead code in array-map.c

* libguile/array-map.c, libguile/array-map.h: deprecate scm_ra_eqp,
  scm_ra_lessp, scm_ra_leqp, scm_ra_grp, scm_ra_greqp, scm_ra_sum,
  scm_ra_product, scm_ra_difference, scm_ra_divide, scm_array_identity.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
Avoid per-element cons for 1-arg case of array-map!

* libguile/array-map.c: (ramap): special case when ras is a 1-element list.
Remove double indirection in array-map! with <2 args

* libguile/array-map.c: (ramap): factor GVSET/GVREF out of rank-1 loop
  for ra0 and the first element of ras.
tests: Use `pass-if-equal' in ramap.test.

* test-suite/tests/ramap.test ("array-for-each"): Use `pass-if-equal'
  instead of `(pass-if ... (equal? ...))'.
tests: Add `array-for-each' tests for one-dimensional traversals.

* test-suite/tests/ramap.test ("array-for-each")["1 source"]: New test
  prefix.