Nim: gc:arc mode breaks tuple let

Created on 8 Feb 2020  路  1Comment  路  Source: nim-lang/Nim

In gc:arc mode (but not other modes), a tuple let breaks memory safety/management

Example

import strutils
proc procStat() =
  for line in lines("/proc/stat"):
    let cols = line.splitWhitespace(maxSplit=1)
    echo cols[0]                        #To see Num loops
    let (nm, rest) = (cols[0], cols[1]) #This breaks stuff
#   let nm = cols[0]
#   let rest = cols[1]
#   let col = rest.splitWhitespace   #Works WITHOUT tuple let
procStat()

Current Output

cpu0
cpu1
Traceback (most recent call last)
/u/cb/s/nim/mrve6.nim(10) mrve6
/usr/lib64/nim/lib/system/iterators.nim(5) procStat
/usr/lib64/nim/lib/system/alloc.nim(968) dealloc
/usr/lib64/nim/lib/system/alloc.nim(867) rawDealloc
/usr/lib64/nim/lib/system/avltree.nim(74) del

Expected Output

cpu0
cpu1
.
.
.

Possible Solution

  • Particular code example trashes my call stack making it a little hard to debug.

Additional Information

  • Works fine without --gc:arc or --newruntime
  • Could find no other issue relating to tuple let.
  • Can probably reproduce on Windows by just
cat /proc/stat > dummy
scp dummy
change path from /proc/stat -> dummy

$ nim -v
Nim Compiler Version 1.1.1 [Linux: amd64]
Compiled at 2020-02-08
Copyright (c) 2006-2019 by Andreas Rumpf

git hash: e4415422fe2b615a6dfe01bb7136ec41ef429108
active boot switches: -d:release -d:useLinenoise -d:nativeStackTrace -d:nimHasLibFFI
```

Destructors

Most helpful comment

I have a fix for this one

>All comments

I have a fix for this one

Was this page helpful?
0 / 5 - 0 ratings