mirror of
https://github.com/ruby/ruby.git
synced 2025-09-18 01:54:00 +02:00
merge revision(s) 43929: [Backport #9178]
* enumerator.c (enumerator_with_index): should not store local variable address to memoise the arguments. it is invalidated after the return. [ruby-core:58692] [Bug #9178] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@43961 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
b851418bb7
commit
c27bd84806
4 changed files with 21 additions and 5 deletions
|
@ -1,3 +1,9 @@
|
|||
Mon Dec 2 23:31:00 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* enumerator.c (enumerator_with_index): should not store local variable
|
||||
address to memoise the arguments. it is invalidated after the return.
|
||||
[ruby-core:58692] [Bug #9178]
|
||||
|
||||
Mon Dec 2 23:16:50 2013 Eric Hodel <drbrain@segment7.net>
|
||||
|
||||
* enumerator.c (enumerator_with_index): Restore handling of a nil memo
|
||||
|
|
|
@ -460,9 +460,9 @@ enumerator_each(int argc, VALUE *argv, VALUE obj)
|
|||
static VALUE
|
||||
enumerator_with_index_i(VALUE val, VALUE m, int argc, VALUE *argv)
|
||||
{
|
||||
VALUE *memo = (VALUE *)m;
|
||||
VALUE idx = *memo;
|
||||
*memo = rb_int_succ(idx);
|
||||
NODE *memo = (NODE *)m;
|
||||
VALUE idx = memo->u1.value;
|
||||
memo->u1.value = rb_int_succ(idx);
|
||||
|
||||
if (argc <= 1)
|
||||
return rb_yield_values(2, val, idx);
|
||||
|
@ -494,7 +494,7 @@ enumerator_with_index(int argc, VALUE *argv, VALUE obj)
|
|||
RETURN_SIZED_ENUMERATOR(obj, argc, argv, enumerator_size);
|
||||
if (NIL_P(memo))
|
||||
memo = INT2NUM(0);
|
||||
return enumerator_block_call(obj, enumerator_with_index_i, (VALUE)&memo);
|
||||
return enumerator_block_call(obj, enumerator_with_index_i, (VALUE)NEW_MEMO(memo, 0, 0));
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -112,6 +112,16 @@ class TestEnumerator < Test::Unit::TestCase
|
|||
assert_equal([[1,s],[2,s+1],[3,s+2]], @obj.to_enum(:foo, 1, 2, 3).with_index(s).to_a, bug8010)
|
||||
end
|
||||
|
||||
def test_with_index_dangling_memo
|
||||
bug9178 = '[ruby-core:58692] [Bug #9178]'
|
||||
assert_separately([], <<-"end;")
|
||||
bug = "#{bug9178}"
|
||||
e = [1].to_enum(:chunk).with_index {|c,i| i == 5}
|
||||
assert_kind_of(Enumerator, e)
|
||||
assert_equal([false, [1]], e.to_a[0], bug)
|
||||
end;
|
||||
end
|
||||
|
||||
def test_with_object
|
||||
obj = [0, 1]
|
||||
ret = (1..10).each.with_object(obj) {|i, memo|
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#define RUBY_VERSION "2.0.0"
|
||||
#define RUBY_RELEASE_DATE "2013-12-02"
|
||||
#define RUBY_PATCHLEVEL 356
|
||||
#define RUBY_PATCHLEVEL 357
|
||||
|
||||
#define RUBY_RELEASE_YEAR 2013
|
||||
#define RUBY_RELEASE_MONTH 12
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue