Skip to content

Commit 0cf72bc

Browse files
committed
Implemented _CVarArgObject protocol to retain the NSString
1 parent 8e039ff commit 0cf72bc

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

Sources/Foundation/NSString.swift

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,15 +1652,14 @@ extension NSString : CVarArg {
16521652
}
16531653
}
16541654

1655-
extension String : CVarArg {
1655+
extension String : CVarArg, _CVarArgObject {
1656+
@inlinable // c-abi
1657+
public var _cVarArgObject: CVarArg {
1658+
return NSString(string: self)
1659+
}
1660+
16561661
@inlinable // c-abi
16571662
public var _cVarArgEncoding: [Int] {
1658-
// We don't have an autorelease pool to retain the NSString until the withVaList closure is complete.
1659-
// So add an operation to release on the next cycle of this thread.
1660-
let ns = Unmanaged.passRetained(NSString(string: self))
1661-
OperationQueue.current?.addOperation {
1662-
ns.release()
1663-
}
1664-
return ns.takeUnretainedValue()._cVarArgEncoding
1663+
fatalError("_cVarArgEncoding must be called on NSString instead")
16651664
}
16661665
}

0 commit comments

Comments
 (0)