modstruct: Rename module to "ustruct", to allow full Python-level impl.
This commit is contained in:
parent
1829d86ef5
commit
3d3ef36e97
|
@ -87,7 +87,7 @@ extern const mp_obj_module_t mp_module_io;
|
||||||
extern const mp_obj_module_t mp_module_math;
|
extern const mp_obj_module_t mp_module_math;
|
||||||
extern const mp_obj_module_t mp_module_cmath;
|
extern const mp_obj_module_t mp_module_cmath;
|
||||||
extern const mp_obj_module_t mp_module_micropython;
|
extern const mp_obj_module_t mp_module_micropython;
|
||||||
extern const mp_obj_module_t mp_module_struct;
|
extern const mp_obj_module_t mp_module_ustruct;
|
||||||
extern const mp_obj_module_t mp_module_sys;
|
extern const mp_obj_module_t mp_module_sys;
|
||||||
extern const mp_obj_module_t mp_module_gc;
|
extern const mp_obj_module_t mp_module_gc;
|
||||||
|
|
||||||
|
|
|
@ -197,7 +197,7 @@ STATIC mp_obj_t struct_pack(mp_uint_t n_args, const mp_obj_t *args) {
|
||||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(struct_pack_obj, 1, MP_OBJ_FUN_ARGS_MAX, struct_pack);
|
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(struct_pack_obj, 1, MP_OBJ_FUN_ARGS_MAX, struct_pack);
|
||||||
|
|
||||||
STATIC const mp_map_elem_t mp_module_struct_globals_table[] = {
|
STATIC const mp_map_elem_t mp_module_struct_globals_table[] = {
|
||||||
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_struct) },
|
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_ustruct) },
|
||||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_calcsize), (mp_obj_t)&struct_calcsize_obj },
|
{ MP_OBJ_NEW_QSTR(MP_QSTR_calcsize), (mp_obj_t)&struct_calcsize_obj },
|
||||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_pack), (mp_obj_t)&struct_pack_obj },
|
{ MP_OBJ_NEW_QSTR(MP_QSTR_pack), (mp_obj_t)&struct_pack_obj },
|
||||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_unpack), (mp_obj_t)&struct_unpack_obj },
|
{ MP_OBJ_NEW_QSTR(MP_QSTR_unpack), (mp_obj_t)&struct_unpack_obj },
|
||||||
|
@ -205,9 +205,9 @@ STATIC const mp_map_elem_t mp_module_struct_globals_table[] = {
|
||||||
|
|
||||||
STATIC MP_DEFINE_CONST_DICT(mp_module_struct_globals, mp_module_struct_globals_table);
|
STATIC MP_DEFINE_CONST_DICT(mp_module_struct_globals, mp_module_struct_globals_table);
|
||||||
|
|
||||||
const mp_obj_module_t mp_module_struct = {
|
const mp_obj_module_t mp_module_ustruct = {
|
||||||
.base = { &mp_type_module },
|
.base = { &mp_type_module },
|
||||||
.name = MP_QSTR_struct,
|
.name = MP_QSTR_ustruct,
|
||||||
.globals = (mp_obj_dict_t*)&mp_module_struct_globals,
|
.globals = (mp_obj_dict_t*)&mp_module_struct_globals,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -142,7 +142,7 @@ STATIC const mp_map_elem_t mp_builtin_module_table[] = {
|
||||||
{ MP_OBJ_NEW_QSTR(MP_QSTR__collections), (mp_obj_t)&mp_module_collections },
|
{ MP_OBJ_NEW_QSTR(MP_QSTR__collections), (mp_obj_t)&mp_module_collections },
|
||||||
#endif
|
#endif
|
||||||
#if MICROPY_PY_STRUCT
|
#if MICROPY_PY_STRUCT
|
||||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_struct), (mp_obj_t)&mp_module_struct },
|
{ MP_OBJ_NEW_QSTR(MP_QSTR_ustruct), (mp_obj_t)&mp_module_ustruct },
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if MICROPY_PY_BUILTINS_FLOAT
|
#if MICROPY_PY_BUILTINS_FLOAT
|
||||||
|
|
|
@ -461,7 +461,7 @@ Q(print_exception)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if MICROPY_PY_STRUCT
|
#if MICROPY_PY_STRUCT
|
||||||
Q(struct)
|
Q(ustruct)
|
||||||
Q(pack)
|
Q(pack)
|
||||||
Q(unpack)
|
Q(unpack)
|
||||||
Q(calcsize)
|
Q(calcsize)
|
||||||
|
@ -469,6 +469,7 @@ Q(calcsize)
|
||||||
|
|
||||||
#if MICROPY_PY_UCTYPES
|
#if MICROPY_PY_UCTYPES
|
||||||
Q(uctypes)
|
Q(uctypes)
|
||||||
|
Q(struct)
|
||||||
Q(sizeof)
|
Q(sizeof)
|
||||||
Q(addressof)
|
Q(addressof)
|
||||||
Q(bytes_at)
|
Q(bytes_at)
|
||||||
|
|
|
@ -126,6 +126,7 @@ extern const struct _mp_obj_module_t mp_module_network;
|
||||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_time), (mp_obj_t)&mp_module_utime }, \
|
{ MP_OBJ_NEW_QSTR(MP_QSTR_time), (mp_obj_t)&mp_module_utime }, \
|
||||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_select), (mp_obj_t)&mp_module_uselect }, \
|
{ MP_OBJ_NEW_QSTR(MP_QSTR_select), (mp_obj_t)&mp_module_uselect }, \
|
||||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_socket), (mp_obj_t)&mp_module_usocket }, \
|
{ MP_OBJ_NEW_QSTR(MP_QSTR_socket), (mp_obj_t)&mp_module_usocket }, \
|
||||||
|
{ MP_OBJ_NEW_QSTR(MP_QSTR_struct), (mp_obj_t)&mp_module_ustruct }, \
|
||||||
|
|
||||||
// extra constants
|
// extra constants
|
||||||
#define MICROPY_PORT_CONSTANTS \
|
#define MICROPY_PORT_CONSTANTS \
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
try:
|
||||||
|
import ustruct as struct
|
||||||
|
except:
|
||||||
import struct
|
import struct
|
||||||
print(struct.calcsize("<bI"))
|
print(struct.calcsize("<bI"))
|
||||||
print(struct.unpack("<bI", b"\x80\0\0\x01\0"))
|
print(struct.unpack("<bI", b"\x80\0\0\x01\0"))
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
# check cases converting float to int, relying only on single precision float
|
# check cases converting float to int, relying only on single precision float
|
||||||
|
|
||||||
|
try:
|
||||||
|
import ustruct as struct
|
||||||
|
except:
|
||||||
import struct
|
import struct
|
||||||
|
|
||||||
# work out configuration values
|
# work out configuration values
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
# check cases converting float to int, requiring double precision float
|
# check cases converting float to int, requiring double precision float
|
||||||
|
|
||||||
|
try:
|
||||||
|
import ustruct as struct
|
||||||
|
except:
|
||||||
import struct
|
import struct
|
||||||
|
|
||||||
# work out configuration values
|
# work out configuration values
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
# test struct package with floats
|
# test struct package with floats
|
||||||
|
|
||||||
|
try:
|
||||||
|
import ustruct as struct
|
||||||
|
except:
|
||||||
import struct
|
import struct
|
||||||
|
|
||||||
i = 1. + 1/2
|
i = 1. + 1/2
|
||||||
|
|
Loading…
Reference in New Issue