[macruby-changes] [1736] MacRuby/branches/experimental
source_changes at macosforge.org
source_changes at macosforge.org
Thu Jun 4 17:48:49 PDT 2009
Revision: 1736
http://trac.macosforge.org/projects/ruby/changeset/1736
Author: lsansonetti at apple.com
Date: 2009-06-04 17:48:48 -0700 (Thu, 04 Jun 2009)
Log Message:
-----------
fixed lex_io_gets_fast() to deal better with scripts containing non-ASCII characters
Modified Paths:
--------------
MacRuby/branches/experimental/include/ruby/ruby.h
MacRuby/branches/experimental/parse.y
MacRuby/branches/experimental/string.c
Modified: MacRuby/branches/experimental/include/ruby/ruby.h
===================================================================
--- MacRuby/branches/experimental/include/ruby/ruby.h 2009-06-05 00:04:31 UTC (rev 1735)
+++ MacRuby/branches/experimental/include/ruby/ruby.h 2009-06-05 00:48:48 UTC (rev 1736)
@@ -357,6 +357,7 @@
VALUE rb_bytestring_new();
VALUE rb_bytestring_new_with_data(const UInt8 *buf, long size);
+VALUE rb_bytestring_new_with_cfdata(CFMutableDataRef data);
CFMutableDataRef rb_bytestring_wrapped_data(VALUE);
UInt8 *rb_bytestring_byte_pointer(VALUE);
VALUE rb_coerce_to_bytestring(VALUE);
Modified: MacRuby/branches/experimental/parse.y
===================================================================
--- MacRuby/branches/experimental/parse.y 2009-06-05 00:04:31 UTC (rev 1735)
+++ MacRuby/branches/experimental/parse.y 2009-06-05 00:48:48 UTC (rev 1736)
@@ -5143,10 +5143,21 @@
lex_gets_ptr = data->buflen;
}
+ // XXX In order to deal with files containing non-ASCII characters,
+ // returning a ByteString object seems to be better with the existing
+ // parsing infrastructure, notably because we deal with raw bytes
+#if 0
CFStringRef v = CFStringCreateWithBytes(NULL, data->buf + beg,
lex_gets_ptr - beg, kCFStringEncodingUTF8, false);
CFMakeCollectable(v);
return (VALUE)v;
+#else
+ CFDataRef cfdata = CFDataCreateWithBytesNoCopy(NULL, data->buf + beg,
+ lex_gets_ptr - beg, kCFAllocatorNull);
+ VALUE v = rb_bytestring_new_with_cfdata((CFMutableDataRef)cfdata);
+ CFMakeCollectable(cfdata);
+ return v;
+#endif
}
static VALUE
Modified: MacRuby/branches/experimental/string.c
===================================================================
--- MacRuby/branches/experimental/string.c 2009-06-05 00:04:31 UTC (rev 1735)
+++ MacRuby/branches/experimental/string.c 2009-06-05 00:48:48 UTC (rev 1736)
@@ -5305,11 +5305,16 @@
return CFDataGetMutableBytePtr(rb_bytestring_wrapped_data(bstr));
}
+static inline VALUE
+bytestring_alloc(void)
+{
+ return (VALUE)class_createInstance((Class)rb_cByteString, sizeof(void *));
+}
+
static VALUE
rb_bytestring_alloc(VALUE klass, SEL sel)
{
- VALUE bstr = (VALUE)class_createInstance((Class)rb_cByteString,
- sizeof(void *));
+ VALUE bstr = bytestring_alloc();
CFMutableDataRef data = CFDataCreateMutable(NULL, 0);
rb_bytestring_set_wrapped_data(bstr, data);
@@ -5334,6 +5339,14 @@
return v;
}
+VALUE
+rb_bytestring_new_with_cfdata(CFMutableDataRef data)
+{
+ VALUE v = bytestring_alloc();
+ rb_bytestring_set_wrapped_data(v, data);
+ return v;
+}
+
static void inline
rb_bytestring_copy_cfstring_content(VALUE bstr, CFStringRef str)
{
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090604/1cda4f63/attachment.html>
More information about the macruby-changes
mailing list