mirror of
https://github.com/micropython/micropython.git
synced 2026-01-06 12:10:13 +01:00
all: Use MP_REGISTER_EXTENSIBLE_MODULE for overrideable built-ins.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user