This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author scoder
Recipients Rosuav, belopolsky, gvanrossum, python-dev, r.david.murray, rhettinger, schlamar, scoder, serhiy.storchaka, vstinner
Date 2014-11-29.08:17:24
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1417249044.51.0.129824816768.issue22906@psf.upfronthosting.co.za>
In-reply-to
Content
Regarding the patch below, isn't most of this redundant? ISTM that simply calling PyErr_SetString(...) should do all of this, including the exception chaining.


diff -r 23ab1197df0b Objects/genobject.c
--- a/Objects/genobject.c	Wed Nov 19 13:21:40 2014 +0200
+++ b/Objects/genobject.c	Thu Nov 20 16:47:59 2014 +1100
@@ -130,6 +130,23 @@
         }
         Py_CLEAR(result);
     }
+    else if (!result)
+    {
+        if (PyErr_ExceptionMatches(PyExc_StopIteration))
+        {
+            PyObject *exc, *val, *val2, *tb;
+            PyErr_Fetch(&exc, &val, &tb);
+            PyErr_NormalizeException(&exc, &val, &tb);
+            Py_DECREF(exc);
+            Py_XDECREF(tb);
+            PyErr_SetString(PyExc_RuntimeError,
+                "generator raised StopIteration");
+            PyErr_Fetch(&exc, &val2, &tb);
+            PyErr_NormalizeException(&exc, &val2, &tb);
+            PyException_SetContext(val2, val);
+            PyErr_Restore(exc, val2, tb);
+        }
+    }
 
     if (!result || f->f_stacktop == NULL) {
         /* generator can't be rerun, so release the frame */
History
Date User Action Args
2014-11-29 08:17:24scodersetrecipients: + scoder, gvanrossum, rhettinger, belopolsky, vstinner, r.david.murray, python-dev, schlamar, Rosuav, serhiy.storchaka
2014-11-29 08:17:24scodersetmessageid: <1417249044.51.0.129824816768.issue22906@psf.upfronthosting.co.za>
2014-11-29 08:17:24scoderlinkissue22906 messages
2014-11-29 08:17:24scodercreate