@@ -390,15 +390,15 @@ mp_obj_t mp_obj_int_binary_op_extra_cases(mp_binary_op_t op, mp_obj_t lhs_in, mp
390
390
// this is a classmethod
391
391
static mp_obj_t int_from_bytes (size_t n_args , const mp_obj_t * args ) {
392
392
// TODO: Support signed param (assumes signed=False at the moment)
393
- (void )n_args ;
394
393
395
394
// get the buffer info
396
395
mp_buffer_info_t bufinfo ;
397
396
mp_get_buffer_raise (args [1 ], & bufinfo , MP_BUFFER_READ );
398
397
399
398
const byte * buf = (const byte * )bufinfo .buf ;
400
399
int delta = 1 ;
401
- if (args [2 ] == MP_OBJ_NEW_QSTR (MP_QSTR_little )) {
400
+ bool big_endian = n_args < 3 || args [2 ] != MP_OBJ_NEW_QSTR (MP_QSTR_little );
401
+ if (!big_endian ) {
402
402
buf += bufinfo .len - 1 ;
403
403
delta = -1 ;
404
404
}
@@ -409,15 +409,15 @@ static mp_obj_t int_from_bytes(size_t n_args, const mp_obj_t *args) {
409
409
#if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE
410
410
if (value > (MP_SMALL_INT_MAX >> 8 )) {
411
411
// Result will overflow a small-int so construct a big-int
412
- return mp_obj_int_from_bytes_impl (args [ 2 ] != MP_OBJ_NEW_QSTR ( MP_QSTR_little ) , bufinfo .len , bufinfo .buf );
412
+ return mp_obj_int_from_bytes_impl (big_endian , bufinfo .len , bufinfo .buf );
413
413
}
414
414
#endif
415
415
value = (value << 8 ) | * buf ;
416
416
}
417
417
return mp_obj_new_int_from_uint (value );
418
418
}
419
419
420
- static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (int_from_bytes_fun_obj , 3 , 4 , int_from_bytes ) ;
420
+ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (int_from_bytes_fun_obj , 2 , 4 , int_from_bytes ) ;
421
421
static MP_DEFINE_CONST_CLASSMETHOD_OBJ (int_from_bytes_obj , MP_ROM_PTR (& int_from_bytes_fun_obj )) ;
422
422
423
423
static mp_obj_t int_to_bytes (size_t n_args , const mp_obj_t * args ) {
0 commit comments