summaryrefslogtreecommitdiff
path: root/Programs
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2015-05-02 19:15:18 -0600
committerEric Snow <ericsnowcurrently@gmail.com>2015-05-02 19:15:18 -0600
commit32439d6eb63f1ea31aed1e45459f0f50f965ef51 (patch)
tree8603d0565af4892f25b0361e46ffedcc35624f30 /Programs
parent6b4c63dea5a1e470849a6925c1b29faea2b01636 (diff)
downloadcpython-git-32439d6eb63f1ea31aed1e45459f0f50f965ef51.tar.gz
Issue #23911: Move path-based bootstrap code to a separate frozen module.
Diffstat (limited to 'Programs')
-rw-r--r--Programs/_freeze_importlib.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/Programs/_freeze_importlib.c b/Programs/_freeze_importlib.c
index b72fcf486f..42749db7ea 100644
--- a/Programs/_freeze_importlib.c
+++ b/Programs/_freeze_importlib.c
@@ -12,6 +12,7 @@
#include <unistd.h>
#endif
+int Py_FrozenFlag = 1; /* Suppress errors from getpath.c */
/* To avoid a circular dependency on frozen.o, we create our own structure
of frozen modules instead, left deliberately blank so as to avoid
@@ -33,13 +34,14 @@ const char header[] = "/* Auto-generated by Programs/_freeze_importlib.c */";
int
main(int argc, char *argv[])
{
- char *inpath, *outpath;
+ char *inpath, *outpath, *code_name;
FILE *infile = NULL, *outfile = NULL;
struct _Py_stat_struct status;
size_t text_size, data_size, n;
char *text = NULL;
unsigned char *data;
PyObject *code = NULL, *marshalled = NULL;
+ int is_bootstrap = 1;
PyImport_FrozenModules = _PyImport_FrozenModules;
@@ -82,8 +84,14 @@ main(int argc, char *argv[])
/* Don't install importlib, since it could execute outdated bytecode. */
_Py_InitializeEx_Private(1, 0);
- code = Py_CompileStringExFlags(text, "<frozen importlib._bootstrap>",
- Py_file_input, NULL, 0);
+ if (strstr(inpath, "_external") != NULL) {
+ is_bootstrap = 0;
+ }
+
+ code_name = is_bootstrap ?
+ "<frozen importlib._bootstrap>" :
+ "<frozen importlib._bootstrap_external>";
+ code = Py_CompileStringExFlags(text, code_name, Py_file_input, NULL, 0);
if (code == NULL)
goto error;
free(text);
@@ -106,7 +114,11 @@ main(int argc, char *argv[])
goto error;
}
fprintf(outfile, "%s\n", header);
- fprintf(outfile, "const unsigned char _Py_M__importlib[] = {\n");
+ if (is_bootstrap)
+ fprintf(outfile, "const unsigned char _Py_M__importlib[] = {\n");
+ else
+ fprintf(outfile,
+ "const unsigned char _Py_M__importlib_external[] = {\n");
for (n = 0; n < data_size; n += 16) {
size_t i, end = Py_MIN(n + 16, data_size);
fprintf(outfile, " ");