kopia lustrzana https://github.com/micropython/micropython
py/objtype: Fix assertion failures in super_attr by checking type.
Fixes assertion failures and segmentation faults when making calls like: super(1, 1).xpull/3829/head
rodzic
05b13fd292
commit
c60589c02b
|
@ -1112,6 +1112,9 @@ STATIC mp_obj_t super_make_new(const mp_obj_type_t *type_in, size_t n_args, size
|
||||||
// 0 arguments are turned into 2 in the compiler
|
// 0 arguments are turned into 2 in the compiler
|
||||||
// 1 argument is not yet implemented
|
// 1 argument is not yet implemented
|
||||||
mp_arg_check_num(n_args, n_kw, 2, 2, false);
|
mp_arg_check_num(n_args, n_kw, 2, 2, false);
|
||||||
|
if (!MP_OBJ_IS_TYPE(args[0], &mp_type_type)) {
|
||||||
|
mp_raise_TypeError(NULL);
|
||||||
|
}
|
||||||
mp_obj_super_t *o = m_new_obj(mp_obj_super_t);
|
mp_obj_super_t *o = m_new_obj(mp_obj_super_t);
|
||||||
*o = (mp_obj_super_t){{type_in}, args[0], args[1]};
|
*o = (mp_obj_super_t){{type_in}, args[0], args[1]};
|
||||||
return MP_OBJ_FROM_PTR(o);
|
return MP_OBJ_FROM_PTR(o);
|
||||||
|
|
|
@ -35,6 +35,12 @@ class B(A):
|
||||||
return super().foo().count(2) # calling a subsequent method
|
return super().foo().count(2) # calling a subsequent method
|
||||||
print(B().foo())
|
print(B().foo())
|
||||||
|
|
||||||
|
# first arg to super must be a type
|
||||||
|
try:
|
||||||
|
super(1, 1)
|
||||||
|
except TypeError:
|
||||||
|
print('TypeError')
|
||||||
|
|
||||||
# store/delete of super attribute not allowed
|
# store/delete of super attribute not allowed
|
||||||
assert hasattr(super(B, B()), 'foo')
|
assert hasattr(super(B, B()), 'foo')
|
||||||
try:
|
try:
|
||||||
|
|
Ładowanie…
Reference in New Issue