Re: Maybe a bug about built-in string to cstring converter

2017-01-08 Thread Araq
Your WORST solution is what the C backend would have emitted.

Re: Maybe a bug about built-in string to cstring converter

2017-01-08 Thread Ward
I don't think adding a nil check will become the performance bottleneck. Here is my test code: import times proc MulDiv*(P1: int32, P2: int32, P3: int32): int32 {.stdcall, discardable, dynlib: "kernel32", importc.} proc test(s: cstring) = # do someting, to ma

Re: Maybe a bug about built-in string to cstring converter

2017-01-07 Thread Araq
The problem is that a `nil` check can always be inserted manually, but it's harder to get rid of it when the compiler emits it. Conversions to `cstring` should be as fast as possible and code size should be small.

Re: Maybe a bug about built-in string to cstring converter

2017-01-06 Thread Krux02
**@yglukhov** I have to say, that I do agree with your pull request. a nil string should be NULL when converted to a cstring. I think the problem here is, that values of type string can be of no string at all (nil), and functions can be implemented that nil is a totally valid argument. I think f

Re: Maybe a bug about built-in string to cstring converter

2017-01-05 Thread yglukhov
Related discussion: [https://github.com/nim-lang/Nim/pull/3261](https://github.com/nim-lang/Nim/pull/3261)

Re: Maybe a bug about built-in string to cstring converter

2017-01-05 Thread xomachine
As far as I know, cstring is just a pointer to the char's array. The inner representation of the string type contains such kind of array, so the converter just passed the array pointer from the inner representation without any nil-checks to your test procedure. Probably the converter should per

Maybe a bug about built-in string to cstring converter

2017-01-05 Thread Ward
proc test(x: cstring) = echo cast[int](x) var str: string = nil test(nil) # output 0 -> correct test(str) # output 8 ?? I think this should be a bug. I use "Nim Compiler Version 0.15.2 (2016-10-23) [Windows: i386]"