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
|
@_exported import BasicBridging
|
||||||
|
import std
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// StringRef
|
// StringRef
|
||||||
@@ -60,6 +61,13 @@ extension String {
|
|||||||
return c(BridgedStringRef(data: buffer.baseAddress, length: buffer.count))
|
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 {
|
extension Array {
|
||||||
|
|||||||
@@ -25,8 +25,7 @@ final public class BasicBlock : ListNode, CustomStringConvertible, HasShortDescr
|
|||||||
public var function: Function { SILBasicBlock_getFunction(bridged).function }
|
public var function: Function { SILBasicBlock_getFunction(bridged).function }
|
||||||
|
|
||||||
public var description: String {
|
public var description: String {
|
||||||
var s = SILBasicBlock_debugDescription(bridged)
|
String(_cxxString: SILBasicBlock_debugDescription(bridged))
|
||||||
return String(cString: s.c_str())
|
|
||||||
}
|
}
|
||||||
public var shortDescription: String { name }
|
public var shortDescription: String { name }
|
||||||
|
|
||||||
|
|||||||
@@ -21,8 +21,7 @@ final public class Function : CustomStringConvertible, HasShortDescription {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final public var description: String {
|
final public var description: String {
|
||||||
var s = SILFunction_debugDescription(bridged)
|
String(_cxxString: SILFunction_debugDescription(bridged))
|
||||||
return String(cString: s.c_str())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public var shortDescription: String { name.string }
|
public var shortDescription: String { name.string }
|
||||||
|
|||||||
@@ -19,8 +19,7 @@ final public class GlobalVariable : CustomStringConvertible, HasShortDescription
|
|||||||
}
|
}
|
||||||
|
|
||||||
public var description: String {
|
public var description: String {
|
||||||
var s = SILGlobalVariable_debugDescription(bridged)
|
String(_cxxString: SILGlobalVariable_debugDescription(bridged))
|
||||||
return String(cString: s.c_str())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public var shortDescription: String { name.string }
|
public var shortDescription: String { name.string }
|
||||||
|
|||||||
@@ -38,8 +38,7 @@ public class Instruction : ListNode, CustomStringConvertible, Hashable {
|
|||||||
final public var function: Function { block.function }
|
final public var function: Function { block.function }
|
||||||
|
|
||||||
final public var description: String {
|
final public var description: String {
|
||||||
var s = SILNode_debugDescription(bridgedNode)
|
String(_cxxString: SILNode_debugDescription(bridgedNode))
|
||||||
return String(cString: s.c_str())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final public var operands: OperandArray {
|
final public var operands: OperandArray {
|
||||||
@@ -143,8 +142,7 @@ public class SingleValueInstruction : Instruction, Value {
|
|||||||
|
|
||||||
public final class MultipleValueInstructionResult : Value {
|
public final class MultipleValueInstructionResult : Value {
|
||||||
final public var description: String {
|
final public var description: String {
|
||||||
var s = SILNode_debugDescription(bridgedNode)
|
String(_cxxString: SILNode_debugDescription(bridgedNode))
|
||||||
return String(cString: s.c_str())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public var instruction: Instruction {
|
public var instruction: Instruction {
|
||||||
|
|||||||
@@ -81,8 +81,7 @@ public enum Ownership {
|
|||||||
|
|
||||||
extension Value {
|
extension Value {
|
||||||
public var description: String {
|
public var description: String {
|
||||||
var s = SILNode_debugDescription(bridgedNode)
|
String(_cxxString: SILNode_debugDescription(bridgedNode))
|
||||||
return String(cString: s.c_str())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public var uses: UseList {
|
public var uses: UseList {
|
||||||
|
|||||||
@@ -2,9 +2,6 @@
|
|||||||
|
|
||||||
// REQUIRES: swift_in_compiler
|
// REQUIRES: swift_in_compiler
|
||||||
|
|
||||||
// rdar92963081
|
|
||||||
// UNSUPPORTED: OS=linux-gnu
|
|
||||||
|
|
||||||
sil_stage canonical
|
sil_stage canonical
|
||||||
|
|
||||||
import Builtin
|
import Builtin
|
||||||
|
|||||||
@@ -2,9 +2,6 @@
|
|||||||
|
|
||||||
// REQUIRES: swift_in_compiler
|
// REQUIRES: swift_in_compiler
|
||||||
|
|
||||||
// rdar92963081
|
|
||||||
// UNSUPPORTED: OS=linux-gnu
|
|
||||||
|
|
||||||
|
|
||||||
sil_stage canonical
|
sil_stage canonical
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,6 @@
|
|||||||
|
|
||||||
// REQUIRES: swift_in_compiler
|
// REQUIRES: swift_in_compiler
|
||||||
|
|
||||||
// rdar92963081
|
|
||||||
// UNSUPPORTED: OS=linux-gnu
|
|
||||||
|
|
||||||
|
|
||||||
sil_stage canonical
|
sil_stage canonical
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user