2019-04-18 00:34:12 -04:00
|
|
|
# test handling of failed heap allocation with memoryview
|
|
|
|
|
|
|
|
import micropython
|
|
|
|
|
2020-03-22 22:26:08 -04:00
|
|
|
|
2019-04-18 00:34:12 -04:00
|
|
|
class GetSlice:
|
|
|
|
def __getitem__(self, idx):
|
|
|
|
return idx
|
2020-03-22 22:26:08 -04:00
|
|
|
|
|
|
|
|
2019-04-18 00:34:12 -04:00
|
|
|
sl = GetSlice()[:]
|
|
|
|
|
|
|
|
# create memoryview
|
|
|
|
micropython.heap_lock()
|
|
|
|
try:
|
|
|
|
memoryview(b"")
|
|
|
|
except MemoryError:
|
|
|
|
print("MemoryError: memoryview create")
|
|
|
|
micropython.heap_unlock()
|
|
|
|
|
|
|
|
# memoryview get with slice
|
|
|
|
m = memoryview(b"")
|
|
|
|
micropython.heap_lock()
|
|
|
|
try:
|
|
|
|
m[sl]
|
|
|
|
except MemoryError:
|
|
|
|
print("MemoryError: memoryview subscr get")
|
|
|
|
micropython.heap_unlock()
|