From 2abf3b717abfd623c89893e14037c34b73ef99f1 Mon Sep 17 00:00:00 2001 From: GrundleTrundle Date: Sat, 21 Feb 2015 14:54:45 -0500 Subject: Removed int64 -> int downcast in timers.`-` On windows when compiling on 32 bit, this can get you a out of range exception for an otherwise valid interval. --- lib/system/timers.nim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/system/timers.nim b/lib/system/timers.nim index e58ff7adc..e5de791ac 100644 --- a/lib/system/timers.nim +++ b/lib/system/timers.nim @@ -27,9 +27,9 @@ when defined(windows): proc `-`(a, b: TTicks): TNanos = var frequency: int64 QueryPerformanceFrequency(frequency) - var performanceCounterRate = 1000000000.0 / toFloat(frequency.int) + var performanceCounterRate = 1e+9'f64 / float64(frequency) - result = ((a.int64 - b.int64).int.toFloat * performanceCounterRate).TNanos + result = TNanos(float64(a.int64 - b.int64) * performanceCounterRate) elif defined(macosx): type -- cgit 1.4.1-2-gfad0 From c41e0bdbe32f1f08951aef6e746265775b1ecba8 Mon Sep 17 00:00:00 2001 From: GrundleTrundle Date: Sat, 21 Feb 2015 14:57:07 -0500 Subject: Changed nimprof.hook() to handle uninitialized t0 It's unlikely, but possible for the conversion to nanoseconds to overflow if QueryPerformanceCounter() returns a large enough timestamp. This change avoids that, at the cost of always taking a sample the first time through when t0 == 0. --- lib/pure/nimprof.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pure/nimprof.nim b/lib/pure/nimprof.nim index 3598cdd3a..cce2a20ae 100644 --- a/lib/pure/nimprof.nim +++ b/lib/pure/nimprof.nim @@ -132,7 +132,7 @@ else: proc hook(st: TStackTrace) {.nimcall.} = if interval == 0: hookAux(st, 1) - elif getTicks() - t0 > interval: + elif int64(t0) == 0 or getTicks() - t0 > interval: hookAux(st, 1) t0 = getTicks() -- cgit 1.4.1-2-gfad0