Re: [swift-users] UnsafeMutableRawPointer to UnsafeMutablePointer: EXC_BAD_ACCESS on pointee

2017-09-26 Thread nyg nyg via swift-users
Thanks Braden for pointing out that toOpaque() was just a cast of c to UnsafeMutableRawPointer. And thanks Guillaume too, I now understand why my code doesn't and can't work. All this messing around has confused me greatly and I lost track of what I originally wanted to do :). At first, I wanted

Re: [swift-users] UnsafeMutableRawPointer to UnsafeMutablePointer: EXC_BAD_ACCESS on pointee

2017-09-24 Thread Guillaume Lessard via swift-users
[re-sending to the list, and elaborating] You are making the runtime use the first word of the referent as if it were the reference. The lowercase-c variable is a reference. rawPointer contains the same value, and points to the beginning of the object data. Your typecasting is telling the

Re: [swift-users] UnsafeMutableRawPointer to UnsafeMutablePointer: EXC_BAD_ACCESS on pointee

2017-09-23 Thread Braden Scothern via swift-users
After doing some testing I looked up the implementation and Unmanaged it is very misleading in how it is behaves and is implemented. When you call toOpaque() it returns the result of unsafeBitCast(_value, to: UnsafeRawPointer.self). _value is an internal field we can't directly access, in your

Re: [swift-users] UnsafeMutableRawPointer to UnsafeMutablePointer: EXC_BAD_ACCESS on pointee

2017-09-23 Thread Michael Ilseman via swift-users
> On Sep 23, 2017, at 3:44 AM, nyg nyg via swift-users > wrote: > > Hello all, > > I'm trying to get an UnsafeMutablePointer from an > UnsafeMutableRawPointer obtained using the Unmanaged structure: > > class C { var foo = 42, bar = "bar" } > let c = C() > > let

[swift-users] UnsafeMutableRawPointer to UnsafeMutablePointer: EXC_BAD_ACCESS on pointee

2017-09-23 Thread nyg nyg via swift-users
Hello all, I'm trying to get an UnsafeMutablePointer from an UnsafeMutableRawPointer obtained using the Unmanaged structure: class C { var foo = 42, bar = "bar" } let c = C() let rawPointer = Unmanaged.passUnretained(c).toOpaque() let pointer = rawPointer.bindMemory(to: C.self, capacity: 1)