newruntime: only check for dangling refs when 'owned ref T' support is enabled

This commit is contained in:
Andreas Rumpf
2019-11-03 09:46:33 +01:00
parent 4c9a7e6f00
commit 3f4b9971fc

View File

@@ -71,13 +71,14 @@ proc nimIncRef(p: pointer) {.compilerRtl, inl.} =
proc nimRawDispose(p: pointer) {.compilerRtl.} =
when not defined(nimscript):
when hasThreadSupport:
let hasDanglingRefs = atomicLoadN(addr head(p).rc, ATOMIC_RELAXED) != 0
else:
let hasDanglingRefs = head(p).rc != 0
if hasDanglingRefs:
cstderr.rawWrite "[FATAL] dangling references exist\n"
quit 1
when defined(nimOwnedEnabled):
when hasThreadSupport:
let hasDanglingRefs = atomicLoadN(addr head(p).rc, ATOMIC_RELAXED) != 0
else:
let hasDanglingRefs = head(p).rc != 0
if hasDanglingRefs:
cstderr.rawWrite "[FATAL] dangling references exist\n"
quit 1
when defined(useMalloc):
c_free(p -! sizeof(RefHeader))
else: