diff options
author | Damien George <damien.p.george@gmail.com> | 2014-10-12 11:46:04 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-10-12 20:18:40 +0100 |
commit | c14a81662c1df812c0c6b4299f97966302f16477 (patch) | |
tree | 68d9169d0ddaf4de9c531ca1212fad6b805bf42b /py/builtintables.c | |
parent | 3c34d4140df74d59e56ccd0465408fecf8876c88 (diff) | |
download | micropython-c14a81662c1df812c0c6b4299f97966302f16477.tar.gz micropython-c14a81662c1df812c0c6b4299f97966302f16477.zip |
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.
Diffstat (limited to 'py/builtintables.c')
-rw-r--r-- | py/builtintables.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/py/builtintables.c b/py/builtintables.c index 1fd60d8177..6d74961384 100644 --- a/py/builtintables.c +++ b/py/builtintables.c @@ -227,3 +227,20 @@ const mp_obj_dict_t mp_builtin_module_dict_obj = { .table = (mp_map_elem_t*)mp_builtin_module_table, }, }; + +#if MICROPY_MODULE_WEAK_LINKS +STATIC const mp_map_elem_t mp_builtin_module_weak_links_table[] = { + MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS +}; + +const mp_obj_dict_t mp_builtin_module_weak_links_dict_obj = { + .base = {&mp_type_dict}, + .map = { + .all_keys_are_qstrs = 1, + .table_is_fixed_array = 1, + .used = MP_ARRAY_SIZE(mp_builtin_module_weak_links_table), + .alloc = MP_ARRAY_SIZE(mp_builtin_module_weak_links_table), + .table = (mp_map_elem_t*)mp_builtin_module_weak_links_table, + }, +}; +#endif |