[macruby-changes] [1629] MacRuby/branches/experimental
source_changes at macosforge.org
source_changes at macosforge.org
Thu May 28 21:32:51 PDT 2009
Revision: 1629
http://trac.macosforge.org/projects/ruby/changeset/1629
Author: lsansonetti at apple.com
Date: 2009-05-28 21:32:50 -0700 (Thu, 28 May 2009)
Log Message:
-----------
define -allocWithZone: and not -alloc on every new Ruby class
Modified Paths:
--------------
MacRuby/branches/experimental/class.c
MacRuby/branches/experimental/id.c
MacRuby/branches/experimental/id.h
MacRuby/branches/experimental/objc.m
Added Paths:
-----------
MacRuby/branches/experimental/spec/macruby/core/object_spec.rb
MacRuby/branches/experimental/spec/macruby/fixtures/object.m
MacRuby/branches/experimental/spec/macruby/fixtures/object.rb
Modified: MacRuby/branches/experimental/class.c
===================================================================
--- MacRuby/branches/experimental/class.c 2009-05-29 03:02:01 UTC (rev 1628)
+++ MacRuby/branches/experimental/class.c 2009-05-29 04:32:50 UTC (rev 1629)
@@ -13,9 +13,10 @@
#include "ruby/signal.h"
#include "ruby/node.h"
#include "ruby/st.h"
+#include <ctype.h>
#include "id.h"
-#include <ctype.h>
#include "vm.h"
+#include "objc.h"
extern st_table *rb_class_tbl;
@@ -56,10 +57,10 @@
return false;
}
-static VALUE
-rb_class_allocate_instance(VALUE klass, SEL sel)
+static void *
+rb_obj_imp_allocWithZone(void *rcv, SEL sel, void *zone)
{
- return rb_robject_allocate_instance(klass);
+ return (void *)rb_robject_allocate_instance((VALUE)rcv);
}
static BOOL
@@ -101,21 +102,21 @@
void
rb_define_object_special_methods(VALUE klass)
{
- rb_objc_define_method(*(VALUE *)klass, "alloc", rb_class_allocate_instance, 0);
- RCLASS_SET_VERSION(*(VALUE *)klass, (RCLASS_VERSION(*(VALUE *)klass) | RCLASS_HAS_ROBJECT_ALLOC));
- rb_objc_define_method(*(VALUE *)klass, "new", rb_class_new_instance_imp, -1);
- rb_objc_define_method(*(VALUE *)klass, "__new__", rb_class_new_instance_imp, -1);
+ RCLASS_SET_VERSION(*(VALUE *)klass,
+ (RCLASS_VERSION(*(VALUE *)klass) | RCLASS_HAS_ROBJECT_ALLOC));
+
+ rb_objc_define_method(*(VALUE *)klass, "new",
+ rb_class_new_instance_imp, -1);
+ rb_objc_define_method(*(VALUE *)klass, "__new__",
+ rb_class_new_instance_imp, -1);
rb_objc_define_method(klass, "dup", rb_obj_dup, 0);
rb_objc_define_method(klass, "initialize", rb_objc_init, 0);
rb_objc_define_method(klass, "initialize_copy", rb_obj_init_copy, 1);
- static SEL sel_isEqual = 0;
- if (sel_isEqual == 0) {
- sel_isEqual = sel_registerName("isEqual:");
- }
- class_addMethod((Class)klass, sel_isEqual, (IMP)rb_obj_imp_isEqual, "c@:@");
-
- class_addMethod((Class)klass, selInit, (IMP)rb_obj_imp_init, "@@:");
+ rb_objc_install_method(*(Class *)klass, selAllocWithZone,
+ (IMP)rb_obj_imp_allocWithZone);
+ rb_objc_install_method((Class)klass, selIsEqual, (IMP)rb_obj_imp_isEqual);
+ rb_objc_install_method((Class)klass, selInit, (IMP)rb_obj_imp_init);
}
static VALUE
Modified: MacRuby/branches/experimental/id.c
===================================================================
--- MacRuby/branches/experimental/id.c 2009-05-29 03:02:01 UTC (rev 1628)
+++ MacRuby/branches/experimental/id.c 2009-05-29 04:32:50 UTC (rev 1629)
@@ -61,6 +61,7 @@
selSucc = sel_registerName("succ");
selNot = sel_registerName("!");
selAlloc = sel_registerName("alloc");
+ selAllocWithZone = sel_registerName("allocWithZone:");
selInit = sel_registerName("init");
selInitialize = sel_registerName("initialize");
selInitialize2 = sel_registerName("initialize:");
@@ -89,6 +90,7 @@
selBackquote = sel_registerName("`:");
selMethodAdded = sel_registerName("method_added:");
selSingletonMethodAdded = sel_registerName("singleton_method_added:");
+ selIsEqual = sel_registerName("isEqual:");
cacheEach = rb_vm_get_call_cache(selEach);
#endif
Modified: MacRuby/branches/experimental/id.h
===================================================================
--- MacRuby/branches/experimental/id.h 2009-05-29 03:02:01 UTC (rev 1628)
+++ MacRuby/branches/experimental/id.h 2009-05-29 04:32:50 UTC (rev 1629)
@@ -71,6 +71,7 @@
extern SEL selSucc;
extern SEL selNot;
extern SEL selAlloc;
+extern SEL selAllocWithZone;
extern SEL selInit;
extern SEL selInitialize;
extern SEL selInitialize2;
@@ -98,6 +99,7 @@
extern SEL selBackquote;
extern SEL selMethodAdded;
extern SEL selSingletonMethodAdded;
+extern SEL selIsEqual;
extern ID idIncludedModules;
extern ID idIncludedInClasses;
extern ID idAncestors;
Modified: MacRuby/branches/experimental/objc.m
===================================================================
--- MacRuby/branches/experimental/objc.m 2009-05-29 03:02:01 UTC (rev 1628)
+++ MacRuby/branches/experimental/objc.m 2009-05-29 04:32:50 UTC (rev 1629)
@@ -417,7 +417,7 @@
}
}
-static void *
+static void
rb_objc_kvo_setter_imp(void *recv, SEL sel, void *value)
{
const char *selname;
@@ -432,8 +432,6 @@
rb_ivar_set((VALUE)recv, rb_intern(buf), value == NULL
? Qnil : OC2RB(value));
-
- return NULL; /* we explicitely return NULL because otherwise a special constant may stay on the stack and be returned to Objective-C, and do some very nasty crap, especially if called via -[performSelector:]. */
}
/*
Added: MacRuby/branches/experimental/spec/macruby/core/object_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/macruby/core/object_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/macruby/core/object_spec.rb 2009-05-29 04:32:50 UTC (rev 1629)
@@ -0,0 +1,26 @@
+require File.dirname(__FILE__) + "/../spec_helper"
+FixtureCompiler.require! "object"
+
+require File.join(FIXTURES, 'object')
+
+describe "A pure MacRuby Class" do
+=begin # TODO
+ it "can be instantiated from Objective-C, using +[new]" do
+ o = TestObject.testNewObject(TestObjectPureMacRuby)
+ o.class.should == TestObjectPureMacRuby
+ o.initialized?.should == true
+ end
+=end
+
+ it "can be instantiated from Objective-C, using +[alloc] and -[init]" do
+ o = TestObject.testAllocInitObject(TestObjectPureMacRuby)
+ o.class.should == TestObjectPureMacRuby
+ o.initialized?.should == true
+ end
+
+ it "can be instantiated from Objective-C, using +[allocWithZone:] and -[init]" do
+ o = TestObject.testAllocWithZoneInitObject(TestObjectPureMacRuby)
+ o.class.should == TestObjectPureMacRuby
+ o.initialized?.should == true
+ end
+end
Added: MacRuby/branches/experimental/spec/macruby/fixtures/object.m
===================================================================
--- MacRuby/branches/experimental/spec/macruby/fixtures/object.m (rev 0)
+++ MacRuby/branches/experimental/spec/macruby/fixtures/object.m 2009-05-29 04:32:50 UTC (rev 1629)
@@ -0,0 +1,25 @@
+#import <Foundation/Foundation.h>
+
+ at interface TestObject : NSObject
+ at end
+
+ at implementation TestObject
+
++ (id)testNewObject:(Class)k
+{
+ return [k new];
+}
+
++ (id)testAllocInitObject:(Class)k
+{
+ return [[k alloc] init];
+}
+
++ (id)testAllocWithZoneInitObject:(Class)k
+{
+ return [[k allocWithZone:NULL] init];
+}
+
+ at end
+
+void Init_object(void) {}
Added: MacRuby/branches/experimental/spec/macruby/fixtures/object.rb
===================================================================
--- MacRuby/branches/experimental/spec/macruby/fixtures/object.rb (rev 0)
+++ MacRuby/branches/experimental/spec/macruby/fixtures/object.rb 2009-05-29 04:32:50 UTC (rev 1629)
@@ -0,0 +1,6 @@
+class TestObjectPureMacRuby
+ def initialize
+ @initialized = true
+ end
+ def initialized?; @initialized; end
+end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090528/37d9dee4/attachment-0001.html>
More information about the macruby-changes
mailing list