From f53d8254474628f0c3710950ee342ecf941f2fd1 Mon Sep 17 00:00:00 2001 From: mame Date: Mon, 25 Jan 2010 18:22:58 +0000 Subject: [PATCH] * cont.c, vm_core.h, eval.c: because rb_protect must not be jumped by callcc, revert r26407. And rename trap_tag to protect_tag and change exception message (across trap -> across stack rewinding barrier). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26415 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 7 +++++++ cont.c | 7 +++++++ eval.c | 5 +++++ vm_core.h | 5 +++++ 4 files changed, 24 insertions(+) diff --git a/ChangeLog b/ChangeLog index 5edf2c0a5a..196f843d62 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Tue Jan 26 03:16:45 2010 Yusuke Endoh + + * cont.c, vm_core.h, eval.c: because rb_protect must not be jumped by + callcc, revert r26407. And rename trap_tag to protect_tag and + change exception message (across trap -> across stack rewinding + barrier). + Mon Jan 25 23:08:10 2010 NAKAMURA Usaku * thread.c (do_select): wrong conditions. [ruby-core:27753] diff --git a/cont.c b/cont.c index 932b10e2dc..185d8122e4 100644 --- a/cont.c +++ b/cont.c @@ -388,6 +388,7 @@ cont_restore_1(rb_context_t *cont) th->state = sth->state; th->status = sth->status; th->tag = sth->tag; + th->protect_tag = sth->protect_tag; th->errinfo = sth->errinfo; th->first_proc = sth->first_proc; @@ -620,6 +621,9 @@ rb_cont_call(int argc, VALUE *argv, VALUE contval) if (cont->saved_thread.self != th->self) { rb_raise(rb_eRuntimeError, "continuation called across threads"); } + if (cont->saved_thread.protect_tag != th->protect_tag) { + rb_raise(rb_eRuntimeError, "continuation called across stack rewinding barrier"); + } if (cont->saved_thread.fiber) { rb_fiber_t *fcont; GetFiberPtr(cont->saved_thread.fiber, fcont); @@ -936,6 +940,9 @@ fiber_switch(VALUE fibval, int argc, VALUE *argv, int is_resume) if (cont->saved_thread.self != th->self) { rb_raise(rb_eFiberError, "fiber called across threads"); } + else if (cont->saved_thread.protect_tag != th->protect_tag) { + rb_raise(rb_eFiberError, "fiber called across stack rewinding barrier"); + } else if (fib->status == TERMINATED) { value = rb_exc_new2(rb_eFiberError, "dead fiber called"); if (th->fiber != fibval) rb_exc_raise(value); diff --git a/eval.c b/eval.c index ffc924edce..6deed9cd30 100644 --- a/eval.c +++ b/eval.c @@ -690,14 +690,19 @@ rb_protect(VALUE (* proc) (VALUE), VALUE data, int * state) int status; rb_thread_t *th = GET_THREAD(); rb_control_frame_t *cfp = th->cfp; + struct rb_vm_protect_tag protect_tag; rb_jmpbuf_t org_jmpbuf; + protect_tag.prev = th->protect_tag; + PUSH_TAG(); + th->protect_tag = &protect_tag; MEMCPY(&org_jmpbuf, &(th)->root_jmpbuf, rb_jmpbuf_t, 1); if ((status = EXEC_TAG()) == 0) { SAVE_ROOT_JMPBUF(th, result = (*proc) (data)); } MEMCPY(&(th)->root_jmpbuf, &org_jmpbuf, rb_jmpbuf_t, 1); + th->protect_tag = protect_tag.prev; POP_TAG(); if (state) { diff --git a/vm_core.h b/vm_core.h index 705df82b18..126f48ec80 100644 --- a/vm_core.h +++ b/vm_core.h @@ -347,6 +347,10 @@ struct rb_vm_tag { struct rb_vm_tag *prev; }; +struct rb_vm_protect_tag { + struct rb_vm_protect_tag *prev; +}; + #define RUBY_VM_VALUE_CACHE_SIZE 0x1000 #define USE_VALUE_CACHE 0 @@ -410,6 +414,7 @@ typedef struct rb_thread_struct int transition_for_lock; struct rb_vm_tag *tag; + struct rb_vm_protect_tag *protect_tag; int parse_in_eval; int mild_compile_error;