Revision
4190
Author
lsansonetti@apple.com
Date
2010-06-01 20:54:58 -0700 (Tue, 01 Jun 2010)

Log Message

finally re-commit r4185, apparently the problem is somewhere else

Modified Paths

Diff

Modified: MacRuby/trunk/dispatcher.cpp (4189 => 4190)


--- MacRuby/trunk/dispatcher.cpp	2010-06-02 03:43:36 UTC (rev 4189)
+++ MacRuby/trunk/dispatcher.cpp	2010-06-02 03:54:58 UTC (rev 4190)
@@ -444,15 +444,18 @@
 	return (*stub)(imp, rcv, sel, argc, argv);
     }
     @catch (id exc) {
-	VALUE rbexc = rb_oc2rb_exception(exc);
+	bool created = false;
+	VALUE rbexc = rb_oc2rb_exception(exc, &created);
 #if __LP64__
 	if (rb_vm_current_exception() == Qnil) {
-	    rb_vm_set_current_exception(rbexc);	
+	    rb_vm_set_current_exception(rbexc);
+	    throw;
 	}
+#endif
+	if (created) {
+	    rb_exc_raise(rbexc);
+	}
 	throw;
-#else
-	rb_exc_raise(rbexc);
-#endif
     }
     abort(); // never reached
 }

Modified: MacRuby/trunk/objc.h (4189 => 4190)


--- MacRuby/trunk/objc.h	2010-06-02 03:43:36 UTC (rev 4189)
+++ MacRuby/trunk/objc.h	2010-06-02 03:54:58 UTC (rev 4190)
@@ -56,7 +56,7 @@
 	size_t name_len);
 
 id rb_rb2oc_exception(VALUE exc);
-VALUE rb_oc2rb_exception(id exc);
+VALUE rb_oc2rb_exception(id exc, bool *created);
 
 size_t rb_objc_type_size(const char *type);
 

Modified: MacRuby/trunk/objc.m (4189 => 4190)


--- MacRuby/trunk/objc.m	2010-06-02 03:43:36 UTC (rev 4189)
+++ MacRuby/trunk/objc.m	2010-06-02 03:54:58 UTC (rev 4190)
@@ -621,26 +621,32 @@
 {
     NSString *name = [NSString stringWithUTF8String:rb_obj_classname(exc)];
     NSString *reason = (NSString *)rb_format_exception_message(exc);
-#if 0
-    // This is technically not required, and it seems that some exceptions
-    // don't like to be treated like NSDictionary values...
     NSDictionary *dict = [NSDictionary dictionaryWithObject:(id)exc
 	forKey:@"RubyException"];
-#else
-    NSDictionary *dict = nil;
-#endif
     return [NSException exceptionWithName:name reason:reason userInfo:dict];
 }
 
 VALUE
-rb_oc2rb_exception(id exc)
+rb_oc2rb_exception(id exc, bool *created)
 {
-    char buf[1000];
-    snprintf(buf, sizeof buf, "%s: %s", [[exc name] UTF8String],
-	    [[exc reason] UTF8String]);
-    VALUE e = rb_exc_new2(rb_eRuntimeError, buf);
-    // Set the backtrace for Obj-C exceptions
-    rb_iv_set(e, "bt", rb_vm_backtrace(0));
+    VALUE e;
+    id rubyExc;
+
+    rubyExc = [[exc userInfo] objectForKey:@"RubyException"];
+    if (rubyExc == nil) {
+	*created = true;
+
+	char buf[1000];
+	snprintf(buf, sizeof buf, "%s: %s", [[exc name] UTF8String],
+		[[exc reason] UTF8String]);
+	e = rb_exc_new2(rb_eRuntimeError, buf);
+	// Set the backtrace for Obj-C exceptions
+	rb_iv_set(e, "bt", rb_vm_backtrace(0));
+    }
+    else {
+	*created = false;
+	e = (VALUE)rubyExc;
+    }
     return e;
 }