-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[cxx-interop] Adding std.string initializer for UnsafePointer<CChar>? #65057
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
[cxx-interop] Adding std.string initializer for UnsafePointer<CChar>? #65057
Conversation
@swift-ci please smoke test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @plotfi!
Could you please also add an execution test to make sure that the std::string
that is created has the correct contents?
Otherwise LGTM.
Hi @egorzhdan can you point me to some similar execution tests that are already in tree? I am a little lost, sorry. |
@plotfi sure! Just adding a new test to StdStringOverlayTestSuite.test("std::string from C string") {
let str = "abc".withCString { ptr in
std.string(ptr)
}
expectEqual(str, std.string("abc"))
} |
Currently without an initializer for the unsafe char pointer type swiftc hits an assert around not being able to handle conversions of unsafe pointers with Any type. This patch adds the ability to convert to a std::string. This is to address issue swiftlang#61218
c237f9f
to
6180387
Compare
@swift-ci please smoke test |
1 similar comment
@swift-ci please smoke test |
Thank You Egor! I will remember this in the future. |
This fixes a build failure that started occurring on CentOS after #65057: ``` error: cannot find 'strlen' in scope ``` rdar://107987115
@plotfi this should also go to 5.9 |
This fixes a build failure that started occurring on CentOS after swiftlang#65057: ``` error: cannot find 'strlen' in scope ``` rdar://107987115
This fixes a build failure that started occurring on CentOS after swiftlang#65057: ``` error: cannot find 'strlen' in scope ``` rdar://107987115 (cherry picked from commit 7774650)
Currently without an initializer for the unsafe char pointer type swiftc hits an assert around not being able to handle conversions of unsafe pointers with Any type. This patch adds the ability to convert to a std::string.
This is to address issue #61218