summaryrefslogtreecommitdiffstats
path: root/Python/frozenmain.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2021-05-17 21:48:35 (GMT)
committerGitHub <noreply@github.com>2021-05-17 21:48:35 (GMT)
commiteaede0ded72e67cee4a91c086847d54cb64ca74c (patch)
tree3c9bf4c33572db77fc79ae6a701628614c94f3a6 /Python/frozenmain.c
parentf32c7950e0077b6d9a8e217c2796fc582f18ca08 (diff)
downloadcpython-eaede0ded72e67cee4a91c086847d54cb64ca74c.zip
cpython-eaede0ded72e67cee4a91c086847d54cb64ca74c.tar.gz
cpython-eaede0ded72e67cee4a91c086847d54cb64ca74c.tar.bz2
bpo-44131: Test Py_FrozenMain() (GH-26126)
* Add test_frozenmain to test_embed * Add Programs/test_frozenmain.py * Add Programs/freeze_test_frozenmain.py * Add Programs/test_frozenmain.h * Add make regen-test-frozenmain * Add test_frozenmain command to Programs/_testembed * _testembed.c: add error(msg) function
Diffstat (limited to 'Python/frozenmain.c')
-rw-r--r--Python/frozenmain.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/Python/frozenmain.c b/Python/frozenmain.c
index 5eb9e31..c3104da 100644
--- a/Python/frozenmain.c
+++ b/Python/frozenmain.c
@@ -1,4 +1,3 @@
-
/* Python interpreter main program for frozen scripts */
#include "Python.h"
@@ -43,10 +42,12 @@ Py_FrozenMain(int argc, char **argv)
PyConfig_InitPythonConfig(&config);
config.pathconfig_warnings = 0; /* Suppress errors from getpath.c */
- if ((p = Py_GETENV("PYTHONINSPECT")) && *p != '\0')
+ if ((p = Py_GETENV("PYTHONINSPECT")) && *p != '\0') {
inspect = 1;
- if ((p = Py_GETENV("PYTHONUNBUFFERED")) && *p != '\0')
+ }
+ if ((p = Py_GETENV("PYTHONUNBUFFERED")) && *p != '\0') {
unbuffered = 1;
+ }
if (unbuffered) {
setbuf(stdin, (char *)NULL);
@@ -65,8 +66,9 @@ Py_FrozenMain(int argc, char **argv)
argv_copy[i] = Py_DecodeLocale(argv[i], NULL);
argv_copy2[i] = argv_copy[i];
if (!argv_copy[i]) {
- fprintf(stderr, "Unable to decode the command line argument #%i\n",
- i + 1);
+ fprintf(stderr,
+ "Unable to decode the command line argument #%i\n",
+ i + 1);
argc = i;
goto error;
}
@@ -97,24 +99,28 @@ Py_FrozenMain(int argc, char **argv)
PyWinFreeze_ExeInit();
#endif
- if (Py_VerboseFlag)
+ if (Py_VerboseFlag) {
fprintf(stderr, "Python %s\n%s\n",
- Py_GetVersion(), Py_GetCopyright());
+ Py_GetVersion(), Py_GetCopyright());
+ }
PySys_SetArgv(argc, argv_copy);
n = PyImport_ImportFrozenModule("__main__");
- if (n == 0)
+ if (n == 0) {
Py_FatalError("the __main__ module is not frozen");
+ }
if (n < 0) {
PyErr_Print();
sts = 1;
}
- else
+ else {
sts = 0;
+ }
- if (inspect && isatty((int)fileno(stdin)))
+ if (inspect && isatty((int)fileno(stdin))) {
sts = PyRun_AnyFile(stdin, "<stdin>") != 0;
+ }
#ifdef MS_WINDOWS
PyWinFreeze_ExeTerm();