summary refs log tree commit diff stats
path: root/lib/system/orc.nim
diff options
context:
space:
mode:
authorringabout <43030857+ringabout@users.noreply.github.com>2022-12-28 23:23:37 +0800
committerGitHub <noreply@github.com>2022-12-28 16:23:37 +0100
commit4b63ac4b87c54a1b31d60b7555e2c60d232817c8 (patch)
tree5cfcf092d967d47dbe9a5b8433755211589c19af /lib/system/orc.nim
parent7a74c2dc3a82488671237555faa95fb38ef31bd5 (diff)
downloadNim-4b63ac4b87c54a1b31d60b7555e2c60d232817c8.tar.gz
fixes #21171; dynamic acyclic refs need to use dyn decRef (#21184)
* fixes #21171; dyn destructors for acyclic inherited  refs

* add a test

* Update compiler/liftdestructors.nim
Diffstat (limited to 'lib/system/orc.nim')
-rw-r--r--lib/system/orc.nim13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/system/orc.nim b/lib/system/orc.nim
index 83b983ee1..a56a0c057 100644
--- a/lib/system/orc.nim
+++ b/lib/system/orc.nim
@@ -485,6 +485,19 @@ proc nimDecRefIsLastCyclicDyn(p: pointer): bool {.compilerRtl, inl.} =
     #if cell.color == colPurple:
     rememberCycle(result, cell, cast[ptr PNimTypeV2](p)[])
 
+proc nimDecRefIsLastDyn(p: pointer): bool {.compilerRtl, inl.} =
+  if p != nil:
+    var cell = head(p)
+    if (cell.rc and not rcMask) == 0:
+      result = true
+      #cprintf("[DESTROY] %p\n", p)
+    else:
+      dec cell.rc, rcIncrement
+    #if cell.color == colPurple:
+    if result:
+      if cell.rootIdx > 0:
+        unregisterCycle(cell)
+
 proc nimDecRefIsLastCyclicStatic(p: pointer; desc: PNimTypeV2): bool {.compilerRtl, inl.} =
   if p != nil:
     var cell = head(p)