aboutsummaryrefslogtreecommitdiff
path: root/py/frozenmod.c
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2016-05-21 21:33:42 +0300
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2016-05-21 21:38:50 +0300
commitfb742cdc1215c5444cbe9e10f37fecb4ffce0006 (patch)
tree997769e40172cbf1129d2703b3526e56ae5f1eba /py/frozenmod.c
parentb58095821623a3f39de70e26d2d9f1fef173064d (diff)
py/{builtinimport,frozenmod}: Rework frozen modules support to support packages.
Now frozen modules is treated just as a kind of VFS, and all operations performed on it correspond to operations on normal filesystem. This allows to support packages properly, and potentially also data files. This change also have changes to rework frozen bytecode modules support to use the same framework, but it's not finished (and actually may not work, as older adhox handling of any type of frozen modules is removed).
Diffstat (limited to 'py/frozenmod.c')
-rw-r--r--py/frozenmod.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/py/frozenmod.c b/py/frozenmod.c
index 18beb0f8e..0fabb06a9 100644
--- a/py/frozenmod.c
+++ b/py/frozenmod.c
@@ -43,6 +43,24 @@ extern const char mp_frozen_str_names[];
extern const uint32_t mp_frozen_str_sizes[];
extern const char mp_frozen_str_content[];
+mp_import_stat_t mp_frozen_stat(const char *str) {
+ size_t len = strlen(str);
+ const char *name = mp_frozen_str_names;
+
+ for (int i = 0; *name != 0; i++) {
+ size_t l = strlen(name);
+ if (l >= len && !memcmp(str, name, len)) {
+ if (name[len] == 0) {
+ return MP_IMPORT_STAT_FILE;
+ } else if (name[len] == '/') {
+ return MP_IMPORT_STAT_DIR;
+ }
+ }
+ name += l + 1;
+ }
+ return MP_IMPORT_STAT_NO_EXIST;
+}
+
STATIC mp_lexer_t *mp_find_frozen_str(const char *str, size_t len) {
const char *name = mp_frozen_str_names;