Skip to content

Commit 71640be

Browse files
authored
Merge pull request #71363 from glessard/rdar115296219
[stdlib] properly rename validatingUTF8 to validatingCString
2 parents a1062d0 + 16af5e6 commit 71640be

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

stdlib/public/core/CString.swift

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,16 @@ extension String {
186186
///
187187
/// - Parameter nullTerminatedUTF8:
188188
/// A pointer to a null-terminated sequence of UTF-8 code units.
189-
@inlinable
190-
@_alwaysEmitIntoClient
189+
@_silgen_name("$sSS14validatingUTF8SSSgSPys4Int8VG_tcfC")
191190
public init?(validatingCString nullTerminatedUTF8: UnsafePointer<CChar>) {
192-
// FIXME: https://github.com/apple/swift/issues/68433 (rdar://115296219)
193-
self.init(validatingUTF8: nullTerminatedUTF8)
191+
let len = UTF8._nullCodeUnitOffset(in: nullTerminatedUTF8)
192+
let validated = nullTerminatedUTF8.withMemoryRebound(
193+
to: UInt8.self,
194+
capacity: len,
195+
{ String._tryFromUTF8(UnsafeBufferPointer(start: $0, count: len)) }
196+
)
197+
guard let validated else { return nil }
198+
self = validated
194199
}
195200

196201
/// Creates a new string by copying and validating the null-terminated UTF-8
@@ -223,15 +228,12 @@ extension String {
223228
///
224229
/// - Parameter cString:
225230
/// A pointer to a null-terminated sequence of UTF-8 code units.
231+
@inlinable
232+
@_alwaysEmitIntoClient
226233
@available(swift, deprecated: 6, renamed: "String.init(validatingCString:)")
234+
@_silgen_name("_swift_se0405_String_validatingUTF8")
227235
public init?(validatingUTF8 cString: UnsafePointer<CChar>) {
228-
let len = UTF8._nullCodeUnitOffset(in: cString)
229-
guard let str = cString.withMemoryRebound(to: UInt8.self, capacity: len, {
230-
String._tryFromUTF8(UnsafeBufferPointer(start: $0, count: len))
231-
})
232-
else { return nil }
233-
234-
self = str
236+
self.init(validatingCString: cString)
235237
}
236238

237239
/// Creates a new string by copying and validating the null-terminated UTF-8

test/api-digester/stability-stdlib-abi-without-asserts.test

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,12 @@ Func UnsafeMutablePointer.moveUpdate(from:count:) is a new API without @availabl
152152
Func UnsafeMutableBufferPointer.initialize(from:) has mangled name changing from 'Swift.UnsafeMutableBufferPointer.initialize<A where A == A1.Element, A1: Swift.Sequence>(from: A1) -> (A1.Iterator, Swift.Int)' to 'Swift.UnsafeMutableBufferPointer.initialize<A where A == A1.Element, A1: Swift.Sequence>(from: A1) -> (unwritten: A1.Iterator, index: Swift.Int)'
153153
Func UnsafeMutableBufferPointer.initialize(from:) has return type change from (τ_1_0.Iterator, Swift.Int) to (unwritten: τ_1_0.Iterator, index: Swift.Int)
154154

155+
// This hasn't actually been removed; it was renamed at the source level while
156+
// retaining its old mangled/silgen name. The old source-level name is preserved
157+
// as an @_alwaysEmitIntoClient function. The source break was accepted as part of se-0405.
158+
Constructor String.init(validatingCString:) is a new API without @available attribute
159+
Constructor String.init(validatingUTF8:) has been removed
160+
155161
// These haven't actually been removed; they are simply marked unavailable.
156162
// This seems to be a false positive in the ABI checker. This is not an ABI
157163
// break because the symbols are still present.

0 commit comments

Comments
 (0)