fixes ptr to cstring warnings[backport] (#20848)
* fix =#13790 ptr char (+friends) should not implicitly convert to cstring * Apply suggestions from code review * first round; compiles on windows * nimPreviewSlimSystem * conversion is unsafe, cast needed * fixes more tests * fixes asyncnet * another try another error * last one * true * one more * why bugs didn't show at once * add `nimPreviewCstringConversion` switch * typo * fixes ptr to cstring warnings[backport] * add fixes Co-authored-by: xflywind <43030857+xflywind@users.noreply.github.com>
This commit is contained in:
parent
3d692d08f7
commit
06cd15663d
25 changed files with 50 additions and 50 deletions
|
|
@ -161,7 +161,7 @@ elif defined(windows) or defined(dos):
|
|||
dec(m)
|
||||
k = k div 10
|
||||
if k == 0: break
|
||||
result = getProcAddress(cast[THINSTANCE](lib), addr decorated)
|
||||
result = getProcAddress(cast[THINSTANCE](lib), cast[cstring](addr decorated))
|
||||
if result != nil: return
|
||||
procAddrError(name)
|
||||
|
||||
|
|
|
|||
|
|
@ -397,9 +397,9 @@ proc reportUnhandledErrorAux(e: ref Exception) {.nodestroy, gcsafe.} =
|
|||
xadd(buf, e.name, e.name.len)
|
||||
add(buf, "]\n")
|
||||
if onUnhandledException != nil:
|
||||
onUnhandledException($buf.addr)
|
||||
onUnhandledException($cast[cstring](buf.addr))
|
||||
else:
|
||||
showErrorMessage(buf.addr, L)
|
||||
showErrorMessage(cast[cstring](buf.addr), L)
|
||||
|
||||
proc reportUnhandledError(e: ref Exception) {.nodestroy, gcsafe.} =
|
||||
if unhandledExceptionHook != nil:
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ proc reprFloat(x: float): string {.compilerproc.} = return $x
|
|||
|
||||
proc reprPointer(x: pointer): string {.compilerproc.} =
|
||||
result = newString(60)
|
||||
let n = c_sprintf(addr result[0], "%p", x)
|
||||
let n = c_sprintf(cast[cstring](addr result[0]), "%p", x)
|
||||
setLen(result, n)
|
||||
|
||||
proc reprStrAux(result: var string, s: cstring; len: int) =
|
||||
|
|
|
|||
|
|
@ -232,7 +232,7 @@ proc nimParseBiggestFloat(s: openArray[char], number: var BiggestFloat,
|
|||
t[ti-2] = ('0'.ord + absExponent mod 10).char
|
||||
absExponent = absExponent div 10
|
||||
t[ti-3] = ('0'.ord + absExponent mod 10).char
|
||||
number = c_strtod(addr t, nil)
|
||||
number = c_strtod(cast[cstring](addr t), nil)
|
||||
|
||||
when defined(nimHasInvariant):
|
||||
{.pop.} # staticBoundChecks
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ proc cstrToNimstr(str: cstring): NimStringV2 {.compilerRtl.} =
|
|||
|
||||
proc nimToCStringConv(s: NimStringV2): cstring {.compilerproc, nonReloadable, inline.} =
|
||||
if s.len == 0: result = cstring""
|
||||
else: result = cstring(unsafeAddr s.p.data)
|
||||
else: result = cast[cstring](unsafeAddr s.p.data)
|
||||
|
||||
proc appendString(dest: var NimStringV2; src: NimStringV2) {.compilerproc, inline.} =
|
||||
if src.len > 0:
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ proc copyStr(s: NimString, start: int): NimString {.compilerproc.} =
|
|||
|
||||
proc nimToCStringConv(s: NimString): cstring {.compilerproc, nonReloadable, inline.} =
|
||||
if s == nil or s.len == 0: result = cstring""
|
||||
else: result = cstring(addr s.data)
|
||||
else: result = cast[cstring](addr s.data)
|
||||
|
||||
proc toNimStr(str: cstring, len: int): NimString {.compilerproc.} =
|
||||
result = rawNewStringNoInit(len)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue