[macruby-changes] [791] MacRuby/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Thu Jan 15 04:52:31 PST 2009
Revision: 791
http://trac.macosforge.org/projects/ruby/changeset/791
Author: eloy.de.enige at gmail.com
Date: 2009-01-15 04:52:28 -0800 (Thu, 15 Jan 2009)
Log Message:
-----------
Fixed constant lookup for modules as well. See r790.
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-15 12:01:49 UTC (rev 790)
+++ MacRuby/trunk/test-macruby/test_objc.rb 2009-01-15 12:52:28 UTC (rev 791)
@@ -14,15 +14,33 @@
class TestClassConstantLookup < Test::Unit::TestCase
module Namespace
class PureRubyClass; end
+ module PureRubyModule; end
+ SINGLETON = (class << self; self; 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
+ it "should find pure Ruby classes in different namespaces if given the correct path" do
assert_nothing_raised(NameError) { Namespace::PureRubyClass }
end
+
+ it "should not find pure Ruby modules in different namespaces" do
+ assert_raise(NameError) { PureRubyModule }
+ end
+
+ it "should find pure Ruby modules in different namespaces if given the correct path" do
+ assert_nothing_raised(NameError) { Namespace::PureRubyModule }
+ end
+
+ it "should not find pure Ruby class singletons in different namespaces" do
+ assert_raise(NameError) { SINGLETON }
+ end
+
+ it "should find pure Ruby class singletons in different namespaces if given the correct path" do
+ assert_nothing_raised(NameError) { Namespace::SINGLETON }
+ end
end
class TestSubclass < Test::Unit::TestCase
Modified: MacRuby/trunk/variable.c
===================================================================
--- MacRuby/trunk/variable.c 2009-01-15 12:01:49 UTC (rev 790)
+++ MacRuby/trunk/variable.c 2009-01-15 12:52:28 UTC (rev 791)
@@ -2082,25 +2082,25 @@
}
#if WITH_OBJC
- /* Classes are typically pre-loaded by Kernel#framework and imported by
- * 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) && (RCLASS_VERSION(k) != (RCLASS_IS_OBJECT_SUBCLASS | RCLASS_IS_RUBY_CLASS)))
- return (VALUE)k;
+ /* Classes are typically pre-loaded by Kernel#framework and imported by
+ * 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/module or not.
+ */
+ Class k = (Class)objc_getClass(rb_id2name(id));
+ if (k != NULL && !RCLASS_RUBY(k))
+ return (VALUE)k;
}
#endif
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090115/d7acb86f/attachment.html>
More information about the macruby-changes
mailing list