diff options
| author | Noralf Trønnes <noralf@tronnes.org> | 2018-10-07 15:37:57 +0200 |
|---|---|---|
| committer | Noralf Trønnes <noralf@tronnes.org> | 2018-10-07 19:36:12 +0200 |
| commit | a63555abc1ce07fe4e9420b5835865282adcd1db (patch) | |
| tree | 40aaa5e179f4384be6d348fd77fac07039453409 /py | |
| parent | c23d2028a86d207fd02d274c809c62075f4595ed (diff) | |
py/builtinimport: Set __file__ on MPY modules
This sets the __file__ property on MPY modules like how it's done on pure python modules.
Diffstat (limited to 'py')
| -rwxr-xr-x | py/builtinimport.c | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/py/builtinimport.c b/py/builtinimport.c index fee875b60..6ed0a7594 100755 --- a/py/builtinimport.c +++ b/py/builtinimport.c @@ -155,11 +155,9 @@ STATIC void do_load_from_lexer(mp_obj_t module_obj, mp_lexer_t *lex) { #endif #if MICROPY_PERSISTENT_CODE_LOAD || MICROPY_MODULE_FROZEN_MPY -STATIC void do_execute_raw_code(mp_obj_t module_obj, mp_raw_code_t *raw_code) { +STATIC void do_execute_raw_code(mp_obj_t module_obj, mp_raw_code_t *raw_code, const char *filename) { #if MICROPY_PY___FILE__ - // TODO - //qstr source_name = lex->source_name; - //mp_store_attr(module_obj, MP_QSTR___file__, MP_OBJ_NEW_QSTR(source_name)); + mp_store_attr(module_obj, MP_QSTR___file__, MP_OBJ_NEW_QSTR(qstr_from_str(filename))); #endif // execute the module in its context @@ -222,7 +220,7 @@ STATIC void do_load(mp_obj_t module_obj, vstr_t *file) { // its data) in the list of frozen files, execute it. #if MICROPY_MODULE_FROZEN_MPY if (frozen_type == MP_FROZEN_MPY) { - do_execute_raw_code(module_obj, modref); + do_execute_raw_code(module_obj, modref, file_str); return; } #endif @@ -235,7 +233,7 @@ STATIC void do_load(mp_obj_t module_obj, vstr_t *file) { #if MICROPY_PERSISTENT_CODE_LOAD if (file_str[file->len - 3] == 'm') { mp_raw_code_t *raw_code = mp_raw_code_load_file(file_str); - do_execute_raw_code(module_obj, raw_code); + do_execute_raw_code(module_obj, raw_code, file_str); return; } #endif |
