Coverage Report

Created: 2026-10-15 06:54

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