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

ruby-changes:2363

From: ko1@a...
Date: 9 Nov 2007 17:14:59 +0900
Subject: [ruby-changes:2363] matz - Ruby:r13854 (trunk): * variable.c (rb_cvar_set): cvar assignment obey same rule to cvar

matz	2007-11-09 17:14:42 +0900 (Fri, 09 Nov 2007)

  New Revision: 13854

  Modified files:
    trunk/ChangeLog
    trunk/variable.c

  Log:
    * variable.c (rb_cvar_set): cvar assignment obey same rule to cvar
      reference.  [ruby-dev:32192]

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/variable.c?r1=13854&r2=13853
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=13854&r2=13853

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 13853)
+++ ChangeLog	(revision 13854)
@@ -3,6 +3,9 @@
 	* io.c (rb_io_each_byte): should update rbuf_off and rbuf_len for
 	  each iteration.  [ruby-dev:31659][ruby-dev:32192]
 
+	* variable.c (rb_cvar_set): cvar assignment obey same rule to cvar
+	  reference.  [ruby-dev:32192]
+
 Fri Nov  9 15:52:00 2007  Nobuyoshi Nakada  <nobu@r...>
 
 	* encoding.c (enc_check_encoding, rb_set_primary_encoding): ENCODING
Index: variable.c
===================================================================
--- variable.c	(revision 13853)
+++ variable.c	(revision 13854)
@@ -1710,41 +1710,6 @@
     return c;
 }
 
-void
-rb_cvar_set(VALUE klass, ID id, VALUE val)
-{
-    VALUE tmp;
-    VALUE front = 0, target = 0;
-
-    tmp = klass;
-    while (tmp) {
-	if (RCLASS_IV_TBL(tmp) && st_lookup(RCLASS_IV_TBL(tmp),id,0)) {
-	    if (!front) front = tmp;
-	    target = tmp;
-	}
-	tmp = RCLASS_SUPER(tmp);
-    }
-    if (target) {
-	if (front && target != front) {
-	    ID did = id;
-
-	    if (RTEST(ruby_verbose)) {
-		rb_warning("class variable %s of %s is overtaken by %s",
-			   rb_id2name(id), rb_class2name(original_module(front)),
-			   rb_class2name(original_module(target)));
-	    }
-	    if (BUILTIN_TYPE(front) == T_CLASS) {
-		st_delete(RCLASS_IV_TBL(front),&did,0);
-	    }
-	}
-    }
-    else {
-	target = klass;
-    }
-
-    mod_av_set(target, id, val, Qfalse);
-}
-
 #define CVAR_LOOKUP(v,r) do {\
     if (RCLASS_IV_TBL(klass) && st_lookup(RCLASS_IV_TBL(klass),id,(v))) {\
 	r;\
@@ -1772,6 +1737,33 @@
     }\
 } while(0)
 
+void
+rb_cvar_set(VALUE klass, ID id, VALUE val)
+{
+    VALUE tmp, front = 0, target = 0;
+
+    tmp = klass;
+    CVAR_LOOKUP(0, {if (!front) front = klass; target = klass;});
+    if (target) {
+	if (front && target != front) {
+	    ID did = id;
+
+	    if (RTEST(ruby_verbose)) {
+		rb_warning("class variable %s of %s is overtaken by %s",
+			   rb_id2name(id), rb_class2name(original_module(front)),
+			   rb_class2name(original_module(target)));
+	    }
+	    if (BUILTIN_TYPE(front) == T_CLASS) {
+		st_delete(RCLASS_IV_TBL(front),&did,0);
+	    }
+	}
+    }
+    else {
+	target = tmp;
+    }
+    mod_av_set(target, id, val, Qfalse);
+}
+
 VALUE
 rb_cvar_get(VALUE klass, ID id)
 {

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

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