mirror of
				https://github.com/python/cpython.git
				synced 2025-10-25 02:43:41 +00:00 
			
		
		
		
	[3.13] gh-132011: Fix crash on invalid CALL_LIST_APPEND deoptimization (GH-132018) (#132161)
				
					
				
			* [3.13] gh-132011: Fix crash on invalid `CALL_LIST_APPEND` deoptimization (GH-132018)
(cherry picked from commit c0661df42a)
Co-authored-by: sobolevn <mail@sobolevn.me>
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
			
			
This commit is contained in:
		
							parent
							
								
									83070aa108
								
							
						
					
					
						commit
						5fb9fe0e3e
					
				
					 4 changed files with 25 additions and 2 deletions
				
			
		|  | @ -1,6 +1,8 @@ | |||
| import sys | ||||
| import textwrap | ||||
| from test import list_tests | ||||
| from test.support import cpython_only | ||||
| from test.support.script_helper import assert_python_ok | ||||
| import pickle | ||||
| import unittest | ||||
| 
 | ||||
|  | @ -309,5 +311,25 @@ def test_tier2_invalidates_iterator(self): | |||
|             a.append(4) | ||||
|             self.assertEqual(list(it), []) | ||||
| 
 | ||||
|     def test_deopt_from_append_list(self): | ||||
|         # gh-132011: it used to crash, because | ||||
|         # of `CALL_LIST_APPEND` specialization failure. | ||||
|         code = textwrap.dedent(""" | ||||
|             l = [] | ||||
|             def lappend(l, x, y): | ||||
|                 l.append((x, y)) | ||||
|             for x in range(3): | ||||
|                 lappend(l, None, None) | ||||
|             try: | ||||
|                 lappend(list, None, None) | ||||
|             except TypeError: | ||||
|                 pass | ||||
|             else: | ||||
|                 raise AssertionError | ||||
|         """) | ||||
| 
 | ||||
|         rc, _, _ = assert_python_ok("-c", code) | ||||
|         self.assertEqual(rc, 0) | ||||
| 
 | ||||
| if __name__ == "__main__": | ||||
|     unittest.main() | ||||
|  |  | |||
|  | @ -0,0 +1 @@ | |||
| Fix crash when calling :meth:`!list.append` as an unbound method. | ||||
|  | @ -3631,7 +3631,7 @@ dummy_func( | |||
|             assert(oparg == 1); | ||||
|             PyInterpreterState *interp = tstate->interp; | ||||
|             DEOPT_IF(callable != interp->callable_cache.list_append); | ||||
|             assert(self != NULL); | ||||
|             DEOPT_IF(self == NULL); | ||||
|             DEOPT_IF(!PyList_Check(self)); | ||||
|             STAT_INC(CALL, hit); | ||||
|             if (_PyList_AppendTakeRef((PyListObject *)self, arg) < 0) { | ||||
|  |  | |||
							
								
								
									
										2
									
								
								Python/generated_cases.c.h
									
										
									
										generated
									
									
									
								
							
							
						
						
									
										2
									
								
								Python/generated_cases.c.h
									
										
									
										generated
									
									
									
								
							|  | @ -1590,7 +1590,7 @@ | |||
|             assert(oparg == 1); | ||||
|             PyInterpreterState *interp = tstate->interp; | ||||
|             DEOPT_IF(callable != interp->callable_cache.list_append, CALL); | ||||
|             assert(self != NULL); | ||||
|             DEOPT_IF(self == NULL, CALL); | ||||
|             DEOPT_IF(!PyList_Check(self), CALL); | ||||
|             STAT_INC(CALL, hit); | ||||
|             if (_PyList_AppendTakeRef((PyListObject *)self, arg) < 0) { | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 sobolevn
						sobolevn