summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--enum.c16
-rw-r--r--version.h2
3 files changed, 19 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index 4a0c8e2339..6124f640d8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Tue Jun 2 17:32:40 2009 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * enum.c (first_i): Enumerator#first should consume only what is
+ needed. a patch from Marc-Andre Lafortune. [ruby-core:23661]
+
+ * enum.c (enum_first): call to_int once for an argument. based on
+ a patch from Marc-Andre Lafortune.
+
Tue Jun 2 13:27:21 2009 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
* test/ripper/test_filter.rb: add tests. see [ruby-dev:37856]
diff --git a/enum.c b/enum.c
index 8c4b5b93e0..f37bf0d375 100644
--- a/enum.c
+++ b/enum.c
@@ -616,14 +616,14 @@ first_i(VALUE i, VALUE *ary, int argc, VALUE *argv)
rb_iter_break();
}
else {
- long n = NUM2LONG(ary[0]);
+ long n = ary[0];
+ rb_ary_push(ary[1], i);
+ n--;
if (n <= 0) {
rb_iter_break();
}
- rb_ary_push(ary[1], i);
- n--;
- ary[0] = INT2NUM(n);
+ ary[0] = n;
}
return Qnil;
}
@@ -648,9 +648,13 @@ enum_first(int argc, VALUE *argv, VALUE obj)
ary[0] = ary[1] = Qnil;
}
else {
+ long len;
+
rb_scan_args(argc, argv, "01", &n);
- ary[0] = n;
- ary[1] = rb_ary_new2(NUM2LONG(n));
+ len = NUM2LONG(n);
+ if (len == 0) return rb_ary_new2(0);
+ ary[0] = len;
+ ary[1] = rb_ary_new2(len);
}
rb_block_call(obj, id_each, 0, 0, first_i, (VALUE)ary);
diff --git a/version.h b/version.h
index 3e7d44b7b7..4fa3d93236 100644
--- a/version.h
+++ b/version.h
@@ -1,6 +1,6 @@
#define RUBY_VERSION "1.9.1"
#define RUBY_RELEASE_DATE "2009-05-22"
-#define RUBY_PATCHLEVEL 166
+#define RUBY_PATCHLEVEL 167
#define RUBY_VERSION_MAJOR 1
#define RUBY_VERSION_MINOR 9
#define RUBY_VERSION_TEENY 1