From 2eba98f1e0d292de0f7e48ce228221ef50c01967 Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Fri, 2 Jun 2023 12:33:25 +1000 Subject: [PATCH] all: Use MP_REGISTER_EXTENSIBLE_MODULE for overrideable built-ins. Signed-off-by: Jim Mussared --- extmod/modbinascii.c | 2 +- extmod/modbluetooth.c | 6 +++++- extmod/modcryptolib.c | 6 +++++- extmod/modhashlib.c | 2 +- extmod/modheapq.c | 2 +- extmod/modjson.c | 2 +- extmod/modlwip.c | 2 +- extmod/modos.c | 2 +- extmod/modplatform.c | 2 +- extmod/modrandom.c | 2 +- extmod/modre.c | 2 +- extmod/modselect.c | 2 +- extmod/modsocket.c | 2 +- extmod/modssl_axtls.c | 2 +- extmod/modssl_mbedtls.c | 2 +- extmod/modtime.c | 2 +- extmod/modtimeq.c | 2 +- extmod/moductypes.c | 2 ++ extmod/modwebsocket.c | 6 +++++- extmod/modzlib.c | 2 +- ports/cc3200/mods/modmachine.c | 2 +- ports/cc3200/mods/modos.c | 2 +- ports/cc3200/mods/modsocket.c | 2 +- ports/cc3200/mods/modssl.c | 2 +- ports/esp32/modmachine.c | 2 +- ports/esp32/modsocket.c | 2 +- ports/esp8266/modmachine.c | 2 +- ports/mimxrt/modmachine.c | 2 +- ports/nrf/modules/machine/modmachine.c | 2 +- ports/nrf/modules/os/modos.c | 2 +- ports/qemu-arm/modmachine.c | 2 +- ports/renesas-ra/modmachine.c | 2 +- ports/rp2/modmachine.c | 2 +- ports/samd/modmachine.c | 2 +- ports/stm32/modmachine.c | 2 +- ports/unix/modmachine.c | 2 +- ports/unix/modselect.c | 2 +- ports/unix/modsocket.c | 2 +- ports/zephyr/modmachine.c | 2 +- ports/zephyr/modsocket.c | 2 +- py/builtinimport.c | 11 +++++++---- py/modarray.c | 2 +- py/modcollections.c | 2 +- py/moderrno.c | 2 +- py/modio.c | 2 +- py/modstruct.c | 2 +- py/modsys.c | 3 +++ 47 files changed, 68 insertions(+), 48 deletions(-) diff --git a/extmod/modbinascii.c b/extmod/modbinascii.c index af8eab79f..46027d5fd 100644 --- a/extmod/modbinascii.c +++ b/extmod/modbinascii.c @@ -203,6 +203,6 @@ const mp_obj_module_t mp_module_binascii = { .globals = (mp_obj_dict_t *)&mp_module_binascii_globals, }; -MP_REGISTER_MODULE(MP_QSTR_binascii, mp_module_binascii); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_binascii, mp_module_binascii); #endif // MICROPY_PY_BINASCII diff --git a/extmod/modbluetooth.c b/extmod/modbluetooth.c index 628c643a5..7b13f9556 100644 --- a/extmod/modbluetooth.c +++ b/extmod/modbluetooth.c @@ -1004,7 +1004,11 @@ const mp_obj_module_t mp_module_bluetooth = { .globals = (mp_obj_dict_t *)&mp_module_bluetooth_globals, }; -MP_REGISTER_MODULE(MP_QSTR_bluetooth, mp_module_bluetooth); +// This module should not be extensible (as it is not a CPython standard +// library nor is it necessary to override from the filesystem), however it +// has previously been known as `ubluetooth`, so by making it extensible the +// `ubluetooth` alias will continue to work. +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_bluetooth, mp_module_bluetooth); // Helpers diff --git a/extmod/modcryptolib.c b/extmod/modcryptolib.c index 229947725..b33d8533f 100644 --- a/extmod/modcryptolib.c +++ b/extmod/modcryptolib.c @@ -375,6 +375,10 @@ const mp_obj_module_t mp_module_cryptolib = { .globals = (mp_obj_dict_t *)&mp_module_cryptolib_globals, }; -MP_REGISTER_MODULE(MP_QSTR_cryptolib, mp_module_cryptolib); +// This module should not be extensible (as it is not a CPython standard +// library nor is it necessary to override from the filesystem), however it +// has previously been known as `ucryptolib`, so by making it extensible the +// `ucryptolib` alias will continue to work. +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_cryptolib, mp_module_cryptolib); #endif // MICROPY_PY_CRYPTOLIB diff --git a/extmod/modhashlib.c b/extmod/modhashlib.c index 1b94cc01a..3fafe6316 100644 --- a/extmod/modhashlib.c +++ b/extmod/modhashlib.c @@ -374,6 +374,6 @@ const mp_obj_module_t mp_module_hashlib = { .globals = (mp_obj_dict_t *)&mp_module_hashlib_globals, }; -MP_REGISTER_MODULE(MP_QSTR_hashlib, mp_module_hashlib); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_hashlib, mp_module_hashlib); #endif // MICROPY_PY_HASHLIB diff --git a/extmod/modheapq.c b/extmod/modheapq.c index 79a12c2b9..db1e35bac 100644 --- a/extmod/modheapq.c +++ b/extmod/modheapq.c @@ -118,7 +118,7 @@ const mp_obj_module_t mp_module_heapq = { .globals = (mp_obj_dict_t *)&mp_module_heapq_globals, }; -MP_REGISTER_MODULE(MP_QSTR_heapq, mp_module_heapq); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_heapq, mp_module_heapq); #endif #endif // MICROPY_PY_HEAPQ diff --git a/extmod/modjson.c b/extmod/modjson.c index 1b475543e..1772b7299 100644 --- a/extmod/modjson.c +++ b/extmod/modjson.c @@ -381,6 +381,6 @@ const mp_obj_module_t mp_module_json = { .globals = (mp_obj_dict_t *)&mp_module_json_globals, }; -MP_REGISTER_MODULE(MP_QSTR_json, mp_module_json); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_json, mp_module_json); #endif // MICROPY_PY_JSON diff --git a/extmod/modlwip.c b/extmod/modlwip.c index 24047b0a9..0d4c03c68 100644 --- a/extmod/modlwip.c +++ b/extmod/modlwip.c @@ -1802,7 +1802,7 @@ const mp_obj_module_t mp_module_lwip = { MP_REGISTER_MODULE(MP_QSTR_lwip, mp_module_lwip); // On LWIP-ports, this is the socket module (replaces extmod/modsocket.c). -MP_REGISTER_MODULE(MP_QSTR_socket, mp_module_lwip); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_socket, mp_module_lwip); MP_REGISTER_ROOT_POINTER(mp_obj_t lwip_slip_stream); diff --git a/extmod/modos.c b/extmod/modos.c index e962a6c17..6df49d7f8 100644 --- a/extmod/modos.c +++ b/extmod/modos.c @@ -195,6 +195,6 @@ const mp_obj_module_t mp_module_os = { .globals = (mp_obj_dict_t *)&os_module_globals, }; -MP_REGISTER_MODULE(MP_QSTR_os, mp_module_os); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_os, mp_module_os); #endif // MICROPY_PY_OS diff --git a/extmod/modplatform.c b/extmod/modplatform.c index 4d10bdb4d..73846f946 100644 --- a/extmod/modplatform.c +++ b/extmod/modplatform.c @@ -75,6 +75,6 @@ const mp_obj_module_t mp_module_platform = { .globals = (mp_obj_dict_t *)&modplatform_globals, }; -MP_REGISTER_MODULE(MP_QSTR_platform, mp_module_platform); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_platform, mp_module_platform); #endif // MICROPY_PY_PLATFORM diff --git a/extmod/modrandom.c b/extmod/modrandom.c index 1c697aec7..e65f31488 100644 --- a/extmod/modrandom.c +++ b/extmod/modrandom.c @@ -255,7 +255,7 @@ const mp_obj_module_t mp_module_random = { .globals = (mp_obj_dict_t *)&mp_module_random_globals, }; -MP_REGISTER_MODULE(MP_QSTR_random, mp_module_random); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_random, mp_module_random); #endif #endif // MICROPY_PY_RANDOM diff --git a/extmod/modre.c b/extmod/modre.c index c8a019be8..7f00b1c23 100644 --- a/extmod/modre.c +++ b/extmod/modre.c @@ -470,7 +470,7 @@ const mp_obj_module_t mp_module_re = { .globals = (mp_obj_dict_t *)&mp_module_re_globals, }; -MP_REGISTER_MODULE(MP_QSTR_re, mp_module_re); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_re, mp_module_re); #endif // Source files #include'd here to make sure they're compiled in diff --git a/extmod/modselect.c b/extmod/modselect.c index 011d5cb83..3d7ccbd99 100644 --- a/extmod/modselect.c +++ b/extmod/modselect.c @@ -373,6 +373,6 @@ const mp_obj_module_t mp_module_select = { .globals = (mp_obj_dict_t *)&mp_module_select_globals, }; -MP_REGISTER_MODULE(MP_QSTR_select, mp_module_select); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_select, mp_module_select); #endif // MICROPY_PY_SELECT diff --git a/extmod/modsocket.c b/extmod/modsocket.c index 316a578ac..488b6d171 100644 --- a/extmod/modsocket.c +++ b/extmod/modsocket.c @@ -653,6 +653,6 @@ const mp_obj_module_t mp_module_socket = { .globals = (mp_obj_dict_t *)&mp_module_socket_globals, }; -MP_REGISTER_MODULE(MP_QSTR_socket, mp_module_socket); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_socket, mp_module_socket); #endif // MICROPY_PY_NETWORK && MICROPY_PY_SOCKET && !MICROPY_PY_LWIP diff --git a/extmod/modssl_axtls.c b/extmod/modssl_axtls.c index 1c9caf76e..de6e0ce5d 100644 --- a/extmod/modssl_axtls.c +++ b/extmod/modssl_axtls.c @@ -357,6 +357,6 @@ const mp_obj_module_t mp_module_ssl = { .globals = (mp_obj_dict_t *)&mp_module_ssl_globals, }; -MP_REGISTER_MODULE(MP_QSTR_ssl, mp_module_ssl); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_ssl, mp_module_ssl); #endif // MICROPY_PY_SSL && MICROPY_SSL_AXTLS diff --git a/extmod/modssl_mbedtls.c b/extmod/modssl_mbedtls.c index d724e0a08..c230b1eaa 100644 --- a/extmod/modssl_mbedtls.c +++ b/extmod/modssl_mbedtls.c @@ -507,6 +507,6 @@ const mp_obj_module_t mp_module_ssl = { .globals = (mp_obj_dict_t *)&mp_module_ssl_globals, }; -MP_REGISTER_MODULE(MP_QSTR_ssl, mp_module_ssl); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_ssl, mp_module_ssl); #endif // MICROPY_PY_SSL && MICROPY_SSL_MBEDTLS diff --git a/extmod/modtime.c b/extmod/modtime.c index 163b874d5..805c2621c 100644 --- a/extmod/modtime.c +++ b/extmod/modtime.c @@ -231,6 +231,6 @@ const mp_obj_module_t mp_module_time = { .globals = (mp_obj_dict_t *)&mp_module_time_globals, }; -MP_REGISTER_MODULE(MP_QSTR_time, mp_module_time); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_time, mp_module_time); #endif // MICROPY_PY_TIME diff --git a/extmod/modtimeq.c b/extmod/modtimeq.c index 7c037ea0a..4edb7dd3c 100644 --- a/extmod/modtimeq.c +++ b/extmod/modtimeq.c @@ -230,6 +230,6 @@ const mp_obj_module_t mp_module_timeq = { .globals = (mp_obj_dict_t *)&mp_module_timeq_globals, }; -MP_REGISTER_MODULE(MP_QSTR_timeq, mp_module_timeq); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_timeq, mp_module_timeq); #endif // MICROPY_PY_TIMEQ diff --git a/extmod/moductypes.c b/extmod/moductypes.c index 86d82f03b..63be621fb 100644 --- a/extmod/moductypes.c +++ b/extmod/moductypes.c @@ -718,6 +718,8 @@ const mp_obj_module_t mp_module_uctypes = { .globals = (mp_obj_dict_t *)&mp_module_uctypes_globals, }; +// uctypes is not a Python standard library module (hence "uctypes" +// not "ctypes") and therefore shouldn't be extensible. MP_REGISTER_MODULE(MP_QSTR_uctypes, mp_module_uctypes); #endif diff --git a/extmod/modwebsocket.c b/extmod/modwebsocket.c index 3bf50cc58..d2cb72039 100644 --- a/extmod/modwebsocket.c +++ b/extmod/modwebsocket.c @@ -311,6 +311,10 @@ const mp_obj_module_t mp_module_websocket = { .globals = (mp_obj_dict_t *)&websocket_module_globals, }; -MP_REGISTER_MODULE(MP_QSTR_websocket, mp_module_websocket); +// This module should not be extensible (as it is not a CPython standard +// library nor is it necessary to override from the filesystem), however it +// has previously been known as `uwebsocket`, so by making it extensible the +// `uwebsocket` alias will continue to work. +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_websocket, mp_module_websocket); #endif // MICROPY_PY_WEBSOCKET diff --git a/extmod/modzlib.c b/extmod/modzlib.c index a912f113c..31096cfeb 100644 --- a/extmod/modzlib.c +++ b/extmod/modzlib.c @@ -224,7 +224,7 @@ const mp_obj_module_t mp_module_zlib = { }; -MP_REGISTER_MODULE(MP_QSTR_zlib, mp_module_zlib); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_zlib, mp_module_zlib); #endif // Source files #include'd here to make sure they're compiled in diff --git a/ports/cc3200/mods/modmachine.c b/ports/cc3200/mods/modmachine.c index a695fdcca..bdf963c31 100644 --- a/ports/cc3200/mods/modmachine.c +++ b/ports/cc3200/mods/modmachine.c @@ -214,5 +214,5 @@ const mp_obj_module_t mp_module_machine = { .globals = (mp_obj_dict_t*)&machine_module_globals, }; -MP_REGISTER_MODULE(MP_QSTR_machine, mp_module_machine); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_machine, mp_module_machine); MP_REGISTER_ROOT_POINTER(mp_obj_t machine_config_main); diff --git a/ports/cc3200/mods/modos.c b/ports/cc3200/mods/modos.c index 7b1e8d79f..1a854750f 100644 --- a/ports/cc3200/mods/modos.c +++ b/ports/cc3200/mods/modos.c @@ -180,4 +180,4 @@ const mp_obj_module_t mp_module_os = { .globals = (mp_obj_dict_t*)&os_module_globals, }; -MP_REGISTER_MODULE(MP_QSTR_os, mp_module_os); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_os, mp_module_os); diff --git a/ports/cc3200/mods/modsocket.c b/ports/cc3200/mods/modsocket.c index fd09cd6a4..a107fa712 100644 --- a/ports/cc3200/mods/modsocket.c +++ b/ports/cc3200/mods/modsocket.c @@ -818,4 +818,4 @@ const mp_obj_module_t mp_module_socket = { .globals = (mp_obj_dict_t*)&mp_module_socket_globals, }; -MP_REGISTER_MODULE(MP_QSTR_socket, mp_module_socket); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_socket, mp_module_socket); diff --git a/ports/cc3200/mods/modssl.c b/ports/cc3200/mods/modssl.c index eb3aea1f8..15c825fcf 100644 --- a/ports/cc3200/mods/modssl.c +++ b/ports/cc3200/mods/modssl.c @@ -160,4 +160,4 @@ const mp_obj_module_t mp_module_ssl = { .globals = (mp_obj_dict_t*)&mp_module_ssl_globals, }; -MP_REGISTER_MODULE(MP_QSTR_ssl, mp_module_ssl); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_ssl, mp_module_ssl); diff --git a/ports/esp32/modmachine.c b/ports/esp32/modmachine.c index a863f716c..fc19618b7 100644 --- a/ports/esp32/modmachine.c +++ b/ports/esp32/modmachine.c @@ -353,6 +353,6 @@ const mp_obj_module_t mp_module_machine = { .globals = (mp_obj_dict_t *)&machine_module_globals, }; -MP_REGISTER_MODULE(MP_QSTR_machine, mp_module_machine); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_machine, mp_module_machine); #endif // MICROPY_PY_MACHINE diff --git a/ports/esp32/modsocket.c b/ports/esp32/modsocket.c index 0b2d40e33..731f69fbc 100644 --- a/ports/esp32/modsocket.c +++ b/ports/esp32/modsocket.c @@ -872,4 +872,4 @@ const mp_obj_module_t mp_module_socket = { // Note: This port doesn't define MICROPY_PY_SOCKET or MICROPY_PY_LWIP so // this will not conflict with the common implementation provided by // extmod/mod{lwip,socket}.c. -MP_REGISTER_MODULE(MP_QSTR_socket, mp_module_socket); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_socket, mp_module_socket); diff --git a/ports/esp8266/modmachine.c b/ports/esp8266/modmachine.c index 383f46dda..64346b4de 100644 --- a/ports/esp8266/modmachine.c +++ b/ports/esp8266/modmachine.c @@ -456,6 +456,6 @@ const mp_obj_module_t mp_module_machine = { .globals = (mp_obj_dict_t *)&machine_module_globals, }; -MP_REGISTER_MODULE(MP_QSTR_machine, mp_module_machine); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_machine, mp_module_machine); #endif // MICROPY_PY_MACHINE diff --git a/ports/mimxrt/modmachine.c b/ports/mimxrt/modmachine.c index 098c3b949..423a67d60 100644 --- a/ports/mimxrt/modmachine.c +++ b/ports/mimxrt/modmachine.c @@ -185,6 +185,6 @@ const mp_obj_module_t mp_module_machine = { .globals = (mp_obj_dict_t *)&machine_module_globals, }; -MP_REGISTER_MODULE(MP_QSTR_machine, mp_module_machine); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_machine, mp_module_machine); #endif // MICROPY_PY_MACHINE diff --git a/ports/nrf/modules/machine/modmachine.c b/ports/nrf/modules/machine/modmachine.c index b7cbdc7b2..616757a96 100644 --- a/ports/nrf/modules/machine/modmachine.c +++ b/ports/nrf/modules/machine/modmachine.c @@ -266,6 +266,6 @@ const mp_obj_module_t mp_module_machine = { .globals = (mp_obj_dict_t*)&machine_module_globals, }; -MP_REGISTER_MODULE(MP_QSTR_machine, mp_module_machine); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_machine, mp_module_machine); #endif // MICROPY_PY_MACHINE diff --git a/ports/nrf/modules/os/modos.c b/ports/nrf/modules/os/modos.c index 7c54f28ab..7654ac119 100644 --- a/ports/nrf/modules/os/modos.c +++ b/ports/nrf/modules/os/modos.c @@ -197,4 +197,4 @@ const mp_obj_module_t mp_module_os = { .globals = (mp_obj_dict_t*)&os_module_globals, }; -MP_REGISTER_MODULE(MP_QSTR_os, mp_module_os); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_os, mp_module_os); diff --git a/ports/qemu-arm/modmachine.c b/ports/qemu-arm/modmachine.c index 1f9151ff7..0d712f792 100644 --- a/ports/qemu-arm/modmachine.c +++ b/ports/qemu-arm/modmachine.c @@ -48,6 +48,6 @@ const mp_obj_module_t mp_module_machine = { .globals = (mp_obj_dict_t *)&machine_module_globals, }; -MP_REGISTER_MODULE(MP_QSTR_machine, mp_module_machine); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_machine, mp_module_machine); #endif // MICROPY_PY_MACHINE diff --git a/ports/renesas-ra/modmachine.c b/ports/renesas-ra/modmachine.c index 07e6103aa..47f7e8c80 100644 --- a/ports/renesas-ra/modmachine.c +++ b/ports/renesas-ra/modmachine.c @@ -307,6 +307,6 @@ const mp_obj_module_t mp_module_machine = { .globals = (mp_obj_dict_t *)&machine_module_globals, }; -MP_REGISTER_MODULE(MP_QSTR_machine, mp_module_machine); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_machine, mp_module_machine); #endif // MICROPY_PY_MACHINE diff --git a/ports/rp2/modmachine.c b/ports/rp2/modmachine.c index 61b91bda0..1efbb0931 100644 --- a/ports/rp2/modmachine.c +++ b/ports/rp2/modmachine.c @@ -278,6 +278,6 @@ const mp_obj_module_t mp_module_machine = { .globals = (mp_obj_dict_t *)&machine_module_globals, }; -MP_REGISTER_MODULE(MP_QSTR_machine, mp_module_machine); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_machine, mp_module_machine); #endif // MICROPY_PY_MACHINE diff --git a/ports/samd/modmachine.c b/ports/samd/modmachine.c index 9890e3b59..9d5b7c2e2 100644 --- a/ports/samd/modmachine.c +++ b/ports/samd/modmachine.c @@ -297,6 +297,6 @@ const mp_obj_module_t mp_module_machine = { .globals = (mp_obj_dict_t *)&machine_module_globals, }; -MP_REGISTER_MODULE(MP_QSTR_machine, mp_module_machine); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_machine, mp_module_machine); #endif // MICROPY_PY_MACHINE diff --git a/ports/stm32/modmachine.c b/ports/stm32/modmachine.c index e6eb73f9c..25fc66eb9 100644 --- a/ports/stm32/modmachine.c +++ b/ports/stm32/modmachine.c @@ -471,6 +471,6 @@ const mp_obj_module_t mp_module_machine = { .globals = (mp_obj_dict_t *)&machine_module_globals, }; -MP_REGISTER_MODULE(MP_QSTR_machine, mp_module_machine); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_machine, mp_module_machine); #endif // MICROPY_PY_MACHINE diff --git a/ports/unix/modmachine.c b/ports/unix/modmachine.c index 29ac532d2..dd3cbf96c 100644 --- a/ports/unix/modmachine.c +++ b/ports/unix/modmachine.c @@ -110,6 +110,6 @@ const mp_obj_module_t mp_module_machine = { .globals = (mp_obj_dict_t *)&machine_module_globals, }; -MP_REGISTER_MODULE(MP_QSTR_machine, mp_module_machine); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_machine, mp_module_machine); #endif // MICROPY_PY_MACHINE diff --git a/ports/unix/modselect.c b/ports/unix/modselect.c index 97c3602e4..894820c63 100644 --- a/ports/unix/modselect.c +++ b/ports/unix/modselect.c @@ -351,6 +351,6 @@ const mp_obj_module_t mp_module_select = { .globals = (mp_obj_dict_t *)&mp_module_select_globals, }; -MP_REGISTER_MODULE(MP_QSTR_select, mp_module_select); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_select, mp_module_select); #endif // MICROPY_PY_SELECT_POSIX diff --git a/ports/unix/modsocket.c b/ports/unix/modsocket.c index 9854f3cbc..871be8dcf 100644 --- a/ports/unix/modsocket.c +++ b/ports/unix/modsocket.c @@ -707,6 +707,6 @@ const mp_obj_module_t mp_module_socket = { .globals = (mp_obj_dict_t *)&mp_module_socket_globals, }; -MP_REGISTER_MODULE(MP_QSTR_socket, mp_module_socket); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_socket, mp_module_socket); #endif // MICROPY_PY_SOCKET diff --git a/ports/zephyr/modmachine.c b/ports/zephyr/modmachine.c index 6f4bbbdab..633416805 100644 --- a/ports/zephyr/modmachine.c +++ b/ports/zephyr/modmachine.c @@ -89,6 +89,6 @@ const mp_obj_module_t mp_module_machine = { .globals = (mp_obj_dict_t *)&machine_module_globals, }; -MP_REGISTER_MODULE(MP_QSTR_machine, mp_module_machine); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_machine, mp_module_machine); #endif // MICROPY_PY_MACHINE diff --git a/ports/zephyr/modsocket.c b/ports/zephyr/modsocket.c index 8d4197410..eacdb049d 100644 --- a/ports/zephyr/modsocket.c +++ b/ports/zephyr/modsocket.c @@ -473,6 +473,6 @@ const mp_obj_module_t mp_module_socket = { .globals = (mp_obj_dict_t *)&mp_module_socket_globals, }; -MP_REGISTER_MODULE(MP_QSTR_socket, mp_module_socket); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_socket, mp_module_socket); #endif // MICROPY_PY_SOCKET diff --git a/py/builtinimport.c b/py/builtinimport.c index 15521c77c..8a125fc53 100644 --- a/py/builtinimport.c +++ b/py/builtinimport.c @@ -380,20 +380,23 @@ STATIC mp_obj_t process_import_at_level(qstr full_mod_name, qstr level_mod_name, mp_obj_t module_obj; if (outer_module_obj == MP_OBJ_NULL) { + // First module in the dotted-name path. DEBUG_printf("Searching for top-level module\n"); // An import of a non-extensible built-in will always bypass the - // filesystem. e.g. `import micropython` or `import pyb`. + // filesystem. e.g. `import micropython` or `import pyb`. So try and + // match a non-extensible built-ins first. module_obj = mp_module_get_builtin(level_mod_name, false); if (module_obj != MP_OBJ_NULL) { return module_obj; } - // First module in the dotted-name; search for a directory or file - // relative to all the locations in sys.path. + // Next try the filesystem. Search for a directory or file relative to + // all the locations in sys.path. stat = stat_top_level(level_mod_name, &path); - // TODO: If stat failed, now try extensible built-in modules. + // If filesystem failed, now try and see if it matches an extensible + // built-in module. if (stat == MP_IMPORT_STAT_NO_EXIST) { module_obj = mp_module_get_builtin(level_mod_name, true); if (module_obj != MP_OBJ_NULL) { diff --git a/py/modarray.c b/py/modarray.c index cfed0fbb5..ac2e56ed3 100644 --- a/py/modarray.c +++ b/py/modarray.c @@ -40,6 +40,6 @@ const mp_obj_module_t mp_module_array = { .globals = (mp_obj_dict_t *)&mp_module_array_globals, }; -MP_REGISTER_MODULE(MP_QSTR_array, mp_module_array); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_array, mp_module_array); #endif diff --git a/py/modcollections.c b/py/modcollections.c index a56fe069e..30a5881bc 100644 --- a/py/modcollections.c +++ b/py/modcollections.c @@ -46,6 +46,6 @@ const mp_obj_module_t mp_module_collections = { .globals = (mp_obj_dict_t *)&mp_module_collections_globals, }; -MP_REGISTER_MODULE(MP_QSTR_collections, mp_module_collections); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_collections, mp_module_collections); #endif // MICROPY_PY_COLLECTIONS diff --git a/py/moderrno.c b/py/moderrno.c index 99ca101bd..4f0673a23 100644 --- a/py/moderrno.c +++ b/py/moderrno.c @@ -99,7 +99,7 @@ const mp_obj_module_t mp_module_errno = { .globals = (mp_obj_dict_t *)&mp_module_errno_globals, }; -MP_REGISTER_MODULE(MP_QSTR_errno, mp_module_errno); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_errno, mp_module_errno); qstr mp_errno_to_str(mp_obj_t errno_val) { #if MICROPY_PY_ERRNO_ERRORCODE diff --git a/py/modio.c b/py/modio.c index 3462611d7..39317c52d 100644 --- a/py/modio.c +++ b/py/modio.c @@ -226,6 +226,6 @@ const mp_obj_module_t mp_module_io = { .globals = (mp_obj_dict_t *)&mp_module_io_globals, }; -MP_REGISTER_MODULE(MP_QSTR_io, mp_module_io); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_io, mp_module_io); #endif diff --git a/py/modstruct.c b/py/modstruct.c index e908c73e1..42f91b282 100644 --- a/py/modstruct.c +++ b/py/modstruct.c @@ -266,6 +266,6 @@ const mp_obj_module_t mp_module_struct = { .globals = (mp_obj_dict_t *)&mp_module_struct_globals, }; -MP_REGISTER_MODULE(MP_QSTR_struct, mp_module_struct); +MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_struct, mp_module_struct); #endif diff --git a/py/modsys.c b/py/modsys.c index 1cfc09ecf..ddc732e00 100644 --- a/py/modsys.c +++ b/py/modsys.c @@ -294,6 +294,9 @@ const mp_obj_module_t mp_module_sys = { .globals = (mp_obj_dict_t *)&mp_module_sys_globals, }; +// Unlike the other CPython-compatible modules, sys is not extensible from the +// filesystem. We rely on it to work so that things like sys.path are always +// available. MP_REGISTER_MODULE(MP_QSTR_sys, mp_module_sys); // If MICROPY_PY_SYS_PATH_ARGV_DEFAULTS is not enabled then these two lists