8000 bpo-46841: Don't jump during `throw()` by brandtbucher · Pull Request #31968 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-46841: Don't jump during throw() #31968

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Handle return-during-throw in SEND
  • Loading branch information
brandtbucher committed Mar 17, 2022
commit 6ee3f3814f17c72b96c424873de64a4602d9788a
11 changes: 2 additions & 9 deletions Objects/genobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -485,15 +485,8 @@ _gen_throw(PyGenObject *gen, int close_on_genexit,
ret = _PyFrame_StackPop((_PyInterpreterFrame *)gen->gi_iframe);
assert(ret == yf);
Py_DECREF(ret);
/* Termination repetition of SEND loop */
assert(frame->f_lasti >= 0);
PyObject *bytecode = gen->gi_code->co_code;
unsigned char *code = (unsigned char *)PyBytes_AS_STRING(bytecode);
/* Backup to SEND */
frame->f_lasti--;
assert(code[frame->f_lasti*sizeof(_Py_CODEUNIT)] == SEND);
int jump = code[frame->f_lasti*sizeof(_Py_CODEUNIT)+1];
frame->f_lasti += jump;
// NULL tells SEND to quit sending:
_PyFrame_StackPush((_PyInterpreterFrame *)gen->gi_iframe, NULL);
if (_PyGen_FetchStopIterationValue(&val) == 0) {
ret = gen_send(gen, val);
Py_DECREF(val);
Expand Down
7 changes: 7 additions & 0 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -2535,6 +2535,13 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
assert(STACK_LEVEL() >= 2);
PyObject *v = POP();
PyObject *receiver = TOP();
if (receiver == NULL) {
// Receiver completed during a throw() call. v is the return
// value:
SET_TOP(v);
JUMPBY(oparg);
DISPATCH();
}
PySendResult gen_status;
PyObject *retval;
if (tstate->c_tracefunc == NULL) {
Expand Down
0