summaryrefslogtreecommitdiff
path: root/libguile/throw.c
AgeCommit message (Collapse)AuthorFilesLines
2012-03-07dynstack: pushing a prompt no longer allocates memoryAndy Wingo1-11/+12
* libguile/control.h: Remove scm_t_prompt_registers and scm_c_make_prompt_registers. (scm_c_abort): Take a pointer to a jmpbuf instead of a cookie. It will serve the same purpose. * libguile/control.c (reify_partial_continuation, scm_at_abort): Adapt to new prompt representation. * libguile/dynstack.h: * libguile/dynstack.c (scm_dynstack_push_prompt): Prompts now have 5 words instead of 2, as they now push the fp, sp, ip, and jmpbuf on the stack separately. This avoids allocation. (scm_dynstack_find_prompt): Likewise, add return values for fp, sp, etc. (scm_dynstack_wind_prompt): Replaces scm_dynstack_relocate_prompt. * libguile/eval.c (eval): * libguile/stacks.c (find_prompt): * libguile/throw.c (pre_init_catch): Adapt to the new prompt mechanism. * libguile/vm-engine.c (vm_engine): Setjmp an on-stack jmpbuf every time the VM enters. We can then re-use that jmpbuf for all prompts in that invocation. * libguile/vm-i-system.c (partial_cont_call): Adapt to change in prompt representation. We don't need to wind here any more, since we pass in the prompt's jmpbuf. (prompt): Adapt to scm_dynstack_push_prompt change. (abort): Adapt to vm_abort change. * libguile/vm.h (struct scm_vm): No more cookie. * libguile/vm.c (vm_abort): Adapt to scm_c_abort change. (vm_reinstate_partial_continuation): Rewind the dynamic stack here, now that we do have a valid jmpbuf. (make_vm): No need to initialize a cookie.
2012-03-03the dynamic stack is really a stack now, instead of a listAndy Wingo1-17/+23
* libguile/dynstack.h: * libguile/dynstack.c: New files, implementing the dynamic stack as a true stack instead of a linked list. This lowers the cost of dynwinds: frames, winders, prompts, with-fluids, and dynamic-wind. For the most part, we allocate these items directly on the stack. * libguile/dynwinds.h: * libguile/dynwinds.c: Adapt all manipulators of the wind stack to use interfaces from dynstack.c. Remove heap-allocated winder and frame object types. (scm_dowinds, scm_i_dowinds): Remove these. The first was exported, but it was not a public interface. * libguile/continuations.c: * libguile/continuations.h (scm_t_contregs): Continuation objects reference scm_t_dynstack* values now. Adapt to the new interfaces. * libguile/control.c: * libguile/control.h: There is no longer a scm_tc7_prompt kind of object that can be allocated on the heap. Instead, the prompt flags, key, and registers are pushed on the dynwind stack. (The registers are still on the heap.) Also, since the vm_cont will reference the dynwinds, make the partial continuation stub take just one extra arg, instead of storing the intwinds separately in the object table. * libguile/fluids.c: * libguile/fluids.h: No more with-fluids objects; instead, the fluids go on the dynstack. The values still have to be on the heap, though. (scm_prepare_fluids, scm_swap_fluids): New internal functions, replacing scm_i_make_with_fluids and scm_i_swap_with_fluids. * libguile/print.c: Remove prompt and with-fluids printers. * libguile/tags.h: Revert prompt and with-fluids tc7 values to what they were before they were allocated. * libguile/vm-i-system.c (partial_cont_call): Just pop the vmcont, the intwinds will not be passed as a second arg. Rewind the dynamic stack from within the VM, so that any rewinder sees valid prompt entries. (call_cc, tail_call_cc): Adapt to pass the dynstack to scm_i_vm_capture_stack. (prompt, wind, unwind, wind_fluids, unwind_fluids): Adapt to the new interfaces. * libguile/vm.h (scm_i_capture_current_stack): Rename from scm_i_vm_capture_continuation. (scm_i_vm_capture_stack): Take a dynstack as an argument. * libguile/vm.c (vm_reinstate_partial_continuation): Don't wind here, as that could result in winders seeing invalid prompts. * libguile/eval.c: * libguile/root.c: * libguile/stacks.c: * libguile/threads.c: * libguile/threads.h: * libguile/throw.c: Adapt other users of dynwinds to use the dynstack.
2011-11-08locking for putc, putsAndy Wingo1-1/+1
* libguile/ports.c (scm_putc, scm_puts): * libguile/ports.h (scm_putc_unlocked, scm_puts_unlocked): Separate into _unlocked and locked variants. Change all callers to use the _unlocked versions.
2011-11-04more robust scm_exit_statusAndy Wingo1-2/+8
* libguile/throw.c (scm_exit_status): In one of my bogus patches, I managed to make #<unspecified> reach this function, causing a segfault on SCM_CAR. Refactor to be more robust.
2011-05-15use of EXIT_SUCCESS and EXIT_FAILUREAndy Wingo1-2/+2
* libguile/threads.c (scm_init_guile): * libguile/throw.c (scm_exit_status): Use EXIT_SUCCESS and EXIT_FAILURE instead of 0 and 1.
2011-03-29fix prompt and abort with the boot evaluatorAndy Wingo1-1/+1
* libguile/control.h: * libguile/control.c (scm_i_prompt_pop_abort_args_x): Take a VM instead of a prompt, given that it's the VM's registers that record the abort arguments, not the prompt registers (which actually point right below the abort values). * libguile/eval.c (eval): * libguile/throw.c (pre_init_catch): Pass the vm instead of a prompt.
2011-02-11better narrowing in catch-all handlers in throw.cAndy Wingo1-1/+7
* libguile/throw.c (handler_message): Narrow away the catch-closure and throw frames.
2011-02-11pre-boot lookup of print-exception worksAndy Wingo1-1/+1
* libguile/backtrace.c (scm_print_exception): Use scm_module_variable to look up print-exception so that it works before boot-9 is loaded. * libguile/throw.c (CACHE_VAR): Tweak to use scm_from_latin1_symbol.
2011-02-11scm_handle_by_message uses scm_print_exceptionAndy Wingo1-95/+23
* libguile/throw.c (handler_message, should_print_backtrace): Use scm_print_exception. Add a helper function to determine when to print a backtrace; don't do so on read or syntax errors.
2011-02-09more robust fallback error printerAndy Wingo1-2/+22
* libguile/throw.c (pre_init_throw): Deal with errors printing the exception.
2011-02-09abort on pre-boot throw without catchAndy Wingo1-1/+3
* libguile/throw.c (pre_init_throw): Abort instead of exit in the error case. Print out a message.
2011-02-09fix a couple of (system vm frame) accesses on boot errorsAndy Wingo1-1/+1
* libguile/backtrace.c (display_error_body): Don't look up the frame-source if Guile isn't initialized yet. Fixes display-error before boot has finished. * libguile/throw.c (handler_message): Likewise, don't backtrace before boot has finished, because we can't load (system vm frame).
2011-02-09fix recursive throws if an error occurs at boot-timeAndy Wingo1-3/+25
* libguile/throw.c (find_pre_init_catch): New internal helper. (pre_init_throw): If we don't find a catch, print out a message and abort. (scm_init_throw): Declare pre-init-throw as taking at least one arg.
2011-01-07use scm_from_latin1_symboln for string literals and load-symbolAndy Wingo1-4/+4
* libguile/bytevectors.c: * libguile/eval.c: * libguile/goops.c: * libguile/i18n.c: * libguile/load.c: * libguile/memoize.c: * libguile/modules.c: * libguile/ports.c: * libguile/print.c: * libguile/procs.c: * libguile/programs.c: * libguile/read.c: * libguile/script.c: * libguile/srfi-14.c: * libguile/stacks.c: * libguile/strings.c: * libguile/throw.c: * libguile/vm.c: Use scm_from_latin1_symboln to make symbols from string literals, because they aren't in the user's locale -- they are in ASCII, and we can optimize this case. * libguile/vm-i-loader.c: Also use scm_from_latin1_symboln when loading narrow symbols.
2010-11-16fix the C syntax-error pretty-printerAndy Wingo1-2/+4
* libguile/throw.c (handler_message): Fix up a bit.
2010-11-16add proper pretty-printing for syntax errorsAndy Wingo1-1/+54
* module/system/repl/repl.scm (display-syntax-error): New helper, displays a syntax error. (abort-on-error, run-repl): Use it. * libguile/throw.c (handler_message): Re-code the same thing in C.
2010-08-16a number of doc fixesAndy Wingo1-1/+3
* doc/ref/api-control.texi (Handling Errors): Update docs for display-error. * libguile/backtrace.h (scm_i_display_error): Change prototype to s/stack/frame/. * libguile/throw.c (handler_message): Change invocation of scm_i_display_error to pass a frame. * doc/ref/api-deprecated.texi (Deprecation): Update wording. * doc/ref/api-evaluation.texi (Local Evaluation): Remove section on local-eval. * doc/ref/api-macros.texi: Fix a couple typos. * doc/ref/api-memory.texi (Objects): Remove terrible section. * doc/ref/api-procedures.texi (Procedure Properties): Remove docs for closure?. (Compiled Procedures): Update wording. * doc/ref/guile.texi (API Reference): Remove reference to "Objects".
2010-06-19deprecate the-last-stackAndy Wingo1-44/+0
* libguile/backtrace.h (scm_the_last_stack_fluid_var) * libguile/backtrace.c (scm_init_backtrace): No more scm_the_last_stack_fluid_var. The replacement is to resolve `the-last-stack' in (ice-9 stack-catch). (scm_backtrace_with_highlights): Accordingly, instead of backtracing the last stack, backtrace the current stack. * libguile/throw.h: * libguile/throw.c: * libguile/deprecated.h: * libguile/deprecated.c (scm_internal_stack_catch): Deprecate this function. * module/ice-9/save-stack.scm (the-last-stack): Move here from boot-9. * module/ice-9/debug.scm: * module/ice-9/debugger.scm: Use (ice-9 save-stack) for the-last-stack. * module/ice-9/deprecated.scm (the-last-stack): Add deprecated shim.
2010-04-09remove libguile/lang.h, deprecate %nil (in favor of #nil)Andy Wingo1-1/+0
* libguile/Makefile.am: * libguile/init.c: * libguile/lang.c: * libguile/lang.h: Remove lang.c and lang.h. * libguile/pairs.h (SCM_NIL_P, SCM_NULL_OR_NIL_P): Moved here. * module/ice-9/deprecated.scm (%nil): %nil definition moved here. * libguile/alist.c: * libguile/async.c: * libguile/backtrace.c: * libguile/boolean.c: * libguile/dynl.c: * libguile/eval.c: * libguile/filesys.c: * libguile/fluids.c: * libguile/list.c: * libguile/load.c: * libguile/options.c: * libguile/posix.c: * libguile/print.c: * libguile/promises.c: * libguile/sort.c: * libguile/throw.c: * libguile/trees.c: * libguile/vectors.c: * libguile/vm.c: * libguile/weaks.c: * srfi/srfi-1.c: <libguile/lang.h> references removed.
2010-03-11remove internal treatment of default prompt tag, it seems there was no needAndy Wingo1-2/+5
* libguile/control.h (scm_sys_default_prompt_tag): * libguile/control.c (scm_init_control): Remove the logic that defined %default-prompt-tag. (scm_c_abort): Remove check for default prompt tag, it wasn't useful. * libguile/throw.c (sym_pre_init_catch_tag): Define as the pre-init prompt tag. (pre_init_catch, pre_init_throw): Use sym_pre_init_catch_tag. * module/ice-9/boot-9.scm (default-prompt-tag): Define as a simple value, not a fluid. Perhaps we can expose it as a fluid later.
2010-02-26rewinding prompts worksAndy Wingo1-2/+2
* libguile/control.h (SCM_PROMPT_HANDLER): Remove, it was unused. (SCM_PROMPT_DYNWINDS): Rename from SCM_PROMPT_DYNENV. * libguile/control.c: (scm_c_make_prompt): Take another arg, the winds that are to be in place for the prompt. Fix allocation to be 4 words instead of 5 (the handler was never used). * libguile/eval.c (eval): * libguile/throw.c (pre_init_catch): Adapt to scm_c_make_prompt change. * libguile/vm-i-system.c (partial-cont-call): Grovel the new elements of the wind list in order to call setjmp() on the new prompts. Pass cookie to vm_reinstate_partial_continuation. (prompt): Adapt to scm_c_make_prompt change. * libguile/vm.c (vm_reinstate_partial_continuation): Take a cookie arg, used when winding captured prompts onto the stack. Winding a prompt implies making a new prompt, actually -- with new registers, a new jump buffer, new winds, etc. * test-suite/tests/control.test ("rewinding prompts"): Add a test for rewinding prompts.
2010-02-26catch, throw, with-throw-handler implemented in SchemeAndy Wingo1-467/+149
* libguile/throw.c (tc16_jmpbuffer, tc16_pre_unwind_data): Remove these smob types, and associated constructors and accessors (all internal). (scm_catch, scm_catch_with_pre_unwind_handler): (scm_with_throw_handler, scm_throw): Simply dispatch to scheme. Lovely. (tc16_catch_closure): Introduce a new applicable smob type, for use by the C catch interface. All constructors and accessors are internal. (scm_c_catch, scm_internal_catch, scm_c_with_throw_handler): Build applicable smobs out of the C procedure arguments, so we can then dispatch through scm_catch et al. (scm_ithrow): Dispatch to scm_throw. (pre_init_catch, pre_init_throw): Restricted catch/throw implementation for use before boot-9 runs. (scm_init_throw): Bind the pre-init catch and throw definitions. * module/ice-9/boot-9.scm (prompt, abort): Move these definitions up in the file. (catch, throw, with-throw-handler): Implement in Scheme. Whee!
2010-02-26deprecate lazy-catchAndy Wingo1-64/+19
* libguile/deprecated.h: * libguile/deprecated.c (scm_internal_lazy_catch, scm_lazy_catch): Deprecate, and print out a nasty warning that people should change to with-throw-handler. * libguile/throw.h: * libguile/throw.c (scm_c_with_throw_handler): Deprecate the use of the lazy_catch_p argument, printing out a nasty warning if someone actually passes 1 as that argument. The combination of the pre-unwind and post-unwind handlers should be sufficient. * test-suite/tests/exceptions.test: Remove lazy-catch tests, as they are deprecated. Two of them fail: * throw/catch: effect of lazy-catch unwinding on throw to another key * throw/catch: repeat of previous test but with lazy-catch Hopefully people are not depending on this behavior, and the warning is sufficiently nasty for people to switch. We will see. * test-suite/tests/eval.test ("promises"): Use with-throw-handler instead of lazy-catch. * doc/ref/api-debug.texi: * doc/ref/api-control.texi: Update to remove references to lazy-catch, folding in the useful bits to with-throw-handler.
2009-12-08SCM_CELL in throw.cAndy Wingo1-12/+10
* libguile/throw.c (JBACTIVE, ACTIVATEJB, DEACTIVATEJB, JBJMPBUF) (SETJBJMPBUF, SCM_JBPREUNWIND, SCM_SETJBPREUNWIND) (pre_unwind_data_print, scm_ithrow): Fix SCM_CELL macro usage.
2009-12-03remove debug framesAndy Wingo1-4/+0
* libguile/debug.h (scm_t_debug_frame): Remove this type, as it was internal to the old evaluator. (SCM_EVALFRAME, SCM_APPLYFRAME, SCM_VOIDFRAME, SCM_MACROEXPF) (SCM_TAILREC, SCM_TRACED_FRAME, SCM_ARGS_READY, SCM_DOVERFLOW) (SCM_MAX_FRAME_SIZE, SCM_FRAMETYPE) (SCM_EVALFRAMEP, SCM_APPLYFRAMEP, SCM_VOIDFRAMEP, SCM_MACROEXPFP) (SCM_TAILRECP, SCM_TRACED_FRAME_P, SCM_ARGS_READY_P, SCM_OVERFLOWP) (SCM_SET_MACROEXP, SCM_SET_TAILREC, SCM_SET_TRACED_FRAME) (SCM_SET_ARGSREADY, SCM_SET_OVERFLOW) (SCM_CLEAR_MACROEXP, SCM_CLEAR_TRACED_FRAME, SCM_CLEAR_ARGSREADY): Remove macro accessors to scm_t_debug_frame. (SCM_DEBUGOBJP, SCM_DEBUGOBJ_FRAME, SCM_SET_DEBUGOBJ_FRAME): (scm_debug_object_p, scm_make_debugobj): Remove debugobj accessors. (scm_i_unmemoize_expr): Remove unused declaration. * libguile/debug.c (scm_debug_options): No more max limit on frame sizes. (scm_start_stack): Just call out to scm_vm_call_with_new_stack. (scm_debug_object_p, scm_make_debugobj, scm_init_debug): No more debugobj smob type. * libguile/deprecated.h: * libguile/deprecated.c (scm_i_deprecated_last_debug_frame) (scm_last_debug_frame): Remove deprecated debug-frame bits. * libguile/stacks.c (scm_make_stack): Rework this function and its dependents to only walk VM frames. (scm_stack_id): Call out to the holder of the VM frame in question, which should be a VM or a VM continuation, for the stack ID. Currently this bit is stubbed out. (scm_last_stack_frame): Removed. It seems this is mainly useful for a debugger, and we need to rewrite the debugger to work on the Scheme level. * test-suite/tests/continuations.test ("continuations"): Remove test for last-stack-frame. * libguile/continuations.h (struct scm_t_contregs): * libguile/continuations.c (scm_make_continuation): (copy_stack_and_call, scm_i_with_continuation_barrier): No need to save and restore debug frames. * libguile/threads.h (scm_i_thread): Don't track debug frames. (scm_i_last_debug_frame, scm_i_set_last_debug_frame): Remove macro accessors. * libguile/threads.c (guilify_self_1): Don't track debug frames. * libguile/throw.c: No need to track debug frames in a jmpbuf. * libguile/vm-engine.c (vm_engine, VM_PUSH_DEBUG_FRAMES): Don't push debug frames. * libguile/vm.h: * libguile/vm.c (scm_vm_call_with_new_stack): New function. Currently stubbed out though.
2009-11-28Remove remaining uses of discouraged constructs, really.Ludovic Courtès1-2/+2
* libguile/throw.c, libguile/vm-engine.h, libguile/vm-i-system.c, libguile/vm.c: Replace uses of discouraged constructs by their current counterparts.
2009-11-28Remove remaining uses of discouraged constructs.Ludovic Courtès1-2/+2
* libguile/frames.c, libguile/instructions.c, libguile/objcodes.c, libguile/programs.c, libguile/throw.c, libguile/vm-i-scheme.c, libguile/vm.c: Replace uses of discouraged constructs by their current counterparts.
2009-09-30Fix spurious `throw from within critical section' errorsNeil Jerram1-1/+1
The crux of this problem was that the thread doing a throw, and so checking scm_i_critical_section_level, was different from the thread that was in a critical section. * libguile/async.h (scm_i_critical_section_level): Removed, replaced by per-thread critical_section_level. (SCM_CRITICAL_SECTION_START, SCM_CRITICAL_SECTION_END): Use per-thread critical_section_level. * libguile/continuations.c (scm_dynthrow): Check per-thread critical_section_level. * libguile/threads.c (guilify_self_1): Init per-thread critical_section_level. (scm_i_critical_section_level): Removed. * libguile/threads.h (scm_i_thread): New critical_section_level field. * libguile/throw.c (scm_ithrow): Check per-thread critical_section_level.
2009-08-23Use string and symbol accessors in struct, throw, and array funcsMichael Gran1-2/+7
* libguile/struct.c (scm_make_struct_layout, scm_struct_init) (scm_struct_vtable_p, scm_struct_ref, scm_struct_set_x): use string and symbol accessors and avoid unpacking strings and symbols * libguile/throw.c (scm_ithrow): allow wide symbols in the error message * libguile/unif.c (scm_enclose_array, scm_istr2bve): use string accessors and avoid unpacking strings
2009-08-21Avoid clash with system setjmp/longjmp on IA64Neil Jerram1-5/+5
Problem was that if an application includes both libguile.h and the system's setjmp.h, and is compiled on IA64, it gets compile errors because of jmp_buf, setjmp and longjmp being multiply defined. * libguile/__scm.h (__ia64__): Define scm_i_jmp_buf, SCM_I_SETJMP and SCM_I_LONGJMP instead of jmp_buf, setjmp and longjmp. (all other platforms): Map scm_i_jmp_buf, SCM_I_SETJMP and SCM_I_LONGJMP to jmp_buf, setjmp and longjmp. * libguile/continuations.c (scm_make_continuation): Use `SCM_I_SETJMP' instead of `setjmp'. (copy_stack_and_call): Use `SCM_I_LONJMP' instead of `longjmp'. (scm_ia64_longjmp): Use type `scm_i_jmp_buf' instead of `jmp_buf'. * libguile/continuations.h (scm_t_contregs): Use type `scm_i_jmp_buf' instead of `jmp_buf'. * libguile/threads.c (suspend): Use `SCM_I_SETJMP' instead of `setjmp'. * libguile/threads.h (scm_i_thread): Use type `scm_i_jmp_buf' instead of `jmp_buf'. * libguile/throw.c (JBJMPBUF, make_jmpbuf, jmp_buf_and_retval): Use type `scm_i_jmp_buf' instead of `jmp_buf'. (scm_c_catch): Use `SCM_I_SETJMP' instead of `setjmp'. (scm_ithrow): Use `SCM_I_LONGJMP' instead of `longjmp'.
2009-06-17Change Guile license to LGPLv3+Neil Jerram1-6/+7
(Not quite finished, the following will be done tomorrow. module/srfi/*.scm module/rnrs/*.scm module/scripts/*.scm testsuite/*.scm guile-readline/* )
2009-02-04make catch cache and restore vm regs, not the vm itself -- speedy speedyAndy Wingo1-0/+34
* libguile/throw.c (scm_c_catch): Stash away the current vm's regs, and restore them if there's a nonlocal exit. There is a terrible case we have to handle if we catch from when the vm smob type isn't registered but the throw has the vm registered, but I think we handle this fine. * libguile/vm-engine.c (vm_run): * libguile/vm-i-system.c (halt): Don't make a dynwind context, so that entering the VM doesn't cons at all, except for the arg list. Maybe we can fix that bit too. * libguile/vm.c (vm_reset_stack): Remove, as there is no more dynwind. (make_vm): Return #f if the tc16 hasn't yet been registered.
2008-09-13Include <config.h> in all C files; use `#ifdef HAVE_CONFIG_H' rather than `#if'.Ludovic Courtès1-0/+3
2008-05-12Fix continuation problems on IA64.Neil Jerram1-0/+6
* Specific problems in IA64 make check ** test-unwind Representation of the relevant dynamic context: non-rewindable catch frame make cont. o----o-----a----------b-------------c \ \ call cont. o-----o-----------d A continuation is captured at (c), with a non-rewindable frame in the dynamic context at (b). If a rewind through that frame was attempted, Guile would throw to the catch at (a). Then the context unwinds back past (a), then winds forwards again, and the captured continuation is called at (d). We should end up at the catch at (a). On ia64, we get an "illegal instruction". The problem is that Guile does not restore the ia64 register backing store (RBS) stack (which is saved off when the continuation is captured) until all the unwinding and rewinding is done. Therefore, when the rewind code (scm_i_dowinds) hits the non-rewindable frame at (b), the RBS stack hasn't yet been restored. The throw finds the jmp_buf (for the catch at (a)) correctly from the dynamic context, and jumps back to (a), but the RBS stack is invalid, hence the illegal instruction. This could be fixed by restoring the RBS stack earlier, at the same point (copy_stack) where the normal stack is restored. But that causes a problem in the next test... ** continuations.test The dynamic context diagram for this case is similar: non-rewindable catch frame make cont. a----x-----o----------b-------------c \ \ call cont. o-------d The only significant difference is that the catch point (a) is upstream of where the dynamic context forks. This means that the RBS stack at (d) already contains the correct RBS contents for throwing back to (a), so it doesn't matter whether the RBS stack that was saved off with the continuation gets restored. This test passes with the Guile 1.8.4 code, but fails (with an "illegal instruction") when the code is changed to restore the RBS stack earlier as described above. The problem now is that the RBS stack is being restored _too_ early; specifically when there is still stuff to do that relies on the old RBS contents. When a continuation is called, the sequence of relevant events is: (1) Grow the (normal) stack until it is bigger than the (normal) stack saved off in the continuation. (scm_dynthrow, grow_stack) (2) scm_i_dowinds calls itself recursively, such that (2.1) for each rewind (from (x) to (c)) that will be needed, another frame is added to the stack (both normal and RBS), with local variables specifying the required rewind; the rewinds don't actually happen yet, they will happen when the stack unwinds again through these frames (2.2) required unwinds - back from where the continuation was called (d) to the fork point (x) - are done immediately. (3) The normal (i.e. non-RBS) stack that was stored in the continuation is restored (i.e. copied on top of the actual stack). Note that this doesn't overwrite the frames that were added in (2.1), because the growth in (1) ensures that the added frames are beyond the end of the restored stack. (4) ? Restore the RBS stack here too ? (5) Return (from copy_stack) through the (2.1) frames, which means that the rewinds now happen. (6) setcontext (or longjmp) to the context (c) where the continuation was captured. The trouble is that step (1) does not create space in the RBS stack in the same kind of way that it does for the normal stack. Therefore, if the saved (in the continuation) RBS stack is big enough, it can overwrite the RBS of the (2.1) frames that still need to complete. This causes an illegal instruction when we return through those frames and try to perform the rewinds. * Fix The key to the fix is that the saved RBS stack only needs to be restored at some point before the next setcontext call, and that doing it as close to the setcontext call as possible will avoid bad interactions with the pre-setcontext stack. Therefore we do the restoration at the last possible point, immediately before the next setcontext call. The situation is complicated by there being two ways that the next setcontext call can happen. - If the unwinding and rewinding is all successful, the next setcontext will be the one from step (6) above. This is the "normal" continuation invocation case. - If one of the rewinds throws an error, the next setcontext will come from the throw implementation code. (And the one in step (6) will never happen.) This is the rewind error case. In the rewind error case, the code calling setcontext knows nothing about the continuation. So to cover both cases, we: - copy (in step (4) above) the address and length of the continuation's saved RBS stack to the current thread state (SCM_I_CURRENT_THREAD) - modify all setcontext callers so that they check the current thread state for a saved RBS stack, and restore it if so before calling setcontext. * Notes ** I think rewinders cannot rely on using any stack data Unless it can be guaranteed that the data won't go into a register. I'm not 100% sure about this, but I think it follows from the fact that the RBS stack is not restored until after the rewinds have happened. Note that this isn't a regression caused by the current fix. In Guile 1.8.4, the RBS stack was restored _after_ the rewinds, and this is still the case now. ** Most setcontext calls for `throw' don't need to change the RBS stack In the absence of continuation invocation, the setcontext call in the throw implementation code always sets context to a place higher up the same stack (both normal and RBS), hence no stack restoration is needed. * Other changes ** Using setcontext for all non-local jumps (for __ia64__) Along the way, I read a claim somewhere that setcontext was more reliable than longjmp, in cases where the stack has been manipulated. I don't now have any reason to believe this, but it seems reasonable anyway to leave the __ia64__ code using getcontext/setcontext, instead of setjmp/longjmp. (I think the only possible argument against this would be performance - if getcontext was significantly slower than setjmp. It that proves to be the case, we should revisit this.) ** Capping RBS base for non-main threads Somewhere else along the way, I hit a problem in GC, involving the RBS stack of a non-main thread. The problem was, in SCM_MARK_BACKING_STORE, that scm_ia64_register_backing_store_base was returning a value that was massively greater than the value of scm_ia64_ar_bsp, leading to a seg fault. This is because the implementation of scm_ia64_register_backing_store_base is only valid for the main thread. I couldn't find a neat way of getting the true RBS base of a non-main thread, but one idea is simply to call scm_ia64_ar_bsp when guilifying a thread, and use the value returned as an upper bound for that thread's RBS base. (Note that the RBS stack grows upwards.) (Were it not for scm_init_guile, we could be much more definitive about this. We could take the value of scm_ia64_ar_bsp as a definitive base address for the part of the RBS stack that Guile cares about. We could also then discard scm_ia64_register_backing_store_base.)
2008-02-07 * threads.c (do_thread_exit, scm_cancel_thread,Neil Jerram1-8/+4
scm_set_thread_cleanup_x, scm_thread_cleanup): Lock on thread-specific admin mutex instead of `thread_admin_mutex'. * threads.h (scm_i_thread)[admin_mutex]: New field. * throw.c (make_jmpbuf): Don't enter critical section during thread spawn -- there is a possibility of deadlock if other threads are exiting.
2007-01-22* backtrace.c, debug.c, debug.h, deprecation.c, eq.c, eval.cHan-Wen Nienhuys1-0/+3
eval.h, gsubr.c, init.c, macros.c, print.c, print.h, read.c, read.h, stacks.c, symbols.c, throw.c: use private-options.h * private-options.h: new file: contain hardcoded option definitions.
2007-01-18(scm_ithrow): more refined error message: print symbolsHan-Wen Nienhuys1-3/+10
too.
2007-01-10(scm_ithrow): print out key symbol and string argumentsHan-Wen Nienhuys1-0/+18
when error happens inside a critical section, and document why.
2006-06-17merge from 1.8 branchKevin Ryde1-0/+5
2006-05-29(scm_ithrow): When looking for the jmpbuf, first test that we have aMarius Vollmer1-1/+2
pair before accessing its cdr. Thanks to Bill Schottstaedt!
2006-04-17merge from 1.8 branchKevin Ryde1-1/+1
2006-02-04* throw.h (scm_c_catch, scm_c_with_throw_handler,Neil Jerram1-69/+232
scm_catch_with_pre_unwind_handler, scm_with_throw_handler): New. * throw.c (SCM_JBPREUNWIND, SCM_SETJBPREUNWIND): New. (struct pre_unwind_data): New, replaces struct lazy_catch. (scm_c_catch): New, replaces scm_internal_catch as the primary catch API for C code; adds pre-unwind handler support. (scm_internal_catch): Now just a wrapper for scm_c_catch, for back compatibility. (tc16_pre_unwind_data, pre_unwind_data_print, make_pre_unwind_data, SCM_PRE_UNWIND_DATA_P): Renamed from "lazy_catch" equivalents. (scm_c_with_throw_handler): New, replaces scm_internal_lazy_catch as the primary C API for a "lazy" catch. (scm_internal_lazy_catch): Now just a wrapper for scm_c_with_throw_handler, for back compatibility. (scm_catch_with_pre_unwind_handler): Renamed from scm_catch; adds pre-unwind handler support. (scm_catch): Now just a wrapper for scm_catch_with_pre_unwind_handler, for back compatibility. (scm_with_throw_handler): New. (scm_lazy_catch): Update comment to say that the handler can return, and what happens if it does. (toggle_pre_unwind_running): New. (scm_ithrow): When identifying the throw target, take running flags into account. In general, change naming of things from "lazy_catch" to "pre_unwind". When throwing to a throw handler, don't unwind the dynamic context first. Add dynwind framing to manage the running flag of a throw handler. If a lazy catch or throw handler returns, rethrow the same exception again. Add pre-unwind support to the normal catch case (SCM_JMPBUFP). * root.c (scm_internal_cwdr): Add NULL args to scm_i_with_continuation_barrier call. * dynwind.c: Change comment mentioning lazy-catch to mention pre-unwind data and throw handler also. * continuations.h (scm_i_with_continuation_barrier): Add pre-unwind handler args. * continuations.c (scm_i_with_continuation_barrier): Add pre-unwind handler args, and pass on to scm_c_catch (changed from scm_internal_catch). (c_handler): Remove scm_handle_by_message_noexit call. (scm_c_with_continuation_barrier): Call scm_i_with_continuation_barrier with scm_handle_by_message_noexit as the pre-unwind handler. (scm_handler): Remove scm_handle_by_message_noexit call. (s_scm_with_continuation_barrier): Call scm_i_with_continuation_barrier with scm_handle_by_message_noexit as the pre-unwind handler.
2005-05-23The FSF has a new address.Marius Vollmer1-1/+1
2005-03-07* throw.c (scm_ithrow): Abort when scm_i_critical_section_level isMarius Vollmer1-0/+7
not zero.
2005-03-02See ChangeLog from 2005-03-02.Marius Vollmer1-31/+32
2005-01-24Reverted changed from 2005/01/24 19:14:54, which was a commit to theMarius Vollmer1-1/+1
wrong branch. Sorry.
2005-01-24Threading changes.Marius Vollmer1-1/+1
2004-10-22* variable.c, threads.c, struct.c, stackchk.c, smob.c, root.c,Marius Vollmer1-1/+1
print.c, ports.c, mallocs.c, hooks.c, hashtab.c, fports.c, guardians.c, filesys.c, coop-pthreads.c, continuations.c: Use scm_uintprint to print unsigned integers, raw heap words, and adresses, using a cast to scm_t_bits to turn pointers into integers.
2004-09-23(handler_message): The rest argument is the fourthMarius Vollmer1-4/+14
argument, not everything after the third. Call scm_display_backtrace_with_highlights, passing the rest argument when appropriate.
2004-09-22*** empty log message ***Marius Vollmer1-4/+4