Skip to content

Expose immortal String initialization for Foundation #78661

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions stdlib/public/core/StringBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,19 @@ internal func _SwiftCreateBridgedString_DoNotCall(
return Unmanaged<AnyObject>.passRetained(str._bridgeToObjectiveCImpl())
}

@available(SwiftStdlib 6.1, *)
@_spi(Foundation) public func _SwiftCreateImmortalString_ForFoundation(
buffer: UnsafeBufferPointer<UInt8>,
isASCII: Bool
) -> String? {
switch validateUTF8(buffer) {
case .success(let extraInfo):
return String(_StringGuts(buffer, isASCII: extraInfo.isASCII))
default:
return nil
}
}

// At runtime, this class is derived from `__SwiftNativeNSStringBase`,
// which is derived from `NSString`.
//
Expand Down
3 changes: 3 additions & 0 deletions test/abi/macOS/arm64/stdlib.swift
Original file line number Diff line number Diff line change
Expand Up @@ -827,3 +827,6 @@ Added: _$ss4SlabVsRi__rlE5countSivpZMV

// Slab._storage _read accessor
Added: _$ss4SlabVsRi__rlE8_storagexq_BVvr

// Shared string creation for Foundation
Added: _$ss40_SwiftCreateImmortalString_ForFoundation6buffer7isASCIISSSgSRys5UInt8VG_SbtF
3 changes: 3 additions & 0 deletions test/abi/macOS/x86_64/stdlib.swift
Original file line number Diff line number Diff line change
Expand Up @@ -828,3 +828,6 @@ Added: _$ss4SlabVsRi__rlE5countSivpZMV

// Slab._storage _read accessor
Added: _$ss4SlabVsRi__rlE8_storagexq_BVvr

// Shared string creation for Foundation
Added: _$ss40_SwiftCreateImmortalString_ForFoundation6buffer7isASCIISSSgSRys5UInt8VG_SbtF