summaryrefslogtreecommitdiffstats
path: root/Modules/main.c
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2007-03-07 00:34:46 (GMT)
committerGeorg Brandl <georg@python.org>2007-03-07 00:34:46 (GMT)
commit49aafc9f2ce7d41be677cdefbcf0af6d9bd1e752 (patch)
treea5bcc5b8ae7b3a3c639510619726f680cf241c37 /Modules/main.c
parent8537c303c796f42b0375922d2d8a17f3ebcb465a (diff)
downloadcpython-49aafc9f2ce7d41be677cdefbcf0af6d9bd1e752.zip
cpython-49aafc9f2ce7d41be677cdefbcf0af6d9bd1e752.tar.gz
cpython-49aafc9f2ce7d41be677cdefbcf0af6d9bd1e752.tar.bz2
Variant of patch #697613: don't exit the interpreter on a SystemExit
exception if the -i command line option or PYTHONINSPECT environment variable is given, but break into the interactive interpreter just like on other exceptions or normal program exit. (backport)
Diffstat (limited to 'Modules/main.c')
-rw-r--r--Modules/main.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/Modules/main.c b/Modules/main.c
index 7594a76..2dbdfe9 100644
--- a/Modules/main.c
+++ b/Modules/main.c
@@ -216,13 +216,11 @@ Py_Main(int argc, char **argv)
char *module = NULL;
FILE *fp = stdin;
char *p;
- int inspect = 0;
int unbuffered = 0;
int skipfirstline = 0;
int stdin_is_interactive = 0;
int help = 0;
int version = 0;
- int saw_inspect_flag = 0;
int saw_unbuffered_flag = 0;
PyCompilerFlags cf;
@@ -297,8 +295,7 @@ Py_Main(int argc, char **argv)
/* NOTREACHED */
case 'i':
- inspect++;
- saw_inspect_flag = 1;
+ Py_InspectFlag++;
Py_InteractiveFlag++;
break;
@@ -369,9 +366,9 @@ Py_Main(int argc, char **argv)
return 0;
}
- if (!saw_inspect_flag &&
+ if (!Py_InspectFlag &&
(p = Py_GETENV("PYTHONINSPECT")) && *p != '\0')
- inspect = 1;
+ Py_InspectFlag = 1;
if (!saw_unbuffered_flag &&
(p = Py_GETENV("PYTHONUNBUFFERED")) && *p != '\0')
unbuffered = 1;
@@ -499,7 +496,7 @@ Py_Main(int argc, char **argv)
PySys_SetArgv(argc-_PyOS_optind, argv+_PyOS_optind);
- if ((inspect || (command == NULL && filename == NULL && module == NULL)) &&
+ if ((Py_InspectFlag || (command == NULL && filename == NULL && module == NULL)) &&
isatty(fileno(stdin))) {
PyObject *v;
v = PyImport_ImportModule("readline");
@@ -518,6 +515,7 @@ Py_Main(int argc, char **argv)
}
else {
if (filename == NULL && stdin_is_interactive) {
+ Py_InspectFlag = 0; /* do exit on SystemExit */
RunStartupFile(&cf);
}
/* XXX */
@@ -530,16 +528,18 @@ Py_Main(int argc, char **argv)
/* Check this environment variable at the end, to give programs the
* opportunity to set it from Python.
*/
- if (!saw_inspect_flag &&
+ if (!Py_InspectFlag &&
(p = Py_GETENV("PYTHONINSPECT")) && *p != '\0')
{
- inspect = 1;
+ Py_InspectFlag = 1;
}
- if (inspect && stdin_is_interactive &&
- (filename != NULL || command != NULL || module != NULL))
+ if (Py_InspectFlag && stdin_is_interactive &&
+ (filename != NULL || command != NULL || module != NULL)) {
+ Py_InspectFlag = 0;
/* XXX */
sts = PyRun_AnyFileFlags(stdin, "<stdin>", &cf) != 0;
+ }
WaitForThreadShutdown();