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

ruby-changes:35492

From: nobu <ko1@a...>
Date: Sat, 13 Sep 2014 22:03:58 +0900 (JST)
Subject: [ruby-changes:35492] nobu:r47574 (trunk): class.c: freeze meta class only

nobu	2014-09-13 22:03:46 +0900 (Sat, 13 Sep 2014)

  New Revision: 47574

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47574

  Log:
    class.c: freeze meta class only
    
    * class.c (singleton_class_of): should not propagete freezing to
      meta meta class.

  Modified files:
    trunk/class.c
    trunk/include/ruby/ruby.h
    trunk/test/ruby/test_class.rb
Index: include/ruby/ruby.h
===================================================================
--- include/ruby/ruby.h	(revision 47573)
+++ include/ruby/ruby.h	(revision 47574)
@@ -1105,6 +1105,7 @@ struct RStruct { https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L1105
     RBASIC(x)->flags |= RBASIC(s)->flags & FL_TAINT : 0)
 
 #define OBJ_FROZEN(x) (FL_ABLE(x) ? !!(RBASIC(x)->flags&FL_FREEZE) : 1)
+#define OBJ_FREEZE_RAW(x) (RBASIC(x)->flags |= FL_FREEZE)
 #define OBJ_FREEZE(x) rb_obj_freeze_inline((VALUE)x)
 
 static inline void
@@ -1112,9 +1113,9 @@ rb_obj_freeze_inline(VALUE x) https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L1113
 {
     if (FL_ABLE(x)) {
 	VALUE klass = RBASIC_CLASS(x);
-	RBASIC(x)->flags |= FL_FREEZE;
+	OBJ_FREEZE_RAW(x);
 	if (FL_TEST(klass, (FL_SINGLETON|FL_FREEZE)) == FL_SINGLETON) {
-	    RBASIC(klass)->flags |= FL_FREEZE;
+	    OBJ_FREEZE_RAW(klass);
 	}
     }
 }
Index: class.c
===================================================================
--- class.c	(revision 47573)
+++ class.c	(revision 47574)
@@ -1575,7 +1575,7 @@ singleton_class_of(VALUE obj) https://github.com/ruby/ruby/blob/trunk/class.c#L1575
     else {
 	FL_UNSET(klass, FL_TAINT);
     }
-    if (OBJ_FROZEN(obj)) OBJ_FREEZE(klass);
+    if (OBJ_FROZEN(obj)) OBJ_FREEZE_RAW(klass);
 
     return klass;
 }
Index: test/ruby/test_class.rb
===================================================================
--- test/ruby/test_class.rb	(revision 47573)
+++ test/ruby/test_class.rb	(revision 47574)
@@ -392,6 +392,9 @@ class TestClass < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_class.rb#L392
     assert_raise_with_message(RuntimeError, /frozen object/) {
       c.class_eval {def f; end}
     }
+  end
+
+  def test_singleton_class_message
     c = Class.new.freeze
     assert_raise_with_message(RuntimeError, /frozen Class/) {
       def c.f; end

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

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