File tree 6 files changed +31
-10
lines changed
6 files changed +31
-10
lines changed Original file line number Diff line number Diff line change 29
29
30
30
#include "py/nlr.h"
31
31
#include "py/compile.h"
32
+ #include "py/frozenmod.h"
32
33
#include "py/mphal.h"
33
34
#include "py/runtime.h"
34
35
#include "py/repl.h"
@@ -165,8 +166,8 @@ void reset_mp(void) {
165
166
mp_obj_list_append (mp_sys_path , MP_OBJ_NEW_QSTR (MP_QSTR_ )); // current dir (or base dir of the script)
166
167
mp_obj_list_append (mp_sys_path , MP_OBJ_NEW_QSTR (MP_QSTR__slash_ ));
167
168
mp_obj_list_append (mp_sys_path , MP_OBJ_NEW_QSTR (MP_QSTR__slash_lib ));
168
- // Frozen modules are in their own pseudo-dir, ".frozen".
169
- mp_obj_list_append (mp_sys_path , MP_OBJ_NEW_QSTR (MP_QSTR__dot_frozen ));
169
+ // Frozen modules are in their own pseudo-dir, e.g., ".frozen".
170
+ mp_obj_list_append (mp_sys_path , MP_OBJ_NEW_QSTR (MP_FROZEN_FAKE_DIR_QSTR ));
170
171
171
172
mp_obj_list_init (mp_sys_argv , 0 );
172
173
}
Original file line number Diff line number Diff line change 29
29
30
30
#include "py/nlr.h"
31
31
#include "py/compile.h"
32
+ #include "py/frozenmod.h"
32
33
#include "py/runtime0.h"
33
34
#include "py/runtime.h"
34
35
#include "py/stackctrl.h"
@@ -98,8 +99,8 @@ STATIC void mp_reset(void) {
98
99
mp_obj_list_append (mp_sys_path , MP_OBJ_NEW_QSTR (MP_QSTR_ )); // current dir (or base dir of the script)
99
100
mp_obj_list_append (mp_sys_path , MP_OBJ_NEW_QSTR (MP_QSTR__slash_lib ));
100
101
mp_obj_list_append (mp_sys_path , MP_OBJ_NEW_QSTR (MP_QSTR__slash_ ));
101
- // Frozen modules are in their own pseudo-dir, ".frozen".
102
- mp_obj_list_append (mp_sys_path , MP_OBJ_NEW_QSTR (MP_QSTR__dot_frozen ));
102
+ // Frozen modules are in their own pseudo-dir, e.g., ".frozen".
103
+ mp_obj_list_append (mp_sys_path , MP_OBJ_NEW_QSTR (MP_FROZEN_FAKE_DIR_QSTR ));
103
104
104
105
mp_obj_list_init (mp_sys_argv , 0 );
105
106
MP_STATE_PORT (term_obj ) = MP_OBJ_NULL ;
Original file line number Diff line number Diff line change @@ -57,8 +57,10 @@ bool mp_obj_is_package(mp_obj_t module) {
57
57
// (whatever is available, if at all).
58
58
STATIC mp_import_stat_t mp_import_stat_any (const char * path ) {
59
59
#if MICROPY_MODULE_FROZEN
60
- if (strlen (path ) > 8 && strncmp (".frozen/" , path , 8 ) == 0 ) {
61
- mp_import_stat_t st = mp_frozen_stat (path + 8 );
60
+ if (strncmp (MP_FROZEN_FAKE_DIR_SLASH ,
61
+ path ,
62
+ MP_FROZEN_FAKE_DIR_SLASH_LENGTH ) == 0 ) {
63
+ mp_import_stat_t st = mp_frozen_stat (path + MP_FROZEN_FAKE_DIR_SLASH_LENGTH );
62
64
if (st != MP_IMPORT_STAT_NO_EXIST ) {
63
65
return st ;
64
66
}
Original file line number Diff line number Diff line change @@ -135,16 +135,21 @@ mp_import_stat_t mp_frozen_stat(const char *str) {
135
135
}
136
136
137
137
int mp_find_frozen_module (const char * str , size_t len , void * * data ) {
138
- // The +8/-8 account for the .frozen/ path prefix used on frozen modules.
138
+ // If the frozen module pseudo dir (e.g., ".frozen/") is a prefix of str, remove it.
139
+ if (strncmp (str , MP_FROZEN_FAKE_DIR_SLASH , MP_FROZEN_FAKE_DIR_SLASH_LENGTH ) == 0 ) {
140
+ str = str + MP_FROZEN_FAKE_DIR_SLASH_LENGTH ;
141
+ len = len - MP_FROZEN_FAKE_DIR_SLASH_LENGTH ;
142
+ }
143
+
139
144
#if MICROPY_MODULE_FROZEN_STR
140
- mp_lexer_t * lex = mp_lexer_frozen_str (str + 8 , len - 8 );
145
+ mp_lexer_t * lex = mp_lexer_frozen_str (str , len );
141
146
if (lex != NULL ) {
142
147
* data = lex ;
143
148
return MP_FROZEN_STR ;
144
149
}
145
150
#en
67F4
dif
146
151
#if MICROPY_MODULE_FROZEN_MPY
147
- const mp_raw_code_t * rc = mp_find_frozen_mpy (str + 8 , len - 8 );
152
+ const mp_raw_code_t * rc = mp_find_frozen_mpy (str , len );
148
153
if (rc != NULL ) {
149
154
* data = (void * )rc ;
150
155
return MP_FROZEN_MPY ;
Original file line number Diff line number Diff line change @@ -34,6 +34,16 @@ enum {
34
34
MP_FROZEN_MPY ,
35
35
};
36
36
37
+ // Frozen modules are in a pseudo-directory, so sys.path can control how they're found.
38
+ #define MP_FROZEN_FAKE_DIR ".frozen"
39
+ #define MP_FROZEN_FAKE_DIR_LENGTH (sizeof(MP_FROZEN_FAKE_DIR)-1)
40
+
41
+ #define MP_FROZEN_FAKE_DIR_SLASH (MP_FROZEN_FAKE_DIR "/")
42
+ #define MP_FROZEN_FAKE_DIR_SLASH_LENGTH (sizeof(MP_FROZEN_FAKE_DIR_SLASH)-1)
43
+
44
+ // This should match MP_FROZEN_FAKE_DIR.
45
+ #define MP_FROZEN_FAKE_DIR_QSTR MP_QSTR__dot_frozen
46
+
37
47
int mp_find_frozen_module (const char * str , size_t len , void * * data );
38
48
const char * mp_find_frozen_str (const char * str , size_t str_len , size_t * len );
39
49
mp_import_stat_t mp_frozen_stat (const char * str );
Original file line number Diff line number Diff line change 40
40
#include "py/mpstate.h"
41
41
#include "py/nlr.h"
42
42
#include "py/compile.h"
43
+ #include "py/frozenmod.h"
43
44
#include "py/runtime.h"
44
45
#include "py/builtin.h"
45
46
#include "py/repl.h"
@@ -469,7 +470,8 @@ MP_NOINLINE int main_(int argc, char **argv) {
469
470
mp_obj_t * path_items ;
470
471
mp_obj_list_get (mp_sys_path , & path_num , & path_items );
471
472
path_items [0 ] = MP_OBJ_NEW_QSTR (MP_QSTR_ );
472
- path_items [1 ] = MP_OBJ_NEW_QSTR (MP_QSTR__dot_frozen );
473
+ // Frozen modules are in their own pseudo-dir, e.g., ".frozen".
474
+ path_items [1 ] = MP_OBJ_NEW_QSTR (MP_FROZEN_FAKE_DIR_QSTR );
473
475
{
474
476
char * p = path ;
475
477
for (mp_uint_t i = builtin_path_count ; i < path_num ; i ++ ) {
You can’t perform that action at this time.
0 commit comments