diff options
author | shadchin <shadchin@yandex-team.ru> | 2022-02-10 16:44:30 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:44:30 +0300 |
commit | 2598ef1d0aee359b4b6d5fdd1758916d5907d04f (patch) | |
tree | 012bb94d777798f1f56ac1cec429509766d05181 /contrib/tools/python3/src/Modules/_asynciomodule.c | |
parent | 6751af0b0c1b952fede40b19b71da8025b5d8bcf (diff) | |
download | ydb-2598ef1d0aee359b4b6d5fdd1758916d5907d04f.tar.gz |
Restoring authorship annotation for <shadchin@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/tools/python3/src/Modules/_asynciomodule.c')
-rw-r--r-- | contrib/tools/python3/src/Modules/_asynciomodule.c | 900 |
1 files changed, 450 insertions, 450 deletions
diff --git a/contrib/tools/python3/src/Modules/_asynciomodule.c b/contrib/tools/python3/src/Modules/_asynciomodule.c index a1421cf5db..c18fe31eef 100644 --- a/contrib/tools/python3/src/Modules/_asynciomodule.c +++ b/contrib/tools/python3/src/Modules/_asynciomodule.c @@ -1,6 +1,6 @@ #include "Python.h" -#include "pycore_pyerrors.h" // _PyErr_ClearExcState() -#include <stddef.h> // offsetof() +#include "pycore_pyerrors.h" // _PyErr_ClearExcState() +#include <stddef.h> // offsetof() /*[clinic input] @@ -11,7 +11,7 @@ module _asyncio /* identifiers used from some functions */ _Py_IDENTIFIER(__asyncio_running_event_loop__); -_Py_IDENTIFIER(_asyncio_future_blocking); +_Py_IDENTIFIER(_asyncio_future_blocking); _Py_IDENTIFIER(add_done_callback); _Py_IDENTIFIER(call_soon); _Py_IDENTIFIER(cancel); @@ -32,13 +32,13 @@ static PyObject *asyncio_task_repr_info_func; static PyObject *asyncio_InvalidStateError; static PyObject *asyncio_CancelledError; static PyObject *context_kwname; -static int module_initialized; +static int module_initialized; static PyObject *cached_running_holder; static volatile uint64_t cached_running_holder_tsid; -/* Counter for autogenerated Task names */ -static uint64_t task_name_counter = 0; +/* Counter for autogenerated Task names */ +static uint64_t task_name_counter = 0; /* WeakSet containing all alive tasks. */ static PyObject *all_tasks; @@ -66,13 +66,13 @@ typedef enum { PyObject *prefix##_exception; \ PyObject *prefix##_result; \ PyObject *prefix##_source_tb; \ - PyObject *prefix##_cancel_msg; \ + PyObject *prefix##_cancel_msg; \ fut_state prefix##_state; \ int prefix##_log_tb; \ int prefix##_blocking; \ PyObject *dict; \ - PyObject *prefix##_weakreflist; \ - _PyErr_StackItem prefix##_cancelled_exc_state; + PyObject *prefix##_weakreflist; \ + _PyErr_StackItem prefix##_cancelled_exc_state; typedef struct { FutureObj_HEAD(fut) @@ -82,7 +82,7 @@ typedef struct { FutureObj_HEAD(task) PyObject *task_fut_waiter; PyObject *task_coro; - PyObject *task_name; + PyObject *task_name; PyObject *task_context; int task_must_cancel; int task_log_destroy_pending; @@ -113,8 +113,8 @@ static PyTypeObject TaskType; static PyTypeObject PyRunningLoopHolder_Type; -#define Future_CheckExact(obj) Py_IS_TYPE(obj, &FutureType) -#define Task_CheckExact(obj) Py_IS_TYPE(obj, &TaskType) +#define Future_CheckExact(obj) Py_IS_TYPE(obj, &FutureType) +#define Task_CheckExact(obj) Py_IS_TYPE(obj, &TaskType) #define Future_Check(obj) PyObject_TypeCheck(obj, &FutureType) #define Task_Check(obj) PyObject_TypeCheck(obj, &TaskType) @@ -143,7 +143,7 @@ _is_coroutine(PyObject *coro) Do this check after 'future_init()'; in case we need to raise an error, __del__ needs a properly initialized object. */ - PyObject *res = PyObject_CallOneArg(asyncio_iscoroutine_func, coro); + PyObject *res = PyObject_CallOneArg(asyncio_iscoroutine_func, coro); if (res == NULL) { return -1; } @@ -217,7 +217,7 @@ get_future_loop(PyObject *fut) return NULL; } if (getloop != NULL) { - PyObject *res = PyObject_CallNoArgs(getloop); + PyObject *res = PyObject_CallNoArgs(getloop); Py_DECREF(getloop); return res; } @@ -232,19 +232,19 @@ get_running_loop(PyObject **loop) PyObject *rl; PyThreadState *ts = PyThreadState_Get(); - uint64_t ts_id = PyThreadState_GetID(ts); - if (ts_id == cached_running_holder_tsid && cached_running_holder != NULL) { + uint64_t ts_id = PyThreadState_GetID(ts); + if (ts_id == cached_running_holder_tsid && cached_running_holder != NULL) { // Fast path, check the cache. rl = cached_running_holder; // borrowed } else { - PyObject *ts_dict = _PyThreadState_GetDict(ts); // borrowed - if (ts_dict == NULL) { + PyObject *ts_dict = _PyThreadState_GetDict(ts); // borrowed + if (ts_dict == NULL) { goto not_found; } rl = _PyDict_GetItemIdWithError( - ts_dict, &PyId___asyncio_running_event_loop__); // borrowed + ts_dict, &PyId___asyncio_running_event_loop__); // borrowed if (rl == NULL) { if (PyErr_Occurred()) { goto error; @@ -255,10 +255,10 @@ get_running_loop(PyObject **loop) } cached_running_holder = rl; // borrowed - cached_running_holder_tsid = ts_id; + cached_running_holder_tsid = ts_id; } - assert(Py_IS_TYPE(rl, &PyRunningLoopHolder_Type)); + assert(Py_IS_TYPE(rl, &PyRunningLoopHolder_Type)); PyObject *running_loop = ((PyRunningLoopHolder *)rl)->rl_loop; if (running_loop == Py_None) { @@ -291,13 +291,13 @@ error: static int set_running_loop(PyObject *loop) { - PyObject *ts_dict = NULL; - - PyThreadState *tstate = PyThreadState_Get(); - if (tstate != NULL) { - ts_dict = _PyThreadState_GetDict(tstate); // borrowed - } - + PyObject *ts_dict = NULL; + + PyThreadState *tstate = PyThreadState_Get(); + if (tstate != NULL) { + ts_dict = _PyThreadState_GetDict(tstate); // borrowed + } + if (ts_dict == NULL) { PyErr_SetString( PyExc_RuntimeError, "thread-local storage is not available"); @@ -317,9 +317,9 @@ set_running_loop(PyObject *loop) } Py_DECREF(rl); - cached_running_holder = (PyObject *)rl; - cached_running_holder_tsid = PyThreadState_GetID(tstate); - + cached_running_holder = (PyObject *)rl; + cached_running_holder_tsid = PyThreadState_GetID(tstate); + return 0; } @@ -337,12 +337,12 @@ get_event_loop(void) return loop; } - policy = PyObject_CallNoArgs(asyncio_get_event_loop_policy); + policy = PyObject_CallNoArgs(asyncio_get_event_loop_policy); if (policy == NULL) { return NULL; } - loop = _PyObject_CallMethodIdNoArgs(policy, &PyId_get_event_loop); + loop = _PyObject_CallMethodIdNoArgs(policy, &PyId_get_event_loop); Py_DECREF(policy); return loop; } @@ -376,7 +376,7 @@ call_soon(PyObject *loop, PyObject *func, PyObject *arg, PyObject *ctx) } stack[nargs] = (PyObject *)ctx; - handle = PyObject_Vectorcall(callable, stack, nargs, context_kwname); + handle = PyObject_Vectorcall(callable, stack, nargs, context_kwname); Py_DECREF(callable); } @@ -487,8 +487,8 @@ future_init(FutureObj *fut, PyObject *loop) Py_CLEAR(fut->fut_result); Py_CLEAR(fut->fut_exception); Py_CLEAR(fut->fut_source_tb); - Py_CLEAR(fut->fut_cancel_msg); - _PyErr_ClearExcState(&fut->fut_cancelled_exc_state); + Py_CLEAR(fut->fut_cancel_msg); + _PyErr_ClearExcState(&fut->fut_cancelled_exc_state); fut->fut_state = STATE_PENDING; fut->fut_log_tb = 0; @@ -505,7 +505,7 @@ future_init(FutureObj *fut, PyObject *loop) } fut->fut_loop = loop; - res = _PyObject_CallMethodIdNoArgs(fut->fut_loop, &PyId_get_debug); + res = _PyObject_CallMethodIdNoArgs(fut->fut_loop, &PyId_get_debug); if (res == NULL) { return -1; } @@ -521,7 +521,7 @@ future_init(FutureObj *fut, PyObject *loop) method, which is called during the interpreter shutdown and the traceback module is already unloaded. */ - fut->fut_source_tb = PyObject_CallNoArgs(traceback_extract_stack); + fut->fut_source_tb = PyObject_CallNoArgs(traceback_extract_stack); if (fut->fut_source_tb == NULL) { return -1; } @@ -564,7 +564,7 @@ future_set_exception(FutureObj *fut, PyObject *exc) } if (PyExceptionClass_Check(exc)) { - exc_val = PyObject_CallNoArgs(exc); + exc_val = PyObject_CallNoArgs(exc); if (exc_val == NULL) { return NULL; } @@ -583,7 +583,7 @@ future_set_exception(FutureObj *fut, PyObject *exc) PyErr_SetString(PyExc_TypeError, "invalid exception object"); return NULL; } - if (Py_IS_TYPE(exc_val, (PyTypeObject *)PyExc_StopIteration)) { + if (Py_IS_TYPE(exc_val, (PyTypeObject *)PyExc_StopIteration)) { Py_DECREF(exc_val); PyErr_SetString(PyExc_TypeError, "StopIteration interacts badly with generators " @@ -603,33 +603,33 @@ future_set_exception(FutureObj *fut, PyObject *exc) Py_RETURN_NONE; } -static PyObject * -create_cancelled_error(PyObject *msg) -{ - PyObject *exc; - if (msg == NULL || msg == Py_None) { - exc = PyObject_CallNoArgs(asyncio_CancelledError); - } else { - exc = PyObject_CallOneArg(asyncio_CancelledError, msg); - } - return exc; -} - -static void -future_set_cancelled_error(FutureObj *fut) -{ - PyObject *exc = create_cancelled_error(fut->fut_cancel_msg); - PyErr_SetObject(asyncio_CancelledError, exc); - Py_DECREF(exc); - - _PyErr_ChainStackItem(&fut->fut_cancelled_exc_state); -} - +static PyObject * +create_cancelled_error(PyObject *msg) +{ + PyObject *exc; + if (msg == NULL || msg == Py_None) { + exc = PyObject_CallNoArgs(asyncio_CancelledError); + } else { + exc = PyObject_CallOneArg(asyncio_CancelledError, msg); + } + return exc; +} + +static void +future_set_cancelled_error(FutureObj *fut) +{ + PyObject *exc = create_cancelled_error(fut->fut_cancel_msg); + PyErr_SetObject(asyncio_CancelledError, exc); + Py_DECREF(exc); + + _PyErr_ChainStackItem(&fut->fut_cancelled_exc_state); +} + static int future_get_result(FutureObj *fut, PyObject **result) { if (fut->fut_state == STATE_CANCELLED) { - future_set_cancelled_error(fut); + future_set_cancelled_error(fut); return -1; } @@ -726,7 +726,7 @@ future_add_done_callback(FutureObj *fut, PyObject *arg, PyObject *ctx) } static PyObject * -future_cancel(FutureObj *fut, PyObject *msg) +future_cancel(FutureObj *fut, PyObject *msg) { fut->fut_log_tb = 0; @@ -735,9 +735,9 @@ future_cancel(FutureObj *fut, PyObject *msg) } fut->fut_state = STATE_CANCELLED; - Py_XINCREF(msg); - Py_XSETREF(fut->fut_cancel_msg, msg); - + Py_XINCREF(msg); + Py_XSETREF(fut->fut_cancel_msg, msg); + if (future_schedule_callbacks(fut) == -1) { return NULL; } @@ -783,8 +783,8 @@ FutureObj_clear(FutureObj *fut) Py_CLEAR(fut->fut_result); Py_CLEAR(fut->fut_exception); Py_CLEAR(fut->fut_source_tb); - Py_CLEAR(fut->fut_cancel_msg); - _PyErr_ClearExcState(&fut->fut_cancelled_exc_state); + Py_CLEAR(fut->fut_cancel_msg); + _PyErr_ClearExcState(&fut->fut_cancelled_exc_state); Py_CLEAR(fut->dict); return 0; } @@ -799,14 +799,14 @@ FutureObj_traverse(FutureObj *fut, visitproc visit, void *arg) Py_VISIT(fut->fut_result); Py_VISIT(fut->fut_exception); Py_VISIT(fut->fut_source_tb); - Py_VISIT(fut->fut_cancel_msg); + Py_VISIT(fut->fut_cancel_msg); Py_VISIT(fut->dict); - - _PyErr_StackItem *exc_state = &fut->fut_cancelled_exc_state; - Py_VISIT(exc_state->exc_type); - Py_VISIT(exc_state->exc_value); - Py_VISIT(exc_state->exc_traceback); - + + _PyErr_StackItem *exc_state = &fut->fut_cancelled_exc_state; + Py_VISIT(exc_state->exc_type); + Py_VISIT(exc_state->exc_value); + Py_VISIT(exc_state->exc_traceback); + return 0; } @@ -871,7 +871,7 @@ _asyncio_Future_exception_impl(FutureObj *self) } if (self->fut_state == STATE_CANCELLED) { - future_set_cancelled_error(self); + future_set_cancelled_error(self); return NULL; } @@ -983,7 +983,7 @@ _asyncio_Future_remove_done_callback(FutureObj *self, PyObject *fn) ENSURE_FUTURE_ALIVE(self) if (self->fut_callback0 != NULL) { - int cmp = PyObject_RichCompareBool(self->fut_callback0, fn, Py_EQ); + int cmp = PyObject_RichCompareBool(self->fut_callback0, fn, Py_EQ); if (cmp == -1) { return NULL; } @@ -1008,7 +1008,7 @@ _asyncio_Future_remove_done_callback(FutureObj *self, PyObject *fn) if (len == 1) { PyObject *cb_tup = PyList_GET_ITEM(self->fut_callbacks, 0); int cmp = PyObject_RichCompareBool( - PyTuple_GET_ITEM(cb_tup, 0), fn, Py_EQ); + PyTuple_GET_ITEM(cb_tup, 0), fn, Py_EQ); if (cmp == -1) { return NULL; } @@ -1030,7 +1030,7 @@ _asyncio_Future_remove_done_callback(FutureObj *self, PyObject *fn) int ret; PyObject *item = PyList_GET_ITEM(self->fut_callbacks, i); Py_INCREF(item); - ret = PyObject_RichCompareBool(PyTuple_GET_ITEM(item, 0), fn, Py_EQ); + ret = PyObject_RichCompareBool(PyTuple_GET_ITEM(item, 0), fn, Py_EQ); if (ret == 0) { if (j < len) { PyList_SET_ITEM(newlist, j, item); @@ -1052,7 +1052,7 @@ _asyncio_Future_remove_done_callback(FutureObj *self, PyObject *fn) } if (j < len) { - Py_SET_SIZE(newlist, j); + Py_SET_SIZE(newlist, j); } j = PyList_GET_SIZE(newlist); len = PyList_GET_SIZE(self->fut_callbacks); @@ -1072,8 +1072,8 @@ fail: /*[clinic input] _asyncio.Future.cancel - msg: object = None - + msg: object = None + Cancel the future and schedule callbacks. If the future is already done or cancelled, return False. Otherwise, @@ -1082,11 +1082,11 @@ return True. [clinic start generated code]*/ static PyObject * -_asyncio_Future_cancel_impl(FutureObj *self, PyObject *msg) -/*[clinic end generated code: output=3edebbc668e5aba3 input=925eb545251f2c5a]*/ +_asyncio_Future_cancel_impl(FutureObj *self, PyObject *msg) +/*[clinic end generated code: output=3edebbc668e5aba3 input=925eb545251f2c5a]*/ { ENSURE_FUTURE_ALIVE(self) - return future_cancel(self, msg); + return future_cancel(self, msg); } /*[clinic input] @@ -1138,7 +1138,7 @@ static PyObject * _asyncio_Future_get_loop_impl(FutureObj *self) /*[clinic end generated code: output=119b6ea0c9816c3f input=cba48c2136c79d1f]*/ { - ENSURE_FUTURE_ALIVE(self) + ENSURE_FUTURE_ALIVE(self) Py_INCREF(self->fut_loop); return self->fut_loop; } @@ -1300,29 +1300,29 @@ FutureObj_get_source_traceback(FutureObj *fut, void *Py_UNUSED(ignored)) } static PyObject * -FutureObj_get_cancel_message(FutureObj *fut, void *Py_UNUSED(ignored)) -{ - if (fut->fut_cancel_msg == NULL) { - Py_RETURN_NONE; - } - Py_INCREF(fut->fut_cancel_msg); - return fut->fut_cancel_msg; -} - -static int -FutureObj_set_cancel_message(FutureObj *fut, PyObject *msg, - void *Py_UNUSED(ignored)) -{ - if (msg == NULL) { - PyErr_SetString(PyExc_AttributeError, "cannot delete attribute"); - return -1; - } - Py_INCREF(msg); - Py_XSETREF(fut->fut_cancel_msg, msg); - return 0; -} - -static PyObject * +FutureObj_get_cancel_message(FutureObj *fut, void *Py_UNUSED(ignored)) +{ + if (fut->fut_cancel_msg == NULL) { + Py_RETURN_NONE; + } + Py_INCREF(fut->fut_cancel_msg); + return fut->fut_cancel_msg; +} + +static int +FutureObj_set_cancel_message(FutureObj *fut, PyObject *msg, + void *Py_UNUSED(ignored)) +{ + if (msg == NULL) { + PyErr_SetString(PyExc_AttributeError, "cannot delete attribute"); + return -1; + } + Py_INCREF(msg); + Py_XSETREF(fut->fut_cancel_msg, msg); + return 0; +} + +static PyObject * FutureObj_get_state(FutureObj *fut, void *Py_UNUSED(ignored)) { _Py_IDENTIFIER(PENDING); @@ -1350,29 +1350,29 @@ FutureObj_get_state(FutureObj *fut, void *Py_UNUSED(ignored)) } /*[clinic input] -_asyncio.Future._make_cancelled_error - -Create the CancelledError to raise if the Future is cancelled. - -This should only be called once when handling a cancellation since -it erases the context exception value. -[clinic start generated code]*/ - -static PyObject * -_asyncio_Future__make_cancelled_error_impl(FutureObj *self) -/*[clinic end generated code: output=a5df276f6c1213de input=ac6effe4ba795ecc]*/ -{ - PyObject *exc = create_cancelled_error(self->fut_cancel_msg); - _PyErr_StackItem *exc_state = &self->fut_cancelled_exc_state; - /* Transfer ownership of exc_value from exc_state to exc since we are - done with it. */ - PyException_SetContext(exc, exc_state->exc_value); - exc_state->exc_value = NULL; - - return exc; -} - -/*[clinic input] +_asyncio.Future._make_cancelled_error + +Create the CancelledError to raise if the Future is cancelled. + +This should only be called once when handling a cancellation since +it erases the context exception value. +[clinic start generated code]*/ + +static PyObject * +_asyncio_Future__make_cancelled_error_impl(FutureObj *self) +/*[clinic end generated code: output=a5df276f6c1213de input=ac6effe4ba795ecc]*/ +{ + PyObject *exc = create_cancelled_error(self->fut_cancel_msg); + _PyErr_StackItem *exc_state = &self->fut_cancelled_exc_state; + /* Transfer ownership of exc_value from exc_state to exc since we are + done with it. */ + PyException_SetContext(exc, exc_state->exc_value); + exc_state->exc_value = NULL; + + return exc; +} + +/*[clinic input] _asyncio.Future._repr_info [clinic start generated code]*/ @@ -1380,7 +1380,7 @@ static PyObject * _asyncio_Future__repr_info_impl(FutureObj *self) /*[clinic end generated code: output=fa69e901bd176cfb input=f21504d8e2ae1ca2]*/ { - return PyObject_CallOneArg(asyncio_future_repr_info_func, (PyObject *)self); + return PyObject_CallOneArg(asyncio_future_repr_info_func, (PyObject *)self); } static PyObject * @@ -1390,8 +1390,8 @@ FutureObj_repr(FutureObj *fut) ENSURE_FUTURE_ALIVE(fut) - PyObject *rinfo = _PyObject_CallMethodIdNoArgs((PyObject*)fut, - &PyId__repr_info); + PyObject *rinfo = _PyObject_CallMethodIdNoArgs((PyObject*)fut, + &PyId__repr_info); if (rinfo == NULL) { return NULL; } @@ -1402,8 +1402,8 @@ FutureObj_repr(FutureObj *fut) return NULL; } - PyObject *rstr = PyUnicode_FromFormat("<%s %U>", - _PyType_Name(Py_TYPE(fut)), rinfo_s); + PyObject *rstr = PyUnicode_FromFormat("<%s %U>", + _PyType_Name(Py_TYPE(fut)), rinfo_s); Py_DECREF(rinfo_s); return rstr; } @@ -1437,7 +1437,7 @@ FutureObj_finalize(FutureObj *fut) } message = PyUnicode_FromFormat( - "%s exception was never retrieved", _PyType_Name(Py_TYPE(fut))); + "%s exception was never retrieved", _PyType_Name(Py_TYPE(fut))); if (message == NULL) { goto finally; } @@ -1456,7 +1456,7 @@ FutureObj_finalize(FutureObj *fut) func = _PyObject_GetAttrId(fut->fut_loop, &PyId_call_exception_handler); if (func != NULL) { - PyObject *res = PyObject_CallOneArg(func, context); + PyObject *res = PyObject_CallOneArg(func, context); if (res == NULL) { PyErr_WriteUnraisable(func); } @@ -1474,12 +1474,12 @@ finally: PyErr_Restore(error_type, error_value, error_traceback); } -static PyObject * -future_cls_getitem(PyObject *cls, PyObject *type) -{ - Py_INCREF(cls); - return cls; -} +static PyObject * +future_cls_getitem(PyObject *cls, PyObject *type) +{ + Py_INCREF(cls); + return cls; +} static PyAsyncMethods FutureType_as_async = { (unaryfunc)future_new_iter, /* am_await */ @@ -1498,9 +1498,9 @@ static PyMethodDef FutureType_methods[] = { _ASYNCIO_FUTURE_CANCELLED_METHODDEF _ASYNCIO_FUTURE_DONE_METHODDEF _ASYNCIO_FUTURE_GET_LOOP_METHODDEF - _ASYNCIO_FUTURE__MAKE_CANCELLED_ERROR_METHODDEF + _ASYNCIO_FUTURE__MAKE_CANCELLED_ERROR_METHODDEF _ASYNCIO_FUTURE__REPR_INFO_METHODDEF - {"__class_getitem__", future_cls_getitem, METH_O|METH_CLASS, NULL}, + {"__class_getitem__", future_cls_getitem, METH_O|METH_CLASS, NULL}, {NULL, NULL} /* Sentinel */ }; @@ -1514,10 +1514,10 @@ static PyMethodDef FutureType_methods[] = { {"_exception", (getter)FutureObj_get_exception, NULL, NULL}, \ {"_log_traceback", (getter)FutureObj_get_log_traceback, \ (setter)FutureObj_set_log_traceback, NULL}, \ - {"_source_traceback", (getter)FutureObj_get_source_traceback, \ - NULL, NULL}, \ - {"_cancel_message", (getter)FutureObj_get_cancel_message, \ - (setter)FutureObj_set_cancel_message, NULL}, + {"_source_traceback", (getter)FutureObj_get_source_traceback, \ + NULL, NULL}, \ + {"_cancel_message", (getter)FutureObj_get_cancel_message, \ + (setter)FutureObj_set_cancel_message, NULL}, static PyGetSetDef FutureType_getsetlist[] = { FUTURE_COMMON_GETSETLIST @@ -1533,7 +1533,7 @@ static PyTypeObject FutureType = { .tp_dealloc = FutureObj_dealloc, .tp_as_async = &FutureType_as_async, .tp_repr = (reprfunc)FutureObj_repr, - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, .tp_doc = _asyncio_Future___init____doc__, .tp_traverse = (traverseproc)FutureObj_traverse, .tp_clear = (inquiry)FutureObj_clear, @@ -1639,7 +1639,7 @@ static PyObject * FutureIter_send(futureiterobject *self, PyObject *unused) { /* Future.__iter__ doesn't care about values that are pushed to the - * generator, it just returns self.result(). + * generator, it just returns self.result(). */ return FutureIter_iternext(self); } @@ -1912,21 +1912,21 @@ TaskWakeupMethWrapper_dealloc(TaskWakeupMethWrapper *o) Py_TYPE(o)->tp_free(o); } -static PyObject * -TaskWakeupMethWrapper_get___self__(TaskWakeupMethWrapper *o, void *Py_UNUSED(ignored)) -{ - if (o->ww_task) { - Py_INCREF(o->ww_task); - return (PyObject*)o->ww_task; - } - Py_RETURN_NONE; -} - -static PyGetSetDef TaskWakeupMethWrapper_getsetlist[] = { - {"__self__", (getter)TaskWakeupMethWrapper_get___self__, NULL, NULL}, - {NULL} /* Sentinel */ -}; - +static PyObject * +TaskWakeupMethWrapper_get___self__(TaskWakeupMethWrapper *o, void *Py_UNUSED(ignored)) +{ + if (o->ww_task) { + Py_INCREF(o->ww_task); + return (PyObject*)o->ww_task; + } + Py_RETURN_NONE; +} + +static PyGetSetDef TaskWakeupMethWrapper_getsetlist[] = { + {"__self__", (getter)TaskWakeupMethWrapper_get___self__, NULL, NULL}, + {NULL} /* Sentinel */ +}; + static PyTypeObject TaskWakeupMethWrapper_Type = { PyVarObject_HEAD_INIT(NULL, 0) "TaskWakeupMethWrapper", @@ -1938,7 +1938,7 @@ static PyTypeObject TaskWakeupMethWrapper_Type = { .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, .tp_traverse = (traverseproc)TaskWakeupMethWrapper_traverse, .tp_clear = (inquiry)TaskWakeupMethWrapper_clear, - .tp_getset = TaskWakeupMethWrapper_getsetlist, + .tp_getset = TaskWakeupMethWrapper_getsetlist, }; static PyObject * @@ -1964,8 +1964,8 @@ register_task(PyObject *task) { _Py_IDENTIFIER(add); - PyObject *res = _PyObject_CallMethodIdOneArg(all_tasks, - &PyId_add, task); + PyObject *res = _PyObject_CallMethodIdOneArg(all_tasks, + &PyId_add, task); if (res == NULL) { return -1; } @@ -1979,8 +1979,8 @@ unregister_task(PyObject *task) { _Py_IDENTIFIER(discard); - PyObject *res = _PyObject_CallMethodIdOneArg(all_tasks, - &PyId_discard, task); + PyObject *res = _PyObject_CallMethodIdOneArg(all_tasks, + &PyId_discard, task); if (res == NULL) { return -1; } @@ -2049,15 +2049,15 @@ _asyncio.Task.__init__ coro: object * loop: object = None - name: object = None + name: object = None A coroutine wrapped in a Future. [clinic start generated code]*/ static int -_asyncio_Task___init___impl(TaskObj *self, PyObject *coro, PyObject *loop, - PyObject *name) -/*[clinic end generated code: output=88b12b83d570df50 input=352a3137fe60091d]*/ +_asyncio_Task___init___impl(TaskObj *self, PyObject *coro, PyObject *loop, + PyObject *name) +/*[clinic end generated code: output=88b12b83d570df50 input=352a3137fe60091d]*/ { if (future_init((FutureObj*)self, loop)) { return -1; @@ -2086,18 +2086,18 @@ _asyncio_Task___init___impl(TaskObj *self, PyObject *coro, PyObject *loop, Py_INCREF(coro); Py_XSETREF(self->task_coro, coro); - if (name == Py_None) { - name = PyUnicode_FromFormat("Task-%" PRIu64, ++task_name_counter); - } else if (!PyUnicode_CheckExact(name)) { - name = PyObject_Str(name); - } else { - Py_INCREF(name); - } - Py_XSETREF(self->task_name, name); - if (self->task_name == NULL) { - return -1; - } - + if (name == Py_None) { + name = PyUnicode_FromFormat("Task-%" PRIu64, ++task_name_counter); + } else if (!PyUnicode_CheckExact(name)) { + name = PyObject_Str(name); + } else { + Py_INCREF(name); + } + Py_XSETREF(self->task_name, name); + if (self->task_name == NULL) { + return -1; + } + if (task_call_step_soon(self, NULL)) { return -1; } @@ -2110,7 +2110,7 @@ TaskObj_clear(TaskObj *task) (void)FutureObj_clear((FutureObj*) task); Py_CLEAR(task->task_context); Py_CLEAR(task->task_coro); - Py_CLEAR(task->task_name); + Py_CLEAR(task->task_name); Py_CLEAR(task->task_fut_waiter); return 0; } @@ -2120,7 +2120,7 @@ TaskObj_traverse(TaskObj *task, visitproc visit, void *arg) { Py_VISIT(task->task_context); Py_VISIT(task->task_coro); - Py_VISIT(task->task_name); + Py_VISIT(task->task_name); Py_VISIT(task->task_fut_waiter); (void)FutureObj_traverse((FutureObj*) task, visit, arg); return 0; @@ -2186,20 +2186,20 @@ TaskObj_get_fut_waiter(TaskObj *task, void *Py_UNUSED(ignored)) } /*[clinic input] -_asyncio.Task._make_cancelled_error +_asyncio.Task._make_cancelled_error -Create the CancelledError to raise if the Task is cancelled. +Create the CancelledError to raise if the Task is cancelled. -This should only be called once when handling a cancellation since -it erases the context exception value. +This should only be called once when handling a cancellation since +it erases the context exception value. [clinic start generated code]*/ static PyObject * -_asyncio_Task__make_cancelled_error_impl(TaskObj *self) -/*[clinic end generated code: output=55a819e8b4276fab input=52c0e32de8e2f840]*/ +_asyncio_Task__make_cancelled_error_impl(TaskObj *self) +/*[clinic end generated code: output=55a819e8b4276fab input=52c0e32de8e2f840]*/ { - FutureObj *fut = (FutureObj*)self; - return _asyncio_Future__make_cancelled_error_impl(fut); + FutureObj *fut = (FutureObj*)self; + return _asyncio_Future__make_cancelled_error_impl(fut); } @@ -2211,14 +2211,14 @@ static PyObject * _asyncio_Task__repr_info_impl(TaskObj *self) /*[clinic end generated code: output=6a490eb66d5ba34b input=3c6d051ed3ddec8b]*/ { - return PyObject_CallOneArg(asyncio_task_repr_info_func, (PyObject *)self); + return PyObject_CallOneArg(asyncio_task_repr_info_func, (PyObject *)self); } /*[clinic input] _asyncio.Task.cancel - msg: object = None - + msg: object = None + Request that this task cancel itself. This arranges for a CancelledError to be thrown into the @@ -2240,8 +2240,8 @@ was not called). [clinic start generated code]*/ static PyObject * -_asyncio_Task_cancel_impl(TaskObj *self, PyObject *msg) -/*[clinic end generated code: output=c66b60d41c74f9f1 input=f4ff8e8ffc5f1c00]*/ +_asyncio_Task_cancel_impl(TaskObj *self, PyObject *msg) +/*[clinic end generated code: output=c66b60d41c74f9f1 input=f4ff8e8ffc5f1c00]*/ { self->task_log_tb = 0; @@ -2253,8 +2253,8 @@ _asyncio_Task_cancel_impl(TaskObj *self, PyObject *msg) PyObject *res; int is_true; - res = _PyObject_CallMethodIdOneArg(self->task_fut_waiter, - &PyId_cancel, msg); + res = _PyObject_CallMethodIdOneArg(self->task_fut_waiter, + &PyId_cancel, msg); if (res == NULL) { return NULL; } @@ -2271,8 +2271,8 @@ _asyncio_Task_cancel_impl(TaskObj *self, PyObject *msg) } self->task_must_cancel = 1; - Py_XINCREF(msg); - Py_XSETREF(self->task_cancel_msg, msg); + Py_XINCREF(msg); + Py_XSETREF(self->task_cancel_msg, msg); Py_RETURN_TRUE; } @@ -2368,58 +2368,58 @@ _asyncio_Task_set_exception(TaskObj *self, PyObject *exception) return NULL; } -/*[clinic input] -_asyncio.Task.get_coro -[clinic start generated code]*/ - -static PyObject * -_asyncio_Task_get_coro_impl(TaskObj *self) -/*[clinic end generated code: output=bcac27c8cc6c8073 input=d2e8606c42a7b403]*/ -{ - Py_INCREF(self->task_coro); - return self->task_coro; -} - -/*[clinic input] -_asyncio.Task.get_name -[clinic start generated code]*/ - -static PyObject * -_asyncio_Task_get_name_impl(TaskObj *self) -/*[clinic end generated code: output=0ecf1570c3b37a8f input=a4a6595d12f4f0f8]*/ -{ - if (self->task_name) { - Py_INCREF(self->task_name); - return self->task_name; - } - - Py_RETURN_NONE; -} - -/*[clinic input] -_asyncio.Task.set_name - - value: object - / -[clinic start generated code]*/ - -static PyObject * -_asyncio_Task_set_name(TaskObj *self, PyObject *value) -/*[clinic end generated code: output=138a8d51e32057d6 input=a8359b6e65f8fd31]*/ -{ - if (!PyUnicode_CheckExact(value)) { - value = PyObject_Str(value); - if (value == NULL) { - return NULL; - } - } else { - Py_INCREF(value); - } - - Py_XSETREF(self->task_name, value); - Py_RETURN_NONE; -} - +/*[clinic input] +_asyncio.Task.get_coro +[clinic start generated code]*/ + +static PyObject * +_asyncio_Task_get_coro_impl(TaskObj *self) +/*[clinic end generated code: output=bcac27c8cc6c8073 input=d2e8606c42a7b403]*/ +{ + Py_INCREF(self->task_coro); + return self->task_coro; +} + +/*[clinic input] +_asyncio.Task.get_name +[clinic start generated code]*/ + +static PyObject * +_asyncio_Task_get_name_impl(TaskObj *self) +/*[clinic end generated code: output=0ecf1570c3b37a8f input=a4a6595d12f4f0f8]*/ +{ + if (self->task_name) { + Py_INCREF(self->task_name); + return self->task_name; + } + + Py_RETURN_NONE; +} + +/*[clinic input] +_asyncio.Task.set_name + + value: object + / +[clinic start generated code]*/ + +static PyObject * +_asyncio_Task_set_name(TaskObj *self, PyObject *value) +/*[clinic end generated code: output=138a8d51e32057d6 input=a8359b6e65f8fd31]*/ +{ + if (!PyUnicode_CheckExact(value)) { + value = PyObject_Str(value); + if (value == NULL) { + return NULL; + } + } else { + Py_INCREF(value); + } + + Py_XSETREF(self->task_name, value); + Py_RETURN_NONE; +} + static void TaskObj_finalize(TaskObj *task) { @@ -2466,7 +2466,7 @@ TaskObj_finalize(TaskObj *task) func = _PyObject_GetAttrId(task->task_loop, &PyId_call_exception_handler); if (func != NULL) { - PyObject *res = PyObject_CallOneArg(func, context); + PyObject *res = PyObject_CallOneArg(func, context); if (res == NULL) { PyErr_WriteUnraisable(func); } @@ -2487,13 +2487,13 @@ done: FutureObj_finalize((FutureObj*)task); } -static PyObject * -task_cls_getitem(PyObject *cls, PyObject *type) -{ - Py_INCREF(cls); - return cls; -} - +static PyObject * +task_cls_getitem(PyObject *cls, PyObject *type) +{ + Py_INCREF(cls); + return cls; +} + static void TaskObj_dealloc(PyObject *); /* Needs Task_CheckExact */ static PyMethodDef TaskType_methods[] = { @@ -2508,12 +2508,12 @@ static PyMethodDef TaskType_methods[] = { _ASYNCIO_TASK_CANCEL_METHODDEF _ASYNCIO_TASK_GET_STACK_METHODDEF _ASYNCIO_TASK_PRINT_STACK_METHODDEF - _ASYNCIO_TASK__MAKE_CANCELLED_ERROR_METHODDEF + _ASYNCIO_TASK__MAKE_CANCELLED_ERROR_METHODDEF _ASYNCIO_TASK__REPR_INFO_METHODDEF - _ASYNCIO_TASK_GET_NAME_METHODDEF - _ASYNCIO_TASK_SET_NAME_METHODDEF - _ASYNCIO_TASK_GET_CORO_METHODDEF - {"__class_getitem__", task_cls_getitem, METH_O|METH_CLASS, NULL}, + _ASYNCIO_TASK_GET_NAME_METHODDEF + _ASYNCIO_TASK_SET_NAME_METHODDEF + _ASYNCIO_TASK_GET_CORO_METHODDEF + {"__class_getitem__", task_cls_getitem, METH_O|METH_CLASS, NULL}, {NULL, NULL} /* Sentinel */ }; @@ -2535,7 +2535,7 @@ static PyTypeObject TaskType = { .tp_dealloc = TaskObj_dealloc, .tp_as_async = &FutureType_as_async, .tp_repr = (reprfunc)FutureObj_repr, - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, .tp_doc = _asyncio_Task___init____doc__, .tp_traverse = (traverseproc)TaskObj_traverse, .tp_clear = (inquiry)TaskObj_clear, @@ -2605,7 +2605,7 @@ task_set_error_soon(TaskObj *task, PyObject *et, const char *format, ...) return NULL; } - PyObject *e = PyObject_CallOneArg(et, msg); + PyObject *e = PyObject_CallOneArg(et, msg); Py_DECREF(msg); if (e == NULL) { return NULL; @@ -2655,8 +2655,8 @@ task_step_impl(TaskObj *task, PyObject *exc) if (!exc) { /* exc was not a CancelledError */ - exc = create_cancelled_error(task->task_cancel_msg); - + exc = create_cancelled_error(task->task_cancel_msg); + if (!exc) { goto fail; } @@ -2671,10 +2671,10 @@ task_step_impl(TaskObj *task, PyObject *exc) coro = task->task_coro; if (coro == NULL) { PyErr_SetString(PyExc_RuntimeError, "uninitialized Task object"); - if (clear_exc) { - /* We created 'exc' during this call */ - Py_DECREF(exc); - } + if (clear_exc) { + /* We created 'exc' during this call */ + Py_DECREF(exc); + } return NULL; } @@ -2683,11 +2683,11 @@ task_step_impl(TaskObj *task, PyObject *exc) result = _PyGen_Send((PyGenObject*)coro, Py_None); } else { - result = _PyObject_CallMethodIdOneArg(coro, &PyId_send, Py_None); + result = _PyObject_CallMethodIdOneArg(coro, &PyId_send, Py_None); } } else { - result = _PyObject_CallMethodIdOneArg(coro, &PyId_throw, exc); + result = _PyObject_CallMethodIdOneArg(coro, &PyId_throw, exc); if (clear_exc) { /* We created 'exc' during this call */ Py_DECREF(exc); @@ -2700,19 +2700,19 @@ task_step_impl(TaskObj *task, PyObject *exc) if (_PyGen_FetchStopIterationValue(&o) == 0) { /* The error is StopIteration and that means that the underlying coroutine has resolved */ - - PyObject *res; + + PyObject *res; if (task->task_must_cancel) { // Task is cancelled right before coro stops. task->task_must_cancel = 0; - res = future_cancel((FutureObj*)task, task->task_cancel_msg); + res = future_cancel((FutureObj*)task, task->task_cancel_msg); } - else { - res = future_set_result((FutureObj*)task, o); - } - + else { + res = future_set_result((FutureObj*)task, o); + } + Py_DECREF(o); - + if (res == NULL) { return NULL; } @@ -2722,15 +2722,15 @@ task_step_impl(TaskObj *task, PyObject *exc) if (PyErr_ExceptionMatches(asyncio_CancelledError)) { /* CancelledError */ - PyErr_Fetch(&et, &ev, &tb); - - FutureObj *fut = (FutureObj*)task; - _PyErr_StackItem *exc_state = &fut->fut_cancelled_exc_state; - exc_state->exc_type = et; - exc_state->exc_value = ev; - exc_state->exc_traceback = tb; - - return future_cancel(fut, NULL); + PyErr_Fetch(&et, &ev, &tb); + + FutureObj *fut = (FutureObj*)task; + _PyErr_StackItem *exc_state = &fut->fut_cancelled_exc_state; + exc_state->exc_type = et; + exc_state->exc_value = ev; + exc_state->exc_traceback = tb; + + return future_cancel(fut, NULL); } /* Some other exception; pop it and call Task.set_exception() */ @@ -2754,10 +2754,10 @@ task_step_impl(TaskObj *task, PyObject *exc) assert(o == Py_None); Py_DECREF(o); - if (PyErr_GivenExceptionMatches(et, PyExc_KeyboardInterrupt) || - PyErr_GivenExceptionMatches(et, PyExc_SystemExit)) - { - /* We've got a KeyboardInterrupt or a SystemError; re-raise it */ + if (PyErr_GivenExceptionMatches(et, PyExc_KeyboardInterrupt) || + PyErr_GivenExceptionMatches(et, PyExc_SystemExit)) + { + /* We've got a KeyboardInterrupt or a SystemError; re-raise it */ PyErr_Restore(et, ev, tb); goto fail; } @@ -2785,148 +2785,148 @@ task_step_impl(TaskObj *task, PyObject *exc) goto different_loop; } - if (!fut->fut_blocking) { - goto yield_insteadof_yf; - } - - fut->fut_blocking = 0; - - /* result.add_done_callback(task._wakeup) */ - wrapper = TaskWakeupMethWrapper_new(task); - if (wrapper == NULL) { - goto fail; - } - res = future_add_done_callback( - (FutureObj*)result, wrapper, task->task_context); - Py_DECREF(wrapper); - if (res == NULL) { - goto fail; - } - Py_DECREF(res); - - /* task._fut_waiter = result */ - task->task_fut_waiter = result; /* no incref is necessary */ - - if (task->task_must_cancel) { - PyObject *r; - int is_true; - r = _PyObject_CallMethodIdOneArg(result, &PyId_cancel, - task->task_cancel_msg); - if (r == NULL) { - return NULL; + if (!fut->fut_blocking) { + goto yield_insteadof_yf; + } + + fut->fut_blocking = 0; + + /* result.add_done_callback(task._wakeup) */ + wrapper = TaskWakeupMethWrapper_new(task); + if (wrapper == NULL) { + goto fail; + } + res = future_add_done_callback( + (FutureObj*)result, wrapper, task->task_context); + Py_DECREF(wrapper); + if (res == NULL) { + goto fail; + } + Py_DECREF(res); + + /* task._fut_waiter = result */ + task->task_fut_waiter = result; /* no incref is necessary */ + + if (task->task_must_cancel) { + PyObject *r; + int is_true; + r = _PyObject_CallMethodIdOneArg(result, &PyId_cancel, + task->task_cancel_msg); + if (r == NULL) { + return NULL; } - is_true = PyObject_IsTrue(r); - Py_DECREF(r); - if (is_true < 0) { - return NULL; + is_true = PyObject_IsTrue(r); + Py_DECREF(r); + if (is_true < 0) { + return NULL; } - else if (is_true) { - task->task_must_cancel = 0; - } - } + else if (is_true) { + task->task_must_cancel = 0; + } + } - Py_RETURN_NONE; - } + Py_RETURN_NONE; + } - /* Check if `result` is None */ - if (result == Py_None) { - /* Bare yield relinquishes control for one event loop iteration. */ - if (task_call_step_soon(task, NULL)) { - goto fail; + /* Check if `result` is None */ + if (result == Py_None) { + /* Bare yield relinquishes control for one event loop iteration. */ + if (task_call_step_soon(task, NULL)) { + goto fail; } - return result; + return result; } /* Check if `result` is a Future-compatible object */ - if (_PyObject_LookupAttrId(result, &PyId__asyncio_future_blocking, &o) < 0) { - goto fail; - } - if (o != NULL && o != Py_None) { - /* `result` is a Future-compatible object */ - PyObject *wrapper; - PyObject *res; - - int blocking = PyObject_IsTrue(o); - Py_DECREF(o); - if (blocking < 0) { - goto fail; - } - - /* Check if `result` future is attached to a different loop */ - PyObject *oloop = get_future_loop(result); - if (oloop == NULL) { + if (_PyObject_LookupAttrId(result, &PyId__asyncio_future_blocking, &o) < 0) { + goto fail; + } + if (o != NULL && o != Py_None) { + /* `result` is a Future-compatible object */ + PyObject *wrapper; + PyObject *res; + + int blocking = PyObject_IsTrue(o); + Py_DECREF(o); + if (blocking < 0) { + goto fail; + } + + /* Check if `result` future is attached to a different loop */ + PyObject *oloop = get_future_loop(result); + if (oloop == NULL) { goto fail; } - if (oloop != task->task_loop) { - Py_DECREF(oloop); - goto different_loop; - } - Py_DECREF(oloop); - - if (!blocking) { - goto yield_insteadof_yf; - } - - /* result._asyncio_future_blocking = False */ - if (_PyObject_SetAttrId( - result, &PyId__asyncio_future_blocking, Py_False) == -1) { - goto fail; - } - - wrapper = TaskWakeupMethWrapper_new(task); - if (wrapper == NULL) { - goto fail; - } - - /* result.add_done_callback(task._wakeup) */ - PyObject *add_cb = _PyObject_GetAttrId( - result, &PyId_add_done_callback); - if (add_cb == NULL) { - Py_DECREF(wrapper); - goto fail; - } - PyObject *stack[2]; - stack[0] = wrapper; - stack[1] = (PyObject *)task->task_context; - res = PyObject_Vectorcall(add_cb, stack, 1, context_kwname); - Py_DECREF(add_cb); - Py_DECREF(wrapper); - if (res == NULL) { - goto fail; - } - Py_DECREF(res); - - /* task._fut_waiter = result */ - task->task_fut_waiter = result; /* no incref is necessary */ - - if (task->task_must_cancel) { - PyObject *r; - int is_true; - r = _PyObject_CallMethodIdOneArg(result, &PyId_cancel, - task->task_cancel_msg); - if (r == NULL) { - return NULL; + if (oloop != task->task_loop) { + Py_DECREF(oloop); + goto different_loop; + } + Py_DECREF(oloop); + + if (!blocking) { + goto yield_insteadof_yf; + } + + /* result._asyncio_future_blocking = False */ + if (_PyObject_SetAttrId( + result, &PyId__asyncio_future_blocking, Py_False) == -1) { + goto fail; + } + + wrapper = TaskWakeupMethWrapper_new(task); + if (wrapper == NULL) { + goto fail; + } + + /* result.add_done_callback(task._wakeup) */ + PyObject *add_cb = _PyObject_GetAttrId( + result, &PyId_add_done_callback); + if (add_cb == NULL) { + Py_DECREF(wrapper); + goto fail; + } + PyObject *stack[2]; + stack[0] = wrapper; + stack[1] = (PyObject *)task->task_context; + res = PyObject_Vectorcall(add_cb, stack, 1, context_kwname); + Py_DECREF(add_cb); + Py_DECREF(wrapper); + if (res == NULL) { + goto fail; + } + Py_DECREF(res); + + /* task._fut_waiter = result */ + task->task_fut_waiter = result; /* no incref is necessary */ + + if (task->task_must_cancel) { + PyObject *r; + int is_true; + r = _PyObject_CallMethodIdOneArg(result, &PyId_cancel, + task->task_cancel_msg); + if (r == NULL) { + return NULL; } - is_true = PyObject_IsTrue(r); - Py_DECREF(r); - if (is_true < 0) { - return NULL; - } - else if (is_true) { - task->task_must_cancel = 0; + is_true = PyObject_IsTrue(r); + Py_DECREF(r); + if (is_true < 0) { + return NULL; } + else if (is_true) { + task->task_must_cancel = 0; + } } - Py_RETURN_NONE; + Py_RETURN_NONE; } - Py_XDECREF(o); + Py_XDECREF(o); /* Check if `result` is a generator */ - res = PyObject_IsInstance(result, (PyObject*)&PyGen_Type); - if (res < 0) { + res = PyObject_IsInstance(result, (PyObject*)&PyGen_Type); + if (res < 0) { goto fail; } - if (res) { + if (res) { /* `result` is a generator */ o = task_set_error_soon( task, PyExc_RuntimeError, @@ -2990,7 +2990,7 @@ task_step(TaskObj *task, PyObject *exc) return NULL; } else { - if (leave_task(task->task_loop, (PyObject*)task) < 0) { + if (leave_task(task->task_loop, (PyObject*)task) < 0) { Py_DECREF(res); return NULL; } @@ -3258,9 +3258,9 @@ new_running_loop_holder(PyObject *loop) static void PyRunningLoopHolder_tp_dealloc(PyRunningLoopHolder *rl) { - if (cached_running_holder == (PyObject *)rl) { - cached_running_holder = NULL; - } + if (cached_running_holder == (PyObject *)rl) { + cached_running_holder = NULL; + } Py_CLEAR(rl->rl_loop); PyObject_Free(rl); } @@ -3320,17 +3320,17 @@ module_free(void *m) Py_CLEAR(context_kwname); module_free_freelists(); - - module_initialized = 0; + + module_initialized = 0; } static int module_init(void) { PyObject *module = NULL; - if (module_initialized) { - return 0; - } + if (module_initialized) { + return 0; + } asyncio_mod = PyImport_ImportModule("asyncio"); if (asyncio_mod == NULL) { @@ -3348,7 +3348,7 @@ module_init(void) } - context_kwname = Py_BuildValue("(s)", "context"); + context_kwname = Py_BuildValue("(s)", "context"); if (context_kwname == NULL) { goto fail; } @@ -3371,8 +3371,8 @@ module_init(void) WITH_MOD("asyncio.base_futures") GET_MOD_ATTR(asyncio_future_repr_info_func, "_future_repr_info") - - WITH_MOD("asyncio.exceptions") + + WITH_MOD("asyncio.exceptions") GET_MOD_ATTR(asyncio_InvalidStateError, "InvalidStateError") GET_MOD_ATTR(asyncio_CancelledError, "CancelledError") @@ -3390,13 +3390,13 @@ module_init(void) PyObject *weak_set; WITH_MOD("weakref") GET_MOD_ATTR(weak_set, "WeakSet"); - all_tasks = PyObject_CallNoArgs(weak_set); + all_tasks = PyObject_CallNoArgs(weak_set); Py_CLEAR(weak_set); if (all_tasks == NULL) { goto fail; } - module_initialized = 1; + module_initialized = 1; Py_DECREF(module); return 0; @@ -3448,7 +3448,7 @@ PyInit__asyncio(void) if (PyType_Ready(&TaskStepMethWrapper_Type) < 0) { return NULL; } - if (PyType_Ready(&TaskWakeupMethWrapper_Type) < 0) { + if (PyType_Ready(&TaskWakeupMethWrapper_Type) < 0) { return NULL; } if (PyType_Ready(&PyRunningLoopHolder_Type) < 0) { @@ -3460,28 +3460,28 @@ PyInit__asyncio(void) return NULL; } - /* FutureType and TaskType are made ready by PyModule_AddType() calls below. */ - if (PyModule_AddType(m, &FutureType) < 0) { - Py_DECREF(m); + /* FutureType and TaskType are made ready by PyModule_AddType() calls below. */ + if (PyModule_AddType(m, &FutureType) < 0) { + Py_DECREF(m); return NULL; } - if (PyModule_AddType(m, &TaskType) < 0) { - Py_DECREF(m); + if (PyModule_AddType(m, &TaskType) < 0) { + Py_DECREF(m); return NULL; } Py_INCREF(all_tasks); if (PyModule_AddObject(m, "_all_tasks", all_tasks) < 0) { Py_DECREF(all_tasks); - Py_DECREF(m); + Py_DECREF(m); return NULL; } Py_INCREF(current_tasks); if (PyModule_AddObject(m, "_current_tasks", current_tasks) < 0) { Py_DECREF(current_tasks); - Py_DECREF(m); + Py_DECREF(m); return NULL; } |