| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,2 @@ | |||
| 1 | + Clear generators' exception state after ``return`` to break reference | ||
| 2 | + cycles. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -149,14 +149,16 @@ gen_dealloc(PyGenObject *gen) | |||
| 149 | 149 | gen->gi_frame_state = FRAME_CLEARED; | |
| 150 | 150 | frame->previous = NULL; | |
| 151 | 151 | _PyFrame_ClearExceptCode(frame); | |
| 152 | + _PyErr_ClearExcState(&gen->gi_exc_state); | ||
| 152 | 153 | } | |
| 154 | + assert(gen->gi_exc_state.exc_value == NULL); | ||
| 153 | 155 | if (_PyGen_GetCode(gen)->co_flags & CO_COROUTINE) { | |
| 154 | 156 | Py_CLEAR(((PyCoroObject *)gen)->cr_origin_or_finalizer); | |
| 155 | 157 | } | |
| 156 | 158 | Py_DECREF(_PyGen_GetCode(gen)); | |
| 157 | 159 | Py_CLEAR(gen->gi_name); | |
| 158 | 160 | Py_CLEAR(gen->gi_qualname); | |
| 159 | - _PyErr_ClearExcState(&gen->gi_exc_state); | ||
| 161 | + | ||
| 160 | 162 | PyObject_GC_Del(gen); | |
| 161 | 163 | } | |
| 162 | 164 | ||
@@ -252,10 +254,7 @@ gen_send_ex2(PyGenObject *gen, PyObject *arg, PyObject **presult, | |||
| 252 | 254 | !PyErr_ExceptionMatches(PyExc_StopAsyncIteration)); | |
| 253 | 255 | } | |
| 254 | 256 | ||
| 255 | - /* generator can't be rerun, so release the frame */ | ||
| 256 | - /* first clean reference cycle through stored exception traceback */ | ||
| 257 | - _PyErr_ClearExcState(&gen->gi_exc_state); | ||
| 258 | - | ||
| 257 | + assert(gen->gi_exc_state.exc_value == NULL); | ||
| 259 | 258 | assert(gen->gi_frame_state == FRAME_CLEARED); | |
| 260 | 259 | *presult = result; | |
| 261 | 260 | return result ? PYGEN_RETURN : PYGEN_ERROR; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1466,6 +1466,7 @@ clear_gen_frame(PyThreadState *tstate, _PyInterpreterFrame * frame) | |||
| 1466 | 1466 | tstate->c_recursion_remaining--; | |
| 1467 | 1467 | assert(frame->frame_obj == NULL || frame->frame_obj->f_frame == frame); | |
| 1468 | 1468 | _PyFrame_ClearExceptCode(frame); | |
| 1469 | + _PyErr_ClearExcState(&gen->gi_exc_state); | ||
| 1469 | 1470 | tstate->c_recursion_remaining++; | |
| 1470 | 1471 | frame->previous = NULL; | |
| 1471 | 1472 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments