[#37959] [Bug:trunk] I can modify literals — Yusuke ENDOH <mame@...>

遠藤です。

13 messages 2009/02/10

[#38005] Is URI.decode() broken? — MOROHASHI Kyosuke <moronatural@...>

もろはしです。いつもお世話になっております。

39 messages 2009/02/14
[#38006] Re: Is URI.decode() broken? — Nobuyoshi Nakada <nobu@...> 2009/02/14

なかだです。

[#38009] Re: Is URI.decode() broken? — "NARUSE, Yui" <naruse@...> 2009/02/14

成瀬です、

[#38016] Re: Is URI.decode() broken? — Fujioka <fuj@...> 2009/02/15

xibbarこと藤岡です。

[#38017] Re: Is URI.decode() broken? — "NARUSE, Yui" <naruse@...> 2009/02/15

成瀬です。

[#38040] Re: Is URI.decode() broken? — akira yamada / やまだあきら <akira@...> 2009/02/17

NARUSE, Yui さんは書きました:

[#38124] Re: Is URI.decode() broken? — "NARUSE, Yui" <naruse@...> 2009/03/03

成瀬です。

[#39214] Re: Is URI.decode() broken? — akira yamada / やまだあきら <akira@...> 2009/09/02

(2009年03月03日 22:45), NARUSE, Yui さんは書きました:

[#39218] Re: Is URI.decode() broken? — "NARUSE, Yui" <naruse@...> 2009/09/02

成瀬です。

[#39236] Re: Is URI.decode() broken? — Tanaka Akira <akr@...> 2009/09/05

In article <4A9E44DD.6050706@airemix.jp>,

[#39242] Re: Is URI.decode() broken? — KOSAKI Motohiro <kosaki.motohiro@...> 2009/09/07

小崎@思いつきを適当に書いてみるテスト

[#39246] Re: Is URI.decode() broken? — Tanaka Akira <akr@...> 2009/09/07

In article <20090907091830.2C7A.A69D9226@jp.fujitsu.com>,

[#38096] 多重代入やメソッド引数の展開でto_aが呼ばれます — nagachika <nagachika00@...>

nagachika と申します。

10 messages 2009/02/26

[#38098] ブロック引数と括弧・引数なしsuper — Shugo Maeda <shugo@...>

前田です。

12 messages 2009/02/27

[ruby-dev:37910] [Bug:1.9] lack consistency in hash iteration

From: Yusuke ENDOH <mame@...>
Date: 2009-02-04 17:51:16 UTC
List: ruby-dev #37910
遠藤です。

[ruby-core:21812] で調べていて気が付いたことですが、

$ ./ruby -e 'h = {0 => nil}; i = 1; h.each_key { h[i] = nil; i += 1 }'

は停止し、

$ ./ruby -e 'h = {0 => nil, 1 => nil}; i = 2; h.each_key { h[i] = nil; i += 1 }'

は無限ループになります。
直感的にはどちらも無限ループになると思いました。


特に反対がなければ、以下のパッチをコミットしようと思います。

Index: st.c
===================================================================
--- st.c	(revision 22051)
+++ st.c	(working copy)
@@ -653,6 +653,7 @@
 	do {
 	    end = ptr->fore == table->head;
 	    retval = (*func)(ptr->key, ptr->record, arg);
+	    end = end && (ptr->fore == table->head);
 	    switch (retval) {
 	      case ST_CHECK:	/* check if hash is modified during iteration */
 		i = ptr->hash % table->num_bins;
Index: test/ruby/test_hash.rb
===================================================================
--- test/ruby/test_hash.rb	(revision 22051)
+++ test/ruby/test_hash.rb	(working copy)
@@ -849,4 +849,30 @@
   def test_hash_hash
     assert_equal({0=>2,11=>1}.hash, {11=>1,0=>2}.hash)
   end
+
+  def test_iteration_order
+    h = {1=>nil,3=>nil,2=>nil,4=>nil}
+    assert_equal([1, 3, 2, 4], h.each_key.to_a)
+
+    h.each_key {|k| h[k + 10] = nil if h.size < 8 }
+    assert_equal([1, 3, 2, 4, 11, 13, 12, 14], h.each_key.to_a)
+
+    h = {0=>nil}
+    i = 1
+    h.each_key do |k|
+      break if h.size == 5
+      h[i] = nil
+      i += 1
+    end
+    assert_equal({0=>nil,1=>nil,2=>nil,3=>nil,4=>nil}, h)
+
+    h = {0=>nil,1=>nil}
+    i = 2
+    h.each_key do |k|
+      break if h.size == 5
+      h[i] = nil
+      i += 1
+    end
+    assert_equal({0=>nil,1=>nil,2=>nil,3=>nil,4=>nil}, h)
+  end
 end

-- 
Yusuke ENDOH <mame@tsg.ne.jp>

In This Thread

Prev Next