Merge remote-tracking branch 'origin/main' into merge-weblate-manually

This commit is contained in:
Jeff Epler 2022-11-30 21:09:31 -06:00
commit 08d372aedc
No known key found for this signature in database
GPG Key ID: D5BF15AB975AB4DE
38 changed files with 188 additions and 162 deletions

82
locale/circuitpython.pot Executable file → Normal file
View File

@ -118,7 +118,7 @@ msgstr ""
msgid "%q is %q" msgid "%q is %q"
msgstr "" msgstr ""
#: py/argcheck.c #: py/argcheck.c shared-bindings/usb_hid/Device.c
msgid "%q length must be %d" msgid "%q length must be %d"
msgstr "" msgstr ""
@ -134,10 +134,6 @@ msgstr ""
msgid "%q length must be >= %d" msgid "%q length must be >= %d"
msgstr "" msgstr ""
#: shared-bindings/busio/I2C.c
msgid "%q length must be >= 1"
msgstr ""
#: py/argcheck.c #: py/argcheck.c
msgid "%q must be %d" msgid "%q must be %d"
msgstr "" msgstr ""
@ -163,15 +159,7 @@ msgstr ""
msgid "%q must be a bytearray or array of type 'h', 'H', 'b', or 'B'" msgid "%q must be a bytearray or array of type 'h', 'H', 'b', or 'B'"
msgstr "" msgstr ""
#: py/argcheck.c #: py/argcheck.c py/obj.c py/objstrunicode.c
msgid "%q must be a string"
msgstr ""
#: py/argcheck.c
msgid "%q must be an int"
msgstr ""
#: py/argcheck.c py/obj.c
msgid "%q must be of type %q" msgid "%q must be of type %q"
msgstr "" msgstr ""
@ -201,8 +189,8 @@ msgstr ""
msgid "%q pin invalid" msgid "%q pin invalid"
msgstr "" msgstr ""
#: shared-bindings/usb_hid/Device.c #: py/objrange.c py/objslice.c shared-bindings/random/__init__.c
msgid "%q with a report ID of 0 must be of length 1" msgid "%q step cannot be zero"
msgstr "" msgstr ""
#: py/bc.c py/objnamedtuple.c #: py/bc.c py/objnamedtuple.c
@ -511,10 +499,6 @@ msgstr ""
msgid "Array values should be single bytes." msgid "Array values should be single bytes."
msgstr "" msgstr ""
#: shared-bindings/microcontroller/Pin.c
msgid "At most %d %q may be specified (not %d)"
msgstr ""
#: shared-module/memorymonitor/AllocationAlarm.c #: shared-module/memorymonitor/AllocationAlarm.c
#, c-format #, c-format
msgid "Attempt to allocate %d blocks" msgid "Attempt to allocate %d blocks"
@ -1260,10 +1244,6 @@ msgstr ""
msgid "Invalid multicast MAC address" msgid "Invalid multicast MAC address"
msgstr "" msgstr ""
#: shared-bindings/busio/UART.c
msgid "Invalid pins"
msgstr ""
#: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c #: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c
msgid "Invalid size" msgid "Invalid size"
msgstr "" msgstr ""
@ -1501,11 +1481,6 @@ msgstr ""
msgid "No long integer support" msgid "No long integer support"
msgstr "" msgstr ""
#: shared-module/usb_hid/__init__.c
#, c-format
msgid "No more than %d HID devices allowed"
msgstr ""
#: shared-bindings/wifi/Radio.c #: shared-bindings/wifi/Radio.c
msgid "No network with that ssid" msgid "No network with that ssid"
msgstr "" msgstr ""
@ -2545,10 +2520,6 @@ msgstr ""
msgid "buffer too small for requested bytes" msgid "buffer too small for requested bytes"
msgstr "" msgstr ""
#: shared-bindings/adafruit_pixelbuf/PixelBuf.c
msgid "byteorder is not a string"
msgstr ""
#: py/objarray.c #: py/objarray.c
msgid "bytes length not a multiple of item size" msgid "bytes length not a multiple of item size"
msgstr "" msgstr ""
@ -2590,14 +2561,10 @@ msgstr ""
msgid "can't cancel self" msgid "can't cancel self"
msgstr "" msgstr ""
#: py/obj.c py/objint.c shared-module/adafruit_pixelbuf/PixelBuf.c #: py/obj.c py/objint.c py/runtime.c shared-module/adafruit_pixelbuf/PixelBuf.c
msgid "can't convert %q to %q" msgid "can't convert %q to %q"
msgstr "" msgstr ""
#: py/runtime.c
msgid "can't convert %q to int"
msgstr ""
#: py/obj.c #: py/obj.c
#, c-format #, c-format
msgid "can't convert %s to complex" msgid "can't convert %s to complex"
@ -2781,10 +2748,6 @@ msgstr ""
msgid "comparison of int and uint" msgid "comparison of int and uint"
msgstr "" msgstr ""
#: py/objcomplex.c
msgid "complex division by zero"
msgstr ""
#: py/objfloat.c py/parsenum.c #: py/objfloat.c py/parsenum.c
msgid "complex values not supported" msgid "complex values not supported"
msgstr "" msgstr ""
@ -2887,12 +2850,7 @@ msgstr ""
msgid "div/mod not implemented for uint" msgid "div/mod not implemented for uint"
msgstr "" msgstr ""
#: py/objfloat.c py/objint_mpz.c #: py/runtime.c
msgid "divide by zero"
msgstr ""
#: py/modmath.c py/objint_longlong.c py/runtime.c
#: shared-bindings/math/__init__.c
msgid "division by zero" msgid "division by zero"
msgstr "" msgstr ""
@ -3264,10 +3222,6 @@ msgstr ""
msgid "inputs are not iterable" msgid "inputs are not iterable"
msgstr "" msgstr ""
#: py/parsenum.c
msgid "int() arg 2 must be >= 2 and <= 36"
msgstr ""
#: extmod/ulab/code/numpy/approx.c #: extmod/ulab/code/numpy/approx.c
msgid "interp is defined for 1D iterables of equal length" msgid "interp is defined for 1D iterables of equal length"
msgstr "" msgstr ""
@ -3405,10 +3359,6 @@ msgstr ""
msgid "local variable referenced before assignment" msgid "local variable referenced before assignment"
msgstr "" msgstr ""
#: py/objint.c
msgid "long int not supported in this build"
msgstr ""
#: ports/espressif/common-hal/canio/CAN.c #: ports/espressif/common-hal/canio/CAN.c
msgid "loopback + silent mode not supported by peripheral" msgid "loopback + silent mode not supported by peripheral"
msgstr "" msgstr ""
@ -3943,10 +3893,6 @@ msgstr ""
msgid "slice step can't be zero" msgid "slice step can't be zero"
msgstr "" msgstr ""
#: py/objslice.c
msgid "slice step cannot be zero"
msgstr ""
#: py/nativeglue.c #: py/nativeglue.c
msgid "slice unsupported" msgid "slice unsupported"
msgstr "" msgstr ""
@ -3995,10 +3941,6 @@ msgstr ""
msgid "start/end indices" msgid "start/end indices"
msgstr "" msgstr ""
#: shared-bindings/random/__init__.c
msgid "step must be non-zero"
msgstr ""
#: shared-bindings/random/__init__.c #: shared-bindings/random/__init__.c
msgid "stop not reachable from start" msgid "stop not reachable from start"
msgstr "" msgstr ""
@ -4007,10 +3949,6 @@ msgstr ""
msgid "stream operation not supported" msgid "stream operation not supported"
msgstr "" msgstr ""
#: py/objstrunicode.c
msgid "string indices must be integers, not %q"
msgstr ""
#: py/stream.c #: py/stream.c
msgid "string not supported; use bytes or bytearray" msgid "string not supported; use bytes or bytearray"
msgstr "" msgstr ""
@ -4043,10 +3981,6 @@ msgstr ""
msgid "syntax error in uctypes descriptor" msgid "syntax error in uctypes descriptor"
msgstr "" msgstr ""
#: shared-bindings/time/__init__.c
msgid "time.struct_time() takes a 9-sequence"
msgstr ""
#: ports/atmel-samd/common-hal/watchdog/WatchDogTimer.c #: ports/atmel-samd/common-hal/watchdog/WatchDogTimer.c
#: ports/espressif/common-hal/watchdog/WatchDogTimer.c #: ports/espressif/common-hal/watchdog/WatchDogTimer.c
#: ports/nrf/common-hal/watchdog/WatchDogTimer.c #: ports/nrf/common-hal/watchdog/WatchDogTimer.c
@ -4328,10 +4262,6 @@ msgstr ""
msgid "y value out of bounds" msgid "y value out of bounds"
msgstr "" msgstr ""
#: py/objrange.c
msgid "zero step"
msgstr ""
#: extmod/ulab/code/scipy/signal/signal.c #: extmod/ulab/code/scipy/signal/signal.c
msgid "zi must be an ndarray" msgid "zi must be an ndarray"
msgstr "" msgstr ""

View File

@ -282,7 +282,7 @@ msgstr "Inaasahan ng '%s' ang hangang r%d"
#: py/emitinlinethumb.c #: py/emitinlinethumb.c
#, c-format #, c-format
msgid "'%s' expects {r0, r1, ...}" msgid "'%s' expects {r0, r1, ...}"
msgstr "Inaasahan ng '%s' ay {r0, r1, }" msgstr "Inaasahan ng '%s' ay {r0, r1, ...}"
#: py/emitinlinextensa.c #: py/emitinlinextensa.c
#, c-format #, c-format
@ -2797,7 +2797,7 @@ msgstr ""
#: shared-bindings/displayio/Palette.c #: shared-bindings/displayio/Palette.c
msgid "color buffer must be a bytearray or array of type 'b' or 'B'" msgid "color buffer must be a bytearray or array of type 'b' or 'B'"
msgstr "ang color buffer ay dapat bytearray o array na type b or B" msgstr "ang color buffer ay dapat bytearray o array na type 'b' or 'B'"
#: shared-bindings/displayio/Palette.c #: shared-bindings/displayio/Palette.c
msgid "color must be between 0x000000 and 0xffffff" msgid "color must be between 0x000000 and 0xffffff"
@ -3915,7 +3915,7 @@ msgstr "return annotation ay dapat na identifier"
#: py/emitnative.c #: py/emitnative.c
msgid "return expected '%q' but got '%q'" msgid "return expected '%q' but got '%q'"
msgstr "return umasa ng '%q' pero ang nakuha ay %q" msgstr "return umasa ng '%q' pero ang nakuha ay '%q'"
#: shared-bindings/rgbmatrix/RGBMatrix.c #: shared-bindings/rgbmatrix/RGBMatrix.c
#, c-format #, c-format
@ -4625,7 +4625,7 @@ msgstr ""
#~ "Mangyaring bisitahin ang learn.adafruit.com/category/circuitpython para " #~ "Mangyaring bisitahin ang learn.adafruit.com/category/circuitpython para "
#~ "sa project guides.\n" #~ "sa project guides.\n"
#~ "\n" #~ "\n"
#~ "Para makita ang listahan ng modules, `help(“modules”)`.\n" #~ "Para makita ang listahan ng modules, `help(\"modules\")`.\n"
#~ msgid "integer required" #~ msgid "integer required"
#~ msgstr "kailangan ng int" #~ msgstr "kailangan ng int"

View File

@ -684,7 +684,7 @@ msgstr "Les blocs CBC doivent être des multiples de 16 octets"
#: supervisor/shared/safe_mode.c #: supervisor/shared/safe_mode.c
msgid "CIRCUITPY drive could not be found or created." msgid "CIRCUITPY drive could not be found or created."
msgstr "Lappareil CIRCUITPY ne peut pas être trouvé ou créé." msgstr "L'appareil CIRCUITPY ne peut pas être trouvé ou créé."
#: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c #: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c
msgid "CRC or checksum was invalid" msgid "CRC or checksum was invalid"
@ -842,11 +842,11 @@ msgstr "Fichier .mpy corrompu"
#: ports/espressif/common-hal/neopixel_write/__init__.c #: ports/espressif/common-hal/neopixel_write/__init__.c
msgid "Could not retrieve clock" msgid "Could not retrieve clock"
msgstr "Impossible dobtenir lhorloge" msgstr "Impossible d'obtenir l'horloge"
#: shared-bindings/_bleio/Adapter.c #: shared-bindings/_bleio/Adapter.c
msgid "Could not set address" msgid "Could not set address"
msgstr "Impossible de définir ladresse" msgstr "Impossible de définir l'adresse"
#: shared-bindings/pwmio/PWMOut.c #: shared-bindings/pwmio/PWMOut.c
msgid "Could not start PWM" msgid "Could not start PWM"
@ -1010,7 +1010,7 @@ msgstr "Échec d'allocation du tampon %q"
#: ports/espressif/common-hal/wifi/__init__.c #: ports/espressif/common-hal/wifi/__init__.c
msgid "Failed to allocate Wifi memory" msgid "Failed to allocate Wifi memory"
msgstr "Impossible dallouer la mémoire pour Wifi" msgstr "Impossible d'allouer la mémoire pour Wifi"
#: ports/espressif/common-hal/wifi/ScannedNetworks.c #: ports/espressif/common-hal/wifi/ScannedNetworks.c
msgid "Failed to allocate wifi scan memory" msgid "Failed to allocate wifi scan memory"
@ -1837,7 +1837,7 @@ msgstr "Ainsi que tout autres modules présents sur le système de fichiers\n"
#: shared-module/vectorio/Polygon.c #: shared-module/vectorio/Polygon.c
msgid "Polygon needs at least 3 points" msgid "Polygon needs at least 3 points"
msgstr "Polygon a besoin dau moins 3 points" msgstr "Polygon a besoin d'au moins 3 points"
#: shared-bindings/_bleio/Adapter.c #: shared-bindings/_bleio/Adapter.c
msgid "Prefix buffer must be on the heap" msgid "Prefix buffer must be on the heap"
@ -2560,7 +2560,7 @@ msgstr "matrice/octets requis à la droite"
#: extmod/ulab/code/numpy/numerical.c #: extmod/ulab/code/numpy/numerical.c
msgid "attempt to get (arg)min/(arg)max of empty sequence" msgid "attempt to get (arg)min/(arg)max of empty sequence"
msgstr "tentative dobtenir (arg)min/(arg)max d'une séquence vide" msgstr "tentative d'obtenir (arg)min/(arg)max d'une séquence vide"
#: extmod/ulab/code/numpy/numerical.c #: extmod/ulab/code/numpy/numerical.c
msgid "attempt to get argmin/argmax of an empty sequence" msgid "attempt to get argmin/argmax of an empty sequence"
@ -2628,7 +2628,7 @@ msgstr "tampon est plus petit que la taille demandée"
#: extmod/ulab/code/numpy/create.c extmod/ulab/code/utils/utils.c #: extmod/ulab/code/numpy/create.c extmod/ulab/code/utils/utils.c
msgid "buffer size must be a multiple of element size" msgid "buffer size must be a multiple of element size"
msgstr "taille du tampon doit être un multiple de la taille de lélément" msgstr "taille du tampon doit être un multiple de la taille de l'élément"
#: shared-module/struct/__init__.c #: shared-module/struct/__init__.c
msgid "buffer size must match format" msgid "buffer size must match format"
@ -3189,7 +3189,7 @@ msgstr "la fonction a reçu plusieurs valeurs pour l'argument '%q'"
#: extmod/ulab/code/scipy/optimize/optimize.c #: extmod/ulab/code/scipy/optimize/optimize.c
msgid "function has the same sign at the ends of interval" msgid "function has the same sign at the ends of interval"
msgstr "la fonction a le même signe aux extrémités de lintervalle" msgstr "la fonction a le même signe aux extrémités de l'intervalle"
#: extmod/ulab/code/ndarray.c #: extmod/ulab/code/ndarray.c
msgid "function is defined for ndarrays only" msgid "function is defined for ndarrays only"
@ -4190,11 +4190,11 @@ msgstr "le délai (timeout) doit être < 655.35 secondes"
#: shared-module/sdcardio/SDCard.c #: shared-module/sdcardio/SDCard.c
msgid "timeout waiting for v1 card" msgid "timeout waiting for v1 card"
msgstr "Délai dexpiration dépassé en attendant une carte v1" msgstr "Délai d'expiration dépassé en attendant une carte v1"
#: shared-module/sdcardio/SDCard.c #: shared-module/sdcardio/SDCard.c
msgid "timeout waiting for v2 card" msgid "timeout waiting for v2 card"
msgstr "Délai dexpiration dépassé en attendant une carte v2" msgstr "Délai d'expiration dépassé en attendant une carte v2"
#: ports/stm/common-hal/pwmio/PWMOut.c #: ports/stm/common-hal/pwmio/PWMOut.c
msgid "timer re-init" msgid "timer re-init"
@ -4394,7 +4394,7 @@ msgstr "width doit être plus que zero"
#: ports/espressif/common-hal/wifi/Radio.c #: ports/espressif/common-hal/wifi/Radio.c
#: ports/raspberrypi/common-hal/wifi/Radio.c #: ports/raspberrypi/common-hal/wifi/Radio.c
msgid "wifi is not enabled" msgid "wifi is not enabled"
msgstr "wifi nest pas activé" msgstr "wifi n'est pas activé"
#: ports/raspberrypi/common-hal/wifi/Monitor.c #: ports/raspberrypi/common-hal/wifi/Monitor.c
msgid "wifi.Monitor not available" msgid "wifi.Monitor not available"

View File

@ -283,7 +283,7 @@ msgstr "'%s' verwacht op zijn meest r%d"
#: py/emitinlinethumb.c #: py/emitinlinethumb.c
#, c-format #, c-format
msgid "'%s' expects {r0, r1, ...}" msgid "'%s' expects {r0, r1, ...}"
msgstr "'%s' verwacht {r0, r1, }" msgstr "'%s' verwacht {r0, r1, ...}"
#: py/emitinlinextensa.c #: py/emitinlinextensa.c
#, c-format #, c-format

41
main.c
View File

@ -218,12 +218,10 @@ void supervisor_execution_status(void) {
} }
#endif #endif
#define STRING_LIST(...) {__VA_ARGS__, ""}
// Look for the first file that exists in the list of filenames, using mp_import_stat(). // Look for the first file that exists in the list of filenames, using mp_import_stat().
// Return its index. If no file found, return -1. // Return its index. If no file found, return -1.
STATIC const char *first_existing_file_in_list(const char *const *filenames) { STATIC const char *first_existing_file_in_list(const char *const *filenames, size_t n_filenames) {
for (int i = 0; filenames[i] != (char *)""; i++) { for (size_t i = 0; i < n_filenames; i++) {
mp_import_stat_t stat = mp_import_stat(filenames[i]); mp_import_stat_t stat = mp_import_stat(filenames[i]);
if (stat == MP_IMPORT_STAT_FILE) { if (stat == MP_IMPORT_STAT_FILE) {
return filenames[i]; return filenames[i];
@ -232,11 +230,11 @@ STATIC const char *first_existing_file_in_list(const char *const *filenames) {
return NULL; return NULL;
} }
STATIC bool maybe_run_list(const char *const *filenames) { STATIC bool maybe_run_list(const char *const *filenames, size_t n_filenames) {
_exec_result.return_code = 0; _exec_result.return_code = 0;
_exec_result.exception = MP_OBJ_NULL; _exec_result.exception = MP_OBJ_NULL;
_exec_result.exception_line = 0; _exec_result.exception_line = 0;
_current_executing_filename = first_existing_file_in_list(filenames); _current_executing_filename = first_existing_file_in_list(filenames, n_filenames);
if (_current_executing_filename == NULL) { if (_current_executing_filename == NULL) {
return false; return false;
} }
@ -391,12 +389,14 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool *simulate_reset) {
filesystem_flush(); filesystem_flush();
} }
if (safe_mode == NO_SAFE_MODE && !autoreload_pending()) { if (safe_mode == NO_SAFE_MODE && !autoreload_pending()) {
static const char *const supported_filenames[] = STRING_LIST( static const char *const supported_filenames[] = {
"code.txt", "code.py", "main.py", "main.txt"); "code.txt", "code.py", "main.py", "main.txt"
};
#if CIRCUITPY_FULL_BUILD #if CIRCUITPY_FULL_BUILD
static const char *const double_extension_filenames[] = STRING_LIST( static const char *const double_extension_filenames[] = {
"code.txt.py", "code.py.txt", "code.txt.txt","code.py.py", "code.txt.py", "code.py.txt", "code.txt.txt","code.py.py",
"main.txt.py", "main.py.txt", "main.txt.txt","main.py.py"); "main.txt.py", "main.py.txt", "main.txt.txt","main.py.py"
};
#endif #endif
supervisor_allocation *heap = allocate_remaining_memory(); supervisor_allocation *heap = allocate_remaining_memory();
@ -410,14 +410,15 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool *simulate_reset) {
// Check if a different run file has been allocated // Check if a different run file has been allocated
if (next_code_allocation) { if (next_code_allocation) {
((next_code_info_t *)next_code_allocation->ptr)->options &= ~SUPERVISOR_NEXT_CODE_OPT_NEWLY_SET; next_code_info_t *info = ((next_code_info_t *)next_code_allocation->ptr);
next_code_options = ((next_code_info_t *)next_code_allocation->ptr)->options; info->options &= ~SUPERVISOR_NEXT_CODE_OPT_NEWLY_SET;
if (((next_code_info_t *)next_code_allocation->ptr)->filename[0] != '\0') { next_code_options = info->options;
const char *next_list[] = {((next_code_info_t *)next_code_allocation->ptr)->filename, ""}; if (info->filename[0] != '\0') {
// This is where the user's python code is actually executed: // This is where the user's python code is actually executed:
found_main = maybe_run_list(next_list); const char *const filenames[] = { info->filename };
found_main = maybe_run_list(filenames, MP_ARRAY_SIZE(filenames));
if (!found_main) { if (!found_main) {
serial_write(((next_code_info_t *)next_code_allocation->ptr)->filename); serial_write(info->filename);
serial_write_compressed(translate(" not found.\n")); serial_write_compressed(translate(" not found.\n"));
} }
} }
@ -425,11 +426,11 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool *simulate_reset) {
// Otherwise, default to the standard list of filenames // Otherwise, default to the standard list of filenames
if (!found_main) { if (!found_main) {
// This is where the user's python code is actually executed: // This is where the user's python code is actually executed:
found_main = maybe_run_list(supported_filenames); found_main = maybe_run_list(supported_filenames, MP_ARRAY_SIZE(supported_filenames));
// If that didn't work, double check the extensions // If that didn't work, double check the extensions
#if CIRCUITPY_FULL_BUILD #if CIRCUITPY_FULL_BUILD
if (!found_main) { if (!found_main) {
found_main = maybe_run_list(double_extension_filenames); found_main = maybe_run_list(double_extension_filenames, MP_ARRAY_SIZE(double_extension_filenames));
if (found_main) { if (found_main) {
serial_write_compressed(translate("WARNING: Your code filename has two extensions\n")); serial_write_compressed(translate("WARNING: Your code filename has two extensions\n"));
} }
@ -741,7 +742,7 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {
&& safe_mode == NO_SAFE_MODE && safe_mode == NO_SAFE_MODE
&& MP_STATE_VM(vfs_mount_table) != NULL; && MP_STATE_VM(vfs_mount_table) != NULL;
static const char *const boot_py_filenames[] = STRING_LIST("boot.py", "boot.txt"); static const char *const boot_py_filenames[] = {"boot.py", "boot.txt"};
// Do USB setup even if boot.py is not run. // Do USB setup even if boot.py is not run.
@ -778,7 +779,7 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {
port_boot_info(); port_boot_info();
#endif #endif
bool found_boot = maybe_run_list(boot_py_filenames); bool found_boot = maybe_run_list(boot_py_filenames, MP_ARRAY_SIZE(boot_py_filenames));
(void)found_boot; (void)found_boot;

View File

@ -24,6 +24,7 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
#if CIRCUITPY_BUSIO_UART
#include "shared-bindings/microcontroller/__init__.h" #include "shared-bindings/microcontroller/__init__.h"
#include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/microcontroller/Pin.h"
#include "shared-bindings/busio/UART.h" #include "shared-bindings/busio/UART.h"
@ -485,3 +486,4 @@ bool common_hal_busio_uart_ready_to_tx(busio_uart_obj_t *self) {
usart_async_get_status(usart_desc_p, &async_status); usart_async_get_status(usart_desc_p, &async_status);
return !(async_status.flags & USART_ASYNC_STATUS_BUSY); return !(async_status.flags & USART_ASYNC_STATUS_BUSY);
} }
#endif

View File

@ -33,6 +33,8 @@
#define MICROPY_USE_INTERNAL_PRINTF (0) #define MICROPY_USE_INTERNAL_PRINTF (0)
#define MICROPY_PY_SYS_PLATFORM "Espressif" #define MICROPY_PY_SYS_PLATFORM "Espressif"
#define CIRCUITPY_DIGITALIO_HAVE_INPUT_ONLY (1)
#include "py/circuitpy_mpconfig.h" #include "py/circuitpy_mpconfig.h"
#if CIRCUITPY_BLEIO #if CIRCUITPY_BLEIO

View File

@ -145,9 +145,11 @@ void mp_arg_parse_all_kw_array(size_t n_pos, size_t n_kw, const mp_obj_t *args,
mp_arg_parse_all(n_pos, args, &kw_args, n_allowed, allowed, out_vals); mp_arg_parse_all(n_pos, args, &kw_args, n_allowed, allowed, out_vals);
} }
#if MICROPY_ERROR_REPORTING <= MICROPY_ERROR_REPORTING_TERSE
NORETURN void mp_arg_error_terse_mismatch(void) { NORETURN void mp_arg_error_terse_mismatch(void) {
mp_raise_TypeError(MP_ERROR_TEXT("argument num/types mismatch")); mp_raise_TypeError(MP_ERROR_TEXT("argument num/types mismatch"));
} }
#endif
#if MICROPY_CPYTHON_COMPAT #if MICROPY_CPYTHON_COMPAT
NORETURN void mp_arg_error_unimpl_kw(void) { NORETURN void mp_arg_error_unimpl_kw(void) {
@ -239,7 +241,7 @@ mp_obj_t mp_arg_validate_type(mp_obj_t obj, const mp_obj_type_t *type, qstr arg_
mp_obj_t mp_arg_validate_type_string(mp_obj_t obj, qstr arg_name) { mp_obj_t mp_arg_validate_type_string(mp_obj_t obj, qstr arg_name) {
if (!mp_obj_is_str(obj)) { if (!mp_obj_is_str(obj)) {
mp_raise_TypeError_varg(translate("%q must be a string"), arg_name); mp_raise_TypeError_varg(translate("%q must be of type %q"), arg_name, MP_QSTR_str);
} }
return obj; return obj;
} }
@ -247,7 +249,7 @@ mp_obj_t mp_arg_validate_type_string(mp_obj_t obj, qstr arg_name) {
mp_int_t mp_arg_validate_type_int(mp_obj_t obj, qstr arg_name) { mp_int_t mp_arg_validate_type_int(mp_obj_t obj, qstr arg_name) {
mp_int_t an_int; mp_int_t an_int;
if (!mp_obj_get_int_maybe(obj, &an_int)) { if (!mp_obj_get_int_maybe(obj, &an_int)) {
mp_raise_TypeError_varg(translate("%q must be an int"), arg_name); mp_raise_TypeError_varg(translate("%q must be of type %q"), arg_name, MP_QSTR_int);
} }
return an_int; return an_int;
} }

View File

@ -582,6 +582,10 @@ void supervisor_run_background_tasks_if_tick(void);
#define MICROPY_WRAP_MP_EXECUTE_BYTECODE PLACE_IN_ITCM #define MICROPY_WRAP_MP_EXECUTE_BYTECODE PLACE_IN_ITCM
#endif #endif
#ifndef CIRCUITPY_DIGITALIO_HAVE_INPUT_ONLY
#define CIRCUITPY_DIGITALIO_HAVE_INPUT_ONLY (0)
#endif
#ifndef CIRCUITPY_DIGITALIO_HAVE_INVALID_PULL #ifndef CIRCUITPY_DIGITALIO_HAVE_INVALID_PULL
#define CIRCUITPY_DIGITALIO_HAVE_INVALID_PULL (0) #define CIRCUITPY_DIGITALIO_HAVE_INVALID_PULL (0)
#endif #endif

View File

@ -12,7 +12,7 @@ import subprocess
from makeqstrdefs import qstr_unescape, QSTRING_BLOCK_LIST from makeqstrdefs import qstr_unescape, QSTRING_BLOCK_LIST
re_line = re.compile(r"#[line]*\s(\d+)\s\"([^\"]+)\"", re.DOTALL) re_line = re.compile(r"#[line]*\s(\d+)\s\"([^\"]+)\"", re.DOTALL)
re_qstr = re.compile(r"MP_QSTR_[_a-zA-Z0-9]+", re.DOTALL) re_qstr = re.compile(r"\bMP_QSTR_[_a-zA-Z0-9]+", re.DOTALL)
re_translate = re.compile(r"translate\(\"((?:(?=(\\?))\2.)*?)\"\)", re.DOTALL) re_translate = re.compile(r"translate\(\"((?:(?=(\\?))\2.)*?)\"\)", re.DOTALL)

View File

@ -10,6 +10,7 @@ supervisor/shared/translate/translate.h
from __future__ import print_function from __future__ import print_function
import bisect import bisect
from dataclasses import dataclass
import re import re
import sys import sys
@ -146,15 +147,69 @@ def iter_substrings(s, minlen, maxlen):
yield s[begin : begin + n] yield s[begin : begin + n]
def compute_huffman_coding(translations, f): translation_requires_uint16 = {"cs", "ja", "ko", "pl", "tr", "zh_Latn_pinyin"}
def compute_unicode_offset(texts):
all_ch = set(" ".join(texts))
ch_160 = sorted(c for c in all_ch if 160 <= ord(c) < 255)
ch_256 = sorted(c for c in all_ch if 255 < ord(c))
if not ch_256:
return 0, 0
min_256 = ord(min(ch_256))
span = ord(max(ch_256)) - ord(min(ch_256)) + 1
if ch_160:
max_160 = ord(max(ch_160)) + 1
else:
max_160 = max(160, 255 - span)
if max_160 + span > 256:
return 0, 0
offstart = max_160
offset = min_256 - max_160
return offstart, offset
@dataclass
class EncodingTable:
values: object
lengths: object
words: object
canonical: object
extractor: object
apply_offset: object
remove_offset: object
def compute_huffman_coding(translation_name, translations, f):
texts = [t[1] for t in translations] texts = [t[1] for t in translations]
words = [] words = []
start_unused = 0x80 start_unused = 0x80
end_unused = 0xFF end_unused = 0xFF
max_ord = 0 max_ord = 0
offstart, offset = compute_unicode_offset(texts)
def apply_offset(c):
oc = ord(c)
if oc >= offstart:
oc += offset
return chr(oc)
def remove_offset(c):
oc = ord(c)
if oc >= offstart:
oc = oc - offset
try:
return chr(oc)
except Exception as e:
raise ValueError(f"remove_offset {offstart=} {oc=}") from e
for text in texts: for text in texts:
for c in text: for c in text:
c = remove_offset(c)
ord_c = ord(c) ord_c = ord(c)
max_ord = max(ord_c, max_ord) max_ord = max(ord_c, max_ord)
if 0x80 <= ord_c < 0xFF: if 0x80 <= ord_c < 0xFF:
@ -163,6 +218,12 @@ def compute_huffman_coding(translations, f):
bits_per_codepoint = 16 if max_ord > 255 else 8 bits_per_codepoint = 16 if max_ord > 255 else 8
values_type = "uint16_t" if max_ord > 255 else "uint8_t" values_type = "uint16_t" if max_ord > 255 else "uint8_t"
translation_name = translation_name.split("/")[-1].split(".")[0]
if max_ord > 255 and translation_name not in translation_requires_uint16:
raise ValueError(
f"Translation {translation_name} expected to fit in 8 bits but required 16 bits"
)
while len(words) < max_words: while len(words) < max_words:
# Until the dictionary is filled to capacity, use a heuristic to find # Until the dictionary is filled to capacity, use a heuristic to find
# the best "word" (2- to 11-gram) to add to it. # the best "word" (2- to 11-gram) to add to it.
@ -267,15 +328,17 @@ def compute_huffman_coding(translations, f):
length_count[length] += 1 length_count[length] += 1
if last_length: if last_length:
renumbered <<= length - last_length renumbered <<= length - last_length
canonical[atom] = "{0:0{width}b}".format(renumbered, width=length)
# print(f"atom={repr(atom)} code={code}", file=sys.stderr) # print(f"atom={repr(atom)} code={code}", file=sys.stderr)
canonical[atom] = "{0:0{width}b}".format(renumbered, width=length)
if len(atom) > 1: if len(atom) > 1:
o = words.index(atom) + 0x80 o = words.index(atom) + 0x80
s = "".join(C_ESCAPES.get(ch1, ch1) for ch1 in atom) s = "".join(C_ESCAPES.get(ch1, ch1) for ch1 in atom)
f.write(f"// {o} {s} {counter[atom]} {canonical[atom]} {renumbered}\n")
else: else:
s = C_ESCAPES.get(atom, atom) s = C_ESCAPES.get(atom, atom)
canonical[atom] = "{0:0{width}b}".format(renumbered, width=length)
o = ord(atom) o = ord(atom)
f.write(f"// {o} {s} {counter[atom]} {canonical[atom]} {renumbered}\n") f.write(f"// {o} {s} {counter[atom]} {canonical[atom]} {renumbered}\n")
renumbered += 1 renumbered += 1
last_length = length last_length = length
lengths = bytearray() lengths = bytearray()
@ -297,7 +360,11 @@ def compute_huffman_coding(translations, f):
f.write("typedef {} mchar_t;\n".format(values_type)) f.write("typedef {} mchar_t;\n".format(values_type))
f.write("const uint8_t lengths[] = {{ {} }};\n".format(", ".join(map(str, lengths)))) f.write("const uint8_t lengths[] = {{ {} }};\n".format(", ".join(map(str, lengths))))
f.write("const mchar_t values[] = {{ {} }};\n".format(", ".join(str(ord(u)) for u in values))) f.write(
"const mchar_t values[] = {{ {} }};\n".format(
", ".join(str(ord(remove_offset(u))) for u in values)
)
)
f.write( f.write(
"#define compress_max_length_bits ({})\n".format( "#define compress_max_length_bits ({})\n".format(
max_translation_encoded_length.bit_length() max_translation_encoded_length.bit_length()
@ -305,7 +372,7 @@ def compute_huffman_coding(translations, f):
) )
f.write( f.write(
"const mchar_t words[] = {{ {} }};\n".format( "const mchar_t words[] = {{ {} }};\n".format(
", ".join(str(ord(c)) for w in words for c in w) ", ".join(str(ord(remove_offset(c))) for w in words for c in w)
) )
) )
f.write("const uint8_t wlencount[] = {{ {} }};\n".format(", ".join(str(p) for p in wlencount))) f.write("const uint8_t wlencount[] = {{ {} }};\n".format(", ".join(str(p) for p in wlencount)))
@ -313,12 +380,17 @@ def compute_huffman_coding(translations, f):
f.write("#define word_end {}\n".format(word_end)) f.write("#define word_end {}\n".format(word_end))
f.write("#define minlen {}\n".format(minlen)) f.write("#define minlen {}\n".format(minlen))
f.write("#define maxlen {}\n".format(maxlen)) f.write("#define maxlen {}\n".format(maxlen))
f.write("#define translation_offstart {}\n".format(offstart))
f.write("#define translation_offset {}\n".format(offset))
return (values, lengths, words, canonical, extractor) return EncodingTable(values, lengths, words, canonical, extractor, apply_offset, remove_offset)
def decompress(encoding_table, encoded, encoded_length_bits): def decompress(encoding_table, encoded, encoded_length_bits):
(values, lengths, words, _, _) = encoding_table values = encoding_table.values
lengths = encoding_table.lengths
words = encoding_table.words
dec = [] dec = []
this_byte = 0 this_byte = 0
this_bit = 7 this_bit = 7
@ -376,7 +448,8 @@ def decompress(encoding_table, encoded, encoded_length_bits):
def compress(encoding_table, decompressed, encoded_length_bits, len_translation_encoded): def compress(encoding_table, decompressed, encoded_length_bits, len_translation_encoded):
if not isinstance(decompressed, str): if not isinstance(decompressed, str):
raise TypeError() raise TypeError()
(_, _, _, canonical, extractor) = encoding_table canonical = encoding_table.canonical
extractor = encoding_table.extractor
enc = bytearray(len(decompressed) * 3) enc = bytearray(len(decompressed) * 3)
current_bit = 7 current_bit = 7
@ -522,5 +595,7 @@ if __name__ == "__main__":
i18ns = parse_input_headers(args.infiles) i18ns = parse_input_headers(args.infiles)
i18ns = sorted(i18ns) i18ns = sorted(i18ns)
translations = translate(args.translation, i18ns) translations = translate(args.translation, i18ns)
encoding_table = compute_huffman_coding(translations, args.compression_filename) encoding_table = compute_huffman_coding(
args.translation, translations, args.compression_filename
)
output_translation_data(encoding_table, translations, args.translation_filename) output_translation_data(encoding_table, translations, args.translation_filename)

View File

@ -254,7 +254,7 @@ STATIC mp_obj_t mp_math_log(size_t n_args, const mp_obj_t *args) {
if (base <= (mp_float_t)0.0) { if (base <= (mp_float_t)0.0) {
math_error(); math_error();
} else if (base == (mp_float_t)1.0) { } else if (base == (mp_float_t)1.0) {
mp_raise_msg(&mp_type_ZeroDivisionError, MP_ERROR_TEXT("division by zero")); mp_raise_ZeroDivisionError();
} }
return mp_obj_new_float(l / MICROPY_FLOAT_C_FUN(log)(base)); return mp_obj_new_float(l / MICROPY_FLOAT_C_FUN(log)(base));
} }

View File

@ -217,7 +217,7 @@ mp_obj_t mp_obj_complex_binary_op(mp_binary_op_t op, mp_float_t lhs_real, mp_flo
case MP_BINARY_OP_INPLACE_TRUE_DIVIDE: case MP_BINARY_OP_INPLACE_TRUE_DIVIDE:
if (rhs_imag == 0) { if (rhs_imag == 0) {
if (rhs_real == 0) { if (rhs_real == 0) {
mp_raise_msg(&mp_type_ZeroDivisionError, MP_ERROR_TEXT("complex division by zero")); mp_raise_ZeroDivisionError();
} }
lhs_real /= rhs_real; lhs_real /= rhs_real;
lhs_imag /= rhs_real; lhs_imag /= rhs_real;

View File

@ -266,7 +266,7 @@ mp_obj_t mp_obj_float_binary_op(mp_binary_op_t op, mp_float_t lhs_val, mp_obj_t
case MP_BINARY_OP_INPLACE_FLOOR_DIVIDE: case MP_BINARY_OP_INPLACE_FLOOR_DIVIDE:
if (rhs_val == 0) { if (rhs_val == 0) {
zero_division_error: zero_division_error:
mp_raise_msg(&mp_type_ZeroDivisionError, MP_ERROR_TEXT("divide by zero")); mp_raise_ZeroDivisionError();
} }
// Python specs require that x == (x//y)*y + (x%y) so we must // Python specs require that x == (x//y)*y + (x%y) so we must
// call divmod to compute the correct floor division, which // call divmod to compute the correct floor division, which

View File

@ -396,7 +396,7 @@ mp_obj_t mp_obj_int_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_i
// This is called only with strings whose value doesn't fit in SMALL_INT // This is called only with strings whose value doesn't fit in SMALL_INT
mp_obj_t mp_obj_new_int_from_str_len(const char **str, size_t len, bool neg, unsigned int base) { mp_obj_t mp_obj_new_int_from_str_len(const char **str, size_t len, bool neg, unsigned int base) {
mp_raise_msg(&mp_type_OverflowError, MP_ERROR_TEXT("long int not supported in this build")); mp_raise_msg(&mp_type_OverflowError, MP_ERROR_TEXT("small int overflow"));
return mp_const_none; return mp_const_none;
} }

View File

@ -236,7 +236,7 @@ mp_obj_t mp_obj_int_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_i
} }
zero_division: zero_division:
mp_raise_msg(&mp_type_ZeroDivisionError, MP_ERROR_TEXT("division by zero")); mp_raise_ZeroDivisionError();
} }
mp_obj_t mp_obj_new_int(mp_int_t value) { mp_obj_t mp_obj_new_int(mp_int_t value) {

View File

@ -244,7 +244,7 @@ mp_obj_t mp_obj_int_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_i
case MP_BINARY_OP_INPLACE_FLOOR_DIVIDE: { case MP_BINARY_OP_INPLACE_FLOOR_DIVIDE: {
if (mpz_is_zero(zrhs)) { if (mpz_is_zero(zrhs)) {
zero_division_error: zero_division_error:
mp_raise_msg(&mp_type_ZeroDivisionError, MP_ERROR_TEXT("divide by zero")); mp_raise_ZeroDivisionError();
} }
mpz_t rem; mpz_t rem;
mpz_init_zero(&rem); mpz_init_zero(&rem);

View File

@ -110,7 +110,7 @@ STATIC mp_obj_t range_make_new(const mp_obj_type_t *type, size_t n_args, size_t
if (n_args == 3) { if (n_args == 3) {
o->step = mp_obj_get_int(args[2]); o->step = mp_obj_get_int(args[2]);
if (o->step == 0) { if (o->step == 0) {
mp_raise_ValueError(MP_ERROR_TEXT("zero step")); mp_raise_ValueError_varg(MP_ERROR_TEXT("%q step cannot be zero"), MP_QSTR_range);
} }
} }
} }

View File

@ -157,7 +157,7 @@ void mp_obj_slice_indices(mp_obj_t self_in, mp_int_t length, mp_bound_slice_t *r
} else { } else {
step = mp_obj_get_int(self->step); step = mp_obj_get_int(self->step);
if (step == 0) { if (step == 0) {
mp_raise_ValueError(MP_ERROR_TEXT("slice step cannot be zero")); mp_raise_ValueError_varg(MP_ERROR_TEXT("%q step cannot be zero"), MP_QSTR_slice);
} }
} }

View File

@ -159,7 +159,7 @@ const byte *str_index_to_ptr(const mp_obj_type_t *type, const byte *self_data, s
if (mp_obj_is_small_int(index)) { if (mp_obj_is_small_int(index)) {
i = MP_OBJ_SMALL_INT_VALUE(index); i = MP_OBJ_SMALL_INT_VALUE(index);
} else if (!mp_obj_get_int_maybe(index, &i)) { } else if (!mp_obj_get_int_maybe(index, &i)) {
mp_raise_TypeError_varg(MP_ERROR_TEXT("string indices must be integers, not %q"), mp_obj_get_type_qstr(index)); mp_raise_TypeError_varg(translate("%q must be of type %q"), MP_QSTR_index, MP_QSTR_int);
} }
const byte *s, *top = self_data + self_len; const byte *s, *top = self_data + self_len;
if (i < 0) { if (i < 0) {

View File

@ -55,9 +55,9 @@ mp_obj_t mp_parse_num_integer(const char *restrict str_, size_t len, int base, m
mp_obj_t ret_val; mp_obj_t ret_val;
// check radix base // check radix base
if ((base != 0 && base < 2) || base > 36) { if (base != 0) {
// this won't be reached if lex!=NULL // this won't be reached if lex!=NULL
mp_raise_ValueError(MP_ERROR_TEXT("int() arg 2 must be >= 2 and <= 36")); mp_arg_validate_int_range(base, 2, 36, MP_QSTR_base);
} }
// skip leading space // skip leading space

View File

@ -262,8 +262,15 @@ $(HEADER_BUILD)/qstrdefs.generated.h: $(PY_SRC)/makeqstrdata.py $(HEADER_BUILD)/
$(STEPECHO) "GEN $@" $(STEPECHO) "GEN $@"
$(Q)$(PYTHON) $(PY_SRC)/makeqstrdata.py --output_type=data $(HEADER_BUILD)/qstrdefs.preprocessed.h > $@ $(Q)$(PYTHON) $(PY_SRC)/makeqstrdata.py --output_type=data $(HEADER_BUILD)/qstrdefs.preprocessed.h > $@
$(PY_BUILD)/translations-$(TRANSLATION).c $(HEADER_BUILD)/compression.generated.h: $(PY_SRC)/maketranslationdata.py $(HEADER_BUILD)/$(TRANSLATION).mo $(HEADER_BUILD)/qstrdefs.preprocessed.h # Is generated as a side-effect of building compression.generated.h
# Specifying both in a single rule actually causes the rule to be run twice!
# This alternative makes it run just once.
$(PY_BUILD)/translations-$(TRANSLATION).c: $(HEADER_BUILD)/compression.generated.h
@true
$(HEADER_BUILD)/compression.generated.h: $(PY_SRC)/maketranslationdata.py $(HEADER_BUILD)/$(TRANSLATION).mo $(HEADER_BUILD)/qstrdefs.preprocessed.h
$(STEPECHO) "GEN $@" $(STEPECHO) "GEN $@"
$(Q)mkdir -p $(PY_BUILD)
$(Q)$(PYTHON) $(PY_SRC)/maketranslationdata.py --compression_filename $(HEADER_BUILD)/compression.generated.h --translation $(HEADER_BUILD)/$(TRANSLATION).mo --translation_filename $(PY_BUILD)/translations-$(TRANSLATION).c $(HEADER_BUILD)/qstrdefs.preprocessed.h $(Q)$(PYTHON) $(PY_SRC)/maketranslationdata.py --compression_filename $(HEADER_BUILD)/compression.generated.h --translation $(HEADER_BUILD)/$(TRANSLATION).mo --translation_filename $(PY_BUILD)/translations-$(TRANSLATION).c $(HEADER_BUILD)/qstrdefs.preprocessed.h
PY_CORE_O += $(PY_BUILD)/translations-$(TRANSLATION).o PY_CORE_O += $(PY_BUILD)/translations-$(TRANSLATION).o

View File

@ -49,7 +49,6 @@ Q({:#x})
Q({:#b}) Q({:#b})
Q( ) Q( )
Q(\n) Q(\n)
Q(maximum recursion depth exceeded)
Q(<module>) Q(<module>)
Q(<lambda>) Q(<lambda>)
Q(<listcomp>) Q(<listcomp>)
@ -63,7 +62,3 @@ Q(utf-8)
#if MICROPY_MODULE_FROZEN #if MICROPY_MODULE_FROZEN
Q(.frozen) Q(.frozen)
#endif #endif
#if MICROPY_ENABLE_PYSTACK
Q(pystack exhausted)
#endif

View File

@ -310,7 +310,7 @@ mp_obj_t mp_unary_op(mp_unary_op_t op, mp_obj_t arg) {
} }
#else #else
if (op == MP_UNARY_OP_INT) { if (op == MP_UNARY_OP_INT) {
mp_raise_TypeError_varg(MP_ERROR_TEXT("can't convert %q to int"), mp_obj_get_type_qstr(arg)); mp_raise_TypeError_varg(MP_ERROR_TEXT("can't convert %q to %q"), mp_obj_get_type_qstr(arg), MP_QSTR_int);
} else { } else {
mp_raise_TypeError_varg(MP_ERROR_TEXT("unsupported type for %q: '%q'"), mp_raise_TypeError_varg(MP_ERROR_TEXT("unsupported type for %q: '%q'"),
mp_unary_op_method_name[op], mp_obj_get_type_qstr(arg)); mp_unary_op_method_name[op], mp_obj_get_type_qstr(arg));
@ -631,7 +631,7 @@ unsupported_op:
#endif #endif
zero_division: zero_division:
mp_raise_msg(&mp_type_ZeroDivisionError, MP_ERROR_TEXT("division by zero")); mp_raise_ZeroDivisionError();
} }
mp_obj_t mp_call_function_0(mp_obj_t fun) { mp_obj_t mp_call_function_0(mp_obj_t fun) {
@ -1765,3 +1765,7 @@ NORETURN void mp_raise_recursion_depth(void) {
mp_raise_RuntimeError(MP_ERROR_TEXT("maximum recursion depth exceeded")); mp_raise_RuntimeError(MP_ERROR_TEXT("maximum recursion depth exceeded"));
} }
#endif #endif
NORETURN void mp_raise_ZeroDivisionError(void) {
mp_raise_msg(&mp_type_ZeroDivisionError, MP_ERROR_TEXT("division by zero"));
}

View File

@ -91,7 +91,9 @@ static inline void mp_arg_check_num(size_t n_args, size_t n_kw, size_t n_args_mi
} }
void mp_arg_parse_all(size_t n_pos, const mp_obj_t *pos, mp_map_t *kws, size_t n_allowed, const mp_arg_t *allowed, mp_arg_val_t *out_vals); void mp_arg_parse_all(size_t n_pos, const mp_obj_t *pos, mp_map_t *kws, size_t n_allowed, const mp_arg_t *allowed, mp_arg_val_t *out_vals);
void mp_arg_parse_all_kw_array(size_t n_pos, size_t n_kw, const mp_obj_t *args, size_t n_allowed, const mp_arg_t *allowed, mp_arg_val_t *out_vals); void mp_arg_parse_all_kw_array(size_t n_pos, size_t n_kw, const mp_obj_t *args, size_t n_allowed, const mp_arg_t *allowed, mp_arg_val_t *out_vals);
#if MICROPY_ERROR_REPORTING <= MICROPY_ERROR_REPORTING_TERSE
NORETURN void mp_arg_error_terse_mismatch(void); NORETURN void mp_arg_error_terse_mismatch(void);
#endif
NORETURN void mp_arg_error_unimpl_kw(void); NORETURN void mp_arg_error_unimpl_kw(void);
NORETURN void mp_arg_error_invalid(qstr arg_name); NORETURN void mp_arg_error_invalid(qstr arg_name);
@ -226,6 +228,7 @@ NORETURN void mp_raise_NotImplementedError(const compressed_string_t *msg);
NORETURN void mp_raise_NotImplementedError_varg(const compressed_string_t *fmt, ...); NORETURN void mp_raise_NotImplementedError_varg(const compressed_string_t *fmt, ...);
NORETURN void mp_raise_OverflowError_varg(const compressed_string_t *fmt, ...); NORETURN void mp_raise_OverflowError_varg(const compressed_string_t *fmt, ...);
NORETURN void mp_raise_recursion_depth(void); NORETURN void mp_raise_recursion_depth(void);
NORETURN void mp_raise_ZeroDivisionError(void);
#endif #endif
#if MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG #if MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG

View File

@ -105,9 +105,13 @@ STATIC mp_obj_t adafruit_bus_device_spidevice_make_new(const mp_obj_type_t *type
if (args[ARG_chip_select].u_obj != MP_OBJ_NULL) { if (args[ARG_chip_select].u_obj != MP_OBJ_NULL) {
digitalinout_result_t result = common_hal_digitalio_digitalinout_switch_to_output(MP_OBJ_TO_PTR(args[ARG_chip_select].u_obj), digitalinout_result_t result = common_hal_digitalio_digitalinout_switch_to_output(MP_OBJ_TO_PTR(args[ARG_chip_select].u_obj),
true, DRIVE_MODE_PUSH_PULL); true, DRIVE_MODE_PUSH_PULL);
#if CIRCUITPY_DIGITALIO_HAVE_INPUT_ONLY
if (result == DIGITALINOUT_INPUT_ONLY) { if (result == DIGITALINOUT_INPUT_ONLY) {
mp_raise_NotImplementedError(translate("Pin is input only")); mp_raise_NotImplementedError(translate("Pin is input only"));
} }
#else
(void)result;
#endif
} }
return (mp_obj_t)self; return (mp_obj_t)self;

View File

@ -129,9 +129,7 @@ STATIC mp_obj_t pixelbuf_pixelbuf_make_new(const mp_obj_type_t *type, size_t n_a
} }
static void parse_byteorder(mp_obj_t byteorder_obj, pixelbuf_byteorder_details_t *parsed) { static void parse_byteorder(mp_obj_t byteorder_obj, pixelbuf_byteorder_details_t *parsed) {
if (!mp_obj_is_str(byteorder_obj)) { mp_arg_validate_type_string(byteorder_obj, MP_QSTR_byteorder);
mp_raise_TypeError(translate("byteorder is not a string"));
}
size_t bo_len; size_t bo_len;
const char *byteorder = mp_obj_str_get_data(byteorder_obj, &bo_len); const char *byteorder = mp_obj_str_get_data(byteorder_obj, &bo_len);

View File

@ -344,9 +344,7 @@ STATIC mp_obj_t busio_i2c_writeto_then_readfrom(size_t n_args, const mp_obj_t *p
int32_t in_start = args[ARG_in_start].u_int; int32_t in_start = args[ARG_in_start].u_int;
const int32_t in_end = args[ARG_in_end].u_int; const int32_t in_end = args[ARG_in_end].u_int;
normalize_buffer_bounds(&in_start, in_end, &in_length); normalize_buffer_bounds(&in_start, in_end, &in_length);
if (in_length == 0) { mp_arg_validate_length_min(in_length, 1, MP_QSTR_out_buffer);
mp_raise_ValueError_varg(translate("%q length must be >= 1"), MP_QSTR_out_buffer);
}
uint8_t status = common_hal_busio_i2c_write_read(self, args[ARG_address].u_int, uint8_t status = common_hal_busio_i2c_write_read(self, args[ARG_address].u_int,
((uint8_t *)out_bufinfo.buf) + out_start, out_length,((uint8_t *)in_bufinfo.buf) + in_start, in_length); ((uint8_t *)out_bufinfo.buf) + out_start, out_length,((uint8_t *)in_bufinfo.buf) + in_start, in_length);

View File

@ -155,7 +155,7 @@ STATIC mp_obj_t busio_uart_make_new(const mp_obj_type_t *type, size_t n_args, si
args[ARG_receiver_buffer_size].u_int, NULL, false); args[ARG_receiver_buffer_size].u_int, NULL, false);
return (mp_obj_t)self; return (mp_obj_t)self;
#else #else
mp_raise_ValueError(translate("Invalid pins")); mp_raise_NotImplementedError(NULL);
#endif // CIRCUITPY_BUSIO_UART #endif // CIRCUITPY_BUSIO_UART
} }

View File

@ -53,8 +53,10 @@ STATIC void check_result(digitalinout_result_t result) {
return; return;
case DIGITALINOUT_PIN_BUSY: case DIGITALINOUT_PIN_BUSY:
mp_raise_ValueError_varg(translate("%q in use"), MP_QSTR_Pin); mp_raise_ValueError_varg(translate("%q in use"), MP_QSTR_Pin);
#if CIRCUITPY_DIGITALIO_HAVE_INPUT_ONLY
case DIGITALINOUT_INPUT_ONLY: case DIGITALINOUT_INPUT_ONLY:
mp_raise_ValueError_varg(translate("Invalid %q"), MP_QSTR_direction); mp_raise_ValueError_varg(translate("Invalid %q"), MP_QSTR_direction);
#endif
#if CIRCUITPY_DIGITALIO_HAVE_INVALID_PULL #if CIRCUITPY_DIGITALIO_HAVE_INVALID_PULL
case DIGITALINOUT_INVALID_PULL: case DIGITALINOUT_INVALID_PULL:
mp_raise_ValueError_varg(translate("Invalid %q"), MP_QSTR_pull); mp_raise_ValueError_varg(translate("Invalid %q"), MP_QSTR_pull);

View File

@ -38,7 +38,9 @@ extern const mp_obj_type_t digitalio_digitalinout_type;
typedef enum { typedef enum {
DIGITALINOUT_OK, DIGITALINOUT_OK,
DIGITALINOUT_PIN_BUSY, DIGITALINOUT_PIN_BUSY,
#if CIRCUITPY_DIGITALIO_HAVE_INPUT_ONLY
DIGITALINOUT_INPUT_ONLY, DIGITALINOUT_INPUT_ONLY,
#endif
#if CIRCUITPY_DIGITALIO_HAVE_INVALID_PULL #if CIRCUITPY_DIGITALIO_HAVE_INVALID_PULL
DIGITALINOUT_INVALID_PULL, DIGITALINOUT_INVALID_PULL,
#endif #endif

View File

@ -371,7 +371,7 @@ STATIC mp_obj_t mp_math_log(size_t n_args, const mp_obj_t *args) {
#pragma GCC diagnostic ignored "-Wfloat-equal" #pragma GCC diagnostic ignored "-Wfloat-equal"
} else if (base == (mp_float_t)1.0) { } else if (base == (mp_float_t)1.0) {
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
mp_raise_msg(&mp_type_ZeroDivisionError, translate("division by zero")); math_error();
} }
return mp_obj_new_float(l / MICROPY_FLOAT_C_FUN(log)(base)); return mp_obj_new_float(l / MICROPY_FLOAT_C_FUN(log)(base));
} }

View File

@ -156,9 +156,7 @@ void validate_no_duplicate_pins_2(mp_obj_t seq1, mp_obj_t seq2, qstr arg_name1,
// Validate every element in the list to be a free pin. // Validate every element in the list to be a free pin.
void validate_list_is_free_pins(qstr what, const mcu_pin_obj_t **pins_out, mp_int_t max_pins, mp_obj_t seq, uint8_t *count_out) { void validate_list_is_free_pins(qstr what, const mcu_pin_obj_t **pins_out, mp_int_t max_pins, mp_obj_t seq, uint8_t *count_out) {
mp_int_t len = MP_OBJ_SMALL_INT_VALUE(mp_obj_len(seq)); mp_int_t len = MP_OBJ_SMALL_INT_VALUE(mp_obj_len(seq));
if (len > max_pins) { mp_arg_validate_length_max(len, max_pins, what);
mp_raise_ValueError_varg(translate("At most %d %q may be specified (not %d)"), max_pins, what, len);
}
*count_out = len; *count_out = len;
for (mp_int_t i = 0; i < len; i++) { for (mp_int_t i = 0; i < len; i++) {
pins_out[i] = validate_obj_is_free_pin(mp_obj_subscr(seq, MP_OBJ_NEW_SMALL_INT(i), MP_OBJ_SENTINEL)); pins_out[i] = validate_obj_is_free_pin(mp_obj_subscr(seq, MP_OBJ_NEW_SMALL_INT(i), MP_OBJ_SENTINEL));

View File

@ -108,7 +108,7 @@ STATIC mp_obj_t random_randrange(size_t n_args, const mp_obj_t *args) {
} else if (step < 0) { } else if (step < 0) {
n = (stop - start + step + 1) / step; n = (stop - start + step + 1) / step;
} else { } else {
mp_raise_ValueError(translate("step must be non-zero")); mp_raise_ValueError_varg(MP_ERROR_TEXT("%q step cannot be zero"), MP_QSTR_randrange);
} }
if (n <= 0) { if (n <= 0) {
mp_raise_ValueError(translate("invalid step")); mp_raise_ValueError(translate("invalid step"));

View File

@ -97,9 +97,7 @@ STATIC mp_obj_t struct_time_make_new(const mp_obj_type_t *type, size_t n_args, s
size_t len; size_t len;
mp_obj_t *items; mp_obj_t *items;
mp_obj_get_array(args[0], &len, &items); mp_obj_get_array(args[0], &len, &items);
if (len != 9) { mp_arg_validate_length(len, 9, MP_QSTR_value);
mp_raise_TypeError(translate("time.struct_time() takes a 9-sequence"));
}
return namedtuple_make_new(type, len, 0, items); return namedtuple_make_new(type, len, 0, items);
} }

View File

@ -155,7 +155,7 @@ STATIC mp_obj_t usb_hid_device_make_new(const mp_obj_type_t *type, size_t n_args
} }
if (report_ids_array[0] == 0 && report_ids_count > 1) { if (report_ids_array[0] == 0 && report_ids_count > 1) {
mp_raise_ValueError_varg(translate("%q with a report ID of 0 must be of length 1"), MP_QSTR_report_ids); mp_raise_ValueError_varg(translate("%q length must be %d"), MP_QSTR_report_id_space_0, 1);
} }
common_hal_usb_hid_device_construct( common_hal_usb_hid_device_construct(

View File

@ -220,9 +220,7 @@ bool common_hal_usb_hid_enable(const mp_obj_t devices, uint8_t boot_device) {
} }
const mp_int_t num_devices = MP_OBJ_SMALL_INT_VALUE(mp_obj_len(devices)); const mp_int_t num_devices = MP_OBJ_SMALL_INT_VALUE(mp_obj_len(devices));
if (num_devices > MAX_HID_DEVICES) { mp_arg_validate_length_max(num_devices, MAX_HID_DEVICES, MP_QSTR_devices);
mp_raise_ValueError_varg(translate("No more than %d HID devices allowed"), MAX_HID_DEVICES);
}
num_hid_devices = num_devices; num_hid_devices = num_devices;

View File

@ -57,6 +57,9 @@ STATIC void get_word(int n, const mchar_t **pos, const mchar_t **end) {
} }
STATIC int put_utf8(char *buf, int u) { STATIC int put_utf8(char *buf, int u) {
if (u >= translation_offstart) {
u += translation_offset;
}
if (u <= 0x7f) { if (u <= 0x7f) {
*buf = u; *buf = u;
return 1; return 1;