Conversation
Four current issues with the PR, please ignore if they're known.Found by GPT-5.4, all verified.
proc mutate(x: var openArray[char]) =
x[0] = 'X'
const longLit = "0123456789abcdef"
doAssert longLit.len == 16
var a = longLit
var b = a
mutate(a)
doAssert a == "X123456789abcdef"
doAssert b == longLit
proc poke(c: var char) =
c = 'X'
var s = "0123456789abcdef"
poke(s[0])
doAssert s == "X123456789abcdef"
proc c_exit(code: cint) {.importc: "exit", header: "<stdlib.h>", noreturn.}
proc c_printf(fmt: cstring): cint {.importc: "printf", header: "<stdio.h>", varargs.}
proc c_fflush(stream: pointer): cint {.importc: "fflush", header: "<stdio.h>".}
type SmallStringMirror = object
bytes: uint
more: pointer
proc dump(label: cstring; s: string) =
let ss = cast[ptr SmallStringMirror](unsafeAddr s)
let p = cast[ptr UncheckedArray[byte]](cast[pointer](ss))
discard c_printf(
"%s raw=0x%08x more=%p bytes=%02x %02x %02x %02x %02x %02x %02x %02x\n",
label,
cuint(ss.bytes),
ss.more,
cuint(p[0]),
cuint(p[1]),
cuint(p[2]),
cuint(p[3]),
cuint(p[4]),
cuint(p[5]),
cuint(p[6]),
cuint(p[7]),
)
var a = newString(4)
a[0] = 'a'
a[1] = 'b'
a[2] = 'c'
a[3] = 'a'
var b = newString(4)
b[0] = 'a'
b[1] = 'b'
b[2] = 'c'
b[3] = 'b'
var lit = "abcdef"
dump("a", a)
dump("b", b)
dump("lit", lit)
discard c_printf("a_eq_b=%d expected=0\n", cint(a == b))
discard c_fflush(nil)
c_exit(0)On 32-bit targets, the PR treats all strings of length The fix is to stop using
proc c_exit(code: cint) {.importc: "exit", header: "<stdlib.h>", noreturn.}
proc c_printf(fmt: cstring): cint {.importc: "printf", header: "<stdio.h>", varargs.}
proc c_fflush(stream: pointer): cint {.importc: "fflush", header: "<stdio.h>".}
type SmallStringMirror = object
bytes: uint
more: pointer
proc dump(label: cstring; s: string) =
let ss = cast[ptr SmallStringMirror](unsafeAddr s)
let p = cast[ptr UncheckedArray[byte]](addr ss.bytes)
discard c_printf(
"%s raw=0x%016llx b0=%u b7=%u more=%p chars=%02x %02x %02x %02x %02x %02x %02x\n",
label,
culonglong(ss.bytes),
cuint(p[0]),
cuint(p[7]),
ss.more,
cuint(p[1]),
cuint(p[2]),
cuint(p[3]),
cuint(p[4]),
cuint(p[5]),
cuint(p[6]),
cuint(p[7]),
)
var short = "abc"
var medium = "abcdefgh"
dump("short", short)
dump("medium", medium)
discard c_fflush(nil)
c_exit(0)The |
|
3 and 4 are known and 1-2 are too and supposed to be caught at compile-time later. |
|
need to warn/error on |
No description provided.