mirror of
https://github.com/micropython/micropython.git
synced 2026-01-06 20:20:14 +01:00
py: Add mp_raise_msg_varg helper and use it where appropriate.
This commit adds mp_raise_msg_varg(type, fmt, ...) as a helper for
nlr_raise(mp_obj_new_exception_msg_varg(type, fmt, ...)). It makes the
C-level API for raising exceptions more consistent, and reduces code size
on most ports:
bare-arm: +28 +0.042%
minimal x86: +100 +0.067%
unix x64: -56 -0.011%
unix nanbox: -300 -0.068%
stm32: -204 -0.054% PYBV10
cc3200: +0 +0.000%
esp8266: -64 -0.010% GENERIC
esp32: -104 -0.007% GENERIC
nrf: -136 -0.094% pca10040
samd: +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
This commit is contained in:
@@ -251,13 +251,13 @@ STATIC mp_obj_t machine_uart_make_new(const mp_obj_type_t *type, size_t n_args,
|
||||
// get uart id
|
||||
mp_int_t uart_num = mp_obj_get_int(args[0]);
|
||||
if (uart_num < 0 || uart_num >= UART_NUM_MAX) {
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "UART(%d) does not exist", uart_num));
|
||||
mp_raise_msg_varg(&mp_type_ValueError, "UART(%d) does not exist", uart_num);
|
||||
}
|
||||
|
||||
// Attempts to use UART0 from Python has resulted in all sorts of fun errors.
|
||||
// FIXME: UART0 is disabled for now.
|
||||
if (uart_num == UART_NUM_0) {
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "UART(%d) is disabled (dedicated to REPL)", uart_num));
|
||||
mp_raise_msg_varg(&mp_type_ValueError, "UART(%d) is disabled (dedicated to REPL)", uart_num);
|
||||
}
|
||||
|
||||
// Defaults
|
||||
|
||||
Reference in New Issue
Block a user