mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	gh-109118: Fix runtime crash when NameError happens in PEP 695 function (#109123)
This commit is contained in:
		
							parent
							
								
									e9e2ca7a7b
								
							
						
					
					
						commit
						17f994174d
					
				
					 7 changed files with 203 additions and 120 deletions
				
			
		
							
								
								
									
										89
									
								
								Python/generated_cases.c.h
									
										
									
										generated
									
									
									
								
							
							
						
						
									
										89
									
								
								Python/generated_cases.c.h
									
										
									
										generated
									
									
									
								
							|  | @ -1675,65 +1675,14 @@ | |||
|             DISPATCH(); | ||||
|         } | ||||
| 
 | ||||
|         TARGET(LOAD_NAME) { | ||||
|             PyObject *locals; | ||||
|             PyObject *mod_or_class_dict; | ||||
|             PyObject *v; | ||||
|             // _LOAD_LOCALS
 | ||||
|             { | ||||
|                 locals = LOCALS(); | ||||
|                 if (locals == NULL) { | ||||
|                     _PyErr_SetString(tstate, PyExc_SystemError, | ||||
|                                      "no locals found"); | ||||
|                     if (true) goto error; | ||||
|                 } | ||||
|                 Py_INCREF(locals); | ||||
|             } | ||||
|             // _LOAD_FROM_DICT_OR_GLOBALS
 | ||||
|             mod_or_class_dict = locals; | ||||
|             { | ||||
|                 PyObject *name = GETITEM(FRAME_CO_NAMES, oparg); | ||||
|                 if (PyMapping_GetOptionalItem(mod_or_class_dict, name, &v) < 0) { | ||||
|                     Py_DECREF(mod_or_class_dict); | ||||
|                     goto error; | ||||
|                 } | ||||
|                 Py_DECREF(mod_or_class_dict); | ||||
|                 if (v == NULL) { | ||||
|                     v = PyDict_GetItemWithError(GLOBALS(), name); | ||||
|                     if (v != NULL) { | ||||
|                         Py_INCREF(v); | ||||
|                     } | ||||
|                     else if (_PyErr_Occurred(tstate)) { | ||||
|                         goto error; | ||||
|                     } | ||||
|                     else { | ||||
|                         if (PyMapping_GetOptionalItem(BUILTINS(), name, &v) < 0) { | ||||
|                             goto error; | ||||
|                         } | ||||
|                         if (v == NULL) { | ||||
|                             _PyEval_FormatExcCheckArg( | ||||
|                                         tstate, PyExc_NameError, | ||||
|                                         NAME_ERROR_MSG, name); | ||||
|                             goto error; | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|             STACK_GROW(1); | ||||
|             stack_pointer[-1] = v; | ||||
|             DISPATCH(); | ||||
|         } | ||||
| 
 | ||||
|         TARGET(LOAD_FROM_DICT_OR_GLOBALS) { | ||||
|             PyObject *mod_or_class_dict; | ||||
|             PyObject *v; | ||||
|             mod_or_class_dict = stack_pointer[-1]; | ||||
|             PyObject *name = GETITEM(FRAME_CO_NAMES, oparg); | ||||
|             if (PyMapping_GetOptionalItem(mod_or_class_dict, name, &v) < 0) { | ||||
|                 Py_DECREF(mod_or_class_dict); | ||||
|                 goto error; | ||||
|             } | ||||
|             Py_DECREF(mod_or_class_dict); | ||||
|             if (v == NULL) { | ||||
|                 v = PyDict_GetItemWithError(GLOBALS(), name); | ||||
|                 if (v != NULL) { | ||||
|  | @ -1754,6 +1703,44 @@ | |||
|                     } | ||||
|                 } | ||||
|             } | ||||
|             Py_DECREF(mod_or_class_dict); | ||||
|             stack_pointer[-1] = v; | ||||
|             DISPATCH(); | ||||
|         } | ||||
| 
 | ||||
|         TARGET(LOAD_NAME) { | ||||
|             PyObject *v; | ||||
|             PyObject *mod_or_class_dict = LOCALS(); | ||||
|             if (mod_or_class_dict == NULL) { | ||||
|                 _PyErr_SetString(tstate, PyExc_SystemError, | ||||
|                                  "no locals found"); | ||||
|                 if (true) goto error; | ||||
|             } | ||||
|             PyObject *name = GETITEM(FRAME_CO_NAMES, oparg); | ||||
|             if (PyMapping_GetOptionalItem(mod_or_class_dict, name, &v) < 0) { | ||||
|                 goto error; | ||||
|             } | ||||
|             if (v == NULL) { | ||||
|                 v = PyDict_GetItemWithError(GLOBALS(), name); | ||||
|                 if (v != NULL) { | ||||
|                     Py_INCREF(v); | ||||
|                 } | ||||
|                 else if (_PyErr_Occurred(tstate)) { | ||||
|                     goto error; | ||||
|                 } | ||||
|                 else { | ||||
|                     if (PyMapping_GetOptionalItem(BUILTINS(), name, &v) < 0) { | ||||
|                         goto error; | ||||
|                     } | ||||
|                     if (v == NULL) { | ||||
|                         _PyEval_FormatExcCheckArg( | ||||
|                                     tstate, PyExc_NameError, | ||||
|                                     NAME_ERROR_MSG, name); | ||||
|                         goto error; | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|             STACK_GROW(1); | ||||
|             stack_pointer[-1] = v; | ||||
|             DISPATCH(); | ||||
|         } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Jelle Zijlstra
						Jelle Zijlstra