2019-04-18 14:34:12 +10:00
|
|
|
# test handling of failed heap allocation with dict
|
|
|
|
|
|
|
|
import micropython
|
|
|
|
|
|
|
|
# create dict
|
|
|
|
x = 1
|
|
|
|
micropython.heap_lock()
|
|
|
|
try:
|
2020-03-22 21:26:08 -05:00
|
|
|
{x: x}
|
2019-04-18 14:34:12 +10:00
|
|
|
except MemoryError:
|
2020-03-22 21:26:08 -05:00
|
|
|
print("MemoryError: create dict")
|
2019-04-18 14:34:12 +10:00
|
|
|
micropython.heap_unlock()
|
|
|
|
|
|
|
|
# create dict view
|
2020-03-22 21:26:08 -05:00
|
|
|
x = {1: 1}
|
2019-04-18 14:34:12 +10:00
|
|
|
micropython.heap_lock()
|
|
|
|
try:
|
|
|
|
x.items()
|
|
|
|
except MemoryError:
|
2020-03-22 21:26:08 -05:00
|
|
|
print("MemoryError: dict.items")
|
2019-04-18 14:34:12 +10:00
|
|
|
micropython.heap_unlock()
|