[macruby-changes] [2595] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Mon Sep 21 18:25:22 PDT 2009


Revision: 2595
          http://trac.macosforge.org/projects/ruby/changeset/2595
Author:   lsansonetti at apple.com
Date:     2009-09-21 18:25:20 -0700 (Mon, 21 Sep 2009)
Log Message:
-----------
fixed the parsing of bytestrings

Modified Paths:
--------------
    MacRuby/trunk/TODO
    MacRuby/trunk/parse.y

Modified: MacRuby/trunk/TODO
===================================================================
--- MacRuby/trunk/TODO	2009-09-21 22:02:20 UTC (rev 2594)
+++ MacRuby/trunk/TODO	2009-09-22 01:25:20 UTC (rev 2595)
@@ -8,7 +8,7 @@
   [X] fix YAML deserialization of booleans
   [ ] fix ~/.gemrc
   [X] `source --add http://gems.github.com' crashes (outside gdb)
-  [ ] `install rest-client' prints parsing errors (encoding problem in thor.gemspec)
+  [X] `install rest-client' prints parsing errors (encoding problem in thor.gemspec)
   [ ] `gem uninstall bacon' doesn't work (Unknown gem bacon >= 0)
   [ ] `macgem install rails --version 2.3.2' crashes (MAX_DISPATCH_ARGS assertion)
 [X] rewrite load.c (needed for RubyGems' #require hack)

Modified: MacRuby/trunk/parse.y
===================================================================
--- MacRuby/trunk/parse.y	2009-09-21 22:02:20 UTC (rev 2594)
+++ MacRuby/trunk/parse.y	2009-09-22 01:25:20 UTC (rev 2595)
@@ -5066,21 +5066,47 @@
 }
 #endif /* !RIPPER */
 
+#ifndef RIPPER
 static VALUE
+lex_get_bstr(struct parser_params *parser, VALUE s)
+{
+    long beg = 0, len; 
+    const long n = rb_bytestring_length(s);
+    if (lex_gets_ptr > 0) {
+	if (n == lex_gets_ptr) {
+	    return Qnil;
+	}
+	beg += lex_gets_ptr;
+    }
+
+    UInt8 *data = rb_bytestring_byte_pointer(s);
+    UInt8 *pos = memchr(data + beg, '\n', n - beg);
+    if (pos != NULL) {
+	lex_gets_ptr = pos - data + 1;
+	len = pos - data - beg;	
+    }
+    else {
+	lex_gets_ptr = n;
+	len = lex_gets_ptr - beg;	
+    }
+
+    return rb_bytestring_new_with_data(data + beg, lex_gets_ptr - beg);
+}
+#endif
+
+static VALUE
 lex_get_str(struct parser_params *parser, VALUE s)
 {
-    long beg, len, n;
-    CFRange search_range;  
-    VALUE v;
- 
-    beg = 0; 
-    n = CFStringGetLength((CFStringRef)s);
+    long beg = 0, len; 
+    const long n = CFStringGetLength((CFStringRef)s);
     if (lex_gets_ptr > 0) {
 	if (n == lex_gets_ptr) {
 	    return Qnil;
 	}
 	beg += lex_gets_ptr;
     }
+
+    CFRange search_range;  
     if (CFStringFindCharacterFromSet((CFStringRef)s, 
 		CFCharacterSetGetPredefined(kCFCharacterSetNewline),
 		CFRangeMake(beg, n - beg),
@@ -5093,10 +5119,11 @@
 	lex_gets_ptr = n;
 	len = lex_gets_ptr - beg;	
     }
-    v = (VALUE)CFStringCreateWithSubstring(NULL, (CFStringRef)s, 
-	CFRangeMake(beg, lex_gets_ptr - beg));
-    CFMakeCollectable((CFTypeRef)v);
-    return v;
+
+    CFStringRef subs = CFStringCreateWithSubstring(NULL, (CFStringRef)s, 
+	    CFRangeMake(beg, lex_gets_ptr - beg));
+    CFMakeCollectable(subs);
+    return (VALUE)subs;
 }
 
 static VALUE
@@ -5128,7 +5155,7 @@
     volatile VALUE tmp;
 
     Data_Get_Struct(vparser, struct parser_params, parser);
-    lex_gets = lex_get_str;
+    lex_gets = CLASS_OF(s) == rb_cByteString ? lex_get_bstr : lex_get_str;
     lex_gets_ptr = 0;
     GC_WB(&lex_input, s);
     lex_pbeg = lex_p = lex_pend = 0;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090921/82f31b2e/attachment.html>


More information about the macruby-changes mailing list