Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1253)

Unified Diff: Python/ceval.c

Issue 11682: PEP 380 reference implementation for 3.3
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« Objects/exceptions.c ('K') | « Python/ast.c ('k') | Python/compile.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Python/ceval.c Thu Jan 12 08:06:49 2012 +0100
+++ b/Python/ceval.c Fri Jan 13 00:26:31 2012 +1000
@@ -1828,6 +1828,52 @@
why = WHY_RETURN;
goto fast_block_end;
+ TARGET(YIELD_FROM)
+ u = POP();
+ x = PyObject_GetIter(u);
+ Py_DECREF(u);
+ if (x == NULL)
+ break;
+ /* x is now the iterator, make the first next() call */
+ retval = (*Py_TYPE(x)->tp_iternext)(x);
+ if (!retval) {
+ /* iter may be exhausted */
+ Py_CLEAR(x);
+ if (!PyErr_ExceptionMatches(PyExc_StopIteration)) {
+ /* some other exception */
+ break;
+ }
+ /* try to get return value from exception */
+ PyObject *et, *ev, *tb;
+ PyErr_Fetch(&et, &ev, &tb);
+ Py_XDECREF(et);
+ Py_XDECREF(tb);
+ /* u is return value */
+ u = NULL;
+ if (ev) {
+ u = PyObject_GetAttrString(ev, "value");
+ Py_DECREF(ev);
+ if (u == NULL) {
+ if (!PyErr_ExceptionMatches(PyExc_AttributeError)) {
+ /* some other exception */
+ break;
+ }
+ PyErr_Clear();
+ }
+ }
+ if (u == NULL) {
+ u = Py_None;
+ Py_INCREF(u);
+ }
+ PUSH(u);
+ continue;
+ }
+ /* x is iterator, retval is value to be yielded */
+ f->f_yieldfrom = x;
+ f->f_stacktop = stack_pointer;
+ why = WHY_YIELD;
+ goto fast_yield;
+
TARGET(YIELD_VALUE)
retval = POP();
f->f_stacktop = stack_pointer;
« Objects/exceptions.c ('K') | « Python/ast.c ('k') | Python/compile.c » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+