diff options
author | Brandt Bucher <brandtbucher@microsoft.com> | 2023-11-07 00:42:49 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-07 00:42:49 (GMT) |
commit | 3e99c9cbf67225ec1d3bb6af812e883f19ef53de (patch) | |
tree | c838f4942faae9d6e8baa43159f4828b1cde5746 /Python | |
parent | d4426e8d001cfb4590911e2e7de6963e12529faf (diff) | |
download | cpython-3e99c9cbf67225ec1d3bb6af812e883f19ef53de.zip cpython-3e99c9cbf67225ec1d3bb6af812e883f19ef53de.tar.gz cpython-3e99c9cbf67225ec1d3bb6af812e883f19ef53de.tar.bz2 |
GH-111485: Make BEFORE_WITH a uop (GH-111812)
Diffstat (limited to 'Python')
-rw-r--r-- | Python/abstract_interp_cases.c.h | 7 | ||||
-rw-r--r-- | Python/bytecodes.c | 5 | ||||
-rw-r--r-- | Python/executor_cases.c.h | 45 | ||||
-rw-r--r-- | Python/generated_cases.c.h | 5 |
4 files changed, 55 insertions, 7 deletions
diff --git a/Python/abstract_interp_cases.c.h b/Python/abstract_interp_cases.c.h index 0e58ed1..c80b5ec 100644 --- a/Python/abstract_interp_cases.c.h +++ b/Python/abstract_interp_cases.c.h @@ -683,6 +683,13 @@ break; } + case BEFORE_WITH: { + STACK_GROW(1); + PARTITIONNODE_OVERWRITE((_Py_PARTITIONNODE_t *)PARTITIONNODE_NULLROOT, PEEK(-(-2)), true); + PARTITIONNODE_OVERWRITE((_Py_PARTITIONNODE_t *)PARTITIONNODE_NULLROOT, PEEK(-(-1)), true); + break; + } + case WITH_EXCEPT_START: { STACK_GROW(1); PARTITIONNODE_OVERWRITE((_Py_PARTITIONNODE_t *)PARTITIONNODE_NULLROOT, PEEK(-(-1)), true); diff --git a/Python/bytecodes.c b/Python/bytecodes.c index f487e95..7c8ee7b 100644 --- a/Python/bytecodes.c +++ b/Python/bytecodes.c @@ -2765,7 +2765,7 @@ dummy_func( GOTO_ERROR(error); } DECREF_INPUTS(); - res = _PyObject_CallNoArgs(enter); + res = _PyObject_CallNoArgsTstate(tstate, enter); Py_DECREF(enter); if (res == NULL) { Py_DECREF(exit); @@ -2774,7 +2774,6 @@ dummy_func( } inst(BEFORE_WITH, (mgr -- exit, res)) { - TIER_ONE_ONLY /* pop the context manager, push its __exit__ and the * value returned from calling its __enter__ */ @@ -2801,7 +2800,7 @@ dummy_func( GOTO_ERROR(error); } DECREF_INPUTS(); - res = _PyObject_CallNoArgs(enter); + res = _PyObject_CallNoArgsTstate(tstate, enter); Py_DECREF(enter); if (res == NULL) { Py_DECREF(exit); diff --git a/Python/executor_cases.c.h b/Python/executor_cases.c.h index eb56c34..df7ddf2 100644 --- a/Python/executor_cases.c.h +++ b/Python/executor_cases.c.h @@ -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); diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h index 12e4f52..1c85304 100644 --- a/Python/generated_cases.c.h +++ b/Python/generated_cases.c.h @@ -3967,7 +3967,7 @@ GOTO_ERROR(error); } Py_DECREF(mgr); - res = _PyObject_CallNoArgs(enter); + res = _PyObject_CallNoArgsTstate(tstate, enter); Py_DECREF(enter); if (res == NULL) { Py_DECREF(exit); @@ -3987,7 +3987,6 @@ PyObject *exit; PyObject *res; mgr = stack_pointer[-1]; - TIER_ONE_ONLY /* pop the context manager, push its __exit__ and the * value returned from calling its __enter__ */ @@ -4014,7 +4013,7 @@ GOTO_ERROR(error); } Py_DECREF(mgr); - res = _PyObject_CallNoArgs(enter); + res = _PyObject_CallNoArgsTstate(tstate, enter); Py_DECREF(enter); if (res == NULL) { Py_DECREF(exit); |