Author: christian.heimes
Date: Thu Nov 15 03:26:46 2007
New Revision: 58974

Modified:
   python/branches/py3k/Modules/_ctypes/callbacks.c
   python/branches/py3k/Modules/_cursesmodule.c
   python/branches/py3k/Modules/threadmodule.c
   python/branches/py3k/Python/bltinmodule.c
   python/branches/py3k/Python/errors.c
   python/branches/py3k/Python/pythonrun.c
   python/branches/py3k/Python/sysmodule.c
Log:
Added some additional checks for sys.std?? is None, see #1440

Modified: python/branches/py3k/Modules/_ctypes/callbacks.c
==============================================================================
--- python/branches/py3k/Modules/_ctypes/callbacks.c    (original)
+++ python/branches/py3k/Modules/_ctypes/callbacks.c    Thu Nov 15 03:26:46 2007
@@ -17,7 +17,7 @@
        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();
 }

Modified: python/branches/py3k/Modules/_cursesmodule.c
==============================================================================
--- python/branches/py3k/Modules/_cursesmodule.c        (original)
+++ python/branches/py3k/Modules/_cursesmodule.c        Thu Nov 15 03:26:46 2007
@@ -2010,7 +2010,7 @@
 
                sys_stdout = PySys_GetObject("stdout");
 
-               if (sys_stdout == NULL) {
+               if (sys_stdout == NULL || sys_stdout == Py_None) {
                        PyErr_SetString(
                                PyCursesError,
                                "lost sys.stdout");

Modified: python/branches/py3k/Modules/threadmodule.c
==============================================================================
--- python/branches/py3k/Modules/threadmodule.c (original)
+++ python/branches/py3k/Modules/threadmodule.c Thu Nov 15 03:26:46 2007
@@ -429,7 +429,7 @@
                        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);

Modified: python/branches/py3k/Python/bltinmodule.c
==============================================================================
--- python/branches/py3k/Python/bltinmodule.c   (original)
+++ python/branches/py3k/Python/bltinmodule.c   Thu Nov 15 03:26:46 2007
@@ -1265,17 +1265,17 @@
                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;

Modified: python/branches/py3k/Python/errors.c
==============================================================================
--- python/branches/py3k/Python/errors.c        (original)
+++ python/branches/py3k/Python/errors.c        Thu Nov 15 03:26:46 2007
@@ -626,7 +626,7 @@
        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;

Modified: python/branches/py3k/Python/pythonrun.c
==============================================================================
--- python/branches/py3k/Python/pythonrun.c     (original)
+++ python/branches/py3k/Python/pythonrun.c     Thu Nov 15 03:26:46 2007
@@ -335,7 +335,7 @@
        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 @@
                        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 @@
        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 @@
        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 @@
        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");
        }

Modified: python/branches/py3k/Python/sysmodule.c
==============================================================================
--- python/branches/py3k/Python/sysmodule.c     (original)
+++ python/branches/py3k/Python/sysmodule.c     Thu Nov 15 03:26:46 2007
@@ -89,7 +89,7 @@
        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;
        }
_______________________________________________
Python-3000-checkins mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000-checkins

Reply via email to