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

source_changes at macosforge.org source_changes at macosforge.org
Fri Oct 24 23:06:01 PDT 2008


Revision: 671
          http://trac.macosforge.org/projects/ruby/changeset/671
Author:   lsansonetti at apple.com
Date:     2008-10-24 23:06:00 -0700 (Fri, 24 Oct 2008)
Log Message:
-----------
more 64-bit madness

Modified Paths:
--------------
    MacRuby/branches/macruby64/class.c
    MacRuby/branches/macruby64/include/ruby/config.h.in
    MacRuby/branches/macruby64/objc.m
    MacRuby/branches/macruby64/object.c
    MacRuby/branches/macruby64/thread.c
    MacRuby/branches/macruby64/variable.c

Modified: MacRuby/branches/macruby64/class.c
===================================================================
--- MacRuby/branches/macruby64/class.c	2008-10-24 21:57:49 UTC (rev 670)
+++ MacRuby/branches/macruby64/class.c	2008-10-25 06:06:00 UTC (rev 671)
@@ -450,13 +450,11 @@
     mdl = rb_objc_alloc_class(id == 0 ? NULL : rb_id2name(id), rb_cObject, T_MODULE, rb_cModule);
     objc_registerClassPair((Class)mdl);
 
-#if 0
     if (rb_mKernel != 0) {
 	/* because Module#initialize can accept a block */
 	extern VALUE rb_mod_initialize(VALUE);
 	rb_define_method(*(VALUE *)mdl, "initialize", rb_mod_initialize, 0);
     }
-#endif
 
     return mdl;
 }

Modified: MacRuby/branches/macruby64/include/ruby/config.h.in
===================================================================
--- MacRuby/branches/macruby64/include/ruby/config.h.in	2008-10-24 21:57:49 UTC (rev 670)
+++ MacRuby/branches/macruby64/include/ruby/config.h.in	2008-10-25 06:06:00 UTC (rev 671)
@@ -21,16 +21,32 @@
 #define _TANDEM_SOURCE 1
 #define HAVE_LONG_LONG 1
 #define HAVE_OFF_T 1
+#define SIZEOF___INT64 0
+#if defined(__LP64__)
 #define SIZEOF_INT 4
 #define SIZEOF_SHORT 2
+#define SIZEOF_LONG 8
+#define SIZEOF_LONG_LONG 8
+#define SIZEOF_OFF_T 8
+#define SIZEOF_VOIDP 8
+#define SIZEOF_FLOAT 4
+#define SIZEOF_DOUBLE 8
+#define SIZEOF_TIME_T 8
+#define SIZEOF_RLIM_T 8
+#define SIZEOF_SIZE_T 8
+#else
+#define SIZEOF_INT 4
+#define SIZEOF_SHORT 2
 #define SIZEOF_LONG 4
 #define SIZEOF_LONG_LONG 8
-#define SIZEOF___INT64 0
 #define SIZEOF_OFF_T 8
 #define SIZEOF_VOIDP 4
 #define SIZEOF_FLOAT 4
 #define SIZEOF_DOUBLE 8
 #define SIZEOF_TIME_T 4
+#define SIZEOF_RLIM_T 8
+#define SIZEOF_SIZE_T 4
+#endif
 #define rb_pid_t pid_t
 #define PIDT2NUM(v) LONG2NUM(v)
 #define NUM2PIDT(v) NUM2LONG(v)
@@ -77,8 +93,6 @@
 #define HAVE_LANGINFO_H 1
 #define HAVE_LOCALE_H 1
 #define HAVE_TIME_H 1
-#define SIZEOF_RLIM_T 8
-#define SIZEOF_SIZE_T 4
 #define HAVE_STRUCT_STAT_ST_BLKSIZE 1
 #define HAVE_ST_BLKSIZE 1
 #define HAVE_STRUCT_STAT_ST_BLOCKS 1

Modified: MacRuby/branches/macruby64/objc.m
===================================================================
--- MacRuby/branches/macruby64/objc.m	2008-10-24 21:57:49 UTC (rev 670)
+++ MacRuby/branches/macruby64/objc.m	2008-10-25 06:06:00 UTC (rev 671)
@@ -1667,21 +1667,29 @@
     }
 
     cif = (ffi_cif *)malloc(sizeof(ffi_cif));
-    if (ffi_prep_cif(cif, FFI_DEFAULT_ABI, arity + 2, ret, args) != FFI_OK)
+    if (ffi_prep_cif(cif, FFI_DEFAULT_ABI, arity + 2, ret, args) != FFI_OK) {
 	rb_fatal("can't prepare ruby to objc cif");
-    
+    }
+
     closure = (ffi_closure *)malloc(sizeof(ffi_closure));
 
+    /* XXX mmap() and mprotect() are 2 expensive calls, maybe we should try to 
+     * mmap() and mprotect() a large memory page and reuse it for closures?
+     */
+
     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 ruby to objc closure");
+    }
 
     if (ffi_prep_closure(closure, cif, rb_ruby_to_objc_closure_handler, node)
-	!= FFI_OK)
+	!= FFI_OK) {
 	rb_fatal("can't prepare ruby to objc 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 the ruby to objc closure");
+    }
 
     rb_objc_retain(node);
 
@@ -3342,6 +3350,18 @@
     assert(m != NULL);
     old_imp_isaForAutonotifying = method_getImplementation(m);
     method_setImplementation(m, (IMP)rb_obj_imp_isaForAutonotifying);
+
+    {
+	VALUE klass;
+	NODE *node, *body;
+	void *closure;
+
+	klass = rb_singleton_class(rb_cNSObject);
+	node = NEW_CFUNC(rb_class_new_instance, -1);
+	body = NEW_FBODY(NEW_METHOD(node, klass, NOEX_PUBLIC), 0);
+	closure = rb_ruby_to_objc_closure("@@:@", 1, body->nd_body);
+	assert(class_addMethod((Class)klass, @selector(new:), (IMP)closure, "@@:@"));
+    }
 }
 
 // for debug in gdb

Modified: MacRuby/branches/macruby64/object.c
===================================================================
--- MacRuby/branches/macruby64/object.c	2008-10-24 21:57:49 UTC (rev 670)
+++ MacRuby/branches/macruby64/object.c	2008-10-25 06:06:00 UTC (rev 671)
@@ -2468,6 +2468,8 @@
     rb_cModule = boot_defclass("Module", rb_cNSObject);
     rb_cClass =  boot_defclass("Class",  rb_cModule);
 
+    rb_define_method(rb_cClass, "new", rb_class_new_instance, -1);
+
     void rb_include_module2(VALUE klass, VALUE module, int check, int add_methods);
 
     rb_include_module2(*(VALUE *)rb_cNSObject, rb_cClass, 0, 0);
@@ -2608,7 +2610,6 @@
     rb_define_method(rb_cModule, "class_variable_defined?", rb_mod_cvar_defined, 1);
 
     rb_define_method(rb_cClass, "allocate", rb_obj_alloc, 0);
-    /*rb_define_method(rb_cClass, "new", rb_class_new_instance, -1);*/
     rb_define_method(rb_cClass, "initialize_copy", rb_class_init_copy, 1); /* in class.c */
     rb_define_alloc_func(rb_cClass, rb_class_s_alloc);
     rb_undef_method(rb_cClass, "extend_object");

Modified: MacRuby/branches/macruby64/thread.c
===================================================================
--- MacRuby/branches/macruby64/thread.c	2008-10-24 21:57:49 UTC (rev 670)
+++ MacRuby/branches/macruby64/thread.c	2008-10-25 06:06:00 UTC (rev 671)
@@ -510,7 +510,7 @@
 		     file);
 	}
         rb_raise(rb_eThreadError, "already initialized thread - %s:%d",
-                 file, NUM2INT(line));
+                 file, (int)NUM2INT(line));
     }
     return thread_create_core(thread, args, 0);
 }

Modified: MacRuby/branches/macruby64/variable.c
===================================================================
--- MacRuby/branches/macruby64/variable.c	2008-10-24 21:57:49 UTC (rev 670)
+++ MacRuby/branches/macruby64/variable.c	2008-10-25 06:06:00 UTC (rev 671)
@@ -577,7 +577,7 @@
     gvar->setter = setter?setter:var_setter;
     gvar->marker = var_marker;
 
-    rb_objc_retain((void *)var);
+    GC_ROOT(var);
 }
 
 void
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20081024/b8f8a31e/attachment-0001.html>


More information about the macruby-changes mailing list