[macruby-changes] [3035] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Fri Nov 20 00:58:30 PST 2009


Revision: 3035
          http://trac.macosforge.org/projects/ruby/changeset/3035
Author:   martinlagardette at apple.com
Date:     2009-11-20 00:58:22 -0800 (Fri, 20 Nov 2009)
Log Message:
-----------

 - Got rid of an unused header I added on last commit
 - Better handle of nesting (and prettier code too)
 - rb_objc_release -> GC_RELEASE

Modified Paths:
--------------
    MacRuby/trunk/vm.cpp
    MacRuby/trunk/vm.h

Modified: MacRuby/trunk/vm.cpp
===================================================================
--- MacRuby/trunk/vm.cpp	2009-11-20 07:47:28 UTC (rev 3034)
+++ MacRuby/trunk/vm.cpp	2009-11-20 08:58:22 UTC (rev 3035)
@@ -45,8 +45,6 @@
 #include "dtrace.h"
 
 #include <objc/objc-exception.h>
-#include <cxxabi.h>
-using namespace __cxxabiv1;
 
 #include <execinfo.h>
 #include <dlfcn.h>
@@ -3836,12 +3834,12 @@
     }
 }
 
-VALUE
-RoxorVM::ruby_catch(VALUE tag)
+void
+RoxorVM::increase_nesting_for_tag(VALUE tag)
 {
-    std::map<VALUE, int*>::iterator iter = catch_nesting.find(tag);
+    std::map<VALUE, int*>::iterator iter = this->catch_nesting.find(tag);
+    int *nested_ptr = NULL;
 
-    int *nested_ptr = NULL;
     if (iter == catch_nesting.end()) {
 	nested_ptr = (int *)malloc(sizeof(int));
 	*nested_ptr = 1;
@@ -3852,8 +3850,33 @@
 	nested_ptr = iter->second;
 	(*nested_ptr)++;
     }
+}
 
+void
+RoxorVM::decrease_nesting_for_tag(VALUE tag)
+{
+    std::map<VALUE, int*>::iterator iter = this->catch_nesting.find(tag);
+    int *nested_ptr = NULL;
+ 
+    iter = catch_nesting.find(tag);
+    assert(iter != catch_nesting.end());
+    nested_ptr = iter->second;
+
+    (*nested_ptr)--;
+    if (*nested_ptr == 0) {
+	nested_ptr = iter->second;
+	free(nested_ptr);
+	catch_nesting.erase(iter);
+	GC_RELEASE(tag);
+    }
+}
+
+VALUE
+RoxorVM::ruby_catch(VALUE tag)
+{
     VALUE retval = Qundef;
+
+    this->increase_nesting_for_tag(tag);
     try {
 	retval = rb_vm_yield(1, &tag);
     }
@@ -3866,26 +3889,20 @@
 	    RoxorCatchThrowException *exc = GET_VM()->get_throw_exc();
 	    if (exc != NULL && exc->throw_symbol == tag) {
 		retval = exc->throw_value;
-		rb_objc_release((void *)retval);
+		GC_RELEASE(retval);
 		delete exc;
 		GET_VM()->set_throw_exc(NULL);
 	    }
+	    else {
+		this->decrease_nesting_for_tag(tag);
+	    }
 	}
 	if (retval == Qundef) {
 	    throw;
 	}
     }
+    this->decrease_nesting_for_tag(tag); 
 
-    iter = catch_nesting.find(tag);
-    assert(iter != catch_nesting.end());
-    (*nested_ptr)--;
-    if (*nested_ptr == 0) {
-	nested_ptr = iter->second;
-	free(nested_ptr);
-	catch_nesting.erase(iter);
-	GC_RELEASE(tag);
-    }
-
     return retval;
 }
 
@@ -3906,7 +3923,7 @@
         rb_raise(rb_eArgError, "uncaught throw %s", RSTRING_PTR(desc));
     }
 
-    rb_objc_retain((void *)value);
+    GC_RETAIN(value);
 
     RoxorCatchThrowException *exc = new RoxorCatchThrowException;
     exc->throw_symbol = tag;

Modified: MacRuby/trunk/vm.h
===================================================================
--- MacRuby/trunk/vm.h	2009-11-20 07:47:28 UTC (rev 3034)
+++ MacRuby/trunk/vm.h	2009-11-20 08:58:22 UTC (rev 3035)
@@ -879,6 +879,9 @@
 
 	RoxorCatchThrowException *throw_exc;
 
+	void increase_nesting_for_tag(VALUE tag);
+	void decrease_nesting_for_tag(VALUE tag);
+
     public:
 	RoxorVM(void);
 	RoxorVM(const RoxorVM &vm);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20091120/f33c41a4/attachment-0001.html>


More information about the macruby-changes mailing list