summary refs log tree commit diff stats
path: root/tests/destructor
diff options
context:
space:
mode:
authorIco Doornekamp <ico@pruts.nl>2020-01-23 14:25:22 +0100
committerAndreas Rumpf <rumpf_a@web.de>2020-01-23 14:25:22 +0100
commitb68eb1cad0dc13d497ae0e620dd2178a6367644c (patch)
tree4456c09a2cf5a964cc1d6cb2cae16dabfa0ff2a8 /tests/destructor
parentf500895efe84525c131beadd2e83b30caa6674a3 (diff)
downloadNim-b68eb1cad0dc13d497ae0e620dd2178a6367644c.tar.gz
Removed lib/system/allocators.nim. seqs_v2 and strs_v2 now uses allocShared0. (#13190)
* Cleanup, remove lib/system/allocators.nim. seqs_v2 and strs_v2 now use
allocShared0 by default.

* Fixed -d:useMalloc allocShared / reallocShared / deallocShared. These now use the alloc/dealloc/realloc implementation that also takes care of zeroing memory at realloc.

* Removed debug printfs

* Removed unpairedEnvAllocs() from tests/destructor/tnewruntime_misc

* More mmdisp cleanups. The shared allocators do not need to zero memory or throw since the regular ones already do that

* Introduced realloc0 and reallocShared0, these procs are now used by
strs_v2 and seqs_v2. This also allowed the -d:useMalloc allocator to
drop the extra header with allocation length.

* Moved strs_v2/seqs_v2 'allocated' flag into 'cap' field

* Added 'getAllocStats()' to get low level alloc/dealloc counters. Enable with -d:allocStats

* *allocShared implementations for boehm and go allocators now depend on the proper *allocImpl procs
Diffstat (limited to 'tests/destructor')
-rw-r--r--tests/destructor/tbintree2.nim10
-rw-r--r--tests/destructor/tgcdestructors.nim10
-rw-r--r--tests/destructor/tnewruntime_misc.nim12
-rw-r--r--tests/destructor/tnewruntime_strutils.nim9
-rw-r--r--tests/destructor/tsimpleclosure.nim8
-rw-r--r--tests/destructor/tuse_ownedref_after_move.nim7
-rw-r--r--tests/destructor/tv2_raise.nim10
-rw-r--r--tests/destructor/twidgets.nim10
-rw-r--r--tests/destructor/twidgets_unown.nim11
9 files changed, 31 insertions, 56 deletions
diff --git a/tests/destructor/tbintree2.nim b/tests/destructor/tbintree2.nim
index 5f88ffff5..6c9047b9a 100644
--- a/tests/destructor/tbintree2.nim
+++ b/tests/destructor/tbintree2.nim
@@ -1,10 +1,9 @@
 discard """
-  cmd: '''nim c --newruntime $file'''
+  cmd: '''nim c -d:allocStats --newruntime $file'''
   output: '''0
-3 3  alloc/dealloc pairs: 0'''
+(allocCount: 6, deallocCount: 6)'''
 """
 
-import system / allocators
 import system / ansi_c
 
 import random
@@ -97,7 +96,6 @@ proc main() =
       discard
   echo res
 
-main()
+dumpAllocStats:
+  main()
 
-let (a, d) = allocCounters()
-discard cprintf("%ld %ld  alloc/dealloc pairs: %ld\n", a, d, system.allocs)
diff --git a/tests/destructor/tgcdestructors.nim b/tests/destructor/tgcdestructors.nim
index 4a66b4f77..c63060af5 100644
--- a/tests/destructor/tgcdestructors.nim
+++ b/tests/destructor/tgcdestructors.nim
@@ -1,5 +1,5 @@
 discard """
-  cmd: '''nim c --newruntime $file'''
+  cmd: '''nim c -d:allocStats --newruntime $file'''
   output: '''hi
 ho
 ha
@@ -10,10 +10,9 @@ a: @[4, 2, 3]
 0
 30
 true
-41 41'''
+(allocCount: 41, deallocCount: 41)'''
 """
 
-import system / allocators
 include system / ansi_c
 
 proc main =
@@ -201,7 +200,4 @@ proc takeAinArray =
 takeAinArray()
 echo ga == "foo"
 
-
-#echo s
-let (a, d) = allocCounters()
-discard cprintf("%ld %ld\n", a, d)
+echo getAllocStats()
diff --git a/tests/destructor/tnewruntime_misc.nim b/tests/destructor/tnewruntime_misc.nim
index 612d1a116..7522bc168 100644
--- a/tests/destructor/tnewruntime_misc.nim
+++ b/tests/destructor/tnewruntime_misc.nim
@@ -1,17 +1,15 @@
 discard """
-  cmd: '''nim cpp --newruntime --threads:on $file'''
+  cmd: '''nim cpp -d:allocStats --newruntime --threads:on $file'''
   output: '''(field: "value")
 Indeed
 axc
 (v: 10)
-0  new: 0
 ...
 destroying GenericObj[T] GenericObj[system.int]
 test
-'''
+(allocCount: 17, deallocCount: 15)'''
 """
 
-import system / allocators
 import system / ansi_c
 
 import tables
@@ -24,6 +22,8 @@ type
 import os
 putEnv("HEAPTRASHING", "Indeed")
 
+let s1 = getAllocStats()
+
 proc main =
   var w = newTable[string, owned Node]()
   w["key"] = Node(field: "value")
@@ -87,9 +87,6 @@ proc testWrongAt() =
 
 testWrongAt()
 
-let (a, d) = allocCounters()
-discard cprintf("%ld  new: %ld\n", a - unpairedEnvAllocs() - d, allocs)
-
 #-------------------------------------------------
 type
   Table[A, B] = object
@@ -134,3 +131,4 @@ proc xx(xml: string): MyObject =
 
 
 discard xx("test")
+echo getAllocStats() - s1
diff --git a/tests/destructor/tnewruntime_strutils.nim b/tests/destructor/tnewruntime_strutils.nim
index 76f2d1a76..27c5a77d5 100644
--- a/tests/destructor/tnewruntime_strutils.nim
+++ b/tests/destructor/tnewruntime_strutils.nim
@@ -1,14 +1,12 @@
 discard """
   valgrind: true
-  cmd: '''nim c --newruntime -d:useMalloc $file'''
+  cmd: '''nim c -d:allocStats --newruntime -d:useMalloc $file'''
   output: '''
-@[(input: @["KXSC", "BGMC"]), (input: @["PXFX"]), (input: @["WXRQ", "ZSCZD"])]
-461 461'''
+@[(input: @["KXSC", "BGMC"]), (input: @["PXFX"]), (input: @["WXRQ", "ZSCZD"])]'''
 """
 
 import strutils, os, std / wordwrap
 
-import system / allocators
 import system / ansi_c
 
 # bug #11004
@@ -213,6 +211,3 @@ staticTests()
 # bug #12965
 let xaa = @[""].join()
 let xbb = @["", ""].join()
-
-let (a, d) = allocCounters()
-discard cprintf("%ld %ld\n", a, d)
diff --git a/tests/destructor/tsimpleclosure.nim b/tests/destructor/tsimpleclosure.nim
index 088f4a95c..bebd1fe72 100644
--- a/tests/destructor/tsimpleclosure.nim
+++ b/tests/destructor/tsimpleclosure.nim
@@ -1,14 +1,13 @@
 discard """
-  cmd: '''nim c --newruntime $file'''
+  cmd: '''nim c -d:allocStats --newruntime $file'''
   output: '''a b
 70
 hello
 hello
 hello
-2 2  alloc/dealloc pairs: 0'''
+(allocCount: 4, deallocCount: 4)'''
 """
 
-import system / allocators
 import system / ansi_c
 
 proc main(): owned(proc()) =
@@ -60,5 +59,4 @@ when false:
 
   stringIter()
 
-let (a, d) = allocCounters()
-discard cprintf("%ld %ld  alloc/dealloc pairs: %ld\n", a, d, system.allocs)
+echo getAllocStats()
diff --git a/tests/destructor/tuse_ownedref_after_move.nim b/tests/destructor/tuse_ownedref_after_move.nim
index 31f580db3..46540837c 100644
--- a/tests/destructor/tuse_ownedref_after_move.nim
+++ b/tests/destructor/tuse_ownedref_after_move.nim
@@ -1,10 +1,9 @@
 discard """
   cmd: '''nim c --newruntime $file'''
-  errormsg: "'=' is not available for type <owned Button>; requires a copy because it's not the last read of ':envAlt.b1'; another read is done here: tuse_ownedref_after_move.nim(53, 4)"
-  line: 49
+  errormsg: "'=' is not available for type <owned Button>; requires a copy because it's not the last read of ':envAlt.b1'; another read is done here: tuse_ownedref_after_move.nim(52, 4)"
+  line: 48
 """
 
-import system / allocators
 import system / ansi_c
 
 type
@@ -56,5 +55,3 @@ proc main =
 
 main()
 
-let (a, d) = allocCounters()
-discard cprintf("%ld %ld  new: %ld\n", a, d, allocs)
diff --git a/tests/destructor/tv2_raise.nim b/tests/destructor/tv2_raise.nim
index 409cdead8..ed5364923 100644
--- a/tests/destructor/tv2_raise.nim
+++ b/tests/destructor/tv2_raise.nim
@@ -1,12 +1,12 @@
 discard """
-  cmd: '''nim c --newruntime $file'''
+  valgrind: true
+  cmd: '''nim c -d:allocStats --newruntime $file'''
   output: '''OK 3
-5 2'''
+(allocCount: 8, deallocCount: 3)'''
 """
 
 import strutils, math
 import system / ansi_c
-import system / allocators
 
 proc mainA =
   try:
@@ -50,6 +50,4 @@ except:
   inc ok
 
 echo "OK ", ok
-
-let (a, d) = allocCounters()
-discard cprintf("%ld %ld\n", a, d)
+echo getAllocStats()
diff --git a/tests/destructor/twidgets.nim b/tests/destructor/twidgets.nim
index 9537748e3..4f32ebfa6 100644
--- a/tests/destructor/twidgets.nim
+++ b/tests/destructor/twidgets.nim
@@ -1,11 +1,10 @@
 discard """
-  cmd: '''nim c --newruntime $file'''
+  cmd: '''nim c -d:allocstats --newruntime $file'''
   output: '''button
 clicked!
-1 1  alloc/dealloc pairs: 0'''
+(allocCount: 4, deallocCount: 4)'''
 """
 
-import system / allocators
 import system / ansi_c
 
 type
@@ -72,7 +71,6 @@ proc main =
 
   w.draw()
 
-main()
+dumpAllocstats:
+  main()
 
-let (a, d) = allocCounters()
-discard cprintf("%ld %ld  alloc/dealloc pairs: %ld\n", a, d, allocs)
diff --git a/tests/destructor/twidgets_unown.nim b/tests/destructor/twidgets_unown.nim
index d594ad54c..333181307 100644
--- a/tests/destructor/twidgets_unown.nim
+++ b/tests/destructor/twidgets_unown.nim
@@ -1,11 +1,10 @@
 discard """
-  cmd: '''nim c --newruntime $file'''
+  cmd: '''nim c -d:allocStats --newruntime $file'''
   output: '''button
 clicked!
-6 6  alloc/dealloc pairs: 0'''
+(allocCount: 9, deallocCount: 9)'''
 """
 
-import system / allocators
 import system / ansi_c
 
 type
@@ -69,7 +68,5 @@ proc main =
   if a != nil:
     a()
 
-main()
-
-let (a, d) = allocCounters()
-discard cprintf("%ld %ld  alloc/dealloc pairs: %ld\n", a, d, allocs)
+dumpAllocStats:
+  main()