]> granicus.if.org Git - python/commitdiff
Backport issue 4597 to python 2.5.3: Fixed several opcodes that weren't always
authorJeffrey Yasskin <jyasskin@gmail.com>
Wed, 10 Dec 2008 17:23:20 +0000 (17:23 +0000)
committerJeffrey Yasskin <jyasskin@gmail.com>
Wed, 10 Dec 2008 17:23:20 +0000 (17:23 +0000)
propagating exceptions.

Lib/test/test_file.py
Misc/NEWS
Python/ceval.c

index 0a8114a0c7bf4a2b277a7ae1485944dc25a143bc..ba6ea47edf7c8ab19d73c81104d112fcccc74880 100644 (file)
@@ -341,6 +341,20 @@ class StdoutTests(unittest.TestCase):
         finally:
             sys.stdout = save_stdout
 
+    def test_del_stdout_before_print(self):
+        # Issue 4597: 'print' with no argument wasn't reporting when
+        # sys.stdout was deleted.
+        save_stdout = sys.stdout
+        del sys.stdout
+        try:
+            print
+        except RuntimeError, e:
+            self.assertEquals(str(e), "lost sys.stdout")
+        else:
+            self.fail("Expected RuntimeError")
+        finally:
+            sys.stdout = save_stdout
+
 
 def test_main():
     # Historically, these tests have been sloppy about removing TESTFN.
index f6ea81069b9424402db7044c727990963b4f7446..518f355e546a86672d481a13e15df0b6f4c93db5 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@ What's New in Python 2.5.3?
 Core and builtins
 -----------------
 
+- Issue #4597: Fixed several opcodes that weren't always propagating
+  exceptions.
+
 - Issue #4589: Propagated an exception thrown by a context manager's
   __exit__ method's result while it's being converted to bool.
 
index d74149c4a936710fab3f8289b36c36ec669e2923..5f8b860ab5d33b805ab6fa8ef545f3694d9ee05f 100644 (file)
@@ -1025,6 +1025,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
                        }
                        Py_FatalError("invalid argument to DUP_TOPX"
                                      " (bytecode corruption?)");
+                       /* Never returns, so don't bother to set why. */
                        break;
 
                case UNARY_POSITIVE:
@@ -1618,9 +1619,11 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
                case PRINT_NEWLINE:
                        if (stream == NULL || stream == Py_None) {
                                w = PySys_GetObject("stdout");
-                               if (w == NULL)
+                               if (w == NULL) {
                                        PyErr_SetString(PyExc_RuntimeError,
                                                        "lost sys.stdout");
+                                       why = WHY_EXCEPTION;
+                               }
                        }
                        if (w != NULL) {
                                Py_INCREF(w);
@@ -1837,6 +1840,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
                                PyErr_Format(PyExc_SystemError,
                                             "no locals when loading %s",
                                             PyObject_REPR(w));
+                               why = WHY_EXCEPTION;
                                break;
                        }
                        if (PyDict_CheckExact(v)) {
@@ -2381,7 +2385,10 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
                        Py_DECREF(v);
                        if (x != NULL) {
                                v = POP();
-                               err = PyFunction_SetClosure(x, v);
+                               if (PyFunction_SetClosure(x, v) != 0) {
+                                       /* Can't happen unless bytecode is corrupt. */
+                                       why = WHY_EXCEPTION;
+                               }
                                Py_DECREF(v);
                        }
                        if (x != NULL && oparg > 0) {
@@ -2395,7 +2402,11 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
                                        w = POP();
                                        PyTuple_SET_ITEM(v, oparg, w);
                                }
-                               err = PyFunction_SetDefaults(x, v);
+                               if (PyFunction_SetDefaults(x, v) != 0) {
+                                       /* Can't happen unless
+                                           PyFunction_SetDefaults changes. */
+                                       why = WHY_EXCEPTION;
+                               }
                                Py_DECREF(v);
                        }
                        PUSH(x);