Commit 49aafc9f authored by Georg Brandl's avatar Georg Brandl

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)
parent 8537c303
...@@ -8,6 +8,7 @@ extern "C" { ...@@ -8,6 +8,7 @@ extern "C" {
PyAPI_DATA(int) Py_DebugFlag; PyAPI_DATA(int) Py_DebugFlag;
PyAPI_DATA(int) Py_VerboseFlag; PyAPI_DATA(int) Py_VerboseFlag;
PyAPI_DATA(int) Py_InteractiveFlag; PyAPI_DATA(int) Py_InteractiveFlag;
PyAPI_DATA(int) Py_InspectFlag;
PyAPI_DATA(int) Py_OptimizeFlag; PyAPI_DATA(int) Py_OptimizeFlag;
PyAPI_DATA(int) Py_NoSiteFlag; PyAPI_DATA(int) Py_NoSiteFlag;
PyAPI_DATA(int) Py_UseClassExceptionsFlag; PyAPI_DATA(int) Py_UseClassExceptionsFlag;
......
...@@ -12,6 +12,11 @@ What's New in Python 2.6 alpha 1? ...@@ -12,6 +12,11 @@ What's New in Python 2.6 alpha 1?
Core and builtins Core and builtins
----------------- -----------------
- 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.
- Patch #1638879: don't accept strings with embedded NUL bytes in long(). - Patch #1638879: don't accept strings with embedded NUL bytes in long().
- Bug #1674503: close the file opened by execfile() in an error condition. - Bug #1674503: close the file opened by execfile() in an error condition.
......
...@@ -216,13 +216,11 @@ Py_Main(int argc, char **argv) ...@@ -216,13 +216,11 @@ Py_Main(int argc, char **argv)
char *module = NULL; char *module = NULL;
FILE *fp = stdin; FILE *fp = stdin;
char *p; char *p;
int inspect = 0;
int unbuffered = 0; int unbuffered = 0;
int skipfirstline = 0; int skipfirstline = 0;
int stdin_is_interactive = 0; int stdin_is_interactive = 0;
int help = 0; int help = 0;
int version = 0; int version = 0;
int saw_inspect_flag = 0;
int saw_unbuffered_flag = 0; int saw_unbuffered_flag = 0;
PyCompilerFlags cf; PyCompilerFlags cf;
...@@ -297,8 +295,7 @@ Py_Main(int argc, char **argv) ...@@ -297,8 +295,7 @@ Py_Main(int argc, char **argv)
/* NOTREACHED */ /* NOTREACHED */
case 'i': case 'i':
inspect++; Py_InspectFlag++;
saw_inspect_flag = 1;
Py_InteractiveFlag++; Py_InteractiveFlag++;
break; break;
...@@ -369,9 +366,9 @@ Py_Main(int argc, char **argv) ...@@ -369,9 +366,9 @@ Py_Main(int argc, char **argv)
return 0; return 0;
} }
if (!saw_inspect_flag && if (!Py_InspectFlag &&
(p = Py_GETENV("PYTHONINSPECT")) && *p != '\0') (p = Py_GETENV("PYTHONINSPECT")) && *p != '\0')
inspect = 1; Py_InspectFlag = 1;
if (!saw_unbuffered_flag && if (!saw_unbuffered_flag &&
(p = Py_GETENV("PYTHONUNBUFFERED")) && *p != '\0') (p = Py_GETENV("PYTHONUNBUFFERED")) && *p != '\0')
unbuffered = 1; unbuffered = 1;
...@@ -499,7 +496,7 @@ Py_Main(int argc, char **argv) ...@@ -499,7 +496,7 @@ Py_Main(int argc, char **argv)
PySys_SetArgv(argc-_PyOS_optind, argv+_PyOS_optind); 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))) { isatty(fileno(stdin))) {
PyObject *v; PyObject *v;
v = PyImport_ImportModule("readline"); v = PyImport_ImportModule("readline");
...@@ -518,6 +515,7 @@ Py_Main(int argc, char **argv) ...@@ -518,6 +515,7 @@ Py_Main(int argc, char **argv)
} }
else { else {
if (filename == NULL && stdin_is_interactive) { if (filename == NULL && stdin_is_interactive) {
Py_InspectFlag = 0; /* do exit on SystemExit */
RunStartupFile(&cf); RunStartupFile(&cf);
} }
/* XXX */ /* XXX */
...@@ -530,16 +528,18 @@ Py_Main(int argc, char **argv) ...@@ -530,16 +528,18 @@ Py_Main(int argc, char **argv)
/* Check this environment variable at the end, to give programs the /* Check this environment variable at the end, to give programs the
* opportunity to set it from Python. * opportunity to set it from Python.
*/ */
if (!saw_inspect_flag && if (!Py_InspectFlag &&
(p = Py_GETENV("PYTHONINSPECT")) && *p != '\0') (p = Py_GETENV("PYTHONINSPECT")) && *p != '\0')
{ {
inspect = 1; Py_InspectFlag = 1;
} }
if (inspect && stdin_is_interactive && if (Py_InspectFlag && stdin_is_interactive &&
(filename != NULL || command != NULL || module != NULL)) (filename != NULL || command != NULL || module != NULL)) {
Py_InspectFlag = 0;
/* XXX */ /* XXX */
sts = PyRun_AnyFileFlags(stdin, "<stdin>", &cf) != 0; sts = PyRun_AnyFileFlags(stdin, "<stdin>", &cf) != 0;
}
WaitForThreadShutdown(); WaitForThreadShutdown();
......
...@@ -69,6 +69,7 @@ extern void _PyGILState_Fini(void); ...@@ -69,6 +69,7 @@ extern void _PyGILState_Fini(void);
int Py_DebugFlag; /* Needed by parser.c */ int Py_DebugFlag; /* Needed by parser.c */
int Py_VerboseFlag; /* Needed by import.c */ int Py_VerboseFlag; /* Needed by import.c */
int Py_InteractiveFlag; /* Needed by Py_FdIsInteractive() below */ int Py_InteractiveFlag; /* Needed by Py_FdIsInteractive() below */
int Py_InspectFlag; /* Needed to determine whether to exit at SystemError */
int Py_NoSiteFlag; /* Suppress 'import site' */ int Py_NoSiteFlag; /* Suppress 'import site' */
int Py_UseClassExceptionsFlag = 1; /* Needed by bltinmodule.c: deprecated */ int Py_UseClassExceptionsFlag = 1; /* Needed by bltinmodule.c: deprecated */
int Py_FrozenFlag; /* Needed by getpath.c */ int Py_FrozenFlag; /* Needed by getpath.c */
...@@ -1019,6 +1020,11 @@ handle_system_exit(void) ...@@ -1019,6 +1020,11 @@ handle_system_exit(void)
PyObject *exception, *value, *tb; PyObject *exception, *value, *tb;
int exitcode = 0; int exitcode = 0;
if (Py_InspectFlag)
/* Don't exit if -i flag was given. This flag is set to 0
* when entering interactive mode for inspecting. */
return;
PyErr_Fetch(&exception, &value, &tb); PyErr_Fetch(&exception, &value, &tb);
if (Py_FlushLine()) if (Py_FlushLine())
PyErr_Clear(); PyErr_Clear();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment