[macruby-changes] [667] MacRuby/branches/macruby64

source_changes at macosforge.org source_changes at macosforge.org
Wed Oct 22 16:45:58 PDT 2008


Revision: 667
          http://trac.macosforge.org/projects/ruby/changeset/667
Author:   lsansonetti at apple.com
Date:     2008-10-22 16:45:57 -0700 (Wed, 22 Oct 2008)
Log Message:
-----------
more 64-bit work

Modified Paths:
--------------
    MacRuby/branches/macruby64/gc.c
    MacRuby/branches/macruby64/objc.m
    MacRuby/branches/macruby64/vm_insnhelper.c

Modified: MacRuby/branches/macruby64/gc.c
===================================================================
--- MacRuby/branches/macruby64/gc.c	2008-10-21 07:30:59 UTC (rev 666)
+++ MacRuby/branches/macruby64/gc.c	2008-10-22 23:45:57 UTC (rev 667)
@@ -1231,7 +1231,8 @@
 static void
 rb_obj_imp_finalize(void *obj, SEL sel)
 {
-    const bool need_protection = GET_THREAD()->thread_id != pthread_self();
+    const bool need_protection = 
+	GET_THREAD()->thread_id != pthread_self();
     bool call_finalize, free_ivar;
 
     if (NATIVE((VALUE)obj)) {
@@ -1263,6 +1264,8 @@
     }
 }
 
+static bool gc_disabled = false;
+
 void
 Init_PreGC(void)
 {
@@ -1276,9 +1279,13 @@
     control = auto_collection_parameters(__auto_zone);
     control->scan_external_callout = 
 	rb_objc_scan_external_callout;
-    if (getenv("GC_DEBUG"))
+    if (getenv("GC_DEBUG")) {
 	control->log = AUTO_LOG_COLLECTIONS | AUTO_LOG_REGIONS 
 		       | AUTO_LOG_UNUSUAL | AUTO_LOG_COLLECT_DECISION;
+    }
+    if (getenv("GC_DISABLE")) {
+	gc_disabled = true;
+    }
 
     Method m = class_getInstanceMethod((Class)objc_getClass("NSObject"), sel_registerName("finalize"));
     assert(m != NULL);
@@ -1290,8 +1297,10 @@
 void
 Init_PostGC(void)
 {
-    objc_startCollectorThread();
-    auto_collector_reenable(__auto_zone);
+    if (!gc_disabled) {
+	objc_startCollectorThread();
+	auto_collector_reenable(__auto_zone);
+    }
 }
 
 void
@@ -1320,7 +1329,7 @@
     rb_global_variable(&nomem_error);
     nomem_error = rb_exc_new2(rb_eNoMemError, "failed to allocate memory");
 
-    rb_define_method(rb_mKernel, "hash", rb_obj_id, 0);
+    //rb_define_method(rb_mKernel, "hash", rb_obj_id, 0);
     rb_define_method(rb_mKernel, "__id__", rb_obj_id, 0);
     rb_define_method(rb_mKernel, "object_id", rb_obj_id, 0);
 

Modified: MacRuby/branches/macruby64/objc.m
===================================================================
--- MacRuby/branches/macruby64/objc.m	2008-10-21 07:30:59 UTC (rev 666)
+++ MacRuby/branches/macruby64/objc.m	2008-10-22 23:45:57 UTC (rev 667)
@@ -44,6 +44,11 @@
 #include "vm.h"
 #include "eval_intern.h"
 
+void native_mutex_lock(pthread_mutex_t *lock);
+void native_mutex_unlock(pthread_mutex_t *lock);
+rb_thread_t *rb_thread_wrap_existing_native_thread(rb_thread_id_t id);
+extern VALUE rb_cMutex;
+
 typedef struct {
     bs_element_type_t type;
     void *value;
@@ -1168,9 +1173,16 @@
 		 argc, count - 2);
     }
 
+#define UNLOCK_GIL() \
+    do { if (rb_cMutex != 0) { native_mutex_unlock(&GET_THREAD()->vm->global_interpreter_lock); }; } while (0)
+#define LOCK_GIL() \
+    do { if (rb_cMutex != 0) { native_mutex_lock(&GET_THREAD()->vm->global_interpreter_lock); }; } while (0)
+
     if (count == 2) {
 	if (sig->types[0] == '@' || sig->types[0] == '#' || sig->types[0] == 'v') {
 	    /* Easy case! */
+	    id exception = nil;
+	    //UNLOCK_GIL();
 	    @try {
 		if (klass == RCLASS_SUPER(*(Class *)ocrcv)) {
 		    struct objc_super s;
@@ -1187,8 +1199,12 @@
 		}
 	    }
 	    @catch (id e) {
-		rb_objc_exc_raise(e);
+		exception = e;
 	    }
+	    //LOCK_GIL();
+	    if (exception != nil) {
+		rb_objc_exc_raise(exception);
+	    }
 	    if (sig->types[0] == '@' || sig->types[0] == '#') {
 		VALUE retval;
 		buf[0] = sig->types[0];
@@ -1603,8 +1619,6 @@
     ctx.args = args;
     ctx.userdata = userdata;
 
-    extern VALUE rb_cMutex;
-
     if (rb_cMutex == 0) {
 	/* GL not initialized yet! */
 	rb_ruby_to_objc_closure_handler_main(&ctx);
@@ -1615,8 +1629,6 @@
 	}
 	else {
 	    rb_thread_t *rb_thread_wrap_existing_native_thread(rb_thread_id_t id);
-	    void native_mutex_lock(pthread_mutex_t *lock);
-	    void native_mutex_unlock(pthread_mutex_t *lock);
 
 	    rb_thread_t *th, *old;
 
@@ -2254,8 +2266,8 @@
 {
     struct rb_struct_accessor_context *ctx;
     VALUE recv, *data;
-
-    recv = (*(VALUE **)args)[0];
+ 
+    recv = *(VALUE *)args[0];
     Data_Get_Struct(recv, VALUE, data);
     assert(data != NULL);
 
@@ -2272,8 +2284,8 @@
     size_t fdata_size;
     void *fdata;
 
-    recv = (*(VALUE **)args)[0];
-    value = (*(VALUE **)args)[1];
+    recv = *(VALUE *)args[0];
+    value = *(VALUE *)args[1];
     Data_Get_Struct(recv, VALUE, data);
     assert(data != NULL);
 
@@ -2309,18 +2321,21 @@
 	args = (ffi_type **)malloc(sizeof(ffi_type *) * 1);
 	args[0] = &ffi_type_pointer;
 	if (ffi_prep_cif(struct_reader_cif, FFI_DEFAULT_ABI, 1, 
-			 &ffi_type_pointer, args) != FFI_OK)
+			 &ffi_type_pointer, args) != FFI_OK) {
 	    rb_fatal("can't prepare struct_reader_cif");
+	}
     }
     if ((closure = mmap(NULL, sizeof(ffi_closure), PROT_READ | PROT_WRITE,
-			MAP_ANON | MAP_PRIVATE, -1, 0)) == (void *)-1)
+			MAP_ANON | MAP_PRIVATE, -1, 0)) == (void *)-1) {
 	rb_fatal("can't allocate struct reader closure");
+    }
     if (ffi_prep_closure(closure, struct_reader_cif, 
-		         rb_struct_reader_closure_handler, ctx)
-	!= FFI_OK)
+		         rb_struct_reader_closure_handler, ctx) != FFI_OK) {
 	rb_fatal("can't prepare struct reader closure");
-    if (mprotect(closure, sizeof(closure), PROT_READ | PROT_EXEC) == -1)
+    }
+    if (mprotect(closure, sizeof(closure), PROT_READ | PROT_EXEC) == -1) {
 	rb_fatal("can't mprotect struct reader closure");
+    }
 
     rb_define_method(klass, field->name, (VALUE(*)(ANYARGS))closure, 0);
 
@@ -2332,18 +2347,21 @@
 	args[0] = &ffi_type_pointer;
 	args[1] = &ffi_type_pointer;
 	if (ffi_prep_cif(struct_writer_cif, FFI_DEFAULT_ABI, 2, 
-			 &ffi_type_pointer, args) != FFI_OK)
+			 &ffi_type_pointer, args) != FFI_OK) {
 	    rb_fatal("can't prepare struct_writer_cif");
+	}
     }
     if ((closure = mmap(NULL, sizeof(ffi_closure), PROT_READ | PROT_WRITE,
-			MAP_ANON | MAP_PRIVATE, -1, 0)) == (void *)-1)
+			MAP_ANON | MAP_PRIVATE, -1, 0)) == (void *)-1) {
 	rb_fatal("can't allocate struct writer closure");
+    }
     if (ffi_prep_closure(closure, struct_writer_cif, 
-			 rb_struct_writer_closure_handler, ctx)
-	!= FFI_OK)
+			 rb_struct_writer_closure_handler, ctx) != FFI_OK) {
 	rb_fatal("can't prepare struct writer closure");
-    if (mprotect(closure, sizeof(closure), PROT_READ | PROT_EXEC) == -1)
+    }
+    if (mprotect(closure, sizeof(closure), PROT_READ | PROT_EXEC) == -1) {
 	rb_fatal("can't mprotect struct writer closure");
+    }
 
     snprintf(buf, sizeof buf, "%s=", field->name);
     rb_define_method(klass, buf, (VALUE(*)(ANYARGS))closure, 1);
@@ -3498,9 +3516,6 @@
 	}
     }
    
-    rb_thread_t *rb_thread_wrap_existing_native_thread(rb_thread_id_t id);
-    void native_mutex_unlock(pthread_mutex_t *lock);
-    void native_mutex_lock(pthread_mutex_t *lock);
     rb_thread_t *th, *old = NULL;
 
     if (need_protection) {
@@ -3563,4 +3578,3 @@
 }
 
 @end
-

Modified: MacRuby/branches/macruby64/vm_insnhelper.c
===================================================================
--- MacRuby/branches/macruby64/vm_insnhelper.c	2008-10-21 07:30:59 UTC (rev 666)
+++ MacRuby/branches/macruby64/vm_insnhelper.c	2008-10-22 23:45:57 UTC (rev 667)
@@ -1491,9 +1491,9 @@
 
 	    imod = RARRAY_AT(ary, i);
 	    saved_imod_super = RCLASS_SUPER(imod);
-	    RCLASS_SET_SUPER(imod, 0);
+	    RCLASS_SUPER(imod) = 0;
 	    mn = rb_objc_method_node(imod, mid, &imp, &sel);
-	    RCLASS_SET_SUPER(imod, saved_imod_super);
+	    RCLASS_SUPER(imod) = saved_imod_super;
 	    if (imp != NULL) {
 		rb_ivar_set(imod, idPreviousKlass, klass);
 		*mnp = mn;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20081022/234dae80/attachment.html>


More information about the macruby-changes mailing list