Skip to content

Commit 8758504

Browse files
dlechdpgeorge
authored andcommitted
extmod/moduselect: Conditionally compile select().
This adds #if MICROPY_PY_USELECT_SELECT around the uselect.select() function. According to the docs, this function is only for CPython compatibility and should not normally be used. So we can disable it and save a few bytes of flash space where possible. Signed-off-by: David Lechner <david@pybricks.com>
1 parent 8be29b9 commit 8758504

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

extmod/moduselect.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ STATIC mp_uint_t poll_map_poll(mp_map_t *poll_map, size_t *rwx_num) {
107107
return n_ready;
108108
}
109109

110+
#if MICROPY_PY_USELECT_SELECT
110111
// select(rlist, wlist, xlist[, timeout])
111112
STATIC mp_obj_t select_select(size_t n_args, const mp_obj_t *args) {
112113
// get array data from tuple/list arguments
@@ -173,6 +174,7 @@ STATIC mp_obj_t select_select(size_t n_args, const mp_obj_t *args) {
173174
}
174175
}
175176
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_select_select_obj, 3, 4, select_select);
177+
#endif // MICROPY_PY_USELECT_SELECT
176178

177179
typedef struct _mp_obj_poll_t {
178180
mp_obj_base_t base;
@@ -355,7 +357,9 @@ MP_DEFINE_CONST_FUN_OBJ_0(mp_select_poll_obj, select_poll);
355357

356358
STATIC const mp_rom_map_elem_t mp_module_select_globals_table[] = {
357359
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uselect) },
360+
#if MICROPY_PY_USELECT_SELECT
358361
{ MP_ROM_QSTR(MP_QSTR_select), MP_ROM_PTR(&mp_select_select_obj) },
362+
#endif
359363
{ MP_ROM_QSTR(MP_QSTR_poll), MP_ROM_PTR(&mp_select_poll_obj) },
360364
{ MP_ROM_QSTR(MP_QSTR_POLLIN), MP_ROM_INT(MP_STREAM_POLL_RD) },
361365
{ MP_ROM_QSTR(MP_QSTR_POLLOUT), MP_ROM_INT(MP_STREAM_POLL_WR) },

py/mpconfig.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,6 +1316,13 @@ typedef double mp_float_t;
13161316
#define MICROPY_PY_USELECT (0)
13171317
#endif
13181318

1319+
// Whether to enable the select() function in the "uselect" module (baremetal
1320+
// implementation). This is present for compatibility but can be disabled to
1321+
// save space.
1322+
#ifndef MICROPY_PY_USELECT_SELECT
1323+
#define MICROPY_PY_USELECT_SELECT (1)
1324+
#endif
1325+
13191326
// Whether to provide "utime" module functions implementation
13201327
// in terms of mp_hal_* functions.
13211328
#ifndef MICROPY_PY_UTIME_MP_HAL

0 commit comments

Comments
 (0)