let a = someConst.unsafeAddr
is very buggy and should be replaced
#16794
Labels
let a = someConst.unsafeAddr
is very buggy and should be replaced
#16794
this recent PR #15466 enabled one to write
let a = someConst.unsafeAddr
; however this feature is very buggy, not documented, had 0 tests in the PR that introduced it and should be reverted; see upcoming proposal for a better and simpler way to solve nim-lang/RFCs#257 that has none of its drawbacksExample 1
unsafeAddr doesn't work with most types
note that these would work with
let c = b
instead oflet c = b.unsafeAddr
Example 2
vm:
[7, 2] # modified from [1,2]
[1, 2] # unmodified from [1,2]: inconsistent
rt:
SIGBUS
Example 3
prints:
4416151424
4416151424
4416151440 # address of a returned is different depending on which module it was called from
4416151440
and this is generated in each module:
unlike what was required in nim-lang/RFCs#257
Example 4
unsafeAddr
still doesn't help with types (including arrays) that (transitively) contain ref/ptr; it still needs #15528Example 5
vm:
4378615304
4378615368 # different from previous line (inconsistent)
rt:
4382200032
4382200032 # same from previous line: inconsistent
Example 6
Example 7
nim r main: SIGBUS
nim r -b:cpp main: prints @[7, 2]
Example 8
nim r main: prints [1, 2] with -d:danger, or SIGBUG without
nim r -b:cpp main: prints [7, 2] with or without -d:danger
Additional Information
1.5.1 2b5841c
links
for ai in a
has quadratic complexity in VM whena
is const #16790The text was updated successfully, but these errors were encountered: