Skip to content

Commit

Permalink
unix: Make micropython -m <module> work for frozen modules.
Browse files Browse the repository at this point in the history
This requires some special handling, which was previosuly applied only to
the main code path.
  • Loading branch information
Paul Sokolovsky committed Jun 5, 2015
1 parent d7192fe commit 07408cb
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions py/builtinimport.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,14 @@ mp_obj_t mp_builtin___import__(mp_uint_t n_args, const mp_obj_t *args) {
mp_lexer_t *lex = mp_find_frozen_module(mod_str, mod_len);
if (lex != NULL) {
module_obj = mp_obj_new_module(module_name_qstr);
// if args[3] (fromtuple) has magic value False, set up
// this module for command-line "-m" option (set module's
// name to __main__ instead of real name).
// TODO: Duplicated below too.
if (fromtuple == mp_const_false) {
mp_obj_module_t *o = module_obj;
mp_obj_dict_store(o->globals, MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR___main__));
}
do_load_from_lexer(module_obj, lex, mod_str);
return module_obj;
}
Expand Down

0 comments on commit 07408cb

Please sign in to comment.