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

source_changes at macosforge.org source_changes at macosforge.org
Sat Oct 25 18:16:07 PDT 2008


Revision: 672
          http://trac.macosforge.org/projects/ruby/changeset/672
Author:   lsansonetti at apple.com
Date:     2008-10-25 18:16:07 -0700 (Sat, 25 Oct 2008)
Log Message:
-----------
introduced Pointer.new_with_type to deal with passed-by-reference arguments, fixed a critical performance regression in the dtrace yarv insn probe, introduced RUBY_ARCH, fixed a few tests

Modified Paths:
--------------
    MacRuby/branches/macruby64/lib/hotcocoa/application_builder.rb
    MacRuby/branches/macruby64/objc.m
    MacRuby/branches/macruby64/test/ruby/test_objc.rb
    MacRuby/branches/macruby64/version.c
    MacRuby/branches/macruby64/vm.h
    MacRuby/branches/macruby64/vm_insnhelper.c

Modified: MacRuby/branches/macruby64/lib/hotcocoa/application_builder.rb
===================================================================
--- MacRuby/branches/macruby64/lib/hotcocoa/application_builder.rb	2008-10-25 06:06:00 UTC (rev 671)
+++ MacRuby/branches/macruby64/lib/hotcocoa/application_builder.rb	2008-10-26 01:16:07 UTC (rev 672)
@@ -176,7 +176,8 @@
             }
           }
         end
-        puts `cd "#{macos_root}" && gcc main.m -o #{name.gsub(/ /, '')} -arch ppc -arch i386 -framework MacRuby -framework Foundation -fobjc-gc-only`
+        archs = RUBY_ARCH.include?('ppc') ? '-arch ppc' : '-arch i386 -arch x86_64'
+        puts `cd "#{macos_root}" && gcc main.m -o #{name.gsub(/ /, '')} #{archs} -framework MacRuby -framework Foundation -fobjc-gc-only`
         File.unlink(objective_c_source_file)
       end
       
@@ -232,4 +233,4 @@
 
   end
   
-end
\ No newline at end of file
+end

Modified: MacRuby/branches/macruby64/objc.m
===================================================================
--- MacRuby/branches/macruby64/objc.m	2008-10-25 06:06:00 UTC (rev 671)
+++ MacRuby/branches/macruby64/objc.m	2008-10-26 01:16:07 UTC (rev 672)
@@ -75,29 +75,14 @@
 static struct st_table *bs_inf_prot_imethods;
 static struct st_table *bs_cftypes;
 
-#if 0
-static char *
-rb_objc_sel_to_mid(SEL selector, char *buffer, unsigned buffer_len)
+VALUE rb_cPointer;
+
+struct RPointer
 {
-    size_t s;
-    char *p;
+  void *ptr;
+  const char *type;
+};
 
-    s = strlcpy(buffer, (const char *)selector, buffer_len);
-
-    p = buffer + s - 1;
-    if (*p == ':')
-	*p = '\0';
-
-    p = buffer;
-    while ((p = strchr(p, ':')) != NULL) {
-	*p = '_';
-	p++;
-    }
-
-    return buffer;
-}
-#endif
-
 static inline const char *
 rb_objc_skip_octype_modifiers(const char *octype)
 {
@@ -519,14 +504,6 @@
     return n;
 }
 
-VALUE rb_cPointer;
-
-struct RPointer
-{
-  void *ptr;
-  const char *type;
-};
-
 static VALUE
 rb_pointer_create(void *ptr, const char *type)
 {
@@ -542,6 +519,25 @@
 static void rb_objc_rval_to_ocval(VALUE, const char *, void **);
 
 static VALUE
+rb_pointer_new_with_type(VALUE recv, VALUE type)
+{
+    const char *ctype;
+    ffi_type *ffitype;
+    struct RPointer *data;
+
+    Check_Type(type, T_STRING);
+    ctype = RSTRING_PTR(type);
+    ffitype = rb_objc_octype_to_ffitype(ctype);
+
+    data = (struct RPointer *)xmalloc(sizeof(struct RPointer ));
+    GC_WB(&data->ptr, xmalloc(ffitype->size));
+    GC_WB(&data->type, xmalloc(strlen(ctype) + 1));
+    strcpy((char *)data->type, ctype);
+
+    return Data_Wrap_Struct(rb_cPointer, NULL, NULL, data);
+}
+
+static VALUE
 rb_pointer_assign(VALUE recv, VALUE val)
 {
     struct RPointer *data;
@@ -720,14 +716,18 @@
 		    }
 		    break;
 		default:
-		    if (strcmp(octype, "^v") == 0) {
-			if (SPECIAL_CONST_P(rval)) {
-			    ok = false;
-			}
-			else {
-			    *(void **)ocval = (void *)rval;
-			}
+		    if (SPECIAL_CONST_P(rval)) {
+			ok = false;
 		    }
+		    else if (*(VALUE *)rval == rb_cPointer) {
+			struct RPointer *data;
+
+			Data_Get_Struct(rval, struct RPointer, data);
+			*(void **)ocval = data->ptr;
+		    }
+		    else if (strcmp(octype, "^v") == 0) {
+			*(void **)ocval = (void *)rval;
+		    }
 		    else if (st_lookup(bs_boxeds, (st_data_t)octype + 1, 
 			     (st_data_t *)&bs_boxed)) {
 			*(void **)ocval = xmalloc(bs_boxed->ffi_type->size);
@@ -3330,6 +3330,7 @@
 
     rb_cPointer = rb_define_class("Pointer", rb_cObject);
     rb_undef_alloc_func(rb_cPointer);
+    rb_define_singleton_method(rb_cPointer, "new_with_type", rb_pointer_new_with_type, 1);
     rb_define_method(rb_cPointer, "assign", rb_pointer_assign, 1);
     rb_define_method(rb_cPointer, "[]", rb_pointer_aref, 1);
 

Modified: MacRuby/branches/macruby64/test/ruby/test_objc.rb
===================================================================
--- MacRuby/branches/macruby64/test/ruby/test_objc.rb	2008-10-25 06:06:00 UTC (rev 671)
+++ MacRuby/branches/macruby64/test/ruby/test_objc.rb	2008-10-26 01:16:07 UTC (rev 672)
@@ -57,7 +57,7 @@
 
 if !File.exist?('/tmp/dummy.bundle') or File.mtime(__FILE__) > File.mtime('/tmp/dummy.bundle')
   File.open('/tmp/dummy.m', 'w') { |io| io.write(DUMMY_M) }
-  system("/usr/bin/gcc /tmp/dummy.m -o /tmp/dummy.bundle -g -framework Foundation -dynamiclib -fobjc-gc")
+  system("/usr/bin/gcc /tmp/dummy.m -o /tmp/dummy.bundle -g -framework Foundation -dynamiclib -fobjc-gc -arch i386 -arch x86_64 -arch ppc")
 end
 require '/tmp/dummy.bundle'
 
@@ -255,18 +255,32 @@
 
   def test_struct_inspect
     r = NSRect.new
-    assert_equal("#<NSRect origin=#<NSPoint x=0.0 y=0.0> size=#<NSSize width=0.0 height=0.0>>",
-                 r.inspect)
+    if RUBY_ARCH == 'x86_64'
+      assert_equal("#<NSRect origin=#<CGPoint x=0.0 y=0.0> size=#<CGSize width=0.0 height=0.0>>",
+                   r.inspect)
+    else
+      assert_equal("#<NSRect origin=#<NSPoint x=0.0 y=0.0> size=#<NSSize width=0.0 height=0.0>>",
+                   r.inspect)
+    end
     r.origin.x = 42
     r.size.width = 42
-    assert_equal("#<NSRect origin=#<NSPoint x=42.0 y=0.0> size=#<NSSize width=42.0 height=0.0>>",
-                 r.inspect)
+    if RUBY_ARCH == 'x86_64'
+      assert_equal("#<NSRect origin=#<CGPoint x=42.0 y=0.0> size=#<CGSize width=42.0 height=0.0>>",
+                   r.inspect)
+    else
+      assert_equal("#<NSRect origin=#<NSPoint x=42.0 y=0.0> size=#<NSSize width=42.0 height=0.0>>",
+                   r.inspect)
+    end
   end
 
   def test_struct_dup
     r = NSMakeRect(1, 2, 3, 4)
     r2 = r.dup
-    assert_kind_of(NSRect, r2)
+    if RUBY_ARCH == 'x86_64'
+      assert_kind_of(CGRect, r2)
+    else
+      assert_kind_of(NSRect, r2)
+    end
     assert_equal(r, r2)
     r2.origin.x = 42
     assert(r != r2) 
@@ -422,4 +436,16 @@
     assert_equal(o, o.mutableCopy)
     assert_equal('^{_NSZone=}', o.methodSignatureForSelector('mutableCopyWithZone:').getArgumentTypeAtIndex(2))
   end 
+
+  def test_create_pointer
+    assert_equal(nil, NSString.stringWithContentsOfFile('/does/not/exist', encoding:NSASCIIStringEncoding, error:nil))
+    p = Pointer.new_with_type('@')
+    p.assign(nil)
+    assert_equal(nil, NSString.stringWithContentsOfFile('/does/not/exist', encoding:NSASCIIStringEncoding, error:p))
+    err = p[0]
+    assert_kind_of(NSError, err) 
+    p.assign(nil)
+    assert(NSString.stringWithContentsOfFile(__FILE__, encoding:NSASCIIStringEncoding, error:p))
+    assert_equal(nil, p[0])
+  end
 end

Modified: MacRuby/branches/macruby64/version.c
===================================================================
--- MacRuby/branches/macruby64/version.c	2008-10-25 06:06:00 UTC (rev 671)
+++ MacRuby/branches/macruby64/version.c	2008-10-26 01:16:07 UTC (rev 672)
@@ -37,6 +37,7 @@
     rb_define_global_const("RUBY_COPYRIGHT", MKSTR(copyright));
     rb_define_global_const("RUBY_ENGINE", MKSTR(engine));
 #if WITH_OBJC
+    rb_define_global_const("RUBY_ARCH", rb_str_new2(RUBY_ARCH));
     rb_define_global_const("MACRUBY_VERSION", rb_float_new(MACRUBY_VERSION));
 #endif
 }

Modified: MacRuby/branches/macruby64/vm.h
===================================================================
--- MacRuby/branches/macruby64/vm.h	2008-10-25 06:06:00 UTC (rev 671)
+++ MacRuby/branches/macruby64/vm.h	2008-10-26 01:16:07 UTC (rev 672)
@@ -82,8 +82,8 @@
 extern void rb_enter_insn_trace(rb_control_frame_t *);
 extern void rb_end_insn_trace(rb_control_frame_t *);
 #define debugs
-#define DEBUG_ENTER_INSN(insn) rb_enter_insn_trace(GET_CFP())
-#define DEBUG_END_INSN() rb_end_insn_trace(GET_CFP());
+#define DEBUG_ENTER_INSN(insn) do { if (MACRUBY_INSN_ENTRY_ENABLED()) rb_enter_insn_trace(GET_CFP()); } while (0)
+#define DEBUG_END_INSN() do { if (MACRUBY_INSN_RETURN_ENABLED()) rb_end_insn_trace(GET_CFP()); } while (0)
 #endif
 
 #define throwdebug if(0)printf

Modified: MacRuby/branches/macruby64/vm_insnhelper.c
===================================================================
--- MacRuby/branches/macruby64/vm_insnhelper.c	2008-10-25 06:06:00 UTC (rev 671)
+++ MacRuby/branches/macruby64/vm_insnhelper.c	2008-10-26 01:16:07 UTC (rev 672)
@@ -1858,39 +1858,35 @@
 void
 rb_enter_insn_trace(rb_control_frame_t *cfp)
 {
-    if (MACRUBY_INSN_ENTRY_ENABLED()) {
-	/* just to get rid of compilation warnings... */
-	if (0) {
-	    insn_op_types(0);
-	    insn_op_type(0, 0);
-	}
+    /* just to get rid of compilation warnings... */
+    if (0) {
+	insn_op_types(0);
+	insn_op_type(0, 0);
+    }
 
-	rb_iseq_t *iseq = cfp->iseq;
+    rb_iseq_t *iseq = cfp->iseq;
 
-	if (iseq != NULL && VM_FRAME_TYPE(cfp) != FRAME_MAGIC_FINISH) {
-	    VALUE *seq = iseq->iseq;
-	    int pc = cfp->pc - iseq->iseq_encoded;
+    if (iseq != NULL && VM_FRAME_TYPE(cfp) != FRAME_MAGIC_FINISH) {
+	VALUE *seq = iseq->iseq;
+	int pc = cfp->pc - iseq->iseq_encoded;
 
-	    MACRUBY_INSN_ENTRY((char *)insn_name(seq[pc]), 
-		    	       (char *)rb_sourcefile(), 
-			       rb_sourceline());
-	}
+	MACRUBY_INSN_ENTRY((char *)insn_name(seq[pc]), 
+		(char *)rb_sourcefile(), 
+		rb_sourceline());
     }
 }
 
 void
 rb_end_insn_trace(rb_control_frame_t *cfp)
 {
-    if (MACRUBY_INSN_RETURN_ENABLED()) {
-	rb_iseq_t *iseq = cfp->iseq;
+    rb_iseq_t *iseq = cfp->iseq;
 
-	if (iseq != NULL && VM_FRAME_TYPE(cfp) != FRAME_MAGIC_FINISH) {
-	    VALUE *seq = iseq->iseq;
-	    int pc = cfp->pc - iseq->iseq_encoded;
+    if (iseq != NULL && VM_FRAME_TYPE(cfp) != FRAME_MAGIC_FINISH) {
+	VALUE *seq = iseq->iseq;
+	int pc = cfp->pc - iseq->iseq_encoded;
 
-	    MACRUBY_INSN_RETURN((char *)insn_name(seq[pc]),
-		    		(char *)rb_sourcefile(),
-				rb_sourceline());
-	}
+	MACRUBY_INSN_RETURN((char *)insn_name(seq[pc]),
+		(char *)rb_sourcefile(),
+		rb_sourceline());
     }
 }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20081025/9a582d6a/attachment-0001.html>


More information about the macruby-changes mailing list