Skip to content

Commit 3566438

Browse files
committed
wip: fix some tests
1 parent 2dd33e3 commit 3566438

File tree

8 files changed

+14
-43
lines changed

8 files changed

+14
-43
lines changed

docs/library/builtins.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ Functions and types
8888

8989
.. classmethod:: from_bytes(bytes, byteorder="big", *, signed=False)
9090

91-
.. method:: to_bytes(length, byteorder="big", *, signed=False)
91+
.. method:: to_bytes(length=1, byteorder="big", *, signed=False)
9292

9393
.. function:: isinstance()
9494

py/binary.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,8 @@ void mp_binary_set_val(char struct_type, char val_type, mp_obj_t val_in, byte *p
474474
bool signed_type = is_signed(val_type);
475475
#if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE
476476
if (mp_obj_is_exact_type(val_in, &mp_type_int)) {
477+
// It's a longint.
478+
mp_obj_int_buffer_overflow_check(val_in, size, signed_type);
477479
mp_obj_int_to_bytes_impl(val_in, struct_type == '>', size, p);
478480
return;
479481
}

py/objint.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ char *mp_obj_int_formatted(char **buf, size_t *buf_size, size_t *fmt_size, mp_co
308308
void mp_obj_int_buffer_overflow_check(mp_obj_t self_in, size_t nbytes, bool is_signed) {
309309
if (is_signed) {
310310
// self must be < 2**(bits - 1)
311-
mp_obj_t edge = mp_binary_op(MP_BINARY_OP_INPLACE_LSHIFT,
311+
mp_obj_t edge = mp_binary_op(MP_BINARY_OP_LSHIFT,
312312
mp_obj_new_int(1),
313313
mp_obj_new_int(nbytes * 8 - 1));
314314

@@ -323,7 +323,7 @@ void mp_obj_int_buffer_overflow_check(mp_obj_t self_in, size_t nbytes, bool is_s
323323
// self must be >= 0
324324
if (mp_obj_int_sign(self_in) >= 0) {
325325
// and < 2**(bits)
326-
mp_obj_t edge = mp_binary_op(MP_BINARY_OP_INPLACE_LSHIFT,
326+
mp_obj_t edge = mp_binary_op(MP_BINARY_OP_LSHIFT,
327327
mp_obj_new_int(1),
328328
mp_obj_new_int(nbytes * 8));
329329

@@ -536,7 +536,7 @@ static MP_DEFINE_CONST_CLASSMETHOD_OBJ(int_from_bytes_obj, MP_ROM_PTR(&int_from_
536536
static mp_obj_t int_to_bytes(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
537537
enum { ARG_length, ARG_byteorder, ARG_signed };
538538
static const mp_arg_t allowed_args[] = {
539-
{ MP_QSTR_length, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 0} },
539+
{ MP_QSTR_length, MP_ARG_INT, {.u_int = 1} },
540540
// CIRCUITPY-CHANGE: not required and given a default value.
541541
{ MP_QSTR_byteorder, MP_ARG_OBJ, {.u_obj = MP_OBJ_NEW_QSTR(MP_QSTR_big)} },
542542
{ MP_QSTR_signed, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} },
@@ -578,8 +578,7 @@ static mp_obj_t int_to_bytes(size_t n_args, const mp_obj_t *pos_args, mp_map_t *
578578

579579
return mp_obj_new_bytes_from_vstr(&vstr);
580580
}
581-
// CIRCUITPY-CHANGE: only two required args.
582-
static MP_DEFINE_CONST_FUN_OBJ_KW(int_to_bytes_obj, 2, int_to_bytes);
581+
static MP_DEFINE_CONST_FUN_OBJ_KW(int_to_bytes_obj, 1, int_to_bytes);
583582

584583
static const mp_rom_map_elem_t int_locals_dict_table[] = {
585584
// CIRCUITPY-CHANGE

tests/basics/int_bytes_intbig.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import skip_if
33
skip_if.no_bigint()
44

5+
import sys
6+
57
# CIRCUITPY-CHANGE: signed support
68
print((2**64).to_bytes(9, "little"))
79
print((-2**64).to_bytes(9, "little", signed=True))

tests/basics/struct_microptyhon.py

Lines changed: 0 additions & 32 deletions
This file was deleted.

tests/micropython/heapalloc_exc_compressed.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# mp_obj_new_exception_msg_varg (exception requires decompression at raise-time to format)
55
# mp_obj_new_exception_msg (decompression can be deferred)
66

7-
# NameError uses mp_obj_new_exception_msg_varg for NameError("name '%q' is not defined")
7+
# NameError uses mp_obj_new_exception_msg_varg for NameError("name '%q' isn't defined")
88
# `raise 0` uses mp_obj_new_exception_msg for TypeError("exceptions must derive from BaseException")
99

1010
# Tests that deferred decompression works both via print(e) and accessing the message directly via e.args.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
NameError name 'name' is not defined
1+
NameError name 'name' isn't defined
22
TypeError exceptions must derive from BaseException
3-
name 'name' is not defined
3+
name 'name' isn't defined
44
exceptions must derive from BaseException
55
NameError
66
TypeError
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
NameError name 'name' is not defined
1+
NameError name 'name' isn't defined
22
TypeError exceptions must derive from BaseException
3-
name 'name' is not defined
3+
name 'name' isn't defined
44
exceptions must derive from BaseException

0 commit comments

Comments
 (0)