diff options
author | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-06-03 03:58:30 +0000 |
---|---|---|
committer | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-06-03 03:58:30 +0000 |
commit | a6f184212ac43baa3f07f828c9663b91b8753ba1 (patch) | |
tree | 6d6ee454225469ff35224167521a1f9f1b64f96a | |
parent | 9b279fa55e3466a44a2f42f6769d0117887e81c4 (diff) | |
download | ruby-a6f184212ac43baa3f07f828c9663b91b8753ba1.tar.gz ruby-a6f184212ac43baa3f07f828c9663b91b8753ba1.tar.xz ruby-a6f184212ac43baa3f07f828c9663b91b8753ba1.zip |
* 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]
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@16767 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | enumerator.c | 22 |
2 files changed, 23 insertions, 6 deletions
@@ -1,3 +1,10 @@ +Tue Jun 3 12:51:57 2008 Akinori MUSHA <knu@iDaemons.org> + + * 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@tsg.ne.jp> * test/ruby/test_method.rb: add a test. diff --git a/enumerator.c b/enumerator.c index a930c2bfa..080151765 100644 --- a/enumerator.c +++ b/enumerator.c @@ -56,7 +56,7 @@ enumerator_ptr(VALUE obj) "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 @@ static VALUE 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,7 +222,13 @@ enumerator_each_i(VALUE v, VALUE enum_obj, int argc, VALUE *argv) 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); @@ -237,8 +248,7 @@ enumerator_init(VALUE enum_obj, VALUE obj, VALUE meth, int argc, VALUE *argv) * 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) |