diff Python/compile.c @ 18228:4ebd292c975f legacy-trunk

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].
author Tim Peters <tim.peters@gmail.com>
date Sat, 23 Jun 2001 02:07:08 +0000
parents 7bc473b2c654
children 47717e5667eb
line wrap: on
line diff
--- a/Python/compile.c	Fri Jun 22 18:36:07 2001 +0000
+++ b/Python/compile.c	Sat Jun 23 02:07:08 2001 +0000
@@ -2659,10 +2659,20 @@
 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);