Skip to content

Commit

Permalink
Merge pull request #12541 from JuliaLang/jb/finallyexception
Browse files Browse the repository at this point in the history
improve interaction of task switches and finally blocks (#12485)
  • Loading branch information
JeffBezanson committed Aug 21, 2015
2 parents 30ed04c + 649fa23 commit 97ac6a0
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 @@ -1216,16 +1216,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 @@ -1236,8 +1238,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 @@ -301,6 +301,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 97ac6a0

Please sign in to comment.