diff options
author | Araq <rumpf_a@web.de> | 2014-08-08 02:26:56 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2014-08-08 02:26:56 +0200 |
commit | 32197b7a130a7abb188cd2b2d386272571396c65 (patch) | |
tree | fe1e2f1f7b8bafd93b3d6da8d6b0e5f4649c52fe /lib | |
parent | 68accb53c4b7bd6740bad21c21bcc633a745874a (diff) | |
download | Nim-32197b7a130a7abb188cd2b2d386272571396c65.tar.gz |
fixes #1456
Diffstat (limited to 'lib')
-rw-r--r-- | lib/system/deepcopy.nim | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/lib/system/deepcopy.nim b/lib/system/deepcopy.nim index 5c10ef9ed..36ceb9ef9 100644 --- a/lib/system/deepcopy.nim +++ b/lib/system/deepcopy.nim @@ -93,20 +93,27 @@ proc genericDeepCopyAux(dest, src: pointer, mt: PNimType) = if s2 == nil: unsureAsgnRef(cast[PPointer](dest), s2) return - let x = usrToCell(s2) - let forw = cast[int](x.typ) - if (forw and 1) == 1: - # we stored a forwarding pointer, so let's use that: - let z = cast[pointer](forw and not 1) - unsureAsgnRef(cast[PPointer](dest), z) + when defined(usrToCell): + # unfortunately we only have cycle detection for our native GCs. + let x = usrToCell(s2) + let forw = cast[int](x.typ) + if (forw and 1) == 1: + # we stored a forwarding pointer, so let's use that: + let z = cast[pointer](forw and not 1) + unsureAsgnRef(cast[PPointer](dest), z) + else: + let realType = x.typ + let z = newObj(realType, realType.base.size) + + unsureAsgnRef(cast[PPointer](dest), z) + x.typ = cast[PNimType](cast[int](z) or 1) + genericDeepCopyAux(z, s2, realType.base) + x.typ = realType else: let realType = x.typ - let z = newObj(realType, realType.base.size) - + let z = newObj(realType, realType.base.size) unsureAsgnRef(cast[PPointer](dest), z) - x.typ = cast[PNimType](cast[int](z) or 1) - genericDeepCopyAux(z, s2, realType.base) - x.typ = realType + genericDeepCopyAux(z, s2, realType.base) of tyPtr: # no cycle check here, but also not really required if mt.base.deepCopy != nil: |