57
57
// uses mp_vfs_import_stat) to also search frozen modules. Given an exact
58
58
// path to a file or directory (e.g. "foo/bar", foo/bar.py" or "foo/bar.mpy"),
59
59
// will return whether the path is a file, directory, or doesn't exist.
60
- STATIC mp_import_stat_t stat_path (const char * path ) {
60
+ STATIC mp_import_stat_t stat_path (vstr_t * path ) {
61
+ const char * str = vstr_null_terminated_str (path );
61
62
#if MICROPY_MODULE_FROZEN
62
63
// Only try and load as a frozen module if it starts with .frozen/.
63
64
const int frozen_path_prefix_len = strlen (MP_FROZEN_PATH_PREFIX );
64
- if (strncmp (path , MP_FROZEN_PATH_PREFIX , frozen_path_prefix_len ) == 0 ) {
65
+ if (strncmp (str , MP_FROZEN_PATH_PREFIX , frozen_path_prefix_len ) == 0 ) {
65
66
// Just stat (which is the return value), don't get the data.
66
- return mp_find_frozen_module (path + frozen_path_prefix_len , NULL , NULL );
67
+ return mp_find_frozen_module (str + frozen_path_prefix_len , NULL , NULL );
67
68
}
68
69
#endif
69
- return mp_import_stat (path );
70
+ return mp_import_stat (str );
70
71
}
71
72
72
73
// Stat a given filesystem path to a .py file. If the file does not exist,
@@ -75,7 +76,7 @@ STATIC mp_import_stat_t stat_path(const char *path) {
75
76
// files. This uses stat_path above, rather than mp_import_stat directly, so
76
77
// that the .frozen path prefix is handled.
77
78
STATIC mp_import_stat_t stat_file_py_or_mpy (vstr_t * path ) {
78
- mp_import_stat_t stat = stat_path (vstr_null_terminated_str ( path ) );
79
+ mp_import_stat_t stat = stat_path (path );
79
80
if (stat == MP_IMPORT_STAT_FILE ) {
80
81
return stat ;
81
82
}
@@ -85,7 +86,7 @@ STATIC mp_import_stat_t stat_file_py_or_mpy(vstr_t *path) {
85
86
// Note: There's no point doing this if it's a frozen path, but adding the check
86
87
// would be extra code, and no harm letting mp_find_frozen_module fail instead.
87
88
vstr_ins_byte (path , path -> len - 2 , 'm' );
88
- stat = stat_path (vstr_null_terminated_str ( path ) );
89
+ stat = stat_path (path );
89
90
if (stat == MP_IMPORT_STAT_FILE ) {
90
91
return stat ;
91
92
}
@@ -99,7 +100,7 @@ STATIC mp_import_stat_t stat_file_py_or_mpy(vstr_t *path) {
99
100
// result is a file, the path argument will be updated to include the file
100
101
// extension.
101
102
STATIC mp_import_stat_t stat_module (vstr_t * path ) {
102
- mp_import_stat_t stat = stat_path (vstr_null_terminated_str ( path ) );
103
+ mp_import_stat_t stat = stat_path (path );
103
104
DEBUG_printf ("stat %s: %d\n" , vstr_str (path ), stat );
104
105
if (stat == MP_IMPORT_STAT_DIR ) {
105
106
return stat ;
0 commit comments