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