parent
c273496d18
commit
114acff98d
1 changed files with 49 additions and 0 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
discard """
|
discard """
|
||||||
output: '''
|
output: '''
|
||||||
|
=destroy called
|
||||||
123xyzabc
|
123xyzabc
|
||||||
destroyed: false
|
destroyed: false
|
||||||
destroyed: false
|
destroyed: false
|
||||||
|
|
@ -38,6 +39,54 @@ destroying variable: 10
|
||||||
cmd: "nim c --gc:arc --deepcopy:on -d:nimAllocPagesViaMalloc $file"
|
cmd: "nim c --gc:arc --deepcopy:on -d:nimAllocPagesViaMalloc $file"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# bug #9401
|
||||||
|
|
||||||
|
type
|
||||||
|
MyObj = object
|
||||||
|
len: int
|
||||||
|
data: ptr UncheckedArray[float]
|
||||||
|
|
||||||
|
proc `=destroy`*(m: var MyObj) =
|
||||||
|
|
||||||
|
echo "=destroy called"
|
||||||
|
|
||||||
|
if m.data != nil:
|
||||||
|
deallocShared(m.data)
|
||||||
|
m.data = nil
|
||||||
|
|
||||||
|
type
|
||||||
|
MyObjDistinct = distinct MyObj
|
||||||
|
|
||||||
|
proc `=copy`*(m: var MyObj, m2: MyObj) =
|
||||||
|
if m.data == m2.data: return
|
||||||
|
if m.data != nil:
|
||||||
|
`=destroy`(m)
|
||||||
|
m.len = m2.len
|
||||||
|
if m.len > 0:
|
||||||
|
m.data = cast[ptr UncheckedArray[float]](allocShared(sizeof(float) * m.len))
|
||||||
|
copyMem(m.data, m2.data, sizeof(float) * m.len)
|
||||||
|
|
||||||
|
|
||||||
|
proc `=sink`*(m: var MyObj, m2: MyObj) =
|
||||||
|
if m.data != m2.data:
|
||||||
|
if m.data != nil:
|
||||||
|
`=destroy`(m)
|
||||||
|
m.len = m2.len
|
||||||
|
m.data = m2.data
|
||||||
|
|
||||||
|
proc newMyObj(len: int): MyObj =
|
||||||
|
result.len = len
|
||||||
|
result.data = cast[ptr UncheckedArray[float]](allocShared(sizeof(float) * len))
|
||||||
|
|
||||||
|
proc newMyObjDistinct(len: int): MyObjDistinct =
|
||||||
|
MyObjDistinct(newMyObj(len))
|
||||||
|
|
||||||
|
proc fooDistinct =
|
||||||
|
doAssert newMyObjDistinct(2).MyObj.len == 2
|
||||||
|
|
||||||
|
fooDistinct()
|
||||||
|
|
||||||
|
|
||||||
proc takeSink(x: sink string): bool = true
|
proc takeSink(x: sink string): bool = true
|
||||||
|
|
||||||
proc b(x: sink string): string =
|
proc b(x: sink string): string =
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue