Skip to content

Commit 011c280

Browse files
author
Dave Abrahams
authored
Merge pull request #4065 from apple/withVaList
Prefer withVaList over getVaList
2 parents e63ac0f + 8d3ac46 commit 011c280

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

stdlib/public/Platform/Platform.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,15 @@ public var stderr : UnsafeMutablePointer<FILE> {
124124
}
125125

126126
public func dprintf(_ fd: Int, _ format: UnsafePointer<Int8>, _ args: CVarArg...) -> Int32 {
127-
let va_args = getVaList(args)
128-
return vdprintf(Int32(fd), format, va_args)
127+
return withVaList(args) { va_args in
128+
vdprintf(Int32(fd), format, va_args)
129+
}
129130
}
130131

131132
public func snprintf(ptr: UnsafeMutablePointer<Int8>, _ len: Int, _ format: UnsafePointer<Int8>, _ args: CVarArg...) -> Int32 {
132-
let va_args = getVaList(args)
133-
return vsnprintf(ptr, len, format, va_args)
133+
return withVaList(args) { va_args in
134+
return vsnprintf(ptr, len, format, va_args)
135+
}
134136
}
135137
#endif
136138

stdlib/public/SDK/os/os.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ public func os_log(
2727
// Since dladdr is in libc, it is safe to unsafeBitCast
2828
// the cstring argument type.
2929
let str = unsafeBitCast(buf.baseAddress!, to: UnsafePointer<Int8>.self)
30-
let valist = getVaList(args)
31-
_swift_os_log(dso, log, type, str, valist)
30+
withVaList(args) { valist in
31+
_swift_os_log(dso, log, type, str, valist)
32+
}
3233
}
3334
}
3435

stdlib/public/core/VarArgs.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ internal func _withVaList<R>(
9494
/// - Warning: This function is best avoided in favor of
9595
/// `withVaList`, but occasionally (i.e. in a `class` initializer) you
9696
/// may find that the language rules don't allow you to use
97-
/// `withVaList` as intended.
97+
/// `withVaList` as intended.
9898
public func getVaList(_ args: [CVarArg]) -> CVaListPointer {
9999
let builder = _VaListBuilder()
100100
for a in args {

0 commit comments

Comments
 (0)