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