diff options
author | Eric Snow <ericsnowcurrently@gmail.com> | 2015-05-03 01:15:18 (GMT) |
---|---|---|
committer | Eric Snow <ericsnowcurrently@gmail.com> | 2015-05-03 01:15:18 (GMT) |
commit | 32439d6eb63f1ea31aed1e45459f0f50f965ef51 (patch) | |
tree | 8603d0565af4892f25b0361e46ffedcc35624f30 /Programs | |
parent | 6b4c63dea5a1e470849a6925c1b29faea2b01636 (diff) | |
download | cpython-32439d6eb63f1ea31aed1e45459f0f50f965ef51.zip cpython-32439d6eb63f1ea31aed1e45459f0f50f965ef51.tar.gz cpython-32439d6eb63f1ea31aed1e45459f0f50f965ef51.tar.bz2 |
Issue #23911: Move path-based bootstrap code to a separate frozen module.
Diffstat (limited to 'Programs')
-rw-r--r-- | Programs/_freeze_importlib.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/Programs/_freeze_importlib.c b/Programs/_freeze_importlib.c index b72fcf4..42749db 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, " "); |