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

9315 commits

Author SHA1 Message Date
Ludovic Courtès
ab2fd70ef1 'strftime' and 'strptime' honor the locale encoding.
Fixes <https://bugs.gnu.org/35920>.
Reported by Christopher Lam <christopher.lck@gmail.com>.

* libguile/stime.c (scm_strftime): Use 'scm_to_locale_stringn' instead
of 'scm_to_utf8_stringn'.
(scm_strptime): Likewise, and use 'scm_string_length' instead of
'u8_strnlen'.
* test-suite/tests/time.test ("strftime")["strftime passes wide
characters"]: Wrap body in 'with-locale'.
["strftime fr_FR.utf8", "strftime fr_FR.iso88591"]: New tests.
("strptime")["strftime fr_FR.utf8", "strftime fr_FR.iso88591"]: New
tests.
2019-06-30 21:31:36 +02:00
Ludovic Courtès
f4f9d177f0 Remove references to 'inet-ntoa' and 'inet-aton'.
These procedures were removed in Guile 2.2 by commit
fc7bd367ab (May 2011).

* libguile/socket.h (scm_inet_aton, scm_inet_ntoa): Remove.
* module/system/repl/server.scm (make-tcp-server-socket): Use
'inet-pton' instead of 'inet-aton'.
* doc/ref/web.texi (HTTP): Likewise in 'declare-header!' example.
* doc/ref/posix.texi (Network Address Conversion): Remove documentation
of 'inet-ntoa' and 'inet-aton'.
2019-06-24 15:10:13 +02:00
Andy Wingo
89e28df1c9 Add an inlined jit fast-path for allocate-words/immediate
* libguile/intrinsics.c (allocate_words_with_freelist)
  (scm_bootstrap_intrinsics):
* libguile/intrinsics.h (SCM_FOR_ALL_VM_INTRINSICS): New intrinsic.
* libguile/jit.c (compile_allocate_words_immediate): Add fast-path.
  A marginal improvement.
2019-06-20 14:02:05 +02:00
Andy Wingo
33aecf48b0 Inline freelist vectors into scm_thread
* libguile/gc-inline.h:
* libguile/threads.h (SCM_INLINE_GC_GRANULE_WORDS)
  (SCM_INLINE_GC_GRANULE_BYTES, SCM_INLINE_GC_FREELIST_COUNT): Move
  definitions here, from gc-inline.h.
  (struct scm_thread): Inline freelist vectors.
* libguile/threads.c (thread_mark): Update marker for pointerless
  freelists.
  (on_thread_exit): Clear individual freelist entries, instead of the
  vector as a whole.
  (guilify_self_2): No need to alloc freelist vectors.
2019-06-20 13:48:24 +02:00
Andy Wingo
117bb3bade Rearrange scm_thread for better locality
* libguile/threads.h (struct scm_thread): Move async-related bits up, so
  that the VM can access them easier.  Likewise for freelists (which we
  will inline soon).
2019-06-20 13:37:47 +02:00
Andy Wingo
cce222d189 Fix compilation on GCC 5.5
* libguile/jit.c (OLD_FP_FOR_RETURN_TRAMPOLINE): Initialize static const
  var from CPP define instead of T0.
  (compile_return_values, emit_return_to_interpreter_trampoline): Adapt
  to upper-casing.
2019-06-20 12:07:40 +02:00
Ludovic Courtès
8cf7b06d24 Copy terminating zero in 'scm_cat_path'.
* libguile/script.c (scm_cat_path): Pass N + 1, not N, to 'strncat'.
Reported by GCC 9.1.0.
2019-06-20 11:43:54 +02:00
Ludovic Courtès
d59dc5fbf2 srfi-14: Fix possible buffer overrun in '%char-set-dump'.
* libguile/srfi-14.c (scm_sys_char_set_dump): Change array size from 9
to 11 as suggested by GCC 9.1.0.
2019-06-20 11:34:46 +02:00
Andy Wingo
7cbbc83dcb Use call/return instructions for non-tail calls
This change speeds up the indirect branches at return sites by taking
advantage of the CPU's return address stack.

* libguile/jit.c (emit_push_frame): Don't store the mra; we do that via
  a trampoline.
  (emit_handle_interrupts_trampoline): Take MRA from link register
  instead of T0.
  (compile_call, compile_call_label): Compute MRA via the new
  jmpi_with_link lightening instruction.
  (compile_return_values): Return to caller via ret instead of jmp.
  (compile_handle_interrupts): Jump to handle-interrupts trampoline via
  jmpi_with_link, to provide the MRA.
  (initialize_jit): Bless the trampolines so that they are valid
  operands to BX on ARM.
2019-06-20 10:55:24 +02:00
Andy Wingo
3b7061323e Merge remote-tracking branch 'lightening/master' 2019-06-20 10:55:13 +02:00
Andy Wingo
acce0297ff Merge remote-tracking branch 'lightening/master' 2019-06-20 10:15:24 +02:00
Andy Wingo
af72d01de8 Speed up returns in JIT
This patch is a bit unfortunate, in the sense that it exposes some of
the JIT guts to the rest of the VM.  Code needs to treat "machine return
addresses" as valid if non-NULL (as before) and also not equal to a
tier-down trampoline.  This is because tier-down at a return needs the
old frame pointer to load the "virtual return address", and the way this
patch works is that it passes the vra in a well-known register.  It's a
custom calling convention for a certain kind of return.

* libguile/jit.h (scm_jit_return_to_interpreter_trampoline): New
  internal global.
* libguile/jit.c: (scm_jit_clear_mcode_return_addresses): Move here,
  from vm.c.  Instead of zeroing return addresses, set them to the
  return-to-interpreter trampoline.
* libguile/vm-engine.c (return-values): Don't enter mcode if the mra is
  scm_jit_return_to_interpreter_trampoline.
* libguile/vm.c (capture_continuation): Treat the tier-down trampoline
  as NULL.
2019-06-18 21:45:29 +02:00
Andy Wingo
e8203a3f8c jit: Direct tail calls assert that target can have mcode
* libguile/jit.c (emit_direct_tail_call): Assert that the callee label
  starts with an instrument-entry.
2019-06-18 21:26:34 +02:00
Mark H Weaver
579dd2da44 Rename 'scm_c_make_char' to 'scm_i_make_char'.
* libguile/chars.c, libguile/chars.h, libguile/ports.c,
libguile/print.c, libguile/read.c, libguile/srfi-13.c,
libguile/strings.c, libguile/vm-engine.c: Rename 'scm_c_make_char' to
'scm_i_make_char'.
2019-06-18 07:30:54 -04:00
Mark H Weaver
a17b727963 fport_seek: Eliminate a fruitless use of 'off_t_or_off64_t'.
This is a followup to commit 91ba73b397.

* 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.
2019-06-18 03:35:36 -04:00
Mark H Weaver
521f1ab470 open-process: Fix dup(2) and execvp(2) error handling.
Previously, in the case where OUT is 0, or ERR is 0 or 1,
e.g. when (current-error-port) points to STDOUT, the code in
'start_child' to relocate OUT/ERR out of the way to another file
descriptor had multiple bugs:

(1) It neglected to close the original file descriptor.

(2) It checked 'errno' without first checking the return value of
    dup(2).  This doesn't work because dup(2) leaves 'errno' unchanged
    if there's no error.

(3) In case 'errno' contained EINTR, the retry code failed because
    OUT (or ERR) was overwritten by the result of the previous failed
    dup(2) call.

This commit fixes these problems, as well as another problem with
'execvp' error reporting.

* libguile/posix.c (renumber_file_descriptor): New static helper
function.
(start_child): Use 'renumber_file_descriptor'.  If 'execvp' fails, write
the error message to file descriptor 2.  Previously, we wrote the error
message to ERR, which was the old file descriptor before being relocated
to 2.
2019-06-18 03:07:27 -04:00
Mark H Weaver
3ec7afb2c6 Refresh a stale comment.
* libguile/numbers.h: In a comment, update the count of number subtypes.
2019-06-18 03:05:05 -04:00
Mark H Weaver
9f7a824206 scm_mkstrport: Optimize the POS -> BYTE_POS conversion.
* libguile/strports.c (scm_mkstrport): Use 'scm_c_string_utf8_length' to
avoid the conversion to UTF-8.
2019-06-18 03:04:41 -04:00
Mark H Weaver
cc73c2ab5d Add get-bytevector-some!.
* libguile/r6rs-ports.c (scm_get_bytevector_some_x): New procedure.
* libguile/r6rs-ports.h (scm_get_bytevector_some_x): Add prototype.
(scm_unget_bytevector): Move prototype next to 'scm_get_bytevector_some_x'.
* module/ice-9/binary-ports.scm: Export 'get-bytevector-some!'.
* doc/ref/api-io.texi (Binary I/O): Document it.
2019-06-18 02:05:20 -04:00
Mark H Weaver
a23ee74fab scm_to_stringn: Avoid passing NULL to c_strcasecmp.
Reported by Massimiliano Gubinelli <m.gubinelli@gmail.com> in
<https://lists.gnu.org/archive/html/guile-user/2019-05/msg00070.html>.

* libguile/strings.c (scm_to_stringn): Check for (encoding == NULL)
before passing it to 'c_strcasecmp'.  Eliminate redundant 'enc'
variable.
2019-06-18 02:05:20 -04:00
Mark H Weaver
a90de2a4c8 Fix typo in tags.h comment.
* libguile/tags.h: Fix typo in comment.
2019-06-18 02:05:20 -04:00
Mark H Weaver
03de93dd5f Save and restore errno in the signal handler.
* libguile/scmsigs.c (take_signal): Save and restore errno.
2019-06-18 02:05:20 -04:00
Mark H Weaver
91ba73b397 Improve overflow checks in bytevector, string, and I/O operations.
* 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'.
2019-06-18 02:05:20 -04:00
Andy Wingo
f07fadc72e VM does not initialize stack frames
* libguile/jit.c (compile_alloc_frame): Stop initializing locals.
  (compile_bind_rest): Use emit_alloc_frame.
* libguile/vm-engine.c (assert_nargs_ee_locals, allocate_frame): Don't
  initialize locals.
  (bind_rest): Don't initialize locals, and assert that the locals count
  has a minimum.
2019-06-06 17:39:53 +02:00
Andy Wingo
c86758c298 Allow for bind-optionals without alloc-frame
This reduces subr trampoline instruction count for subrs with optional
args.

* libguile/gsubr.c (get_subr_stub_code): Insert bind-optionals
  instructions.
  (primitive_call_ip): Handle bind-optionals.
* libguile/programs.c (try_parse_arity): Handle bind-optionals.
* libguile/jit.c (struct scm_jit_state)
  (compile_call, compile_call_label, compile_tail_call)
  (compile_tail_call_label, compile_receive), compile_receive_values)
  (compile_shuffle_down, compile_return_values, compile_subr_call)
  (compile_foreign_call, compile_continuation_call)
  (compile_compose_continuation, compile_abort, compile_assert_nargs_ee)
  (compile_assert_nargs_ge, compile_assert_nargs_le)
  (compile_alloc_frame, compile_reset_frame, compile_push)
  (compile_pop, compile_drop, compile_expand_apply_argument)
  (compile_bind_kwargs, compile_bind_rest, compile_bind_optionals)
  (compile, compute_mcode): Separately track min and max frame sizes.
2019-06-06 17:26:59 +02:00
Andy Wingo
9fd978ed7e Add bind-optionals instruction
* doc/ref/vm.texi (Function Prologue Instructions): Document new
  instruction.
* libguile/jit.c (compile_bind_optionals): New compiler.
* libguile/vm-engine.c (VM_NAME): New interpreter.
* module/system/vm/assembler.scm (opt-prelude): Emit bind-optionals as
  appropriate.
* module/system/vm/disassembler.scm (define-stack-effect-parser)
  (code-annotation): Handle bind-optionals.
2019-06-06 16:36:32 +02:00
Andy Wingo
12d6e43176 Avoid saving IP for <? fast-path
* libguile/jit.c (compile_less): Only save IP on slow-path.
2019-06-06 14:39:02 +02:00
Ludovic Courtès
36ad1d24b3 'basename' correctly handles "/" and "//".
* libguile/filesys.c (scm_basename): Special-case "/" and "//".
* test-suite/tests/filesys.test ("basename"): New test prefix.
2019-06-04 21:24:02 +02:00
Andy Wingo
1128dbc444 Remove check for instrument-entry
* libguile/jit.c (emit_indirect_tail_call): If everything starts with
  instrument-entry, and thus has a vcode pointer, no need to emit a
  dynamic check.
2019-05-27 19:22:23 +02:00
Andy Wingo
9c5098ab25 Dynamically assert functions start with instrument-entry
* libguile/jit.c (emit_indirect_tail_call): Add dynamic assertion.
2019-05-27 19:09:12 +02:00
Andy Wingo
1fb39929f9 Reapply atomics inlining
This patch reapplies 230a555976 and
e8d34258be, but fixing a misplaced
comma (!).
2019-05-27 19:05:10 +02:00
Andy Wingo
2ba50e2fe6 Revert "Inline the atomic intrinsics"
This reverts commit 230a555976.
2019-05-27 18:40:42 +02:00
Andy Wingo
d0a95bfbe8 Revert "Fix atomics usage in handle-interrupts JIT."
This reverts commit e8d34258be.
2019-05-27 18:40:41 +02:00
Andy Wingo
49fa49c42d Merge remote-tracking branch 'lightening/master' 2019-05-27 18:30:16 +02:00
Andy Wingo
09e4fc45c1 Merge remote-tracking branch 'lightening/master' 2019-05-27 13:53:09 +02:00
Andy Wingo
e8d34258be Fix atomics usage in handle-interrupts JIT.
* libguile/jit.c (compile_handle_interrupts): Use atomics in
  handle-interrupts.
2019-05-27 12:08:58 +02:00
Andy Wingo
230a555976 Inline the atomic intrinsics
* libguile/intrinsics.h (SCM_FOR_ALL_VM_INTRINSICS):
* libguile/intrinsics.c (scm_bootstrap_intrinsics): Remove the atomic
  intrinsics, as the JIT no longer needs them.
* libguile/vm-engine.c (VM_NAME): Inline the intrinsics.
2019-05-27 12:01:38 +02:00
Andy Wingo
33e07fc56c Use new atomic instructions from lightening
* libguile/jit.c (compile_atomic_scm_ref_immediate):
(compile_atomic_scm_set_immediate):
(compile_atomic_scm_swap_immediate):
(compile_atomic_scm_compare_and_swap_immediate): Use lightening
instructions.
2019-05-27 11:57:36 +02:00
Andy Wingo
803e412f53 Merge remote-tracking branch 'lightening/master' 2019-05-27 11:34:39 +02:00
Andy Wingo
d1c2d7de2f Switch to use atomic_compare_exchange_strong
* libguile/atomics-internal.h (scm_atomic_compare_and_swap_scm): Change
  to use same API as atomic-box-compare-and-swap!.
* libguile/intrinsics.c (atomic_compare_and_swap_scm): Remove loop, as
  we're using the strong variant now.
* libguile/async.c (scm_i_async_pop, scm_i_async_push): Adapt to new API
  of scm_atomic_compare_and_swap_scm.
2019-05-25 17:17:49 +02:00
Mark H Weaver
bd50407d1f Strings, i18n: Limit the use of alloca to approximately 8 kilobytes.
* libguile/i18n.c (SCM_MAX_ALLOCA): New macro.
(SCM_STRING_TO_U32_BUF): Accept an additional variable to remember
whether we used malloc to allocate the buffer.  Use malloc if the
allocation size is greater than SCM_MAX_ALLOCA.
(SCM_CLEANUP_U32_BUF): New macro.
(compare_u32_strings, compare_u32_strings_ci, str_to_case): Adapt.
* libguile/strings.c (SCM_MAX_ALLOCA): New macro.
(normalize_str, unistring_escapes_to_r6rs_escapes): Use malloc if the
allocation size is greater than SCM_MAX_ALLOCA.
* test-suite/tests/i18n.test, test-suite/tests/strings.test: Add tests.
2019-05-23 17:51:36 +02:00
Mark H Weaver
2bfa4f73f1 put-u8: Always write a single byte, regardless of the port encoding.
Previously, 'put-u8' used textual I/O to write a single character,
relying on the usual practice of setting the port encoding to ISO-8859-1
for binary ports.

* libguile/r6rs-ports.c (scm_put_u8): Use 'scm_c_write', not 'scm_putc'.
2019-05-23 17:49:10 +02:00
Mark H Weaver
a3a726c868 Optimize fixnum exact integer square roots.
* libguile/numbers.c (scm_exact_integer_sqrt, scm_sqrt)
(exact_integer_is_perfect_square, exact_integer_floor_square_root):
Where it is trivial to do so, use GMP's low-level mpn functions to
avoid heap allocation.
2019-05-23 17:48:55 +02:00
Mark H Weaver
66ffd93dcf Fix indentation in scm_sum. 2019-05-23 17:48:55 +02:00
Mark H Weaver
506c70e72b Fix typo in comment. 2019-05-23 17:48:55 +02:00
Mark H Weaver
d5c420a888 Add 'scm_c_make_char' and use it where appropriate.
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),
2019-05-23 17:48:46 +02:00
Mark H Weaver
7e208c8f25 Reimplement SCM_MAKE_CHAR to evaluate its argument only once.
The motivation for this change is that SCM_MAKE_CHAR is sometimes passed
an expression that involves a procedure call that is not always trivial.
In other cases, the results are not guaranteed to be the same both
times, which could lead to the creation of invalid SCM objects.

* libguile/chars.h (SCM_MAKE_CHAR): Reimplement.
2019-05-23 17:41:48 +02:00
Andrea Azzarone
fd4ba18bca Fix gc.test "after-gc-hook gets called" failures.
* libguile/scmsigs.c (signal_delivery_thread): Call scm_async_tick to
give any pending asyncs a chance to run before we block indefinitely
waiting for a signal to arrive.
2019-05-23 17:41:10 +02:00
Mark H Weaver
980d8265c2 Avoid passing NULL to 'memcpy' and 'memcmp'.
Reported by Jeffrey Walton <noloader@gmail.com> in
<https://lists.gnu.org/archive/html/guile-devel/2019-03/msg00001.html>.

Note that C11 section 7.1.4 (Use of library functions) states that:
"unless explicitly stated otherwise in the detailed descriptions [of
library functions] that follow: If an argument to a function has an
invalid value (such as ... a null pointer ...) ..., the behavior is
undefined."  Note that 'strxfrm' is an example of a standard C function
that explicitly states otherwise, allowing NULL to be passed in the
first argument if the size argument is zero, but no similar allowance is
specified for 'memcpy' or 'memcmp'.

* libguile/bytevectors.c (scm_uniform_array_to_bytevector): Call memcpy
only if 'byte_len' is non-zero.
* libguile/srfi-14.c (charsets_equal): Call memcmp only if the number of
ranges is non-zero.
* libguile/stime.c (setzone): Pass 1-character buffer to
'scm_to_locale_stringbuf', instead of NULL.
* libguile/strings.c (scm_to_locale_stringbuf): Call memcpy only if the
number of bytes to copy is non-zero.
2019-05-23 17:40:08 +02:00
Michael Gran
69bc964d7b Handle newlib C library's langinfo constant names
The newlib C library (used in Cygwin) has alternative names for
nl_langinfo GNU extensions

* configure.ac (_NL_NUMERIC_GROUPING): new test
* libguile/i18n.c (INT_CURR_SYMBOL, MON_DECIMAL_POINT, MON_THOUSANDS_SEP)
   (MON_GROUPING, POSITIVE_SIGN, NEGATIVE_SIGN, GROUPING, INT_FRAC_DIGITS)
   (FRAC_DIGITS, P_CS_PRECEDES, P_SEP_BY_SPACE, N_CS_PRECEDES, N_SEP_BY_SPACE)
   (P_SIGN_POSN, N_SIGN_POSN, INT_P_CS_PRECEDES, INT_P_SEP_BY_SPACE)
   (INT_N_CS_PRECEDES, INT_N_SEP_BY_SPACE, INT_P_SIGN_POSN, INT_N_SIGN_POSN)
   [HAVE_DECL__NL_NUMERIC_GROUPING]: map to newlib C constants, when present
2019-05-23 17:32:08 +02:00