Use _PyErr_ChainStackItem() inside gen_send_ex(). (GH-20173) (#20202) · python/cpython@f02c304 (original) (raw)

Original file line number Diff line number Diff line change
@@ -203,16 +203,8 @@ gen_send_ex(PyGenObject *gen, PyObject *arg, int exc, int closing)
203 203 assert(f->f_back == NULL);
204 204 f->f_back = tstate->frame;
205 205
206 -_PyErr_StackItem *gi_exc_state = &gen->gi_exc_state;
207 -if (exc && gi_exc_state->exc_type != NULL &&
208 -gi_exc_state->exc_type != Py_None)
209 - {
210 -Py_INCREF(gi_exc_state->exc_type);
211 -Py_XINCREF(gi_exc_state->exc_value);
212 -Py_XINCREF(gi_exc_state->exc_traceback);
213 -_PyErr_ChainExceptions(gi_exc_state->exc_type,
214 -gi_exc_state->exc_value,
215 -gi_exc_state->exc_traceback);
206 +if (exc) {
207 +_PyErr_ChainStackItem(&gen->gi_exc_state);
216 208 }
217 209
218 210 gen->gi_running = 1;