From 65388f24bfdd5dafbbca401e59d6ced7a2b04296 Mon Sep 17 00:00:00 2001 From: matz Date: Fri, 21 Dec 2007 05:59:20 +0000 Subject: * enumerator.c (enumerator_init_copy): prohibit cloning of generators since Fibers cannot be copied. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@14404 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- enumerator.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'enumerator.c') diff --git a/enumerator.c b/enumerator.c index 366c64c28..729d7c04c 100644 --- a/enumerator.c +++ b/enumerator.c @@ -285,14 +285,20 @@ enumerator_initialize(int argc, VALUE *argv, VALUE obj) static VALUE enumerator_init_copy(VALUE obj, VALUE orig) { - struct enumerator *ptr0 = enumerator_ptr(orig); - struct enumerator *ptr1 = enumerator_ptr(obj); + struct enumerator *ptr0, *ptr1; + + ptr0 = enumerator_ptr(orig); + if (ptr1->fib) { + /* Fibers cannot be copied */ + rb_raise(rb_eTypeError, "can't copy execution context"); + } + ptr1 = enumerator_ptr(obj); ptr1->method = ptr0->method; ptr1->proc = ptr0->proc; ptr1->iter = ptr0->iter; ptr1->args = ptr0->args; - ptr1->fib = ptr0->fib; + ptr1->fib = 0; return obj; } -- cgit