From 70fa5a6df0dfc3cbe1e046736651788a5fc490af Mon Sep 17 00:00:00 2001 From: Araq Date: Sat, 6 Oct 2012 22:46:41 +0200 Subject: [PATCH] attempt to fix #183 --- lib/system/alloc.nim | 10 +++++++--- tests/compile/mdefaultprocparam.nim | 5 +++++ tests/compile/tdefaultprocparam.nim | 4 ++++ 3 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 tests/compile/mdefaultprocparam.nim create mode 100644 tests/compile/tdefaultprocparam.nim diff --git a/lib/system/alloc.nim b/lib/system/alloc.nim index d6093c5b18..bcc70b853a 100755 --- a/lib/system/alloc.nim +++ b/lib/system/alloc.nim @@ -17,8 +17,9 @@ # some platforms have really weird unmap behaviour: unmap(blockStart, PageSize) # really frees the whole block. Happens for Linux/PowerPC for example. Amd64 -# and x86 are safe though: -const weirdUnmap = not (defined(amd64) or defined(i386)) +# and x86 are safe though; Windows is special because MEM_RELEASE can only be +# used with a size of 0: +const weirdUnmap = not (defined(amd64) or defined(i386)) or defined(windows) when defined(posix): const @@ -75,7 +76,10 @@ elif defined(windows): # This means that the OS has some different view over how big the block is # that we want to free! So, we cannot reliably release the memory back to # Windows :-(. We have to live with MEM_DECOMMIT instead. - when reallyOsDealloc: VirtualFree(p, size, MEM_DECOMMIT) + # Well that used to be the case but MEM_DECOMMIT fragments the address + # space heavily, so we now treat Windows as a strange unmap target. + when reallyOsDealloc: VirtualFree(p, 0, MEM_RELEASE) + #VirtualFree(p, size, MEM_DECOMMIT) else: {.error: "Port memory manager to your platform".} diff --git a/tests/compile/mdefaultprocparam.nim b/tests/compile/mdefaultprocparam.nim new file mode 100644 index 0000000000..4a17277c0b --- /dev/null +++ b/tests/compile/mdefaultprocparam.nim @@ -0,0 +1,5 @@ + + +proc p*(f = (proc(): string = "hi")) = + echo f() + diff --git a/tests/compile/tdefaultprocparam.nim b/tests/compile/tdefaultprocparam.nim new file mode 100644 index 0000000000..23ecf72e92 --- /dev/null +++ b/tests/compile/tdefaultprocparam.nim @@ -0,0 +1,4 @@ + +import mdefaultprocparam + +p()