Skip to content

Commit 65d5196

Browse files
committed
micropython: update to v1.25
Update to current MicroPython stable release v1.25. Includes changes required to compile without errors: - Handling of PYEXEC_FORCED_EXIT/SystemExit changed - mp_make_function_from_raw_code() replaced by mp_make_function_from_proto_fun() - Module import code changed - mp_lexer_new_from_file() function signature changed - mp_hal_stdout_tx_strn() function signature changed - MP_REGISTER_MODULE_DELEGATION() replaces MP_MODULE_ATTR_DELEGATION_ENTRY() - mp_obj_malloc_var() signature changed - mp_generic_unary_op was removed - m_new_obj_var_with_finaliser() replaced by mp_obj_malloc_var_with_finaliser() - Handling of 'u' prefix on builtin modules has changed
1 parent d50d711 commit 65d5196

File tree

19 files changed

+97
-54
lines changed

19 files changed

+97
-54
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ jobs:
7676
- name: Test
7777
if: ${{ success() }}
7878
run: |
79+
ulimit -n 1024 # needed for micropython/tests/extmod/select_poll_fd.py
7980
cd micropython
8081
make -C ports/unix VARIANT=coverage test_full
8182
(cd tests && MICROPY_CPYTHON3=python3 MICROPY_MICROPYTHON=../ports/unix/build-coverage/micropython ./run-multitests.py multi_net/*.py)

bricks/_common/micropython.c

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ void pbsys_main_stop_program(bool force_stop) {
5555
if (force_stop) {
5656
mp_sched_vm_abort();
5757
} else {
58-
pyexec_system_exit = PYEXEC_FORCED_EXIT;
59-
6058
static mp_obj_exception_t system_exit;
6159
system_exit.base.type = &mp_type_SystemExit;
6260
system_exit.traceback_alloc = system_exit.traceback_len = 0;
@@ -106,9 +104,9 @@ static void mp_vfs_map_minimal_new_reader(mp_reader_t *reader, mp_vfs_map_minima
106104
}
107105

108106
// Prints the exception that ended the program.
109-
static void print_final_exception(mp_obj_t exc) {
107+
static void print_final_exception(mp_obj_t exc, int ret) {
110108
// Handle graceful stop with button.
111-
if (pyexec_system_exit == PYEXEC_FORCED_EXIT &&
109+
if ((ret & PYEXEC_FORCED_EXIT) &&
112110
mp_obj_exception_match(exc, MP_OBJ_FROM_PTR(&mp_type_SystemExit))) {
113111
mp_printf(&mp_plat_print, "The program was stopped (%q).\n",
114112
((mp_obj_exception_t *)MP_OBJ_TO_PTR(exc))->base.type->name);
@@ -121,8 +119,9 @@ static void print_final_exception(mp_obj_t exc) {
121119

122120
#if PBSYS_CONFIG_FEATURE_BUILTIN_USER_PROGRAM_REPL
123121
static void run_repl(void) {
122+
int ret = 0;
123+
124124
readline_init0();
125-
pyexec_system_exit = 0;
126125

127126
nlr_buf_t nlr;
128127
nlr.ret_val = NULL;
@@ -134,12 +133,12 @@ static void run_repl(void) {
134133
if (pyexec_mode_kind == PYEXEC_MODE_RAW_REPL) {
135134
// Compatibility with mpremote.
136135
mp_printf(&mp_plat_print, "MPY: soft reboot\n");
137-
pyexec_raw_repl();
136+
ret = pyexec_raw_repl();
138137
} else {
139-
pyexec_friendly_repl();
138+
ret = pyexec_friendly_repl();
140139
}
141140
#else // PYBRICKS_OPT_RAW_REPL
142-
pyexec_friendly_repl();
141+
ret = pyexec_friendly_repl();
143142
#endif // PYBRICKS_OPT_RAW_REPL
144143
nlr_pop();
145144
} else {
@@ -152,7 +151,7 @@ static void run_repl(void) {
152151
// clear any pending exceptions (and run any callbacks).
153152
mp_handle_pending(false);
154153
// Print which exception triggered this.
155-
print_final_exception(MP_OBJ_FROM_PTR(nlr.ret_val));
154+
print_final_exception(MP_OBJ_FROM_PTR(nlr.ret_val), ret);
156155
}
157156

158157
nlr_set_abort(NULL);
@@ -175,7 +174,7 @@ static void do_execute_raw_code(mp_module_context_t *context, const mp_raw_code_
175174

176175
nlr_buf_t nlr;
177176
if (nlr_push(&nlr) == 0) {
178-
mp_obj_t module_fun = mp_make_function_from_raw_code(rc, mc, NULL);
177+
mp_obj_t module_fun = mp_make_function_from_proto_fun(rc, mc, NULL);
179178
mp_call_function_0(module_fun);
180179

181180
// finish nlr block, restore context
@@ -241,7 +240,7 @@ static mpy_info_t *mpy_data_find(qstr name) {
241240
* Runs the __main__ module from user RAM.
242241
*/
243242
static void run_user_program(void) {
244-
pyexec_system_exit = 0;
243+
int ret = 0;
245244

246245
nlr_buf_t nlr;
247246
nlr.ret_val = NULL;
@@ -264,7 +263,7 @@ static void run_user_program(void) {
264263
mp_compiled_module_t compiled_module;
265264
compiled_module.context = context;
266265
mp_raw_code_load(&reader, &compiled_module);
267-
mp_obj_t module_fun = mp_make_function_from_raw_code(compiled_module.rc, context, NULL);
266+
mp_obj_t module_fun = mp_make_function_from_proto_fun(compiled_module.rc, context, NULL);
268267

269268
// Run the script while letting CTRL-C interrupt it.
270269
mp_hal_set_interrupt_char(CHAR_CTRL_C);
@@ -287,7 +286,12 @@ static void run_user_program(void) {
287286
// Clear any pending exceptions (and run any callbacks).
288287
mp_handle_pending(false);
289288

290-
print_final_exception(MP_OBJ_FROM_PTR(nlr.ret_val));
289+
if (mp_obj_is_subclass_fast(MP_OBJ_FROM_PTR(((mp_obj_base_t *)nlr.ret_val)->type), MP_OBJ_FROM_PTR(&mp_type_SystemExit))) {
290+
// at the moment, the value of SystemExit is unused
291+
ret = PYEXEC_FORCED_EXIT;
292+
}
293+
294+
print_final_exception(MP_OBJ_FROM_PTR(nlr.ret_val), ret);
291295

292296
#if PBSYS_CONFIG_FEATURE_BUILTIN_USER_PROGRAM_REPL
293297
// On KeyboardInterrupt, drop to REPL for debugging.
@@ -430,9 +434,21 @@ mp_obj_t pb_builtin_import(size_t n_args, const mp_obj_t *args) {
430434
mp_raise_NotImplementedError(MP_ERROR_TEXT("relative import"));
431435
}
432436

433-
// Check if module already exists, and return it if it does
437+
// Check if the module is already loaded.
438+
mp_map_elem_t *elem = mp_map_lookup(&MP_STATE_VM(mp_loaded_modules_dict).map, args[0], MP_MAP_LOOKUP);
439+
if (elem) {
440+
return elem->value;
441+
}
442+
443+
// Try the name directly as a non-extensible built-in (e.g. `micropython`).
434444
qstr module_name_qstr = mp_obj_str_get_qstr(args[0]);
435-
mp_obj_t module_obj = mp_module_get_loaded_or_builtin(module_name_qstr);
445+
mp_obj_t module_obj = mp_module_get_builtin(module_name_qstr, false);
446+
if (module_obj != MP_OBJ_NULL) {
447+
return module_obj;
448+
}
449+
450+
// Now try as an extensible built-in (e.g. `struct`/`ustruct`).
451+
module_obj = mp_module_get_builtin(module_name_qstr, true);
436452
if (module_obj != MP_OBJ_NULL) {
437453
return module_obj;
438454
}
@@ -473,7 +489,7 @@ mp_obj_t pb_builtin_import(size_t n_args, const mp_obj_t *args) {
473489
mp_module_context_t *context = MP_OBJ_TO_PTR(module_obj);
474490
const mp_frozen_module_t *frozen = modref;
475491
context->constants = frozen->constants;
476-
do_execute_raw_code(context, frozen->rc, context);
492+
do_execute_raw_code(context, frozen->proto_fun, context);
477493
return module_obj;
478494
}
479495
#endif
@@ -486,7 +502,7 @@ mp_import_stat_t mp_import_stat(const char *path) {
486502
return MP_IMPORT_STAT_NO_EXIST;
487503
}
488504

489-
mp_lexer_t *mp_lexer_new_from_file(const char *filename) {
505+
mp_lexer_t *mp_lexer_new_from_file(qstr filename) {
490506
mp_raise_OSError(MP_ENOENT);
491507
}
492508

bricks/_common/mpconfigport.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
#define MICROPY_PY_MICROPYTHON (PYBRICKS_OPT_EXTRA_LEVEL1)
2121
#define MICROPY_PY_STRUCT (PYBRICKS_OPT_EXTRA_LEVEL1)
2222
#define MICROPY_PY_SYS (PYBRICKS_OPT_EXTRA_LEVEL1)
23-
#define MICROPY_PY_UERRNO (1)
24-
#define MICROPY_PY_UJSON (PYBRICKS_OPT_EXTRA_LEVEL1)
25-
#define MICROPY_PY_URANDOM (PYBRICKS_OPT_EXTRA_LEVEL1)
26-
#define MICROPY_PY_USELECT (PYBRICKS_OPT_EXTRA_LEVEL1)
23+
#define MICROPY_PY_ERRNO (1)
24+
#define MICROPY_PY_JSON (PYBRICKS_OPT_EXTRA_LEVEL1)
25+
#define MICROPY_PY_RANDOM (PYBRICKS_OPT_EXTRA_LEVEL1)
26+
#define MICROPY_PY_SELECT (PYBRICKS_OPT_EXTRA_LEVEL1)
2727

28-
#define MICROPY_PY_UERRNO_LIST \
28+
#define MICROPY_PY_ERRNO_LIST \
2929
X(EPERM) \
3030
X(EIO) \
3131
X(EBUSY) \
@@ -93,11 +93,9 @@
9393
#define MICROPY_PY_SYS_STDFILES (PYBRICKS_OPT_EXTRA_LEVEL1)
9494
#define MICROPY_PY_SYS_STDIO_BUFFER (PYBRICKS_OPT_EXTRA_LEVEL1)
9595
#define MICROPY_PY_SYS_STDIO_FLUSH (PYBRICKS_OPT_EXTRA_LEVEL1)
96-
#define MICROPY_PY_URANDOM_EXTRA_FUNCS (PYBRICKS_OPT_EXTRA_LEVEL1)
97-
#define MICROPY_PY_URANDOM_SEED_INIT_FUNC ({ extern uint32_t pbdrv_clock_get_us(void); pbdrv_clock_get_us(); })
98-
#define MICROPY_PY_UTIME_MP_HAL (0)
96+
#define MICROPY_PY_RANDOM_EXTRA_FUNCS (PYBRICKS_OPT_EXTRA_LEVEL1)
97+
#define MICROPY_PY_RANDOM_SEED_INIT_FUNC ({ extern uint32_t pbdrv_clock_get_us(void); pbdrv_clock_get_us(); })
9998
#define MICROPY_MODULE_BUILTIN_INIT (1)
100-
#define MICROPY_MODULE_WEAK_LINKS (0)
10199
#define MICROPY_CPYTHON_COMPAT (0)
102100
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_NONE)
103101
#if PYBRICKS_OPT_FLOAT

bricks/_common_stm32/mphalport.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,13 @@ int mp_hal_stdin_rx_chr(void) {
6464
}
6565

6666
// Send string of given length
67-
void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
67+
mp_uint_t mp_hal_stdout_tx_strn(const char *str, size_t len) {
6868
while (pbsys_host_tx((const uint8_t *)str, len) == PBIO_ERROR_AGAIN) {
6969
MICROPY_EVENT_POLL_HOOK
7070
}
7171
// Not raising the error. This means stdout lost if host is not connected.
72+
73+
return len;
7274
}
7375

7476
void mp_hal_stdout_tx_flush(void) {

bricks/ev3/mphalport.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ int mp_hal_stdin_rx_chr(void) {
5757

5858
extern uint32_t pbdrv_usb_write(const uint8_t *data, uint32_t size);
5959

60-
void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
60+
mp_uint_t mp_hal_stdout_tx_strn(const char *str, size_t len) {
6161
pbdrv_uart_debug_printf("%.*s", len, str);
6262

6363
uint32_t done = 0;
@@ -69,6 +69,8 @@ void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
6969
while (!pbdrv_uart_debug_is_done()) {
7070
MICROPY_VM_HOOK_LOOP;
7171
}
72+
73+
return len;
7274
}
7375

7476
extern void pbdrv_usb_tx_flush(void);

bricks/nxt/mphalport.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,19 @@ int mp_hal_stdin_rx_chr(void) {
7474
}
7575

7676
// Send string of given length
77-
void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
77+
mp_uint_t mp_hal_stdout_tx_strn(const char *str, size_t len) {
7878

7979
// Nothing to do if disconnected or empty data
8080
if (!nx_bt_stream_opened() || len == 0) {
81-
return;
81+
return len;
8282
}
8383

8484
nx_bt_stream_write((uint8_t *)str, len);
8585
while (!nx_bt_stream_data_written()) {
8686
MICROPY_EVENT_POLL_HOOK;
8787
}
88+
89+
return len;
8890
}
8991

9092
void mp_hal_stdout_tx_flush(void) {

bricks/virtualhub/mpconfigvariant.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,23 +56,24 @@
5656
#define MICROPY_DEBUG_PRINTERS (1)
5757
#define MICROPY_MODULE_ATTR_DELEGATION (1)
5858
#define MICROPY_MODULE_BUILTIN_INIT (1)
59+
#define MICROPY_MODULE_BUILTIN_SUBPACKAGES (1)
5960
#define MICROPY_PY_MICROPYTHON_MEM_INFO (1)
6061
#define MICROPY_PY_BUILTINS_HELP (1)
6162
#define MICROPY_PY_BUILTINS_HELP_MODULES (1)
6263
#define MICROPY_PY_SYS_SETTRACE (1)
63-
#define MICROPY_PY_UERRNO (1)
64-
#define MICROPY_PY_UOS (1)
65-
#define MICROPY_PY_UOS_GETENV_PUTENV_UNSETENV (1)
66-
#define MICROPY_PY_UOS_INCLUDEFILE "ports/unix/moduos.c"
67-
#define MICROPY_PY_URANDOM_EXTRA_FUNCS (1)
64+
#define MICROPY_PY_ERRNO (1)
65+
#define MICROPY_PY_OS (1)
66+
#define MICROPY_PY_OS_GETENV_PUTENV_UNSETENV (1)
67+
#define MICROPY_PY_OS_INCLUDEFILE "ports/unix/modos.c"
68+
#define MICROPY_PY_RANDOM_EXTRA_FUNCS (1)
6869
#define MICROPY_PY_BUILTINS_SLICE_INDICES (1)
6970
#define MICROPY_PERSISTENT_CODE_SAVE (1)
7071
#define MICROPY_STREAMS_POSIX_API (1)
7172
#define MICROPY_HELPER_REPL (1)
7273
#define MICROPY_KBD_EXCEPTION (1)
7374

7475
// REVISIT: This list currently matches the stm32 builds.
75-
#define MICROPY_PY_UERRNO_LIST \
76+
#define MICROPY_PY_ERRNO_LIST \
7677
X(EPERM) \
7778
X(EIO) \
7879
X(EBUSY) \

bricks/virtualhub/mpconfigvariant.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ MICROPY_PY_SOCKET = 1
3030
# ffi module requires libffi (libffi-dev Debian package)
3131
MICROPY_PY_FFI = 1
3232

33-
# ussl module requires one of the TLS libraries below
34-
MICROPY_PY_USSL = 0
33+
# ssl module requires one of the TLS libraries below
34+
MICROPY_PY_SSL = 0
3535
# axTLS has minimal size but implements only a subset of modern TLS
3636
# functionality, so may have problems with some servers.
3737
MICROPY_SSL_AXTLS = 0

micropython

Submodule micropython updated 4273 files

pybricks/common/pb_type_ble.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ mp_obj_t pb_type_BLE_new(mp_obj_t broadcast_channel_in, mp_obj_t observe_channel
566566
}
567567
#endif // PBSYS_CONFIG_BLUETOOTH_TOGGLE
568568

569-
pb_obj_BLE_t *self = mp_obj_malloc_var(pb_obj_BLE_t, observed_data_t, num_observe_channels, &pb_type_BLE);
569+
pb_obj_BLE_t *self = mp_obj_malloc_var(pb_obj_BLE_t, observed_data, observed_data_t, num_observe_channels, &pb_type_BLE);
570570
self->broadcast_channel = broadcast_channel_in;
571571

572572
for (mp_int_t i = 0; i < num_observe_channels; i++) {

0 commit comments

Comments
 (0)