Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Lib/test/test_asyncio/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2924,6 +2924,16 @@ async def coro():
with self.assertRaises(AttributeError):
del task._log_destroy_pending

def test_get_context_uninitialized_segfault(self):
# https://github.com/python/cpython/issues/154871

class UninitializedTask(self.Task):
def __init__(self, *args, **kwargs):
pass

task = UninitializedTask()
self.assertIsNone(task.get_context())


@unittest.skipUnless(hasattr(futures, '_CFuture') and
hasattr(tasks, '_CTask'),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed a crash in :meth:`asyncio.Task.get_context`
when called on an uninitialized task.
6 changes: 5 additions & 1 deletion Modules/_asynciomodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2787,7 +2787,11 @@ static PyObject *
_asyncio_Task_get_context_impl(TaskObj *self)
/*[clinic end generated code: output=6996f53d3dc01aef input=87c0b209b8fceeeb]*/
{
return Py_NewRef(self->task_context);
if (self->task_context) {
return Py_NewRef(self->task_context);
}

Py_RETURN_NONE;
}

/*[clinic input]
Expand Down
Loading