Skip to content

Commit

Permalink
*allocShared implementations for boehm and go allocators now depend o…
Browse files Browse the repository at this point in the history
…n the proper *allocImpl procs
  • Loading branch information
Ico Doornekamp authored and zevv committed Jan 21, 2020
1 parent 00742d2 commit 13f9bb8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 25 deletions.
10 changes: 5 additions & 5 deletions lib/system/alloc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1050,10 +1050,10 @@ template instantiateForRegion(allocator: untyped) {.dirty.} =
result = alloc(sharedHeap, size)
releaseSys(heapLock)
else:
result = alloc(size)
result = allocImpl(size)

proc allocShared0Impl(size: Natural): pointer =
result = allocShared(size)
result = allocSharedImpl(size)
zeroMem(result, size)

proc deallocSharedImpl(p: pointer) =
Expand All @@ -1062,23 +1062,23 @@ template instantiateForRegion(allocator: untyped) {.dirty.} =
dealloc(sharedHeap, p)
releaseSys(heapLock)
else:
dealloc(p)
deallocImpl(p)

proc reallocSharedImpl(p: pointer, newSize: Natural): pointer =
when hasThreadSupport:
acquireSys(heapLock)
result = realloc(sharedHeap, p, newSize)
releaseSys(heapLock)
else:
result = realloc(p, newSize)
result = reallocImpl(p, newSize)

proc reallocShared0Impl(p: pointer, oldSize, newSize: Natural): pointer =
when hasThreadSupport:
acquireSys(heapLock)
result = realloc0(sharedHeap, p, oldSize, newSize)
releaseSys(heapLock)
else:
result = realloc0(p, oldSize, newSize)
result = realloc0Impl(p, oldSize, newSize)

when hasThreadSupport:
template sharedMemStatsShared(v: int) =
Expand Down
28 changes: 10 additions & 18 deletions lib/system/mmdisp.nim
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ when defined(boehmgc):
zeroMem(cast[pointer](cast[int](result) + oldsize), newsize - oldsize)
proc deallocImpl(p: pointer) = boehmDealloc(p)

proc allocSharedImpl(size: Natural): pointer = alloc(size)
proc allocShared0Impl(size: Natural): pointer = alloc(size)
proc reallocSharedImpl(p: pointer, newSize: Natural): pointer = realloc(p, newSize)
proc reallocShared0Impl(p: pointer, oldSize, newSize: Natural): pointer = realloc0Impl(p, newSize, oldSize)
proc deallocSharedImpl(p: pointer) = dealloc(p)
proc allocSharedImpl(size: Natural): pointer = allocImpl(size)
proc allocShared0Impl(size: Natural): pointer = alloc0Impl(size)
proc reallocSharedImpl(p: pointer, newsize: Natural): pointer = reallocImpl(p, newsize)
proc reallocShared0Impl(p: pointer, oldsize, newsize: Natural): pointer = realloc0Impl(p, oldsize, newsize)
proc deallocSharedImpl(p: pointer) = deallocImpl(p)

when hasThreadSupport:
proc getFreeSharedMem(): int =
Expand Down Expand Up @@ -281,19 +281,11 @@ elif defined(gogc):
proc deallocImpl(p: pointer) =
discard

proc allocSharedImpl(size: Natural): pointer =
result = alloc(size)

proc allocShared0Impl(size: Natural): pointer =
result = alloc0(size)

proc reallocSharedImpl(p: pointer, newsize: Natural): pointer =
result = realloc(p, newsize)

proc reallocShared0Impl(p: pointer, oldsize, newsize: Natural): pointer =
result = realloc0(p, oldsize, newsize)

proc deallocSharedImpl(p: pointer) = dealloc(p)
proc allocSharedImpl(size: Natural): pointer = allocImpl(size)
proc allocShared0Impl(size: Natural): pointer = alloc0Impl(size)
proc reallocSharedImpl(p: pointer, newsize: Natural): pointer = reallocImpl(p, newsize)
proc reallocShared0Impl(p: pointer, oldsize, newsize: Natural): pointer = realloc0Impl(p, oldsize, newsize)
proc deallocSharedImpl(p: pointer) = deallocImpl(p)

when hasThreadSupport:
proc getFreeSharedMem(): int = discard
Expand Down
2 changes: 1 addition & 1 deletion tests/destructor/tbintree2.nim
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
discard """
cmd: '''nim c -d:allocStats --newruntime $file'''
output: '''0
(allocCount: 12, deallocCount: 9)'''
(allocCount: 6, deallocCount: 6)'''
"""

import system / ansi_c
Expand Down
2 changes: 1 addition & 1 deletion tests/destructor/tgcdestructors.nim
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ a: @[4, 2, 3]
0
30
true
(allocCount: 123, deallocCount: 82)'''
(allocCount: 41, deallocCount: 41)'''
"""

include system / ansi_c
Expand Down

0 comments on commit 13f9bb8

Please sign in to comment.