diff options
author | Christian Heimes <christian@cheimes.de> | 2007-11-15 02:26:46 (GMT) |
---|---|---|
committer | Christian Heimes <christian@cheimes.de> | 2007-11-15 02:26:46 (GMT) |
commit | 2be03734f89fa0a5de0a2426790be2d16440fb68 (patch) | |
tree | 7d41e63de62d8ebbc41a7d3b46604fe84f65aff6 | |
parent | 70021d716456ffcca9caba707a735e845e18dd6e (diff) | |
download | cpython-2be03734f89fa0a5de0a2426790be2d16440fb68.zip cpython-2be03734f89fa0a5de0a2426790be2d16440fb68.tar.gz cpython-2be03734f89fa0a5de0a2426790be2d16440fb68.tar.bz2 |
Added some additional checks for sys.std?? is None, see #1440
-rw-r--r-- | Modules/_ctypes/callbacks.c | 2 | ||||
-rw-r--r-- | Modules/_cursesmodule.c | 2 | ||||
-rw-r--r-- | Modules/threadmodule.c | 2 | ||||
-rw-r--r-- | Python/bltinmodule.c | 6 | ||||
-rw-r--r-- | Python/errors.c | 2 | ||||
-rw-r--r-- | Python/pythonrun.c | 13 | ||||
-rw-r--r-- | Python/sysmodule.c | 2 |
7 files changed, 17 insertions, 12 deletions
diff --git a/Modules/_ctypes/callbacks.c b/Modules/_ctypes/callbacks.c index 9f5e5d0..9e1aa4f 100644 --- a/Modules/_ctypes/callbacks.c +++ b/Modules/_ctypes/callbacks.c @@ -17,7 +17,7 @@ PrintError(char *msg, ...) va_start(marker, msg); vsnprintf(buf, sizeof(buf), msg, marker); va_end(marker); - if (f) + if (f != NULL && f != Py_None) PyFile_WriteString(buf, f); PyErr_Print(); } diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c index cf412d8..3a88360 100644 --- a/Modules/_cursesmodule.c +++ b/Modules/_cursesmodule.c @@ -2010,7 +2010,7 @@ PyCurses_setupterm(PyObject* self, PyObject *args, PyObject* keywds) sys_stdout = PySys_GetObject("stdout"); - if (sys_stdout == NULL) { + if (sys_stdout == NULL || sys_stdout == Py_None) { PyErr_SetString( PyCursesError, "lost sys.stdout"); diff --git a/Modules/threadmodule.c b/Modules/threadmodule.c index 62ea660..876d5e2 100644 --- a/Modules/threadmodule.c +++ b/Modules/threadmodule.c @@ -429,7 +429,7 @@ t_bootstrap(void *boot_raw) PySys_WriteStderr( "Unhandled exception in thread started by "); file = PySys_GetObject("stderr"); - if (file) + if (file != NULL && file != Py_None) PyFile_WriteObject(boot->func, file, 0); else PyObject_Print(boot->func, stderr, 0); diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 755bfc1..1b1593e 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -1265,17 +1265,17 @@ builtin_input(PyObject *self, PyObject *args) return NULL; /* Check that stdin/out/err are intact */ - if (fin == NULL) { + if (fin == NULL || fin == Py_None) { PyErr_SetString(PyExc_RuntimeError, "input(): lost sys.stdin"); return NULL; } - if (fout == NULL) { + if (fout == NULL || fout == Py_None) { PyErr_SetString(PyExc_RuntimeError, "input(): lost sys.stdout"); return NULL; } - if (ferr == NULL) { + if (ferr == NULL || ferr == Py_None) { PyErr_SetString(PyExc_RuntimeError, "input(): lost sys.stderr"); return NULL; diff --git a/Python/errors.c b/Python/errors.c index b45dad4..1cd5dfd 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -626,7 +626,7 @@ PyErr_WriteUnraisable(PyObject *obj) PyObject *f, *t, *v, *tb; PyErr_Fetch(&t, &v, &tb); f = PySys_GetObject("stderr"); - if (f != NULL) { + if (f != NULL && f != Py_None) { PyFile_WriteString("Exception ", f); if (t) { PyObject* moduleName; diff --git a/Python/pythonrun.c b/Python/pythonrun.c index 763f905..8643951 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -335,7 +335,7 @@ flush_std_files(void) PyObject *ferr = PySys_GetObject("stderr"); PyObject *tmp; - if (fout != NULL) { + if (fout != NULL && fout != Py_None) { tmp = PyObject_CallMethod(fout, "flush", ""); if (tmp == NULL) PyErr_Clear(); @@ -343,7 +343,7 @@ flush_std_files(void) Py_DECREF(tmp); } - if (ferr != NULL) { + if (ferr != NULL || ferr != Py_None) { tmp = PyObject_CallMethod(ferr, "flush", ""); if (tmp == NULL) PyErr_Clear(); @@ -693,6 +693,8 @@ initsite(void) m = PyImport_ImportModule("site"); if (m == NULL) { f = PySys_GetObject("stderr"); + if (f == NULL || f == Py_None) + return; if (Py_VerboseFlag) { PyFile_WriteString( "'import site' failed; traceback:\n", f); @@ -900,7 +902,7 @@ PyRun_InteractiveOneFlags(FILE *fp, const char *filename, PyCompilerFlags *flags if (fp == stdin) { /* Fetch encoding from sys.stdin */ v = PySys_GetObject("stdin"); - if (!v) + if (v == NULL || v == Py_None) return -1; oenc = PyObject_GetAttrString(v, "encoding"); if (!oenc) @@ -1293,7 +1295,10 @@ PyErr_Display(PyObject *exception, PyObject *value, PyObject *tb) int err = 0; PyObject *f = PySys_GetObject("stderr"); Py_INCREF(value); - if (f == NULL) { + if (f == Py_None) { + /* pass */ + } + else if (f == NULL) { _PyObject_Dump(value); fprintf(stderr, "lost sys.stderr\n"); } diff --git a/Python/sysmodule.c b/Python/sysmodule.c index b77d184..2fcba54 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -89,7 +89,7 @@ sys_displayhook(PyObject *self, PyObject *o) if (PyObject_SetAttrString(builtins, "_", Py_None) != 0) return NULL; outf = PySys_GetObject("stdout"); - if (outf == NULL) { + if (outf == NULL || outf == Py_None) { PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout"); return NULL; } |