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] Is this really a race condition?

2017-03-01 Thread Edward Connell via swift-users
Ahh! thank you. That makes sense. On Wed, Mar 1, 2017 at 3:29 PM, Guillaume Lessard < gless...@tffenterprises.com> wrote: > > > On Mar 1, 2017, at 3:21 PM, Edward Connell via swift-users < > swift-users@swift.org> wrote: > > > > The thread sanitizer on Linux is reporting that I have race conditio

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:

Re: [swift-users] Using withUnsafePointer on char arrays within C structs

2017-03-01 Thread Hooman Mehr via swift-users
Your co-worker needs to get passed the learning curve of these “unsafe” APIs and note that Swift arrays are complex data structures. &allZeros does not give you a pointer to a bunch of zero bytes, but a pointer to a struct that contains the private implementation details of allZeros array. Her

Re: [swift-users] Is this really a race condition?

2017-03-01 Thread Guillaume Lessard via swift-users
> On Mar 1, 2017, at 3:21 PM, Edward Connell via swift-users > wrote: > > The thread sanitizer on Linux is reporting that I have race conditions in > libswiftcore. I eliminated enough code down to this trivial example. Is there > really a race condition here or are these bogus errors? > >

Re: [swift-users] Is this really a race condition?

2017-03-01 Thread Dave Abrahams via swift-users
on Wed Mar 01 2017, Edward Connell wrote: > The thread sanitizer on Linux is reporting that I have race conditions in > libswiftcore. The only one we currently know about that's actually in libswiftcore is the one addressed by https://github.com/apple/swift/pull/7183 > I eliminated enough cod

Re: [swift-users] Using withUnsafePointer on char arrays within C structs

2017-03-01 Thread Russell Finn via swift-users
Thanks to Joe and Quinn for their answers. I have a related followup — a co-worker learning Swift wrote the following function: func allZerosUUID() -> String { var allZeros = [UInt8](repeating: 0, count: 32) return withUnsafePointer(to: &allZeros) { zerosPtr in retu

[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

[swift-users] Is this really a race condition?

2017-03-01 Thread Edward Connell via swift-users
The thread sanitizer on Linux is reporting that I have race conditions in libswiftcore. I eliminated enough code down to this trivial example. Is there really a race condition here or are these bogus errors? let count = 1000 var items = [[UInt8]?](repeating: nil, count: count) DispatchQueue.concu