mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
Issue #23911: Move path-based bootstrap code to a separate frozen module.
This commit is contained in:
parent
6b4c63dea5
commit
32439d6eb6
27 changed files with 6192 additions and 5712 deletions
|
@ -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, " ");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue