4545#define DEBUG_printf (...) (void)0
4646#endif
4747
48- #if MICROPY_MODULE_WEAK_LINKS
49- STATIC qstr make_weak_link_name (vstr_t * buffer , qstr name ) {
50- vstr_reset (buffer );
51- vstr_add_char (buffer , 'u' );
52- vstr_add_str (buffer , qstr_str (name ));
53- return qstr_from_strn (buffer -> buf , buffer -> len );
54- }
55- #endif
56-
5748#if MICROPY_ENABLE_EXTERNAL_IMPORT
5849
5950// Must be a string of one byte.
@@ -391,13 +382,8 @@ STATIC mp_obj_t process_import_at_level(qstr full_mod_name, qstr level_mod_name,
391382 if (outer_module_obj == MP_OBJ_NULL ) {
392383 DEBUG_printf ("Searching for top-level module\n" );
393384
394- // An exact match of a built-in will always bypass the filesystem.
395- // Note that CPython-compatible built-ins are named e.g. utime, so this
396- // means that an exact match is only for `import utime`, so `import
397- // time` will search the filesystem and failing that hit the weak
398- // link handling below. Whereas micropython-specific built-ins like
399- // `micropython`, `pyb`, `network`, etc will match exactly and cannot
400- // be overridden by the filesystem.
385+ // An import of a non-extensible built-in will always bypass the
386+ // filesystem. e.g. `import micropython` or `import pyb`.
401387 module_obj = mp_module_get_builtin (level_mod_name );
402388 if (module_obj != MP_OBJ_NULL ) {
403389 return module_obj ;
@@ -417,20 +403,9 @@ STATIC mp_obj_t process_import_at_level(qstr full_mod_name, qstr level_mod_name,
417403 // relative to all the locations in sys.path.
418404 stat = stat_top_level (level_mod_name , & path );
419405
420- #if MICROPY_MODULE_WEAK_LINKS
421- if (stat == MP_IMPORT_STAT_NO_EXIST ) {
422- // No match on the filesystem. (And not a built-in either).
423- // If "foo" was requested, then try "ufoo" as a built-in. This
424- // allows `import time` to use built-in `utime`, unless `time`
425- // exists on the filesystem. This feature was formerly known
426- // as "weak links".
427- qstr umodule_name = make_weak_link_name (& path , level_mod_name );
428- module_obj = mp_module_get_builtin (umodule_name );
429- if (module_obj != MP_OBJ_NULL ) {
430- return module_obj ;
431- }
432- }
433- #endif
406+ // TODO: If stat failed, now try extensible built-in modules.
407+
408+ // TODO: If importing `ufoo`, try `foo`.
434409 } else {
435410 DEBUG_printf ("Searching for sub-module\n" );
436411
@@ -667,21 +642,6 @@ mp_obj_t mp_builtin___import___default(size_t n_args, const mp_obj_t *args) {
667642 return module_obj ;
668643 }
669644
670- #if MICROPY_MODULE_WEAK_LINKS
671- // Check if the u-prefixed name is a built-in.
672- VSTR_FIXED (umodule_path , MICROPY_ALLOC_PATH_MAX );
673- qstr umodule_name_qstr = make_weak_link_name (& umodule_path , module_name_qstr );
674- module_obj = mp_module_get_builtin (umodule_name_qstr );
675- if (module_obj != MP_OBJ_NULL ) {
676- return module_obj ;
677- }
678- #elif MICROPY_PY_SYS
679- // Special handling to make `import sys` work even if weak links aren't enabled.
680- if (module_name_qstr == MP_QSTR_sys ) {
681- return MP_OBJ_FROM_PTR (& mp_module_sys );
682- }
683- #endif
684-
685645 // Couldn't find the module, so fail
686646 #if MICROPY_ERROR_REPORTING <= MICROPY_ERROR_REPORTING_TERSE
687647 mp_raise_msg (& mp_type_ImportError , MP_ERROR_TEXT ("module not found" ));
0 commit comments