topttree destructor finally works

This commit is contained in:
Araq 2017-10-24 09:58:07 +02:00
commit 4f2b79a380
5 changed files with 16 additions and 60 deletions

View file

@ -8,6 +8,8 @@ after 20 20'''
cmd: '''nim c --newruntime $file'''
"""
{.this: self.}
type
mystring = object
len, cap: int
@ -46,10 +48,10 @@ proc `=`*(a: var mystring; b: mystring) =
copyMem(a.data, b.data, a.cap+1)
proc resize(self: var mystring) =
if cap == 0: cap = 8
else: cap = (cap * 3) shr 1
if data == nil: inc allocCount
data = cast[type(data)](realloc(data, cap + 1))
if self.cap == 0: self.cap = 8
else: self.cap = (self.cap * 3) shr 1
if self.data == nil: inc allocCount
self.data = cast[type(data)](realloc(self.data, self.cap + 1))
proc add*(self: var mystring; c: char) =
if self.len >= self.cap: resize(self)

View file

@ -3,7 +3,7 @@ discard """
60.0
90.0
120.0
4 1'''
4 4'''
cmd: '''nim c --newruntime $file'''
"""
@ -18,8 +18,8 @@ var
proc `=destroy`*[T](x: var opt[T]) =
if x.data != nil:
when not supportsCopyMem(T):
`=destroy`(x.data[])
#when not supportsCopyMem(T):
`=destroy`(x.data[])
dealloc(x.data)
inc deallocCount
x.data = nil