From 32439d6eb63f1ea31aed1e45459f0f50f965ef51 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Sat, 2 May 2015 19:15:18 -0600 Subject: Issue #23911: Move path-based bootstrap code to a separate frozen module. --- Programs/_freeze_importlib.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'Programs') 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 #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, "", - Py_file_input, NULL, 0); + if (strstr(inpath, "_external") != NULL) { + is_bootstrap = 0; + } + + code_name = is_bootstrap ? + "" : + ""; + 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, " "); -- cgit v1.2.1