mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
merge revision(s) 39722,43929: [Backport #9178]
* enumerator.c (enumerator_with_index): try to convert given offset to integer. fix bug introduced in r39594. * 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_1_9_3@44745 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f984d0782b
commit
0678e02501
6 changed files with 42 additions and 6 deletions
11
ChangeLog
11
ChangeLog
|
@ -1,3 +1,14 @@
|
||||||
|
Wed Jan 29 14:26:10 2014 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]
|
||||||
|
|
||||||
|
Wed Jan 29 14:26:10 2014 NARUSE, Yui <naruse@ruby-lang.org>
|
||||||
|
|
||||||
|
* enumerator.c (enumerator_with_index): try to convert given offset to
|
||||||
|
integer. fix bug introduced in r39594.
|
||||||
|
|
||||||
Wed Jan 29 14:20:11 2014 Eric Hodel <drbrain@segment7.net>
|
Wed Jan 29 14:20:11 2014 Eric Hodel <drbrain@segment7.net>
|
||||||
|
|
||||||
* enumerator.c (enumerator_with_index): Restore handling of a nil memo
|
* enumerator.c (enumerator_with_index): Restore handling of a nil memo
|
||||||
|
|
|
@ -619,7 +619,7 @@ encoding.$(OBJEXT): {$(VPATH)}encoding.c $(RUBY_H_INCLUDES) \
|
||||||
{$(VPATH)}internal.h
|
{$(VPATH)}internal.h
|
||||||
enum.$(OBJEXT): {$(VPATH)}enum.c $(RUBY_H_INCLUDES) {$(VPATH)}node.h \
|
enum.$(OBJEXT): {$(VPATH)}enum.c $(RUBY_H_INCLUDES) {$(VPATH)}node.h \
|
||||||
{$(VPATH)}util.h $(ID_H_INCLUDES)
|
{$(VPATH)}util.h $(ID_H_INCLUDES)
|
||||||
enumerator.$(OBJEXT): {$(VPATH)}enumerator.c $(RUBY_H_INCLUDES)
|
enumerator.$(OBJEXT): {$(VPATH)}enumerator.c $(RUBY_H_INCLUDES) {$(VPATH)}node.h
|
||||||
error.$(OBJEXT): {$(VPATH)}error.c {$(VPATH)}known_errors.inc \
|
error.$(OBJEXT): {$(VPATH)}error.c {$(VPATH)}known_errors.inc \
|
||||||
$(RUBY_H_INCLUDES) $(VM_CORE_H_INCLUDES) $(ENCODING_H_INCLUDES) \
|
$(RUBY_H_INCLUDES) $(VM_CORE_H_INCLUDES) $(ENCODING_H_INCLUDES) \
|
||||||
{$(VPATH)}debug.h \
|
{$(VPATH)}debug.h \
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
************************************************/
|
************************************************/
|
||||||
|
|
||||||
#include "ruby/ruby.h"
|
#include "ruby/ruby.h"
|
||||||
|
#include "node.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Document-class: Enumerator
|
* Document-class: Enumerator
|
||||||
|
@ -368,9 +369,9 @@ enumerator_each(VALUE obj)
|
||||||
static VALUE
|
static VALUE
|
||||||
enumerator_with_index_i(VALUE val, VALUE m, int argc, VALUE *argv)
|
enumerator_with_index_i(VALUE val, VALUE m, int argc, VALUE *argv)
|
||||||
{
|
{
|
||||||
VALUE *memo = (VALUE *)m;
|
NODE *memo = (NODE *)m;
|
||||||
VALUE idx = *memo;
|
VALUE idx = memo->u1.value;
|
||||||
*memo = rb_int_succ(idx);
|
memo->u1.value = rb_int_succ(idx);
|
||||||
|
|
||||||
if (argc <= 1)
|
if (argc <= 1)
|
||||||
return rb_yield_values(2, val, idx);
|
return rb_yield_values(2, val, idx);
|
||||||
|
@ -401,7 +402,7 @@ enumerator_with_index(int argc, VALUE *argv, VALUE obj)
|
||||||
memo = INT2FIX(0);
|
memo = INT2FIX(0);
|
||||||
else
|
else
|
||||||
memo = rb_to_int(memo);
|
memo = rb_to_int(memo);
|
||||||
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
1
node.h
1
node.h
|
@ -447,6 +447,7 @@ typedef struct RNode {
|
||||||
#define NEW_ATTRASGN(r,m,a) NEW_NODE(NODE_ATTRASGN,r,m,a)
|
#define NEW_ATTRASGN(r,m,a) NEW_NODE(NODE_ATTRASGN,r,m,a)
|
||||||
#define NEW_PRELUDE(p,b) NEW_NODE(NODE_PRELUDE,p,b,0)
|
#define NEW_PRELUDE(p,b) NEW_NODE(NODE_PRELUDE,p,b,0)
|
||||||
#define NEW_OPTBLOCK(a) NEW_NODE(NODE_OPTBLOCK,a,0,0)
|
#define NEW_OPTBLOCK(a) NEW_NODE(NODE_OPTBLOCK,a,0,0)
|
||||||
|
#define NEW_MEMO(a,b,c) NEW_NODE(NODE_MEMO,a,b,c)
|
||||||
|
|
||||||
#if defined __GNUC__ && __GNUC__ >= 4
|
#if defined __GNUC__ && __GNUC__ >= 4
|
||||||
#pragma GCC visibility push(default)
|
#pragma GCC visibility push(default)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
|
require_relative "envutil"
|
||||||
|
|
||||||
class TestEnumerator < Test::Unit::TestCase
|
class TestEnumerator < Test::Unit::TestCase
|
||||||
def setup
|
def setup
|
||||||
|
@ -105,6 +106,28 @@ 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)
|
assert_equal([[1,s],[2,s+1],[3,s+2]], @obj.to_enum(:foo, 1, 2, 3).with_index(s).to_a, bug8010)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_with_index_nonnum_offset
|
||||||
|
bug8010 = '[ruby-dev:47131] [Bug #8010]'
|
||||||
|
s = Object.new
|
||||||
|
def s.to_int; 1 end
|
||||||
|
assert_equal([[1,1],[2,2],[3,3]], @obj.to_enum(:foo, 1, 2, 3).with_index(s).to_a, bug8010)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_with_index_string_offset
|
||||||
|
bug8010 = '[ruby-dev:47131] [Bug #8010]'
|
||||||
|
assert_raise(TypeError, bug8010){ @obj.to_enum(:foo, 1, 2, 3).with_index('1').to_a }
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_with_index_dangling_memo
|
||||||
|
bug9178 = '[ruby-core:58692] [Bug #9178]'
|
||||||
|
assert_in_out_err([], <<-"end;", ["Enumerator", "[false, [1]]"], [], bug9178)
|
||||||
|
bug = "#{bug9178}"
|
||||||
|
e = [1].to_enum(:chunk).with_index {|c,i| i == 5}
|
||||||
|
puts e.class
|
||||||
|
p e.to_a[0]
|
||||||
|
end;
|
||||||
|
end
|
||||||
|
|
||||||
def test_with_object
|
def test_with_object
|
||||||
obj = [0, 1]
|
obj = [0, 1]
|
||||||
ret = (1..10).each.with_object(obj) {|i, memo|
|
ret = (1..10).each.with_object(obj) {|i, memo|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#define RUBY_VERSION "1.9.3"
|
#define RUBY_VERSION "1.9.3"
|
||||||
#define RUBY_PATCHLEVEL 499
|
#define RUBY_PATCHLEVEL 500
|
||||||
|
|
||||||
#define RUBY_RELEASE_DATE "2014-01-29"
|
#define RUBY_RELEASE_DATE "2014-01-29"
|
||||||
#define RUBY_RELEASE_YEAR 2014
|
#define RUBY_RELEASE_YEAR 2014
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue