py: Add module weak link support.
With this patch a port can enable module weak link support and provide
a dict of qstr->module mapping. This mapping is looked up only if an
import fails to find the requested module in the filesystem.
This allows to have the builtin module named, eg, usocket, and provide
a weak link of "socket" to the same module, but this weak link can be
overridden if a file by the name "socket.py" is found in the import
path.
diff --git a/py/mpconfig.h b/py/mpconfig.h
index 92b61d0..13ccb9c 100644
--- a/py/mpconfig.h
+++ b/py/mpconfig.h
@@ -269,6 +269,11 @@
#define MICROPY_STREAMS_NON_BLOCK (0)
#endif
+// Whether module weak links are supported
+#ifndef MICROPY_MODULE_WEAK_LINKS
+#define MICROPY_MODULE_WEAK_LINKS (0)
+#endif
+
/*****************************************************************************/
/* Fine control over Python builtins, classes, modules, etc */
@@ -411,6 +416,11 @@
#define MICROPY_PORT_BUILTIN_MODULES
#endif
+// Any module weak links - see builtintables.c:mp_builtin_module_weak_links_table.
+#ifndef MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS
+#define MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS
+#endif
+
// Additional constant definitions for the compiler - see compile.c:mp_constants_table.
#ifndef MICROPY_PORT_CONSTANTS
#define MICROPY_PORT_CONSTANTS