Permalink
Browse files

Merge pull request #43 from ferrous26/master

A couple of fixes for cfstr_to_str()
  • Loading branch information...
2 parents 161ed66 + 4ae1f11 commit 954b7829f65efdf27dfc32ded1efe7271b92816b @alloy alloy committed Jan 7, 2013
Showing with 3 additions and 5 deletions.
  1. +3 −5 ext/xcodeproj/xcodeproj_ext.c
@@ -21,20 +21,18 @@ static VALUE
cfstr_to_str(const void *cfstr) {
CFDataRef data = CFStringCreateExternalRepresentation(NULL, cfstr, kCFStringEncodingUTF8, 0);
assert(data != NULL);
- long len = (long)CFDataGetLength(data);
- char *buf = (char *)malloc(len+1);
- assert(buf != NULL);
- CFDataGetBytes(data, CFRangeMake(0, len), buf);
+ long len = (long)CFDataGetLength(data);
+ char *buf = (char *)CFDataGetBytePtr(data);
register VALUE str = rb_str_new(buf, len);
- free(buf);
// force UTF-8 encoding in Ruby 1.9+
ID forceEncodingId = rb_intern("force_encoding");
if (rb_respond_to(str, forceEncodingId)) {
rb_funcall(str, forceEncodingId, 1, rb_str_new("UTF-8", 5));
}
+ CFRelease(data);
return str;
}

0 comments on commit 954b782

Please sign in to comment.