Kyle-Ye
(Kyle)
October 19, 2023, 5:22am
1
Why do we declare in the document comments of the initialization method of the UnsafeMutablePointer type that it "Create an immutable typed pointer"?
I am a little confused by the doc statement here.
Could you help check with it and maybe give some explanation here? Thanks @Alex_Martini
/// Creates an immutable typed pointer referencing the same memory as the
/// given mutable pointer.
///
/// - Parameter other: The pointer to convert.
@_transparent
public init(@_nonEphemeral _ other: UnsafeMutablePointer<Pointee>) {
self._rawValue = other._rawValue
}
/// Creates an immutable typed pointer referencing the same memory as the
/// given mutable pointer.
///
/// - Parameter other: The pointer to convert. If `other` is `nil`, the
/// result is `nil`.
@_transparent
public init?(@_nonEphemeral _ other: UnsafeMutablePointer<Pointee>?) {
guard let unwrapped = other else { return nil }
self.init(unwrapped)
}
2 Likes
I'm not sure — the work I've done on "unsafe' docs was cleaning up some trailing whitespace and other minor wording fixes. It's possible this is just a copy/paste error from UnsafePointer
to UnsafeMutablePointer
.
Looking at Git blame, maybe @nnnnnnnn or @hamishknight can help with this? But it's probably not in anybody's recent memory, since changes to these docs and APIs are from 4 and 7 years ago.
3 Likes
scanon
(Steve Canon)
October 19, 2023, 9:47pm
3
Yeah, I'm pretty sure this is just an error.
1 Like
For folks following along, Kyle Ye's PR that fixes this copy/paste error was merged:
https://github.com/apple/swift/pull/69297
Thanks!
3 Likes