Re: [swift-users] Ugliness bridging Swift String to char *

2017-03-06 Thread Andrew Trick via swift-users
> On Mar 1, 2017, at 7:08 PM, Kenny Leung via swift-users > wrote: > > Hi Jordan. > > Thanks for the lengthy answer. > >> On Mar 1, 2017, at 6:21 PM, Jordan Rose > > wrote: >> >> Hey, Kenny. The const vs non-const part is important, since both the >> implicit c

Re: [swift-users] Ugliness bridging Swift String to char *

2017-03-06 Thread Guillaume Lessard via swift-users
> On Mar 6, 2017, at 12:28 AM, Kenny Leung via swift-users > wrote: > > Follow-up on this: > > The StaticString solution doesn’t work: > > let separator: StaticString = “|” > opt.fieldSep = UnsafeMutablePointer(mutating: separator.utf8start) > > … because utf8start returns UnsafePointer, and

Re: [swift-users] Ugliness bridging Swift String to char *

2017-03-05 Thread Kenny Leung via swift-users
Follow-up on this: The StaticString solution doesn’t work: let separator: StaticString = “|” opt.fieldSep = UnsafeMutablePointer(mutating: separator.utf8start) … because utf8start returns UnsafePointer, and fieldSep is actually UnsafeMutablePointer. There doesn’t seem to be any way to convert

Re: [swift-users] Ugliness bridging Swift String to char *

2017-03-01 Thread Kenny Leung via swift-users
> On Mar 1, 2017, at 7:08 PM, Kenny Leung via swift-users > wrote: > > If it’s “making very few assumptions”, I would think that, for safety’s sake, > functions that return a pointer would always be optional, forcing the user to > deal with any possible null pointer returns. > Talking mysel

Re: [swift-users] Ugliness bridging Swift String to char *

2017-03-01 Thread Kenny Leung via swift-users
Hi Jordan. Thanks for the lengthy answer. > On Mar 1, 2017, at 6:21 PM, Jordan Rose wrote: > > Hey, Kenny. The const vs non-const part is important, since both the implicit > conversion and cString(using:) are allowed to return a pointer to the > internal data being used by the String, and mo

Re: [swift-users] Ugliness bridging Swift String to char *

2017-03-01 Thread Jordan Rose via swift-users
> On Mar 1, 2017, at 14:23, Kenny Leung via swift-users > wrote: > > Hi All. > > Swift automatically bridges String to char * when calling C functions. For > instance, strlen gets translated as: > > public func strlen(_ __s: UnsafePointer!) -> UInt > > I can call it from Swift like this:

[swift-users] Ugliness bridging Swift String to char *

2017-03-01 Thread Kenny Leung via swift-users
Hi All. Swift automatically bridges String to char * when calling C functions. For instance, strlen gets translated as: public func strlen(_ __s: UnsafePointer!) -> UInt I can call it from Swift like this: strlen("|") I’m But, I’m working with a C struct containing a char *: publ