Browse Source
Previous to this patch a call such as list.append(1, 2) would lead to a seg fault. This is because list.append is a builtin method and the first argument to such methods is always assumed to have the correct type. Now, when a builtin method is extracted like this it is wrapped in a checker object which checks the the type of the first argument before calling the builtin function. This feature is contrelled by MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG and is enabled by default. See issue #1216.pull/1338/merge
Damien George
10 years ago
7 changed files with 112 additions and 3 deletions
@ -0,0 +1,12 @@ |
|||
# check that we can use an instance of B in a method of A |
|||
|
|||
class A: |
|||
def store(a, b): |
|||
a.value = b |
|||
|
|||
class B: |
|||
pass |
|||
|
|||
b = B() |
|||
A.store(b, 1) |
|||
print(b.value) |
@ -0,0 +1,31 @@ |
|||
# make sure type of first arg (self) to a builtin method is checked |
|||
|
|||
list.append |
|||
|
|||
try: |
|||
list.append() |
|||
except TypeError as e: |
|||
print("TypeError") |
|||
|
|||
try: |
|||
list.append(1) |
|||
except TypeError as e: |
|||
print("TypeError") |
|||
|
|||
try: |
|||
list.append(1, 2) |
|||
except TypeError as e: |
|||
print("TypeError") |
|||
|
|||
l = [] |
|||
list.append(l, 2) |
|||
print(l) |
|||
|
|||
try: |
|||
getattr(list, "append")(1, 2) |
|||
except TypeError as e: |
|||
print("TypeError") |
|||
|
|||
l = [] |
|||
getattr(list, "append")(l, 2) |
|||
print(l) |
Loading…
Reference in new issue