[macruby-changes] [1553] MacRuby/branches/experimental
source_changes at macosforge.org
source_changes at macosforge.org
Thu May 7 17:53:20 PDT 2009
Revision: 1553
http://trac.macosforge.org/projects/ruby/changeset/1553
Author: lsansonetti at apple.com
Date: 2009-05-07 17:53:20 -0700 (Thu, 07 May 2009)
Log Message:
-----------
make sure primitive classes can be subclassed again, fixed immutability check, added preliminary specs
Modified Paths:
--------------
MacRuby/branches/experimental/array.c
MacRuby/branches/experimental/hash.c
MacRuby/branches/experimental/set.c
MacRuby/branches/experimental/string.c
Added Paths:
-----------
MacRuby/branches/experimental/spec/macruby/array_spec.rb
MacRuby/branches/experimental/spec/macruby/hash_spec.rb
MacRuby/branches/experimental/spec/macruby/string_spec.rb
Modified: MacRuby/branches/experimental/array.c
===================================================================
--- MacRuby/branches/experimental/array.c 2009-05-07 22:05:46 UTC (rev 1552)
+++ MacRuby/branches/experimental/array.c 2009-05-08 00:53:20 UTC (rev 1553)
@@ -43,10 +43,8 @@
#else
mask = rb_objc_flag_get_mask((void *)ary);
#endif
- if (mask == 0) {
- if (RARRAY_IMMUTABLE(ary)) {
- mask |= FL_FREEZE;
- }
+ if (RARRAY_IMMUTABLE(ary)) {
+ mask |= FL_FREEZE;
}
if ((mask & FL_FREEZE) == FL_FREEZE) {
rb_raise(rb_eRuntimeError, "can't modify frozen/immutable array");
@@ -3504,9 +3502,12 @@
rb_objc_install_array_primitives(Class klass)
{
rb_objc_install_method2(klass, "count", (IMP)imp_rb_array_count);
- rb_objc_install_method2(klass, "objectAtIndex:", (IMP)imp_rb_array_objectAtIndex);
- rb_objc_install_method2(klass, "insertObject:atIndex:", (IMP)imp_rb_array_insertObjectAtIndex);
- rb_objc_install_method2(klass, "removeObjectAtIndex:", (IMP)imp_rb_array_removeObjectAtIndex);
+ rb_objc_install_method2(klass, "objectAtIndex:",
+ (IMP)imp_rb_array_objectAtIndex);
+ rb_objc_install_method2(klass, "insertObject:atIndex:",
+ (IMP)imp_rb_array_insertObjectAtIndex);
+ rb_objc_install_method2(klass, "removeObjectAtIndex:",
+ (IMP)imp_rb_array_removeObjectAtIndex);
rb_objc_install_method2(klass, "replaceObjectAtIndex:withObject:",
(IMP)imp_rb_array_replaceObjectAtIndexWithObject);
rb_objc_install_method2(klass, "replaceObjectsInRange:withObjects:count:",
@@ -3525,7 +3526,7 @@
method_getImplementation(m), method_getTypeEncoding(m));
#endif
- rb_define_alloc_func((VALUE)klass, ary_alloc);
+ rb_objc_define_method(*(VALUE *)klass, "alloc", ary_alloc, 0);
}
/* Arrays are ordered, integer-indexed collections of any object.
Modified: MacRuby/branches/experimental/hash.c
===================================================================
--- MacRuby/branches/experimental/hash.c 2009-05-07 22:05:46 UTC (rev 1552)
+++ MacRuby/branches/experimental/hash.c 2009-05-08 00:53:20 UTC (rev 1553)
@@ -230,15 +230,15 @@
#else
mask = rb_objc_flag_get_mask((const void *)hash);
#endif
- if (mask == 0) {
- if (RHASH_IMMUTABLE(hash)) {
- mask |= FL_FREEZE;
- }
+ if (RHASH_IMMUTABLE(hash)) {
+ mask |= FL_FREEZE;
}
- if ((mask & FL_FREEZE) == FL_FREEZE)
+ if ((mask & FL_FREEZE) == FL_FREEZE) {
rb_raise(rb_eRuntimeError, "can't modify frozen/immutable hash");
- if ((mask & FL_TAINT) == FL_TAINT && rb_safe_level() >= 4)
+ }
+ if ((mask & FL_TAINT) == FL_TAINT && rb_safe_level() >= 4) {
rb_raise(rb_eSecurityError, "Insecure: can't modify hash");
+ }
}
#define rb_hash_modify rb_hash_modify_check
@@ -2436,7 +2436,7 @@
rb_objc_install_method2(klass, "isEqual:", (IMP)imp_rb_hash_isEqual);
rb_objc_install_method2(klass, "containsObject:", (IMP)imp_rb_hash_containsObject);
- rb_define_alloc_func((VALUE)klass, hash_alloc);
+ rb_objc_define_method(*(VALUE *)klass, "alloc", hash_alloc, 0);
}
/*
Modified: MacRuby/branches/experimental/set.c
===================================================================
--- MacRuby/branches/experimental/set.c 2009-05-07 22:05:46 UTC (rev 1552)
+++ MacRuby/branches/experimental/set.c 2009-05-08 00:53:20 UTC (rev 1553)
@@ -21,15 +21,15 @@
{
long mask;
mask = rb_objc_flag_get_mask((void *)set);
- if (mask == 0) {
- if (RSET_IMMUTABLE(set)) {
- mask |= FL_FREEZE;
- }
+ if (RSET_IMMUTABLE(set)) {
+ mask |= FL_FREEZE;
}
- if ((mask & FL_FREEZE) == FL_FREEZE)
+ if ((mask & FL_FREEZE) == FL_FREEZE) {
rb_raise(rb_eRuntimeError, "can't modify frozen/immutable set");
- if ((mask & FL_TAINT) == FL_TAINT && rb_safe_level() >= 4)
+ }
+ if ((mask & FL_TAINT) == FL_TAINT && rb_safe_level() >= 4) {
rb_raise(rb_eSecurityError, "Insecure: can't modify set");
+ }
}
static VALUE
Added: MacRuby/branches/experimental/spec/macruby/array_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/macruby/array_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/macruby/array_spec.rb 2009-05-08 00:53:20 UTC (rev 1553)
@@ -0,0 +1,71 @@
+require File.dirname(__FILE__) + "/spec_helper"
+
+describe "The Array class" do
+ it "is an alias to NSMutableArray" do
+ Array.should == NSMutableArray
+ end
+
+ it "can be subclassed and later instantiated" do
+ k = Class.new(Array)
+ a = k.new
+ a.class.should == k
+ a << 42
+ a[0].should == 42
+ end
+end
+
+=begin
+describe "The NSArray class" do
+ it "can be subclassed and later instantiated" do
+ k = Class.new(NSArray)
+ a = k.new
+ a.class.should == k
+ a.size.should == 0
+ lambda { a << 42 }.should raise_error(RuntimeError)
+ end
+end
+=end
+
+describe "An Array object" do
+ it "is an instance of the Array/NSMutableArray class" do
+ [].class.should == Array
+ [].kind_of?(Array).should == true
+ [].instance_of?(Array).should == true
+ end
+
+ it "is mutable" do
+ a = []
+ a << 42
+ a[0].should == 42
+ end
+
+ it "can have a singleton class" do
+ a = []
+ def a.foo; 42; end
+ a.foo.should == 42
+ a << 42
+ a[0].should == 42
+ end
+end
+
+describe "An NSArray object" do
+ it "is an instance of the NSArray class" do
+ a = NSArray.array
+ a.class.should == NSArray
+ end
+
+ it "is immutable" do
+ a = NSArray.array
+ a.size.should == 0
+ lambda { a << 123 }.should raise_error(RuntimeError)
+ end
+
+=begin
+ it "can have a singleton class" do
+ a = NSArray.array
+ def a.foo; 42; end
+ a.foo.should == 42
+ lambda { a << 123 }.should raise_error(RuntimeError)
+ end
+=end
+end
Added: MacRuby/branches/experimental/spec/macruby/hash_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/macruby/hash_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/macruby/hash_spec.rb 2009-05-08 00:53:20 UTC (rev 1553)
@@ -0,0 +1,71 @@
+require File.dirname(__FILE__) + "/spec_helper"
+
+describe "The Hash class" do
+ it "is an alias to NSMutableDictionary" do
+ Hash.should == NSMutableDictionary
+ end
+
+ it "can be subclassed and later instantiated" do
+ k = Class.new(Hash)
+ a = k.new
+ a.class.should == k
+ a[42] = 123
+ a[42].should == 123
+ end
+end
+
+=begin
+describe "The NSDictionary class" do
+ it "can be subclassed and later instantiated" do
+ k = Class.new(NSDictionary)
+ a = k.new
+ a.class.should == k
+ a.size.should == 0
+ lambda { a[42] = 123 }.should raise_error(RuntimeError)
+ end
+end
+=end
+
+describe "An Hash object" do
+ it "is an instance of the Hash/NSMutableDictionary class" do
+ {}.class.should == Hash
+ {}.kind_of?(Hash).should == true
+ {}.instance_of?(Hash).should == true
+ end
+
+ it "is mutable" do
+ a = {}
+ a[42] = 123
+ a[42].should == 123
+ end
+
+ it "can have a singleton class" do
+ a = {}
+ def a.foo; 42; end
+ a.foo.should == 42
+ a[42] = 123
+ a[42].should == 123
+ end
+end
+
+describe "An NSDictionary object" do
+ it "is an instance of the NSDictionary class" do
+ a = NSDictionary.dictionary
+ a.class.should == NSDictionary
+ end
+
+ it "is immutable" do
+ a = NSDictionary.dictionary
+ a.size.should == 0
+ lambda { a[42] = 123 }.should raise_error(RuntimeError)
+ end
+
+=begin
+ it "can have a singleton class" do
+ a = NSDictionary.array
+ def a.foo; 42; end
+ a.foo.should == 42
+ lambda { a[42] = 123 }.should raise_error(RuntimeError)
+ end
+=end
+end
Added: MacRuby/branches/experimental/spec/macruby/string_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/macruby/string_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/macruby/string_spec.rb 2009-05-08 00:53:20 UTC (rev 1553)
@@ -0,0 +1,71 @@
+require File.dirname(__FILE__) + "/spec_helper"
+
+describe "The String class" do
+ it "is an alias to NSMutableString" do
+ String.should == NSMutableString
+ end
+
+ it "can be subclassed and later instantiated" do
+ k = Class.new(String)
+ a = k.new
+ a.class.should == k
+ a << 'foo'
+ a.should == 'foo'
+ end
+end
+
+=begin
+describe "The NSString class" do
+ it "can be subclassed and later instantiated" do
+ k = Class.new(NSString)
+ a = k.new
+ a.class.should == k
+ a.size.should == 0
+ lambda { a << 'foo' }.should raise_error(RuntimeError)
+ end
+end
+=end
+
+describe "An String object" do
+ it "is an instance of the String/NSMutableString class" do
+ ''.class.should == String
+ ''.kind_of?(String).should == true
+ ''.instance_of?(String).should == true
+ end
+
+ it "is mutable" do
+ a = ''
+ a << 'foo'
+ a.should == 'foo'
+ end
+
+ it "can have a singleton class" do
+ a = ''
+ def a.foo; 42; end
+ a.foo.should == 42
+ a << 'foo'
+ a.should == 'foo'
+ end
+end
+
+describe "An NSString object" do
+ it "is an instance of the NSString class" do
+ a = NSString.string
+ a.class.should == NSString
+ end
+
+ it "is immutable" do
+ a = NSString.string
+ a.size.should == 0
+ lambda { a << 'foo' }.should raise_error(RuntimeError)
+ end
+
+=begin
+ it "can have a singleton class" do
+ a = NSString.string
+ def a.foo; 42; end
+ a.foo.should == 42
+ lambda { a << 'foo' }.should raise_error(RuntimeError)
+ end
+=end
+end
Modified: MacRuby/branches/experimental/string.c
===================================================================
--- MacRuby/branches/experimental/string.c 2009-05-07 22:05:46 UTC (rev 1552)
+++ MacRuby/branches/experimental/string.c 2009-05-08 00:53:20 UTC (rev 1553)
@@ -807,6 +807,7 @@
rb_str_append(VALUE str, VALUE str2)
{
StringValue(str2);
+ rb_str_modify(str);
return rb_str_buf_append(str, str2);
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090507/3a9f3929/attachment-0001.html>
More information about the macruby-changes
mailing list