[macruby-changes] [790] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Thu Jan 15 04:01:51 PST 2009


Revision: 790
          http://trac.macosforge.org/projects/ruby/changeset/790
Author:   eloy.de.enige at gmail.com
Date:     2009-01-15 04:01:49 -0800 (Thu, 15 Jan 2009)
Log Message:
-----------
rb_const_get_0 should not return pure Ruby classes from any namespace. Closes #182.

Modified Paths:
--------------
    MacRuby/trunk/test-macruby/test_objc.rb
    MacRuby/trunk/variable.c

Modified: MacRuby/trunk/test-macruby/test_objc.rb
===================================================================
--- MacRuby/trunk/test-macruby/test_objc.rb	2009-01-13 15:54:09 UTC (rev 789)
+++ MacRuby/trunk/test-macruby/test_objc.rb	2009-01-15 12:01:49 UTC (rev 790)
@@ -1,5 +1,30 @@
+#!/usr/bin/env macruby
+
 require 'test/unit'
 
+require 'test/unit'
+class Test::Unit::TestCase
+  class << self
+    def it(name, &block)
+      define_method("test_#{name}", &block)
+    end
+  end
+end
+
+class TestClassConstantLookup < Test::Unit::TestCase
+  module Namespace
+    class PureRubyClass; end
+  end
+  
+  it "should not find pure Ruby classes in different namespaces" do
+    assert_raise(NameError) { PureRubyClass }
+  end
+  
+  it "should find pure Ruby class in different namespaces if given the correct path" do
+    assert_nothing_raised(NameError) { Namespace::PureRubyClass }
+  end
+end
+
 class TestSubclass < Test::Unit::TestCase
 
   def setup

Modified: MacRuby/trunk/variable.c
===================================================================
--- MacRuby/trunk/variable.c	2009-01-13 15:54:09 UTC (rev 789)
+++ MacRuby/trunk/variable.c	2009-01-15 12:01:49 UTC (rev 790)
@@ -2086,10 +2086,20 @@
      * rb_objc_resolve_const_value(), but it is still useful to keep the
      * dynamic import facility, because someone in the Objective-C world may
      * dynamically define classes at runtime (like ScriptingBridge.framework).
+     *
+     * Note that objc_getClass does _not_ honor namespaces. Consider:
+     *
+     *  module Namespace
+     *    class RubyClass; end
+     *  end
+     *
+     * In this case objc_getClass will happily return the Namespace::RubyClass
+     * object, which is ok but _not_ when trying to find a Ruby class. So we
+     * test whether or not the found class is a pure Ruby class or not.
      */
     {
 	Class k = (Class)objc_getClass(rb_id2name(id));
-	if (k != NULL)
+	if ((k != NULL) && (RCLASS_VERSION(k) != (RCLASS_IS_OBJECT_SUBCLASS | RCLASS_IS_RUBY_CLASS)))
 	    return (VALUE)k;
     }
 #endif
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090115/2cc2d43f/attachment.html>


More information about the macruby-changes mailing list