-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Support internal null characters in NSString initializers [SR-2225] #496
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@xwu how are you building AppFoundation and Tests? Which snapshot are you using and Xcode version. I am having trouble building and testing as well after i update to master from 7/29? |
return CFStringCreateWithBytes(kCFAllocatorDefault, bytes, data.count, CFStringConvertNSStringEncodingToEncoding(encoding), true) | ||
}) else { return nil } | ||
|
||
guard let cf = CFStringCreateFromExternalRepresentation(kCFAllocatorDefault, data._cfObject, CFStringConvertNSStringEncodingToEncoding(encoding)) else { return nil } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The story of what happens on Darwin here is fairly complicated, which is probably why this was different in the first place, but it boils down to this:
- initWithData:(NSData *)data encoding:(NSStringEncoding)encoding {
return (id)CFStringCreateFromExternalRepresentation(kCFAllocatorDefault, (CFDataRef)data, CFStringConvertNSStringEncodingToEncoding(encoding));
}
So this change looks correct.
I debugged this a bit. I'm not finished yet, but I think the discrepancy has to do with the bridging happening after the CFString initialization. The CFString call returns the same result on both platforms (reading past the NULL). |
Wow, that's neat. For now, I'll create another PR with the change for |
@parkera I bet you've found it too, but things go awry during bridging because, if |
@DaveLiu888 Sorry for the delayed reply. I put off hacking on corelibs-foundation directly for a few days. Everything is now building fine for me with the 8/7 snapshot (although I did have to disable the NSString reflection test, which segfaults). |
I actually didn't get too much further on this (we've been busy getting all of those API changes landed). |
@xwu thanks for the update yea everything is working for me as well. 👍 |
@parkera OK, I will forge ahead and see how far I get with this. Since the solution is taking a different turn, I'll close this PR and open another one once I have something presentable. I'll roll in the |
Cool, thanks. |
This PR aims to fix a discrepancy in NSString between corelibs-foundation and Apple Foundation. Namely, initialization of an NSString from a byte sequence currently calls
CFStringCreateWithBytes(_:_:_:_:_:)
, which cannot accept null characters. Instead, switch to usingCFStringCreateFromExternalRepresentation(_:_:_:)
.Resolves SR-2225.
Note: I'm having trouble getting TestFoundation to compile in Xcode at the moment, but I've checked that previous builds of corelibs-foundation fail the test supplied, while Apple Foundation passes that test.