]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.6] bpo-34066: Disabled interruption before SETUP_WITH and BEFORE_ASYNC_WITH. ...
authorSerhiy Storchaka <storchaka@gmail.com>
Mon, 9 Jul 2018 16:02:25 +0000 (19:02 +0300)
committerGitHub <noreply@github.com>
Mon, 9 Jul 2018 16:02:25 +0000 (19:02 +0300)
This will prevent emitting a resource warning when the execution was
interrupted by Ctrl-C between calling open() and entering a 'with' block
in "with open()".
(cherry picked from commit 3f4d90d4d72921f16babd3f52d7df804916af224)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Misc/NEWS.d/next/Core and Builtins/2018-07-07-20-15-34.bpo-34066.y9vs6s.rst [new file with mode: 0644]
Python/ceval.c

diff --git a/Misc/NEWS.d/next/Core and Builtins/2018-07-07-20-15-34.bpo-34066.y9vs6s.rst b/Misc/NEWS.d/next/Core and Builtins/2018-07-07-20-15-34.bpo-34066.y9vs6s.rst
new file mode 100644 (file)
index 0000000..b12afad
--- /dev/null
@@ -0,0 +1,2 @@
+Disabled interruption by Ctrl-C between calling ``open()`` and entering a
+**with** block in ``with open()``.
index 646f6a5bea9ca80c4571692a25c5562810d6744e..50834f82c74607c25a9fc3eb3f9c1bf0af025ba8 100644 (file)
@@ -1155,11 +1155,18 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
            Py_MakePendingCalls() above. */
 
         if (_Py_atomic_load_relaxed(&eval_breaker)) {
-            if (_Py_OPCODE(*next_instr) == SETUP_FINALLY ||
-                _Py_OPCODE(*next_instr) == YIELD_FROM) {
-                /* Two cases where we skip running signal handlers and other
+            opcode = _Py_OPCODE(*next_instr);
+            if (opcode == SETUP_FINALLY ||
+                opcode == SETUP_WITH ||
+                opcode == BEFORE_ASYNC_WITH ||
+                opcode == YIELD_FROM) {
+                /* Few cases where we skip running signal handlers and other
                    pending calls:
-                   - If we're about to enter the try: of a try/finally (not
+                   - If we're about to enter the 'with:'. It will prevent
+                     emitting a resource warning in the common idiom
+                     'with open(path) as file:'.
+                   - If we're about to enter the 'async with:'.
+                   - If we're about to enter the 'try:' of a try/finally (not
                      *very* useful, but might help in some cases and it's
                      traditional)
                    - If we're resuming a chain of nested 'yield from' or