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

19998 commits

Author SHA1 Message Date
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
1c36f036f6 push/pop of link register does not affect stack size on x86
* lightening/x86-cpu.c (pop_link_register, push_link_register): Don't
  record stack size changes here.
2019-06-20 10:53:12 +02:00
Andy Wingo
acce0297ff Merge remote-tracking branch 'lightening/master' 2019-06-20 10:15:24 +02:00
Andy Wingo
62183fb098 Add jmpi_with_link instruction
The existing calli / callr interface is for ABI calls.  Sometimes though
you want to call some of your own code, just to get the current return
address.  ARM's branch-and-link instructions are ideal for this but they
don't exist on x86; there we emulate them by adding corresponding
pop_link_register / push_link_register instructions that are no-ops on
ARM.

* lightening.h (FOR_EACH_INSTRUCTION): Add jit_jmpi_with_link,
  pop_link_register, push_link_register.
* lightening/arm-cpu.c:
* lightening/x86-cpu.c:
* lightening/aarch64-cpu.c (jmpi_with_link, push_link_register)
  (pop_link_register): Add implementations.
* lightening/arm.h:
* lightening/aarch64.h:
* lightening/x86.h (JIT_LR): New definition.
* tests/link-register.c: New test.
2019-06-20 10:13:37 +02:00
Mark H Weaver
6263d0350b NEWS: Add information to remaining news items.
* NEWS: Update.
2019-06-18 22:23:26 -04:00
Mark H Weaver
4e5b31cd7a NEWS: Fix typo.
* NEWS: Fix typo.
2019-06-18 16:08:36 -04:00
Mark H Weaver
c10b6a3f34 NEWS: More tweaks.
* NEWS: Update.
2019-06-18 15:57:11 -04:00
Mark H Weaver
8e2919b952 NEWS: Add more details.
* NEWS: Update text.
2019-06-18 15:46:43 -04: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
c5c9ec9b1b NEWS: Add more text.
* NEWS: Update.
2019-06-18 14:04:03 -04:00
Mark H Weaver
cbc37f296e NEWS: Add first draft of 2.2.5 changes.
* NEWS: Add draft updates.
2019-06-18 11:53:06 -04:00
Mark H Weaver
1acc40d532 THANKS: Christopher Allan Webber -> Christopher Lemmer Webber.
* THANKS: Update name and re-sort.
2019-06-18 10:57:53 -04:00
Mark H Weaver
b91e42091d Update THANKS.
* THANKS: Thank Christopher Allan Webber, Christopher Baines, and
Timothy Sample for contributions.  Thank Andrea Azzarone, Михаил
Бахтерев, Jonathan Brielmaier, Josh Datko, Massimiliano Gubinelli, Arun
Isaac, Shea Levy, Chris Marusich, Jan Smydke, Tom de Vries, Jeffrey
Walton, and Zefram for fixes.  Move Michael Talbot-Wilson and Michael
Tuexen to their proper place to fix the sorting.
2019-06-18 10:51:53 -04:00
Christopher Baines
4c1901b90f stexi->shtml: Add support for @i, @math, @tie and @dots.
* module/texinfo/html.scm (tag-replacements): Add support for @i
and @math.  The tags used come from the texinfo documentation.
(rules): Convert @tie and @dots to the appropriate HTML entities.
2019-06-18 10:05:55 -04:00
Mark H Weaver
78b261d376 Avoid regexp ranges in HTTP inter-protocol exploitation check.
* module/system/repl/server.scm (permissive-http-request-line?): Avoid
character ranges in regexp.
2019-06-18 08:59:47 -04:00
Mark H Weaver
73cde5ed72 web: Add support for HTTP header continuation lines.
* module/web/http.scm (spaces-and-tabs, space-or-tab?): New variables.
(read-header-line): After reading a header, if a space or tab follows,
read the continuation lines and join them.
* test-suite/tests/web-http.test: Add test.
2019-06-18 08:28:01 -04: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
2d49ffa588 Make 'get-bytevector-n!' suspendable.
* module/ice-9/suspendable-ports.scm (get-bytevector-n!): New procedure.
(get-bytevector-n): Rewrite in terms of 'get-bytevector-n!'.
(port-bindings): Add 'get-bytevector-n!'.
2019-06-18 05:15:07 -04:00
Mark H Weaver
2980b66f6f SRFI-19: Rename 'tai-epoch-in-jd' to 'utc-epoch-in-jd'.
* module/srfi/srfi-19.scm: Rename 'tai-epoch-in-jd' to
'utc-epoch-in-jd', to reflect its actual meaning and usage.
2019-06-18 05:15:07 -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
2095033b42 Fix documentation of R6RS 'binary-port?' to reflect reality.
* doc/ref/r6rs.texi (rnrs io ports): Improve the descriptions of
'binary-port?' and 'textual-port?'.
* module/rnrs/io/ports.scm (binary-port?, textual-port?): Update the
docstrings.
2019-06-18 03:09:42 -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
8150823fc8 Make 'get-bytevector-some' and 'get-bytevector-some!' suspendable.
* module/ice-9/suspendable-ports.scm (get-bytevector-some)
(get-bytevector-some!): New procedures.
(port-bindings): Add them.
2019-06-18 02:05:20 -04:00
Mark H Weaver
d4df87fd7a open-pipe*: Improve performance of OPEN_BOTH mode.
* module/ice-9/popen.scm (make-rw-port): Re-implement using R6RS
custom binary input/output ports.
2019-06-18 02:05:20 -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
75f3ba7759 time.test: Use 'pass-if-equal' in more tests.
* test-suite/tests/time.test ("strftime"): Change some uses of 'pass-if'
to instead use 'pass-if-equal'.
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
ba94bcafea Fix intmap-intersect edge case
* module/language/cps/intmap.scm (intmap-intersect): If intersection of
  same-level intmaps is empty, return empty intmap.
2019-06-11 12:56:23 +02:00
Andy Wingo
8d46966052 Fix RTL tests for recent arity change
* test-suite/tests/rtl.test: Fix tests.
2019-06-07 17:10:32 +02:00
Andy Wingo
3bbdf22312 Enable closure elision.
* module/language/cps/closure-conversion.scm (convert-one): Elide
  closures when possible.
2019-06-07 17:01:43 +02:00
Andy Wingo
73a769fc2b Add support no closure in $callk
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/contification.scm (compute-contification-candidates):
* module/language/cps/cse.scm (apply-cse):
* module/language/cps/dce.scm (compute-live-code):
* module/language/cps/devirtualize-integers.scm (compute-use-counts):
* module/language/cps/peel-loops.scm (rename-cont):
* module/language/cps/renumber.scm (renumber):
* module/language/cps/rotate-loops.scm (rotate-loop):
* module/language/cps/simplify.scm (compute-singly-referenced-vars):
(beta-reduce):
* module/language/cps/slot-allocation.scm (compute-defs-and-uses):
(compute-lazy-vars):
(compute-shuffles):
(compute-frame-size):
(allocate-lazy-vars):
(allocate-slots):
* module/language/cps/specialize-numbers.scm (compute-significant-bits):
* module/language/cps/verify.scm (check-valid-var-uses): Allow for the
  $callk proc to be #f.
* module/language/cps/compile-bytecode.scm (compile-function): Reset
  frame to appropriate size.
2019-06-07 17:01:43 +02:00
Andy Wingo
f6c07e4eb2 Add compiler support for eliding closure bindings
* module/language/cps/closure-conversion.scm (compute-elidable-closures):
  New function.
  (convert-one, convert-closures): Add ability to set "self" variable of
  $kfun to $f, hopefully avoiding passing that argument in some cases.
* module/language/cps/compile-bytecode.scm (compile-function): Pass the
  has-closure? bit on through to the assembler.
* module/system/vm/assembler.scm (begin-standard-arity)
  (begin-opt-arity, begin-kw-arity): Only reserve space for the closure
  as appropriate.
* module/language/cps/slot-allocation.scm (allocate-args)
  (compute-defs-and-uses, compute-needs-slot)
  (compute-var-representations): Allow for closure slot allocation
  differences.
* module/language/cps/cse.scm (compute-defs):
* module/language/cps/dce.scm (compute-live-code):
* module/language/cps/renumber.scm (renumber, compute-renaming):
(allocate-args):
* module/language/cps/specialize-numbers.scm (compute-significant-bits):
(compute-defs):
* module/language/cps/split-rec.scm (compute-free-vars):
* module/language/cps/types.scm (infer-types):
* module/language/cps/utils.scm (compute-max-label-and-var):
* module/language/cps/verify.scm (check-distinct-vars):
(compute-available-definitions): Allow closure to be #f.
2019-06-07 17:01:37 +02: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
Timothy Sample
420c2632bb Make URI handling locale independent.
Fixes <https://bugs.gnu.org/35785>.

* module/web/uri.scm (digits, hex-digits, letters): New variables.
(ipv4-regexp, ipv6-regexp, domain-label-regexp, top-label-regexp,
userinfo-pat, host-pat, ipv6-host-pat, port-pat, scheme-pat): Explicitly
list each character instead of using character ranges.
* test-suite/tests/web-uri.test: Add corresponding tests.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2019-06-04 21:24: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