summaryrefslogtreecommitdiff
path: root/array.c
diff options
context:
space:
mode:
authormarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-03-22 22:30:45 +0000
committermarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-03-22 22:30:45 +0000
commitcb0093d54552cff4c1c914973ffe30e7d175cd64 (patch)
treead166874a4ae786b943dd1798e8d99e5ecae364d /array.c
parent4edd787b140737172ff8f74ac556ce7b9c58e8d6 (diff)
* array.c: Avoid zip bug by not using obsolete rb_check_block_call [Bug #8153]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39877 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r--array.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/array.c b/array.c
index da94b3a100..daf66e5ea9 100644
--- a/array.c
+++ b/array.c
@@ -17,6 +17,7 @@
#include "ruby/encoding.h"
#include "internal.h"
#include "probes.h"
+#include "node.h"
#include "id.h"
#ifndef ARRAY_DEBUG
@@ -3032,11 +3033,11 @@ rb_ary_delete_if(VALUE ary)
}
static VALUE
-take_i(VALUE val, VALUE *args, int argc, VALUE *argv)
+take_i(VALUE i, VALUE args, int argc, VALUE *argv)
{
- if (args[1]-- == 0) rb_iter_break();
- if (argc > 1) val = rb_ary_new4(argc, argv);
- rb_ary_push(args[0], val);
+ NODE *memo = RNODE(args);
+ rb_ary_push(memo->u1.value, rb_enum_values_pack(argc, argv));
+ if (--memo->u3.cnt == 0) rb_iter_break();
return Qnil;
}
@@ -3044,18 +3045,19 @@ static VALUE
take_items(VALUE obj, long n)
{
VALUE result = rb_check_array_type(obj);
- VALUE args[2];
+ NODE *memo;
if (!NIL_P(result)) return rb_ary_subseq(result, 0, n);
+ if (!rb_respond_to(obj, idEach)) {
+ rb_raise(rb_eTypeError, "wrong argument type %s (must respond to :each)",
+ rb_obj_classname(obj));
+ }
result = rb_ary_new2(n);
- args[0] = result; args[1] = (VALUE)n;
- if (rb_check_block_call(obj, idEach, 0, 0, take_i, (VALUE)args) == Qundef)
- rb_raise(rb_eTypeError, "wrong argument type %s (must respond to :each)",
- rb_obj_classname(obj));
+ memo = NEW_MEMO(result, 0, n);
+ rb_block_call(obj, idEach, 0, 0, take_i, (VALUE)memo);
return result;
}
-
/*
* call-seq:
* ary.zip(arg, ...) -> new_ary