summary refs log tree commit diff stats
path: root/lib/core
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2019-04-08 23:07:21 +0200
committerAndreas Rumpf <rumpf_a@web.de>2019-04-08 23:07:21 +0200
commit58df5b0a8f9d5d1d6826bd178cbec3f7ea12a499 (patch)
tree467c947e8f5d74a402d3c0377f152174345f6c64 /lib/core
parent430814fdb35a93a1c9e0045756d744253df613c5 (diff)
downloadNim-58df5b0a8f9d5d1d6826bd178cbec3f7ea12a499.tar.gz
allocators.nim: use zero initialization
Diffstat (limited to 'lib/core')
-rw-r--r--lib/core/allocators.nim11
1 files changed, 8 insertions, 3 deletions
diff --git a/lib/core/allocators.nim b/lib/core/allocators.nim
index c4302fc2c..962a99fd6 100644
--- a/lib/core/allocators.nim
+++ b/lib/core/allocators.nim
@@ -29,7 +29,11 @@ var
 
 when defined(useMalloc) and not defined(nimscript):
   import "system/ansi_c"
-  import "system/memory"
+
+import "system/memory"
+
+template `+!`(p: pointer, s: int): pointer =
+  cast[pointer](cast[int](p) +% s)
 
 proc getLocalAllocator*(): Allocator =
   result = localAllocator
@@ -41,7 +45,7 @@ proc getLocalAllocator*(): Allocator =
         # XXX do we need this?
         nimZeroMem(result, size)
       else:
-        result = system.alloc(size)
+        result = system.alloc0(size)
       inc a.allocCount
     result.dealloc = proc (a: Allocator; p: pointer; size: int) {.nimcall, raises: [].} =
       when defined(useMalloc) and not defined(nimscript):
@@ -54,8 +58,9 @@ proc getLocalAllocator*(): Allocator =
         result = c_realloc(p, newSize)
       else:
         result = system.realloc(p, newSize)
+      nimZeroMem(result +! oldSize, newSize - oldSize)
     result.deallocAll = nil
-    result.flags = {ThreadLocal}
+    result.flags = {ThreadLocal, ZerosMem}
     result.name = "nim_local"
     localAllocator = result