]> granicus.if.org Git - python/commitdiff
Fix issue 26287: While handling FORMAT_VALUE opcode, the top of stack was being corru...
authorEric V. Smith <eric@trueblade.com>
Fri, 5 Feb 2016 23:23:08 +0000 (18:23 -0500)
committerEric V. Smith <eric@trueblade.com>
Fri, 5 Feb 2016 23:23:08 +0000 (18:23 -0500)
Lib/test/test_fstring.py
Python/ceval.c

index d6f781c846e28dcf7acea1e11a48f99799ac5d45..a82dedffe4b32a9d8ef09309636a60e4a4346866 100644 (file)
@@ -692,6 +692,17 @@ f'{a * x()}'"""
                              r"f'{a(4]}'",
                             ])
 
+    def test_errors(self):
+        # see issue 26287
+        self.assertAllRaise(TypeError, 'non-empty',
+                            [r"f'{(lambda: 0):x}'",
+                             r"f'{(0,):x}'",
+                             ])
+        self.assertAllRaise(ValueError, 'Unknown format code',
+                            [r"f'{1000:j}'",
+                             r"f'{1000:j}'",
+                            ])
+
     def test_loop(self):
         for i in range(1000):
             self.assertEqual(f'i:{i}', 'i:' + str(i))
index 743a969f6bfebaa4d2e391a0e44d9baf07231679..b815ccd9d0a97391df61283b38b77b15873480d2 100644 (file)
@@ -3383,7 +3383,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
             int have_fmt_spec = (oparg & FVS_MASK) == FVS_HAVE_SPEC;
 
             fmt_spec = have_fmt_spec ? POP() : NULL;
-            value = TOP();
+            value = POP();
 
             /* See if any conversion is specified. */
             switch (which_conversion) {
@@ -3426,7 +3426,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
                     goto error;
             }
 
-            SET_TOP(result);
+            PUSH(result);
             DISPATCH();
         }