]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Backport:
authorGuido van Rossum <guido@python.org>
Wed, 12 Jun 2002 03:48:46 +0000 (03:48 +0000)
committerGuido van Rossum <guido@python.org>
Wed, 12 Jun 2002 03:48:46 +0000 (03:48 +0000)
SF bug 567538: Generator can crash the interpreter (Finn Bock).

This was a simple typo.  Strange that the compiler didn't catch it!
Instead of WHY_CONTINUE, two tests used CONTINUE_LOOP, which isn't a
why_code at all, but an opcode; but even though 'why' is declared as
an enum, comparing it to an int is apparently not even worth a
warning -- not in gcc, and not in VC++. :-(

Lib/test/test_generators.py
Misc/NEWS
Python/ceval.c

index 2c319e5db982901f4dee8df50a4faa4942af12f1..410f043fd363a1ca2c8ad6a5082d36f02c5bc943 100644 (file)
@@ -807,6 +807,26 @@ SyntaxError: invalid syntax
 ...         yield 2             # because it's a generator
 Traceback (most recent call last):
 SyntaxError: 'return' with argument inside generator (<string>, line 8)
+
+This one caused a crash (see SF bug 567538):
+
+>>> def f():
+...     for i in range(3):
+...         try:
+...             continue
+...         finally:
+...             yield i
+... 
+>>> g = f()
+>>> print g.next()
+0
+>>> print g.next()
+1
+>>> print g.next()
+2
+>>> print g.next()
+Traceback (most recent call last):
+StopIteration
 """
 
 # conjoin is a simple backtracking generator, named in honor of Icon's
index 1e81675ba43c055473ead39231409e84bfa78841..cf5f9e1fdc5779e2cddbb9a0a6bfac1d93e71255 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -4,6 +4,9 @@ Release date: dd-mmm-2002
 
 Core and builtins
 
+- Fixed a bug with a continue inside a try block and a yield in the
+  finally clause.  [SF bug 567538]
+
 - Cycles going through the __class__ link of a new-style instance are
   now detected by the garbage collector.
 
index 0fa58877819122a5a77399a9b797f18186e1ce20..914431afb18344aeb8fe6d4ce626c3a394ab2f6c 100644 (file)
@@ -1497,7 +1497,7 @@ eval_frame(PyFrameObject *f)
                                why = (enum why_code) PyInt_AsLong(v);
                                if (why == WHY_RETURN ||
                                    why == WHY_YIELD ||
-                                   why == CONTINUE_LOOP)
+                                   why == WHY_CONTINUE)
                                        retval = POP();
                        }
                        else if (PyString_Check(v) || PyClass_Check(v)) {
@@ -2293,7 +2293,7 @@ eval_frame(PyFrameObject *f)
                                }
                                else {
                                        if (why == WHY_RETURN ||
-                                           why == CONTINUE_LOOP)
+                                           why == WHY_CONTINUE)
                                                PUSH(retval);
                                        v = PyInt_FromLong((long)why);
                                        PUSH(v);