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

8144 commits

Author SHA1 Message Date
Andy Wingo
4819276185 Better backtraces from C, especially for optimized closures
* libguile/frames.h:
* libguile/frames.c (scm_frame_call_representation): New interface;
  dispatches to Scheme.

* libguile/backtrace.c (display_application): Use
  scm_frame_call_representation.  This should be monotonically better,
  given that scm_frame_arguments (which was previously called) also
  dispatched to Scheme and actually ended up calling
  frame-call-representation.
2014-04-16 14:33:20 +02:00
Andy Wingo
b7ee9e086e Fix up some opcode metadata
* libguile/vm-engine.c (make-long-immediate, static-ref): Mark as "dst"
  instructions.
2014-04-16 12:51:34 +02:00
Andy Wingo
1a82c2012b Bump minor objcode version for recent changes
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION):
* module/system/vm/assembler.scm (*bytecode-minor-version*): Bump.
2014-04-15 20:20:01 +02:00
Andy Wingo
3b14dd2f27 Optimize make-stack
* libguile/continuations.h:
* libguile/continuations.c (scm_i_continuation_to_frame): Operate on
  low-level C structures instead of heap objects.

* libguile/frames.h:
* libguile/frames.c (frame_offset, frame_stack_base): Const args.
  (scm_c_frame_closure): New helper.
  (scm_frame_procedure): Use the new helper.

* libguile/stacks.c (stack_depth, narrow_stack, scm_make_stack): Rework
  to avoid allocating frames as we traverse the stack, and to avoid an
  n**2 case where there are outer cuts.
2014-04-14 16:31:02 +02:00
Andy Wingo
8de051da47 scm_c_make_frame takes struct scm_frame as arg
* libguile/frames.h:
* libguile/frames.c (scm_c_make_frame): Adapt to take a const struct
  scm_frame as the argument.  Adapt callers.

* libguile/continuations.c:
* libguile/stacks.c: Adapt callers.
2014-04-14 15:14:26 +02:00
Andy Wingo
44d9705464 Refactor to frames code
* libguile/frames.h:
* libguile/frames.c (scm_c_frame_previous): New internal helper.
  (scm_frame_previous): Use the helper.
  (RELOC): Take kind and low-level frame args separately.  Adapt
  callers.
  (frame_stack_base, frame_offset): New helpers.
  (scm_i_frame_offset, scm_i_frame_stack_base): Use low-level helpers.
2014-04-14 14:54:14 +02:00
David Kastrup
0ece4850c5 Make reverse! forego the cost of SCM_VALIDATE_LIST
* libguile/list.c (scm_reverse_x): Do not validate first argument to
  reverse! in advance.  Instead undo reversal in error case.

Signed-off-by: David Kastrup <dak@gnu.org>
Signed-off-by: Mark H Weaver <mhw@netris.org>
2014-04-01 10:59:18 -04:00
Andy Wingo
63b9e8b03f Fix compile warnings
* libguile/throw.c (catch): Fix bad declarations.

* libguile/stackchk.c (reset_scm_stack_checking_enabled_p): Remove
  unused static function.
2014-03-22 16:06:39 +01:00
Andy Wingo
c2247b782a Out-of-memory situations raise exceptions instead of aborting
* libguile/gc.c (scm_oom_fn, scm_init_gc): Install an out-of-memory
  handler that raises an unwind-only out-of-memory exception.
  (scm_gc_warn_proc, scm_init_gc): Install a warning proc that tries to
  print to the current warning port, if the current warning port is a
  file port.
  (scm_gc_after_nonlocal_exit): New interface.  Should be called after a
  nonlocal return to potentially collect memory; otherwise allocations
  could try to expand again when they should collect.

* libguile/continuations.c (scm_i_make_continuation):
* libguile/eval.c (eval):
* libguile/throw.c (catch):
* libguile/vm.c (scm_call_n): Call scm_gc_after_nonlocal_exit after
  nonlocal returns.

* libguile/throw.c (abort_to_prompt, throw_without_pre_unwind): Rework
  to avoid allocating memory.
  (scm_report_out_of_memory): New interface.
  (scm_init_throw): Pre-allocate the arguments for stack-overflow and
  out-of-memory errors.

* module/ice-9/boot-9.scm: Add an out-of-memory exception printer.
* module/system/repl/error-handling.scm (call-with-error-handling): Add
  out-of-memory to the report-keys set.

* libguile/gc-malloc.c (scm_realloc): Call scm_report_out_of_memory if
  realloc fails.

* libguile/error.h:
* libguile/error.c:
* libguile/deprecated.h:
* libguile/deprecated.c (scm_memory_error): Deprecate.

* test-suite/standalone/Makefile.am:
* test-suite/standalone/test-out-of-memory: New test case.
2014-03-22 15:49:31 +01:00
Andy Wingo
0463a927c4 Define a C fluid for current-warning-port
* libguile/ports.c (scm_current_input_port, scm_current_output_port)
  (scm_current_error_port): Fix declarations to C99.
  (scm_current_warning_port, scm_set_current_warning_port): Rework to
  use a C fluid, like scm_current_error_port.
  (scm_init_ports): Initialize and define the warning port fluid.

* libguile/init.c (scm_init_standard_ports): Init the current warning
  port.

* module/ice-9/boot-9.scm: Remove definitions for current-warning-port.
  Instead, steal it from the boot objtable with port-parameterize!.
2014-03-22 15:42:15 +01:00
Ludovic Courtès
f2c3d29fd2 tests: Check 'simple-format' with closed current-output-port.
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.
2014-03-20 09:40:42 +01:00
Mark H Weaver
e26ab067b2 simple-format: Don't assume the current output port is valid.
* libguile/print.c (scm_simple_format): Validate the current output
  port.
2014-03-19 17:55:20 -04:00
Andy Wingo
2be7131ee0 Fix breakage of SRFI-4 C accessors
* libguile/srfi-4.c (DEFINE_SRFI_4_C_FUNCS): Fix bad assumption that
  width was a byte width.  Thanks very much to Barry Fishman for the
  report, and to Daniel Llorens for tracking it down.

* test-suite/standalone/Makefile.am (test_srfi_4_CFLAGS):
* test-suite/standalone/test-srfi-4.c: Add test.
2014-03-19 22:41:19 +01:00
Andy Wingo
bf7e38643d Refine unwind-only exception message.
* libguile/throw.c (throw_without_pre_unwind): Refine warning message.
2014-03-16 15:46:28 +01:00
Andy Wingo
4189a5c0bd Add stack overflow test
* libguile/throw.c (throw_without_pre_unwind): Newline after the
  unwind-only warning.

* test-suite/standalone/Makefile.am:
* test-suite/standalone/test-stack-overflow: New test to handle
  mmap/malloc failure.
2014-03-15 18:56:18 +01:00
Mark H Weaver
950a966e64 Check SCM_USE_PTHREAD_THREADS using #if not #ifdef.
* libguile/bdw-gc.h: Check SCM_USE_PTHREAD_THREADS using #if not #ifdef.
2014-03-13 23:27:25 -04:00
Mark H Weaver
17d4daa8bd Include <config.h> in gen-scmconfig even when cross-compiling.
Partially reverts 8cb0d6d7fa.

* libguile/Makefile.am (gen-scmconfig.$(OBJEXT)): Remove
  -DCROSS_COMPILING=1 from cross-compiling case.
* libguile/gen-scmconfig.c: Include <config.h> regardless of
  whether CROSS_COMPILING is defined.
2014-03-13 23:27:16 -04:00
Andy Wingo
f764e2590f Remove default soft stack limit; add call-with-stack-overflow-handler
* libguile/vm.h:
* libguile/vm.c (default_max_stack_size, initialize_default_stack_size):
  Remove the default stack limit.  In this way, programs run from the
  command line or outside of the REPL will have no soft stack limit.
  (make_vm): Change `max_stack_size' field to be a stack of limits and
  handlers.
  (current_overflow_size, should_handle_stack_overflow)
  (reset_stack_limit, wind_overflow_handler, unwind_overflow_handler)
  (vm_expand_stack): If the stack surpasses a user-set limit, call the
  user-specified handler within its outer stack limit.
  (call-with-stack-overflow-handler): New interface.

* module/system/vm/vm.scm: Export call-with-stack-overflow-handler.
2014-03-12 17:18:13 +01:00
Ludovic Courtès
21a7ba9b7e build: Remove libguile-2.0-gdb.scm and $infodir/dir upon uninstall.
* libguile/Makefile.am (uninstall-data-hook): New target.
2014-03-12 16:22:15 +01:00
Ludovic Courtès
de32a951c0 build: Install libguile-2.0-gdb.scm after libguile-2.0.so.
* libguile/Makefile.am (install-data-local): Rename to...
  (install-data-hook): ... this.  This guarantees that the rule runs
  after libguile-2.0.so has been installed.
2014-03-12 15:18:27 +01:00
Ludovic Courtès
8cb0d6d7fa build: Don't include <config.h> in native programs when cross-compiling.
* libguile/Makefile.am (gen-scmconfig.$(OBJEXT)): When cross-compiling,
  pass -DCROSS_COMPILING=1.
  (c-tokenize.$(OBJEXT)): Likewise.
* libguile/c-tokenize.lex (%top): Include <config.h> only when
  CROSS_COMPILING is undefined.
* libguile/gen-scmconfig.c: Likewise.
2014-03-12 14:35:07 +01:00
David Thompson
c6a2691fff Test for deleted weak pairs in hash-for-each.
* libguile/hashtab.c (scm_internal_hash_for_each_handle): Test for
  deleted weak pairs.
* test-suite/tests/hash.test: Add test case.
2014-03-12 02:36:35 -04:00
Mark H Weaver
3aecd36464 SCM_I_INUM: Rewrite to avoid unspecified behavior when not using GNU C.
* libguile/numbers.h (SCM_I_INUM): Unless using GNU C, use a portable
  implementation that avoids unspecified behavior.
2014-03-11 21:39:36 -04:00
Mark H Weaver
e293c94c65 SCM_SRS: Improve fallback implemention to avoid unspecified behavior.
* libguile/numbers.h (SCM_SRS): Rewrite preprocessor test to avoid
  left-shifting negative integers, and to test more comprehensively for
  the behavior we need.  Rewrite fallback implementation to avoid
  unspecified behavior.
2014-03-11 21:39:31 -04:00
Mark H Weaver
7f8ad91b99 SRFI-60: Reimplement 'rotate-bit-field' on inums to be more portable.
* libguile/srfi-60.c (scm_srfi60_rotate_bit_field): Avoid division by
  zero in the (start == end) case.  Rewrite inum case to work with
  unsigned integers in two's complement format.

* test-suite/tests/srfi-60.test ("rotate-bit-field"): Add more tests.
2014-03-11 21:39:26 -04:00
Mark H Weaver
9fcee9da3f Use 'offsetof' to avoid undefined behavior.
* libguile/socket.c (SUN_LEN): Use 'offsetof'.
2014-03-11 21:39:20 -04:00
Mark H Weaver
03cce0ce5f Avoid undefined behavior regarding signed integers and left shifts.
* libguile/numbers.c (scm_logbit_p): If the requested bit is the sign
  bit (or above), check the sign portably.  Otherwise, ensure that we're
  testing the bit in a two's complement representation.
  (left_shift_exact_integer): Avoid left-shifting negative integers.

* libguile/vm-i-scheme.c (ash): Avoid left-shifting negative integers.
2014-03-11 21:39:13 -04:00
Mark H Weaver
5fbf0e0f99 Avoid signed overflow in random.c.
* libguile/random.c (scm_i_mask32): Avoid signed overflow from shifting
  an unsigned char (promoted to signed int) 24 bits to the left.
2014-03-11 21:39:08 -04:00
Mark H Weaver
19c0bd22a8 Avoid side effects in argument to SCM_I_INUM.
* libguile/vm-i-system.c (halt): Avoid side effects in argument to
  SCM_I_INUM.
2014-03-11 21:37:58 -04:00
Mark H Weaver
de7aa61ac4 Improve compliance with C standards regarding signed integer shifts.
* configure.ac: Add -fwrapv when using GCC (or compatible), if
  supported.

* libguile/numbers.h (SCM_I_MAKINUM): Cast to scm_t_bits (unsigned)
  before shifting, to avoid undefined behavior.
2014-03-07 04:34:27 -05:00
Mark H Weaver
ce0ba9d087 chars.c: Remove duplicate 'const' specifiers.
* libguile/chars.c (scm_r5rs_charnums, scm_r6rs_charnums)
  (scm_r7rs_charnums, scm_C0_control_charnums, scm_alt_charnums):
  Remove duplicate 'const' specifiers.
2014-03-06 23:59:56 -05:00
Mark H Weaver
b8d7aacd68 snarf.h: Declare static const function name vars as SCM_UNUSED.
* libguile/snarf.h (SCM_DEFINE_GSUBR, SCM_DEFINE, SCM_PRIMITIVE_GENERIC,
  SCM_DEFINE_PUBLIC, SCM_PROC, SCM_REGISTER_PROC, SCM_GPROC): Declare
  static const function name variables as SCM_UNUSED to avoid spurious
  warnings.
2014-03-06 23:56:48 -05:00
Mark H Weaver
c3c3032608 Make snarfing tools more robust to varied C preprocessor behavior.
* libguile/guile-snarf.in (modern_snarf): Rewrite sed script to cope
  with newlines in the snarfed code segments, or multiple code segments
  on the same line.

* module/scripts/snarf-check-and-output-texi.scm (process-stream):
  Strip all 'hash' tokens from the stream.
  (do-command): Remove special cases that handled 'hash' tokens
  in a few places.
2014-03-06 17:25:55 -05:00
Ludovic Courtès
e1bb79fde6 build: Make c-tokenize.c build on non-GNU systems.
* libguile/c-tokenize.lex: Add %top directive to include <config.h>
  first.  This fixes builds on systems that use Gnulib's <stdio.h> and
  similar replacements.  See <http://hydra.nixos.org/build/9259627> for
  an example.
2014-02-28 21:01:27 +01:00
Andy Wingo
966d4bdd70 Fix setitimer documentation. Allow microseconds >= 1e6.
* doc/ref/posix.texi (Signals): Fix the documentation for setitimer; it
  was wrong.

* libguile/scmsigs.c (pack_tv): New helper.  Allow usecs >= 1e6.
  (unpack_tv): New helper.
  (scm_setitimer): Use the new helpers.

* test-suite/tests/signals.test: Add setitimer tests.
2014-02-28 10:31:12 +01:00
Mark H Weaver
bc8e6d7d8c Rely on Gnulib for <unistd.h>.
* libguile/async.c:
* libguile/backtrace.c:
* libguile/error.c:
* libguile/filesys.c:
* libguile/fports.c:
* libguile/gc-malloc.c:
* libguile/gc.c:
* libguile/gdbint.c:
* libguile/init.c:
* libguile/ioext.c:
* libguile/load.c:
* libguile/mallocs.c:
* libguile/mkstemp.c:
* libguile/ports.c:
* libguile/posix.c:
* libguile/r6rs-ports.c:
* libguile/random.c:
* libguile/rw.c:
* libguile/scmsigs.c:
* libguile/script.c:
* libguile/simpos.c:
* libguile/socket.c:
* libguile/stime.c:
* libguile/strports.c:
* libguile/threads.c: Unconditionally include <unistd.h>.
2014-02-27 22:38:48 -05:00
Mark H Weaver
ca6adcc6df Rely on Gnulib for fsync, link, readlink, mkdir, rmdir, and rename.
* libguile/filesys.c: Remove 'fsync' wrapper for MinGW.
  (scm_link, scm_readlink, scm_mkdir, scm_rmdir): Define these
  unconditionally.
  (my_rename): Remove.
  (scm_rename): Use 'rename' instead of 'my_rename'.
2014-02-27 22:38:09 -05:00
Ludovic Courtès
a8b80d6b29 build: Fix out-of-source-tree installation of libguile-2.0-gdb.scm.
* libguile/Makefile.am (install-data-local): Use $< instead of just
  libguile-2.0-gdb.scm.  Quote file names in $(INSTALL_DATA) invocation.
2014-02-27 14:14:21 +01:00
Andy Wingo
fcd3c8ccd3 Zero-offset branches are backward branches; fix "br" backward branches
* libguile/vm-engine.c (BR_UNARY, BR_BINARY, BR_ARITHMETIC): A jump with
  a zero offset is also a backward branch, in the sense that it's not a
  forward branch.
  ("br"): We forgot to VM_HANDLE_INTERRUPTS here on backwards branches.
  Oops!
2014-02-22 15:39:29 +01:00
Andy Wingo
c65ea594e9 Fix segfault in thread_mark
* libguile/threads.c (thread_mark): There is a window in which the
  thread has a handle but doesn't yet have the set of pointerless
  freelists, so don't unconditionally dereference
  t->pointerless_freelists.
2014-02-21 14:42:24 +01:00
Andy Wingo
c53d0f01dd Threadsafe stack relocation
* libguile/vm.c (vm_return_to_continuation, vm_expand_stack):
  (vm_reinstate_partial_continuation): Hold the GC lock while relocating
  the stack.
2014-02-20 21:09:08 +01:00
Andy Wingo
698c55b04b assertion refactor in the vm
* libguile/vm.c:
* libguile/vm-engine.c: Change the one use of
  VM_ENABLE_PARANOID_ASSERTIONS to ASSERT.  That becomes the one use of
  VM_ENABLE_ASSERTIONS, so disable that too.
2014-02-20 19:57:47 +01:00
Andy Wingo
2a62eda85a Fix "VM never extends vp->sp ..." commit
* libguile/vm.c (vm_expand_stack): Make sure the new SP is visible to
  vm_error if we throw because of stack overflow.
2014-02-20 10:43:40 +01:00
Andy Wingo
24af549ac1 Remove the hard stack size limit
* libguile/vm.c (vm_expand_stack): Remove the hard stack size limit.
2014-02-20 10:21:51 +01:00
Andy Wingo
c2ae85beab VM never extends vp->sp beyond mapped region of stack
* libguile/vm-engine.c (ALLOC_FRAME): Fold CHECK_OVERFLOW into this
  routine, and rework to not extend vp->sp until the stack has been
  expanded.

* libguile/vm.c (vm_increase_sp): Likewise, don't extend vp->sp until
  the stack has expanded.
  (vm_expand_stack): Rework to take the new stack pointer as an
  argument, and also to update vp->sp_max_since_gc and vp->sp.
2014-02-20 10:17:51 +01:00
Andy Wingo
7e2fd4e7f5 Unwind-only stack overflow exceptions
* module/ice-9/boot-9.scm (catch): Signal an early error if the handler
  or pre-unwind handler types aren't right.  This is more important than
  it was, given that we dispatch on type now when finding matching catch
  clauses.

* libguile/vm.c (vm_expand_stack): Use the standard
  scm_report_stack_overflow to signal stack overflow.  This will avoid
  running pre-unwind handlers.

* libguile/throw.h: Move scm_report_stack_overflow here.

* libguile/throw.c (catch): Define a version of catch in C.
  (throw_without_pre_unwind): New helper.  Besides serving as the
  pre-boot "throw" binding, it allows stack overflow to throw without
  running pre-unwind handlers.
  (scm_catch, scm_catch_with_pre_unwind_handler)
  (scm_with_throw_handler): Use the new catch in C.
  (scm_report_stack_overflow): Moved from stackchk.c; throws an
  unwind-only exception.

* libguile/stackchk.h:
* libguile/stackchk.c: Remove the scm_report_stack_overflow bits.
2014-02-20 09:45:01 +01:00
Andy Wingo
5d20fd49fe %exception-handler fluid refactor
* libguile/throw.c (scm_init_throw): Define %exception-handler here.
* module/ice-9/boot-9.scm (%eh): Use the incoming %exception-handler,
  and then delete it.  This way we should be able to do unwind-only
  exceptions from C.
2014-02-19 21:57:40 +01:00
Andy Wingo
ee1c6b575f Fix scm_i_vm_capture_stack comment.
* libguile/vm.c (scm_i_vm_capture_stack): Fix a comment.
2014-02-19 11:19:10 +01:00
Andy Wingo
f2d592185f Default stack size is one page.
* libguile/vm.c (initialize_default_stack_size): Initial stack size is
  one page.
2014-02-19 11:15:50 +01:00
Andy Wingo
b8321c24aa More robust stack expansion and contraction
* libguile/vm.c (allocate_stack, expand_stack): Return NULL on
  allocation failure instead of throwing an exception.  Throwing an
  exception is tricky to get right, and we need more context to do it
  correctly.
  (return_unused_stack_to_os): Try again if madvise returns -EAGAIN.  If
  madvise fails, print an error message.
  (vm_expand_stack): Abort if stack expansion fails.  We'll fix this in
  a future patch.
  (make_vm): Abort if we can't mmap a single page.
2014-02-19 11:11:24 +01:00