Skip to content

Commit 693f87e

Browse files
author
Ico Doornekamp
committed
*allocShared implementations for boehm and go allocators now depend on the proper *allocImpl procs
1 parent 00742d2 commit 693f87e

File tree

9 files changed

+28
-33
lines changed

9 files changed

+28
-33
lines changed

lib/system/alloc.nim

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,10 +1050,10 @@ template instantiateForRegion(allocator: untyped) {.dirty.} =
10501050
result = alloc(sharedHeap, size)
10511051
releaseSys(heapLock)
10521052
else:
1053-
result = alloc(size)
1053+
result = allocImpl(size)
10541054

10551055
proc allocShared0Impl(size: Natural): pointer =
1056-
result = allocShared(size)
1056+
result = allocSharedImpl(size)
10571057
zeroMem(result, size)
10581058

10591059
proc deallocSharedImpl(p: pointer) =
@@ -1062,23 +1062,23 @@ template instantiateForRegion(allocator: untyped) {.dirty.} =
10621062
dealloc(sharedHeap, p)
10631063
releaseSys(heapLock)
10641064
else:
1065-
dealloc(p)
1065+
deallocImpl(p)
10661066

10671067
proc reallocSharedImpl(p: pointer, newSize: Natural): pointer =
10681068
when hasThreadSupport:
10691069
acquireSys(heapLock)
10701070
result = realloc(sharedHeap, p, newSize)
10711071
releaseSys(heapLock)
10721072
else:
1073-
result = realloc(p, newSize)
1073+
result = reallocImpl(p, newSize)
10741074

10751075
proc reallocShared0Impl(p: pointer, oldSize, newSize: Natural): pointer =
10761076
when hasThreadSupport:
10771077
acquireSys(heapLock)
10781078
result = realloc0(sharedHeap, p, oldSize, newSize)
10791079
releaseSys(heapLock)
10801080
else:
1081-
result = realloc0(p, oldSize, newSize)
1081+
result = realloc0Impl(p, oldSize, newSize)
10821082

10831083
when hasThreadSupport:
10841084
template sharedMemStatsShared(v: int) =

lib/system/mmdisp.nim

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,11 @@ when defined(boehmgc):
122122
zeroMem(cast[pointer](cast[int](result) + oldsize), newsize - oldsize)
123123
proc deallocImpl(p: pointer) = boehmDealloc(p)
124124

125-
proc allocSharedImpl(size: Natural): pointer = alloc(size)
126-
proc allocShared0Impl(size: Natural): pointer = alloc(size)
127-
proc reallocSharedImpl(p: pointer, newSize: Natural): pointer = realloc(p, newSize)
128-
proc reallocShared0Impl(p: pointer, oldSize, newSize: Natural): pointer = realloc0Impl(p, newSize, oldSize)
129-
proc deallocSharedImpl(p: pointer) = dealloc(p)
125+
proc allocSharedImpl(size: Natural): pointer = allocImpl(size)
126+
proc allocShared0Impl(size: Natural): pointer = alloc0Impl(size)
127+
proc reallocSharedImpl(p: pointer, newsize: Natural): pointer = reallocImpl(p, newsize)
128+
proc reallocShared0Impl(p: pointer, oldsize, newsize: Natural): pointer = realloc0Impl(p, oldsize, newsize)
129+
proc deallocSharedImpl(p: pointer) = deallocImpl(p)
130130

131131
when hasThreadSupport:
132132
proc getFreeSharedMem(): int =
@@ -281,19 +281,11 @@ elif defined(gogc):
281281
proc deallocImpl(p: pointer) =
282282
discard
283283

284-
proc allocSharedImpl(size: Natural): pointer =
285-
result = alloc(size)
286-
287-
proc allocShared0Impl(size: Natural): pointer =
288-
result = alloc0(size)
289-
290-
proc reallocSharedImpl(p: pointer, newsize: Natural): pointer =
291-
result = realloc(p, newsize)
292-
293-
proc reallocShared0Impl(p: pointer, oldsize, newsize: Natural): pointer =
294-
result = realloc0(p, oldsize, newsize)
295-
296-
proc deallocSharedImpl(p: pointer) = dealloc(p)
284+
proc allocSharedImpl(size: Natural): pointer = allocImpl(size)
285+
proc allocShared0Impl(size: Natural): pointer = alloc0Impl(size)
286+
proc reallocSharedImpl(p: pointer, newsize: Natural): pointer = reallocImpl(p, newsize)
287+
proc reallocShared0Impl(p: pointer, oldsize, newsize: Natural): pointer = realloc0Impl(p, oldsize, newsize)
288+
proc deallocSharedImpl(p: pointer) = deallocImpl(p)
297289

298290
when hasThreadSupport:
299291
proc getFreeSharedMem(): int = discard

tests/destructor/tbintree2.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
discard """
22
cmd: '''nim c -d:allocStats --newruntime $file'''
33
output: '''0
4-
(allocCount: 12, deallocCount: 9)'''
4+
(allocCount: 6, deallocCount: 6)'''
55
"""
66

77
import system / ansi_c

tests/destructor/tgcdestructors.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ a: @[4, 2, 3]
1010
0
1111
30
1212
true
13-
(allocCount: 123, deallocCount: 82)'''
13+
(allocCount: 41, deallocCount: 41)'''
1414
"""
1515

1616
include system / ansi_c

tests/destructor/tnewruntime_misc.nim

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ axc
77
...
88
destroying GenericObj[T] GenericObj[system.int]
99
test
10-
(allocCount: 34, deallocCount: 15)'''
10+
(allocCount: 7, deallocCount: 5)'''
1111
"""
1212

1313
import system / ansi_c
@@ -22,8 +22,6 @@ type
2222
import os
2323
putEnv("HEAPTRASHING", "Indeed")
2424

25-
let s1 = getAllocStats()
26-
2725
proc main =
2826
var w = newTable[string, owned Node]()
2927
w["key"] = Node(field: "value")
@@ -37,6 +35,8 @@ proc main =
3735

3836
main()
3937

38+
let s1 = getAllocStats()
39+
4040
# bug #11745
4141

4242
type
@@ -131,4 +131,6 @@ proc xx(xml: string): MyObject =
131131

132132

133133
discard xx("test")
134-
echo getAllocStats() - s1
134+
135+
let s2 = getAllocStats()
136+
echo $(s2-s1)

tests/destructor/tsimpleclosure.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ discard """
55
hello
66
hello
77
hello
8-
(allocCount: 8, deallocCount: 6)'''
8+
(allocCount: 4, deallocCount: 4)'''
99
"""
1010

1111
import system / ansi_c

tests/destructor/tv2_raise.nim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
discard """
2+
valgrind: true
23
cmd: '''nim c -d:allocStats --newruntime $file'''
34
output: '''OK 3
4-
(allocCount: 18, deallocCount: 5)'''
5+
(allocCount: 8, deallocCount: 3)'''
56
"""
67

78
import strutils, math

tests/destructor/twidgets.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ discard """
22
cmd: '''nim c -d:allocstats --newruntime $file'''
33
output: '''button
44
clicked!
5-
(allocCount: 6, deallocCount: 5)'''
5+
(allocCount: 4, deallocCount: 4)'''
66
"""
77

88
import system / ansi_c

tests/destructor/twidgets_unown.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ discard """
22
cmd: '''nim c -d:allocStats --newruntime $file'''
33
output: '''button
44
clicked!
5-
(allocCount: 21, deallocCount: 15)'''
5+
(allocCount: 9, deallocCount: 9)'''
66
"""
77

88
import system / ansi_c

0 commit comments

Comments
 (0)