_Py_IDENTIFIER(get_loop);
_Py_IDENTIFIER(_loop);
+ PyObject *getloop;
if (Future_CheckExact(fut) || Task_CheckExact(fut)) {
PyObject *loop = ((FutureObj *)fut)->fut_loop;
return loop;
}
- PyObject *getloop = _PyObject_GetAttrId(fut, &PyId_get_loop);
+ if (_PyObject_LookupAttrId(fut, &PyId_get_loop, &getloop) < 0) {
+ return NULL;
+ }
if (getloop != NULL) {
PyObject *res = _PyObject_CallNoArg(getloop);
Py_DECREF(getloop);
return res;
}
- PyErr_Clear();
return _PyObject_GetAttrId(fut, &PyId__loop);
}
}
item = _PyDict_GetItem_KnownHash(current_tasks, loop, hash);
if (item != NULL) {
+ Py_INCREF(item);
PyErr_Format(
PyExc_RuntimeError,
"Cannot enter into task %R while another " \
"task %R is being executed.",
task, item, NULL);
+ Py_DECREF(item);
return -1;
}
- if (_PyDict_SetItem_KnownHash(current_tasks, loop, task, hash) < 0) {
+ if (PyErr_Occurred()) {
return -1;
}
- return 0;
+ return _PyDict_SetItem_KnownHash(current_tasks, loop, task, hash);
}
if (loop == Py_None) {
loop = get_event_loop();
if (loop == NULL) {
+ Py_DECREF(current_task_func);
return NULL;
}
ret = PyObject_CallFunctionObjArgs(current_task_func, loop, NULL);
PyObject *res;
PyObject *all_tasks_func;
- all_tasks_func = _PyObject_GetAttrId(asyncio_mod, &PyId_all_tasks);
- if (all_tasks_func == NULL) {
- return NULL;
- }
-
if (PyErr_WarnEx(PyExc_PendingDeprecationWarning,
"Task.all_tasks() is deprecated, " \
"use asyncio.all_tasks() instead",
return NULL;
}
+ all_tasks_func = _PyObject_GetAttrId(asyncio_mod, &PyId_all_tasks);
+ if (all_tasks_func == NULL) {
+ return NULL;
+ }
+
res = PyObject_CallFunctionObjArgs(all_tasks_func, loop, NULL);
Py_DECREF(all_tasks_func);
return res;
PyObject *add_cb = _PyObject_GetAttrId(
result, &PyId_add_done_callback);
if (add_cb == NULL) {
+ Py_DECREF(wrapper);
goto fail;
}
PyObject *stack[2];
}
if (res == 1) {
/* `result` is a generator */
- PyObject *ret;
- ret = task_set_error_soon(
+ o = task_set_error_soon(
task, PyExc_RuntimeError,
"yield was used instead of yield from for "
- "generator in task %R with %S", task, result);
+ "generator in task %R with %R", task, result);
Py_DECREF(result);
- return ret;
+ return o;
}
/* The `result` is none of the above */
- Py_DECREF(result);
- return task_set_error_soon(
+ o = task_set_error_soon(
task, PyExc_RuntimeError, "Task got bad yield: %R", result);
+ Py_DECREF(result);
+ return o;
self_await:
o = task_set_error_soon(