Skip to content
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

return gc traced object from dynlib cause crash when orc/arc enabled #16457

Open
codehz opened this issue Dec 24, 2020 · 2 comments
Open

return gc traced object from dynlib cause crash when orc/arc enabled #16457

codehz opened this issue Dec 24, 2020 · 2 comments

Comments

@codehz
Copy link
Contributor

codehz commented Dec 24, 2020

Example

# nim c --gc:arc --debugger:native --cc:clang_cl --debuginfo:on a.nim
proc create(): ref int {.dynlib: "b.dll", importc.}

block:
  var x = create()
  echo cast[int](x) # check the pointer
echo "here"
GC_fullCollect()
# nim c --gc:arc --debugger:native --cc:clang_cl --debuginfo:on --app:lib b.nim
proc create(): ref int{.dynlib, exportc.} =
  new int

Current Output

2317140426832
Traceback (most recent call last)
D:\Temp\nimdll\a.nim(4)  a
C:\Users\CodeHz\.choosenim\toolchains\nim-1.4.2\lib\system\arc.nim(161) nimRawDispose
C:\Users\CodeHz\.choosenim\toolchains\nim-1.4.2\lib\system\alloc.nim(972) dealloc
C:\Users\CodeHz\.choosenim\toolchains\nim-1.4.2\lib\system\alloc.nim(857) rawDealloc
C:\Users\CodeHz\.choosenim\toolchains\nim-1.4.2\lib\system\alloc.nim(518) listRemove
SIGSEGV: Illegal storage access. (Attempt to read from nil?)

Expected Output

no output and no crash

Possible Solution

  • In file xyz there is a call that might be the cause of it.

Additional Information

$ nim -v
Nim Compiler Version 1.4.2 [Windows: amd64]
Compiled at 2020-11-30
Copyright (c) 2006-2020 by Andreas Rumpf

active boot switches: -d:release
@codehz codehz changed the title return ref object from dynlib cause crash when orc/arc enabled return ref RootObj from dynlib cause crash when orc/arc enabled Dec 24, 2020
@codehz codehz changed the title return ref RootObj from dynlib cause crash when orc/arc enabled return gc traced object from dynlib cause crash when orc/arc enabled Dec 24, 2020
@cooldome
Copy link
Member

add -d:useMalloc to Nim command line

@timotheecour
Copy link
Member

timotheecour commented Dec 24, 2020

add -d:useMalloc to Nim command line

that's hardly a viable workaround in the general case though; also user passed --gc:arc, not --newruntime so docs are either incorrect or imprecise

``useMalloc``            Makes Nim use C's `malloc`:idx: instead of Nim's
                         own memory manager, albeit prefixing each allocation with
                         its size to support clearing memory on reallocation.
                         This only works with ``gc:none`` and
                         with ``--newruntime``.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants