mirror of
				https://github.com/python/cpython.git
				synced 2025-10-27 03:34:32 +00:00 
			
		
		
		
	Fix issue 26287: While handling FORMAT_VALUE opcode, the top of stack was being corrupted if an error occurred in PyObject_Format().
This commit is contained in:
		
							parent
							
								
									a3643c280f
								
							
						
					
					
						commit
						135d5f49f6
					
				
					 2 changed files with 13 additions and 2 deletions
				
			
		|  | @ -692,6 +692,17 @@ def test_invalid_expressions(self): | ||||||
|                              r"f'{a(4]}'", |                              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): |     def test_loop(self): | ||||||
|         for i in range(1000): |         for i in range(1000): | ||||||
|             self.assertEqual(f'i:{i}', 'i:' + str(i)) |             self.assertEqual(f'i:{i}', 'i:' + str(i)) | ||||||
|  |  | ||||||
|  | @ -3383,7 +3383,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag) | ||||||
|             int have_fmt_spec = (oparg & FVS_MASK) == FVS_HAVE_SPEC; |             int have_fmt_spec = (oparg & FVS_MASK) == FVS_HAVE_SPEC; | ||||||
| 
 | 
 | ||||||
|             fmt_spec = have_fmt_spec ? POP() : NULL; |             fmt_spec = have_fmt_spec ? POP() : NULL; | ||||||
|             value = TOP(); |             value = POP(); | ||||||
| 
 | 
 | ||||||
|             /* See if any conversion is specified. */ |             /* See if any conversion is specified. */ | ||||||
|             switch (which_conversion) { |             switch (which_conversion) { | ||||||
|  | @ -3426,7 +3426,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag) | ||||||
|                     goto error; |                     goto error; | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             SET_TOP(result); |             PUSH(result); | ||||||
|             DISPATCH(); |             DISPATCH(); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Eric V. Smith
						Eric V. Smith