mirror of
https://github.com/python/cpython.git
synced 2025-07-09 20:35:26 +00:00
GH-111485: Make BEFORE_WITH a uop (GH-111812)
This commit is contained in:
parent
d4426e8d00
commit
3e99c9cbf6
5 changed files with 56 additions and 7 deletions
45
Python/executor_cases.c.h
generated
45
Python/executor_cases.c.h
generated
|
@ -2304,7 +2304,50 @@
|
|||
GOTO_ERROR(error);
|
||||
}
|
||||
Py_DECREF(mgr);
|
||||
res = _PyObject_CallNoArgs(enter);
|
||||
res = _PyObject_CallNoArgsTstate(tstate, enter);
|
||||
Py_DECREF(enter);
|
||||
if (res == NULL) {
|
||||
Py_DECREF(exit);
|
||||
if (true) goto pop_1_error_tier_two;
|
||||
}
|
||||
STACK_GROW(1);
|
||||
stack_pointer[-2] = exit;
|
||||
stack_pointer[-1] = res;
|
||||
break;
|
||||
}
|
||||
|
||||
case BEFORE_WITH: {
|
||||
PyObject *mgr;
|
||||
PyObject *exit;
|
||||
PyObject *res;
|
||||
mgr = stack_pointer[-1];
|
||||
/* pop the context manager, push its __exit__ and the
|
||||
* value returned from calling its __enter__
|
||||
*/
|
||||
PyObject *enter = _PyObject_LookupSpecial(mgr, &_Py_ID(__enter__));
|
||||
if (enter == NULL) {
|
||||
if (!_PyErr_Occurred(tstate)) {
|
||||
_PyErr_Format(tstate, PyExc_TypeError,
|
||||
"'%.200s' object does not support the "
|
||||
"context manager protocol",
|
||||
Py_TYPE(mgr)->tp_name);
|
||||
}
|
||||
GOTO_ERROR(error);
|
||||
}
|
||||
exit = _PyObject_LookupSpecial(mgr, &_Py_ID(__exit__));
|
||||
if (exit == NULL) {
|
||||
if (!_PyErr_Occurred(tstate)) {
|
||||
_PyErr_Format(tstate, PyExc_TypeError,
|
||||
"'%.200s' object does not support the "
|
||||
"context manager protocol "
|
||||
"(missed __exit__ method)",
|
||||
Py_TYPE(mgr)->tp_name);
|
||||
}
|
||||
Py_DECREF(enter);
|
||||
GOTO_ERROR(error);
|
||||
}
|
||||
Py_DECREF(mgr);
|
||||
res = _PyObject_CallNoArgsTstate(tstate, enter);
|
||||
Py_DECREF(enter);
|
||||
if (res == NULL) {
|
||||
Py_DECREF(exit);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue