vm_eval.c: preserve passed_block
* vm_eval.c (check_funcall_respond_to): preserve passed_block, which is modified in vm_call0_body() via vm_call0(), and caused a bug of rb_check_funcall() by false negative result of rb_block_given_p(). re-fix [ruby-core:53650] [Bug #8153]. [ruby-core:53653] [Bug #8154] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39881 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
1a56e716b1
commit
04c9bdb190
@ -1,7 +1,10 @@
|
|||||||
Sat Mar 23 07:30:31 2013 Marc-Andre Lafortune <ruby-core@marc-andre.ca>
|
Sat Mar 23 17:39:49 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* array.c: Avoid zip bug by not using obsolete rb_check_block_call
|
* vm_eval.c (check_funcall_respond_to): preserve passed_block, which
|
||||||
[Bug #8153]
|
is modified in vm_call0_body() via vm_call0(), and caused a bug of
|
||||||
|
rb_check_funcall() by false negative result of rb_block_given_p().
|
||||||
|
re-fix [ruby-core:53650] [Bug #8153].
|
||||||
|
[ruby-core:53653] [Bug #8154]
|
||||||
|
|
||||||
Fri Mar 22 17:48:34 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Fri Mar 22 17:48:34 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
22
array.c
22
array.c
@ -17,7 +17,6 @@
|
|||||||
#include "ruby/encoding.h"
|
#include "ruby/encoding.h"
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
#include "probes.h"
|
#include "probes.h"
|
||||||
#include "node.h"
|
|
||||||
#include "id.h"
|
#include "id.h"
|
||||||
|
|
||||||
#ifndef ARRAY_DEBUG
|
#ifndef ARRAY_DEBUG
|
||||||
@ -3033,11 +3032,11 @@ rb_ary_delete_if(VALUE ary)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
take_i(VALUE i, VALUE args, int argc, VALUE *argv)
|
take_i(VALUE val, VALUE *args, int argc, VALUE *argv)
|
||||||
{
|
{
|
||||||
NODE *memo = RNODE(args);
|
if (args[1]-- == 0) rb_iter_break();
|
||||||
rb_ary_push(memo->u1.value, rb_enum_values_pack(argc, argv));
|
if (argc > 1) val = rb_ary_new4(argc, argv);
|
||||||
if (--memo->u3.cnt == 0) rb_iter_break();
|
rb_ary_push(args[0], val);
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3045,19 +3044,18 @@ static VALUE
|
|||||||
take_items(VALUE obj, long n)
|
take_items(VALUE obj, long n)
|
||||||
{
|
{
|
||||||
VALUE result = rb_check_array_type(obj);
|
VALUE result = rb_check_array_type(obj);
|
||||||
NODE *memo;
|
VALUE args[2];
|
||||||
|
|
||||||
if (!NIL_P(result)) return rb_ary_subseq(result, 0, n);
|
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);
|
result = rb_ary_new2(n);
|
||||||
memo = NEW_MEMO(result, 0, n);
|
args[0] = result; args[1] = (VALUE)n;
|
||||||
rb_block_call(obj, idEach, 0, 0, take_i, (VALUE)memo);
|
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));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* ary.zip(arg, ...) -> new_ary
|
* ary.zip(arg, ...) -> new_ary
|
||||||
|
@ -358,7 +358,8 @@ check_funcall_respond_to(rb_thread_t *th, VALUE klass, VALUE recv, ID mid)
|
|||||||
const rb_method_entry_t *me = rb_method_entry(klass, idRespond_to, &defined_class);
|
const rb_method_entry_t *me = rb_method_entry(klass, idRespond_to, &defined_class);
|
||||||
|
|
||||||
if (me && !(me->flag & NOEX_BASIC)) {
|
if (me && !(me->flag & NOEX_BASIC)) {
|
||||||
VALUE args[2];
|
const rb_block_t *passed_block = th->passed_block;
|
||||||
|
VALUE args[2], result;
|
||||||
int arity = rb_method_entry_arity(me);
|
int arity = rb_method_entry_arity(me);
|
||||||
|
|
||||||
if (arity > 2)
|
if (arity > 2)
|
||||||
@ -368,7 +369,9 @@ check_funcall_respond_to(rb_thread_t *th, VALUE klass, VALUE recv, ID mid)
|
|||||||
|
|
||||||
args[0] = ID2SYM(mid);
|
args[0] = ID2SYM(mid);
|
||||||
args[1] = Qtrue;
|
args[1] = Qtrue;
|
||||||
if (!RTEST(vm_call0(th, recv, idRespond_to, arity, args, me, defined_class))) {
|
result = vm_call0(th, recv, idRespond_to, arity, args, me, defined_class);
|
||||||
|
th->passed_block = passed_block;
|
||||||
|
if (!RTEST(result)) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user