123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- discard """
- cmd: '''nim cpp -d:nimAllocStats --newruntime --threads:on $file'''
- output: '''(field: "value")
- Indeed
- axc
- (v: 10)
- ...
- destroying GenericObj[T] GenericObj[system.int]
- test
- (allocCount: 13, deallocCount: 11)
- 3'''
- """
- import system / ansi_c
- import tables
- type
- Node = ref object
- field: string
- # bug #11807
- import os
- putEnv("HEAPTRASHING", "Indeed")
- let s1 = getAllocStats()
- proc main =
- var w = newTable[string, owned Node]()
- w["key"] = Node(field: "value")
- echo w["key"][]
- echo getEnv("HEAPTRASHING")
- # bug #11891
- var x = "abc"
- x[1] = 'x'
- echo x
- main()
- # bug #11745
- type
- Foo = object
- bar: seq[int]
- var x = [Foo()]
- # bug #11563
- type
- MyTypeType = enum
- Zero, One
- MyType = object
- case kind: MyTypeType
- of Zero:
- s*: seq[MyType]
- of One:
- x*: int
- var t: MyType
- # bug #11254
- proc test(p: owned proc()) =
- let x = (proc())p
- test(proc() = discard)
- # bug #10689
- type
- O = object
- v: int
- proc `=sink`(d: var O, s: O) =
- d.v = s.v
- proc selfAssign =
- var o = O(v: 10)
- o = o
- echo o
- selfAssign()
- # bug #11833
- type FooAt = object
- proc testWrongAt() =
- var x = @[@[FooAt()]]
- testWrongAt()
- #-------------------------------------------------
- type
- Table[A, B] = object
- x: seq[(A, B)]
- proc toTable[A,B](p: sink openArray[(A, B)]): Table[A, B] =
- for zz in mitems(p):
- result.x.add move(zz)
- let table = {"a": new(int)}.toTable()
- # bug # #12051
- type
- GenericObj[T] = object
- val: T
- Generic[T] = owned ref GenericObj[T]
- proc `=destroy`[T](x: var GenericObj[T]) =
- echo "destroying GenericObj[T] ", x.typeof # to know when its being destroyed
- proc main12() =
- let gnrc = Generic[int](val: 42)
- echo "..."
- main12()
- #####################################################################
- ## bug #12827
- type
- MyObject = object
- x: string
- y: seq[string]
- needs_ref: ref int
- proc xx(xml: string): MyObject =
- let stream = xml
- result.x = xml
- defer: echo stream
- discard xx("test")
- echo getAllocStats() - s1
- # bug #13457
- var s = "abcde"
- s.setLen(3)
- echo s.cstring.len
|