Re: [swift-users] Passing variadic C args through?

2017-11-14 Thread Rick Mann via swift-users
Here you go: https://bugs.swift.org/browse/SR-6386

> On Nov 14, 2017, at 18:01 , Jordan Rose  wrote:
> 
> Sure. I'm not sure we have a good idea for how to catch the bug—what if you 
> really meant to pass the array as an NSArray?—but it's worth recording 
> somewhere. Thanks, Rick.
> 
> Jordan
> 
> 
>> On Nov 14, 2017, at 18:00, Rick Mann  wrote:
>> 
>> I tried to find an alternative init() to use, but couldn't (despite dozens 
>> of releases, Xcode's code completion still fails much of the time). Thanks 
>> for pointing me to the right one!
>> 
>> Should I file a bug?
>> 
>>> On Nov 14, 2017, at 17:47 , Jordan Rose  wrote:
>>> 
>>> Heh, it would be nice to catch this. You're collecting a bunch of arguments 
>>> in an Array, and then passing that array straight on as a single argument 
>>> itself, which means it gets passed as either an NSArray or a pointer (not 
>>> sure which). Use 'init(format:arguments:)' instead.
>>> 
>>> Jordan
>>> 
>>> 
 On Nov 14, 2017, at 17:19, Rick Mann via swift-users 
  wrote:
 
 I've had a long-working `debugLog()` method that looks like this:
 
 ```
 func
 debugLog(_ 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:)`:
 
 ```
 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:108Pixel 0.00, 0.00 length too far 
 0.00
 ```
 
 Something is being misinterpreted in the passing of `inArgs: CVarArg...`
 
 TIA,
 
 -- 
 Rick Mann
 rm...@latencyzero.com
 
 
 
 ___
 swift-users mailing list
 swift-users@swift.org
 https://lists.swift.org/mailman/listinfo/swift-users
>>> 
>> 
>> 
>> -- 
>> Rick Mann
>> rm...@latencyzero.com
>> 
>> 
> 


-- 
Rick Mann
rm...@latencyzero.com


___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Passing variadic C args through?

2017-11-14 Thread Jordan Rose via swift-users
Sure. I'm not sure we have a good idea for how to catch the bug—what if you 
really meant to pass the array as an NSArray?—but it's worth recording 
somewhere. Thanks, Rick.

Jordan


> On Nov 14, 2017, at 18:00, Rick Mann  wrote:
> 
> I tried to find an alternative init() to use, but couldn't (despite dozens of 
> releases, Xcode's code completion still fails much of the time). Thanks for 
> pointing me to the right one!
> 
> Should I file a bug?
> 
>> On Nov 14, 2017, at 17:47 , Jordan Rose  wrote:
>> 
>> Heh, it would be nice to catch this. You're collecting a bunch of arguments 
>> in an Array, and then passing that array straight on as a single argument 
>> itself, which means it gets passed as either an NSArray or a pointer (not 
>> sure which). Use 'init(format:arguments:)' instead.
>> 
>> Jordan
>> 
>> 
>>> On Nov 14, 2017, at 17:19, Rick Mann via swift-users 
>>>  wrote:
>>> 
>>> I've had a long-working `debugLog()` method that looks like this:
>>> 
>>> ```
>>> func
>>> debugLog(_ 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:)`:
>>> 
>>> ```
>>> 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:108Pixel 0.00, 0.00 length too far 
>>> 0.00
>>> ```
>>> 
>>> Something is being misinterpreted in the passing of `inArgs: CVarArg...`
>>> 
>>> TIA,
>>> 
>>> -- 
>>> Rick Mann
>>> rm...@latencyzero.com
>>> 
>>> 
>>> 
>>> ___
>>> swift-users mailing list
>>> swift-users@swift.org
>>> https://lists.swift.org/mailman/listinfo/swift-users
>> 
> 
> 
> -- 
> Rick Mann
> rm...@latencyzero.com
> 
> 

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Passing variadic C args through?

2017-11-14 Thread Rick Mann via swift-users
I tried to find an alternative init() to use, but couldn't (despite dozens of 
releases, Xcode's code completion still fails much of the time). Thanks for 
pointing me to the right one!

Should I file a bug?

> On Nov 14, 2017, at 17:47 , Jordan Rose  wrote:
> 
> Heh, it would be nice to catch this. You're collecting a bunch of arguments 
> in an Array, and then passing that array straight on as a single argument 
> itself, which means it gets passed as either an NSArray or a pointer (not 
> sure which). Use 'init(format:arguments:)' instead.
> 
> Jordan
> 
> 
>> On Nov 14, 2017, at 17:19, Rick Mann via swift-users  
>> wrote:
>> 
>> I've had a long-working `debugLog()` method that looks like this:
>> 
>> ```
>> func
>> debugLog(_ 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:)`:
>> 
>> ```
>> 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:108Pixel 0.00, 0.00 length too far 
>> 0.00
>> ```
>> 
>> Something is being misinterpreted in the passing of `inArgs: CVarArg...`
>> 
>> TIA,
>> 
>> -- 
>> Rick Mann
>> rm...@latencyzero.com
>> 
>> 
>> 
>> ___
>> swift-users mailing list
>> swift-users@swift.org
>> https://lists.swift.org/mailman/listinfo/swift-users
> 


-- 
Rick Mann
rm...@latencyzero.com


___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Passing variadic C args through?

2017-11-14 Thread Jordan Rose via swift-users
Heh, it would be nice to catch this. You're collecting a bunch of arguments in 
an Array, and then passing that array straight on as a single argument itself, 
which means it gets passed as either an NSArray or a pointer (not sure which). 
Use 'init(format:arguments:)' instead.

Jordan


> On Nov 14, 2017, at 17:19, Rick Mann via swift-users  
> wrote:
> 
> I've had a long-working `debugLog()` method that looks like this:
> 
> ```
> func
> debugLog(_ 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:)`:
> 
> ```
> 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:108Pixel 0.00, 0.00 length too far 
> 0.00
> ```
> 
> Something is being misinterpreted in the passing of `inArgs: CVarArg...`
> 
> TIA,
> 
> -- 
> Rick Mann
> rm...@latencyzero.com
> 
> 
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users