From: David Flanagan Date: 2007-09-12T08:05:42+09:00 Subject: autoloading Fiber In order to use the new Fiber class in 1.9, we have to require 'fiber'. The fiber functionality is actually built into the core (so it can be used for external iterators) but in order to get at the API for using it in Ruby, we have to require 'fiber'. Ko1 says that this is for safety reasons. (The same goes for continuations in Ruby 1.9: you must explictly require them if you want to use them.) Someone (I forget who) on this list pointed out that the Fiber class itself is defined by default, but that the methods of the class are not. I don't understand why this is, and I've just realized that it causes problems with autoload: autoload :Fiber, "fiber" This won't work. Since Fiber is already defined, the "fiber" module will never be autoloaded... (Unless ko1 thinks that fibers are so unsafe we should not be allowed to autoload them? :-) Maybe I'm missing something, but I don't see any code that depends on the Fiber constant being defined before any of its methods are, so I'm wondering if the patch below wouldn't be okay. I've barely tested it, but it makes autoload work and it doesn't seem to interfere with external iterators. David $ diff -u cont.c~ cont.c --- cont.c~ 2007-08-29 22:59:14.000000000 -0700 +++ cont.c 2007-09-11 15:55:37.000000000 -0700 @@ -729,9 +729,6 @@ void Init_Cont(void) { - rb_cFiber = rb_define_class("Fiber", rb_cObject); - rb_undef_alloc_func(rb_cFiber); - rb_eFiberError = rb_define_class("FiberError", rb_eStandardError); } void @@ -748,6 +745,9 @@ void Init_Fiber_body(void) { + rb_cFiber = rb_define_class("Fiber", rb_cObject); + rb_undef_alloc_func(rb_cFiber); + rb_eFiberError = rb_define_class("FiberError", rb_eStandardError); 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);