mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 05:50:30 +00:00
gc:arc: support GC_ref/unref for ref T
This commit is contained in:
@@ -28,8 +28,8 @@ hash of ``package & "." & module & "." & name`` to save space.
|
||||
type
|
||||
RefHeader = object
|
||||
rc: int # the object header is now a single RC field.
|
||||
# we could remove it in non-debug builds but this seems
|
||||
# unwise.
|
||||
# we could remove it in non-debug builds for the 'owned ref'
|
||||
# design but this seems unwise.
|
||||
|
||||
template `+!`(p: pointer, s: int): pointer =
|
||||
cast[pointer](cast[int](p) +% s)
|
||||
@@ -121,6 +121,17 @@ proc nimDecRefIsLast(p: pointer): bool {.compilerRtl, inl.} =
|
||||
else:
|
||||
dec head(p).rc
|
||||
|
||||
proc GC_unref*[T](x: ref T) =
|
||||
## New runtime only supports this operation for 'ref T'.
|
||||
if nimDecRefIsLast(cast[pointer](x)):
|
||||
# XXX this does NOT work for virtual destructors!
|
||||
`=destroy`(x[])
|
||||
nimRawDispose(cast[pointer](x))
|
||||
|
||||
proc GC_ref*[T](x: ref T) =
|
||||
## New runtime only supports this operation for 'ref T'.
|
||||
if x != nil: nimIncRef(cast[pointer](x))
|
||||
|
||||
proc isObj(obj: PNimType, subclass: cstring): bool {.compilerRtl, inl.} =
|
||||
proc strstr(s, sub: cstring): cstring {.header: "<string.h>", importc.}
|
||||
|
||||
|
||||
@@ -3269,7 +3269,7 @@ when not defined(nimscript) and hasAlloc:
|
||||
## Expands operating GC stack range to `theStackBottom`. Does nothing
|
||||
## if current stack bottom is already lower than `theStackBottom`.
|
||||
|
||||
else:
|
||||
elif defined(JS):
|
||||
template GC_disable* =
|
||||
{.warning: "GC_disable is a no-op in JavaScript".}
|
||||
|
||||
|
||||
@@ -531,12 +531,12 @@ when not defined(noSignalHandler) and not defined(useNimRtl):
|
||||
when defined(memtracker):
|
||||
logPendingOps()
|
||||
when hasSomeStackTrace:
|
||||
GC_disable()
|
||||
when not defined(gcDestructors): GC_disable()
|
||||
var buf = newStringOfCap(2000)
|
||||
rawWriteStackTrace(buf)
|
||||
processSignal(sign, buf.add) # nice hu? currying a la Nim :-)
|
||||
showErrorMessage(buf)
|
||||
GC_enable()
|
||||
when not defined(gcDestructors): GC_enable()
|
||||
else:
|
||||
var msg: cstring
|
||||
template asgn(y) =
|
||||
|
||||
Reference in New Issue
Block a user