Taking slice of memoryview in Viper function crashes PyBoard
On a PyBoard v1.1 with firmware 1.13, put the following code into a file:
import micropython
@micropython.viper
def take_memoryview_slice():
ba = bytearray(10)
mv = memoryview(ba)
slice = mv[0:1]
Running take_memoryview_slice() resets the PyBoard.
py/objarray: Raise error on out-of-bound memoryview slice start.
32 bit platforms only support a slice offset start of 24 bit max due to the limited size of https://github.com/micropython/micropython/blob/9dfabcd6d3d080aced888e8474e921f11dc979bb/py/objarray.h#L47
As it stands, if a memoryview object is sliced with a start index of 16MB or more then it's aliased back to the start of the array providing incorrect results.
I initially tried to increase the size of size_t free in the link above when used on a 32bit platform, however this breaks a lot more. Not sure why, presuably the total size of that structure is hardcoded / assumed elsewhere perhaps?
For now, this PR just raises an exception if the start index is too high to prevent accidental use of the wrong data.