py/objint: from_bytes, to_bytes: Require byteorder arg, require "little".
CPython requires byteorder arg, make uPy compatible. As we support only "little", error out on anything else.
This commit is contained in:
parent
93ee6603b1
commit
9d787de2a1
16
py/objint.c
16
py/objint.c
@ -383,10 +383,14 @@ mp_obj_t mp_obj_int_binary_op_extra_cases(mp_uint_t op, mp_obj_t lhs_in, mp_obj_
|
||||
// this is a classmethod
|
||||
STATIC mp_obj_t int_from_bytes(size_t n_args, const mp_obj_t *args) {
|
||||
// TODO: Support long ints
|
||||
// TODO: Support byteorder param (assumes 'little' at the moment)
|
||||
// TODO: Support byteorder param
|
||||
// TODO: Support signed param (assumes signed=False at the moment)
|
||||
(void)n_args;
|
||||
|
||||
if (args[2] != MP_OBJ_NEW_QSTR(MP_QSTR_little)) {
|
||||
mp_not_implemented("");
|
||||
}
|
||||
|
||||
// get the buffer info
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_get_buffer_raise(args[1], &bufinfo, MP_BUFFER_READ);
|
||||
@ -400,14 +404,18 @@ STATIC mp_obj_t int_from_bytes(size_t n_args, const mp_obj_t *args) {
|
||||
return mp_obj_new_int_from_uint(value);
|
||||
}
|
||||
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(int_from_bytes_fun_obj, 2, 3, int_from_bytes);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(int_from_bytes_fun_obj, 3, 4, int_from_bytes);
|
||||
STATIC MP_DEFINE_CONST_CLASSMETHOD_OBJ(int_from_bytes_obj, MP_ROM_PTR(&int_from_bytes_fun_obj));
|
||||
|
||||
STATIC mp_obj_t int_to_bytes(size_t n_args, const mp_obj_t *args) {
|
||||
// TODO: Support byteorder param (assumes 'little')
|
||||
// TODO: Support byteorder param
|
||||
// TODO: Support signed param (assumes signed=False)
|
||||
(void)n_args;
|
||||
|
||||
if (args[2] != MP_OBJ_NEW_QSTR(MP_QSTR_little)) {
|
||||
mp_not_implemented("");
|
||||
}
|
||||
|
||||
mp_uint_t len = MP_OBJ_SMALL_INT_VALUE(args[1]);
|
||||
|
||||
vstr_t vstr;
|
||||
@ -427,7 +435,7 @@ STATIC mp_obj_t int_to_bytes(size_t n_args, const mp_obj_t *args) {
|
||||
|
||||
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(int_to_bytes_obj, 2, 4, int_to_bytes);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(int_to_bytes_obj, 3, 4, int_to_bytes);
|
||||
|
||||
STATIC const mp_rom_map_elem_t int_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_from_bytes), MP_ROM_PTR(&int_from_bytes_obj) },
|
||||
|
Loading…
Reference in New Issue
Block a user