cpython/Python
Yury Selivanov e89f95bfd0 [3.6] bpo-30039: Don't run signal handlers while resuming a yield from stack (GH-1081) (#1640)
If we have a chain of generators/coroutines that are 'yield from'ing
each other, then resuming the stack works like:

- call send() on the outermost generator
- this enters _PyEval_EvalFrameDefault, which re-executes the
  YIELD_FROM opcode
- which calls send() on the next generator
- which enters _PyEval_EvalFrameDefault, which re-executes the
  YIELD_FROM opcode
- ...etc.

However, every time we enter _PyEval_EvalFrameDefault, the first thing
we do is to check for pending signals, and if there are any then we
run the signal handler. And if it raises an exception, then we
immediately propagate that exception *instead* of starting to execute
bytecode. This means that e.g. a SIGINT at the wrong moment can "break
the chain" – it can be raised in the middle of our yield from chain,
with the bottom part of the stack abandoned for the garbage collector.

The fix is pretty simple: there's already a special case in
_PyEval_EvalFrameEx where it skips running signal handlers if the next
opcode is SETUP_FINALLY. (I don't see how this accomplishes anything
useful, but that's another story.) If we extend this check to also
skip running signal handlers when the next opcode is YIELD_FROM, then
that closes the hole – now the exception can only be raised at the
innermost stack frame.

This shouldn't have any performance implications, because the opcode
check happens inside the "slow path" after we've already determined
that there's a pending signal or something similar for us to process;
the vast majority of the time this isn't true and the new check
doesn't run at all..
(cherry picked from commit ab4413a7e9)
2017-06-09 17:06:39 -04:00
..
clinic Issue #27810: Rerun Argument Clinic on all modules 2016-09-09 20:00:13 -07:00
Python-ast.c Issue #24098: Fixed possible crash when AST is changed in process of 2016-10-07 21:55:49 +03:00
README
_warnings.c Issue #28701: Replace PyUnicode_CompareWithASCIIString with _PyUnicode_EqualToASCIIString. 2016-11-16 10:19:20 +02:00
asdl.c
ast.c [3.6] bpo-30529: Fix errors for invalid whitespaces in f-string subexpressions. (GH-1888) (#2013) 2017-06-09 00:38:06 +03:00
bltinmodule.c [3.6] bpo-8256: Fixed possible failing or crashing input() (#641) 2017-03-12 21:52:17 +02:00
ceval.c [3.6] bpo-30039: Don't run signal handlers while resuming a yield from stack (GH-1081) (#1640) 2017-06-09 17:06:39 -04:00
ceval_gil.h
codecs.c
compile.c bpo-29607: Fix stack_effect computation for CALL_FUNCTION_EX (GH-219) 2017-02-22 02:33:24 +09:00
condvar.h
dtoa.c
dup2.c
dynamic_annotations.c
dynload_aix.c
dynload_dl.c
dynload_hpux.c
dynload_next.c
dynload_shlib.c
dynload_stub.c
dynload_win.c
errors.c Issue #25677: Merge SyntaxError caret positioning from 3.5 2016-12-19 06:46:01 +00:00
fileutils.c bpo-29619: Convert st_ino using unsigned integer (#557) (#584) 2017-03-09 18:43:39 +01:00
formatter_unicode.c merge 3.5 (#28119) 2016-09-13 22:46:15 -07:00
frozen.c
frozenmain.c
future.c Replaced outdated macros _PyUnicode_AsString and _PyUnicode_AsStringAndSize 2016-11-20 09:13:07 +02:00
getargs.c Issue #28701: Replace PyUnicode_CompareWithASCIIString with _PyUnicode_EqualToASCIIString. 2016-11-16 10:19:20 +02:00
getcompiler.c
getcopyright.c ring in 2017 for Python 2017-01-01 22:04:13 -06:00
getopt.c
getplatform.c
getversion.c
graminit.c
import.c Issue #28701: Replace PyUnicode_CompareWithASCIIString with _PyUnicode_EqualToASCIIString. 2016-11-16 10:19:20 +02:00
importdl.c Issue #28715: Added error checks for PyUnicode_AsUTF8(). 2016-11-20 08:48:07 +02:00
importdl.h
importlib.h Refresh Python/importlib.h and Python/importlib_external.h (#464) 2017-03-04 07:04:41 -05:00
importlib_external.h Refresh Python/importlib.h and Python/importlib_external.h (#464) 2017-03-04 07:04:41 -05:00
makeopcodetargets.py
marshal.c bpo-29746: Update marshal docs to Python 3. (#547) (#631) 2017-03-12 10:05:05 +02:00
modsupport.c va_end() all va_copy()ed va_lists. 2016-09-21 11:37:27 +02:00
mysnprintf.c
mystrtoul.c
opcode_targets.h Issue #28257: Improved error message when pass a non-iterable as 2016-10-02 10:33:46 +03:00
peephole.c Issue #28517: Fixed of-by-one error in the peephole optimizer that caused 2016-10-25 09:30:43 +03:00
pyarena.c
pyctype.c
pyfpe.c
pyhash.c Issue #28126: Replace Py_MEMCPY with memcpy(). Visual Studio can properly optimize memcpy(). 2016-09-13 20:22:02 +02:00
pylifecycle.c bpo-30225: Fix is_valid_fd() on macOS Tiger (#1443) (#1449) 2017-05-04 13:21:10 +02:00
pymath.c
pystate.c [3.6] bpo-30395 _PyGILState_Reinit deadlock fix (GH-1734) (#1740) 2017-05-22 22:23:05 -07:00
pystrcmp.c
pystrhex.c
pystrtod.c
pythonrun.c Issue #25677: Merge SyntaxError caret positioning from 3.5 2016-12-19 06:46:01 +00:00
pytime.c Issue #28148: Stop using localtime() and gmtime() in the time module. 2016-09-28 17:31:35 -04:00
random.c Issue #29157: Prefer getrandom() over getentropy() 2017-01-09 11:18:53 +01:00
sigcheck.c
strdup.c
structmember.c Replaced outdated macros _PyUnicode_AsString and _PyUnicode_AsStringAndSize 2016-11-20 09:13:07 +02:00
symtable.c Issue #28701: Replace PyUnicode_CompareWithASCIIString with _PyUnicode_EqualToASCIIString. 2016-11-16 10:19:20 +02:00
sysmodule.c [3.6] bpo-30567: Fix refleak in sys.getwindowsversion (GH-1940) (#1970) 2017-06-06 19:23:02 +03:00
thread.c
thread_foobar.h
thread_nt.h
thread_pthread.h bpo-29859: Fix error messages from return codes for pthread_* calls (GH-753) 2017-03-22 03:46:26 +09:00
traceback.c Issue #23782: Fixed possible memory leak in _PyTraceback_Add() and exception 2016-10-18 13:26:25 +03:00
wordcode_helpers.h Issue #27129: Replaced wordcode related magic constants with macros. 2016-09-11 13:48:15 +03:00

README

Miscellaneous source files for the main Python shared library