@@ -89,7 +89,6 @@ frame_setlineno(PyFrameObject *f, PyObject* p_new_lineno)
8989 long l_new_lineno ;
9090 int overflow ;
9191 int new_lasti = 0 ; /* The new value of f_lasti */
92- int new_iblock = 0 ; /* The new value of f_iblock */
9392 unsigned char * code = NULL ; /* The bytecode for the frame... */
9493 Py_ssize_t code_len = 0 ; /* ...and its length */
9594 unsigned char * lnotab = NULL ; /* Iterating over co_lnotab */
@@ -99,6 +98,7 @@ frame_setlineno(PyFrameObject *f, PyObject* p_new_lineno)
9998 int addr = 0 ; /* (ditto) */
10099 int delta_iblock = 0 ; /* Scanning the SETUPs and POPs */
101100 int for_loop_delta = 0 ; /* (ditto) */
101+ int delta ;
102102 int blockstack [CO_MAXBLOCKS ]; /* Walking the 'finally' blocks */
103103 int blockstack_top = 0 ; /* (ditto) */
104104
@@ -258,19 +258,25 @@ frame_setlineno(PyFrameObject *f, PyObject* p_new_lineno)
258258 assert (blockstack_top == 0 );
259259
260260 /* Pop any blocks that we're jumping out of. */
261- new_iblock = f -> f_iblock - delta_iblock ;
262- while (f -> f_iblock > new_iblock ) {
263- PyTryBlock * b = & f -> f_blockstack [-- f -> f_iblock ];
264- while ((f -> f_stacktop - f -> f_valuestack ) > b -> b_level ) {
265- PyObject * v = (* -- f -> f_stacktop );
266- Py_DECREF (v );
261+ delta = 0 ;
262+ if (delta_iblock > 0 ) {
263+ f -> f_iblock -= delta_iblock ;
264+ PyTryBlock * b = & f -> f_blockstack [f -> f_iblock ];
265+ delta = (f -> f_stacktop - f -> f_valuestack ) - b -> b_level ;
266+ if (b -> b_type == SETUP_FINALLY &&
267+ code [b -> b_handler ] == WITH_CLEANUP_START )
268+ {
269+ /* Pop the exit function. */
270+ delta ++ ;
267271 }
268272 }
269273 /* Pop the iterators of any 'for' loop we're jumping out of. */
270- while (for_loop_delta > 0 ) {
274+ delta += for_loop_delta ;
275+
276+ while (delta > 0 ) {
271277 PyObject * v = (* -- f -> f_stacktop );
272278 Py_DECREF (v );
273- for_loop_delta -- ;
279+ delta -- ;
274280 }
275281
276282 /* Finally set the new f_lineno and f_lasti and return OK. */
0 commit comments