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