Skip to content

Commit 0b8da63

Browse files
committed
Stackless issue python#222: fix main-tasklet termination with serial mismatch
Fix the termination of a main-tasklet when serial_last_jump != initial_stub.serial. This caused an assertion failure and a reference leak.
1 parent 4f7b3ec commit 0b8da63

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

Stackless/changelog.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ What's New in Stackless 3.X.X?
99

1010
*Release date: 20XX-XX-XX*
1111

12+
- https://github.com/stackless-dev/stackless/issues/221
13+
Fix a bug that could cause an assertion failure and a reference leak during
14+
the termination of a main-tasklet, if an application embeds Stackless Python.
15+
1216
- https://github.com/stackless-dev/stackless/issues/221
1317
Change the width of C-stack serial numbers to 64bit. This prevents overflows
1418
in long running applications with an embedded Stackless Python.

Stackless/module/scheduling.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,8 +1441,13 @@ slp_tasklet_end(PyObject *retval)
14411441
* the original stub if necessary. (Meanwhile, task->cstate may be an old nesting state and not
14421442
* the original stub, so we take the stub from the tstate)
14431443
*/
1444-
if (ts->st.serial_last_jump != ts->st.initial_stub->serial)
1445-
slp_transfer_return(ts->st.initial_stub);
1444+
if (ts->st.serial_last_jump != ts->st.initial_stub->serial) {
1445+
Py_DECREF(retval);
1446+
SLP_STORE_NEXT_FRAME(ts, NULL);
1447+
slp_transfer_return(ts->st.initial_stub); /* does not return */
1448+
assert(0);
1449+
return NULL;
1450+
}
14461451
}
14471452

14481453
/* remove current from runnables. We now own its reference. */

0 commit comments

Comments
 (0)