From eaf43a1bd9b66d0f068dac12bb0a57a22c44c911 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Thu, 17 Nov 2022 04:19:32 +0800 Subject: [PATCH] fixes remaining ptr2cstring warnings on version-1-6 (#20861) --- lib/pure/os.nim | 4 ++-- lib/system/formatfloat.nim | 6 +++--- tests/system/tostring.nim | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/pure/os.nim b/lib/pure/os.nim index 24945095f2..dd0048fd14 100644 --- a/lib/pure/os.nim +++ b/lib/pure/os.nim @@ -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 @@ -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 diff --git a/lib/system/formatfloat.nim b/lib/system/formatfloat.nim index 3bcd3257b8..22a6f6553e 100644 --- a/lib/system/formatfloat.nim +++ b/lib/system/formatfloat.nim @@ -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] == ',': @@ -85,7 +85,7 @@ 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: @@ -93,7 +93,7 @@ proc addFloatSprintf*(result: var string; x: float) = 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 diff --git a/tests/system/tostring.nim b/tests/system/tostring.nim index bb6e453fbb..ca54ae5b2f 100644 --- a/tests/system/tostring.nim +++ b/tests/system/tostring.nim @@ -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""