From 3d3ef36e977b5f5a4153b8df6447f3f73e4726e3 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Mon, 4 May 2015 16:35:40 +0300 Subject: [PATCH] modstruct: Rename module to "ustruct", to allow full Python-level impl. --- py/builtin.h | 2 +- py/modstruct.c | 6 +++--- py/objmodule.c | 2 +- py/qstrdefs.h | 3 ++- stmhal/mpconfigport.h | 1 + tests/basics/struct1.py | 5 ++++- tests/float/float2int.py | 5 ++++- tests/float/float2int_doubleprec.py | 5 ++++- tests/float/float_struct.py | 5 ++++- 9 files changed, 24 insertions(+), 10 deletions(-) diff --git a/py/builtin.h b/py/builtin.h index 6bec64fdcf..829d34358b 100644 --- a/py/builtin.h +++ b/py/builtin.h @@ -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_cmath; 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_gc; diff --git a/py/modstruct.c b/py/modstruct.c index 1103e40a5b..0c4af707d6 100644 --- a/py/modstruct.c +++ b/py/modstruct.c @@ -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); 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_pack), (mp_obj_t)&struct_pack_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); -const mp_obj_module_t mp_module_struct = { +const mp_obj_module_t mp_module_ustruct = { .base = { &mp_type_module }, - .name = MP_QSTR_struct, + .name = MP_QSTR_ustruct, .globals = (mp_obj_dict_t*)&mp_module_struct_globals, }; diff --git a/py/objmodule.c b/py/objmodule.c index c67a9b26d9..e0fad37f0a 100644 --- a/py/objmodule.c +++ b/py/objmodule.c @@ -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 }, #endif #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 #if MICROPY_PY_BUILTINS_FLOAT diff --git a/py/qstrdefs.h b/py/qstrdefs.h index 8550ac39ac..77277c095f 100644 --- a/py/qstrdefs.h +++ b/py/qstrdefs.h @@ -461,7 +461,7 @@ Q(print_exception) #endif #if MICROPY_PY_STRUCT -Q(struct) +Q(ustruct) Q(pack) Q(unpack) Q(calcsize) @@ -469,6 +469,7 @@ Q(calcsize) #if MICROPY_PY_UCTYPES Q(uctypes) +Q(struct) Q(sizeof) Q(addressof) Q(bytes_at) diff --git a/stmhal/mpconfigport.h b/stmhal/mpconfigport.h index 0f38eb030b..26c969cd55 100644 --- a/stmhal/mpconfigport.h +++ b/stmhal/mpconfigport.h @@ -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_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_struct), (mp_obj_t)&mp_module_ustruct }, \ // extra constants #define MICROPY_PORT_CONSTANTS \ diff --git a/tests/basics/struct1.py b/tests/basics/struct1.py index c473fc0b0c..87e2f07026 100644 --- a/tests/basics/struct1.py +++ b/tests/basics/struct1.py @@ -1,4 +1,7 @@ -import struct +try: + import ustruct as struct +except: + import struct print(struct.calcsize("bI")) diff --git a/tests/float/float2int.py b/tests/float/float2int.py index ca395997c4..e9bdf15de6 100644 --- a/tests/float/float2int.py +++ b/tests/float/float2int.py @@ -1,6 +1,9 @@ # check cases converting float to int, relying only on single precision float -import struct +try: + import ustruct as struct +except: + import struct # work out configuration values is_64bit = struct.calcsize("P") == 8 diff --git a/tests/float/float2int_doubleprec.py b/tests/float/float2int_doubleprec.py index 63138c0d4e..acdc8c69c4 100644 --- a/tests/float/float2int_doubleprec.py +++ b/tests/float/float2int_doubleprec.py @@ -1,6 +1,9 @@ # check cases converting float to int, requiring double precision float -import struct +try: + import ustruct as struct +except: + import struct # work out configuration values is_64bit = struct.calcsize("P") == 8 diff --git a/tests/float/float_struct.py b/tests/float/float_struct.py index 8ad0e492c6..e55890a2cd 100644 --- a/tests/float/float_struct.py +++ b/tests/float/float_struct.py @@ -1,6 +1,9 @@ # test struct package with floats -import struct +try: + import ustruct as struct +except: + import struct i = 1. + 1/2 # TODO: it looks like '=' format modifier is not yet supported