ruby-changes:5268
From: knu <ko1@a...>
Date: Tue, 3 Jun 2008 12:58:49 +0900 (JST)
Subject: [ruby-changes:5268] Ruby:r16767 (trunk): * enumerator.c (enumerator_allocate, enumerator_ptr): Properly
knu 2008-06-03 12:58:30 +0900 (Tue, 03 Jun 2008) New Revision: 16767 Modified files: trunk/ChangeLog trunk/enumerator.c Log: * enumerator.c (enumerator_allocate, enumerator_ptr): Properly detect if the object is initialized and raise error when appropriate. (enumerator_initialize): Fix a typo in rdoc. [ruby-core:17052] http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=16767&r2=16766&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/enumerator.c?r1=16767&r2=16766&diff_format=u Index: ChangeLog =================================================================== --- ChangeLog (revision 16766) +++ ChangeLog (revision 16767) @@ -1,3 +1,10 @@ +Tue Jun 3 12:51:57 2008 Akinori MUSHA <knu@i...> + + * enumerator.c (enumerator_allocate, enumerator_ptr): Properly + detect if the object is initialized and raise error when + appropriate. + (enumerator_initialize): Fix a typo in rdoc. [ruby-core:17052] + Tue Jun 3 01:21:51 2008 Yusuke Endoh <mame@t...> * test/ruby/test_method.rb: add a test. Index: enumerator.c =================================================================== --- enumerator.c (revision 16766) +++ enumerator.c (revision 16767) @@ -56,7 +56,7 @@ "wrong argument type %s (expected %s)", rb_obj_classname(obj), rb_class2name(rb_cEnumerator)); } - if (!ptr) { + if (!ptr || ptr->obj == Qundef) { rb_raise(rb_eArgError, "uninitialized enumerator"); } return ptr; @@ -204,8 +204,13 @@ enumerator_allocate(VALUE klass) { struct enumerator *ptr; - return Data_Make_Struct(klass, struct enumerator, - enumerator_mark, -1, ptr); + VALUE enum_obj; + + enum_obj = Data_Make_Struct(klass, struct enumerator, + enumerator_mark, -1, ptr); + ptr->obj = Qundef; + + return enum_obj; } static VALUE @@ -217,8 +222,14 @@ static VALUE enumerator_init(VALUE enum_obj, VALUE obj, VALUE meth, int argc, VALUE *argv) { - struct enumerator *ptr = enumerator_ptr(enum_obj); + struct enumerator *ptr; + Data_Get_Struct(enum_obj, struct enumerator, ptr); + + if (!ptr) { + rb_raise(rb_eArgError, "unallocated enumerator"); + } + ptr->obj = obj; ptr->meth = rb_to_id(meth); if (argc) ptr->args = rb_ary_new4(argc, argv); @@ -237,8 +248,7 @@ * used as an Enumerable object using the given object's given * method with the given arguments. * - * Use of this method is not discouraged. Use Kernel#enum_for() - * instead. + * Use of this method is discouraged. Use Kernel#enum_for() instead. */ static VALUE enumerator_initialize(int argc, VALUE *argv, VALUE obj) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/