[macruby-changes] [2698] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Thu Oct 1 00:35:14 PDT 2009


Revision: 2698
          http://trac.macosforge.org/projects/ruby/changeset/2698
Author:   mattaimonetti at gmail.com
Date:     2009-10-01 00:35:10 -0700 (Thu, 01 Oct 2009)
Log Message:
-----------
another Array#pack bug fix by Ninh Bui(Phusion)

Modified Paths:
--------------
    MacRuby/trunk/pack.c
    MacRuby/trunk/spec/frozen/tags/macruby/core/array/pack_tags.txt

Modified: MacRuby/trunk/pack.c
===================================================================
--- MacRuby/trunk/pack.c	2009-10-01 02:25:40 UTC (rev 2697)
+++ MacRuby/trunk/pack.c	2009-10-01 07:35:10 UTC (rev 2698)
@@ -364,7 +364,7 @@
 #endif
 static const char toofew[] = "too few arguments";
 
-static void encodes(CFMutableDataRef,const char*,long,int);
+static void encodes(CFMutableDataRef,const char*,long,int,int);
 static void qpencode(CFMutableDataRef,VALUE,long);
 
 static unsigned long utf8_to_uv(const char*,long*);
@@ -910,6 +910,11 @@
 	    ptr = RSTRING_PTR(from);
 	    plen = RSTRING_LEN(from);
 
+	    if (len == 0 && type == 'm') {
+		encodes(data, ptr, plen, type, 0);
+		ptr += plen;
+		break;
+	    }
 	    if (len <= 2) {
 		len = 45;
 	    }
@@ -925,7 +930,7 @@
 		else {
 		    todo = plen;
 		}
-		encodes(data, ptr, todo, type);
+		encodes(data, ptr, todo, type, 1);
 		plen -= todo;
 		ptr += todo;
 	    }
@@ -1037,7 +1042,7 @@
 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
 
 static void
-encodes(CFMutableDataRef data, const char *s, long len, int type)
+encodes(CFMutableDataRef data, const char *s, long len, int type, int tail_lf)
 {
     char *buff = ALLOCA_N(char, len * 4 / 3 + 6);
     long i = 0;
@@ -1052,12 +1057,18 @@
 	padding = '=';
     }
     while (len >= 3) {
-	buff[i++] = trans[077 & (*s >> 2)];
-	buff[i++] = trans[077 & (((*s << 4) & 060) | ((s[1] >> 4) & 017))];
-	buff[i++] = trans[077 & (((s[1] << 2) & 074) | ((s[2] >> 6) & 03))];
-	buff[i++] = trans[077 & s[2]];
-	s += 3;
-	len -= 3;
+	while (len >= 3 && sizeof(buff) - i >= 4) {
+	    buff[i++] = trans[077 & (*s >> 2)];
+	    buff[i++] = trans[077 & (((*s << 4) & 060) | ((s[1] >> 4) & 017))];
+	    buff[i++] = trans[077 & (((s[1] << 2) & 074) | ((s[2] >> 6) & 03))];
+	    buff[i++] = trans[077 & s[2]];
+	    s += 3;
+	    len -= 3;
+	}
+	if (sizeof(buff) - i < 4) {
+	    CFDataAppendBytes(data, (const UInt8 *)buff, i);
+	    i = 0;
+	}
     }
     if (len == 2) {
 	buff[i++] = trans[077 & (*s >> 2)];
@@ -1071,10 +1082,11 @@
 	buff[i++] = padding;
 	buff[i++] = padding;
     }
-    buff[i++] = '\n';
+    if (tail_lf) {
+	buff[i++] = '\n';
+    }
     CFDataAppendBytes(data, (const UInt8 *)buff, i);
 }
-
 static const char hex_table[] = "0123456789ABCDEF";
 
 static void

Modified: MacRuby/trunk/spec/frozen/tags/macruby/core/array/pack_tags.txt
===================================================================
--- MacRuby/trunk/spec/frozen/tags/macruby/core/array/pack_tags.txt	2009-10-01 02:25:40 UTC (rev 2697)
+++ MacRuby/trunk/spec/frozen/tags/macruby/core/array/pack_tags.txt	2009-10-01 07:35:10 UTC (rev 2698)
@@ -8,7 +8,6 @@
 fails:Array#pack with format 'H' fills low-nibble of the last byte with 0 when count is odd even if pack argument has insufficient length
 fails:Array#pack with format 'M' ignores star parameter
 critical:Array#pack with format 'M' does not check whether the pack argument responds to #to_s before call #to_s
-fails:Array#pack with format 'm' does not append newline if line length parameter is 0
 fails:Array#pack with format 'U' returns a UTF-8 string
 fails:Array#pack with format 'm' ignores star parameter
 fails:Array#pack just ignores unknown format
\ No newline at end of file
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20091001/179cad53/attachment-0001.html>


More information about the macruby-changes mailing list