breaking change: arrays of char do not convert to cstring; ptr to array of char does
This commit is contained in:
parent
db0d353281
commit
3308d26581
12 changed files with 73 additions and 36 deletions
|
|
@ -496,11 +496,12 @@ proc getLocalAddr*(socket: SocketHandle, domain: Domain): (string, Port) =
|
|||
addr(namelen)) == -1'i32:
|
||||
raiseOSError(osLastError())
|
||||
# Cannot use INET6_ADDRSTRLEN here, because it's a C define.
|
||||
var buf: array[64, char]
|
||||
result[0] = newString(64)
|
||||
if inet_ntop(name.sin6_family.cint,
|
||||
addr name.sin6_addr, buf.cstring, sizeof(buf).int32).isNil:
|
||||
addr name.sin6_addr, addr result[0][0], (result[0].len+1).int32).isNil:
|
||||
raiseOSError(osLastError())
|
||||
result = ($buf.cstring, Port(nativesockets.ntohs(name.sin6_port)))
|
||||
setLen(result[0], result[0].cstring.len)
|
||||
result[1] = Port(nativesockets.ntohs(name.sin6_port))
|
||||
else:
|
||||
raiseOSError(OSErrorCode(-1), "invalid socket family in getLocalAddr")
|
||||
|
||||
|
|
@ -532,11 +533,12 @@ proc getPeerAddr*(socket: SocketHandle, domain: Domain): (string, Port) =
|
|||
addr(namelen)) == -1'i32:
|
||||
raiseOSError(osLastError())
|
||||
# Cannot use INET6_ADDRSTRLEN here, because it's a C define.
|
||||
var buf: array[64, char]
|
||||
result[0] = newString(64)
|
||||
if inet_ntop(name.sin6_family.cint,
|
||||
addr name.sin6_addr, buf.cstring, sizeof(buf).int32).isNil:
|
||||
addr name.sin6_addr, addr result[0][0], (result[0].len+1).int32).isNil:
|
||||
raiseOSError(osLastError())
|
||||
result = ($buf.cstring, Port(nativesockets.ntohs(name.sin6_port)))
|
||||
setLen(result[0], result[0].cstring.len)
|
||||
result[1] = Port(nativesockets.ntohs(name.sin6_port))
|
||||
else:
|
||||
raiseOSError(OSErrorCode(-1), "invalid socket family in getLocalAddr")
|
||||
|
||||
|
|
|
|||
|
|
@ -790,7 +790,10 @@ iterator walkDir*(dir: string; relative=false): tuple[kind: PathComponent, path:
|
|||
while true:
|
||||
var x = readdir(d)
|
||||
if x == nil: break
|
||||
var y = $x.d_name.cstring
|
||||
when defined(nimNoArrayToCstringConversion):
|
||||
var y = $cstring(addr x.d_name)
|
||||
else:
|
||||
var y = $x.d_name.cstring
|
||||
if y != "." and y != "..":
|
||||
var s: Stat
|
||||
if not relative:
|
||||
|
|
|
|||
|
|
@ -1890,11 +1890,17 @@ proc formatBiggestFloat*(f: BiggestFloat, format: FloatFormatMode = ffDefault,
|
|||
frmtstr[3] = '*'
|
||||
frmtstr[4] = floatFormatToChar[format]
|
||||
frmtstr[5] = '\0'
|
||||
L = c_sprintf(buf, frmtstr, precision, f)
|
||||
when defined(nimNoArrayToCstringConversion):
|
||||
L = c_sprintf(addr buf, addr frmtstr, precision, f)
|
||||
else:
|
||||
L = c_sprintf(buf, frmtstr, precision, f)
|
||||
else:
|
||||
frmtstr[1] = floatFormatToChar[format]
|
||||
frmtstr[2] = '\0'
|
||||
L = c_sprintf(buf, frmtstr, f)
|
||||
when defined(nimNoArrayToCstringConversion):
|
||||
L = c_sprintf(addr buf, addr frmtstr, f)
|
||||
else:
|
||||
L = c_sprintf(buf, frmtstr, f)
|
||||
result = newString(L)
|
||||
for i in 0 ..< L:
|
||||
# Depending on the locale either dot or comma is produced,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue