[macruby-changes] [195] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Thu May 15 17:11:06 PDT 2008


Revision: 195
          http://trac.macosforge.org/projects/ruby/changeset/195
Author:   lsansonetti at apple.com
Date:     2008-05-15 17:11:05 -0700 (Thu, 15 May 2008)

Log Message:
-----------
fixed long packing

Modified Paths:
--------------
    MacRuby/trunk/pack.c
    MacRuby/trunk/string.c

Modified: MacRuby/trunk/pack.c
===================================================================
--- MacRuby/trunk/pack.c	2008-05-15 22:04:42 UTC (rev 194)
+++ MacRuby/trunk/pack.c	2008-05-16 00:11:05 UTC (rev 195)
@@ -450,6 +450,10 @@
     pend = p + RSTRING_CLEN(fmt);
     res = rb_str_buf_new(0);
 
+#if WITH_OBJC
+    RSTRING_PTR(res); /* create bytestring */
+#endif
+
     items = RARRAY_LEN(ary);
     idx = 0;
 
@@ -510,7 +514,9 @@
 		StringValue(from);
 		ptr = RSTRING_CPTR(from);
 		plen = RSTRING_CLEN(from);
+#if !WITH_OBJC
 		OBJ_INFECT(res, from);
+#endif
 	    }
 
 	    if (p[-1] == '*')
@@ -1140,7 +1146,9 @@
 {
     VALUE s = rb_str_new(ptr, len);
 
+#if !WITH_OBJC
     OBJ_INFECT(s, str);
+#endif
     return s;
 }
 
@@ -1557,6 +1565,7 @@
 	    }
 	    PACK_ITEM_ADJUST();
 	    break;
+
 	  case 'L':
 	    PACK_LENGTH_ADJUST(unsigned long,4);
 	    while (len-- > 0) {
@@ -1577,6 +1586,7 @@
 	    }
 	    PACK_ITEM_ADJUST();
 	    break;
+
 	  case 'Q':
 	    PACK_LENGTH_ADJUST_SIZE(QUAD_SIZE);
 	    while (len-- > 0) {
@@ -1773,8 +1783,8 @@
 		}
 
 		rb_str_set_len(buf, total);
+		RSTRING_SYNC(buf);
 		UNPACK_PUSH(buf);
-		RSTRING_SYNC(buf);
 	    }
 	    break;
 
@@ -1824,8 +1834,8 @@
 		    }
 		}
 		rb_str_set_len(buf, ptr - RSTRING_PTR(buf));
+		RSTRING_SYNC(buf);
 		UNPACK_PUSH(buf);
-		RSTRING_SYNC(buf);
 	    }
 	    break;
 
@@ -1853,8 +1863,8 @@
 		    s++;
 		}
 		rb_str_set_len(buf, ptr - RSTRING_PTR(buf));
+		RSTRING_SYNC(buf);
 		UNPACK_PUSH(buf);
-		RSTRING_SYNC(buf);
 	    }
 	    break;
 

Modified: MacRuby/trunk/string.c
===================================================================
--- MacRuby/trunk/string.c	2008-05-15 22:04:42 UTC (rev 194)
+++ MacRuby/trunk/string.c	2008-05-16 00:11:05 UTC (rev 195)
@@ -1772,28 +1772,32 @@
 static void
 rb_objc_str_cat(VALUE str, const char *ptr, long len, int cfstring_encoding)
 {
-    long slen;
-    if (ptr[len] != '\0') {
-	char *p = alloca(len + 1);
-	memcpy(p, ptr, len);
-	p[len] = '\0';
-	ptr = p;
+    CFMutableDataRef data;
+
+    data = (CFMutableDataRef)rb_str_cfdata2(str);
+    if (data != NULL) {
+	CFDataAppendBytes(data, (const UInt8 *)ptr, len);
     }
-    slen = strlen(ptr);
-    if (slen == len) {
-	CFStringAppendCString((CFMutableStringRef)str, ptr, cfstring_encoding);
-    }
     else {
-#if 1
-	CFStringRef substr = CFStringCreateWithBytes(NULL, (const UInt8 *)ptr,
+	long slen;
+	if (ptr[len] != '\0') {
+	    char *p = alloca(len + 1);
+	    memcpy(p, ptr, len);
+	    p[len] = '\0';
+	    ptr = p;
+	}
+	slen = strlen(ptr);
+	if (slen == len) {
+	    CFStringAppendCString((CFMutableStringRef)str, ptr, 
+		cfstring_encoding);
+	}
+	else {
+	    CFStringRef substr = CFStringCreateWithBytes(NULL, 
+		(const UInt8 *)ptr,
 		len, cfstring_encoding, false);
-	CFStringAppend((CFMutableStringRef)str, substr);
-	CFRelease(substr);
-#else
-	CFMutableDataRef data;
-	data = (CFMutableDataRef)rb_str_cfdata(str);
-	CFDataAppendBytes(data, (const UInt8 *)ptr, len);
-#endif
+	    CFStringAppend((CFMutableStringRef)str, substr);
+	    CFRelease(substr);
+	}
     }
 }
 #endif
@@ -2421,6 +2425,11 @@
 	return rb_equal(str2, str1);
     }
 #if WITH_OBJC
+    len = RSTRING_CLEN(str1);
+    if (len != RSTRING_CLEN(str2))
+	return Qfalse;
+    if (rb_str_cfdata2(str1) != NULL || rb_str_cfdata2(str2) != NULL)
+	return memcmp(RSTRING_CPTR(str1), RSTRING_CPTR(str2), len) == 0;
     if (!rb_objc_str_is_pure(str2)) {
 	/* This is to work around a strange bug in CFEqual's objc 
 	 * dispatching.
@@ -2429,8 +2438,6 @@
 	str1 = str2;
 	str2 = tmp;
     }
-    if (RSTRING_CLEN(str1) == 0)
-	return RSTRING_CLEN(str2) == 0 ? Qtrue : Qfalse;
     if (CFEqual((CFTypeRef)str1, (CFTypeRef)str2))
 	return Qtrue;
 #else

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


More information about the macruby-changes mailing list