From d55c0f53825546c309dc613e34a96b2b13d61170 Mon Sep 17 00:00:00 2001 From: ko1 Date: Sun, 26 Aug 2007 03:31:20 +0000 Subject: [PATCH] * cont.c: fix to remove Fiber.new until fiber.so is not loaded. * test/ruby/test_continuation.rb: fix to use resume. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13278 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ cont.c | 26 ++++++++++++++++---------- test/ruby/test_continuation.rb | 2 +- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1c2713760d..0b526eb5c6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Sun Aug 26 12:27:14 2007 Koichi Sasada + + * cont.c: fix to remove Fiber.new until fiber.so is not loaded. + + * test/ruby/test_continuation.rb: fix to use resume. + Sun Aug 26 06:51:46 2007 Masaki Suketa * ext/win32ole/win32ole.c (ole_wc2mb, reg_enum_key): allocate diff --git a/cont.c b/cont.c index cb0745c276..c50b50e3f2 100644 --- a/cont.c +++ b/cont.c @@ -471,16 +471,10 @@ rb_cont_call(int argc, VALUE *argv, VALUE contval) #define FIBER_VM_STACK_SIZE (4 * 1024) -VALUE -rb_fiber_new(VALUE (*func)(ANYARGS), VALUE obj) -{ - return rb_block_call(rb_cFiber, rb_intern("new"), 0, 0, func, obj); -} - static VALUE -rb_fiber_s_new(VALUE self) +fiber_alloc(VALUE klass, VALUE proc) { - rb_context_t *cont = cont_new(self); + rb_context_t *cont = cont_new(klass); VALUE contval = cont->self; rb_thread_t *th = &cont->saved_thread; @@ -507,13 +501,25 @@ rb_fiber_s_new(VALUE self) th->cfp->block_iseq = 0; th->tag = 0; - th->first_proc = rb_block_proc(); + th->first_proc = proc; MEMCPY(&cont->jmpbuf, &th->root_jmpbuf, rb_jmpbuf_t, 1); return contval; } +VALUE +rb_fiber_new(VALUE (*func)(ANYARGS), VALUE obj) +{ + return fiber_alloc(rb_cFiber, rb_proc_new(func, obj)); +} + +static VALUE +rb_fiber_s_new(VALUE self) +{ + return fiber_alloc(self, rb_block_proc()); +} + static VALUE return_fiber(void) { @@ -725,7 +731,6 @@ Init_Cont(void) { rb_cFiber = rb_define_class("Fiber", rb_cObject); rb_undef_alloc_func(rb_cFiber); - rb_define_singleton_method(rb_cFiber, "new", rb_fiber_s_new, 0); rb_eFiberError = rb_define_class("FiberError", rb_eStandardError); } @@ -743,6 +748,7 @@ Init_Continuation_body(void) void Init_Fiber_body(void) { + rb_define_singleton_method(rb_cFiber, "new", rb_fiber_s_new, 0); rb_define_method(rb_cFiber, "resume", rb_fiber_m_resume, -1); rb_define_method(rb_cFiber, "transfer", rb_fiber_m_transfer, -1); rb_define_method(rb_cFiber, "alive?", rb_fiber_alive_p, 0); diff --git a/test/ruby/test_continuation.rb b/test/ruby/test_continuation.rb index eccc973932..0313d71249 100644 --- a/test/ruby/test_continuation.rb +++ b/test/ruby/test_continuation.rb @@ -46,7 +46,7 @@ class TestContinuation < Test::Unit::TestCase c = nil Fiber.new do callcc {|c2| c = c2 } - end.yield + end.resume c.call } end