Skip to content
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

[SR-371] Swift needs better interoperation between char * const _[] and UnsafePointer<UnsafeMutablePointer<Int8>> #42990

Open
swift-ci opened this issue Dec 25, 2015 · 0 comments
Labels
compiler The Swift compiler itself improvement standard library Area: Standard library umbrella

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-371
Radar None
Original Reporter djs-code (JIRA User)
Type Improvement
Additional Detail from JIRA
Votes 0
Component/s Compiler, Standard Library
Labels Improvement
Assignee None
Priority Medium

md5: 9fef48dfcb05d6f5109d915a1154149d

Issue Description:

Swift currently doesn't provide good facilities for passing arguments to methods that take in char * const _[] in C, which get mapped to UnsafePointer<UnsafeMutablePointer<Int8>>. The closest solution I've found (https://www.reddit.com/r/swift/comments/3r5027/char_in_swift/) requires some legwork.

let arguments = ["bash", "-c", "echo foo"]

let argv: UnsafeMutablePointer<UnsafeMutablePointer<CChar>> = arguments.withUnsafeBufferPointer {
let buffer = UnsafeMutablePointer<UnsafeMutablePointer<CChar>>.alloc($0.count + 1)
buffer.initializeFrom($0.map { $0.withCString(strdup) })
buffer[$0.count] = nil
return buffer
}

Whether it be done in the compiler or through new APIs in the standard library, there really should be a better solution for this.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler The Swift compiler itself improvement standard library Area: Standard library umbrella
Projects
None yet
Development

No branches or pull requests

1 participant