This commit is contained in:
Araq 2014-08-08 02:26:56 +02:00
commit 32197b7a13

View file

@ -93,20 +93,27 @@ proc genericDeepCopyAux(dest, src: pointer, mt: PNimType) =
if s2 == nil: if s2 == nil:
unsureAsgnRef(cast[PPointer](dest), s2) unsureAsgnRef(cast[PPointer](dest), s2)
return return
let x = usrToCell(s2) when defined(usrToCell):
let forw = cast[int](x.typ) # unfortunately we only have cycle detection for our native GCs.
if (forw and 1) == 1: let x = usrToCell(s2)
# we stored a forwarding pointer, so let's use that: let forw = cast[int](x.typ)
let z = cast[pointer](forw and not 1) if (forw and 1) == 1:
unsureAsgnRef(cast[PPointer](dest), z) # 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: else:
let realType = x.typ let realType = x.typ
let z = newObj(realType, realType.base.size) let z = newObj(realType, realType.base.size)
unsureAsgnRef(cast[PPointer](dest), z) unsureAsgnRef(cast[PPointer](dest), z)
x.typ = cast[PNimType](cast[int](z) or 1) genericDeepCopyAux(z, s2, realType.base)
genericDeepCopyAux(z, s2, realType.base)
x.typ = realType
of tyPtr: of tyPtr:
# no cycle check here, but also not really required # no cycle check here, but also not really required
if mt.base.deepCopy != nil: if mt.base.deepCopy != nil: