Skip to content

Commit 021f08c

Browse files
author
Anselm Kruis
committed
Stackless issue python#84: fix tasklet_kill(...) and typeobject.c wrap_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)
1 parent d6d0830 commit 021f08c

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

Objects/typeobject.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4812,12 +4812,15 @@ RICHCMP_WRAPPER(ge, Py_GE)
48124812
static PyObject *
48134813
wrap_next(PyObject *self, PyObject *args, void *wrapped)
48144814
{
4815+
STACKLESS_GETARG();
48154816
unaryfunc func = (unaryfunc)wrapped;
48164817
PyObject *res;
48174818

48184819
if (!check_num_args(args, 0))
48194820
return NULL;
4821+
STACKLESS_PROMOTE_ALL();
48204822
res = (*func)(self);
4823+
STACKLESS_ASSERT();
48214824
if (res == NULL && !PyErr_Occurred())
48224825
PyErr_SetNone(PyExc_StopIteration);
48234826
return res;

Stackless/module/taskletobject.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1258,15 +1258,20 @@ int PyTasklet_Kill(PyTaskletObject *task)
12581258
static PyObject *
12591259
tasklet_kill(PyObject *self, PyObject *args, PyObject *kwds)
12601260
{
1261+
STACKLESS_GETARG();
12611262
int pending;
1263+
PyObject *result;
12621264
PyObject *pendingO = Py_False;
12631265
char *kwlist[] = {"pending", 0};
12641266
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O:kill", kwlist, &pendingO))
12651267
return NULL;
12661268
pending = PyObject_IsTrue(pendingO);
12671269
if (pending == -1)
12681270
return NULL;
1269-
return impl_tasklet_kill((PyTaskletObject*)self, pending);
1271+
STACKLESS_PROMOTE_ALL();
1272+
result = impl_tasklet_kill((PyTaskletObject*)self, pending);
1273+
STACKLESS_ASSERT();
1274+
return result;
12701275
}
12711276

12721277

Stackless/unittests/test_defects.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,23 @@ def func():
275275
self.assertEqual(rc, 42)
276276

277277

278+
class TestStacklessProtokoll(StacklessTestCase):
279+
"""Various tests for violations of the STACKLESS_GETARG() STACKLESS_ASSERT() protocol
280+
281+
See https://bitbucket.org/stackless-dev/stackless/issues/84
282+
"""
283+
def test_invalid_args_channel_next(self):
284+
"""test of typeobject.c wrap_next(...)"""
285+
func = stackless.channel().__next__
286+
# func(None) causes the crash
287+
self.assertRaises(TypeError, func, None)
288+
289+
def test_invalid_args_tasklet_kill(self):
290+
func = stackless.tasklet().kill
291+
# func(False, None) causes the crash
292+
self.assertRaises(TypeError, func, False, None)
293+
294+
278295
if __name__ == '__main__':
279296
if not sys.argv[1:]:
280297
sys.argv.append('-v')

0 commit comments

Comments
 (0)