...
 
Commits (7)
ValueError('name must be 4 bytes long',)
rtems_queue
1
7
bytearray(b'message\x00\x00\x00')
......
......@@ -15,6 +15,9 @@ buf = bytearray(10)
er = None # global variable needed for try/except below
# test printing the queue object
print(repr(q)[:11])
micropython.heap_lock()
q.send('message')
......
ValueError('name must be 4 bytes long',)
rtems_sem
have sem
have sem
have sem
......
......@@ -15,6 +15,9 @@ s = sem.create('ssss')
er = None # global variable needed for try/except below
# test printing the sem object
print(repr(s)[:9])
micropython.heap_lock()
# simple obtain/release
......
......@@ -124,10 +124,9 @@ mp_obj_t mp_obj_int_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_i
if (MP_OBJ_IS_SMALL_INT(lhs_in)) {
lhs_val = MP_OBJ_SMALL_INT_VALUE(lhs_in);
} else if (MP_OBJ_IS_TYPE(lhs_in, &mp_type_int)) {
lhs_val = ((mp_obj_int_t*)lhs_in)->val;
} else {
return MP_OBJ_NULL; // op not supported
assert(MP_OBJ_IS_TYPE(lhs_in, &mp_type_int));
lhs_val = ((mp_obj_int_t*)lhs_in)->val;
}
if (MP_OBJ_IS_SMALL_INT(rhs_in)) {
......
......@@ -170,11 +170,9 @@ mp_obj_t mp_obj_int_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_i
if (MP_OBJ_IS_SMALL_INT(lhs_in)) {
mpz_init_fixed_from_int(&z_int, z_int_dig, MPZ_NUM_DIG_FOR_INT, MP_OBJ_SMALL_INT_VALUE(lhs_in));
zlhs = &z_int;
} else if (MP_OBJ_IS_TYPE(lhs_in, &mp_type_int)) {
zlhs = &((mp_obj_int_t*)MP_OBJ_TO_PTR(lhs_in))->mpz;
} else {
// unsupported type
return MP_OBJ_NULL;
assert(MP_OBJ_IS_TYPE(lhs_in, &mp_type_int));
zlhs = &((mp_obj_int_t*)MP_OBJ_TO_PTR(lhs_in))->mpz;
}
// if rhs is small int, then lhs was not (otherwise mp_binary_op handles it)
......
......@@ -7,3 +7,7 @@ print(abs(-123456789012345678901234567890))
# edge cases for 32 and 64 bit archs (small int overflow when negating)
print(abs(-0x3fffffff - 1))
print(abs(-0x3fffffffffffffff - 1))
# edge case for nan-boxing with 47-bit small int
i = -0x3fffffffffff
print(abs(i - 1))
......@@ -34,3 +34,14 @@ class B(A):
print(super().bar) # accessing attribute after super()
return super().foo().count(2) # calling a subsequent method
print(B().foo())
# store/delete of super attribute not allowed
assert hasattr(super(B, B()), 'foo')
try:
super(B, B()).foo = 1
except AttributeError:
print('AttributeError')
try:
del super(B, B()).foo
except AttributeError:
print('AttributeError')
......@@ -90,6 +90,11 @@ x = 1073741823 # small
x = -1073741823 # small
x = 1073741824 # big
x = -1073741824 # big
# for nan-boxing with 47-bit small ints
print(int('0x3fffffffffff', 16)) # small
print(int('-0x3fffffffffff', 16)) # small
print(int('0x400000000000', 16)) # big
print(int('-0x400000000000', 16)) # big
# for 64 bit archs
x = 4611686018427387903 # small
x = -4611686018427387903 # small
......
......@@ -5,6 +5,11 @@ i = 0x3fffffff
print(i + i)
print(-i + -i)
# 47-bit overflow
i = 0x3fffffffffff
print(i + i)
print(-i + -i)
# 63-bit overflow
i = 0x3fffffffffffffff
print(i + i)
......
......@@ -53,3 +53,6 @@ print("1/" <= "1")
# that does have a hash, but the lengths of the two strings are different
import sys
print(sys.version == 'a long string that has a hash')
# this special string would have a hash of 0 but is incremented to 1
print('Q+?' == 'Q' + '+?')
# test some extreme cases of allocating exceptions and tracebacks
import micropython
# some ports need to allocate heap for the emergency exception
try:
micropython.alloc_emergency_exception_buf(256)
except AttributeError:
pass
def main():
# create an exception with many args while heap is locked
# should revert to empty tuple for args
micropython.heap_lock()
e = Exception(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
micropython.heap_unlock()
print(repr(e))
# create an exception with a long formatted error message while heap is locked
# should use emergency exception buffer and truncate the message
def f():
pass
micropython.heap_lock()
try:
f(abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz=1)
except Exception as er:
e = er
micropython.heap_unlock()
print(repr(e)[:50])
# create an exception with a long formatted error message while heap is low
# should use the heap and truncate the message
lst = []
while 1:
try:
lst = [lst]
except MemoryError:
break
try:
f(abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz=1)
except Exception as er:
e = er
lst = None
print(repr(e))
# raise a deep exception with the heap locked
# should use emergency exception and be unable to resize traceback array
def g():
g()
micropython.heap_lock()
try:
g()
except Exception as er:
e = er
micropython.heap_unlock()
print(repr(e))
# create an exception on the heap with some traceback on the heap, but then
# raise it with the heap locked so it can't allocate any more traceback
exc = Exception('my exception')
try:
raise exc
except:
pass
def h(e):
raise e
micropython.heap_lock()
try:
h(exc)
except Exception as er:
e = er
micropython.heap_unlock()
print(repr(e))
main()
Exception()
TypeError("unexpected keyword argument 'abcdefghij
TypeError("unexpected keyword argument 'abc",)
RuntimeError('maximum recursion depth exceeded',)
Exception('my exception',)