[macruby-changes] [4332] MacRuby/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Thu Jul 8 15:56:55 PDT 2010
Revision: 4332
http://trac.macosforge.org/projects/ruby/changeset/4332
Author: lsansonetti at apple.com
Date: 2010-07-08 15:56:52 -0700 (Thu, 08 Jul 2010)
Log Message:
-----------
don't crash when trying to deal with constants whose symbols cannot be located or constants tagged as magic cookies
Modified Paths:
--------------
MacRuby/trunk/bridgesupport.cpp
MacRuby/trunk/spec/macruby/core/constant_spec.rb
MacRuby/trunk/spec/macruby/fixtures/constant.bridgesupport
MacRuby/trunk/spec/macruby/fixtures/constant.m
MacRuby/trunk/variable.c
Modified: MacRuby/trunk/bridgesupport.cpp
===================================================================
--- MacRuby/trunk/bridgesupport.cpp 2010-07-08 21:20:24 UTC (rev 4331)
+++ MacRuby/trunk/bridgesupport.cpp 2010-07-08 22:56:52 UTC (rev 4332)
@@ -77,10 +77,19 @@
void *sym = dlsym(RTLD_DEFAULT, bs_const->name);
if (sym == NULL) {
- rb_bug("cannot locate symbol for BridgeSupport constant `%s'",
- bs_const->name);
+ // The symbol can't be located, it's probably because the current
+ // program links against a different version of the framework.
+ rb_raise(rb_eRuntimeError, "can't locate symbol for constant %s",
+ rb_id2name(id));
}
+ if (bs_const->magic_cookie) {
+ // Constant is a magic cookie. We don't support these yet.
+ rb_raise(rb_eRuntimeError,
+ "magic-cookie constant %s is not supported yet",
+ rb_id2name(id));
+ }
+
void *convertor = GET_CORE()->gen_to_rval_convertor(bs_const->type);
v = ((VALUE (*)(void *))convertor)(sym);
Modified: MacRuby/trunk/spec/macruby/core/constant_spec.rb
===================================================================
--- MacRuby/trunk/spec/macruby/core/constant_spec.rb 2010-07-08 21:20:24 UTC (rev 4331)
+++ MacRuby/trunk/spec/macruby/core/constant_spec.rb 2010-07-08 22:56:52 UTC (rev 4332)
@@ -80,6 +80,14 @@
ConstantNSRect.class.should == NSRect
ConstantNSRect.should == NSRect.new(NSPoint.new(1, 2), NSSize.new(3, 4))
end
+
+ it "whose symbol cannot be located at Runtime will raise a RuntimeError" do
+ lambda { ConstantWhichDoesNotExist }.should raise_error(RuntimeError)
+ end
+
+ it "tagged as a magic cookie will raise a RuntimeError (not yet supported)" do
+ lambda { ConstantMagicCookie }.should raise_error(RuntimeError)
+ end
end
describe "NSNotFound" do
Modified: MacRuby/trunk/spec/macruby/fixtures/constant.bridgesupport
===================================================================
--- MacRuby/trunk/spec/macruby/fixtures/constant.bridgesupport 2010-07-08 21:20:24 UTC (rev 4331)
+++ MacRuby/trunk/spec/macruby/fixtures/constant.bridgesupport 2010-07-08 22:56:52 UTC (rev 4332)
@@ -21,4 +21,6 @@
<constant name='ConstantUnsignedLongLong' type='Q'/>
<constant name='ConstantUnsignedShort' type='S'/>
<constant name='ConstantYES' type='B'/>
+ <constant name='ConstantWhichDoesNotExist' type='@'/>
+ <constant name='ConstantMagicCookie' type='@' magic_cookie='true'/>
</signatures>
Modified: MacRuby/trunk/spec/macruby/fixtures/constant.m
===================================================================
--- MacRuby/trunk/spec/macruby/fixtures/constant.m 2010-07-08 21:20:24 UTC (rev 4331)
+++ MacRuby/trunk/spec/macruby/fixtures/constant.m 2010-07-08 22:56:52 UTC (rev 4332)
@@ -20,6 +20,7 @@
NSPoint ConstantNSPoint;
NSSize ConstantNSSize;
NSRect ConstantNSRect;
+id ConstantMagicCookie;
void
Init_constant(void)
@@ -44,4 +45,5 @@
ConstantNSPoint = NSMakePoint(1, 2);
ConstantNSSize = NSMakeSize(3, 4);
ConstantNSRect = NSMakeRect(1, 2, 3, 4);
+ ConstantMagicCookie = (id)0x1234;
}
Modified: MacRuby/trunk/variable.c
===================================================================
--- MacRuby/trunk/variable.c 2010-07-08 21:20:24 UTC (rev 4331)
+++ MacRuby/trunk/variable.c 2010-07-08 22:56:52 UTC (rev 4332)
@@ -1499,8 +1499,7 @@
rb_warn("toplevel constant %s referenced by %s::%s",
rb_id2name(id), rb_class2name(klass), rb_id2name(id));
}
- value = rb_vm_resolve_const_value(value, klass, id);
- return value;
+ return rb_vm_resolve_const_value(value, klass, id);
}
if (!recurse && klass != rb_cObject) {
break;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100708/b89d4441/attachment.html>
More information about the macruby-changes
mailing list