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

source_changes at macosforge.org source_changes at macosforge.org
Thu Jun 4 22:58:34 PDT 2009


Revision: 1746
          http://trac.macosforge.org/projects/ruby/changeset/1746
Author:   lsansonetti at apple.com
Date:     2009-06-04 22:58:34 -0700 (Thu, 04 Jun 2009)
Log Message:
-----------
in many String methods returning new copies, make sure we return subclass instances when called on a subclass

Modified Paths:
--------------
    MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/center_tags.txt
    MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/chomp_tags.txt
    MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/chop_tags.txt
    MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/delete_tags.txt
    MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/downcase_tags.txt
    MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/gsub_tags.txt
    MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/ljust_tags.txt
    MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/rjust_tags.txt
    MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/squeeze_tags.txt
    MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/sub_tags.txt
    MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/swapcase_tags.txt
    MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/tr_s_tags.txt
    MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/tr_tags.txt
    MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/upcase_tags.txt
    MacRuby/branches/experimental/string.c

Modified: MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/center_tags.txt
===================================================================
--- MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/center_tags.txt	2009-06-05 05:54:01 UTC (rev 1745)
+++ MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/center_tags.txt	2009-06-05 05:58:34 UTC (rev 1746)
@@ -2,4 +2,3 @@
 fails:String#center with length, padding returns a new string of specified length with self centered and padded with padstr
 fails:String#center with length, padding calls #to_str to convert padstr to a String
 fails:String#center with length, padding raises a TypeError when padstr can't be converted to a string
-fails:String#center with length, padding returns subclass instances when called on subclasses

Modified: MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/chomp_tags.txt
===================================================================
--- MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/chomp_tags.txt	2009-06-05 05:54:01 UTC (rev 1745)
+++ MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/chomp_tags.txt	2009-06-05 05:58:34 UTC (rev 1746)
@@ -2,6 +2,5 @@
 fails:String#chomp with separator removes carriage return (except \r) chars multiple times when separator is an empty string
 fails:String#chomp with separator taints result when self is tainted
 fails:String#chomp with separator raises a TypeError if separator can't be converted to a string
-fails:String#chomp with separator returns subclass instances when called on a subclass
 fails:String#chomp! with separator modifies self in place and returns self
-fails:String#chomp! with separator raises a RuntimeError when self is frozen
\ No newline at end of file
+fails:String#chomp! with separator raises a RuntimeError when self is frozen

Modified: MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/chop_tags.txt
===================================================================
--- MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/chop_tags.txt	2009-06-05 05:54:01 UTC (rev 1745)
+++ MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/chop_tags.txt	2009-06-05 05:58:34 UTC (rev 1746)
@@ -1,4 +1,3 @@
 fails:String#chop returns a new string with the last character removed
-fails:String#chop returns subclass instances when called on a subclass
 fails:String#chop! raises a TypeError when self is frozen
 fails:String#chop! raises a RuntimeError when self is frozen

Modified: MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/delete_tags.txt
===================================================================
--- MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/delete_tags.txt	2009-06-05 05:54:01 UTC (rev 1745)
+++ MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/delete_tags.txt	2009-06-05 05:58:34 UTC (rev 1746)
@@ -2,5 +2,4 @@
 fails:String#delete deletes all chars in a sequence
 fails:String#delete taints result when self is tainted
 fails:String#delete raises a TypeError when one set arg can't be converted to a string
-fails:String#delete returns subclass instances when called on a subclass
 fails:String#delete! raises a TypeError when self is frozen

Modified: MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/downcase_tags.txt
===================================================================
--- MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/downcase_tags.txt	2009-06-05 05:54:01 UTC (rev 1745)
+++ MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/downcase_tags.txt	2009-06-05 05:58:34 UTC (rev 1746)
@@ -1,2 +1 @@
 fails:String#downcase is locale insensitive (only replaces A-Z)
-fails:String#downcase returns a subclass instance for subclasses

Modified: MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/gsub_tags.txt
===================================================================
--- MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/gsub_tags.txt	2009-06-05 05:54:01 UTC (rev 1745)
+++ MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/gsub_tags.txt	2009-06-05 05:58:34 UTC (rev 1746)
@@ -4,7 +4,6 @@
 fails:String#gsub with pattern and replacement tries to convert pattern to a string using to_str
 fails:String#gsub with pattern and replacement raises a TypeError when pattern can't be converted to a string
 fails:String#gsub with pattern and replacement raises a TypeError when replacement can't be converted to a string
-fails:String#gsub with pattern and replacement returns subclass instances when called on a subclass
 fails:String#gsub with pattern and block raises a RuntimeError if the string is modified while substituting
 fails:String#gsub with pattern and block untrusts the result if the original string or replacement is untrusted
 fails:String#gsub! with pattern and replacement taints self if replacement is tainted
@@ -13,4 +12,4 @@
 fails:String#gsub! with pattern and block taints self if block's result is tainted
 fails:String#gsub! with pattern and block untrusts self if block's result is untrusted
 fails:String#gsub! with pattern and replacement raises a RuntimeError when self is frozen
-fails:String#gsub! with pattern and block raises a RuntimeError when self is frozen
\ No newline at end of file
+fails:String#gsub! with pattern and block raises a RuntimeError when self is frozen

Modified: MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/ljust_tags.txt
===================================================================
--- MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/ljust_tags.txt	2009-06-05 05:54:01 UTC (rev 1745)
+++ MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/ljust_tags.txt	2009-06-05 05:58:34 UTC (rev 1746)
@@ -2,4 +2,3 @@
 fails:String#ljust with length, padding returns a new string of specified length with self left justified and padded with padstr
 fails:String#ljust with length, padding tries to convert padstr to a string using to_str
 fails:String#ljust with length, padding raises a TypeError when padstr can't be converted
-fails:String#ljust with length, padding returns subclass instances when called on subclasses

Modified: MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/rjust_tags.txt
===================================================================
--- MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/rjust_tags.txt	2009-06-05 05:54:01 UTC (rev 1745)
+++ MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/rjust_tags.txt	2009-06-05 05:58:34 UTC (rev 1746)
@@ -2,4 +2,3 @@
 fails:String#rjust with length, padding returns a new string of specified length with self right justified and padded with padstr
 fails:String#rjust with length, padding tries to convert padstr to a string using to_str
 fails:String#rjust with length, padding raises a TypeError when padstr can't be converted
-fails:String#rjust with length, padding returns subclass instances when called on subclasses

Modified: MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/squeeze_tags.txt
===================================================================
--- MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/squeeze_tags.txt	2009-06-05 05:54:01 UTC (rev 1745)
+++ MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/squeeze_tags.txt	2009-06-05 05:58:34 UTC (rev 1746)
@@ -2,5 +2,4 @@
 fails:String#squeeze squeezes all chars in a sequence
 fails:String#squeeze taints the result when self is tainted
 fails:String#squeeze raises a TypeError when one set arg can't be converted to a string
-fails:String#squeeze returns subclass instances when called on a subclass
 fails:String#squeeze! raises a TypeError when self is frozen

Modified: MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/sub_tags.txt
===================================================================
--- MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/sub_tags.txt	2009-06-05 05:54:01 UTC (rev 1745)
+++ MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/sub_tags.txt	2009-06-05 05:58:34 UTC (rev 1746)
@@ -3,7 +3,6 @@
 fails:String#sub with pattern, replacement tries to convert pattern to a string using to_str
 fails:String#sub with pattern, replacement raises a TypeError when pattern can't be converted to a string
 fails:String#sub with pattern, replacement raises a TypeError when replacement can't be converted to a string
-fails:String#sub with pattern, replacement returns subclass instances when called on a subclass
 fails:String#sub with pattern and block returns a copy of self with the first occurrences of pattern replaced with the block's return value
 fails:String#sub with pattern and block taints the result if the original string or replacement is tainted
 fails:String#sub! with pattern, replacement taints self if replacement is tainted

Modified: MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/swapcase_tags.txt
===================================================================
--- MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/swapcase_tags.txt	2009-06-05 05:54:01 UTC (rev 1745)
+++ MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/swapcase_tags.txt	2009-06-05 05:58:34 UTC (rev 1746)
@@ -1,2 +1 @@
 fails:String#swapcase is locale insensitive (only upcases a-z and only downcases A-Z)
-fails:String#swapcase returns subclass instances when called on a subclass

Modified: MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/tr_s_tags.txt
===================================================================
--- MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/tr_s_tags.txt	2009-06-05 05:54:01 UTC (rev 1745)
+++ MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/tr_s_tags.txt	2009-06-05 05:58:34 UTC (rev 1746)
@@ -1,5 +1,4 @@
 fails:String#tr_s accepts c1-c2 notation to denote ranges of characters
 fails:String#tr_s translates chars not in from_string when it starts with a ^
-fails:String#tr_s returns subclass instances when called on a subclass
 fails:String#tr_s taints the result when self is tainted
 fails:String#tr_s! raises a TypeError if self is frozen

Modified: MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/tr_tags.txt
===================================================================
--- MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/tr_tags.txt	2009-06-05 05:54:01 UTC (rev 1745)
+++ MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/tr_tags.txt	2009-06-05 05:58:34 UTC (rev 1746)
@@ -1,7 +1,6 @@
 fails:String#tr accepts c1-c2 notation to denote ranges of characters
 fails:String#tr pads to_str with its last char if it is shorter than from_string
 fails:String#tr translates chars not in from_string when it starts with a ^
-fails:String#tr returns subclass instances when called on a subclass
 fails:String#tr taints the result when self is tainted
 fails:String#tr! modifies self in place
 fails:String#tr! raises a TypeError if self is frozen

Modified: MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/upcase_tags.txt
===================================================================
--- MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/upcase_tags.txt	2009-06-05 05:54:01 UTC (rev 1745)
+++ MacRuby/branches/experimental/spec/frozen/tags/macruby/core/string/upcase_tags.txt	2009-06-05 05:58:34 UTC (rev 1746)
@@ -1,2 +1 @@
 fails:String#upcase is locale insensitive (only replaces a-z)
-fails:String#upcase returns a subclass instance for subclasses

Modified: MacRuby/branches/experimental/string.c
===================================================================
--- MacRuby/branches/experimental/string.c	2009-06-05 05:54:01 UTC (rev 1745)
+++ MacRuby/branches/experimental/string.c	2009-06-05 05:58:34 UTC (rev 1746)
@@ -59,19 +59,23 @@
     }
 }
 
-static inline VALUE
-str_alloc(VALUE klass)
+static inline void
+str_change_class(VALUE str, VALUE klass)
 {
-    VALUE str;
-
-    str = (VALUE)CFStringCreateMutable(NULL, 0);
     if (klass != 0 
 	&& klass != rb_cNSString 
 	&& klass != rb_cNSMutableString
 	&& klass != rb_cSymbol
 	&& klass != rb_cByteString) {
-	*(Class *)str = (Class)klass;
+	*(VALUE *)str = (VALUE)klass;
     }
+}
+
+static inline VALUE
+str_alloc(VALUE klass)
+{
+    VALUE str = (VALUE)CFStringCreateMutable(NULL, 0);
+    str_change_class(str, klass);
     CFMakeCollectable((CFTypeRef)str);
 
     return (VALUE)str;
@@ -203,18 +207,18 @@
     return str;
 }
 
-static VALUE
+static inline VALUE
 str_new3(VALUE klass, VALUE str)
 {
-    return rb_str_dup(str);
+    VALUE str2 = rb_str_dup(str);
+    str_change_class(str2, klass);
+    return str2;
 }
 
 VALUE
 rb_str_new3(VALUE str)
 {
-    VALUE str2 = str_new3(rb_obj_class(str), str);
-
-    return str2;
+    return str_new3(rb_obj_class(str), str);
 }
 
 VALUE
@@ -1970,7 +1974,7 @@
 static VALUE
 rb_str_sub(VALUE str, SEL sel, int argc, VALUE *argv)
 {
-    str = rb_str_dup(str);
+    str = rb_str_new3(str);
     rb_str_sub_bang(str, 0, argc, argv);
     return str;
 }
@@ -2013,7 +2017,7 @@
 	if (bang) {
 	    return Qnil;	/* no match, no substitution */
 	}
-	return rb_str_dup(str);
+	return rb_str_new3(str);
     }
 
     dest = rb_str_new5(str, NULL, 0);
@@ -2694,7 +2698,7 @@
 static VALUE
 rb_str_upcase(VALUE str, SEL sel)
 {
-    str = rb_str_dup(str);
+    str = rb_str_new3(str);
     rb_str_upcase_bang(str, 0);
     return str;
 }
@@ -2738,7 +2742,7 @@
 static VALUE
 rb_str_downcase(VALUE str, SEL sel)
 {
-    str = rb_str_dup(str);
+    str = rb_str_new3(str);
     rb_str_downcase_bang(str, 0);
     return str;
 }
@@ -2884,7 +2888,7 @@
 static VALUE
 rb_str_swapcase(VALUE str, SEL sel)
 {
-    str = rb_str_dup(str);
+    str = rb_str_new3(str);
     rb_str_swapcase_bang(str, 0);
     return str;
 }
@@ -3273,7 +3277,7 @@
 static VALUE
 rb_str_tr(VALUE str, SEL sel, VALUE src, VALUE repl)
 {
-    str = rb_str_dup(str);
+    str = rb_str_new3(str);
     rb_str_tr_bang(str, 0, src, repl);
     return str;
 }
@@ -3331,7 +3335,7 @@
 static VALUE
 rb_str_delete(VALUE str, SEL sel, int argc, VALUE *argv)
 {
-    str = rb_str_dup(str);
+    str = rb_str_new3(str);
     rb_str_delete_bang(str, 0, argc, argv);
     return str;
 }
@@ -3398,7 +3402,7 @@
 static VALUE
 rb_str_squeeze(VALUE str, SEL sel, int argc, VALUE *argv)
 {
-    str = rb_str_dup(str);
+    str = rb_str_new3(str);
     rb_str_squeeze_bang(str, 0, argc, argv);
     return str;
 }
@@ -3435,7 +3439,7 @@
 static VALUE
 rb_str_tr_s(VALUE str, SEL sel, VALUE src, VALUE repl)
 {
-    str = rb_str_dup(str);
+    str = rb_str_new3(str);
     rb_str_tr_s_bang(str, 0, src, repl);
     return str;
 }
@@ -3978,7 +3982,7 @@
 static VALUE
 rb_str_chop(VALUE str, SEL sel)
 {
-    VALUE str2 = rb_str_dup(str);
+    VALUE str2 = rb_str_new3(str);
     rb_str_chop_bang(str2, 0);
     return str2;
 }
@@ -4063,7 +4067,7 @@
 static VALUE
 rb_str_chomp(VALUE str, SEL sel, int argc, VALUE *argv)
 {
-    str = rb_str_dup(str);
+    str = rb_str_new3(str);
     rb_str_chomp_bang(str, 0, argc, argv);
     return str;
 }
@@ -4567,7 +4571,7 @@
     width = NUM2LONG(w);
     n = CFStringGetLength((CFStringRef)str);
    
-    str = rb_str_dup(str);
+    str = rb_str_new3(str);
     if (width < 0 || width <= n) {
 	return str;
     }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090604/3785a19f/attachment-0001.html>


More information about the macruby-changes mailing list