Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ed6de73

Browse files
committed
Merge 3.6
2 parents fbff9b3 + f7d199f commit ed6de73

3 files changed

Lines changed: 14 additions & 0 deletions

File tree

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ What's New in Python 3.7.0 alpha 1
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #28782: Fix a bug in the implementation ``yield from`` when checking
14+
if the next instruction is YIELD_FROM. Regression introduced by WORDCODE
15+
(issue #26647).
16+
1317
- Issue #28774: Fix error position of the unicode error in ASCII and Latin1
1418
encoders when a string returned by the error handler contains multiple
1519
non-encodable characters (non-ASCII for the ASCII codec, characters out

Objects/genobject.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,14 @@ _PyGen_yf(PyGenObject *gen)
355355
PyObject *bytecode = f->f_code->co_code;
356356
unsigned char *code = (unsigned char *)PyBytes_AS_STRING(bytecode);
357357

358+
if (f->f_lasti < 0) {
359+
/* Return immediately if the frame didn't start yet. YIELD_FROM
360+
always come after LOAD_CONST: a code object should not start
361+
with YIELD_FROM */
362+
assert(code[0] != YIELD_FROM);
363+
return NULL;
364+
}
365+
358366
if (code[f->f_lasti + sizeof(_Py_CODEUNIT)] != YIELD_FROM)
359367
return NULL;
360368
yf = f->f_stacktop[-1];
@@ -463,6 +471,7 @@ _gen_throw(PyGenObject *gen, int close_on_genexit,
463471
assert(ret == yf);
464472
Py_DECREF(ret);
465473
/* Termination repetition of YIELD_FROM */
474+
assert(gen->gi_frame->f_lasti >= 0);
466475
gen->gi_frame->f_lasti += sizeof(_Py_CODEUNIT);
467476
if (_PyGen_FetchStopIterationValue(&val) == 0) {
468477
ret = gen_send_ex(gen, val, 0, 0);

Python/ceval.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2049,6 +2049,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
20492049
f->f_stacktop = stack_pointer;
20502050
why = WHY_YIELD;
20512051
/* and repeat... */
2052+
assert(f->f_lasti >= (int)sizeof(_Py_CODEUNIT));
20522053
f->f_lasti -= sizeof(_Py_CODEUNIT);
20532054
goto fast_yield;
20542055
}

0 commit comments

Comments
 (0)