]> granicus.if.org Git - python/commitdiff
SF bug 567538: Generator can crash the interpreter (Finn Bock).
authorGuido van Rossum <guido@python.org>
Wed, 12 Jun 2002 03:45:21 +0000 (03:45 +0000)
committerGuido van Rossum <guido@python.org>
Wed, 12 Jun 2002 03:45:21 +0000 (03:45 +0000)
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++. :-(

Will fix in 2.2 too.

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

index 77c477fe35a20240f2af1dae22bc08b898d23e35..17523ba71c92c1688ed69429bb59af1d9c917beb 100644 (file)
@@ -805,6 +805,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 9c51c1f0608d72ac5e92c044026f3deb43bb0737..aef5a24b2fa34932110d83b1ea21eceed0bf87de 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -6,6 +6,9 @@ Type/class unification and new-style classes
 
 Core and builtins
 
+- Fixed a bug with a continue inside a try block and a yield in the
+  finally clause.  [SF bug 567538]
+
 - Most builtin sequences now support "extended slices", i.e. slices
   with a third "stride" parameter.  For example, "range(10)[1:6:2]"
   evaluates to [1, 3, 5].
index fd30e8f3312731a3c4330823953b63da9a639d4d..b9c0d5d3b32470e976f444aa18c0f20486c06e1e 100644 (file)
@@ -1543,7 +1543,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);