Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Commit cb1c4ea

Browse files
author
Anselm Kruis
committed
Stackless issue #149: Fix exc state handling during tasklet deallocation
Fix a few incorrect assertions introduced by commit 245a802. A test in the upcoming commit for Stackless issue #190 triggered an assertion failure.
1 parent 0d490e1 commit cb1c4ea

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

Stackless/module/taskletobject.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,13 @@ tasklet_clear(PyTaskletObject *t)
189189
Py_CLEAR(t->exc_state.exc_value);
190190
Py_CLEAR(t->exc_state.exc_traceback);
191191

192-
/* The stack of exception states should contain just this tasklet. */
193-
assert(t->exc_info->previous_item == NULL);
194-
if (Py_VerboseFlag && t->exc_info != &t->exc_state) {
195-
fprintf(stderr,
196-
"PyTaskletObject_Clear: warning: tasklet still has a generator\n");
197-
}
192+
/* Assert that the tasklet is at the end of the chain. */
193+
assert(t->exc_state.previous_item == NULL);
194+
/* Unlink the exc_info chain. There is no guarantee, that
195+
* the object t->exc_info points to still exists, because
196+
* the order of calls to tp_clear is undefined.
197+
*/
198+
t->exc_info = &t->exc_state;
198199
}
199200

200201
/*
@@ -281,8 +282,13 @@ tasklet_dealloc(PyTaskletObject *t)
281282
}
282283
Py_DECREF(t->tempval);
283284
Py_XDECREF(t->def_globals);
285+
/* Assert that the tasklet is at the end of the chain. */
284286
assert(t->exc_state.previous_item == NULL);
285-
assert(t->exc_info == &t->exc_state);
287+
/* Unlink the exc_info chain. There is no guarantee, that
288+
* the object t->exc_info points to still exists, because
289+
* the order of calls to tp_clear is undefined.
290+
*/
291+
t->exc_info = &t->exc_state;
286292
exc_state_clear(&t->exc_state);
287293
Py_TYPE(t)->tp_free((PyObject*)t);
288294
}

0 commit comments

Comments
 (0)