Coverage Report

Created: 2026-05-30 06:18

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/cpython/Modules/clinic/_asynciomodule.c.h
Line
Count
Source
1
/*[clinic input]
2
preserve
3
[clinic start generated code]*/
4
5
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6
#  include "pycore_gc.h"          // PyGC_Head
7
#  include "pycore_runtime.h"     // _Py_ID()
8
#endif
9
#include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION()
10
#include "pycore_modsupport.h"    // _PyArg_UnpackKeywords()
11
12
PyDoc_STRVAR(_asyncio_Future___init____doc__,
13
"Future(*, loop=None)\n"
14
"--\n"
15
"\n"
16
"This class is *almost* compatible with concurrent.futures.Future.\n"
17
"\n"
18
"    Differences:\n"
19
"\n"
20
"    - result() and exception() do not take a timeout argument and\n"
21
"      raise an exception when the future isn\'t done yet.\n"
22
"\n"
23
"    - Callbacks registered with add_done_callback() are always called\n"
24
"      via the event loop\'s call_soon_threadsafe().\n"
25
"\n"
26
"    - This class is not compatible with the wait() and as_completed()\n"
27
"      methods in the concurrent.futures package.");
28
29
static int
30
_asyncio_Future___init___impl(FutureObj *self, PyObject *loop);
31
32
static int
33
_asyncio_Future___init__(PyObject *self, PyObject *args, PyObject *kwargs)
34
0
{
35
0
    int return_value = -1;
36
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
37
38
0
    #define NUM_KEYWORDS 1
39
0
    static struct {
40
0
        PyGC_Head _this_is_not_used;
41
0
        PyObject_VAR_HEAD
42
0
        Py_hash_t ob_hash;
43
0
        PyObject *ob_item[NUM_KEYWORDS];
44
0
    } _kwtuple = {
45
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
46
0
        .ob_hash = -1,
47
0
        .ob_item = { &_Py_ID(loop), },
48
0
    };
49
0
    #undef NUM_KEYWORDS
50
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
51
52
    #else  // !Py_BUILD_CORE
53
    #  define KWTUPLE NULL
54
    #endif  // !Py_BUILD_CORE
55
56
0
    static const char * const _keywords[] = {"loop", NULL};
57
0
    static _PyArg_Parser _parser = {
58
0
        .keywords = _keywords,
59
0
        .fname = "Future",
60
0
        .kwtuple = KWTUPLE,
61
0
    };
62
0
    #undef KWTUPLE
63
0
    PyObject *argsbuf[1];
64
0
    PyObject * const *fastargs;
65
0
    Py_ssize_t nargs = PyTuple_GET_SIZE(args);
66
0
    Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0;
67
0
    PyObject *loop = Py_None;
68
69
0
    fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
70
0
            /*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
71
0
    if (!fastargs) {
72
0
        goto exit;
73
0
    }
74
0
    if (!noptargs) {
75
0
        goto skip_optional_kwonly;
76
0
    }
77
0
    loop = fastargs[0];
78
0
skip_optional_kwonly:
79
0
    return_value = _asyncio_Future___init___impl((FutureObj *)self, loop);
80
81
0
exit:
82
0
    return return_value;
83
0
}
84
85
PyDoc_STRVAR(_asyncio_Future_result__doc__,
86
"result($self, /)\n"
87
"--\n"
88
"\n"
89
"Return the result this future represents.\n"
90
"\n"
91
"If the future has been cancelled, raises CancelledError.  If the\n"
92
"future\'s result isn\'t yet available, raises InvalidStateError.  If\n"
93
"the future is done and has an exception set, this exception is\n"
94
"raised.");
95
96
#define _ASYNCIO_FUTURE_RESULT_METHODDEF    \
97
    {"result", (PyCFunction)_asyncio_Future_result, METH_NOARGS, _asyncio_Future_result__doc__},
98
99
static PyObject *
100
_asyncio_Future_result_impl(FutureObj *self);
101
102
static PyObject *
103
_asyncio_Future_result(PyObject *self, PyObject *Py_UNUSED(ignored))
104
0
{
105
0
    PyObject *return_value = NULL;
106
107
0
    Py_BEGIN_CRITICAL_SECTION(self);
108
0
    return_value = _asyncio_Future_result_impl((FutureObj *)self);
109
0
    Py_END_CRITICAL_SECTION();
110
111
0
    return return_value;
112
0
}
113
114
PyDoc_STRVAR(_asyncio_Future_exception__doc__,
115
"exception($self, /)\n"
116
"--\n"
117
"\n"
118
"Return the exception that was set on this future.\n"
119
"\n"
120
"The exception (or None if no exception was set) is returned only if\n"
121
"the future is done.  If the future has been cancelled, raises\n"
122
"CancelledError.  If the future isn\'t done yet, raises\n"
123
"InvalidStateError.");
124
125
#define _ASYNCIO_FUTURE_EXCEPTION_METHODDEF    \
126
    {"exception", _PyCFunction_CAST(_asyncio_Future_exception), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _asyncio_Future_exception__doc__},
127
128
static PyObject *
129
_asyncio_Future_exception_impl(FutureObj *self, PyTypeObject *cls);
130
131
static PyObject *
132
_asyncio_Future_exception(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
133
0
{
134
0
    PyObject *return_value = NULL;
135
136
0
    if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
137
0
        PyErr_SetString(PyExc_TypeError, "exception() takes no arguments");
138
0
        goto exit;
139
0
    }
140
0
    Py_BEGIN_CRITICAL_SECTION(self);
141
0
    return_value = _asyncio_Future_exception_impl((FutureObj *)self, cls);
142
0
    Py_END_CRITICAL_SECTION();
143
144
0
exit:
145
0
    return return_value;
146
0
}
147
148
PyDoc_STRVAR(_asyncio_Future_set_result__doc__,
149
"set_result($self, result, /)\n"
150
"--\n"
151
"\n"
152
"Mark the future done and set its result.\n"
153
"\n"
154
"If the future is already done when this method is called, raises\n"
155
"InvalidStateError.");
156
157
#define _ASYNCIO_FUTURE_SET_RESULT_METHODDEF    \
158
    {"set_result", _PyCFunction_CAST(_asyncio_Future_set_result), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _asyncio_Future_set_result__doc__},
159
160
static PyObject *
161
_asyncio_Future_set_result_impl(FutureObj *self, PyTypeObject *cls,
162
                                PyObject *result);
163
164
static PyObject *
165
_asyncio_Future_set_result(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
166
0
{
167
0
    PyObject *return_value = NULL;
168
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
169
0
    #  define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
170
    #else
171
    #  define KWTUPLE NULL
172
    #endif
173
174
0
    static const char * const _keywords[] = {"", NULL};
175
0
    static _PyArg_Parser _parser = {
176
0
        .keywords = _keywords,
177
0
        .fname = "set_result",
178
0
        .kwtuple = KWTUPLE,
179
0
    };
180
0
    #undef KWTUPLE
181
0
    PyObject *argsbuf[1];
182
0
    PyObject *result;
183
184
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
185
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
186
0
    if (!args) {
187
0
        goto exit;
188
0
    }
189
0
    result = args[0];
190
0
    Py_BEGIN_CRITICAL_SECTION(self);
191
0
    return_value = _asyncio_Future_set_result_impl((FutureObj *)self, cls, result);
192
0
    Py_END_CRITICAL_SECTION();
193
194
0
exit:
195
0
    return return_value;
196
0
}
197
198
PyDoc_STRVAR(_asyncio_Future_set_exception__doc__,
199
"set_exception($self, exception, /)\n"
200
"--\n"
201
"\n"
202
"Mark the future done and set an exception.\n"
203
"\n"
204
"If the future is already done when this method is called, raises\n"
205
"InvalidStateError.");
206
207
#define _ASYNCIO_FUTURE_SET_EXCEPTION_METHODDEF    \
208
    {"set_exception", _PyCFunction_CAST(_asyncio_Future_set_exception), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _asyncio_Future_set_exception__doc__},
209
210
static PyObject *
211
_asyncio_Future_set_exception_impl(FutureObj *self, PyTypeObject *cls,
212
                                   PyObject *exception);
213
214
static PyObject *
215
_asyncio_Future_set_exception(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
216
0
{
217
0
    PyObject *return_value = NULL;
218
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
219
0
    #  define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
220
    #else
221
    #  define KWTUPLE NULL
222
    #endif
223
224
0
    static const char * const _keywords[] = {"", NULL};
225
0
    static _PyArg_Parser _parser = {
226
0
        .keywords = _keywords,
227
0
        .fname = "set_exception",
228
0
        .kwtuple = KWTUPLE,
229
0
    };
230
0
    #undef KWTUPLE
231
0
    PyObject *argsbuf[1];
232
0
    PyObject *exception;
233
234
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
235
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
236
0
    if (!args) {
237
0
        goto exit;
238
0
    }
239
0
    exception = args[0];
240
0
    Py_BEGIN_CRITICAL_SECTION(self);
241
0
    return_value = _asyncio_Future_set_exception_impl((FutureObj *)self, cls, exception);
242
0
    Py_END_CRITICAL_SECTION();
243
244
0
exit:
245
0
    return return_value;
246
0
}
247
248
PyDoc_STRVAR(_asyncio_Future_add_done_callback__doc__,
249
"add_done_callback($self, fn, /, *, context=<unrepresentable>)\n"
250
"--\n"
251
"\n"
252
"Add a callback to be run when the future becomes done.\n"
253
"\n"
254
"The callback is called with a single argument - the future object.\n"
255
"If the future is already done when this is called, the callback is\n"
256
"scheduled with call_soon.");
257
258
#define _ASYNCIO_FUTURE_ADD_DONE_CALLBACK_METHODDEF    \
259
    {"add_done_callback", _PyCFunction_CAST(_asyncio_Future_add_done_callback), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _asyncio_Future_add_done_callback__doc__},
260
261
static PyObject *
262
_asyncio_Future_add_done_callback_impl(FutureObj *self, PyTypeObject *cls,
263
                                       PyObject *fn, PyObject *context);
264
265
static PyObject *
266
_asyncio_Future_add_done_callback(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
267
0
{
268
0
    PyObject *return_value = NULL;
269
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
270
271
0
    #define NUM_KEYWORDS 1
272
0
    static struct {
273
0
        PyGC_Head _this_is_not_used;
274
0
        PyObject_VAR_HEAD
275
0
        Py_hash_t ob_hash;
276
0
        PyObject *ob_item[NUM_KEYWORDS];
277
0
    } _kwtuple = {
278
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
279
0
        .ob_hash = -1,
280
0
        .ob_item = { &_Py_ID(context), },
281
0
    };
282
0
    #undef NUM_KEYWORDS
283
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
284
285
    #else  // !Py_BUILD_CORE
286
    #  define KWTUPLE NULL
287
    #endif  // !Py_BUILD_CORE
288
289
0
    static const char * const _keywords[] = {"", "context", NULL};
290
0
    static _PyArg_Parser _parser = {
291
0
        .keywords = _keywords,
292
0
        .fname = "add_done_callback",
293
0
        .kwtuple = KWTUPLE,
294
0
    };
295
0
    #undef KWTUPLE
296
0
    PyObject *argsbuf[2];
297
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
298
0
    PyObject *fn;
299
0
    PyObject *context = NULL;
300
301
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
302
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
303
0
    if (!args) {
304
0
        goto exit;
305
0
    }
306
0
    fn = args[0];
307
0
    if (!noptargs) {
308
0
        goto skip_optional_kwonly;
309
0
    }
310
0
    context = args[1];
311
0
skip_optional_kwonly:
312
0
    Py_BEGIN_CRITICAL_SECTION(self);
313
0
    return_value = _asyncio_Future_add_done_callback_impl((FutureObj *)self, cls, fn, context);
314
0
    Py_END_CRITICAL_SECTION();
315
316
0
exit:
317
0
    return return_value;
318
0
}
319
320
PyDoc_STRVAR(_asyncio_Future_remove_done_callback__doc__,
321
"remove_done_callback($self, fn, /)\n"
322
"--\n"
323
"\n"
324
"Remove all instances of a callback from the \"call when done\" list.\n"
325
"\n"
326
"Returns the number of callbacks removed.");
327
328
#define _ASYNCIO_FUTURE_REMOVE_DONE_CALLBACK_METHODDEF    \
329
    {"remove_done_callback", _PyCFunction_CAST(_asyncio_Future_remove_done_callback), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _asyncio_Future_remove_done_callback__doc__},
330
331
static PyObject *
332
_asyncio_Future_remove_done_callback_impl(FutureObj *self, PyTypeObject *cls,
333
                                          PyObject *fn);
334
335
static PyObject *
336
_asyncio_Future_remove_done_callback(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
337
0
{
338
0
    PyObject *return_value = NULL;
339
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
340
0
    #  define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
341
    #else
342
    #  define KWTUPLE NULL
343
    #endif
344
345
0
    static const char * const _keywords[] = {"", NULL};
346
0
    static _PyArg_Parser _parser = {
347
0
        .keywords = _keywords,
348
0
        .fname = "remove_done_callback",
349
0
        .kwtuple = KWTUPLE,
350
0
    };
351
0
    #undef KWTUPLE
352
0
    PyObject *argsbuf[1];
353
0
    PyObject *fn;
354
355
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
356
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
357
0
    if (!args) {
358
0
        goto exit;
359
0
    }
360
0
    fn = args[0];
361
0
    Py_BEGIN_CRITICAL_SECTION(self);
362
0
    return_value = _asyncio_Future_remove_done_callback_impl((FutureObj *)self, cls, fn);
363
0
    Py_END_CRITICAL_SECTION();
364
365
0
exit:
366
0
    return return_value;
367
0
}
368
369
PyDoc_STRVAR(_asyncio_Future_cancel__doc__,
370
"cancel($self, /, msg=None)\n"
371
"--\n"
372
"\n"
373
"Cancel the future and schedule callbacks.\n"
374
"\n"
375
"If the future is already done or cancelled, return False.\n"
376
"Otherwise, change the future\'s state to cancelled, schedule the\n"
377
"callbacks and return True.");
378
379
#define _ASYNCIO_FUTURE_CANCEL_METHODDEF    \
380
    {"cancel", _PyCFunction_CAST(_asyncio_Future_cancel), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _asyncio_Future_cancel__doc__},
381
382
static PyObject *
383
_asyncio_Future_cancel_impl(FutureObj *self, PyTypeObject *cls,
384
                            PyObject *msg);
385
386
static PyObject *
387
_asyncio_Future_cancel(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
388
0
{
389
0
    PyObject *return_value = NULL;
390
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
391
392
0
    #define NUM_KEYWORDS 1
393
0
    static struct {
394
0
        PyGC_Head _this_is_not_used;
395
0
        PyObject_VAR_HEAD
396
0
        Py_hash_t ob_hash;
397
0
        PyObject *ob_item[NUM_KEYWORDS];
398
0
    } _kwtuple = {
399
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
400
0
        .ob_hash = -1,
401
0
        .ob_item = { &_Py_ID(msg), },
402
0
    };
403
0
    #undef NUM_KEYWORDS
404
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
405
406
    #else  // !Py_BUILD_CORE
407
    #  define KWTUPLE NULL
408
    #endif  // !Py_BUILD_CORE
409
410
0
    static const char * const _keywords[] = {"msg", NULL};
411
0
    static _PyArg_Parser _parser = {
412
0
        .keywords = _keywords,
413
0
        .fname = "cancel",
414
0
        .kwtuple = KWTUPLE,
415
0
    };
416
0
    #undef KWTUPLE
417
0
    PyObject *argsbuf[1];
418
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
419
0
    PyObject *msg = Py_None;
420
421
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
422
0
            /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
423
0
    if (!args) {
424
0
        goto exit;
425
0
    }
426
0
    if (!noptargs) {
427
0
        goto skip_optional_pos;
428
0
    }
429
0
    msg = args[0];
430
0
skip_optional_pos:
431
0
    Py_BEGIN_CRITICAL_SECTION(self);
432
0
    return_value = _asyncio_Future_cancel_impl((FutureObj *)self, cls, msg);
433
0
    Py_END_CRITICAL_SECTION();
434
435
0
exit:
436
0
    return return_value;
437
0
}
438
439
PyDoc_STRVAR(_asyncio_Future_cancelled__doc__,
440
"cancelled($self, /)\n"
441
"--\n"
442
"\n"
443
"Return True if the future was cancelled.");
444
445
#define _ASYNCIO_FUTURE_CANCELLED_METHODDEF    \
446
    {"cancelled", (PyCFunction)_asyncio_Future_cancelled, METH_NOARGS, _asyncio_Future_cancelled__doc__},
447
448
static PyObject *
449
_asyncio_Future_cancelled_impl(FutureObj *self);
450
451
static PyObject *
452
_asyncio_Future_cancelled(PyObject *self, PyObject *Py_UNUSED(ignored))
453
0
{
454
0
    PyObject *return_value = NULL;
455
456
0
    Py_BEGIN_CRITICAL_SECTION(self);
457
0
    return_value = _asyncio_Future_cancelled_impl((FutureObj *)self);
458
0
    Py_END_CRITICAL_SECTION();
459
460
0
    return return_value;
461
0
}
462
463
PyDoc_STRVAR(_asyncio_Future_done__doc__,
464
"done($self, /)\n"
465
"--\n"
466
"\n"
467
"Return True if the future is done.\n"
468
"\n"
469
"Done means either that a result / exception are available, or that\n"
470
"the future was cancelled.");
471
472
#define _ASYNCIO_FUTURE_DONE_METHODDEF    \
473
    {"done", (PyCFunction)_asyncio_Future_done, METH_NOARGS, _asyncio_Future_done__doc__},
474
475
static PyObject *
476
_asyncio_Future_done_impl(FutureObj *self);
477
478
static PyObject *
479
_asyncio_Future_done(PyObject *self, PyObject *Py_UNUSED(ignored))
480
0
{
481
0
    PyObject *return_value = NULL;
482
483
0
    Py_BEGIN_CRITICAL_SECTION(self);
484
0
    return_value = _asyncio_Future_done_impl((FutureObj *)self);
485
0
    Py_END_CRITICAL_SECTION();
486
487
0
    return return_value;
488
0
}
489
490
PyDoc_STRVAR(_asyncio_Future_get_loop__doc__,
491
"get_loop($self, /)\n"
492
"--\n"
493
"\n"
494
"Return the event loop the Future is bound to.");
495
496
#define _ASYNCIO_FUTURE_GET_LOOP_METHODDEF    \
497
    {"get_loop", _PyCFunction_CAST(_asyncio_Future_get_loop), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _asyncio_Future_get_loop__doc__},
498
499
static PyObject *
500
_asyncio_Future_get_loop_impl(FutureObj *self, PyTypeObject *cls);
501
502
static PyObject *
503
_asyncio_Future_get_loop(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
504
0
{
505
0
    PyObject *return_value = NULL;
506
507
0
    if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
508
0
        PyErr_SetString(PyExc_TypeError, "get_loop() takes no arguments");
509
0
        goto exit;
510
0
    }
511
0
    Py_BEGIN_CRITICAL_SECTION(self);
512
0
    return_value = _asyncio_Future_get_loop_impl((FutureObj *)self, cls);
513
0
    Py_END_CRITICAL_SECTION();
514
515
0
exit:
516
0
    return return_value;
517
0
}
518
519
#if !defined(_asyncio_Future__asyncio_awaited_by_DOCSTR)
520
#  define _asyncio_Future__asyncio_awaited_by_DOCSTR NULL
521
#endif
522
#if defined(_ASYNCIO_FUTURE__ASYNCIO_AWAITED_BY_GETSETDEF)
523
#  undef _ASYNCIO_FUTURE__ASYNCIO_AWAITED_BY_GETSETDEF
524
#  define _ASYNCIO_FUTURE__ASYNCIO_AWAITED_BY_GETSETDEF {"_asyncio_awaited_by", (getter)_asyncio_Future__asyncio_awaited_by_get, (setter)_asyncio_Future__asyncio_awaited_by_set, _asyncio_Future__asyncio_awaited_by_DOCSTR},
525
#else
526
#  define _ASYNCIO_FUTURE__ASYNCIO_AWAITED_BY_GETSETDEF {"_asyncio_awaited_by", (getter)_asyncio_Future__asyncio_awaited_by_get, NULL, _asyncio_Future__asyncio_awaited_by_DOCSTR},
527
#endif
528
529
static PyObject *
530
_asyncio_Future__asyncio_awaited_by_get_impl(FutureObj *self);
531
532
static PyObject *
533
_asyncio_Future__asyncio_awaited_by_get(PyObject *self, void *Py_UNUSED(context))
534
0
{
535
0
    PyObject *return_value = NULL;
536
537
0
    Py_BEGIN_CRITICAL_SECTION(self);
538
0
    return_value = _asyncio_Future__asyncio_awaited_by_get_impl((FutureObj *)self);
539
0
    Py_END_CRITICAL_SECTION();
540
541
0
    return return_value;
542
0
}
543
544
#if !defined(_asyncio_Future__asyncio_future_blocking_DOCSTR)
545
#  define _asyncio_Future__asyncio_future_blocking_DOCSTR NULL
546
#endif
547
#if defined(_ASYNCIO_FUTURE__ASYNCIO_FUTURE_BLOCKING_GETSETDEF)
548
#  undef _ASYNCIO_FUTURE__ASYNCIO_FUTURE_BLOCKING_GETSETDEF
549
#  define _ASYNCIO_FUTURE__ASYNCIO_FUTURE_BLOCKING_GETSETDEF {"_asyncio_future_blocking", (getter)_asyncio_Future__asyncio_future_blocking_get, (setter)_asyncio_Future__asyncio_future_blocking_set, _asyncio_Future__asyncio_future_blocking_DOCSTR},
550
#else
551
#  define _ASYNCIO_FUTURE__ASYNCIO_FUTURE_BLOCKING_GETSETDEF {"_asyncio_future_blocking", (getter)_asyncio_Future__asyncio_future_blocking_get, NULL, _asyncio_Future__asyncio_future_blocking_DOCSTR},
552
#endif
553
554
static PyObject *
555
_asyncio_Future__asyncio_future_blocking_get_impl(FutureObj *self);
556
557
static PyObject *
558
_asyncio_Future__asyncio_future_blocking_get(PyObject *self, void *Py_UNUSED(context))
559
0
{
560
0
    PyObject *return_value = NULL;
561
562
0
    Py_BEGIN_CRITICAL_SECTION(self);
563
0
    return_value = _asyncio_Future__asyncio_future_blocking_get_impl((FutureObj *)self);
564
0
    Py_END_CRITICAL_SECTION();
565
566
0
    return return_value;
567
0
}
568
569
#if !defined(_asyncio_Future__asyncio_future_blocking_DOCSTR)
570
#  define _asyncio_Future__asyncio_future_blocking_DOCSTR NULL
571
#endif
572
#if defined(_ASYNCIO_FUTURE__ASYNCIO_FUTURE_BLOCKING_GETSETDEF)
573
#  undef _ASYNCIO_FUTURE__ASYNCIO_FUTURE_BLOCKING_GETSETDEF
574
#  define _ASYNCIO_FUTURE__ASYNCIO_FUTURE_BLOCKING_GETSETDEF {"_asyncio_future_blocking", (getter)_asyncio_Future__asyncio_future_blocking_get, (setter)_asyncio_Future__asyncio_future_blocking_set, _asyncio_Future__asyncio_future_blocking_DOCSTR},
575
#else
576
#  define _ASYNCIO_FUTURE__ASYNCIO_FUTURE_BLOCKING_GETSETDEF {"_asyncio_future_blocking", NULL, (setter)_asyncio_Future__asyncio_future_blocking_set, NULL},
577
#endif
578
579
static int
580
_asyncio_Future__asyncio_future_blocking_set_impl(FutureObj *self,
581
                                                  PyObject *value);
582
583
static int
584
_asyncio_Future__asyncio_future_blocking_set(PyObject *self, PyObject *value, void *Py_UNUSED(context))
585
0
{
586
0
    int return_value;
587
588
0
    Py_BEGIN_CRITICAL_SECTION(self);
589
0
    return_value = _asyncio_Future__asyncio_future_blocking_set_impl((FutureObj *)self, value);
590
0
    Py_END_CRITICAL_SECTION();
591
592
0
    return return_value;
593
0
}
594
595
#if !defined(_asyncio_Future__log_traceback_DOCSTR)
596
#  define _asyncio_Future__log_traceback_DOCSTR NULL
597
#endif
598
#if defined(_ASYNCIO_FUTURE__LOG_TRACEBACK_GETSETDEF)
599
#  undef _ASYNCIO_FUTURE__LOG_TRACEBACK_GETSETDEF
600
#  define _ASYNCIO_FUTURE__LOG_TRACEBACK_GETSETDEF {"_log_traceback", (getter)_asyncio_Future__log_traceback_get, (setter)_asyncio_Future__log_traceback_set, _asyncio_Future__log_traceback_DOCSTR},
601
#else
602
#  define _ASYNCIO_FUTURE__LOG_TRACEBACK_GETSETDEF {"_log_traceback", (getter)_asyncio_Future__log_traceback_get, NULL, _asyncio_Future__log_traceback_DOCSTR},
603
#endif
604
605
static PyObject *
606
_asyncio_Future__log_traceback_get_impl(FutureObj *self);
607
608
static PyObject *
609
_asyncio_Future__log_traceback_get(PyObject *self, void *Py_UNUSED(context))
610
0
{
611
0
    PyObject *return_value = NULL;
612
613
0
    Py_BEGIN_CRITICAL_SECTION(self);
614
0
    return_value = _asyncio_Future__log_traceback_get_impl((FutureObj *)self);
615
0
    Py_END_CRITICAL_SECTION();
616
617
0
    return return_value;
618
0
}
619
620
#if !defined(_asyncio_Future__log_traceback_DOCSTR)
621
#  define _asyncio_Future__log_traceback_DOCSTR NULL
622
#endif
623
#if defined(_ASYNCIO_FUTURE__LOG_TRACEBACK_GETSETDEF)
624
#  undef _ASYNCIO_FUTURE__LOG_TRACEBACK_GETSETDEF
625
#  define _ASYNCIO_FUTURE__LOG_TRACEBACK_GETSETDEF {"_log_traceback", (getter)_asyncio_Future__log_traceback_get, (setter)_asyncio_Future__log_traceback_set, _asyncio_Future__log_traceback_DOCSTR},
626
#else
627
#  define _ASYNCIO_FUTURE__LOG_TRACEBACK_GETSETDEF {"_log_traceback", NULL, (setter)_asyncio_Future__log_traceback_set, NULL},
628
#endif
629
630
static int
631
_asyncio_Future__log_traceback_set_impl(FutureObj *self, PyObject *value);
632
633
static int
634
_asyncio_Future__log_traceback_set(PyObject *self, PyObject *value, void *Py_UNUSED(context))
635
0
{
636
0
    int return_value;
637
638
0
    Py_BEGIN_CRITICAL_SECTION(self);
639
0
    return_value = _asyncio_Future__log_traceback_set_impl((FutureObj *)self, value);
640
0
    Py_END_CRITICAL_SECTION();
641
642
0
    return return_value;
643
0
}
644
645
#if !defined(_asyncio_Future__loop_DOCSTR)
646
#  define _asyncio_Future__loop_DOCSTR NULL
647
#endif
648
#if defined(_ASYNCIO_FUTURE__LOOP_GETSETDEF)
649
#  undef _ASYNCIO_FUTURE__LOOP_GETSETDEF
650
#  define _ASYNCIO_FUTURE__LOOP_GETSETDEF {"_loop", (getter)_asyncio_Future__loop_get, (setter)_asyncio_Future__loop_set, _asyncio_Future__loop_DOCSTR},
651
#else
652
#  define _ASYNCIO_FUTURE__LOOP_GETSETDEF {"_loop", (getter)_asyncio_Future__loop_get, NULL, _asyncio_Future__loop_DOCSTR},
653
#endif
654
655
static PyObject *
656
_asyncio_Future__loop_get_impl(FutureObj *self);
657
658
static PyObject *
659
_asyncio_Future__loop_get(PyObject *self, void *Py_UNUSED(context))
660
0
{
661
0
    PyObject *return_value = NULL;
662
663
0
    Py_BEGIN_CRITICAL_SECTION(self);
664
0
    return_value = _asyncio_Future__loop_get_impl((FutureObj *)self);
665
0
    Py_END_CRITICAL_SECTION();
666
667
0
    return return_value;
668
0
}
669
670
#if !defined(_asyncio_Future__callbacks_DOCSTR)
671
#  define _asyncio_Future__callbacks_DOCSTR NULL
672
#endif
673
#if defined(_ASYNCIO_FUTURE__CALLBACKS_GETSETDEF)
674
#  undef _ASYNCIO_FUTURE__CALLBACKS_GETSETDEF
675
#  define _ASYNCIO_FUTURE__CALLBACKS_GETSETDEF {"_callbacks", (getter)_asyncio_Future__callbacks_get, (setter)_asyncio_Future__callbacks_set, _asyncio_Future__callbacks_DOCSTR},
676
#else
677
#  define _ASYNCIO_FUTURE__CALLBACKS_GETSETDEF {"_callbacks", (getter)_asyncio_Future__callbacks_get, NULL, _asyncio_Future__callbacks_DOCSTR},
678
#endif
679
680
static PyObject *
681
_asyncio_Future__callbacks_get_impl(FutureObj *self);
682
683
static PyObject *
684
_asyncio_Future__callbacks_get(PyObject *self, void *Py_UNUSED(context))
685
0
{
686
0
    PyObject *return_value = NULL;
687
688
0
    Py_BEGIN_CRITICAL_SECTION(self);
689
0
    return_value = _asyncio_Future__callbacks_get_impl((FutureObj *)self);
690
0
    Py_END_CRITICAL_SECTION();
691
692
0
    return return_value;
693
0
}
694
695
#if !defined(_asyncio_Future__result_DOCSTR)
696
#  define _asyncio_Future__result_DOCSTR NULL
697
#endif
698
#if defined(_ASYNCIO_FUTURE__RESULT_GETSETDEF)
699
#  undef _ASYNCIO_FUTURE__RESULT_GETSETDEF
700
#  define _ASYNCIO_FUTURE__RESULT_GETSETDEF {"_result", (getter)_asyncio_Future__result_get, (setter)_asyncio_Future__result_set, _asyncio_Future__result_DOCSTR},
701
#else
702
#  define _ASYNCIO_FUTURE__RESULT_GETSETDEF {"_result", (getter)_asyncio_Future__result_get, NULL, _asyncio_Future__result_DOCSTR},
703
#endif
704
705
static PyObject *
706
_asyncio_Future__result_get_impl(FutureObj *self);
707
708
static PyObject *
709
_asyncio_Future__result_get(PyObject *self, void *Py_UNUSED(context))
710
0
{
711
0
    PyObject *return_value = NULL;
712
713
0
    Py_BEGIN_CRITICAL_SECTION(self);
714
0
    return_value = _asyncio_Future__result_get_impl((FutureObj *)self);
715
0
    Py_END_CRITICAL_SECTION();
716
717
0
    return return_value;
718
0
}
719
720
#if !defined(_asyncio_Future__exception_DOCSTR)
721
#  define _asyncio_Future__exception_DOCSTR NULL
722
#endif
723
#if defined(_ASYNCIO_FUTURE__EXCEPTION_GETSETDEF)
724
#  undef _ASYNCIO_FUTURE__EXCEPTION_GETSETDEF
725
#  define _ASYNCIO_FUTURE__EXCEPTION_GETSETDEF {"_exception", (getter)_asyncio_Future__exception_get, (setter)_asyncio_Future__exception_set, _asyncio_Future__exception_DOCSTR},
726
#else
727
#  define _ASYNCIO_FUTURE__EXCEPTION_GETSETDEF {"_exception", (getter)_asyncio_Future__exception_get, NULL, _asyncio_Future__exception_DOCSTR},
728
#endif
729
730
static PyObject *
731
_asyncio_Future__exception_get_impl(FutureObj *self);
732
733
static PyObject *
734
_asyncio_Future__exception_get(PyObject *self, void *Py_UNUSED(context))
735
0
{
736
0
    PyObject *return_value = NULL;
737
738
0
    Py_BEGIN_CRITICAL_SECTION(self);
739
0
    return_value = _asyncio_Future__exception_get_impl((FutureObj *)self);
740
0
    Py_END_CRITICAL_SECTION();
741
742
0
    return return_value;
743
0
}
744
745
#if !defined(_asyncio_Future__source_traceback_DOCSTR)
746
#  define _asyncio_Future__source_traceback_DOCSTR NULL
747
#endif
748
#if defined(_ASYNCIO_FUTURE__SOURCE_TRACEBACK_GETSETDEF)
749
#  undef _ASYNCIO_FUTURE__SOURCE_TRACEBACK_GETSETDEF
750
#  define _ASYNCIO_FUTURE__SOURCE_TRACEBACK_GETSETDEF {"_source_traceback", (getter)_asyncio_Future__source_traceback_get, (setter)_asyncio_Future__source_traceback_set, _asyncio_Future__source_traceback_DOCSTR},
751
#else
752
#  define _ASYNCIO_FUTURE__SOURCE_TRACEBACK_GETSETDEF {"_source_traceback", (getter)_asyncio_Future__source_traceback_get, NULL, _asyncio_Future__source_traceback_DOCSTR},
753
#endif
754
755
static PyObject *
756
_asyncio_Future__source_traceback_get_impl(FutureObj *self);
757
758
static PyObject *
759
_asyncio_Future__source_traceback_get(PyObject *self, void *Py_UNUSED(context))
760
0
{
761
0
    PyObject *return_value = NULL;
762
763
0
    Py_BEGIN_CRITICAL_SECTION(self);
764
0
    return_value = _asyncio_Future__source_traceback_get_impl((FutureObj *)self);
765
0
    Py_END_CRITICAL_SECTION();
766
767
0
    return return_value;
768
0
}
769
770
#if !defined(_asyncio_Future__cancel_message_DOCSTR)
771
#  define _asyncio_Future__cancel_message_DOCSTR NULL
772
#endif
773
#if defined(_ASYNCIO_FUTURE__CANCEL_MESSAGE_GETSETDEF)
774
#  undef _ASYNCIO_FUTURE__CANCEL_MESSAGE_GETSETDEF
775
#  define _ASYNCIO_FUTURE__CANCEL_MESSAGE_GETSETDEF {"_cancel_message", (getter)_asyncio_Future__cancel_message_get, (setter)_asyncio_Future__cancel_message_set, _asyncio_Future__cancel_message_DOCSTR},
776
#else
777
#  define _ASYNCIO_FUTURE__CANCEL_MESSAGE_GETSETDEF {"_cancel_message", (getter)_asyncio_Future__cancel_message_get, NULL, _asyncio_Future__cancel_message_DOCSTR},
778
#endif
779
780
static PyObject *
781
_asyncio_Future__cancel_message_get_impl(FutureObj *self);
782
783
static PyObject *
784
_asyncio_Future__cancel_message_get(PyObject *self, void *Py_UNUSED(context))
785
0
{
786
0
    PyObject *return_value = NULL;
787
788
0
    Py_BEGIN_CRITICAL_SECTION(self);
789
0
    return_value = _asyncio_Future__cancel_message_get_impl((FutureObj *)self);
790
0
    Py_END_CRITICAL_SECTION();
791
792
0
    return return_value;
793
0
}
794
795
#if !defined(_asyncio_Future__cancel_message_DOCSTR)
796
#  define _asyncio_Future__cancel_message_DOCSTR NULL
797
#endif
798
#if defined(_ASYNCIO_FUTURE__CANCEL_MESSAGE_GETSETDEF)
799
#  undef _ASYNCIO_FUTURE__CANCEL_MESSAGE_GETSETDEF
800
#  define _ASYNCIO_FUTURE__CANCEL_MESSAGE_GETSETDEF {"_cancel_message", (getter)_asyncio_Future__cancel_message_get, (setter)_asyncio_Future__cancel_message_set, _asyncio_Future__cancel_message_DOCSTR},
801
#else
802
#  define _ASYNCIO_FUTURE__CANCEL_MESSAGE_GETSETDEF {"_cancel_message", NULL, (setter)_asyncio_Future__cancel_message_set, NULL},
803
#endif
804
805
static int
806
_asyncio_Future__cancel_message_set_impl(FutureObj *self, PyObject *value);
807
808
static int
809
_asyncio_Future__cancel_message_set(PyObject *self, PyObject *value, void *Py_UNUSED(context))
810
0
{
811
0
    int return_value;
812
813
0
    Py_BEGIN_CRITICAL_SECTION(self);
814
0
    return_value = _asyncio_Future__cancel_message_set_impl((FutureObj *)self, value);
815
0
    Py_END_CRITICAL_SECTION();
816
817
0
    return return_value;
818
0
}
819
820
#if !defined(_asyncio_Future__state_DOCSTR)
821
#  define _asyncio_Future__state_DOCSTR NULL
822
#endif
823
#if defined(_ASYNCIO_FUTURE__STATE_GETSETDEF)
824
#  undef _ASYNCIO_FUTURE__STATE_GETSETDEF
825
#  define _ASYNCIO_FUTURE__STATE_GETSETDEF {"_state", (getter)_asyncio_Future__state_get, (setter)_asyncio_Future__state_set, _asyncio_Future__state_DOCSTR},
826
#else
827
#  define _ASYNCIO_FUTURE__STATE_GETSETDEF {"_state", (getter)_asyncio_Future__state_get, NULL, _asyncio_Future__state_DOCSTR},
828
#endif
829
830
static PyObject *
831
_asyncio_Future__state_get_impl(FutureObj *self);
832
833
static PyObject *
834
_asyncio_Future__state_get(PyObject *self, void *Py_UNUSED(context))
835
0
{
836
0
    PyObject *return_value = NULL;
837
838
0
    Py_BEGIN_CRITICAL_SECTION(self);
839
0
    return_value = _asyncio_Future__state_get_impl((FutureObj *)self);
840
0
    Py_END_CRITICAL_SECTION();
841
842
0
    return return_value;
843
0
}
844
845
PyDoc_STRVAR(_asyncio_Future__make_cancelled_error__doc__,
846
"_make_cancelled_error($self, /)\n"
847
"--\n"
848
"\n"
849
"Create the CancelledError to raise if the Future is cancelled.\n"
850
"\n"
851
"This should only be called once when handling a cancellation since\n"
852
"it erases the context exception value.");
853
854
#define _ASYNCIO_FUTURE__MAKE_CANCELLED_ERROR_METHODDEF    \
855
    {"_make_cancelled_error", (PyCFunction)_asyncio_Future__make_cancelled_error, METH_NOARGS, _asyncio_Future__make_cancelled_error__doc__},
856
857
static PyObject *
858
_asyncio_Future__make_cancelled_error_impl(FutureObj *self);
859
860
static PyObject *
861
_asyncio_Future__make_cancelled_error(PyObject *self, PyObject *Py_UNUSED(ignored))
862
0
{
863
0
    PyObject *return_value = NULL;
864
865
0
    Py_BEGIN_CRITICAL_SECTION(self);
866
0
    return_value = _asyncio_Future__make_cancelled_error_impl((FutureObj *)self);
867
0
    Py_END_CRITICAL_SECTION();
868
869
0
    return return_value;
870
0
}
871
872
PyDoc_STRVAR(_asyncio_Task___init____doc__,
873
"Task(coro, *, loop=None, name=None, context=None, eager_start=False)\n"
874
"--\n"
875
"\n"
876
"A coroutine wrapped in a Future.");
877
878
static int
879
_asyncio_Task___init___impl(TaskObj *self, PyObject *coro, PyObject *loop,
880
                            PyObject *name, PyObject *context,
881
                            int eager_start);
882
883
static int
884
_asyncio_Task___init__(PyObject *self, PyObject *args, PyObject *kwargs)
885
0
{
886
0
    int return_value = -1;
887
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
888
889
0
    #define NUM_KEYWORDS 5
890
0
    static struct {
891
0
        PyGC_Head _this_is_not_used;
892
0
        PyObject_VAR_HEAD
893
0
        Py_hash_t ob_hash;
894
0
        PyObject *ob_item[NUM_KEYWORDS];
895
0
    } _kwtuple = {
896
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
897
0
        .ob_hash = -1,
898
0
        .ob_item = { &_Py_ID(coro), &_Py_ID(loop), &_Py_ID(name), &_Py_ID(context), &_Py_ID(eager_start), },
899
0
    };
900
0
    #undef NUM_KEYWORDS
901
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
902
903
    #else  // !Py_BUILD_CORE
904
    #  define KWTUPLE NULL
905
    #endif  // !Py_BUILD_CORE
906
907
0
    static const char * const _keywords[] = {"coro", "loop", "name", "context", "eager_start", NULL};
908
0
    static _PyArg_Parser _parser = {
909
0
        .keywords = _keywords,
910
0
        .fname = "Task",
911
0
        .kwtuple = KWTUPLE,
912
0
    };
913
0
    #undef KWTUPLE
914
0
    PyObject *argsbuf[5];
915
0
    PyObject * const *fastargs;
916
0
    Py_ssize_t nargs = PyTuple_GET_SIZE(args);
917
0
    Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
918
0
    PyObject *coro;
919
0
    PyObject *loop = Py_None;
920
0
    PyObject *name = Py_None;
921
0
    PyObject *context = Py_None;
922
0
    int eager_start = 0;
923
924
0
    fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
925
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
926
0
    if (!fastargs) {
927
0
        goto exit;
928
0
    }
929
0
    coro = fastargs[0];
930
0
    if (!noptargs) {
931
0
        goto skip_optional_kwonly;
932
0
    }
933
0
    if (fastargs[1]) {
934
0
        loop = fastargs[1];
935
0
        if (!--noptargs) {
936
0
            goto skip_optional_kwonly;
937
0
        }
938
0
    }
939
0
    if (fastargs[2]) {
940
0
        name = fastargs[2];
941
0
        if (!--noptargs) {
942
0
            goto skip_optional_kwonly;
943
0
        }
944
0
    }
945
0
    if (fastargs[3]) {
946
0
        context = fastargs[3];
947
0
        if (!--noptargs) {
948
0
            goto skip_optional_kwonly;
949
0
        }
950
0
    }
951
0
    eager_start = PyObject_IsTrue(fastargs[4]);
952
0
    if (eager_start < 0) {
953
0
        goto exit;
954
0
    }
955
0
skip_optional_kwonly:
956
0
    return_value = _asyncio_Task___init___impl((TaskObj *)self, coro, loop, name, context, eager_start);
957
958
0
exit:
959
0
    return return_value;
960
0
}
961
962
#if !defined(_asyncio_Task__log_destroy_pending_DOCSTR)
963
#  define _asyncio_Task__log_destroy_pending_DOCSTR NULL
964
#endif
965
#if defined(_ASYNCIO_TASK__LOG_DESTROY_PENDING_GETSETDEF)
966
#  undef _ASYNCIO_TASK__LOG_DESTROY_PENDING_GETSETDEF
967
#  define _ASYNCIO_TASK__LOG_DESTROY_PENDING_GETSETDEF {"_log_destroy_pending", (getter)_asyncio_Task__log_destroy_pending_get, (setter)_asyncio_Task__log_destroy_pending_set, _asyncio_Task__log_destroy_pending_DOCSTR},
968
#else
969
#  define _ASYNCIO_TASK__LOG_DESTROY_PENDING_GETSETDEF {"_log_destroy_pending", (getter)_asyncio_Task__log_destroy_pending_get, NULL, _asyncio_Task__log_destroy_pending_DOCSTR},
970
#endif
971
972
static PyObject *
973
_asyncio_Task__log_destroy_pending_get_impl(TaskObj *self);
974
975
static PyObject *
976
_asyncio_Task__log_destroy_pending_get(PyObject *self, void *Py_UNUSED(context))
977
0
{
978
0
    PyObject *return_value = NULL;
979
980
0
    Py_BEGIN_CRITICAL_SECTION(self);
981
0
    return_value = _asyncio_Task__log_destroy_pending_get_impl((TaskObj *)self);
982
0
    Py_END_CRITICAL_SECTION();
983
984
0
    return return_value;
985
0
}
986
987
#if !defined(_asyncio_Task__log_destroy_pending_DOCSTR)
988
#  define _asyncio_Task__log_destroy_pending_DOCSTR NULL
989
#endif
990
#if defined(_ASYNCIO_TASK__LOG_DESTROY_PENDING_GETSETDEF)
991
#  undef _ASYNCIO_TASK__LOG_DESTROY_PENDING_GETSETDEF
992
#  define _ASYNCIO_TASK__LOG_DESTROY_PENDING_GETSETDEF {"_log_destroy_pending", (getter)_asyncio_Task__log_destroy_pending_get, (setter)_asyncio_Task__log_destroy_pending_set, _asyncio_Task__log_destroy_pending_DOCSTR},
993
#else
994
#  define _ASYNCIO_TASK__LOG_DESTROY_PENDING_GETSETDEF {"_log_destroy_pending", NULL, (setter)_asyncio_Task__log_destroy_pending_set, NULL},
995
#endif
996
997
static int
998
_asyncio_Task__log_destroy_pending_set_impl(TaskObj *self, PyObject *value);
999
1000
static int
1001
_asyncio_Task__log_destroy_pending_set(PyObject *self, PyObject *value, void *Py_UNUSED(context))
1002
0
{
1003
0
    int return_value;
1004
1005
0
    Py_BEGIN_CRITICAL_SECTION(self);
1006
0
    return_value = _asyncio_Task__log_destroy_pending_set_impl((TaskObj *)self, value);
1007
0
    Py_END_CRITICAL_SECTION();
1008
1009
0
    return return_value;
1010
0
}
1011
1012
#if !defined(_asyncio_Task__must_cancel_DOCSTR)
1013
#  define _asyncio_Task__must_cancel_DOCSTR NULL
1014
#endif
1015
#if defined(_ASYNCIO_TASK__MUST_CANCEL_GETSETDEF)
1016
#  undef _ASYNCIO_TASK__MUST_CANCEL_GETSETDEF
1017
#  define _ASYNCIO_TASK__MUST_CANCEL_GETSETDEF {"_must_cancel", (getter)_asyncio_Task__must_cancel_get, (setter)_asyncio_Task__must_cancel_set, _asyncio_Task__must_cancel_DOCSTR},
1018
#else
1019
#  define _ASYNCIO_TASK__MUST_CANCEL_GETSETDEF {"_must_cancel", (getter)_asyncio_Task__must_cancel_get, NULL, _asyncio_Task__must_cancel_DOCSTR},
1020
#endif
1021
1022
static PyObject *
1023
_asyncio_Task__must_cancel_get_impl(TaskObj *self);
1024
1025
static PyObject *
1026
_asyncio_Task__must_cancel_get(PyObject *self, void *Py_UNUSED(context))
1027
0
{
1028
0
    PyObject *return_value = NULL;
1029
1030
0
    Py_BEGIN_CRITICAL_SECTION(self);
1031
0
    return_value = _asyncio_Task__must_cancel_get_impl((TaskObj *)self);
1032
0
    Py_END_CRITICAL_SECTION();
1033
1034
0
    return return_value;
1035
0
}
1036
1037
#if !defined(_asyncio_Task__coro_DOCSTR)
1038
#  define _asyncio_Task__coro_DOCSTR NULL
1039
#endif
1040
#if defined(_ASYNCIO_TASK__CORO_GETSETDEF)
1041
#  undef _ASYNCIO_TASK__CORO_GETSETDEF
1042
#  define _ASYNCIO_TASK__CORO_GETSETDEF {"_coro", (getter)_asyncio_Task__coro_get, (setter)_asyncio_Task__coro_set, _asyncio_Task__coro_DOCSTR},
1043
#else
1044
#  define _ASYNCIO_TASK__CORO_GETSETDEF {"_coro", (getter)_asyncio_Task__coro_get, NULL, _asyncio_Task__coro_DOCSTR},
1045
#endif
1046
1047
static PyObject *
1048
_asyncio_Task__coro_get_impl(TaskObj *self);
1049
1050
static PyObject *
1051
_asyncio_Task__coro_get(PyObject *self, void *Py_UNUSED(context))
1052
0
{
1053
0
    PyObject *return_value = NULL;
1054
1055
0
    Py_BEGIN_CRITICAL_SECTION(self);
1056
0
    return_value = _asyncio_Task__coro_get_impl((TaskObj *)self);
1057
0
    Py_END_CRITICAL_SECTION();
1058
1059
0
    return return_value;
1060
0
}
1061
1062
#if !defined(_asyncio_Task__fut_waiter_DOCSTR)
1063
#  define _asyncio_Task__fut_waiter_DOCSTR NULL
1064
#endif
1065
#if defined(_ASYNCIO_TASK__FUT_WAITER_GETSETDEF)
1066
#  undef _ASYNCIO_TASK__FUT_WAITER_GETSETDEF
1067
#  define _ASYNCIO_TASK__FUT_WAITER_GETSETDEF {"_fut_waiter", (getter)_asyncio_Task__fut_waiter_get, (setter)_asyncio_Task__fut_waiter_set, _asyncio_Task__fut_waiter_DOCSTR},
1068
#else
1069
#  define _ASYNCIO_TASK__FUT_WAITER_GETSETDEF {"_fut_waiter", (getter)_asyncio_Task__fut_waiter_get, NULL, _asyncio_Task__fut_waiter_DOCSTR},
1070
#endif
1071
1072
static PyObject *
1073
_asyncio_Task__fut_waiter_get_impl(TaskObj *self);
1074
1075
static PyObject *
1076
_asyncio_Task__fut_waiter_get(PyObject *self, void *Py_UNUSED(context))
1077
0
{
1078
0
    PyObject *return_value = NULL;
1079
1080
0
    Py_BEGIN_CRITICAL_SECTION(self);
1081
0
    return_value = _asyncio_Task__fut_waiter_get_impl((TaskObj *)self);
1082
0
    Py_END_CRITICAL_SECTION();
1083
1084
0
    return return_value;
1085
0
}
1086
1087
PyDoc_STRVAR(_asyncio_Task__make_cancelled_error__doc__,
1088
"_make_cancelled_error($self, /)\n"
1089
"--\n"
1090
"\n"
1091
"Create the CancelledError to raise if the Task is cancelled.\n"
1092
"\n"
1093
"This should only be called once when handling a cancellation since\n"
1094
"it erases the context exception value.");
1095
1096
#define _ASYNCIO_TASK__MAKE_CANCELLED_ERROR_METHODDEF    \
1097
    {"_make_cancelled_error", (PyCFunction)_asyncio_Task__make_cancelled_error, METH_NOARGS, _asyncio_Task__make_cancelled_error__doc__},
1098
1099
static PyObject *
1100
_asyncio_Task__make_cancelled_error_impl(TaskObj *self);
1101
1102
static PyObject *
1103
_asyncio_Task__make_cancelled_error(PyObject *self, PyObject *Py_UNUSED(ignored))
1104
0
{
1105
0
    PyObject *return_value = NULL;
1106
1107
0
    Py_BEGIN_CRITICAL_SECTION(self);
1108
0
    return_value = _asyncio_Task__make_cancelled_error_impl((TaskObj *)self);
1109
0
    Py_END_CRITICAL_SECTION();
1110
1111
0
    return return_value;
1112
0
}
1113
1114
PyDoc_STRVAR(_asyncio_Task_cancel__doc__,
1115
"cancel($self, /, msg=None)\n"
1116
"--\n"
1117
"\n"
1118
"Request that this task cancel itself.\n"
1119
"\n"
1120
"This arranges for a CancelledError to be thrown into the\n"
1121
"wrapped coroutine on the next cycle through the event loop.\n"
1122
"The coroutine then has a chance to clean up or even deny\n"
1123
"the request using try/except/finally.\n"
1124
"\n"
1125
"Unlike Future.cancel, this does not guarantee that the\n"
1126
"task will be cancelled: the exception might be caught and\n"
1127
"acted upon, delaying cancellation of the task or preventing\n"
1128
"cancellation completely.  The task may also return a value or\n"
1129
"raise a different exception.\n"
1130
"\n"
1131
"Immediately after this method is called, Task.cancelled() will\n"
1132
"not return True (unless the task was already cancelled).  A\n"
1133
"task will be marked as cancelled when the wrapped coroutine\n"
1134
"terminates with a CancelledError exception (even if cancel()\n"
1135
"was not called).\n"
1136
"\n"
1137
"This also increases the task\'s count of cancellation requests.");
1138
1139
#define _ASYNCIO_TASK_CANCEL_METHODDEF    \
1140
    {"cancel", _PyCFunction_CAST(_asyncio_Task_cancel), METH_FASTCALL|METH_KEYWORDS, _asyncio_Task_cancel__doc__},
1141
1142
static PyObject *
1143
_asyncio_Task_cancel_impl(TaskObj *self, PyObject *msg);
1144
1145
static PyObject *
1146
_asyncio_Task_cancel(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1147
0
{
1148
0
    PyObject *return_value = NULL;
1149
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1150
1151
0
    #define NUM_KEYWORDS 1
1152
0
    static struct {
1153
0
        PyGC_Head _this_is_not_used;
1154
0
        PyObject_VAR_HEAD
1155
0
        Py_hash_t ob_hash;
1156
0
        PyObject *ob_item[NUM_KEYWORDS];
1157
0
    } _kwtuple = {
1158
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1159
0
        .ob_hash = -1,
1160
0
        .ob_item = { &_Py_ID(msg), },
1161
0
    };
1162
0
    #undef NUM_KEYWORDS
1163
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1164
1165
    #else  // !Py_BUILD_CORE
1166
    #  define KWTUPLE NULL
1167
    #endif  // !Py_BUILD_CORE
1168
1169
0
    static const char * const _keywords[] = {"msg", NULL};
1170
0
    static _PyArg_Parser _parser = {
1171
0
        .keywords = _keywords,
1172
0
        .fname = "cancel",
1173
0
        .kwtuple = KWTUPLE,
1174
0
    };
1175
0
    #undef KWTUPLE
1176
0
    PyObject *argsbuf[1];
1177
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
1178
0
    PyObject *msg = Py_None;
1179
1180
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1181
0
            /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1182
0
    if (!args) {
1183
0
        goto exit;
1184
0
    }
1185
0
    if (!noptargs) {
1186
0
        goto skip_optional_pos;
1187
0
    }
1188
0
    msg = args[0];
1189
0
skip_optional_pos:
1190
0
    Py_BEGIN_CRITICAL_SECTION(self);
1191
0
    return_value = _asyncio_Task_cancel_impl((TaskObj *)self, msg);
1192
0
    Py_END_CRITICAL_SECTION();
1193
1194
0
exit:
1195
0
    return return_value;
1196
0
}
1197
1198
PyDoc_STRVAR(_asyncio_Task_cancelling__doc__,
1199
"cancelling($self, /)\n"
1200
"--\n"
1201
"\n"
1202
"Return the count of the task\'s cancellation requests.\n"
1203
"\n"
1204
"This count is incremented when .cancel() is called\n"
1205
"and may be decremented using .uncancel().");
1206
1207
#define _ASYNCIO_TASK_CANCELLING_METHODDEF    \
1208
    {"cancelling", (PyCFunction)_asyncio_Task_cancelling, METH_NOARGS, _asyncio_Task_cancelling__doc__},
1209
1210
static PyObject *
1211
_asyncio_Task_cancelling_impl(TaskObj *self);
1212
1213
static PyObject *
1214
_asyncio_Task_cancelling(PyObject *self, PyObject *Py_UNUSED(ignored))
1215
0
{
1216
0
    PyObject *return_value = NULL;
1217
1218
0
    Py_BEGIN_CRITICAL_SECTION(self);
1219
0
    return_value = _asyncio_Task_cancelling_impl((TaskObj *)self);
1220
0
    Py_END_CRITICAL_SECTION();
1221
1222
0
    return return_value;
1223
0
}
1224
1225
PyDoc_STRVAR(_asyncio_Task_uncancel__doc__,
1226
"uncancel($self, /)\n"
1227
"--\n"
1228
"\n"
1229
"Decrement the task\'s count of cancellation requests.\n"
1230
"\n"
1231
"This should be used by tasks that catch CancelledError\n"
1232
"and wish to continue indefinitely until they are cancelled again.\n"
1233
"\n"
1234
"Returns the remaining number of cancellation requests.");
1235
1236
#define _ASYNCIO_TASK_UNCANCEL_METHODDEF    \
1237
    {"uncancel", (PyCFunction)_asyncio_Task_uncancel, METH_NOARGS, _asyncio_Task_uncancel__doc__},
1238
1239
static PyObject *
1240
_asyncio_Task_uncancel_impl(TaskObj *self);
1241
1242
static PyObject *
1243
_asyncio_Task_uncancel(PyObject *self, PyObject *Py_UNUSED(ignored))
1244
0
{
1245
0
    PyObject *return_value = NULL;
1246
1247
0
    Py_BEGIN_CRITICAL_SECTION(self);
1248
0
    return_value = _asyncio_Task_uncancel_impl((TaskObj *)self);
1249
0
    Py_END_CRITICAL_SECTION();
1250
1251
0
    return return_value;
1252
0
}
1253
1254
PyDoc_STRVAR(_asyncio_Task_get_stack__doc__,
1255
"get_stack($self, /, *, limit=None)\n"
1256
"--\n"
1257
"\n"
1258
"Return the list of stack frames for this task\'s coroutine.\n"
1259
"\n"
1260
"If the coroutine is not done, this returns the stack where it is\n"
1261
"suspended.  If the coroutine has completed successfully or was\n"
1262
"cancelled, this returns an empty list.  If the coroutine was\n"
1263
"terminated by an exception, this returns the list of traceback\n"
1264
"frames.\n"
1265
"\n"
1266
"The frames are always ordered from oldest to newest.\n"
1267
"\n"
1268
"The optional limit gives the maximum number of frames to\n"
1269
"return; by default all available frames are returned.  Its\n"
1270
"meaning differs depending on whether a stack or a traceback is\n"
1271
"returned: the newest frames of a stack are returned, but the\n"
1272
"oldest frames of a traceback are returned.  (This matches the\n"
1273
"behavior of the traceback module.)\n"
1274
"\n"
1275
"For reasons beyond our control, only one stack frame is\n"
1276
"returned for a suspended coroutine.");
1277
1278
#define _ASYNCIO_TASK_GET_STACK_METHODDEF    \
1279
    {"get_stack", _PyCFunction_CAST(_asyncio_Task_get_stack), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _asyncio_Task_get_stack__doc__},
1280
1281
static PyObject *
1282
_asyncio_Task_get_stack_impl(TaskObj *self, PyTypeObject *cls,
1283
                             PyObject *limit);
1284
1285
static PyObject *
1286
_asyncio_Task_get_stack(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1287
0
{
1288
0
    PyObject *return_value = NULL;
1289
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1290
1291
0
    #define NUM_KEYWORDS 1
1292
0
    static struct {
1293
0
        PyGC_Head _this_is_not_used;
1294
0
        PyObject_VAR_HEAD
1295
0
        Py_hash_t ob_hash;
1296
0
        PyObject *ob_item[NUM_KEYWORDS];
1297
0
    } _kwtuple = {
1298
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1299
0
        .ob_hash = -1,
1300
0
        .ob_item = { &_Py_ID(limit), },
1301
0
    };
1302
0
    #undef NUM_KEYWORDS
1303
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1304
1305
    #else  // !Py_BUILD_CORE
1306
    #  define KWTUPLE NULL
1307
    #endif  // !Py_BUILD_CORE
1308
1309
0
    static const char * const _keywords[] = {"limit", NULL};
1310
0
    static _PyArg_Parser _parser = {
1311
0
        .keywords = _keywords,
1312
0
        .fname = "get_stack",
1313
0
        .kwtuple = KWTUPLE,
1314
0
    };
1315
0
    #undef KWTUPLE
1316
0
    PyObject *argsbuf[1];
1317
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
1318
0
    PyObject *limit = Py_None;
1319
1320
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1321
0
            /*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1322
0
    if (!args) {
1323
0
        goto exit;
1324
0
    }
1325
0
    if (!noptargs) {
1326
0
        goto skip_optional_kwonly;
1327
0
    }
1328
0
    limit = args[0];
1329
0
skip_optional_kwonly:
1330
0
    return_value = _asyncio_Task_get_stack_impl((TaskObj *)self, cls, limit);
1331
1332
0
exit:
1333
0
    return return_value;
1334
0
}
1335
1336
PyDoc_STRVAR(_asyncio_Task_print_stack__doc__,
1337
"print_stack($self, /, *, limit=None, file=None)\n"
1338
"--\n"
1339
"\n"
1340
"Print the stack or traceback for this task\'s coroutine.\n"
1341
"\n"
1342
"This produces output similar to that of the traceback module,\n"
1343
"for the frames retrieved by get_stack().  The limit argument\n"
1344
"is passed to get_stack().  The file argument is an I/O stream\n"
1345
"to which the output is written; by default output is written\n"
1346
"to sys.stderr.");
1347
1348
#define _ASYNCIO_TASK_PRINT_STACK_METHODDEF    \
1349
    {"print_stack", _PyCFunction_CAST(_asyncio_Task_print_stack), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _asyncio_Task_print_stack__doc__},
1350
1351
static PyObject *
1352
_asyncio_Task_print_stack_impl(TaskObj *self, PyTypeObject *cls,
1353
                               PyObject *limit, PyObject *file);
1354
1355
static PyObject *
1356
_asyncio_Task_print_stack(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1357
0
{
1358
0
    PyObject *return_value = NULL;
1359
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1360
1361
0
    #define NUM_KEYWORDS 2
1362
0
    static struct {
1363
0
        PyGC_Head _this_is_not_used;
1364
0
        PyObject_VAR_HEAD
1365
0
        Py_hash_t ob_hash;
1366
0
        PyObject *ob_item[NUM_KEYWORDS];
1367
0
    } _kwtuple = {
1368
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1369
0
        .ob_hash = -1,
1370
0
        .ob_item = { &_Py_ID(limit), &_Py_ID(file), },
1371
0
    };
1372
0
    #undef NUM_KEYWORDS
1373
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1374
1375
    #else  // !Py_BUILD_CORE
1376
    #  define KWTUPLE NULL
1377
    #endif  // !Py_BUILD_CORE
1378
1379
0
    static const char * const _keywords[] = {"limit", "file", NULL};
1380
0
    static _PyArg_Parser _parser = {
1381
0
        .keywords = _keywords,
1382
0
        .fname = "print_stack",
1383
0
        .kwtuple = KWTUPLE,
1384
0
    };
1385
0
    #undef KWTUPLE
1386
0
    PyObject *argsbuf[2];
1387
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
1388
0
    PyObject *limit = Py_None;
1389
0
    PyObject *file = Py_None;
1390
1391
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1392
0
            /*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1393
0
    if (!args) {
1394
0
        goto exit;
1395
0
    }
1396
0
    if (!noptargs) {
1397
0
        goto skip_optional_kwonly;
1398
0
    }
1399
0
    if (args[0]) {
1400
0
        limit = args[0];
1401
0
        if (!--noptargs) {
1402
0
            goto skip_optional_kwonly;
1403
0
        }
1404
0
    }
1405
0
    file = args[1];
1406
0
skip_optional_kwonly:
1407
0
    return_value = _asyncio_Task_print_stack_impl((TaskObj *)self, cls, limit, file);
1408
1409
0
exit:
1410
0
    return return_value;
1411
0
}
1412
1413
PyDoc_STRVAR(_asyncio_Task_set_result__doc__,
1414
"set_result($self, result, /)\n"
1415
"--\n"
1416
"\n");
1417
1418
#define _ASYNCIO_TASK_SET_RESULT_METHODDEF    \
1419
    {"set_result", (PyCFunction)_asyncio_Task_set_result, METH_O, _asyncio_Task_set_result__doc__},
1420
1421
static PyObject *
1422
_asyncio_Task_set_result_impl(TaskObj *self, PyObject *result);
1423
1424
static PyObject *
1425
_asyncio_Task_set_result(PyObject *self, PyObject *result)
1426
0
{
1427
0
    PyObject *return_value = NULL;
1428
1429
0
    return_value = _asyncio_Task_set_result_impl((TaskObj *)self, result);
1430
1431
0
    return return_value;
1432
0
}
1433
1434
PyDoc_STRVAR(_asyncio_Task_set_exception__doc__,
1435
"set_exception($self, exception, /)\n"
1436
"--\n"
1437
"\n");
1438
1439
#define _ASYNCIO_TASK_SET_EXCEPTION_METHODDEF    \
1440
    {"set_exception", (PyCFunction)_asyncio_Task_set_exception, METH_O, _asyncio_Task_set_exception__doc__},
1441
1442
static PyObject *
1443
_asyncio_Task_set_exception_impl(TaskObj *self, PyObject *exception);
1444
1445
static PyObject *
1446
_asyncio_Task_set_exception(PyObject *self, PyObject *exception)
1447
0
{
1448
0
    PyObject *return_value = NULL;
1449
1450
0
    return_value = _asyncio_Task_set_exception_impl((TaskObj *)self, exception);
1451
1452
0
    return return_value;
1453
0
}
1454
1455
PyDoc_STRVAR(_asyncio_Task_get_coro__doc__,
1456
"get_coro($self, /)\n"
1457
"--\n"
1458
"\n");
1459
1460
#define _ASYNCIO_TASK_GET_CORO_METHODDEF    \
1461
    {"get_coro", (PyCFunction)_asyncio_Task_get_coro, METH_NOARGS, _asyncio_Task_get_coro__doc__},
1462
1463
static PyObject *
1464
_asyncio_Task_get_coro_impl(TaskObj *self);
1465
1466
static PyObject *
1467
_asyncio_Task_get_coro(PyObject *self, PyObject *Py_UNUSED(ignored))
1468
0
{
1469
0
    PyObject *return_value = NULL;
1470
1471
0
    Py_BEGIN_CRITICAL_SECTION(self);
1472
0
    return_value = _asyncio_Task_get_coro_impl((TaskObj *)self);
1473
0
    Py_END_CRITICAL_SECTION();
1474
1475
0
    return return_value;
1476
0
}
1477
1478
PyDoc_STRVAR(_asyncio_Task_get_context__doc__,
1479
"get_context($self, /)\n"
1480
"--\n"
1481
"\n");
1482
1483
#define _ASYNCIO_TASK_GET_CONTEXT_METHODDEF    \
1484
    {"get_context", (PyCFunction)_asyncio_Task_get_context, METH_NOARGS, _asyncio_Task_get_context__doc__},
1485
1486
static PyObject *
1487
_asyncio_Task_get_context_impl(TaskObj *self);
1488
1489
static PyObject *
1490
_asyncio_Task_get_context(PyObject *self, PyObject *Py_UNUSED(ignored))
1491
0
{
1492
0
    return _asyncio_Task_get_context_impl((TaskObj *)self);
1493
0
}
1494
1495
PyDoc_STRVAR(_asyncio_Task_get_name__doc__,
1496
"get_name($self, /)\n"
1497
"--\n"
1498
"\n");
1499
1500
#define _ASYNCIO_TASK_GET_NAME_METHODDEF    \
1501
    {"get_name", (PyCFunction)_asyncio_Task_get_name, METH_NOARGS, _asyncio_Task_get_name__doc__},
1502
1503
static PyObject *
1504
_asyncio_Task_get_name_impl(TaskObj *self);
1505
1506
static PyObject *
1507
_asyncio_Task_get_name(PyObject *self, PyObject *Py_UNUSED(ignored))
1508
0
{
1509
0
    PyObject *return_value = NULL;
1510
1511
0
    Py_BEGIN_CRITICAL_SECTION(self);
1512
0
    return_value = _asyncio_Task_get_name_impl((TaskObj *)self);
1513
0
    Py_END_CRITICAL_SECTION();
1514
1515
0
    return return_value;
1516
0
}
1517
1518
PyDoc_STRVAR(_asyncio_Task_set_name__doc__,
1519
"set_name($self, value, /)\n"
1520
"--\n"
1521
"\n");
1522
1523
#define _ASYNCIO_TASK_SET_NAME_METHODDEF    \
1524
    {"set_name", (PyCFunction)_asyncio_Task_set_name, METH_O, _asyncio_Task_set_name__doc__},
1525
1526
static PyObject *
1527
_asyncio_Task_set_name_impl(TaskObj *self, PyObject *value);
1528
1529
static PyObject *
1530
_asyncio_Task_set_name(PyObject *self, PyObject *value)
1531
0
{
1532
0
    PyObject *return_value = NULL;
1533
1534
0
    Py_BEGIN_CRITICAL_SECTION(self);
1535
0
    return_value = _asyncio_Task_set_name_impl((TaskObj *)self, value);
1536
0
    Py_END_CRITICAL_SECTION();
1537
1538
0
    return return_value;
1539
0
}
1540
1541
PyDoc_STRVAR(_asyncio__get_running_loop__doc__,
1542
"_get_running_loop($module, /)\n"
1543
"--\n"
1544
"\n"
1545
"Return the running event loop or None.\n"
1546
"\n"
1547
"This is a low-level function intended to be used by event loops.\n"
1548
"This function is thread-specific.");
1549
1550
#define _ASYNCIO__GET_RUNNING_LOOP_METHODDEF    \
1551
    {"_get_running_loop", (PyCFunction)_asyncio__get_running_loop, METH_NOARGS, _asyncio__get_running_loop__doc__},
1552
1553
static PyObject *
1554
_asyncio__get_running_loop_impl(PyObject *module);
1555
1556
static PyObject *
1557
_asyncio__get_running_loop(PyObject *module, PyObject *Py_UNUSED(ignored))
1558
0
{
1559
0
    return _asyncio__get_running_loop_impl(module);
1560
0
}
1561
1562
PyDoc_STRVAR(_asyncio__set_running_loop__doc__,
1563
"_set_running_loop($module, loop, /)\n"
1564
"--\n"
1565
"\n"
1566
"Set the running event loop.\n"
1567
"\n"
1568
"This is a low-level function intended to be used by event loops.\n"
1569
"This function is thread-specific.");
1570
1571
#define _ASYNCIO__SET_RUNNING_LOOP_METHODDEF    \
1572
    {"_set_running_loop", (PyCFunction)_asyncio__set_running_loop, METH_O, _asyncio__set_running_loop__doc__},
1573
1574
PyDoc_STRVAR(_asyncio_get_event_loop__doc__,
1575
"get_event_loop($module, /)\n"
1576
"--\n"
1577
"\n"
1578
"Return an asyncio event loop.\n"
1579
"\n"
1580
"When called from a coroutine or a callback (e.g. scheduled with\n"
1581
"call_soon or similar API), this function will always return the\n"
1582
"running event loop.\n"
1583
"\n"
1584
"If there is no running event loop set, the function will return\n"
1585
"the result of `get_event_loop_policy().get_event_loop()` call.");
1586
1587
#define _ASYNCIO_GET_EVENT_LOOP_METHODDEF    \
1588
    {"get_event_loop", (PyCFunction)_asyncio_get_event_loop, METH_NOARGS, _asyncio_get_event_loop__doc__},
1589
1590
static PyObject *
1591
_asyncio_get_event_loop_impl(PyObject *module);
1592
1593
static PyObject *
1594
_asyncio_get_event_loop(PyObject *module, PyObject *Py_UNUSED(ignored))
1595
0
{
1596
0
    return _asyncio_get_event_loop_impl(module);
1597
0
}
1598
1599
PyDoc_STRVAR(_asyncio_get_running_loop__doc__,
1600
"get_running_loop($module, /)\n"
1601
"--\n"
1602
"\n"
1603
"Return the running event loop.  Raise a RuntimeError if there is none.\n"
1604
"\n"
1605
"This function is thread-specific.");
1606
1607
#define _ASYNCIO_GET_RUNNING_LOOP_METHODDEF    \
1608
    {"get_running_loop", (PyCFunction)_asyncio_get_running_loop, METH_NOARGS, _asyncio_get_running_loop__doc__},
1609
1610
static PyObject *
1611
_asyncio_get_running_loop_impl(PyObject *module);
1612
1613
static PyObject *
1614
_asyncio_get_running_loop(PyObject *module, PyObject *Py_UNUSED(ignored))
1615
0
{
1616
0
    return _asyncio_get_running_loop_impl(module);
1617
0
}
1618
1619
PyDoc_STRVAR(_asyncio__register_task__doc__,
1620
"_register_task($module, /, task)\n"
1621
"--\n"
1622
"\n"
1623
"Register a new task in asyncio as executed by loop.\n"
1624
"\n"
1625
"Returns None.");
1626
1627
#define _ASYNCIO__REGISTER_TASK_METHODDEF    \
1628
    {"_register_task", _PyCFunction_CAST(_asyncio__register_task), METH_FASTCALL|METH_KEYWORDS, _asyncio__register_task__doc__},
1629
1630
static PyObject *
1631
_asyncio__register_task_impl(PyObject *module, PyObject *task);
1632
1633
static PyObject *
1634
_asyncio__register_task(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1635
0
{
1636
0
    PyObject *return_value = NULL;
1637
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1638
1639
0
    #define NUM_KEYWORDS 1
1640
0
    static struct {
1641
0
        PyGC_Head _this_is_not_used;
1642
0
        PyObject_VAR_HEAD
1643
0
        Py_hash_t ob_hash;
1644
0
        PyObject *ob_item[NUM_KEYWORDS];
1645
0
    } _kwtuple = {
1646
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1647
0
        .ob_hash = -1,
1648
0
        .ob_item = { &_Py_ID(task), },
1649
0
    };
1650
0
    #undef NUM_KEYWORDS
1651
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1652
1653
    #else  // !Py_BUILD_CORE
1654
    #  define KWTUPLE NULL
1655
    #endif  // !Py_BUILD_CORE
1656
1657
0
    static const char * const _keywords[] = {"task", NULL};
1658
0
    static _PyArg_Parser _parser = {
1659
0
        .keywords = _keywords,
1660
0
        .fname = "_register_task",
1661
0
        .kwtuple = KWTUPLE,
1662
0
    };
1663
0
    #undef KWTUPLE
1664
0
    PyObject *argsbuf[1];
1665
0
    PyObject *task;
1666
1667
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1668
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1669
0
    if (!args) {
1670
0
        goto exit;
1671
0
    }
1672
0
    task = args[0];
1673
0
    return_value = _asyncio__register_task_impl(module, task);
1674
1675
0
exit:
1676
0
    return return_value;
1677
0
}
1678
1679
PyDoc_STRVAR(_asyncio__register_eager_task__doc__,
1680
"_register_eager_task($module, /, task)\n"
1681
"--\n"
1682
"\n"
1683
"Register a new task in asyncio as executed by loop.\n"
1684
"\n"
1685
"Returns None.");
1686
1687
#define _ASYNCIO__REGISTER_EAGER_TASK_METHODDEF    \
1688
    {"_register_eager_task", _PyCFunction_CAST(_asyncio__register_eager_task), METH_FASTCALL|METH_KEYWORDS, _asyncio__register_eager_task__doc__},
1689
1690
static PyObject *
1691
_asyncio__register_eager_task_impl(PyObject *module, PyObject *task);
1692
1693
static PyObject *
1694
_asyncio__register_eager_task(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1695
0
{
1696
0
    PyObject *return_value = NULL;
1697
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1698
1699
0
    #define NUM_KEYWORDS 1
1700
0
    static struct {
1701
0
        PyGC_Head _this_is_not_used;
1702
0
        PyObject_VAR_HEAD
1703
0
        Py_hash_t ob_hash;
1704
0
        PyObject *ob_item[NUM_KEYWORDS];
1705
0
    } _kwtuple = {
1706
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1707
0
        .ob_hash = -1,
1708
0
        .ob_item = { &_Py_ID(task), },
1709
0
    };
1710
0
    #undef NUM_KEYWORDS
1711
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1712
1713
    #else  // !Py_BUILD_CORE
1714
    #  define KWTUPLE NULL
1715
    #endif  // !Py_BUILD_CORE
1716
1717
0
    static const char * const _keywords[] = {"task", NULL};
1718
0
    static _PyArg_Parser _parser = {
1719
0
        .keywords = _keywords,
1720
0
        .fname = "_register_eager_task",
1721
0
        .kwtuple = KWTUPLE,
1722
0
    };
1723
0
    #undef KWTUPLE
1724
0
    PyObject *argsbuf[1];
1725
0
    PyObject *task;
1726
1727
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1728
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1729
0
    if (!args) {
1730
0
        goto exit;
1731
0
    }
1732
0
    task = args[0];
1733
0
    return_value = _asyncio__register_eager_task_impl(module, task);
1734
1735
0
exit:
1736
0
    return return_value;
1737
0
}
1738
1739
PyDoc_STRVAR(_asyncio__unregister_task__doc__,
1740
"_unregister_task($module, /, task)\n"
1741
"--\n"
1742
"\n"
1743
"Unregister a task.\n"
1744
"\n"
1745
"Returns None.");
1746
1747
#define _ASYNCIO__UNREGISTER_TASK_METHODDEF    \
1748
    {"_unregister_task", _PyCFunction_CAST(_asyncio__unregister_task), METH_FASTCALL|METH_KEYWORDS, _asyncio__unregister_task__doc__},
1749
1750
static PyObject *
1751
_asyncio__unregister_task_impl(PyObject *module, PyObject *task);
1752
1753
static PyObject *
1754
_asyncio__unregister_task(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1755
0
{
1756
0
    PyObject *return_value = NULL;
1757
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1758
1759
0
    #define NUM_KEYWORDS 1
1760
0
    static struct {
1761
0
        PyGC_Head _this_is_not_used;
1762
0
        PyObject_VAR_HEAD
1763
0
        Py_hash_t ob_hash;
1764
0
        PyObject *ob_item[NUM_KEYWORDS];
1765
0
    } _kwtuple = {
1766
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1767
0
        .ob_hash = -1,
1768
0
        .ob_item = { &_Py_ID(task), },
1769
0
    };
1770
0
    #undef NUM_KEYWORDS
1771
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1772
1773
    #else  // !Py_BUILD_CORE
1774
    #  define KWTUPLE NULL
1775
    #endif  // !Py_BUILD_CORE
1776
1777
0
    static const char * const _keywords[] = {"task", NULL};
1778
0
    static _PyArg_Parser _parser = {
1779
0
        .keywords = _keywords,
1780
0
        .fname = "_unregister_task",
1781
0
        .kwtuple = KWTUPLE,
1782
0
    };
1783
0
    #undef KWTUPLE
1784
0
    PyObject *argsbuf[1];
1785
0
    PyObject *task;
1786
1787
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1788
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1789
0
    if (!args) {
1790
0
        goto exit;
1791
0
    }
1792
0
    task = args[0];
1793
0
    return_value = _asyncio__unregister_task_impl(module, task);
1794
1795
0
exit:
1796
0
    return return_value;
1797
0
}
1798
1799
PyDoc_STRVAR(_asyncio__unregister_eager_task__doc__,
1800
"_unregister_eager_task($module, /, task)\n"
1801
"--\n"
1802
"\n"
1803
"Unregister a task.\n"
1804
"\n"
1805
"Returns None.");
1806
1807
#define _ASYNCIO__UNREGISTER_EAGER_TASK_METHODDEF    \
1808
    {"_unregister_eager_task", _PyCFunction_CAST(_asyncio__unregister_eager_task), METH_FASTCALL|METH_KEYWORDS, _asyncio__unregister_eager_task__doc__},
1809
1810
static PyObject *
1811
_asyncio__unregister_eager_task_impl(PyObject *module, PyObject *task);
1812
1813
static PyObject *
1814
_asyncio__unregister_eager_task(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1815
0
{
1816
0
    PyObject *return_value = NULL;
1817
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1818
1819
0
    #define NUM_KEYWORDS 1
1820
0
    static struct {
1821
0
        PyGC_Head _this_is_not_used;
1822
0
        PyObject_VAR_HEAD
1823
0
        Py_hash_t ob_hash;
1824
0
        PyObject *ob_item[NUM_KEYWORDS];
1825
0
    } _kwtuple = {
1826
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1827
0
        .ob_hash = -1,
1828
0
        .ob_item = { &_Py_ID(task), },
1829
0
    };
1830
0
    #undef NUM_KEYWORDS
1831
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1832
1833
    #else  // !Py_BUILD_CORE
1834
    #  define KWTUPLE NULL
1835
    #endif  // !Py_BUILD_CORE
1836
1837
0
    static const char * const _keywords[] = {"task", NULL};
1838
0
    static _PyArg_Parser _parser = {
1839
0
        .keywords = _keywords,
1840
0
        .fname = "_unregister_eager_task",
1841
0
        .kwtuple = KWTUPLE,
1842
0
    };
1843
0
    #undef KWTUPLE
1844
0
    PyObject *argsbuf[1];
1845
0
    PyObject *task;
1846
1847
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1848
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1849
0
    if (!args) {
1850
0
        goto exit;
1851
0
    }
1852
0
    task = args[0];
1853
0
    return_value = _asyncio__unregister_eager_task_impl(module, task);
1854
1855
0
exit:
1856
0
    return return_value;
1857
0
}
1858
1859
PyDoc_STRVAR(_asyncio__enter_task__doc__,
1860
"_enter_task($module, /, loop, task)\n"
1861
"--\n"
1862
"\n"
1863
"Enter into task execution or resume suspended task.\n"
1864
"\n"
1865
"Task belongs to loop.\n"
1866
"\n"
1867
"Returns None.");
1868
1869
#define _ASYNCIO__ENTER_TASK_METHODDEF    \
1870
    {"_enter_task", _PyCFunction_CAST(_asyncio__enter_task), METH_FASTCALL|METH_KEYWORDS, _asyncio__enter_task__doc__},
1871
1872
static PyObject *
1873
_asyncio__enter_task_impl(PyObject *module, PyObject *loop, PyObject *task);
1874
1875
static PyObject *
1876
_asyncio__enter_task(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1877
0
{
1878
0
    PyObject *return_value = NULL;
1879
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1880
1881
0
    #define NUM_KEYWORDS 2
1882
0
    static struct {
1883
0
        PyGC_Head _this_is_not_used;
1884
0
        PyObject_VAR_HEAD
1885
0
        Py_hash_t ob_hash;
1886
0
        PyObject *ob_item[NUM_KEYWORDS];
1887
0
    } _kwtuple = {
1888
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1889
0
        .ob_hash = -1,
1890
0
        .ob_item = { &_Py_ID(loop), &_Py_ID(task), },
1891
0
    };
1892
0
    #undef NUM_KEYWORDS
1893
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1894
1895
    #else  // !Py_BUILD_CORE
1896
    #  define KWTUPLE NULL
1897
    #endif  // !Py_BUILD_CORE
1898
1899
0
    static const char * const _keywords[] = {"loop", "task", NULL};
1900
0
    static _PyArg_Parser _parser = {
1901
0
        .keywords = _keywords,
1902
0
        .fname = "_enter_task",
1903
0
        .kwtuple = KWTUPLE,
1904
0
    };
1905
0
    #undef KWTUPLE
1906
0
    PyObject *argsbuf[2];
1907
0
    PyObject *loop;
1908
0
    PyObject *task;
1909
1910
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1911
0
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1912
0
    if (!args) {
1913
0
        goto exit;
1914
0
    }
1915
0
    loop = args[0];
1916
0
    task = args[1];
1917
0
    return_value = _asyncio__enter_task_impl(module, loop, task);
1918
1919
0
exit:
1920
0
    return return_value;
1921
0
}
1922
1923
PyDoc_STRVAR(_asyncio__leave_task__doc__,
1924
"_leave_task($module, /, loop, task)\n"
1925
"--\n"
1926
"\n"
1927
"Leave task execution or suspend a task.\n"
1928
"\n"
1929
"Task belongs to loop.\n"
1930
"\n"
1931
"Returns None.");
1932
1933
#define _ASYNCIO__LEAVE_TASK_METHODDEF    \
1934
    {"_leave_task", _PyCFunction_CAST(_asyncio__leave_task), METH_FASTCALL|METH_KEYWORDS, _asyncio__leave_task__doc__},
1935
1936
static PyObject *
1937
_asyncio__leave_task_impl(PyObject *module, PyObject *loop, PyObject *task);
1938
1939
static PyObject *
1940
_asyncio__leave_task(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1941
0
{
1942
0
    PyObject *return_value = NULL;
1943
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1944
1945
0
    #define NUM_KEYWORDS 2
1946
0
    static struct {
1947
0
        PyGC_Head _this_is_not_used;
1948
0
        PyObject_VAR_HEAD
1949
0
        Py_hash_t ob_hash;
1950
0
        PyObject *ob_item[NUM_KEYWORDS];
1951
0
    } _kwtuple = {
1952
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1953
0
        .ob_hash = -1,
1954
0
        .ob_item = { &_Py_ID(loop), &_Py_ID(task), },
1955
0
    };
1956
0
    #undef NUM_KEYWORDS
1957
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1958
1959
    #else  // !Py_BUILD_CORE
1960
    #  define KWTUPLE NULL
1961
    #endif  // !Py_BUILD_CORE
1962
1963
0
    static const char * const _keywords[] = {"loop", "task", NULL};
1964
0
    static _PyArg_Parser _parser = {
1965
0
        .keywords = _keywords,
1966
0
        .fname = "_leave_task",
1967
0
        .kwtuple = KWTUPLE,
1968
0
    };
1969
0
    #undef KWTUPLE
1970
0
    PyObject *argsbuf[2];
1971
0
    PyObject *loop;
1972
0
    PyObject *task;
1973
1974
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1975
0
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1976
0
    if (!args) {
1977
0
        goto exit;
1978
0
    }
1979
0
    loop = args[0];
1980
0
    task = args[1];
1981
0
    return_value = _asyncio__leave_task_impl(module, loop, task);
1982
1983
0
exit:
1984
0
    return return_value;
1985
0
}
1986
1987
PyDoc_STRVAR(_asyncio__swap_current_task__doc__,
1988
"_swap_current_task($module, /, loop, task)\n"
1989
"--\n"
1990
"\n"
1991
"Temporarily swap in the supplied task and return the original one (or None).\n"
1992
"\n"
1993
"This is intended for use during eager coroutine execution.");
1994
1995
#define _ASYNCIO__SWAP_CURRENT_TASK_METHODDEF    \
1996
    {"_swap_current_task", _PyCFunction_CAST(_asyncio__swap_current_task), METH_FASTCALL|METH_KEYWORDS, _asyncio__swap_current_task__doc__},
1997
1998
static PyObject *
1999
_asyncio__swap_current_task_impl(PyObject *module, PyObject *loop,
2000
                                 PyObject *task);
2001
2002
static PyObject *
2003
_asyncio__swap_current_task(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2004
0
{
2005
0
    PyObject *return_value = NULL;
2006
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2007
2008
0
    #define NUM_KEYWORDS 2
2009
0
    static struct {
2010
0
        PyGC_Head _this_is_not_used;
2011
0
        PyObject_VAR_HEAD
2012
0
        Py_hash_t ob_hash;
2013
0
        PyObject *ob_item[NUM_KEYWORDS];
2014
0
    } _kwtuple = {
2015
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2016
0
        .ob_hash = -1,
2017
0
        .ob_item = { &_Py_ID(loop), &_Py_ID(task), },
2018
0
    };
2019
0
    #undef NUM_KEYWORDS
2020
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2021
2022
    #else  // !Py_BUILD_CORE
2023
    #  define KWTUPLE NULL
2024
    #endif  // !Py_BUILD_CORE
2025
2026
0
    static const char * const _keywords[] = {"loop", "task", NULL};
2027
0
    static _PyArg_Parser _parser = {
2028
0
        .keywords = _keywords,
2029
0
        .fname = "_swap_current_task",
2030
0
        .kwtuple = KWTUPLE,
2031
0
    };
2032
0
    #undef KWTUPLE
2033
0
    PyObject *argsbuf[2];
2034
0
    PyObject *loop;
2035
0
    PyObject *task;
2036
2037
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2038
0
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2039
0
    if (!args) {
2040
0
        goto exit;
2041
0
    }
2042
0
    loop = args[0];
2043
0
    task = args[1];
2044
0
    return_value = _asyncio__swap_current_task_impl(module, loop, task);
2045
2046
0
exit:
2047
0
    return return_value;
2048
0
}
2049
2050
PyDoc_STRVAR(_asyncio_current_task__doc__,
2051
"current_task($module, /, loop=None)\n"
2052
"--\n"
2053
"\n"
2054
"Return a currently executed task.");
2055
2056
#define _ASYNCIO_CURRENT_TASK_METHODDEF    \
2057
    {"current_task", _PyCFunction_CAST(_asyncio_current_task), METH_FASTCALL|METH_KEYWORDS, _asyncio_current_task__doc__},
2058
2059
static PyObject *
2060
_asyncio_current_task_impl(PyObject *module, PyObject *loop);
2061
2062
static PyObject *
2063
_asyncio_current_task(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2064
0
{
2065
0
    PyObject *return_value = NULL;
2066
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2067
2068
0
    #define NUM_KEYWORDS 1
2069
0
    static struct {
2070
0
        PyGC_Head _this_is_not_used;
2071
0
        PyObject_VAR_HEAD
2072
0
        Py_hash_t ob_hash;
2073
0
        PyObject *ob_item[NUM_KEYWORDS];
2074
0
    } _kwtuple = {
2075
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2076
0
        .ob_hash = -1,
2077
0
        .ob_item = { &_Py_ID(loop), },
2078
0
    };
2079
0
    #undef NUM_KEYWORDS
2080
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2081
2082
    #else  // !Py_BUILD_CORE
2083
    #  define KWTUPLE NULL
2084
    #endif  // !Py_BUILD_CORE
2085
2086
0
    static const char * const _keywords[] = {"loop", NULL};
2087
0
    static _PyArg_Parser _parser = {
2088
0
        .keywords = _keywords,
2089
0
        .fname = "current_task",
2090
0
        .kwtuple = KWTUPLE,
2091
0
    };
2092
0
    #undef KWTUPLE
2093
0
    PyObject *argsbuf[1];
2094
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
2095
0
    PyObject *loop = Py_None;
2096
2097
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2098
0
            /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2099
0
    if (!args) {
2100
0
        goto exit;
2101
0
    }
2102
0
    if (!noptargs) {
2103
0
        goto skip_optional_pos;
2104
0
    }
2105
0
    loop = args[0];
2106
0
skip_optional_pos:
2107
0
    return_value = _asyncio_current_task_impl(module, loop);
2108
2109
0
exit:
2110
0
    return return_value;
2111
0
}
2112
2113
PyDoc_STRVAR(_asyncio_all_tasks__doc__,
2114
"all_tasks($module, /, loop=None)\n"
2115
"--\n"
2116
"\n"
2117
"Return a set of all tasks for the loop.");
2118
2119
#define _ASYNCIO_ALL_TASKS_METHODDEF    \
2120
    {"all_tasks", _PyCFunction_CAST(_asyncio_all_tasks), METH_FASTCALL|METH_KEYWORDS, _asyncio_all_tasks__doc__},
2121
2122
static PyObject *
2123
_asyncio_all_tasks_impl(PyObject *module, PyObject *loop);
2124
2125
static PyObject *
2126
_asyncio_all_tasks(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2127
0
{
2128
0
    PyObject *return_value = NULL;
2129
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2130
2131
0
    #define NUM_KEYWORDS 1
2132
0
    static struct {
2133
0
        PyGC_Head _this_is_not_used;
2134
0
        PyObject_VAR_HEAD
2135
0
        Py_hash_t ob_hash;
2136
0
        PyObject *ob_item[NUM_KEYWORDS];
2137
0
    } _kwtuple = {
2138
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2139
0
        .ob_hash = -1,
2140
0
        .ob_item = { &_Py_ID(loop), },
2141
0
    };
2142
0
    #undef NUM_KEYWORDS
2143
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2144
2145
    #else  // !Py_BUILD_CORE
2146
    #  define KWTUPLE NULL
2147
    #endif  // !Py_BUILD_CORE
2148
2149
0
    static const char * const _keywords[] = {"loop", NULL};
2150
0
    static _PyArg_Parser _parser = {
2151
0
        .keywords = _keywords,
2152
0
        .fname = "all_tasks",
2153
0
        .kwtuple = KWTUPLE,
2154
0
    };
2155
0
    #undef KWTUPLE
2156
0
    PyObject *argsbuf[1];
2157
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
2158
0
    PyObject *loop = Py_None;
2159
2160
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2161
0
            /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2162
0
    if (!args) {
2163
0
        goto exit;
2164
0
    }
2165
0
    if (!noptargs) {
2166
0
        goto skip_optional_pos;
2167
0
    }
2168
0
    loop = args[0];
2169
0
skip_optional_pos:
2170
0
    return_value = _asyncio_all_tasks_impl(module, loop);
2171
2172
0
exit:
2173
0
    return return_value;
2174
0
}
2175
2176
PyDoc_STRVAR(_asyncio_future_add_to_awaited_by__doc__,
2177
"future_add_to_awaited_by($module, fut, waiter, /)\n"
2178
"--\n"
2179
"\n"
2180
"Record that `fut` is awaited on by `waiter`.");
2181
2182
#define _ASYNCIO_FUTURE_ADD_TO_AWAITED_BY_METHODDEF    \
2183
    {"future_add_to_awaited_by", _PyCFunction_CAST(_asyncio_future_add_to_awaited_by), METH_FASTCALL, _asyncio_future_add_to_awaited_by__doc__},
2184
2185
static PyObject *
2186
_asyncio_future_add_to_awaited_by_impl(PyObject *module, PyObject *fut,
2187
                                       PyObject *waiter);
2188
2189
static PyObject *
2190
_asyncio_future_add_to_awaited_by(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
2191
0
{
2192
0
    PyObject *return_value = NULL;
2193
0
    PyObject *fut;
2194
0
    PyObject *waiter;
2195
2196
0
    if (!_PyArg_CheckPositional("future_add_to_awaited_by", nargs, 2, 2)) {
2197
0
        goto exit;
2198
0
    }
2199
0
    fut = args[0];
2200
0
    waiter = args[1];
2201
0
    return_value = _asyncio_future_add_to_awaited_by_impl(module, fut, waiter);
2202
2203
0
exit:
2204
0
    return return_value;
2205
0
}
2206
2207
PyDoc_STRVAR(_asyncio_future_discard_from_awaited_by__doc__,
2208
"future_discard_from_awaited_by($module, fut, waiter, /)\n"
2209
"--\n"
2210
"\n");
2211
2212
#define _ASYNCIO_FUTURE_DISCARD_FROM_AWAITED_BY_METHODDEF    \
2213
    {"future_discard_from_awaited_by", _PyCFunction_CAST(_asyncio_future_discard_from_awaited_by), METH_FASTCALL, _asyncio_future_discard_from_awaited_by__doc__},
2214
2215
static PyObject *
2216
_asyncio_future_discard_from_awaited_by_impl(PyObject *module, PyObject *fut,
2217
                                             PyObject *waiter);
2218
2219
static PyObject *
2220
_asyncio_future_discard_from_awaited_by(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
2221
0
{
2222
0
    PyObject *return_value = NULL;
2223
0
    PyObject *fut;
2224
0
    PyObject *waiter;
2225
2226
0
    if (!_PyArg_CheckPositional("future_discard_from_awaited_by", nargs, 2, 2)) {
2227
0
        goto exit;
2228
0
    }
2229
0
    fut = args[0];
2230
0
    waiter = args[1];
2231
0
    return_value = _asyncio_future_discard_from_awaited_by_impl(module, fut, waiter);
2232
2233
0
exit:
2234
0
    return return_value;
2235
0
}
2236
/*[clinic end generated code: output=32996fb47c48245b input=a9049054013a1b77]*/