[macruby-changes] [1628] MacRuby/branches/experimental
source_changes at macosforge.org
source_changes at macosforge.org
Thu May 28 20:02:01 PDT 2009
Revision: 1628
http://trac.macosforge.org/projects/ruby/changeset/1628
Author: lsansonetti at apple.com
Date: 2009-05-28 20:02:01 -0700 (Thu, 28 May 2009)
Log Message:
-----------
now throwing pure objc exceptions from ruby, this way they can be catched by objc
Modified Paths:
--------------
MacRuby/branches/experimental/objc.h
MacRuby/branches/experimental/objc.m
MacRuby/branches/experimental/spec/macruby/spec_helper.rb
MacRuby/branches/experimental/vm.cpp
Added Paths:
-----------
MacRuby/branches/experimental/spec/macruby/core/exception_spec.rb
MacRuby/branches/experimental/spec/macruby/fixtures/exception.m
Modified: MacRuby/branches/experimental/objc.h
===================================================================
--- MacRuby/branches/experimental/objc.h 2009-05-28 23:15:53 UTC (rev 1627)
+++ MacRuby/branches/experimental/objc.h 2009-05-29 03:02:01 UTC (rev 1628)
@@ -88,6 +88,8 @@
bool rb_objc_symbolize_address(void *addr, void **start, char *name,
size_t name_len);
+id rb_objc_create_exception(VALUE exc);
+
static inline int
SubtypeUntil(const char *type, char end)
{
Modified: MacRuby/branches/experimental/objc.m
===================================================================
--- MacRuby/branches/experimental/objc.m 2009-05-28 23:15:53 UTC (rev 1627)
+++ MacRuby/branches/experimental/objc.m 2009-05-29 03:02:01 UTC (rev 1628)
@@ -606,6 +606,16 @@
return ret;
}
+id
+rb_objc_create_exception(VALUE exc)
+{
+ NSString *name = [NSString stringWithUTF8String:rb_obj_classname(exc)];
+ NSString *reason = [(id)exc performSelector:@selector(message)];
+ NSDictionary *dict = [NSDictionary dictionaryWithObject:(id)exc
+ forKey:@"RubyException"];
+ return [NSException exceptionWithName:name reason:reason userInfo:dict];
+}
+
void *placeholder_String = NULL;
void *placeholder_Dictionary = NULL;
void *placeholder_Array = NULL;
Added: MacRuby/branches/experimental/spec/macruby/core/exception_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/macruby/core/exception_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/macruby/core/exception_spec.rb 2009-05-29 03:02:01 UTC (rev 1628)
@@ -0,0 +1,20 @@
+require File.dirname(__FILE__) + "/../spec_helper"
+FixtureCompiler.require! "exception"
+
+=begin # TODO
+describe "An Objective-C exception" do
+ it "can be catched from Ruby" do
+ lambda { TestException.raiseObjCException }.should raise_error
+ end
+end
+=end
+
+describe "A Ruby exception" do
+ it "can be catched from Objective-C" do
+ o = Object.new
+ def o.raiseRubyException
+ raise 'foo'
+ end
+ TestException.catchRubyException(o).should == 1
+ end
+end
Added: MacRuby/branches/experimental/spec/macruby/fixtures/exception.m
===================================================================
--- MacRuby/branches/experimental/spec/macruby/fixtures/exception.m (rev 0)
+++ MacRuby/branches/experimental/spec/macruby/fixtures/exception.m 2009-05-29 03:02:01 UTC (rev 1628)
@@ -0,0 +1,26 @@
+#import <Foundation/Foundation.h>
+
+ at interface TestException : NSObject
+ at end
+
+ at implementation TestException
+
++ (void)raiseObjCException
+{
+ [NSException raise:@"SinkingShipException" format:@"the ship is sinking!"];
+}
+
++ (BOOL)catchRubyException:(id)obj
+{
+ @try {
+ [obj performSelector:@selector(raiseRubyException)];
+ }
+ @catch (id e) {
+ return YES;
+ }
+ return NO;
+}
+
+ at end
+
+void Init_exception(void) {}
Modified: MacRuby/branches/experimental/spec/macruby/spec_helper.rb
===================================================================
--- MacRuby/branches/experimental/spec/macruby/spec_helper.rb 2009-05-28 23:15:53 UTC (rev 1627)
+++ MacRuby/branches/experimental/spec/macruby/spec_helper.rb 2009-05-29 03:02:01 UTC (rev 1628)
@@ -49,7 +49,9 @@
def load!
require bundle[0..-8]
- load_bridge_support_file bridge_support
+ if File.exist? bridge_support
+ load_bridge_support_file bridge_support
+ end
end
end
Modified: MacRuby/branches/experimental/vm.cpp
===================================================================
--- MacRuby/branches/experimental/vm.cpp 2009-05-28 23:15:53 UTC (rev 1627)
+++ MacRuby/branches/experimental/vm.cpp 2009-05-29 03:02:01 UTC (rev 1628)
@@ -37,6 +37,8 @@
#include "compiler.h"
#include "objc.h"
+#include <objc/objc-exception.h>
+
#if ROXOR_COMPILER_DEBUG
# include <mach/mach.h>
# include <mach/mach_time.h>
@@ -3287,8 +3289,13 @@
static inline void
__vm_raise(void)
{
+#if 1
+ id exc = rb_objc_create_exception(GET_VM()->current_exception());
+ objc_exception_throw(exc);
+#else
void *exc = __cxa_allocate_exception(0);
__cxa_throw(exc, NULL, NULL);
+#endif
}
extern "C"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090528/9fcba92f/attachment.html>
More information about the macruby-changes
mailing list