Skip to content

Commit c8ae80f

Browse files
committed
Foundation: adjust initialization codepath for Windows
This adds in a quick workaround to ensure that `_NSCFConstantString` is properly bridged on platforms where the value witness tables are lazily initialized.
1 parent cfd7974 commit c8ae80f

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

Foundation/NSSwiftRuntime.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,13 @@ internal func __CFInitializeSwift() {
154154
__CFSocketInitializeWinSock()
155155
#endif
156156

157+
// Ensure that the foreign type value witness for `_NSCFConstantString` is
158+
// initialized prior to access. This may be lazily initialized on some
159+
// targets when the type cache is updated due to a type-cast.
160+
//
161+
// TODO: invoke `swift_getForeignTypeMetadata` to do this directly
162+
if let _ = "" as? _NSCFConstantString {}
163+
157164
_CFRuntimeBridgeTypeToClass(CFStringGetTypeID(), unsafeBitCast(_NSCFString.self, to: UnsafeRawPointer.self))
158165
_CFRuntimeBridgeTypeToClass(CFArrayGetTypeID(), unsafeBitCast(_NSCFArray.self, to: UnsafeRawPointer.self))
159166
_CFRuntimeBridgeTypeToClass(CFDictionaryGetTypeID(), unsafeBitCast(_NSCFDictionary.self, to: UnsafeRawPointer.self))

0 commit comments

Comments
 (0)