Skip to content

Commit 3d3ef36

Browse files
committed
modstruct: Rename module to "ustruct", to allow full Python-level impl.
1 parent 1829d86 commit 3d3ef36

9 files changed

Lines changed: 24 additions & 10 deletions

File tree

py/builtin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ extern const mp_obj_module_t mp_module_io;
8787
extern const mp_obj_module_t mp_module_math;
8888
extern const mp_obj_module_t mp_module_cmath;
8989
extern const mp_obj_module_t mp_module_micropython;
90-
extern const mp_obj_module_t mp_module_struct;
90+
extern const mp_obj_module_t mp_module_ustruct;
9191
extern const mp_obj_module_t mp_module_sys;
9292
extern const mp_obj_module_t mp_module_gc;
9393

py/modstruct.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,17 +197,17 @@ STATIC mp_obj_t struct_pack(mp_uint_t n_args, const mp_obj_t *args) {
197197
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(struct_pack_obj, 1, MP_OBJ_FUN_ARGS_MAX, struct_pack);
198198

199199
STATIC const mp_map_elem_t mp_module_struct_globals_table[] = {
200-
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_struct) },
200+
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_ustruct) },
201201
{ MP_OBJ_NEW_QSTR(MP_QSTR_calcsize), (mp_obj_t)&struct_calcsize_obj },
202202
{ MP_OBJ_NEW_QSTR(MP_QSTR_pack), (mp_obj_t)&struct_pack_obj },
203203
{ MP_OBJ_NEW_QSTR(MP_QSTR_unpack), (mp_obj_t)&struct_unpack_obj },
204204
};
205205

206206
STATIC MP_DEFINE_CONST_DICT(mp_module_struct_globals, mp_module_struct_globals_table);
207207

208-
const mp_obj_module_t mp_module_struct = {
208+
const mp_obj_module_t mp_module_ustruct = {
209209
.base = { &mp_type_module },
210-
.name = MP_QSTR_struct,
210+
.name = MP_QSTR_ustruct,
211211
.globals = (mp_obj_dict_t*)&mp_module_struct_globals,
212212
};
213213

py/objmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ STATIC const mp_map_elem_t mp_builtin_module_table[] = {
142142
{ MP_OBJ_NEW_QSTR(MP_QSTR__collections), (mp_obj_t)&mp_module_collections },
143143
#endif
144144
#if MICROPY_PY_STRUCT
145-
{ MP_OBJ_NEW_QSTR(MP_QSTR_struct), (mp_obj_t)&mp_module_struct },
145+
{ MP_OBJ_NEW_QSTR(MP_QSTR_ustruct), (mp_obj_t)&mp_module_ustruct },
146146
#endif
147147

148148
#if MICROPY_PY_BUILTINS_FLOAT

py/qstrdefs.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,14 +461,15 @@ Q(print_exception)
461461
#endif
462462

463463
#if MICROPY_PY_STRUCT
464-
Q(struct)
464+
Q(ustruct)
465465
Q(pack)
466466
Q(unpack)
467467
Q(calcsize)
468468
#endif
469469

470470
#if MICROPY_PY_UCTYPES
471471
Q(uctypes)
472+
Q(struct)
472473
Q(sizeof)
473474
Q(addressof)
474475
Q(bytes_at)

stmhal/mpconfigport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ extern const struct _mp_obj_module_t mp_module_network;
126126
{ MP_OBJ_NEW_QSTR(MP_QSTR_time), (mp_obj_t)&mp_module_utime }, \
127127
{ MP_OBJ_NEW_QSTR(MP_QSTR_select), (mp_obj_t)&mp_module_uselect }, \
128128
{ MP_OBJ_NEW_QSTR(MP_QSTR_socket), (mp_obj_t)&mp_module_usocket }, \
129+
{ MP_OBJ_NEW_QSTR(MP_QSTR_struct), (mp_obj_t)&mp_module_ustruct }, \
129130

130131
// extra constants
131132
#define MICROPY_PORT_CONSTANTS \

tests/basics/struct1.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import struct
1+
try:
2+
import ustruct as struct
3+
except:
4+
import struct
25
print(struct.calcsize("<bI"))
36
print(struct.unpack("<bI", b"\x80\0\0\x01\0"))
47
print(struct.calcsize(">bI"))

tests/float/float2int.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# check cases converting float to int, relying only on single precision float
22

3-
import struct
3+
try:
4+
import ustruct as struct
5+
except:
6+
import struct
47

58
# work out configuration values
69
is_64bit = struct.calcsize("P") == 8

tests/float/float2int_doubleprec.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# check cases converting float to int, requiring double precision float
22

3-
import struct
3+
try:
4+
import ustruct as struct
5+
except:
6+
import struct
47

58
# work out configuration values
69
is_64bit = struct.calcsize("P") == 8

tests/float/float_struct.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# test struct package with floats
22

3-
import struct
3+
try:
4+
import ustruct as struct
5+
except:
6+
import struct
47

58
i = 1. + 1/2
69
# TODO: it looks like '=' format modifier is not yet supported

0 commit comments

Comments
 (0)