Skip to content

Commit 77521e2

Browse files
author
Anselm Kruis
committed
Stackless issue python#241: add precondition test to tasklet.__setstate__
Add a check to tasklet.__setstate__() to raise RuntimeError, if the tasklet is already alive. (cherry picked from commit 58613bc)
1 parent 8d0e9a0 commit 77521e2

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

Stackless/changelog.txt

+10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ Stackless-Python News
44
This file documents user visible changes to the Stackless extension of C-Python.
55
For other changes see Misc/NEWS.
66

7+
What's New in Stackless 3.X.X?
8+
==============================
9+
10+
*Release date: 20XX-XX-XX*
11+
12+
- https://github.com/stackless-dev/stackless/issues/241
13+
Prevent a crash, if you call tasklet.__setstate__() on a tasklet, that is
14+
alive.
15+
16+
717
What's New in Stackless 3.6.9, 3.6.10, 3.6.11, 3.6.12 and 3.6.13?
818
=================================================================
919

Stackless/module/taskletobject.c

+5
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,11 @@ tasklet_setstate(PyObject *self, PyObject *args)
535535
Py_ssize_t i, nframes;
536536
int j;
537537

538+
assert(t && PyTasklet_Check(t));
539+
540+
if (PyTasklet_Alive(t))
541+
RUNTIME_ERROR("tasklet is alive", NULL);
542+
538543
if (!PyArg_ParseTuple(args, "iOiO!:tasklet",
539544
&flags,
540545
&tempval,

Stackless/unittests/test_defects.py

+17
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,23 @@ def func():
646646
self.assertEqual(r, 4711)
647647

648648

649+
class TestTaskletSetstate(StacklessTestCase):
650+
# a test case for https://github.com/stackless-dev/stackless/issues/241
651+
652+
def test_setstate_not_alive(self):
653+
state = stackless.tasklet().__reduce__()[2]
654+
t = stackless.tasklet()
655+
self.assertFalse(t.alive)
656+
self.assertIs(t.__setstate__(state), t)
657+
t.bind() # unbind t
658+
659+
def test_setstate_alive(self):
660+
state = stackless.tasklet().__reduce__()[2]
661+
t = stackless.tasklet(lambda: None,())
662+
self.assertTrue(t.alive)
663+
self.assertRaisesRegex(RuntimeError, "tasklet is alive", t.__setstate__, state)
664+
665+
649666
if __name__ == '__main__':
650667
if not sys.argv[1:]:
651668
sys.argv.append('-v')

0 commit comments

Comments
 (0)