[macruby-changes] [1425] MacRuby/branches/experimental

source_changes at macosforge.org source_changes at macosforge.org
Fri Apr 17 23:23:08 PDT 2009


Revision: 1425
          http://trac.macosforge.org/projects/ruby/changeset/1425
Author:   lsansonetti at apple.com
Date:     2009-04-17 23:23:07 -0700 (Fri, 17 Apr 2009)
Log Message:
-----------
more work on the new objc dispatcher

Modified Paths:
--------------
    MacRuby/branches/experimental/dln.c
    MacRuby/branches/experimental/load.c
    MacRuby/branches/experimental/roxor.cpp
    MacRuby/branches/experimental/spec/frozen/macruby/method_spec.rb

Added Paths:
-----------
    MacRuby/branches/experimental/spec/frozen/macruby/fixtures/
    MacRuby/branches/experimental/spec/frozen/macruby/fixtures/method.m

Modified: MacRuby/branches/experimental/dln.c
===================================================================
--- MacRuby/branches/experimental/dln.c	2009-04-18 00:56:43 UTC (rev 1424)
+++ MacRuby/branches/experimental/dln.c	2009-04-18 06:23:07 UTC (rev 1425)
@@ -20,7 +20,7 @@
 #include <sys/param.h>
 #include <unistd.h>
 
-#define FUNCNAME_PATTERN "_Init_%s"
+#define FUNCNAME_PATTERN "Init_%s"
 
 static int
 init_funcname_len(char **buf, const char *file)

Modified: MacRuby/branches/experimental/load.c
===================================================================
--- MacRuby/branches/experimental/load.c	2009-04-18 00:56:43 UTC (rev 1424)
+++ MacRuby/branches/experimental/load.c	2009-04-18 06:23:07 UTC (rev 1425)
@@ -5,9 +5,8 @@
 #include "ruby/ruby.h"
 #include "ruby/node.h"
 #include "roxor.h"
+#include "dln.h"
 
-VALUE ruby_dln_librefs;
-
 #define IS_RBEXT(e) (strcmp(e, ".rb") == 0)
 #define IS_SOEXT(e) (strcmp(e, ".so") == 0 || strcmp(e, ".o") == 0)
 #ifdef DLEXT2
@@ -119,7 +118,8 @@
 }
 
 static int
-rb_feature_p(const char *feature, const char *ext, int rb, int expanded, const char **fn)
+rb_feature_p(const char *feature, const char *ext, int rb, int expanded,
+	     const char **fn)
 {
     VALUE v, features, p, load_path = 0;
     const char *f, *e;
@@ -486,8 +486,7 @@
 		    break;
 
 		case 's':
-		    // TODO
-		    abort();
+		    dln_load(RSTRING_PTR(path));
 		    break;
 	    }
 	    rb_provide_feature(path);
@@ -609,8 +608,4 @@
     rb_objc_define_method(rb_mKernel, "autoload?", rb_f_autoload_p, 1);
 
     rb_objc_define_method(rb_mKernel, "framework", rb_require_framework, -1);
-
-    ruby_dln_librefs = rb_ary_new();
-    GC_ROOT(&ruby_dln_librefs);
-    rb_register_mark_object(ruby_dln_librefs);
 }

Modified: MacRuby/branches/experimental/roxor.cpp
===================================================================
--- MacRuby/branches/experimental/roxor.cpp	2009-04-18 00:56:43 UTC (rev 1424)
+++ MacRuby/branches/experimental/roxor.cpp	2009-04-18 06:23:07 UTC (rev 1425)
@@ -6381,11 +6381,20 @@
 	}
 
 	if (sel == selClass) {
+	    // Because +[NSObject class] returns self.
 	    if (RCLASS_META(klass)) {
-		// Because +[NSObject class] returns self.
 		return RCLASS_MODULE(self) ? rb_cModule : rb_cClass;
 	    }
 	    // Because the CF classes should be hidden, for Ruby compat.
+	    if (self == Qnil) {
+		return rb_cNilClass;
+	    }
+	    if (self == Qtrue) {
+		return rb_cTrueClass;
+	    }
+	    if (self == Qfalse) {
+		return rb_cFalseClass;
+	    }
 	    if (klass == (Class)rb_cCFString) {
 		return RSTRING_IMMUTABLE(self)
 		    ? rb_cNSString : rb_cNSMutableString;
@@ -7598,7 +7607,7 @@
 static VALUE
 builtin_ostub1(IMP imp, id self, SEL sel, int argc, VALUE *argv)
 {
-    return ((VALUE (*)(id, SEL))*imp)(self, sel);
+    return OC2RB(((id (*)(id, SEL))*imp)(self, sel));
 }
 
 static void

Added: MacRuby/branches/experimental/spec/frozen/macruby/fixtures/method.m
===================================================================
--- MacRuby/branches/experimental/spec/frozen/macruby/fixtures/method.m	                        (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/macruby/fixtures/method.m	2009-04-18 06:23:07 UTC (rev 1425)
@@ -0,0 +1,34 @@
+#import <Foundation/Foundation.h>
+
+ at interface TestMethod : NSObject
+ at end
+
+ at implementation TestMethod
+
+- (id)methodReturningSelf
+{
+    return self;
+}
+
+- (id)methodReturningCFTrue
+{
+    return (id)kCFBooleanTrue;
+}
+
+- (id)methodReturningCFFalse
+{
+    return (id)kCFBooleanFalse;
+}
+
+- (id)methodReturningCFNull
+{
+    return (id)kCFNull;
+}
+
+ at end
+
+void
+Init_method(void)
+{
+    // Do nothing.
+}

Modified: MacRuby/branches/experimental/spec/frozen/macruby/method_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/macruby/method_spec.rb	2009-04-18 00:56:43 UTC (rev 1424)
+++ MacRuby/branches/experimental/spec/frozen/macruby/method_spec.rb	2009-04-18 06:23:07 UTC (rev 1425)
@@ -1,7 +1,5 @@
 require File.dirname(__FILE__) + '/../spec_helper'
 
-framework 'Foundation'
-
 describe "A MacRuby method" do
   it "uses argument-names + colon + variable syntax to form the method name" do
     o = Object.new
@@ -91,6 +89,22 @@
   end
 end
 
+framework 'Foundation'
+
+fixture_source = File.dirname(__FILE__) + '/fixtures/method.m'
+fixture_ext = '/tmp/method.bundle'
+if !File.exist?(fixture_ext) or File.mtime(fixture_source) > File.mtime(fixture_ext)
+=begin
+  # #system is currently broken
+  unless system("/usr/bin/gcc #{fixture_source} -o #{fixture_ext} -g -framework Foundation -dynamiclib -fobjc-gc -arch i386 -arch x86_64 -arch ppc")
+    $stderr.puts "cannot compile fixture source file `#{fixture_source}' - aborting"
+    exit 1
+  end
+=end
+  `/usr/bin/gcc #{fixture_source} -o #{fixture_ext} -g -framework Foundation -dynamiclib -fobjc-gc -arch i386 -arch x86_64 -arch ppc`
+end
+require '/tmp/method'
+
 describe "An Objective-C method" do
   it "named using the setFoo pattern can be called using #foo=" do
     o = []
@@ -115,4 +129,28 @@
     o.methods(true, true).include?(:'performSelector').should == true
     o.methods(false, true).include?(:'performSelector').should == true
   end
+
+  it "returning self returns the same receiver object" do
+    o = TestMethod.new
+    o.methodReturningSelf.should == o
+    o.methodReturningSelf.object_id == o.object_id
+  end
+
+  it "returning kCFBooleanTrue returns true in Ruby" do
+    o = TestMethod.new
+    o.methodReturningCFTrue.should == true
+    o.methodReturningCFTrue.class.should == TrueClass
+  end
+
+  it "returning kCFBooleanFalse returns false in Ruby" do
+    o = TestMethod.new
+    o.methodReturningCFFalse.should == false
+    o.methodReturningCFFalse.class.should == FalseClass
+  end
+
+  it "returning kCFNull returns nil in Ruby" do
+    o = TestMethod.new
+    o.methodReturningCFNull.should == nil
+    o.methodReturningCFNull.class.should == NilClass
+  end
 end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090417/10d2f601/attachment-0001.html>


More information about the macruby-changes mailing list