summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-08-25 02:03:44 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-08-25 02:03:44 +0000
commit977d66ec993b0f1892fb3e4cd8ac1c41716daf85 (patch)
tree90e36b2fb912f657c8b94278961b938c805c6dd8
parentcfaf3d9a1aee75a51f63bda5ff447da2bfc4234f (diff)
* cont.c: separate Continuation and Fiber from core.
* ext/continuation/*, ext/fiber/*: ditto. * include/ruby/ruby.h: remove rb_cFiber. * include/ruby/intern.h: add the rb_fiber_new() declaration. * enumerator.c (next_init): fix to use rb_fiber_new(). * test/ruby/test_enumerator.rb: remove next? tests. * test/ruby/test_continuation.rb: add a require 'continuation'. * test/ruby/test_fiber.rb: add a require 'fiber'. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13259 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog18
-rw-r--r--cont.c61
-rw-r--r--enumerator.c2
-rw-r--r--ext/continuation/continuation.c8
-rw-r--r--ext/continuation/extconf.rb3
-rw-r--r--ext/fiber/extconf.rb3
-rw-r--r--ext/fiber/fiber.c8
-rw-r--r--include/ruby/intern.h1
-rw-r--r--include/ruby/ruby.h1
-rw-r--r--test/ruby/test_continuation.rb2
-rw-r--r--test/ruby/test_enumerator.rb11
-rw-r--r--test/ruby/test_fiber.rb5
12 files changed, 83 insertions, 40 deletions
diff --git a/ChangeLog b/ChangeLog
index e37624d..34603b3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+Sat Aug 25 10:59:19 2007 Koichi Sasada <ko1@atdot.net>
+
+ * cont.c: separate Continuation and Fiber from core.
+
+ * ext/continuation/*, ext/fiber/*: ditto.
+
+ * include/ruby/ruby.h: remove rb_cFiber.
+
+ * include/ruby/intern.h: add the rb_fiber_new() declaration.
+
+ * enumerator.c (next_init): fix to use rb_fiber_new().
+
+ * test/ruby/test_enumerator.rb: remove next? tests.
+
+ * test/ruby/test_continuation.rb: add a require 'continuation'.
+
+ * test/ruby/test_fiber.rb: add a require 'fiber'.
+
Sat Aug 25 10:20:28 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* common.mk (prelude.o): depends on vm_core.h now.
diff --git a/cont.c b/cont.c
index 99fab9d..d98208a 100644
--- a/cont.c
+++ b/cont.c
@@ -34,10 +34,9 @@ typedef struct rb_context_struct {
int alive;
} rb_context_t;
-VALUE rb_cCont;
-VALUE rb_cFiber;
-VALUE rb_cFiberCore;
-VALUE rb_eFiberError;
+static VALUE rb_cContinuation;
+static VALUE rb_cFiber;
+static VALUE rb_eFiberError;
#define GetContPtr(obj, ptr) \
Data_Get_Struct(obj, rb_context_t, ptr)
@@ -151,9 +150,6 @@ cont_new(VALUE klass)
contval = Data_Make_Struct(klass, rb_context_t,
cont_mark, cont_free, cont);
- RUBY_GC_INFO("cont alloc: %p (klass: %s)\n", cont,
- klass == rb_cFiber ? "Fiber": "Continuation");
-
cont->self = contval;
cont->alive = Qtrue;
@@ -173,7 +169,7 @@ cont_capture(volatile int *stat)
volatile VALUE contval;
vm_stack_to_heap(th);
- cont = cont_new(rb_cCont);
+ cont = cont_new(rb_cContinuation);
contval = cont->self;
sth = &cont->saved_thread;
@@ -475,6 +471,12 @@ rb_cont_call(int argc, VALUE *argv, VALUE contval)
#define FIBER_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)
{
@@ -590,7 +592,7 @@ rb_fiber_current()
rb_thread_t *th = GET_THREAD();
if (th->fiber == 0) {
/* save root */
- rb_context_t *cont = cont_new(rb_cFiberCore);
+ rb_context_t *cont = cont_new(rb_cFiber);
cont->prev = Qnil;
th->root_fiber = th->fiber = cont->self;
}
@@ -720,30 +722,29 @@ rb_fiber_s_current(VALUE klass)
void
Init_Cont(void)
{
- rb_cCont = rb_define_class("Continuation", rb_cObject);
- rb_undef_alloc_func(rb_cCont);
- rb_undef_method(CLASS_OF(rb_cCont), "new");
- rb_define_method(rb_cCont, "call", rb_cont_call, -1);
- rb_define_method(rb_cCont, "[]", rb_cont_call, -1);
- rb_define_global_function("callcc", rb_callcc, 0);
-
rb_cFiber = rb_define_class("Fiber", rb_cObject);
rb_undef_alloc_func(rb_cFiber);
- rb_define_method(rb_cFiber, "resume", rb_fiber_m_resume, -1);
- rb_define_method(rb_cFiber, "alive?", rb_fiber_alive_p, 0);
-
- rb_define_singleton_method(rb_cFiber, "current", rb_fiber_s_current, 0);
- rb_define_singleton_method(rb_cFiber, "yield", rb_fiber_s_yield, -1);
rb_define_singleton_method(rb_cFiber, "new", rb_fiber_s_new, 0);
-
- rb_cFiberCore = rb_define_class_under(rb_cFiber, "Core", rb_cObject);
- rb_undef_alloc_func(rb_cFiberCore);
- rb_define_method(rb_cFiberCore, "transfer", rb_fiber_m_transfer, -1);
- rb_define_method(rb_cFiberCore, "alive?", rb_fiber_alive_p, 0);
-
- rb_define_singleton_method(rb_cFiberCore, "current", rb_fiber_s_current, 0);
- rb_define_singleton_method(rb_cFiberCore, "new", rb_fiber_s_new, 0);
-
rb_eFiberError = rb_define_class("FiberError", rb_eStandardError);
}
+void
+Init_Continuation_body(void)
+{
+ rb_cContinuation = rb_define_class("Continuation", rb_cObject);
+ rb_undef_alloc_func(rb_cContinuation);
+ rb_undef_method(CLASS_OF(rb_cContinuation), "new");
+ rb_define_method(rb_cContinuation, "call", rb_cont_call, -1);
+ rb_define_method(rb_cContinuation, "[]", rb_cont_call, -1);
+ rb_define_global_function("callcc", rb_callcc, 0);
+}
+
+void
+Init_Fiber_body(void)
+{
+ 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);
+ rb_define_singleton_method(rb_cFiber, "yield", rb_fiber_s_yield, -1);
+ rb_define_singleton_method(rb_cFiber, "current", rb_fiber_s_current, 0);
+}
diff --git a/enumerator.c b/enumerator.c
index 019179f..4cbe3fc 100644
--- a/enumerator.c
+++ b/enumerator.c
@@ -391,7 +391,7 @@ next_init(VALUE obj, struct enumerator *e)
{
VALUE curr = rb_fiber_current();
e->dst = curr;
- e->fib = rb_block_call(rb_cFiber, rb_intern("new"), 0, 0, next_i, obj);
+ e->fib = rb_fiber_new(next_i, obj);
}
/*
diff --git a/ext/continuation/continuation.c b/ext/continuation/continuation.c
new file mode 100644
index 0000000..a1b43b5
--- /dev/null
+++ b/ext/continuation/continuation.c
@@ -0,0 +1,8 @@
+
+void Init_Continuation_body(void);
+
+void
+Init_continuation(void)
+{
+ Init_Continuation_body();
+}
diff --git a/ext/continuation/extconf.rb b/ext/continuation/extconf.rb
new file mode 100644
index 0000000..17e2d05
--- /dev/null
+++ b/ext/continuation/extconf.rb
@@ -0,0 +1,3 @@
+require 'mkmf'
+create_makefile('continuation')
+
diff --git a/ext/fiber/extconf.rb b/ext/fiber/extconf.rb
new file mode 100644
index 0000000..904ab94
--- /dev/null
+++ b/ext/fiber/extconf.rb
@@ -0,0 +1,3 @@
+require 'mkmf'
+create_makefile('fiber')
+
diff --git a/ext/fiber/fiber.c b/ext/fiber/fiber.c
new file mode 100644
index 0000000..b6f5589
--- /dev/null
+++ b/ext/fiber/fiber.c
@@ -0,0 +1,8 @@
+
+void Init_Fiber_body(void);
+
+void
+Init_fiber(void)
+{
+ Init_Fiber_body();
+}
diff --git a/include/ruby/intern.h b/include/ruby/intern.h
index 485d390..aefee7f 100644
--- a/include/ruby/intern.h
+++ b/include/ruby/intern.h
@@ -148,6 +148,7 @@ VALUE rb_singleton_class(VALUE);
int rb_cmpint(VALUE, VALUE, VALUE);
NORETURN(void rb_cmperr(VALUE, VALUE));
/* cont.c */
+VALUE rb_fiber_new(VALUE (*)(ANYARGS), VALUE);
VALUE rb_fiber_resume(VALUE fib, int argc, VALUE *args);
VALUE rb_fiber_yield(int argc, VALUE *args);
VALUE rb_fiber_current(void);
diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h
index acb101a..ea32655 100644
--- a/include/ruby/ruby.h
+++ b/include/ruby/ruby.h
@@ -761,7 +761,6 @@ RUBY_EXTERN VALUE rb_cCont;
RUBY_EXTERN VALUE rb_cDir;
RUBY_EXTERN VALUE rb_cData;
RUBY_EXTERN VALUE rb_cFalseClass;
-RUBY_EXTERN VALUE rb_cFiber;
RUBY_EXTERN VALUE rb_cFile;
RUBY_EXTERN VALUE rb_cFixnum;
RUBY_EXTERN VALUE rb_cFloat;
diff --git a/test/ruby/test_continuation.rb b/test/ruby/test_continuation.rb
index 729da88..eccc973 100644
--- a/test/ruby/test_continuation.rb
+++ b/test/ruby/test_continuation.rb
@@ -1,4 +1,6 @@
require 'test/unit'
+require 'continuation'
+require 'fiber'
class TestContinuation < Test::Unit::TestCase
def test_create
diff --git a/test/ruby/test_enumerator.rb b/test/ruby/test_enumerator.rb
index 885cb4a..27a71e4 100644
--- a/test/ruby/test_enumerator.rb
+++ b/test/ruby/test_enumerator.rb
@@ -24,14 +24,13 @@ class TestEnumerator < Test::Unit::TestCase
assert_raise(StopIteration){e.next}
end
- def test_next?
+ def test_loop
e = 3.times
- assert_equal true, e.next?
- 3.times{|i|
- assert_equal true, e.next?
- assert_equal i, e.next
+ i = 0
+ loop{
+ assert_equal(i, e.next)
+ i += 1
}
- assert_equal false, e.next?
end
def test_nested_itaration
diff --git a/test/ruby/test_fiber.rb b/test/ruby/test_fiber.rb
index bd39ba5..a8bce8a 100644
--- a/test/ruby/test_fiber.rb
+++ b/test/ruby/test_fiber.rb
@@ -1,4 +1,5 @@
require 'test/unit'
+require 'fiber'
class TestFiber < Test::Unit::TestCase
def test_normal
@@ -118,11 +119,11 @@ class TestFiber < Test::Unit::TestCase
def test_transfer
ary = []
f2 = nil
- f1 = Fiber::Core.new{
+ f1 = Fiber.new{
ary << f2.transfer(:foo)
:ok
}
- f2 = Fiber::Core.new{
+ f2 = Fiber.new{
ary << f1.transfer(:baz)
:ng
}