[macruby-changes] [2701] MacRuby/trunk/string.c
source_changes at macosforge.org
source_changes at macosforge.org
Thu Oct 1 14:14:52 PDT 2009
Revision: 2701
http://trac.macosforge.org/projects/ruby/changeset/2701
Author: lsansonetti at apple.com
Date: 2009-10-01 14:14:49 -0700 (Thu, 01 Oct 2009)
Log Message:
-----------
fixed bytestring promotion
Modified Paths:
--------------
MacRuby/trunk/string.c
Modified: MacRuby/trunk/string.c
===================================================================
--- MacRuby/trunk/string.c 2009-10-01 20:36:45 UTC (rev 2700)
+++ MacRuby/trunk/string.c 2009-10-01 21:14:49 UTC (rev 2701)
@@ -34,6 +34,11 @@
VALUE rb_cSymbol;
VALUE rb_cByteString;
+typedef struct {
+ struct RBasic basic;
+ CFMutableDataRef data;
+} rb_bstr_t;
+
VALUE
rb_str_freeze(VALUE str)
{
@@ -785,13 +790,17 @@
}
else {
// Promoting as bytestring!
- CFDataRef data = CFStringCreateExternalRepresentation(NULL, (CFStringRef)str,
- kCFStringEncodingUTF8, 0);
+ CFDataRef data = CFStringCreateExternalRepresentation(NULL,
+ (CFStringRef)str, kCFStringEncodingUTF8, 0);
assert(data != NULL);
CFMutableDataRef mdata = CFDataCreateMutableCopy(NULL, 0, data);
CFRelease(data);
- *(VALUE *)str = rb_cByteString;
- *(void **)((char *)str + sizeof(void *)) = (void *)mdata;
+
+ rb_bstr_t *bstr = (rb_bstr_t *)str;
+ bstr->basic.klass = rb_cByteString;
+ bstr->basic.flags = 0;
+ GC_WB(&bstr->data, mdata);
+
CFMakeCollectable(mdata);
}
}
@@ -5379,11 +5388,6 @@
#undef INSTALL_METHOD
-typedef struct {
- struct RBasic basic;
- CFMutableDataRef data;
-} rb_bstr_t;
-
CFMutableDataRef
rb_bytestring_wrapped_data(VALUE bstr)
{
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20091001/e5ebd0f3/attachment.html>
More information about the macruby-changes
mailing list