summaryrefslogtreecommitdiffstats
path: root/Python/frozen.c
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2021-10-05 17:26:37 (GMT)
committerGitHub <noreply@github.com>2021-10-05 17:26:37 (GMT)
commit08285d563e64c179a56ab2f952345b3dbcdb54f3 (patch)
tree7bc95d1865dcb6c29f835044e678fd9ebbe85904 /Python/frozen.c
parent444429142c88b7e22117a6e14c95d1fbdd638c60 (diff)
downloadcpython-08285d563e64c179a56ab2f952345b3dbcdb54f3.zip
cpython-08285d563e64c179a56ab2f952345b3dbcdb54f3.tar.gz
cpython-08285d563e64c179a56ab2f952345b3dbcdb54f3.tar.bz2
bpo-45020: Identify which frozen modules are actually aliases. (gh-28655)
In the list of generated frozen modules at the top of Tools/scripts/freeze_modules.py, you will find that some of the modules have a different name than the module (or .py file) that is actually frozen. Let's call each case an "alias". Aliases do not come into play until we get to the (generated) list of modules in Python/frozen.c. (The tool for freezing modules, Programs/_freeze_module, is only concerned with the source file, not the module it will be used for.) Knowledge of which frozen modules are aliases (and the identity of the original module) normally isn't important. However, this information is valuable when we go to set __file__ on frozen stdlib modules. This change updates Tools/scripts/freeze_modules.py to map aliases to the original module name (or None if not a stdlib module) in Python/frozen.c. We also add a helper function in Python/import.c to look up a frozen module's alias and add the result of that function to the frozen info returned from find_frozen(). https://bugs.python.org/issue45020
Diffstat (limited to 'Python/frozen.c')
-rw-r--r--Python/frozen.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/Python/frozen.c b/Python/frozen.c
index b4f7121..499b3b9 100644
--- a/Python/frozen.c
+++ b/Python/frozen.c
@@ -36,6 +36,7 @@
and __phello__.spam. Loading any will print some famous words... */
#include "Python.h"
+#include "pycore_import.h"
/* Includes for frozen modules: */
#include "frozen_modules/importlib._bootstrap.h"
@@ -102,9 +103,24 @@ static const struct _frozen _PyImport_FrozenModules[] = {
{"__phello__.spam", _Py_M____phello___spam,
(int)sizeof(_Py_M____phello___spam)},
{"__hello_only__", _Py_M__frozen_only, (int)sizeof(_Py_M__frozen_only)},
- {0, 0, 0} /* sentinel */
+ {0, 0, 0} /* modules sentinel */
};
+static const struct _module_alias aliases[] = {
+ {"_frozen_importlib", "importlib._bootstrap"},
+ {"_frozen_importlib_external", "importlib._bootstrap_external"},
+ {"os.path", "posixpath"},
+ {"__hello_alias__", "__hello__"},
+ {"__phello_alias__", "__hello__"},
+ {"__phello_alias__.spam", "__hello__"},
+ {"__phello__.__init__", "<__phello__"},
+ {"__phello__.ham.__init__", "<__phello__.ham"},
+ {"__hello_only__", NULL},
+ {0, 0} /* aliases sentinel */
+};
+const struct _module_alias *_PyImport_FrozenAliases = aliases;
+
+
/* Embedding apps may change this pointer to point to their favorite
collection of frozen modules: */