We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
md5: c1e78ccbc6e54d3f8578b6e6c8b37666
relates to:
Issue Description:
I've had a long-working debugLog() method that looks like this:
debugLog()
func debugLog<T>(_ inMsg: T, file inFile : String = #file, line inLine : Int = #line) { let file = (inFile as NSString).lastPathComponent let s = "\(file):\(inLine) \(inMsg)" print(s) }
I wanted to add a version that works like String(format:):
String(format:)
func debugLog(format inFormat: String, file inFile : String = #file, line inLine : Int = #line, _ inArgs: CVarArg...) { let s = String(format: inFormat, inArgs) debugLog(s, file: inFile, line: inLine) }
While this compiles and executes, all of the values are zero for this example:
let xc = CGFloat(1.0) let yc = CGFloat(0.0) let len = CGFloat(282.1364917907643) debugLog(format: "Pixel %f, %f length too far %f", xc, yc, len)
Output:
FisheyeImageRenderer.swift:108 Pixel 0.000000, 0.000000 length too far 0.000000
Something is being misinterpreted in the passing of inArgs: CVarArg.... The solution is to call
inArgs: CVarArg...
let s = String(format: inFormat, arguments: inArgs)
The compiler, perhaps, should warn of this mistake.
The text was updated successfully, but these errors were encountered:
Comment by Federico Cappelli (JIRA)
I don't think this is a bug.
When you pass a `CVarArg` to `String(format: inFormat, inArgs)` at that point `inArgs` is already an array.
If you check the Swift implementation of os_log(...) in https://github.com/apple/swift/blob/6e7051eb1e38e743a514555d09256d12d3fec750/stdlib/public/Darwin/os/os_log.swift you can see how this is done:
public func os_log( _ message: StaticString, dso: UnsafeRawPointer? = #dsohandle, log: OSLog = .default, type: OSLogType = .default, _ args: CVarArg...) { guard log.isEnabled(type: type) else { return } let ra = _swift_os_log_return_address() message.withUTF8Buffer { (buf: UnsafeBufferPointer<UInt8>) in // Since dladdr is in libc, it is safe to unsafeBitCast // the cstring argument type. buf.baseAddress!.withMemoryRebound( to: CChar.self, capacity: buf.count ) { str in withVaList(args) { valist in <<<<<<<<HERE _swift_os_log(dso, ra, log, type, str, valist) } } } }
Sorry, something went wrong.
No branches or pull requests
Additional Detail from JIRA
md5: c1e78ccbc6e54d3f8578b6e6c8b37666
relates to:
Issue Description:
I've had a long-working
debugLog()
method that looks like this:I wanted to add a version that works like
String(format:)
:While this compiles and executes, all of the values are zero for this example:
Output:
Something is being misinterpreted in the passing of
inArgs: CVarArg...
. The solution is to callThe compiler, perhaps, should warn of this mistake.
The text was updated successfully, but these errors were encountered: