From a6e489daf5b04a859c1df60b63694123316b58fc Mon Sep 17 00:00:00 2001 From: Mark Shannon Date: Mon, 31 Aug 2020 11:24:42 +0100 Subject: [PATCH 1/6] Remove PREDICTion of POP_BLOCK from FOR_ITER. Partial fix for https://bugs.python.org/issue41670. --- Python/ceval.c | 1 - 1 file changed, 1 deletion(-) diff --git a/Python/ceval.c b/Python/ceval.c index f747faaebf024a..99aa7861edede3 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -3352,7 +3352,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, PyFrameObject *f, int throwflag) STACK_SHRINK(1); Py_DECREF(iter); JUMPBY(oparg); - PREDICT(POP_BLOCK); DISPATCH(); } From d95771f5ad7fa32efdc23d0f41b5fe1e73e14d1b Mon Sep 17 00:00:00 2001 From: Mark Shannon Date: Mon, 31 Aug 2020 11:33:32 +0100 Subject: [PATCH 2/6] Add test for https://bugs.python.org/issue41670. --- Lib/test/test_sys_settrace.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Lib/test/test_sys_settrace.py b/Lib/test/test_sys_settrace.py index 3f902b1fe74ce8..dd4418dd98b22a 100644 --- a/Lib/test/test_sys_settrace.py +++ b/Lib/test/test_sys_settrace.py @@ -602,6 +602,23 @@ def run(tracer): self.compare_events(doit_async.__code__.co_firstlineno, tracer.events, events) + def test_loop_in_try_except(self): + # https://bugs.python.org/issue41670 + + def func(): + try: + for i in []: pass + return 1 + except: + return 2 + + self.run_and_compare(func, + [(0, 'call'), + (1, 'line'), + (2, 'line'), + (3, 'line'), + (3, 'return')]) + class SkipLineEventsTraceTestCase(TraceTestCase): """Repeat the trace tests, but with per-line events skipped""" From 0c8177d1032919c8346af18d59c351cc2a69fbb6 Mon Sep 17 00:00:00 2001 From: Mark Shannon Date: Mon, 31 Aug 2020 11:38:18 +0100 Subject: [PATCH 3/6] Add news --- .../Core and Builtins/2020-08-31-11-37-59.bpo-41670.vmRJRx.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2020-08-31-11-37-59.bpo-41670.vmRJRx.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-08-31-11-37-59.bpo-41670.vmRJRx.rst b/Misc/NEWS.d/next/Core and Builtins/2020-08-31-11-37-59.bpo-41670.vmRJRx.rst new file mode 100644 index 00000000000000..4e49de63326464 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-08-31-11-37-59.bpo-41670.vmRJRx.rst @@ -0,0 +1,2 @@ +Prevent line trace being skipped on Windows and Mac when a for loop is +nexted within a try-except block. From 8e99b2151c6f35cd34b64530da7b722630b514be Mon Sep 17 00:00:00 2001 From: Mark Shannon Date: Mon, 31 Aug 2020 12:24:10 +0100 Subject: [PATCH 4/6] Remove unused PREDICTED macro invocation. --- Python/ceval.c | 1 - 1 file changed, 1 deletion(-) diff --git a/Python/ceval.c b/Python/ceval.c index 99aa7861edede3..d29e135a64d0cf 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -2297,7 +2297,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, PyFrameObject *f, int throwflag) } case TARGET(POP_BLOCK): { - PREDICTED(POP_BLOCK); PyFrame_BlockPop(f); DISPATCH(); } From b041795e97237780c91e00daed0394dd55ae7c38 Mon Sep 17 00:00:00 2001 From: Mark Shannon Date: Mon, 31 Aug 2020 12:31:30 +0100 Subject: [PATCH 5/6] Fix typo --- .../Core and Builtins/2020-08-31-11-37-59.bpo-41670.vmRJRx.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-08-31-11-37-59.bpo-41670.vmRJRx.rst b/Misc/NEWS.d/next/Core and Builtins/2020-08-31-11-37-59.bpo-41670.vmRJRx.rst index 4e49de63326464..d1f3312d8e3719 100644 --- a/Misc/NEWS.d/next/Core and Builtins/2020-08-31-11-37-59.bpo-41670.vmRJRx.rst +++ b/Misc/NEWS.d/next/Core and Builtins/2020-08-31-11-37-59.bpo-41670.vmRJRx.rst @@ -1,2 +1,2 @@ Prevent line trace being skipped on Windows and Mac when a for loop is -nexted within a try-except block. +nested within a try-except block. From 2dbee99fe6399e2443cb1d3ee0263e51e6bb3f73 Mon Sep 17 00:00:00 2001 From: Mark Shannon Date: Fri, 25 Sep 2020 09:58:30 +0100 Subject: [PATCH 6/6] Clarify change note. --- .../2020-08-31-11-37-59.bpo-41670.vmRJRx.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-08-31-11-37-59.bpo-41670.vmRJRx.rst b/Misc/NEWS.d/next/Core and Builtins/2020-08-31-11-37-59.bpo-41670.vmRJRx.rst index d1f3312d8e3719..6ad5fb6dc9bb40 100644 --- a/Misc/NEWS.d/next/Core and Builtins/2020-08-31-11-37-59.bpo-41670.vmRJRx.rst +++ b/Misc/NEWS.d/next/Core and Builtins/2020-08-31-11-37-59.bpo-41670.vmRJRx.rst @@ -1,2 +1,4 @@ -Prevent line trace being skipped on Windows and Mac when a for loop is -nested within a try-except block. +Prevent line trace being skipped on platforms not compiled +with ``USE_COMPUTED_GOTOS``. +Fixes issue where some lines nested within a try-except block +were not being traced on Windows.