Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions atmel-samd/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#include "py/nlr.h"
#include "py/compile.h"
#include "py/frozenmod.h"
#include "py/mphal.h"
#include "py/runtime.h"
#include "py/repl.h"
Expand Down Expand Up @@ -165,8 +166,8 @@ void reset_mp(void) {
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR_)); // current dir (or base dir of the script)
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_));
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_lib));
// Frozen modules are in their own pseudo-dir, ".frozen".
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__dot_frozen));
// Frozen modules are in their own pseudo-dir, e.g., ".frozen".
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_FROZEN_FAKE_DIR_QSTR));

mp_obj_list_init(mp_sys_argv, 0);
}
Expand Down
5 changes: 3 additions & 2 deletions esp8266/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#include "py/nlr.h"
#include "py/compile.h"
#include "py/frozenmod.h"
#include "py/runtime0.h"
#include "py/runtime.h"
#include "py/stackctrl.h"
Expand Down Expand Up @@ -98,8 +99,8 @@ STATIC void mp_reset(void) {
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR_)); // current dir (or base dir of the script)
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_lib));
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_));
// Frozen modules are in their own pseudo-dir, ".frozen".
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__dot_frozen));
// Frozen modules are in their own pseudo-dir, e.g., ".frozen".
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_FROZEN_FAKE_DIR_QSTR));

mp_obj_list_init(mp_sys_argv, 0);
MP_STATE_PORT(term_obj) = MP_OBJ_NULL;
Expand Down
6 changes: 4 additions & 2 deletions py/builtinimport.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ bool mp_obj_is_package(mp_obj_t module) {
// (whatever is available, if at all).
STATIC mp_import_stat_t mp_import_stat_any(const char *path) {
#if MICROPY_MODULE_FROZEN
if (strlen(path) > 8 && strncmp(".frozen/", path, 8) == 0) {
mp_import_stat_t st = mp_frozen_stat(path + 8);
if (strncmp(MP_FROZEN_FAKE_DIR_SLASH,
path,
MP_FROZEN_FAKE_DIR_SLASH_LENGTH) == 0) {
mp_import_stat_t st = mp_frozen_stat(path + MP_FROZEN_FAKE_DIR_SLASH_LENGTH);
if (st != MP_IMPORT_STAT_NO_EXIST) {
return st;
}
Expand Down
11 changes: 8 additions & 3 deletions py/frozenmod.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,21 @@ mp_import_stat_t mp_frozen_stat(const char *str) {
}

int mp_find_frozen_module(const char *str, size_t len, void **data) {
// The +8/-8 account for the .frozen/ path prefix used on frozen modules.
// If the frozen module pseudo dir (e.g., ".frozen/") is a prefix of str, remove it.
if (strncmp(str, MP_FROZEN_FAKE_DIR_SLASH, MP_FROZEN_FAKE_DIR_SLASH_LENGTH) == 0) {
str = str + MP_FROZEN_FAKE_DIR_SLASH_LENGTH;
len = len - MP_FROZEN_FAKE_DIR_SLASH_LENGTH;
}

#if MICROPY_MODULE_FROZEN_STR
mp_lexer_t *lex = mp_lexer_frozen_str(str + 8, len - 8);
mp_lexer_t *lex = mp_lexer_frozen_str(str, len);
if (lex != NULL) {
*data = lex;
return MP_FROZEN_STR;
}
#endif
#if MICROPY_MODULE_FROZEN_MPY
const mp_raw_code_t *rc = mp_find_frozen_mpy(str + 8, len - 8);
const mp_raw_code_t *rc = mp_find_frozen_mpy(str, len);
if (rc != NULL) {
*data = (void*)rc;
return MP_FROZEN_MPY;
Expand Down
10 changes: 10 additions & 0 deletions py/frozenmod.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ enum {
MP_FROZEN_MPY,
};

// Frozen modules are in a pseudo-directory, so sys.path can control how they're found.
#define MP_FROZEN_FAKE_DIR ".frozen"
#define MP_FROZEN_FAKE_DIR_LENGTH (sizeof(MP_FROZEN_FAKE_DIR)-1)

#define MP_FROZEN_FAKE_DIR_SLASH (MP_FROZEN_FAKE_DIR "/")
#define MP_FROZEN_FAKE_DIR_SLASH_LENGTH (sizeof(MP_FROZEN_FAKE_DIR_SLASH)-1)

// This should match MP_FROZEN_FAKE_DIR.
#define MP_FROZEN_FAKE_DIR_QSTR MP_QSTR__dot_frozen

int mp_find_frozen_module(const char *str, size_t len, void **data);
const char *mp_find_frozen_str(const char *str, size_t str_len, size_t *len);
mp_import_stat_t mp_frozen_stat(const char *str);
Expand Down
4 changes: 3 additions & 1 deletion unix/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "py/mpstate.h"
#include "py/nlr.h"
#include "py/compile.h"
#include "py/frozenmod.h"
#include "py/runtime.h"
#include "py/builtin.h"
#include "py/repl.h"
Expand Down Expand Up @@ -469,7 +470,8 @@ MP_NOINLINE int main_(int argc, char **argv) {
mp_obj_t *path_items;
mp_obj_list_get(mp_sys_path, &path_num, &path_items);
path_items[0] = MP_OBJ_NEW_QSTR(MP_QSTR_);
path_items[1] = MP_OBJ_NEW_QSTR(MP_QSTR__dot_frozen);
// Frozen modules are in their own pseudo-dir, e.g., ".frozen".
path_items[1] = MP_OBJ_NEW_QSTR(MP_FROZEN_FAKE_DIR_QSTR);
{
char *p = path;
for (mp_uint_t i = builtin_path_count; i < path_num; i++) {
Expand Down