fixup for backward compat

This commit is contained in:
Timothee Cour 2018-11-27 16:49:52 -05:00 committed by zah
parent 3b8e821b85
commit f776d57b3e
2 changed files with 14 additions and 4 deletions

View File

@ -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)

View File

@ -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)