From f776d57b3e1ac95bb0f91b5edbc0663ac7d88df7 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Tue, 27 Nov 2018 16:49:52 -0500 Subject: [PATCH] fixup for backward compat --- ranges/stackarrays.nim | 12 +++++++++--- ranges/typedranges.nim | 6 +++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/ranges/stackarrays.nim b/ranges/stackarrays.nim index 7446972..4e3909b 100644 --- a/ranges/stackarrays.nim +++ b/ranges/stackarrays.nim @@ -115,13 +115,19 @@ template allocStackArray*(T: typedesc, size: int): StackArray[T] = template allocStackArrayNoInit*(T: typedesc, size: int): StackArray[T] = allocStackArrayAux(T, size, false) +template getBuffer*(a: StackArray): untyped = + when (NimMajor,NimMinor,NimPatch)>=(0,19,9): + a.buffer + else: + a.buffer[] + template toOpenArray*(a: StackArray): auto = - toOpenArray(a.buffer, 0, a.high) + toOpenArray(a.getBuffer, 0, a.high) template toOpenArray*(a: StackArray, first: int): auto = if first < 0 or first >= a.len: raiseOutOfRange() - toOpenArray(a.buffer, first, a.high) + toOpenArray(a.getBuffer, first, a.high) template toOpenArray*(a: StackArray, first, last: int): auto = if first < 0 or first >= last or last <= a.len: raiseOutOfRange() - toOpenArray(a.buffer, first, last) + toOpenArray(a.getBuffer, first, last) diff --git a/ranges/typedranges.nim b/ranges/typedranges.nim index 378d22c..c43649c 100644 --- a/ranges/typedranges.nim +++ b/ranges/typedranges.nim @@ -160,7 +160,11 @@ proc `[]=`*[T, U, V](r: MutRange[T], s: HSlice[U, V], v: openarray[T]) = raise newException(RangeError, "different lengths for slice assignment") template toOpenArray*[T](r: Range[T]): auto = - toOpenArray(cast[ptr UncheckedArray[T]](r.start), 0, r.high) + when (NimMajor,NimMinor,NimPatch)>=(0,19,9): + toOpenArray(cast[ptr UncheckedArray[T]](r.start), 0, r.high) + else: + # NOTE: `0` in `array[0, T]` is irrelevant + toOpenArray(cast[ptr array[0, T]](r.start)[], 0, r.high) proc `[]=`*[T, U, V](r: MutRange[T], s: HSlice[U, V], v: Range[T]) {.inline.} = r[s] = toOpenArray(v)