aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-12-10 05:02:17 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-12-10 05:02:17 +0000
commit9bd802f5567d78551668c51f091deb05e43b97ea (patch)
tree15902cc30c1d939bb1585ed084b5c1ceb7c87a5c
parent332decb490d56025f7b24088aa7f5f1a6fcb03e5 (diff)
downloadruby-9bd802f5567d78551668c51f091deb05e43b97ea.tar.gz
gc.c: fix WeakMap#inspect
* gc.c (wmap_inspect_i): fix key/value order. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44107 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--gc.c4
-rw-r--r--test/ruby/test_weakmap.rb8
2 files changed, 10 insertions, 2 deletions
diff --git a/gc.c b/gc.c
index ad67023321..157dfce495 100644
--- a/gc.c
+++ b/gc.c
@@ -6346,8 +6346,8 @@ wmap_inspect(VALUE self)
TypedData_Get_Struct(self, struct weakmap, &weakmap_type, w);
str = rb_sprintf("-<%"PRIsVALUE":%p", c, (void *)self);
- if (w->obj2wmap) {
- st_foreach(w->obj2wmap, wmap_inspect_i, str);
+ if (w->wmap2obj) {
+ st_foreach(w->wmap2obj, wmap_inspect_i, str);
}
RSTRING_PTR(str)[0] = '#';
rb_str_cat2(str, ">");
diff --git a/test/ruby/test_weakmap.rb b/test/ruby/test_weakmap.rb
index c0d1747d2a..0f147a6b0f 100644
--- a/test/ruby/test_weakmap.rb
+++ b/test/ruby/test_weakmap.rb
@@ -28,6 +28,14 @@ class TestWeakMap < Test::Unit::TestCase
alias test_member? test_include?
alias test_key? test_include?
+ def test_inspect
+ x = Object.new
+ k = BasicObject.new
+ @wm[k] = x
+ assert_match(/\A\#<#{@wm.class.name}:[^:]+:\s\#<BasicObject:[^:]*>\s=>\s\#<Object:[^:]*>>\z/,
+ @wm.inspect)
+ end
+
def test_each
m = __callee__[/test_(.*)/, 1]
x1 = Object.new