dumping ground for random patches and texts
 help / color / mirror / Atom feed
* [PATCH] resolve class name earlier and more consistently
@ 2016-01-12  2:14 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2016-01-12  2:14 UTC (permalink / raw)
  To: spew

* class.c (Init_class_hierarchy): resolve name for rb_cObject ASAP
* object.c (rb_mod_const_set): move name resolution to rb_const_set
* variable.c (rb_const_set): do class resolution here

[ruby-core:72807] [Bug #11977]
---
 class.c    | 4 ++++
 object.c   | 7 -------
 variable.c | 7 +++++++
 3 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/class.c b/class.c
index 5c72a4b..b4eaabc 100644
--- a/class.c
+++ b/class.c
@@ -547,6 +547,10 @@ Init_class_hierarchy(void)
 {
     rb_cBasicObject = boot_defclass("BasicObject", 0);
     rb_cObject = boot_defclass("Object", rb_cBasicObject);
+
+    /* resolve class name ASAP for order-independence */
+    rb_class_name(rb_cObject);
+
     rb_cModule = boot_defclass("Module", rb_cObject);
     rb_cClass =  boot_defclass("Class",  rb_cModule);
 
diff --git a/object.c b/object.c
index 53354e9..2497043 100644
--- a/object.c
+++ b/object.c
@@ -2178,13 +2178,6 @@ rb_mod_const_set(VALUE mod, VALUE name, VALUE value)
     if (!id) id = rb_intern_str(name);
     rb_const_set(mod, id, value);
 
-    /*
-     * Resolve and cache class name immediately to resolve ambiguity
-     * and avoid order-dependency on const_tbl
-     */
-    if (RB_TYPE_P(value, T_MODULE) || RB_TYPE_P(value, T_CLASS)) {
-	rb_class_name(value);
-    }
     return value;
 }
 
diff --git a/variable.c b/variable.c
index b033461..f0a4c1c 100644
--- a/variable.c
+++ b/variable.c
@@ -2569,6 +2569,13 @@ rb_const_set(VALUE klass, ID id, VALUE val)
 	args.value = val;
 	const_tbl_update(&args);
     }
+    /*
+     * Resolve and cache class name immediately to resolve ambiguity
+     * and avoid order-dependency on const_tbl
+     */
+    if (rb_cObject && (RB_TYPE_P(val, T_MODULE) || RB_TYPE_P(val, T_CLASS))) {
+	rb_class_name(val);
+    }
 }
 
 static void
-- 
EW


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2016-01-12  2:14 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-01-12  2:14 [PATCH] resolve class name earlier and more consistently Eric Wong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).