-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[se-0405] rename String.init(validatingUTF8:)
#68423
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
7fed3e6
to
ef4a977
Compare
ef4a977
to
8bdfbca
Compare
- use the new name `String(validatingCString:)`
- use the new name `String(validatingCString:)`
8bdfbca
to
c30307e
Compare
@swift-ci please smoke test |
@swift-ci please smoke test |
The existing extension String {
public init(cString nullTerminatedUTF8: UnsafePointer<CChar>)
public init(cString nullTerminatedUTF8: UnsafePointer<UInt8>)
public init(cString nullTerminatedUTF8: [CChar])
public init(cString nullTerminatedUTF8: [UInt8])
}
@available(*, deprecated)
extension String {
public init(cString nullTerminatedUTF8: inout CChar)
public init(cString nullTerminatedUTF8: inout UInt8)
public init(cString nullTerminatedUTF8: String)
}
|
The decision to always typealias I have been wondering about the This being said, in the spirit of SE-0324, it seems like we should have |
public init?(validatingCString nullTerminatedUTF8: UnsafePointer<CChar>) { | ||
// FIXME: https://github.com/apple/swift/issues/68433 (rdar://115296219) | ||
self.init(validatingUTF8: nullTerminatedUTF8) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would seem preferable to point the ABI entry point to String.init?(validatingCString:)
, but renaming initializers isn't supported by @_silgen_name
. This solution will cause a warning when compiling the stdlib in Swift 6.
@swift-ci please test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Would be nice to take this opportunity to give that initializer docs, too 👍🏻
@@ -162,39 +200,59 @@ extension String { | |||
|
|||
@inlinable | |||
@_alwaysEmitIntoClient | |||
public init?(validatingUTF8 cString: [CChar]) { | |||
guard let length = cString.firstIndex(of: 0) else { | |||
public init?(validatingCString nullTerminatedUTF8: [CChar]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we more or less duplicate the docs for the other validatingCString
initializer here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good thought. These are stop-gap api that should be removed once pointer conversions can be restricted, but the time horizon is so long that it makes sense to document them until then. I should probably have done that when adding them last year.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will do the documentation update you suggest in a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressing the documentation issues in #71224
API renaming from SE-0405, namely:
renamed to
We expected to do a symbol switch using
@_silgen_name
, but that cannot be done at the moment. (See #68433). The most compact alternative is this, where the renamed initializer uses the deprecated symbol -- sadly resulting in a deprecation warning when building the standard library.Follow-up to #68419, rdar://114999766