aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2024-06-12 18:41:33 +0200
committerMichał Górny <mgorny@gentoo.org>2024-06-12 18:41:33 +0200
commit9a447185dcf476dd25417267d99f30a86e1ecbb3 (patch)
tree6782ae7a621a8b675e27a2fab1257c9f487d3b8d
parenttest_lzma: Skip tests requiring extra-filters (diff)
downloadcpython-gentoo-3.12.4_p1.tar.gz
cpython-gentoo-3.12.4_p1.tar.bz2
cpython-gentoo-3.12.4_p1.zip
Revert "[3.12] gh-100762: Fix optimization in gen_close (GH-111069) (#115818)"gentoo-3.12.4_p1
This reverts commit eb4774d2b7f5d50cd3cb8dc5abce9f94ce54197e. Bug: https://github.com/python/cpython/issues/119897
-rw-r--r--Lib/test/test_cprofile.py4
-rw-r--r--Lib/test/test_sys_setprofile.py4
-rw-r--r--Objects/genobject.c5
3 files changed, 8 insertions, 5 deletions
diff --git a/Lib/test/test_cprofile.py b/Lib/test/test_cprofile.py
index 27e8a767903..3056fe84dac 100644
--- a/Lib/test/test_cprofile.py
+++ b/Lib/test/test_cprofile.py
@@ -83,8 +83,8 @@ class CProfileTest(ProfileTest):
for func, (cc, nc, _, _, _) in pr.stats.items():
if func[2] == "<genexpr>":
- self.assertEqual(cc, 1)
- self.assertEqual(nc, 1)
+ self.assertEqual(cc, 2)
+ self.assertEqual(nc, 2)
class TestCommandLine(unittest.TestCase):
diff --git a/Lib/test/test_sys_setprofile.py b/Lib/test/test_sys_setprofile.py
index bb8adc8b555..9e8936630de 100644
--- a/Lib/test/test_sys_setprofile.py
+++ b/Lib/test/test_sys_setprofile.py
@@ -267,6 +267,10 @@ class ProfileHookTestCase(TestCaseBase):
self.check_events(g, [(1, 'call', g_ident),
(2, 'call', f_ident),
(2, 'return', f_ident),
+ # once more; the generator is being garbage collected
+ # and it will do a PY_THROW
+ (2, 'call', f_ident),
+ (2, 'return', f_ident),
(1, 'return', g_ident),
])
diff --git a/Objects/genobject.c b/Objects/genobject.c
index dc034a4b723..98d24b9acf4 100644
--- a/Objects/genobject.c
+++ b/Objects/genobject.c
@@ -374,6 +374,7 @@ static PyObject *
gen_close(PyGenObject *gen, PyObject *args)
{
PyObject *retval;
+ PyObject *yf = _PyGen_yf(gen);
int err = 0;
if (gen->gi_frame_state == FRAME_CREATED) {
@@ -383,7 +384,6 @@ gen_close(PyGenObject *gen, PyObject *args)
if (gen->gi_frame_state >= FRAME_COMPLETED) {
Py_RETURN_NONE;
}
- PyObject *yf = _PyGen_yf(gen);
if (yf) {
PyFrameState state = gen->gi_frame_state;
gen->gi_frame_state = FRAME_EXECUTING;
@@ -396,13 +396,12 @@ gen_close(PyGenObject *gen, PyObject *args)
* YIELD_VALUE if the debugger has changed the lineno. */
if (err == 0 && is_yield(frame->prev_instr)) {
assert(is_resume(frame->prev_instr + 1));
- int exception_handler_depth = frame->prev_instr[0].op.arg;
+ int exception_handler_depth = frame->prev_instr[0].op.code;
assert(exception_handler_depth > 0);
/* We can safely ignore the outermost try block
* as it automatically generated to handle
* StopIteration. */
if (exception_handler_depth == 1) {
- gen->gi_frame_state = FRAME_COMPLETED;
_PyFrame_ClearLocals((_PyInterpreterFrame *)gen->gi_iframe);
Py_RETURN_NONE;
}