cpython/Python
Nathaniel J. Smith ab4413a7e9 bpo-30039: Don't run signal handlers while resuming a yield from stack (#1081)
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.
2017-05-17 13:33:23 -07:00
..
clinic bpo-20185: Convert the marshal module to Argument Clinic. (#541) 2017-03-12 09:20:15 +02:00
Python-ast.c bpo-29622: Make AST constructor to accept less than enough number of positional arguments (GH-249) 2017-02-24 02:48:17 +09:00
README
_warnings.c bpo-29878: Add global instances of int for 0 and 1. (#852) 2017-03-30 09:09:41 +03:00
asdl.c
ast.c bpo-29865: Use PyXXX_GET_SIZE macros rather than Py_SIZE for concrete types. (#748) 2017-03-21 08:53:25 +02:00
bltinmodule.c bpo-30061: Check if PyObject_Size()/PySequence_Size()/PyMapping_Size() (#1096) 2017-04-19 20:03:52 +03:00
ceval.c bpo-30039: Don't run signal handlers while resuming a yield from stack (#1081) 2017-05-17 13:33:23 -07:00
ceval_gil.h
codecs.c Issue #28858: Remove _PyObject_CallArg1() macro 2016-12-05 17:04:32 +01:00
compile.c bpo-30024: Circular imports involving absolute imports with binding (#1264) 2017-05-09 22:31:05 +03: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.6 2016-12-19 06:46:12 +00:00
fileutils.c bpo-29619: Convert st_ino using unsigned integer (#557) 2017-03-09 17:34:28 +01:00
formatter_unicode.c
frozen.c
frozenmain.c
future.c bpo-29463: Add docstring field to some AST nodes. (#46) 2017-02-22 16:31:59 +01:00
getargs.c bpo-29951: Include function name for some error messages in `PyArg_ParseTuple*` (#916) 2017-04-09 10:47:12 +03: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 bpo-6532: Make the thread id an unsigned integer. (#781) 2017-03-23 14:48:39 +01:00
importdl.c Issue #28748: Private variable _Py_PackageContext is now of type "const char *" 2016-11-21 10:25:54 +02:00
importdl.h
importlib.h bpo-29463: Add docstring field to some AST nodes. (#46) 2017-02-22 16:31:59 +01:00
importlib_external.h bpo-30022: Get rid of using EnvironmentError and IOError (except test… (#1051) 2017-04-16 10:46:38 +03:00
makeopcodetargets.py
marshal.c bpo-20185: Convert the marshal module to Argument Clinic. (#541) 2017-03-12 09:20:15 +02:00
modsupport.c bpo-29852: Argument Clinic Py_ssize_t converter now supports None (#716) 2017-03-30 09:15:31 +03:00
mysnprintf.c
mystrtoul.c
opcode_targets.h Issue #26110: Add LOAD_METHOD/CALL_METHOD opcodes. 2016-12-13 19:03:51 -05: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
pylifecycle.c bpo-30225: Fix is_valid_fd() on macOS Tiger (#1443) 2017-05-04 00:45:56 +02:00
pymath.c
pystate.c bpo-6532: Make the thread id an unsigned integer. (#781) 2017-03-23 14:48:39 +01:00
pystrcmp.c
pystrhex.c
pystrtod.c
pythonrun.c bpo-29556: Remove unused #include <langinfo.h> (#98) 2017-02-16 00:34:30 +01:00
pytime.c
random.c Issue #29157: Prefer getrandom() over getentropy() 2017-01-09 11:18:53 +01:00
sigcheck.c
strdup.c
structmember.c Added the const qualifier to char* variables that refer to readonly internal 2016-11-20 10:16:47 +02:00
symtable.c Issue #28701: Replace PyUnicode_CompareWithASCIIString with _PyUnicode_EqualToASCIIString. 2016-11-16 10:19:20 +02:00
sysmodule.c bpo-27593: Get SCM build info from git instead of hg. (#446) 2017-03-04 00:19:55 -05:00
thread.c bpo-30279: Remove unused Python/thread_foobar.h (#1473) 2017-05-05 10:04:13 +02:00
thread_nt.h bpo-6532: Make the thread id an unsigned integer. (#781) 2017-03-23 14:48:39 +01:00
thread_pthread.h bpo-6532: Make the thread id an unsigned integer. (#781) 2017-03-23 14:48:39 +01:00
traceback.c bpo-6532: Make the thread id an unsigned integer. (#781) 2017-03-23 14:48:39 +01:00
wordcode_helpers.h

README

Miscellaneous source files for the main Python shared library