make tests green again

This commit is contained in:
Andreas Rumpf 2016-11-22 10:01:51 +01:00
commit 204838b358

View file

@ -9,7 +9,7 @@
## Memory tracking support for Nim. ## Memory tracking support for Nim.
when not defined(memTracker): when not defined(memTracker) and not isMainModule:
{.error: "Memory tracking support is turned off!".} {.error: "Memory tracking support is turned off!".}
{.push memtracker: off.} {.push memtracker: off.}
@ -31,21 +31,22 @@ template sbind(x: int; value) =
if ret != SQLITE_OK: if ret != SQLITE_OK:
quit "could not bind value" quit "could not bind value"
proc logEntries(log: TrackLog) {.nimcall.} = when defined(memTracker):
for i in 0..log.count-1: proc logEntries(log: TrackLog) {.nimcall.} =
var success = false for i in 0..log.count-1:
let e = log.data[i] var success = false
discard sqlite3.reset(insertStmt) let e = log.data[i]
discard clearBindings(insertStmt) discard sqlite3.reset(insertStmt)
sbind 1, e.op discard clearBindings(insertStmt)
sbind(2, cast[int](e.address)) sbind 1, e.op
sbind 3, e.size sbind(2, cast[int](e.address))
sbind 4, e.file sbind 3, e.size
sbind 5, e.line sbind 4, e.file
if step(insertStmt) == SQLITE_DONE: sbind 5, e.line
success = true if step(insertStmt) == SQLITE_DONE:
if not success: success = true
quit "could not write to database!" if not success:
quit "could not write to database!"
proc execQuery(q: string) = proc execQuery(q: string) =
var s: Pstmt 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 (?, ?, ?, ?, ?)" const query = "INSERT INTO tracking(op, address, size, file, line) values (?, ?, ?, ?, ?)"
if prepare_v2(dbHandle, query, if prepare_v2(dbHandle, query,
query.len, insertStmt, nil) == SQLITE_OK: query.len, insertStmt, nil) == SQLITE_OK:
setTrackLogger logEntries when defined(memTracker):
setTrackLogger logEntries
else: else:
quit "could not prepare statement B " & $sqlite3.errmsg(dbHandle) quit "could not prepare statement B " & $sqlite3.errmsg(dbHandle)
{.pop.} {.pop.}