Skip to content

Commit

Permalink
add asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
kumaraditya303 committed Dec 21, 2024
1 parent b972121 commit eeb0273
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion Modules/_asynciomodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,8 @@ future_ensure_alive(FutureObj *fut)
static int
future_schedule_callbacks(asyncio_state *state, FutureObj *fut)
{
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(fut);

if (fut->fut_callback0 != NULL) {
/* There's a 1st callback */

Expand Down Expand Up @@ -492,10 +494,11 @@ future_init(FutureObj *fut, PyObject *loop)
static PyObject *
future_set_result(asyncio_state *state, FutureObj *fut, PyObject *res)
{
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(fut);

if (future_ensure_alive(fut)) {
return NULL;
}
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(fut);

if (fut->fut_state != STATE_PENDING) {
PyErr_SetString(state->asyncio_InvalidStateError, "invalid state");
Expand All @@ -515,6 +518,8 @@ future_set_result(asyncio_state *state, FutureObj *fut, PyObject *res)
static PyObject *
future_set_exception(asyncio_state *state, FutureObj *fut, PyObject *exc)
{
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(fut);

PyObject *exc_val = NULL;

if (fut->fut_state != STATE_PENDING) {
Expand Down Expand Up @@ -581,6 +586,8 @@ future_set_exception(asyncio_state *state, FutureObj *fut, PyObject *exc)
static PyObject *
create_cancelled_error(asyncio_state *state, FutureObj *fut)
{
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(fut);

PyObject *exc;
if (fut->fut_cancelled_exc != NULL) {
/* transfer ownership */
Expand All @@ -600,6 +607,8 @@ create_cancelled_error(asyncio_state *state, FutureObj *fut)
static void
future_set_cancelled_error(asyncio_state *state, FutureObj *fut)
{
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(fut);

PyObject *exc = create_cancelled_error(state, fut);
if (exc == NULL) {
return;
Expand All @@ -611,6 +620,8 @@ future_set_cancelled_error(asyncio_state *state, FutureObj *fut)
static int
future_get_result(asyncio_state *state, FutureObj *fut, PyObject **result)
{
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(fut);

if (fut->fut_state == STATE_CANCELLED) {
future_set_cancelled_error(state, fut);
return -1;
Expand Down Expand Up @@ -644,6 +655,8 @@ static PyObject *
future_add_done_callback(asyncio_state *state, FutureObj *fut, PyObject *arg,
PyObject *ctx)
{
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(fut);

if (!future_is_alive(fut)) {
PyErr_SetString(PyExc_RuntimeError, "uninitialized Future object");
return NULL;
Expand Down Expand Up @@ -718,6 +731,8 @@ future_add_done_callback(asyncio_state *state, FutureObj *fut, PyObject *arg,
static PyObject *
future_cancel(asyncio_state *state, FutureObj *fut, PyObject *msg)
{
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(fut);

fut->fut_log_tb = 0;

if (fut->fut_state != STATE_PENDING) {
Expand Down

0 comments on commit eeb0273

Please sign in to comment.