This reverts the change to SCM_MAKE_CHAR made in the previous commit
63818453ad, which used an arithmetic trick
to avoid evaluating its argument more than once.
Here, we restore the previous implementation of SCM_MAKE_CHAR, which
evaluates its argument twice. Instead, we introduce a new inlinable
function 'scm_c_make_char' and replace uses of SCM_MAKE_CHAR with calls
to 'scm_c_make_char' where appropriate.
* libguile/chars.h (scm_c_make_char): New inline function.
* libguile/inline.c: Include chars.h.
* libguile/srfi-13.c (REF_IN_CHARSET, scm_string_any, scm_string_every)
(scm_string_trim, scm_string_trim_right, scm_string_trim_both)
(scm_string_index, scm_string_index_right, scm_string_skip)
(scm_string_skip_right, scm_string_count, string_titlecase_x)
(string_reverse_x, scm_string_fold, scm_string_fold_right)
(scm_string_for_each, scm_string_filter, scm_string_delete):
Use 'scm_c_make_char' instead of 'SCM_MAKE_CHAR' in cases where the
argument calls a function.
* libguile/chars.c (scm_char_upcase, scm_char_downcase, scm_char_titlecase),
libguile/ports.c (scm_port_decode_char),
libguile/print.c (scm_simple_format),
libguile/read.c (scm_read_character),
libguile/strings.c (scm_string_ref, scm_c_string_ref),
Partial fix for <https://bugs.gnu.org/33044>.
Reported by Tom de Vries <tdevries@suse.de>.
Fix several instances of the mistake of using 'scm_from_locale_*' for C
strings that originally came from a C string literal. Change several
uses of 'scm_from_latin1_*' as well, to promote the practice of writing
code that works for arbitrary C string literals.
Also add missing years to the copyright notices of changed files, based
on the git history.
* libguile/debug-malloc.c, libguile/deprecation.c, libguile/error.c,
libguile/eval.c, libguile/expand.c, libguile/extensions.c,
libguile/filesys.c, libguile/init.c, libguile/load.c,
libguile/modules.c, libguile/pairs.c, libguile/posix.c,
libguile/print.c, libguile/random.c, libguile/read.c,
libguile/regex-posix.c, libguile/snarf.h, libguile/srfi-13.c,
libguile/stacks.c, libguile/stime.c, libguile/strports.c,
libguile/values.c: Use 'scm_from_utf8_*' where appropriate.
* libguile/scm.h (scm_tc7_values): New tc7. Never seen by Scheme, so we
don't need to update it anywhere else.
* libguile/values.h (scm_is_values): New public static inline function.
(scm_i_nvalues, scm_i_value_ref): New private static inline
functions.
(SCM_VALUESP): Use scm_is_value.
(scm_values_2, scm_values_3): New functions.
(scm_values_vtable): Remove; values objects are not structs any more.
* libguile/values.c (scm_i_extract_values_2): Adapt to new values
representation.
(print_values): Remove now-unused function.
(scm_c_nvalues): Use scm_i_nvalues.
(scm_c_value_ref): Use scm_i_value_ref.
(scm_values, scm_c_values): Make the new-style objects, which store
their values inline.
(scm_values_2, scm_values_3): New helpers, to avoid consing little
useless lists.
* libguile/vm-engine.c (halt, subr-call)
* libguile/eval.c (eval): Adapt to new values representation.
* libguile/i18n.c (scm_locale_string_to_integer)
(scm_locale_string_to_integer)
* libguile/numbers.c (scm_i_floor_divide, scm_i_ceiling_divide)
(scm_i_truncate_divide, scm_i_centered_divide, scm_i_round_divide)
(scm_i_exact_integer_sqrt)
* libguile/r6rs-ports.c (make_bytevector_output_port)
* libguile/srfi-1.c (scm_srfi1_partition, scm_srfi1_partition_x)
* libguile/srfi-14.c (scm_char_set_diff_plus_intersection)
(scm_char_set_diff_plus_intersection_x)
* libguile/posix.c (scm_getrlimit, scm_open_process): Adapt to use
scm_values_2 or scm_values_3.
* libguile/print.c (iprin1): Add printer for values objects.
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.
* 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.
* libguile/print.h (SCM_PRINT_STATE_LAYOUT): Use a normal slot instead
of a self slot.
* libguile/print.c (make_print_state): Initialize "handle" slot
manually.
* libguile/struct.c (issue_deprecation_warning_for_self_slots): New
helper, called when making vtables to issue deprecation warnings for
"self" slots. Avoids warning for the "self" slot that's part of the
fixed vtable slots.
(scm_i_struct_inherit_vtable_magic): Call
issue_deprecation_warning_for_self_slots.
* doc/ref/api-data.texi (Vtables, Structure Basics): Remove references
to self slots.
* NEWS: Add entry.
* libguile/struct.c: Replace uses of scm_make_struct with
scm_make_struct_no_tail or scm_c_make_struct.
(scm_make_struct_no_tail): Move this function to C instead of Scheme
to be able to deprecate scm_make_struct.
* libguile/struct.h (scm_make_struct_no_tail): New public declaration.
* libguile/deprecated.h:
* libguile/deprecated.c (scm_make_struct): Deprecate.
* libguile/print.c:
* libguile/procs.c:
* libguile/stacks.c: Replace uses of scm_make_struct with
scm_make_struct_no_tail.
* test-suite/tests/coverage.test:
* test-suite/tests/structs.test: Use make-struct/no-tail instead of
make-struct.
* NEWS: Add entry.
* libguile/Makefile.am (libguile_@GUILE_EFFECTIVE_VERSION@_la_SOURCES):
(DOT_X_FILES, DOT_DOC_FILES, noinst_HEADERS): Add syntax.c and
syntax.h.
* libguile/evalext.c (scm_self_evaluating_p):
* libguile/goops.c (class_syntax, scm_class_of, scm_goops_early_init):
* libguile/init.c (scm_init_guile):
* libguile/print.c (iprin1):
* libguile/tags.h (scm_tc7_syntax):
* module/oop/goops.scm (<syntax>):
* module/system/base/types.scm (%tc7-syntax, cell->object):
* module/system/vm/disassembler.scm (code-annotation): Wire up the new
data type.
* libguile/syntax.c:
* libguile/syntax.h: New files.
* module/ice-9/boot-9.scm: Move new definitions to (system syntax
internal).
* module/system/syntax.scm (print-syntax): New helper.
* module/system/vm/assembler.scm (statically-allocatable?)
(intern-constant, link-data): Arrange to be able to write syntax
objects into images.
* module/language/cps/types.scm (&syntax): New type. Remove
&hash-table; it was never detected, an internal binding, and we need
the bit to avoid going into bignum territory.
* libguile/root.h:
* libguile/root.c: Remove these files.
* libguile/deprecated.h:
* libguile/deprecated.c (scm_internal_cwdr, scm_call_with_dynamic_root)
(scm_dynamic_root, scm_apply_with_dynamic_root): Deprecate.
Remove all root.h usage, which was vestigial.
* module/ice-9/serialize.scm: Use (current-thread) instead
of (dynamic-root).
* libguile/print.c (iprin1): Use scm_c_put_string for strings.
* test-suite/test-suite/lib.scm (exception:encoding-error): Add an
additional expected error string for `encoding-error'.
* libguile/ports-internal.h (scm_t_port): Rework to store iconv
descriptors inline, so that the port finalizer doesn't race with the
iconv descriptor finalizer. Access is serialized through a lock.
Fixes a bug whereby if the port finalizer and the descriptor finalizer
run on different threads, the close-port run by the port finalizer
could try to free the iconv descriptors at the same time as the
descriptor finalizer.
* libguile/ports.c (iconv_lock): New static variable.
(scm_c_make_port_with_encoding): Initialize iconv-related fields.
(scm_close_port): Lock while frobbing iconv descriptors.
(prepare_iconv_descriptors): Adapt.
(scm_specialize_port_encoding_x, scm_i_set_port_encoding_x): Lock
while preparing iconv descriptors.
(scm_port_acquire_iconv_descriptors)
(scm_port_release_iconv_descriptors): New functions, which replace
scm_i_port_iconv_descriptors.
(scm_port_decode_char): Lock around iconv operations.
(port_clear_stream_start_for_bom_write): Acquire iconv descriptors
before checking precise_encoding, to make sure precise_encoding is
initialized.
* libguile/print.c (display_string_using_iconv): Adapt to use the new
interface to get iconv descriptors from a port.
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.
* libguile/print.c (display_string_using_iconv): Remove BOM handling;
this is now handled by scm_lfwrite.
* libguile/ports.c (open_iconv_descriptors): Refactor to take encoding
as a symbol.
(prepare_iconv_descriptors): New helper.
(scm_i_port_iconv_descriptors): Remove scm_t_port_rw_active argument,
and don't sniff UTF-16/UTF-32 byte orders here. Instead BOM handlers
will call prepare_iconv_descriptors.
(scm_c_read_bytes): Call new port_clear_stream_start_for_bom_read
helper.
(port_maybe_consume_initial_byte_order_mark)
(scm_port_maybe_consume_initial_byte_order_mark): Remove. Leaves
Scheme %peek-char broken but it's unused currently so that's OK.
(peek_iconv_codepoint): Fetch iconv descriptors after doing fill-input
because it's fill-input that will sniff the BOM.
(peek_codepoint): Instead of handling BOM at every character, handle
in fill-input instead.
(maybe_consume_bom, port_clear_stream_start_for_bom_read)
(port_clear_stream_start_for_bom_write): New helpers.
(scm_fill_input): Slurp a BOM if needed.
(scm_i_write): Clear the start-of-stream-for-bom-write flag.
(scm_lfwrite): Write a BOM if needed.
* 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.
* 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.
* libguile/print.c (scm_write, scm_display):
* libguile/read.c (set_port_read_option): Remove port locking. Reading
and writing to the same port from multiple threads just must not
crash; it doesn't have to make sense.
This shows a 19% improvement on the "string without escapes"
micro-benchmark of 'write.bm', and 12% on "string with escapes".
* libguile/print.c (iprin1) <scm_tc7_string>: Replace 'scm_i_string_ref'
loop with a call to 'write_string'.
(display_character): Adjust description of return value in comment.
(write_string): New function.
* libguile/print.c (print_vector_or_weak_vector): New static function.
(iprin1): Use 'print_vector_or_weak_vector' in the vector and weak
vector cases.
This is a follow-up to e26ab06.
* libguile/print.c (scm_simple_format): Pass 1 to
SCM_VALIDATE_OPORT_VALUE, for 'destination'.
* test-suite/tests/format.test ("simple-format"): Add test.