New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

terminal.nim colored output is not GCSAFE. #8294

Closed
cheatfate opened this Issue Jul 12, 2018 · 2 comments

Comments

Projects
None yet
3 participants
@cheatfate
Copy link
Member

cheatfate commented Jul 12, 2018

Using terminal.nim with colored output generates many GCSAFE problem warnings, because of global variables usage for caching ANSI codes.

const
  hasThreadSupport = compileOption("threads")

when not hasThreadSupport:
  import tables
  var
    colorsFGCache = initTable[Color, string]()
    colorsBGCache = initTable[Color, string]()
    styleCache = initTable[int, string]()

var
  trueColorIsSupported: bool
  trueColorIsEnabled: bool
  fgSetColor: bool

https://github.com/nim-lang/Nim/blob/devel/lib/pure/terminal.nim#L28-L32.

Possible solution is to move this caches into {.threadvar.} variable.

@Araq

This comment has been minimized.

Copy link
Member

Araq commented Jul 12, 2018

Re-open if this is still a problem. I think you fixed it.

@Araq Araq closed this Jul 12, 2018

@stefantalpalaru

This comment has been minimized.

Copy link
Contributor

stefantalpalaru commented Jan 15, 2019

I got a related compilation error on Windows, with latest HEAD:

import terminal

proc f() {.gcsafe.} =
  resetAttributes()

f()

nim c -r --threads:on terminal_test.nim output:

Nim\lib\pure\terminal.nim(42, 6) Warning: 'getTerminal' is not GC-safe as it calls 'newTerminal' [GcUnsafe2]
Nim\lib\pure\terminal.nim(461, 6) Warning: 'resetAttributes' is not GC-safe as it calls 'getTerminal' [GcUnsafe2]
Nim\lib\pure\terminal.nim(848, 6) Warning: 'resetAttributes' is not GC-safe as it calls 'resetAttributes' [GcUnsafe2]
terminal_test.nim(3, 6) Error: 'f' is not GC-safe as it calls 'resetAttributes'

@stefantalpalaru stefantalpalaru referenced this issue Jan 15, 2019

Open

GC safety of Nimbus-related projects #209

22 of 25 tasks complete

@Araq Araq reopened this Jan 15, 2019

@Araq Araq closed this in 27e366e Jan 15, 2019

stefantalpalaru added a commit to status-im/Nim that referenced this issue Jan 16, 2019

narimiran added a commit that referenced this issue Jan 25, 2019

fixes #8294 [backport]
(cherry picked from commit 27e366e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment