[swift-evolution] [swift-evolution-announce] [Review] SE-0127: Cleaning up stdlib Pointer and Buffer Routines

Dmitri Gribenko gribozavr at gmail.com
Fri Jul 22 15:37:57 CDT 2016

On Fri, Jul 22, 2016 at 11:16 AM, Bob Wilson via swift-evolution
<swift-evolution at swift.org> wrote:
> I have been looking at the parts of this proposal related to
> withUnsafe[Mutable]Pointer:

I agree with everything that Bob said, and I would like to comment on this part:

> unsafeAddressOf is removed, in favor of adding a unsafeAddress field on ObjectIdentifier. ObjectIdentifier already contains a raw pointer in the internal _value field and can be initialized with AnyObject just like the argument of unsafeAddressOf.

I think we should not add the ObjectIdentifier.unsafeAddress API.  I
don't agree with the motivation from the proposal:

> Remove unsafeAddressOf and use Unmanaged.takeUnretainedValue(_:) instead. This, however, requires the caller to deal with retain logic for something as simple as getting an object address.

We want users to be explicit about their reference counting semantics
when working unsafely with object addresses.  Otherwise it is not
clear for how long the resulting pointer is valid.  Getting an unsafe
object address is not "simple", it is not commonly when working with
Swift or Objective-C APIs, and there should be no need to have
shorthand convenience syntax for it.  The current way to perform
manual reference counting and bridging of objects to the unsafe world
is through Unmanaged, so the conversion from object to a pointer
should be on Unmanaged (where it is now).


(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/

More information about the swift-evolution mailing list