[macruby-changes] [2498] MacRuby/trunk/vm.cpp

source_changes at macosforge.org source_changes at macosforge.org
Sat Sep 5 22:19:06 PDT 2009


Revision: 2498
          http://trac.macosforge.org/projects/ruby/changeset/2498
Author:   lsansonetti at apple.com
Date:     2009-09-05 22:19:06 -0700 (Sat, 05 Sep 2009)
Log Message:
-----------
raise TypeError exceptions in case we try to get a constant from a non-module outer and when we re-open a non-module constant as a module

Modified Paths:
--------------
    MacRuby/trunk/vm.cpp

Modified: MacRuby/trunk/vm.cpp
===================================================================
--- MacRuby/trunk/vm.cpp	2009-09-06 05:17:45 UTC (rev 2497)
+++ MacRuby/trunk/vm.cpp	2009-09-06 05:19:06 UTC (rev 2498)
@@ -836,6 +836,12 @@
 	    outer = (VALUE)k;
 	}
     }
+#if ROXOR_VM_DEBUG
+    printf("define const %s::%s to %p\n", 
+	    class_getName((Class)outer), 
+	    rb_id2name(id),
+	    (void *)obj);
+#endif
     rb_const_set(outer, id, obj);
     GET_CORE()->const_defined(id);
 }
@@ -889,6 +895,20 @@
     return defined ? rb_const_defined(outer, path) : rb_const_get(outer, path);
 }
 
+static inline void
+check_if_module(VALUE mod)
+{
+    switch (TYPE(mod)) {
+	case T_CLASS:
+	case T_MODULE:
+	    break;
+
+	default:
+	    rb_raise(rb_eTypeError, "%s is not a class/module",
+		    RSTRING_PTR(rb_inspect(mod)));
+    }
+}
+
 extern "C"
 VALUE
 rb_vm_get_const(VALUE outer, unsigned char lexical_lookup,
@@ -908,6 +928,7 @@
 	val = cache->val;
     }
     else {
+	check_if_module(outer);
 	val = rb_vm_const_lookup(outer, path, lexical_lookup, false);
 	cache->outer = outer;
 	cache->val = val;
@@ -938,20 +959,6 @@
     return o == NULL ? Qundef : (VALUE)o->klass;
 }
 
-static inline void
-check_if_module(VALUE mod)
-{
-    switch (TYPE(mod)) {
-	case T_CLASS:
-	case T_MODULE:
-	    break;
-
-	default:
-	    rb_raise(rb_eTypeError, "%s is not a class/module",
-		    RSTRING_PTR(rb_inspect(mod)));
-    }
-}
-
 extern "C"
 VALUE
 rb_vm_define_class(ID path, VALUE outer, VALUE super, int flags,
@@ -970,8 +977,8 @@
     VALUE klass;
     if (rb_const_defined_at(outer, path)) {
 	klass = rb_const_get_at(outer, path);
+	check_if_module(klass);
 	if (!(flags & DEFINE_MODULE) && super != 0) {
-	    check_if_module(klass);
 	    if (RCLASS_SUPER(klass) != super) {
 		rb_raise(rb_eTypeError, "superclass mismatch for class %s",
 			rb_class2name(klass));
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090905/1466aee2/attachment.html>


More information about the macruby-changes mailing list