Skip to content

Commit

Permalink
improve interaction of task switches and finally blocks (#12485)
Browse files Browse the repository at this point in the history
- save the exception to be rethrown around the code in a finally block
- set bt_size=0 on task switch. since we don't remember which task the
  backtrace came from, it must be associated with the current task or else
  not exist.
  • Loading branch information
JeffBezanson committed Aug 10, 2015
1 parent ebd7230 commit 649fa23
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -1207,16 +1207,18 @@
(and catchb
(not (block-returns? catchb))))
(gensy)))
(retval (gensy))
(retval (if hasret (gensy) #f))
(bb (gensy))
(finally-exception (gensy))
(val (gensy))) ;; this is jlgensym, but llvm has trouble determining that it dominates all uses
(let ((tryb (replace-return tryb bb ret retval))
(catchb (replace-return catchb bb ret retval)))
(expand-binding-forms
`(scope-block
(block
(local ,retval)
,@(if hasret `((local ,retval)) '())
(local ,val)
(local ,finally-exception)
(= ,err false)
,@(if ret `((= ,ret false)) '())
(break-block
Expand All @@ -1227,8 +1229,9 @@
tryb))
#f
(= ,err true)))
(= ,finally-exception (the_exception))
,finalb
(if ,err (ccall 'jl_rethrow Void (tuple)))
(if ,err (ccall 'jl_rethrow_other Void (tuple Any) ,finally-exception))
,(if hasret
(if ret
`(if ,ret (return ,retval) ,val)
Expand Down
1 change: 1 addition & 0 deletions src/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ static void ctx_switch(jl_task_t *t, jl_jmp_buf *where)
*/
//JL_SIGATOMIC_BEGIN();
if (!jl_setjmp(jl_current_task->ctx, 0)) {
bt_size = 0; // backtraces don't survive task switches, see e.g. issue #12485
#ifdef COPY_STACKS
jl_task_t *lastt = jl_current_task;
save_stack(lastt);
Expand Down

0 comments on commit 649fa23

Please sign in to comment.