QUERY · ISSUE
Taking slice of memoryview in Viper function crashes PyBoard
bugpy-core
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.
CANDIDATE · ISSUE
viper code fails if a function has an unused argument
This manifests itself in various ways, including a hard to debug case where code ran but produced incorrect results. The following example bar.py can crash the Pyboard.
@micropython.viper
def foo(line: int, pixelmask: int, offset: int, unused_arg: int):
index = 0
buf = bytearray(10)
image = bytearray([1,1,1,1,1,1,1,1,1,1])
for b in range(10, 0, -1):
buf[index] = int(image[offset + b - 1]) ^ pixelmask | 0xaa
index += 1
print(buf)
foo(0, 0, 0, 0)
At the REPL if import bar is issued nothing happens (it should print the buffer contents). A subsequent bar.foo(0,0,0,0) crashes the board. Unused arguments should either be ignored or a compile time error should be issued.