[前][次][番号順一覧][スレッド一覧]

ruby-changes:56195

From: Nobuyoshi <ko1@a...>
Date: Sun, 23 Jun 2019 00:37:08 +0900 (JST)
Subject: [ruby-changes:56195] Nobuyoshi Nakada: f3c81b4e90 (trunk): Frozen objects in WeakMap

https://git.ruby-lang.org/ruby.git/commit/?id=f3c81b4e90

From f3c81b4e90ec492382e299573f2c3ac272adbb5f Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Sun, 23 Jun 2019 00:31:16 +0900
Subject: Frozen objects in WeakMap

* gc.c (wmap_aset): bypass check for frozen and allow frozen
  object in WeakMap.  [Bug #13498]

diff --git a/gc.c b/gc.c
index 7b82a88..a1984f8 100644
--- a/gc.c
+++ b/gc.c
@@ -2937,13 +2937,20 @@ should_be_callable(VALUE block) https://github.com/ruby/ruby/blob/trunk/gc.c#L2937
 		 rb_obj_class(block));
     }
 }
+
 static void
-should_be_finalizable(VALUE obj)
+should_be_finalizable_internal(VALUE obj)
 {
     if (!FL_ABLE(obj)) {
 	rb_raise(rb_eArgError, "cannot define finalizer for %s",
 		 rb_obj_classname(obj));
     }
+}
+
+static void
+should_be_finalizable(VALUE obj)
+{
+    should_be_finalizable_internal(obj);
     rb_check_frozen(obj);
 }
 
@@ -10399,8 +10406,8 @@ wmap_aset(VALUE self, VALUE wmap, VALUE orig) https://github.com/ruby/ruby/blob/trunk/gc.c#L10406
     struct weakmap *w;
 
     TypedData_Get_Struct(self, struct weakmap, &weakmap_type, w);
-    should_be_finalizable(orig);
-    should_be_finalizable(wmap);
+    should_be_finalizable_internal(orig);
+    should_be_finalizable_internal(wmap);
     define_final0(orig, w->final);
     define_final0(wmap, w->final);
     st_update(w->obj2wmap, (st_data_t)orig, wmap_aset_update, wmap);
diff --git a/test/ruby/test_weakmap.rb b/test/ruby/test_weakmap.rb
index fb57903..8eb32b5 100644
--- a/test/ruby/test_weakmap.rb
+++ b/test/ruby/test_weakmap.rb
@@ -141,4 +141,10 @@ class TestWeakMap < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_weakmap.rb#L141
     assert_equal(2, @wm.__send__(m))
   end
   alias test_length test_size
+
+  def test_frozen_object
+    o = Object.new.freeze
+    assert_nothing_raised(FrozenError) {@wm[o] = 'foo'}
+    assert_nothing_raised(FrozenError) {@wm['foo'] = o}
+  end
 end
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]