summaryrefslogtreecommitdiff
path: root/cont.c
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-11-09 04:26:39 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-11-09 04:26:39 +0000
commit9cd8b76e6df560d1da61138e99eab76b7c3e1f6b (patch)
treeecd19cfe7725e89638ca973121a3c2de646444ad /cont.c
parentb2c44e7af5b2eb17dc492dc2a2431cfe29b02d89 (diff)
* cont.c (rb_fiber_m_transfer, rb_fiber_resume): prohibit using
"resume" after "transfer" method are used. You should not mix "resume" fiber and "transfer" fiber. [Bug #5526] * NEWS: add information about this change. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33684 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'cont.c')
-rw-r--r--cont.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/cont.c b/cont.c
index 0ed1f2c..cb934f7 100644
--- a/cont.c
+++ b/cont.c
@@ -103,6 +103,12 @@ typedef struct rb_fiber_struct {
enum fiber_status status;
struct rb_fiber_struct *prev_fiber;
struct rb_fiber_struct *next_fiber;
+ /* If a fiber invokes "transfer",
+ * then this fiber can't "resume" any more after that.
+ * You shouldn't mix "transfer" and "resume".
+ */
+ int transfered;
+
#if FIBER_USE_NATIVE
#ifdef _WIN32
void *fib_handle;
@@ -1322,6 +1328,9 @@ rb_fiber_resume(VALUE fibval, int argc, VALUE *argv)
if (fib->prev != Qnil || fib->cont.type == ROOT_FIBER_CONTEXT) {
rb_raise(rb_eFiberError, "double resume");
}
+ if (fib->transfered != 0) {
+ rb_raise(rb_eFiberError, "cannot resume transferred Fiber");
+ }
return fiber_switch(fibval, argc, argv, 1);
}
@@ -1389,9 +1398,12 @@ rb_fiber_m_resume(int argc, VALUE *argv, VALUE fib)
* back to this fiber before it can yield and resume.
*/
static VALUE
-rb_fiber_m_transfer(int argc, VALUE *argv, VALUE fib)
+rb_fiber_m_transfer(int argc, VALUE *argv, VALUE fibval)
{
- return rb_fiber_transfer(fib, argc, argv);
+ rb_fiber_t *fib;
+ GetFiberPtr(fibval, fib);
+ fib->transfered = 1;
+ return rb_fiber_transfer(fibval, argc, argv);
}
/*