Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/pure/os.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,7 @@ when defined(windows) and not weirdTarget:
template findNextFile(a, b: untyped): untyped = findNextFileA(a, b)
template getCommandLine(): untyped = getCommandLineA()

template getFilename(f: untyped): untyped = $cstring(addr f.cFileName)
template getFilename(f: untyped): untyped = $cast[cstring](addr f.cFileName)

proc skipFindData(f: WIN32_FIND_DATA): bool {.inline.} =
# Note - takes advantage of null delimiter in the cstring
Expand Down Expand Up @@ -2337,7 +2337,7 @@ iterator walkDir*(dir: string; relative = false, checkDir = false):
while true:
var x = readdir(d)
if x == nil: break
var y = $cstring(addr x.d_name)
var y = $cast[cstring](addr x.d_name)
if y != "." and y != "..":
var s: Stat
let path = dir / y
Expand Down
6 changes: 3 additions & 3 deletions lib/system/formatfloat.nim
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ proc writeFloatToBufferSprintf*(buf: var array[65, char]; value: BiggestFloat):
##
## returns the amount of bytes written to `buf` not counting the
## terminating '\0' character.
var n: int = c_sprintf(addr buf, "%.16g", value)
var n: int = c_sprintf(cast[cstring](addr buf), "%.16g", value)
var hasDot = false
for i in 0..n-1:
if buf[i] == ',':
Expand Down Expand Up @@ -85,15 +85,15 @@ proc addFloatRoundtrip*(result: var string; x: float | float32) =
else:
var buffer {.noinit.}: array[65, char]
let n = writeFloatToBufferRoundtrip(buffer, x)
result.addCstringN(cstring(buffer[0].addr), n)
result.addCstringN(cast[cstring](buffer[0].addr), n)

proc addFloatSprintf*(result: var string; x: float) =
when nimvm:
doAssert false
else:
var buffer {.noinit.}: array[65, char]
let n = writeFloatToBufferSprintf(buffer, x)
result.addCstringN(cstring(buffer[0].addr), n)
result.addCstringN(cast[cstring](buffer[0].addr), n)

proc nimFloatToString(a: float): cstring =
## ensures the result doesn't print like an integer, i.e. return 2.0, not 2
Expand Down
2 changes: 1 addition & 1 deletion tests/system/tostring.nim
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import strutils

let arr = ['H','e','l','l','o',' ','W','o','r','l','d','!','\0']
doAssert $arr == "['H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd', '!', '\\x00']"
doAssert $cast[cstring](addr arr) == "Hello World!"
doAssert $cast[cstring](unsafeAddr arr) == "Hello World!"

proc takes(c: cstring) =
doAssert c == cstring""
Expand Down