← index #6523Issue #1380
Related · high · value 3.305
QUERY · ISSUE

Taking slice of memoryview in Viper function crashes PyBoard

openby twisteroidambassadoropened 2020-10-07updated 2025-07-02
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

closedby peterhinchopened 2015-07-13updated 2015-07-23

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.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied