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

ruby-changes:35475

From: nobu <ko1@a...>
Date: Fri, 12 Sep 2014 23:25:07 +0900 (JST)
Subject: [ruby-changes:35475] nobu:r47557 (trunk): ruby/ruby.h: freeze singleton class

nobu	2014-09-12 23:25:01 +0900 (Fri, 12 Sep 2014)

  New Revision: 47557

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

  Log:
    ruby/ruby.h: freeze singleton class
    
    * include/ruby/ruby.h (rb_obj_freeze_inline): propagate freezing
      to the singleton class if it is existing.

  Modified files:
    trunk/eval.c
    trunk/include/ruby/ruby.h
Index: include/ruby/ruby.h
===================================================================
--- include/ruby/ruby.h	(revision 47556)
+++ include/ruby/ruby.h	(revision 47557)
@@ -1105,7 +1105,19 @@ 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(x) FL_SET((x), FL_FREEZE)
+#define OBJ_FREEZE(x) rb_obj_freeze_inline((VALUE)x)
+
+static inline void
+rb_obj_freeze_inline(VALUE x)
+{
+    if (FL_ABLE(x)) {
+	VALUE klass = RBASIC_CLASS(x);
+	RBASIC(x)->flags |= FL_FREEZE;
+	if (FL_TEST(klass, (FL_SINGLETON|FL_FREEZE)) == FL_SINGLETON) {
+	    RBASIC(klass)->flags |= FL_FREEZE;
+	}
+    }
+}
 
 #if USE_RGENGC
 #define OBJ_PROMOTED_RAW(x)         ((RBASIC(x)->flags & (FL_PROMOTED0|FL_PROMOTED1)) == (FL_PROMOTED0|FL_PROMOTED1))
Index: eval.c
===================================================================
--- eval.c	(revision 47556)
+++ eval.c	(revision 47557)
@@ -409,10 +409,6 @@ rb_frozen_class_p(VALUE klass) https://github.com/ruby/ruby/blob/trunk/eval.c#L409
       noclass:
 	Check_Type(klass, T_CLASS);
     }
-    if (FL_TEST(klass, FL_SINGLETON)) {
-	VALUE obj = rb_ivar_get(klass, id__attached__);
-	if (OBJ_FROZEN(obj)) OBJ_FREEZE(klass);
-    }
     if (OBJ_FROZEN(klass)) {
 	const char *desc;
 

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

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