- Notifications
You must be signed in to change notification settings - Fork 31.7k
/
Copy path_bootstrap_python.c
109 lines (91 loc) · 2.96 KB
/
_bootstrap_python.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/* Frozen modules bootstrap
*
* Limited and restricted Python interpreter to run
* "Tools/build/deepfreeze.py" on systems with no or older Python
* interpreter.
*/
#include"Python.h"
#include"pycore_import.h"
/* Includes for frozen modules: */
#include"Python/frozen_modules/importlib._bootstrap.h"
#include"Python/frozen_modules/importlib._bootstrap_external.h"
#include"Python/frozen_modules/zipimport.h"
/* End includes */
/* Note that a negative size indicates a package. */
staticconststruct_frozenbootstrap_modules[] = {
{"_frozen_importlib", _Py_M__importlib__bootstrap, (int)sizeof(_Py_M__importlib__bootstrap)},
{"_frozen_importlib_external", _Py_M__importlib__bootstrap_external, (int)sizeof(_Py_M__importlib__bootstrap_external)},
{"zipimport", _Py_M__zipimport, (int)sizeof(_Py_M__zipimport)},
{0, 0, 0} /* bootstrap sentinel */
};
staticconststruct_frozenstdlib_modules[] = {
{0, 0, 0} /* stdlib sentinel */
};
staticconststruct_frozentest_modules[] = {
{0, 0, 0} /* test sentinel */
};
conststruct_frozen*_PyImport_FrozenBootstrap=bootstrap_modules;
conststruct_frozen*_PyImport_FrozenStdlib=stdlib_modules;
conststruct_frozen*_PyImport_FrozenTest=test_modules;
staticconststruct_module_aliasaliases[] = {
{"_frozen_importlib", "importlib._bootstrap"},
{"_frozen_importlib_external", "importlib._bootstrap_external"},
{0, 0} /* aliases sentinel */
};
conststruct_module_alias*_PyImport_FrozenAliases=aliases;
/* Embedding apps may change this pointer to point to their favorite
collection of frozen modules: */
conststruct_frozen*PyImport_FrozenModules=NULL;
int
#ifdefMS_WINDOWS
wmain(intargc, wchar_t**argv)
#else
main(intargc, char**argv)
#endif
{
PyStatusstatus;
PyConfigconfig;
PyConfig_InitIsolatedConfig(&config);
// don't warn, pybuilddir.txt does not exist yet
config.pathconfig_warnings=0;
// parse arguments
config.parse_argv=1;
// add current script dir to sys.path
config.isolated=0;
config.safe_path=0;
#ifdefMS_WINDOWS
status=PyConfig_SetArgv(&config, argc, argv);
#else
status=PyConfig_SetBytesArgv(&config, argc, argv);
#endif
if (PyStatus_Exception(status)) {
goto error;
}
status=PyConfig_Read(&config);
if (config.run_filename==NULL) {
status=PyStatus_Error("Run filename expected");
goto error;
}
#defineCLEAR(ATTR) \
do { \
PyMem_RawFree(ATTR); \
ATTR = NULL; \
} while (0)
// isolate from system Python
CLEAR(config.base_prefix);
CLEAR(config.prefix);
CLEAR(config.base_exec_prefix);
CLEAR(config.exec_prefix);
status=Py_InitializeFromConfig(&config);
if (PyStatus_Exception(status)) {
goto error;
}
PyConfig_Clear(&config);
returnPy_RunMain();
error:
PyConfig_Clear(&config);
if (PyStatus_IsExit(status)) {
returnstatus.exitcode;
}
Py_ExitStatusException(status);
}