summaryrefslogtreecommitdiffstats
path: root/Python/compile.c
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2001-06-23 02:07:08 (GMT)
committerTim Peters <tim.peters@gmail.com>2001-06-23 02:07:08 (GMT)
commit95c80f84392e6fb2a023542a0a4a50dfe3298cc2 (patch)
treeee3a0dcb30c7faf07acd213f202cf8f9822954bd /Python/compile.c
parent1bf198e946a10eb34d6e2a8a5beccb67c88ab7d6 (diff)
downloadcpython-95c80f84392e6fb2a023542a0a4a50dfe3298cc2.zip
cpython-95c80f84392e6fb2a023542a0a4a50dfe3298cc2.tar.gz
cpython-95c80f84392e6fb2a023542a0a4a50dfe3298cc2.tar.bz2
Disallow 'yield' in a 'try' block when there's a 'finally' clause.
Derived from Thomas Wouters's patch on the Iterators list, but doesn't try to read c->c_block[c->c_nblocks].
Diffstat (limited to 'Python/compile.c')
-rw-r--r--Python/compile.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/Python/compile.c b/Python/compile.c
index 6c13bb9..843cf09 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -2659,10 +2659,20 @@ com_return_stmt(struct compiling *c, node *n)
static void
com_yield_stmt(struct compiling *c, node *n)
{
+ int i;
REQ(n, yield_stmt); /* 'yield' testlist */
if (!c->c_infunction) {
com_error(c, PyExc_SyntaxError, "'yield' outside function");
}
+
+ for (i = 0; i < c->c_nblocks; ++i) {
+ if (c->c_block[i] == SETUP_FINALLY) {
+ com_error(c, PyExc_SyntaxError,
+ "'yield' not allowed in a 'try' block "
+ "with a 'finally' clause");
+ return;
+ }
+ }
com_node(c, CHILD(n, 1));
com_addbyte(c, YIELD_VALUE);
com_pop(c, 1);