Unmanaged API flip flop


(Kyle Jessup) #1

I have this code which uses Unmanaged and the API seems to vary depending on if I am using a 3.0 Preview or a development snapshot. I see it now when trying the June 13th/27th preview vs June 20th snapshot.

class MyClass {}

let holderObject = MyClass()

#if FLIP // works with PREVIEW
  let leakyObject = UnsafeMutablePointer<Void>(OpaquePointer(bitPattern: Unmanaged.passRetained(holderObject)))
#else // works with SNAPSHOT
  let leakyObject = Unmanaged.passRetained(holderObject).toOpaque()
#endif

#if FLIP // works with PREVIEW
  let unleakyObject = Unmanaged<MyClass>.fromOpaque(OpaquePointer(leakyObject)).takeRetainedValue()
#else // works with SNAPSHOT
  let unleakyObject = Unmanaged<MyClass>.fromOpaque(leakyObject).takeRetainedValue()
#endif

I see the same difference between the previous snapshots and previews all the way back to the “false” preview of yore.

Am I misunderstanding something about the API or is this a bug?

Thanks,
-Kyle


(Jordan Rose) #2

We just didn’t manage to get SE-0017 <https://github.com/apple/swift-evolution/blob/master/proposals/0017-convert-unmanaged-to-use-unsafepointer.md> in before the first preview. The development branch (your SNAPSHOT) is the one that will match the final Swift 3.

Jordan

···

On Jul 4, 2016, at 13:32, Kyle Jessup via swift-dev <swift-dev@swift.org> wrote:

I have this code which uses Unmanaged and the API seems to vary depending on if I am using a 3.0 Preview or a development snapshot. I see it now when trying the June 13th/27th preview vs June 20th snapshot.

class MyClass {}

let holderObject = MyClass()

#if FLIP // works with PREVIEW
  let leakyObject = UnsafeMutablePointer<Void>(OpaquePointer(bitPattern: Unmanaged.passRetained(holderObject)))
#else // works with SNAPSHOT
  let leakyObject = Unmanaged.passRetained(holderObject).toOpaque()
#endif

#if FLIP // works with PREVIEW
  let unleakyObject = Unmanaged<MyClass>.fromOpaque(OpaquePointer(leakyObject)).takeRetainedValue()
#else // works with SNAPSHOT
  let unleakyObject = Unmanaged<MyClass>.fromOpaque(leakyObject).takeRetainedValue()
#endif

I see the same difference between the previous snapshots and previews all the way back to the “false” preview of yore.

Am I misunderstanding something about the API or is this a bug?