Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8f18320

Browse files
committed
Last-minute fix for Jim H: don't die after del sys.stdout
1 parent d11ec25 commit 8f18320

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

Python/ceval.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,8 +1017,12 @@ eval_code2(co, globals, locals,
10171017
err = Py_FlushLine();
10181018
if (err == 0) {
10191019
x = PySys_GetObject("stdout");
1020-
if (x == NULL)
1020+
if (x == NULL) {
1021+
PyErr_SetString(
1022+
PyExc_RuntimeError,
1023+
"lost sys.stdout");
10211024
err = -1;
1025+
}
10221026
}
10231027
if (err == 0)
10241028
err = PyFile_WriteObject(v, x, 0);
@@ -1037,7 +1041,12 @@ eval_code2(co, globals, locals,
10371041
case PRINT_ITEM:
10381042
v = POP();
10391043
w = PySys_GetObject("stdout");
1040-
if (PyFile_SoftSpace(w, 1))
1044+
if (w == NULL) {
1045+
PyErr_SetString(PyExc_RuntimeError,
1046+
"lost sys.stdout");
1047+
err = -1;
1048+
}
1049+
else if (PyFile_SoftSpace(w, 1))
10411050
err = PyFile_WriteString(" ", w);
10421051
if (err == 0)
10431052
err = PyFile_WriteObject(v, w, Py_PRINT_RAW);

0 commit comments

Comments
 (0)