Skip to content

Commit 05aebb9

Browse files
committed
tests/heapalloc_inst_call: Test for no alloc for simple object calls.
1 parent 492c612 commit 05aebb9

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Test that calling clazz.__call__() with up to at least 3 arguments
2+
# doesn't require heap allocation.
3+
import micropython
4+
5+
class Foo0:
6+
def __call__(self):
7+
print("__call__")
8+
9+
class Foo1:
10+
def __call__(self, a):
11+
print("__call__", a)
12+
13+
class Foo2:
14+
def __call__(self, a, b):
15+
print("__call__", a, b)
16+
17+
class Foo3:
18+
def __call__(self, a, b, c):
19+
print("__call__", a, b, c)
20+
21+
f0 = Foo0()
22+
f1 = Foo1()
23+
f2 = Foo2()
24+
f3 = Foo3()
25+
26+
micropython.heap_lock()
27+
f0()
28+
f1(1)
29+
f2(1, 2)
30+
f3(1, 2, 3)
31+
micropython.heap_unlock()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
__call__
2+
__call__ 1
3+
__call__ 1 2
4+
__call__ 1 2 3

0 commit comments

Comments
 (0)