From 62c1bebe2ef6cf1b7b6afcc5fc5fb5ddc7047b8f Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Thu, 26 Sep 2019 17:20:51 +0200 Subject: [PATCH] ptrops: remove mixin and work around compiler bugs --- stew/ptrops.nim | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/stew/ptrops.nim b/stew/ptrops.nim index 261a65f..4a1dff2 100644 --- a/stew/ptrops.nim +++ b/stew/ptrops.nim @@ -35,9 +35,8 @@ template offset*[T](p: ptr T, count: int): ptr T = # We turn off checking here - too large counts is UB {.checks: off.} - mixin offset let bytes = count * sizeof(T) - cast[ptr T](cast[pointer](p).offset(bytes)) + cast[ptr T](offset(cast[pointer](p), bytes)) template distance*(a, b: pointer): int = ## Number of bytes between a and b - undefined behavior when difference @@ -50,5 +49,4 @@ template distance*[T](a, b: ptr T): int = # Number of elements between a and b - undefined behavior when difference # exceeds what can be represented in an int {.checks: off.} - mixin toMemAddress, distance - cast[pointer](a).distance(cast[pointer](b)) div sizeof(T) + distance(cast[pointer](a), cast[pointer](b)) div sizeof(T)