summary refs log tree commit diff stats
path: root/lib/pure/nimtracker.nim
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2016-11-22 10:01:51 +0100
committerAndreas Rumpf <rumpf_a@web.de>2016-11-22 10:01:51 +0100
commit204838b3585d13ea88d3b8ac8e7f0fc19e55f3e9 (patch)
treef731c5aa90b665688fb53a86bdb846af479103de /lib/pure/nimtracker.nim
parent83ffc6bf54aa3c8151f5b079c957bd5845227344 (diff)
downloadNim-204838b3585d13ea88d3b8ac8e7f0fc19e55f3e9.tar.gz
make tests green again
Diffstat (limited to 'lib/pure/nimtracker.nim')
-rw-r--r--lib/pure/nimtracker.nim36
1 files changed, 19 insertions, 17 deletions
diff --git a/lib/pure/nimtracker.nim b/lib/pure/nimtracker.nim
index b5072419f..db29b4252 100644
--- a/lib/pure/nimtracker.nim
+++ b/lib/pure/nimtracker.nim
@@ -9,7 +9,7 @@
 
 ## Memory tracking support for Nim.
 
-when not defined(memTracker):
+when not defined(memTracker) and not isMainModule:
   {.error: "Memory tracking support is turned off!".}
 
 {.push memtracker: off.}
@@ -31,21 +31,22 @@ template sbind(x: int; value) =
     if ret != SQLITE_OK:
       quit "could not bind value"
 
-proc logEntries(log: TrackLog) {.nimcall.} =
-  for i in 0..log.count-1:
-    var success = false
-    let e = log.data[i]
-    discard sqlite3.reset(insertStmt)
-    discard clearBindings(insertStmt)
-    sbind 1, e.op
-    sbind(2, cast[int](e.address))
-    sbind 3, e.size
-    sbind 4, e.file
-    sbind 5, e.line
-    if step(insertStmt) == SQLITE_DONE:
-      success = true
-    if not success:
-      quit "could not write to database!"
+when defined(memTracker):
+  proc logEntries(log: TrackLog) {.nimcall.} =
+    for i in 0..log.count-1:
+      var success = false
+      let e = log.data[i]
+      discard sqlite3.reset(insertStmt)
+      discard clearBindings(insertStmt)
+      sbind 1, e.op
+      sbind(2, cast[int](e.address))
+      sbind 3, e.size
+      sbind 4, e.file
+      sbind 5, e.line
+      if step(insertStmt) == SQLITE_DONE:
+        success = true
+      if not success:
+        quit "could not write to database!"
 
 proc execQuery(q: string) =
   var s: Pstmt
@@ -72,7 +73,8 @@ if sqlite3.open("memtrack.db", dbHandle) == SQLITE_OK:
   const query = "INSERT INTO tracking(op, address, size, file, line) values (?, ?, ?, ?, ?)"
   if prepare_v2(dbHandle, query,
       query.len, insertStmt, nil) == SQLITE_OK:
-    setTrackLogger logEntries
+    when defined(memTracker):
+      setTrackLogger logEntries
   else:
     quit "could not prepare statement B " & $sqlite3.errmsg(dbHandle)
 {.pop.}