Skip to content

Commit

Permalink
Stackless issue python#84: fix tasklet_kill(...) and typeobject.c wra…
Browse files Browse the repository at this point in the history
…p_next(...)

Add the required STACKLESS_... macros to taskletobject.c tasklet_kill(...)
and wrap_next(). Add a test class.

https://bitbucket.org/stackless-dev/stackless/issue/84
(grafted from 5d3898850c2f06d2a57b7589e4b5b8ebd9355e84, af52a8f20449 and
27e7e0fa1709)
  • Loading branch information
Anselm Kruis committed Aug 31, 2016
1 parent d6d0830 commit 021f08c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -4812,12 +4812,15 @@ RICHCMP_WRAPPER(ge, Py_GE)
static PyObject *
wrap_next(PyObject *self, PyObject *args, void *wrapped)
{
STACKLESS_GETARG();
unaryfunc func = (unaryfunc)wrapped;
PyObject *res;

if (!check_num_args(args, 0))
return NULL;
STACKLESS_PROMOTE_ALL();
res = (*func)(self);
STACKLESS_ASSERT();
if (res == NULL && !PyErr_Occurred())
PyErr_SetNone(PyExc_StopIteration);
return res;
Expand Down
7 changes: 6 additions & 1 deletion Stackless/module/taskletobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1258,15 +1258,20 @@ int PyTasklet_Kill(PyTaskletObject *task)
static PyObject *
tasklet_kill(PyObject *self, PyObject *args, PyObject *kwds)
{
STACKLESS_GETARG();
int pending;
PyObject *result;
PyObject *pendingO = Py_False;
char *kwlist[] = {"pending", 0};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O:kill", kwlist, &pendingO))
return NULL;
pending = PyObject_IsTrue(pendingO);
if (pending == -1)
return NULL;
return impl_tasklet_kill((PyTaskletObject*)self, pending);
STACKLESS_PROMOTE_ALL();
result = impl_tasklet_kill((PyTaskletObject*)self, pending);
STACKLESS_ASSERT();
return result;
}


Expand Down
17 changes: 17 additions & 0 deletions Stackless/unittests/test_defects.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,23 @@ def func():
self.assertEqual(rc, 42)


class TestStacklessProtokoll(StacklessTestCase):
"""Various tests for violations of the STACKLESS_GETARG() STACKLESS_ASSERT() protocol
See https://bitbucket.org/stackless-dev/stackless/issues/84
"""
def test_invalid_args_channel_next(self):
"""test of typeobject.c wrap_next(...)"""
func = stackless.channel().__next__
# func(None) causes the crash
self.assertRaises(TypeError, func, None)

def test_invalid_args_tasklet_kill(self):
func = stackless.tasklet().kill
# func(False, None) causes the crash
self.assertRaises(TypeError, func, False, None)


if __name__ == '__main__':
if not sys.argv[1:]:
sys.argv.append('-v')
Expand Down

0 comments on commit 021f08c

Please sign in to comment.