* cont.c (cont_capture): store all local variables in heap
([ruby-dev:30832]). * vm.c (th_stack_to_heap): added. * test/ruby/test_continuation.rb: add a test for above. * eval_intern.h (th_get_ruby_level_cfp): fix to clean code. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12415 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
426fcba891
commit
284565992f
11
ChangeLog
11
ChangeLog
@ -1,3 +1,14 @@
|
|||||||
|
Wed May 30 14:43:00 2007 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
|
* cont.c (cont_capture): store all local variables in heap
|
||||||
|
([ruby-dev:30832]).
|
||||||
|
|
||||||
|
* vm.c (th_stack_to_heap): added.
|
||||||
|
|
||||||
|
* test/ruby/test_continuation.rb: add a test for above.
|
||||||
|
|
||||||
|
* eval_intern.h (th_get_ruby_level_cfp): fix to clean code.
|
||||||
|
|
||||||
Wed May 30 13:32:34 2007 Shugo Maeda <shugo@ruby-lang.org>
|
Wed May 30 13:32:34 2007 Shugo Maeda <shugo@ruby-lang.org>
|
||||||
|
|
||||||
* lib/net/imap.rb (ResponseParser#next_token): fixed
|
* lib/net/imap.rb (ResponseParser#next_token): fixed
|
||||||
|
10
cont.c
10
cont.c
@ -120,11 +120,17 @@ cont_new(VALUE klass)
|
|||||||
return cont;
|
return cont;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void th_stack_to_heap(rb_thread_t *th);
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
cont_capture(volatile int *stat)
|
cont_capture(volatile int *stat)
|
||||||
{
|
{
|
||||||
rb_context_t *cont = cont_new(rb_cCont);
|
rb_context_t *cont;
|
||||||
rb_thread_t *th = &cont->saved_thread;
|
rb_thread_t *th;
|
||||||
|
|
||||||
|
th_stack_to_heap(GET_THREAD());
|
||||||
|
cont = cont_new(rb_cCont);
|
||||||
|
th = &cont->saved_thread;
|
||||||
|
|
||||||
cont->vm_stack = ALLOC_N(VALUE, th->stack_size);
|
cont->vm_stack = ALLOC_N(VALUE, th->stack_size);
|
||||||
MEMCPY(cont->vm_stack, th->stack, VALUE, th->stack_size);
|
MEMCPY(cont->vm_stack, th->stack, VALUE, th->stack_size);
|
||||||
|
@ -207,18 +207,13 @@ NODE *th_set_special_cref(rb_thread_t *th, VALUE *lfp, NODE * cref_stack);
|
|||||||
static rb_control_frame_t *
|
static rb_control_frame_t *
|
||||||
th_get_ruby_level_cfp(rb_thread_t *th, rb_control_frame_t *cfp)
|
th_get_ruby_level_cfp(rb_thread_t *th, rb_control_frame_t *cfp)
|
||||||
{
|
{
|
||||||
rb_iseq_t *iseq = 0;
|
|
||||||
while (!RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(th, cfp)) {
|
while (!RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(th, cfp)) {
|
||||||
if (RUBY_VM_NORMAL_ISEQ_P(cfp->iseq)) {
|
if (RUBY_VM_NORMAL_ISEQ_P(cfp->iseq)) {
|
||||||
iseq = cfp->iseq;
|
return cfp;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
|
cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
|
||||||
}
|
}
|
||||||
if (!iseq) {
|
return 0;
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return cfp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline NODE *
|
static inline NODE *
|
||||||
|
@ -18,6 +18,20 @@ class TestContinuation < Test::Unit::TestCase
|
|||||||
assert_equal([:a, :b, :b], ary)
|
assert_equal([:a, :b, :b], ary)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_check_localvars
|
||||||
|
vv = 0
|
||||||
|
@v = 0
|
||||||
|
@ary = []
|
||||||
|
[1, 2, 3].each{|i|
|
||||||
|
callcc {|k| @k = k}
|
||||||
|
@v += 1
|
||||||
|
vv += 1
|
||||||
|
}
|
||||||
|
@ary << [vv, @v]
|
||||||
|
@k.call if @v < 10
|
||||||
|
assert_equal((3..10).map{|e| [e, e]}, @ary)
|
||||||
|
end
|
||||||
|
|
||||||
def test_error
|
def test_error
|
||||||
cont = callcc{|c| c}
|
cont = callcc{|c| c}
|
||||||
assert_raise(RuntimeError){
|
assert_raise(RuntimeError){
|
||||||
|
11
vm.c
11
vm.c
@ -400,7 +400,6 @@ th_collect_local_variables_in_heap(rb_thread_t *th, VALUE *dfp, VALUE ary)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
th_make_env_object(rb_thread_t *th, rb_control_frame_t *cfp)
|
th_make_env_object(rb_thread_t *th, rb_control_frame_t *cfp)
|
||||||
{
|
{
|
||||||
@ -413,6 +412,16 @@ th_make_env_object(rb_thread_t *th, rb_control_frame_t *cfp)
|
|||||||
return envval;
|
return envval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
th_stack_to_heap(rb_thread_t *th)
|
||||||
|
{
|
||||||
|
rb_control_frame_t *cfp = th->cfp;
|
||||||
|
while ((cfp = th_get_ruby_level_cfp(th, cfp)) != 0) {
|
||||||
|
th_make_env_object(th, cfp);
|
||||||
|
cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
th_make_proc_from_block(rb_thread_t *th, rb_control_frame_t *cfp,
|
th_make_proc_from_block(rb_thread_t *th, rb_control_frame_t *cfp,
|
||||||
rb_block_t *block)
|
rb_block_t *block)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user