mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[cxx-interop][SwiftCompilerSources] Fix conversion between std::string and Swift.String
This fixes a dangling pointer issue when creating a `Swift.String` from `std::string`.
Also fixes a warning:
```
warning: variable 's' was never mutated; consider changing to 'let' constant
var s = SILBasicBlock_debugDescription(bridged)
~~~ ^
let
```
rdar://92963081
rdar://93053488
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
@_exported import BasicBridging
|
||||
import std
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// StringRef
|
||||
@@ -60,6 +61,13 @@ extension String {
|
||||
return c(BridgedStringRef(data: buffer.baseAddress, length: buffer.count))
|
||||
}
|
||||
}
|
||||
|
||||
/// Underscored to avoid name collision with the std overlay.
|
||||
/// To be replaced with an overlay call once the CI uses SDKs built with Swift 5.8.
|
||||
public init(_cxxString s: std.string) {
|
||||
self.init(cString: s.c_str())
|
||||
withExtendedLifetime(s) {}
|
||||
}
|
||||
}
|
||||
|
||||
extension Array {
|
||||
|
||||
Reference in New Issue
Block a user