mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 21:51:50 +00:00 
			
		
		
		
	GH-117224: Move the body of a few large-ish micro-ops into helper functions (GH-122601)
This commit is contained in:
		
							parent
							
								
									498376d7a7
								
							
						
					
					
						commit
						7aca84e557
					
				
					 5 changed files with 163 additions and 335 deletions
				
			
		
							
								
								
									
										117
									
								
								Python/executor_cases.c.h
									
										
									
										generated
									
									
									
								
							
							
						
						
									
										117
									
								
								Python/executor_cases.c.h
									
										
									
										generated
									
									
									
								
							|  | @ -1243,45 +1243,9 @@ | |||
|             _PyStackRef aiter; | ||||
|             _PyStackRef awaitable; | ||||
|             aiter = stack_pointer[-1]; | ||||
|             unaryfunc getter = NULL; | ||||
|             PyObject *next_iter = NULL; | ||||
|             PyObject *awaitable_o; | ||||
|             PyObject *aiter_o = PyStackRef_AsPyObjectBorrow(aiter); | ||||
|             PyTypeObject *type = Py_TYPE(aiter_o); | ||||
|             if (PyAsyncGen_CheckExact(aiter_o)) { | ||||
|                 awaitable_o = type->tp_as_async->am_anext(aiter_o); | ||||
|                 if (awaitable_o == NULL) { | ||||
|                     JUMP_TO_ERROR(); | ||||
|                 } | ||||
|             } else { | ||||
|                 if (type->tp_as_async != NULL){ | ||||
|                     getter = type->tp_as_async->am_anext; | ||||
|                 } | ||||
|                 if (getter != NULL) { | ||||
|                     next_iter = (*getter)(aiter_o); | ||||
|                     if (next_iter == NULL) { | ||||
|                         JUMP_TO_ERROR(); | ||||
|                     } | ||||
|                 } | ||||
|                 else { | ||||
|                     _PyErr_Format(tstate, PyExc_TypeError, | ||||
|                                   "'async for' requires an iterator with " | ||||
|                                   "__anext__ method, got %.100s", | ||||
|                                   type->tp_name); | ||||
|                     JUMP_TO_ERROR(); | ||||
|                 } | ||||
|                 awaitable_o = _PyCoro_GetAwaitableIter(next_iter); | ||||
|                 if (awaitable_o == NULL) { | ||||
|                     _PyErr_FormatFromCause( | ||||
|                         PyExc_TypeError, | ||||
|                         "'async for' received an invalid object " | ||||
|                         "from __anext__: %.100s", | ||||
|                         Py_TYPE(next_iter)->tp_name); | ||||
|                     Py_DECREF(next_iter); | ||||
|                     JUMP_TO_ERROR(); | ||||
|                 } else { | ||||
|                     Py_DECREF(next_iter); | ||||
|                 } | ||||
|             PyObject *awaitable_o = _PyEval_GetANext(PyStackRef_AsPyObjectBorrow(aiter)); | ||||
|             if (awaitable_o == NULL) { | ||||
|                 JUMP_TO_ERROR(); | ||||
|             } | ||||
|             awaitable = PyStackRef_FromPyObjectSteal(awaitable_o); | ||||
|             stack_pointer[0] = awaitable; | ||||
|  | @ -1295,25 +1259,8 @@ | |||
|             _PyStackRef iter; | ||||
|             oparg = CURRENT_OPARG(); | ||||
|             iterable = stack_pointer[-1]; | ||||
|             PyObject *iter_o = _PyCoro_GetAwaitableIter(PyStackRef_AsPyObjectBorrow(iterable)); | ||||
|             if (iter_o == NULL) { | ||||
|                 _PyEval_FormatAwaitableError(tstate, | ||||
|                     Py_TYPE(PyStackRef_AsPyObjectBorrow(iterable)), oparg); | ||||
|             } | ||||
|             PyObject *iter_o = _PyEval_GetAwaitable(PyStackRef_AsPyObjectBorrow(iterable), oparg); | ||||
|             PyStackRef_CLOSE(iterable); | ||||
|             if (iter_o != NULL && PyCoro_CheckExact(iter_o)) { | ||||
|                 PyObject *yf = _PyGen_yf((PyGenObject*)iter_o); | ||||
|                 if (yf != NULL) { | ||||
|                     /* `iter` is a coroutine object that is being
 | ||||
|                        awaited, `yf` is a pointer to the current awaitable | ||||
|                        being awaited on. */ | ||||
|                     Py_DECREF(yf); | ||||
|                     Py_CLEAR(iter_o); | ||||
|                     _PyErr_SetString(tstate, PyExc_RuntimeError, | ||||
|                                      "coroutine is being awaited already"); | ||||
|                     /* The code below jumps to `error` if `iter` is NULL. */ | ||||
|                 } | ||||
|             } | ||||
|             if (iter_o == NULL) JUMP_TO_ERROR(); | ||||
|             iter = PyStackRef_FromPyObjectSteal(iter_o); | ||||
|             stack_pointer[-1] = iter; | ||||
|  | @ -1676,27 +1623,9 @@ | |||
|         case _LOAD_NAME: { | ||||
|             _PyStackRef v; | ||||
|             oparg = CURRENT_OPARG(); | ||||
|             PyObject *v_o; | ||||
|             PyObject *mod_or_class_dict = LOCALS(); | ||||
|             if (mod_or_class_dict == NULL) { | ||||
|                 _PyErr_SetString(tstate, PyExc_SystemError, | ||||
|                                  "no locals found"); | ||||
|                 if (true) JUMP_TO_ERROR(); | ||||
|             } | ||||
|             PyObject *name = GETITEM(FRAME_CO_NAMES, oparg); | ||||
|             if (PyMapping_GetOptionalItem(mod_or_class_dict, name, &v_o) < 0) JUMP_TO_ERROR(); | ||||
|             if (v_o == NULL) { | ||||
|                 if (PyDict_GetItemRef(GLOBALS(), name, &v_o) < 0) JUMP_TO_ERROR(); | ||||
|                 if (v_o == NULL) { | ||||
|                     if (PyMapping_GetOptionalItem(BUILTINS(), name, &v_o) < 0) JUMP_TO_ERROR(); | ||||
|                     if (v_o == NULL) { | ||||
|                         _PyEval_FormatExcCheckArg( | ||||
|                             tstate, PyExc_NameError, | ||||
|                             NAME_ERROR_MSG, name); | ||||
|                         if (true) JUMP_TO_ERROR(); | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|             PyObject *v_o = _PyEval_LoadName(tstate, frame, name); | ||||
|             if (v_o == NULL) JUMP_TO_ERROR(); | ||||
|             v = PyStackRef_FromPyObjectSteal(v_o); | ||||
|             stack_pointer[0] = v; | ||||
|             stack_pointer += 1; | ||||
|  | @ -1709,38 +1638,8 @@ | |||
|             _PyStackRef null = PyStackRef_NULL; | ||||
|             oparg = CURRENT_OPARG(); | ||||
|             PyObject *name = GETITEM(FRAME_CO_NAMES, oparg>>1); | ||||
|             PyObject *res_o; | ||||
|             if (PyDict_CheckExact(GLOBALS()) | ||||
|                 && PyDict_CheckExact(BUILTINS())) | ||||
|             { | ||||
|                 res_o = _PyDict_LoadGlobal((PyDictObject *)GLOBALS(), | ||||
|                     (PyDictObject *)BUILTINS(), | ||||
|                     name); | ||||
|                 if (res_o == NULL) { | ||||
|                     if (!_PyErr_Occurred(tstate)) { | ||||
|                         /* _PyDict_LoadGlobal() returns NULL without raising
 | ||||
|                          * an exception if the key doesn't exist */ | ||||
|                         _PyEval_FormatExcCheckArg(tstate, PyExc_NameError, | ||||
|                             NAME_ERROR_MSG, name); | ||||
|                     } | ||||
|                     if (true) JUMP_TO_ERROR(); | ||||
|                 } | ||||
|             } | ||||
|             else { | ||||
|                 /* Slow-path if globals or builtins is not a dict */ | ||||
|                 /* namespace 1: globals */ | ||||
|                 if (PyMapping_GetOptionalItem(GLOBALS(), name, &res_o) < 0) JUMP_TO_ERROR(); | ||||
|                 if (res_o == NULL) { | ||||
|                     /* namespace 2: builtins */ | ||||
|                     if (PyMapping_GetOptionalItem(BUILTINS(), name, &res_o) < 0) JUMP_TO_ERROR(); | ||||
|                     if (res_o == NULL) { | ||||
|                         _PyEval_FormatExcCheckArg( | ||||
|                             tstate, PyExc_NameError, | ||||
|                             NAME_ERROR_MSG, name); | ||||
|                         if (true) JUMP_TO_ERROR(); | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|             PyObject *res_o = _PyEval_LoadGlobal(GLOBALS(), BUILTINS(), name); | ||||
|             if (res_o == NULL) JUMP_TO_ERROR(); | ||||
|             null = PyStackRef_NULL; | ||||
|             res = PyStackRef_FromPyObjectSteal(res_o); | ||||
|             stack_pointer[0] = res; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Mark Shannon
						Mark Shannon