[macruby-changes] [203] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Wed May 21 12:34:54 PDT 2008


Revision: 203
          http://trac.macosforge.org/projects/ruby/changeset/203
Author:   lsansonetti at apple.com
Date:     2008-05-21 12:34:54 -0700 (Wed, 21 May 2008)

Log Message:
-----------
fixing a bunch of new regressions

Modified Paths:
--------------
    MacRuby/trunk/encoding.c
    MacRuby/trunk/io.c
    MacRuby/trunk/object.c
    MacRuby/trunk/sample/test.rb
    MacRuby/trunk/string.c
    MacRuby/trunk/test/ruby/test_array.rb
    MacRuby/trunk/test/ruby/test_hash.rb
    MacRuby/trunk/test/ruby/test_string.rb

Modified: MacRuby/trunk/encoding.c
===================================================================
--- MacRuby/trunk/encoding.c	2008-05-20 19:57:20 UTC (rev 202)
+++ MacRuby/trunk/encoding.c	2008-05-21 19:34:54 UTC (rev 203)
@@ -109,6 +109,8 @@
 rb_encoding *
 rb_to_encoding(VALUE v)
 {
+    if (TYPE(v) == T_STRING)
+	return rb_enc_find2(v);
     return rb_enc_to_enc_ptr(v);
 }
 
@@ -1018,8 +1020,14 @@
     CFStringEncoding e;
 
     str = (CFStringRef)StringValue(enc);
-    if (CFEqual(str, CFSTR("ASCII-8BIT")))
+    if (CFStringCompare(str, CFSTR("ASCII-8BIT"), 
+			kCFCompareCaseInsensitive) == 0) {
 	str = CFSTR("ASCII");
+    }
+    else if (CFStringCompare(str, CFSTR("SJIS"), 
+	     kCFCompareCaseInsensitive) == 0) {
+	str = CFSTR("Shift-JIS");
+    }
 
     e = CFStringConvertIANACharSetNameToEncoding(str);
     if (e == kCFStringEncodingInvalidId)

Modified: MacRuby/trunk/io.c
===================================================================
--- MacRuby/trunk/io.c	2008-05-20 19:57:20 UTC (rev 202)
+++ MacRuby/trunk/io.c	2008-05-21 19:34:54 UTC (rev 203)
@@ -1313,7 +1313,6 @@
 	    break;
 	}
     }
-    RSTRING_SYNC(str);
     return len - n;
 }
 
@@ -1330,6 +1329,7 @@
     str = rb_str_new(ptr, len);
     n = io_fread(str, 0, &of);
     MEMCPY(ptr, RSTRING_PTR(str), char, n);
+    RSTRING_SYNC(str);
     return n;
 }
 
@@ -1423,6 +1423,7 @@
 	ENC_CODERANGE_SET(str, cr);
     }
 #endif
+    RSTRING_SYNC(str);
     return str;
 }
 
@@ -1719,6 +1720,7 @@
         return Qnil;
     }
     rb_str_resize(str, n);
+    RSTRING_SYNC(str);
 
     return str;
 }

Modified: MacRuby/trunk/object.c
===================================================================
--- MacRuby/trunk/object.c	2008-05-20 19:57:20 UTC (rev 202)
+++ MacRuby/trunk/object.c	2008-05-21 19:34:54 UTC (rev 203)
@@ -812,6 +812,7 @@
     if (SPECIAL_CONST_P(obj)) {
 	if (!immediate_frozen_tbl) return Qfalse;
 	if (st_lookup(immediate_frozen_tbl, obj, 0)) return Qtrue;
+	return Qfalse;
     }
 #if WITH_OBJC
     if (rb_objc_is_non_native(obj)) {

Modified: MacRuby/trunk/sample/test.rb
===================================================================
--- MacRuby/trunk/sample/test.rb	2008-05-20 19:57:20 UTC (rev 202)
+++ MacRuby/trunk/sample/test.rb	2008-05-21 19:34:54 UTC (rev 203)
@@ -1869,7 +1869,7 @@
 
 def valid_syntax?(code, fname)
   p fname
-  #code.force_encoding("ascii-8bit")
+  code.force_encoding("ascii-8bit")
   code = code.sub(/\A(?:\s*\#.*$)*(\n)?/n) {
     "#$&#{"\n" if $1 && !$2}BEGIN{return true}\n"
   }

Modified: MacRuby/trunk/string.c
===================================================================
--- MacRuby/trunk/string.c	2008-05-20 19:57:20 UTC (rev 202)
+++ MacRuby/trunk/string.c	2008-05-21 19:34:54 UTC (rev 203)
@@ -194,13 +194,7 @@
 	if (bytestr != NULL) {
 	    CFStringReplaceAll((CFMutableStringRef)str, (CFStringRef)bytestr);
 	    CFRelease(bytestr);
-	    strptr = CFStringGetCStringPtr((CFStringRef)str, 0);
-	    if (strptr != NULL
-		&& ((const char *)dataptr == strptr
-		    || dataptr == NULL
-		    || memcmp((const char *)dataptr, strptr, datalen) == 0)) {
-		rb_str_cfdata_set(str, NULL);
-	    }
+	    rb_str_cfdata_set(str, NULL);
 	}
     }
 }
@@ -545,7 +539,7 @@
 		    rb_objc_str_set_bytestring(str, ptr, len);
 	    }
 	    else {
-		if (len < slen) {
+		if (slen == 0 || len < slen) {
 		    CFStringRef substr;
 
 		    substr = CFStringCreateWithBytes(NULL, (const UInt8 *)ptr, 
@@ -1552,25 +1546,59 @@
 rb_str_subseq(VALUE str, long beg, long len)
 {
 #if WITH_OBJC
-    long n = CFStringGetLength((CFStringRef)str);
+    CFDataRef data;
     CFMutableStringRef substr;
+    long n;
+
+#if 1
+    data = NULL;
+    n = CFStringGetLength((CFStringRef)str);
+#else
+    /* the world is not prepared for this yet */
+    data = (CFDataRef)rb_str_cfdata2(str);
+    if (data != NULL) {
+	n = CFDataGetLength(data);
+    }
+    else {
+        n = CFStringGetLength((CFStringRef)str);
+    }
+#endif
+
     if (beg < 0)
 	beg += n;
     if (beg > n || beg < 0)
 	return Qnil;
     if (beg + len > n)
 	return (VALUE)CFSTR("");
+
     substr = CFStringCreateMutable(NULL, 0);
-    if (len == 1) {
-	UniChar c = CFStringGetCharacterAtIndex((CFStringRef)str, beg);
-	CFStringAppendCharacters(substr, &c, 1);
+
+    if (data != NULL) {
+	const UInt8 *bytes;
+	CFMutableDataRef subdata;
+
+	bytes = CFDataGetBytePtr(data);
+	subdata = CFDataCreateMutable(NULL, 0);
+	CFDataAppendBytes(subdata, bytes + beg, len);
+	rb_str_cfdata_set((VALUE)substr, subdata);
+	CFMakeCollectable(subdata);
+	rb_gc_malloc_increase(sizeof(UInt8) * len);
+
+	RSTRING_SYNC(substr);
     }
     else {
-	UniChar *buffer = alloca(sizeof(UniChar) * len);
-	CFStringGetCharacters((CFStringRef)str, CFRangeMake(beg, len), buffer);
-	CFStringAppendCharacters(substr, buffer, len);
+	if (len == 1) {
+	    UniChar c = CFStringGetCharacterAtIndex((CFStringRef)str, beg);
+	    CFStringAppendCharacters(substr, &c, 1);
+	}
+	else {
+	    UniChar *buffer = alloca(sizeof(UniChar) * len);
+	    CFStringGetCharacters((CFStringRef)str, CFRangeMake(beg, len), 
+		buffer);
+	    CFStringAppendCharacters(substr, buffer, len);
+	}
+	rb_gc_malloc_increase(sizeof(UniChar) * len);
     }
-    rb_gc_malloc_increase(sizeof(UniChar) * len);
     CFMakeCollectable(substr);
     return (VALUE)substr;
 #else
@@ -6211,8 +6239,8 @@
     else {
       fs_set:
 	if (TYPE(spat) == T_STRING) {
+#if WITH_OBJC
 	    spat_string = Qtrue;
-#if WITH_OBJC
 	    if (RSTRING_CLEN(spat) == 1
 		&& CFStringGetCharacterAtIndex((CFStringRef)spat, 0) == ' ') {
 		awk_split = Qtrue;
@@ -6384,10 +6412,12 @@
 	}
     }
     if (clen > 0 && (!NIL_P(limit) || clen > beg || lim < 0)) {
-	if (clen == beg)
+	if (clen == beg) {
 	    tmp = rb_str_new5(str, 0, 0);
-	else
+	}
+	else {
 	    tmp = rb_str_subseq(str, beg, clen-beg);
+	}
 	rb_ary_push(result, tmp);
     }
     if (NIL_P(limit) && lim == 0) {
@@ -7952,7 +7982,24 @@
 {
     str_modifiable(str);
 #if WITH_OBJC
-    /* TODO */
+# if 0
+    CFDataRef data = rb_str_cfdata2(str);
+    if (data != NULL) {
+	CFStringRef substr;
+	CFStringEncoding *cfenc;
+
+	cfenc = rb_to_encoding(enc);
+	assert(cfenc != NULL);
+
+	substr = CFStringCreateFromExternalRepresentation(NULL, data, *cfenc);
+
+	if (substr) {
+	    CFStringReplaceAll((CFMutableStringRef)str, substr);
+	    CFRelease(substr);
+	    rb_str_cfdata_set(str, NULL);
+	}
+    }
+# endif
 #else
     rb_enc_associate(str, rb_to_encoding(enc));
 #endif

Modified: MacRuby/trunk/test/ruby/test_array.rb
===================================================================
--- MacRuby/trunk/test/ruby/test_array.rb	2008-05-20 19:57:20 UTC (rev 202)
+++ MacRuby/trunk/test/ruby/test_array.rb	2008-05-21 19:34:54 UTC (rev 203)
@@ -1134,7 +1134,10 @@
   end
 
   def test_sort_with_callcc
-    respond_to?(:callcc) or require 'continuation'
+    begin
+      respond_to?(:callcc) or require 'continuation'
+    rescue LoadError; return
+    end
     n = 1000
     cont = nil
     ary = (1..100).to_a
@@ -1291,7 +1294,7 @@
     assert_raise(SecurityError) do
       Thread.new do
         $SAFE = 4
-       a.shift
+        a.shift
       end.value
     end
   end

Modified: MacRuby/trunk/test/ruby/test_hash.rb
===================================================================
--- MacRuby/trunk/test/ruby/test_hash.rb	2008-05-20 19:57:20 UTC (rev 202)
+++ MacRuby/trunk/test/ruby/test_hash.rb	2008-05-21 19:34:54 UTC (rev 203)
@@ -1,5 +1,4 @@
 require 'test/unit'
-#require 'continuation'
 
 class TestHash < Test::Unit::TestCase
 
@@ -801,6 +800,10 @@
   end
 
   def test_callcc
+    begin
+      respond_to?(:callcc) or require 'continuation'
+    rescue LoadError; return
+    end
     h = {1=>2}
     c = nil
     f = false

Modified: MacRuby/trunk/test/ruby/test_string.rb
===================================================================
--- MacRuby/trunk/test/ruby/test_string.rb	2008-05-20 19:57:20 UTC (rev 202)
+++ MacRuby/trunk/test/ruby/test_string.rb	2008-05-21 19:34:54 UTC (rev 203)
@@ -1066,6 +1066,7 @@
     assert_equal([S("a"), S(""), S("b"), S("c"), S("")], S("a||b|c|").split(S('|'), -1))
 
     assert_equal([], "".split(//, 1))
+    assert_equal(["\0"], "\0".split(//))
   end
 
   def test_squeeze

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macruby-changes/attachments/20080521/a10889dd/attachment.htm 


More information about the macruby-changes mailing list