--gc:destructors now means Nim uses pure refcounting (#12557)

This commit is contained in:
Andreas Rumpf 2019-10-30 16:15:17 +01:00 • committed by GitHub
commit 1746da2d9e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 123 additions and 35 deletions

View file

@ -57,13 +57,13 @@ proc nimNewObj(size: int): pointer {.compilerRtl.} =
else:
inc allocs
proc nimDecWeakRef(p: pointer) {.compilerRtl.} =
proc nimDecWeakRef(p: pointer) {.compilerRtl, inl.} =
when hasThreadSupport:
atomicDec head(p).rc
else:
dec head(p).rc
proc nimIncWeakRef(p: pointer) {.compilerRtl.} =
proc nimIncRef(p: pointer) {.compilerRtl, inl.} =
when hasThreadSupport:
atomicInc head(p).rc
else:
@ -106,11 +106,25 @@ proc nimDestroyAndDispose(p: pointer) {.compilerRtl.} =
cstderr.rawWrite "has destructor!\n"
nimRawDispose(p)
proc isObj(obj: PNimType, subclass: cstring): bool {.compilerproc.} =
proc nimDecRefIsLast(p: pointer): bool {.compilerRtl, inl.} =
if p != nil:
when hasThreadSupport:
if atomicLoadN(addr head(p).rc, ATOMIC_RELAXED) == 0:
result = true
else:
if atomicDec(head(p).rc) <= 0:
result = true
else:
if head(p).rc == 0:
result = true
else:
dec head(p).rc
proc isObj(obj: PNimType, subclass: cstring): bool {.compilerRtl, inl.} =
proc strstr(s, sub: cstring): cstring {.header: "<string.h>", importc.}
result = strstr(obj.name, subclass) != nil
proc chckObj(obj: PNimType, subclass: cstring) {.compilerproc.} =
proc chckObj(obj: PNimType, subclass: cstring) {.compilerRtl.} =
# checks if obj is of type subclass:
if not isObj(obj, subclass): sysFatal(ObjectConversionError, "invalid object conversion")