From 13f9bb8d9911c7afb68d6734c9c1d9e1c9cdbec5 Mon Sep 17 00:00:00 2001 From: Ico Doornekamp Date: Mon, 20 Jan 2020 20:44:39 +0100 Subject: [PATCH] *allocShared implementations for boehm and go allocators now depend on the proper *allocImpl procs --- lib/system/alloc.nim | 10 +++++----- lib/system/mmdisp.nim | 28 ++++++++++------------------ tests/destructor/tbintree2.nim | 2 +- tests/destructor/tgcdestructors.nim | 2 +- 4 files changed, 17 insertions(+), 25 deletions(-) diff --git a/lib/system/alloc.nim b/lib/system/alloc.nim index 0c220f9b1307c..59b7fcfd96e35 100644 --- a/lib/system/alloc.nim +++ b/lib/system/alloc.nim @@ -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) = @@ -1062,7 +1062,7 @@ template instantiateForRegion(allocator: untyped) {.dirty.} = dealloc(sharedHeap, p) releaseSys(heapLock) else: - dealloc(p) + deallocImpl(p) proc reallocSharedImpl(p: pointer, newSize: Natural): pointer = when hasThreadSupport: @@ -1070,7 +1070,7 @@ template instantiateForRegion(allocator: untyped) {.dirty.} = 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: @@ -1078,7 +1078,7 @@ template instantiateForRegion(allocator: untyped) {.dirty.} = 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) = diff --git a/lib/system/mmdisp.nim b/lib/system/mmdisp.nim index 9336857245874..1f42f1aa5358d 100644 --- a/lib/system/mmdisp.nim +++ b/lib/system/mmdisp.nim @@ -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 = @@ -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 diff --git a/tests/destructor/tbintree2.nim b/tests/destructor/tbintree2.nim index 273f41dd2bf57..6c9047b9a99a2 100644 --- a/tests/destructor/tbintree2.nim +++ b/tests/destructor/tbintree2.nim @@ -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 diff --git a/tests/destructor/tgcdestructors.nim b/tests/destructor/tgcdestructors.nim index 44e970d19a8c1..c63060af54bf1 100644 --- a/tests/destructor/tgcdestructors.nim +++ b/tests/destructor/tgcdestructors.nim @@ -10,7 +10,7 @@ a: @[4, 2, 3] 0 30 true -(allocCount: 123, deallocCount: 82)''' +(allocCount: 41, deallocCount: 41)''' """ include system / ansi_c