Skip to content

Commit cb78f86

Browse files
committed
py: Allow to disable array module and bytearray type.
array.array and bytearray share big deal of code, so to get real savings, both need to be disabled.
1 parent 0a1ea40 commit cb78f86

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

py/builtintables.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ STATIC const mp_map_elem_t mp_builtin_object_table[] = {
4343
// built-in types
4444
{ MP_OBJ_NEW_QSTR(MP_QSTR_bool), (mp_obj_t)&mp_type_bool },
4545
{ MP_OBJ_NEW_QSTR(MP_QSTR_bytes), (mp_obj_t)&mp_type_bytes },
46+
#if MICROPY_PY_BUILTINS_BYTEARRAY
4647
{ MP_OBJ_NEW_QSTR(MP_QSTR_bytearray), (mp_obj_t)&mp_type_bytearray },
48+
#endif
4749
#if MICROPY_PY_BUILTINS_COMPLEX
4850
{ MP_OBJ_NEW_QSTR(MP_QSTR_complex), (mp_obj_t)&mp_type_complex },
4951
#endif
@@ -160,7 +162,9 @@ STATIC const mp_map_elem_t mp_builtin_module_table[] = {
160162
{ MP_OBJ_NEW_QSTR(MP_QSTR___main__), (mp_obj_t)&mp_module___main__ },
161163
{ MP_OBJ_NEW_QSTR(MP_QSTR_micropython), (mp_obj_t)&mp_module_micropython },
162164

165+
#if MICROPY_PY_ARRAY
163166
{ MP_OBJ_NEW_QSTR(MP_QSTR_array), (mp_obj_t)&mp_module_array },
167+
#endif
164168
#if MICROPY_PY_IO
165169
{ MP_OBJ_NEW_QSTR(MP_QSTR__io), (mp_obj_t)&mp_module_io },
166170
#endif

py/modarray.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#include "obj.h"
3131
#include "builtin.h"
3232

33+
#if MICROPY_PY_ARRAY
34+
3335
STATIC const mp_map_elem_t mp_module_array_globals_table[] = {
3436
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_array) },
3537
{ MP_OBJ_NEW_QSTR(MP_QSTR_array), (mp_obj_t)&mp_type_array },
@@ -51,3 +53,5 @@ const mp_obj_module_t mp_module_array = {
5153
.name = MP_QSTR_array,
5254
.globals = (mp_obj_dict_t*)&mp_module_array_globals,
5355
};
56+
57+
#endif

py/mpconfig.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,11 @@ typedef double mp_float_t;
249249
/*****************************************************************************/
250250
/* Fine control over Python builtins, classes, modules, etc */
251251

252+
// Whether to support bytearray object
253+
#ifndef MICROPY_PY_BUILTINS_BYTEARRAY
254+
#define MICROPY_PY_BUILTINS_BYTEARRAY (1)
255+
#endif
256+
252257
// Whether to support set object
253258
#ifndef MICROPY_PY_BUILTINS_SET
254259
#define MICROPY_PY_BUILTINS_SET (1)
@@ -269,6 +274,13 @@ typedef double mp_float_t;
269274
#define MICROPY_PY_BUILTINS_PROPERTY (1)
270275
#endif
271276

277+
// Whether to provide "array" module. Note that large chunk of the
278+
// underlying code is shared with "bytearray" builtin type, so to
279+
// get real savings, it should be disabled too.
280+
#ifndef MICROPY_PY_ARRAY
281+
#define MICROPY_PY_ARRAY (1)
282+
#endif
283+
272284
// Whether to provide "collections" module
273285
#ifndef MICROPY_PY_COLLECTIONS
274286
#define MICROPY_PY_COLLECTIONS (1)

py/objarray.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
#include "runtime.h"
3838
#include "binary.h"
3939

40+
#if MICROPY_PY_ARRAY || MICROPY_PY_BUILTINS_BYTEARRAY
41+
4042
typedef struct _mp_obj_array_t {
4143
mp_obj_base_t base;
4244
machine_uint_t typecode : 8;
@@ -310,3 +312,5 @@ STATIC mp_obj_t array_iterator_new(mp_obj_t array_in) {
310312
o->cur = 0;
311313
return o;
312314
}
315+
316+
#endif // MICROPY_PY_ARRAY || MICROPY_PY_BUILTINS_BYTEARRAY

0 commit comments

Comments
 (0)