Debian Codegraph @

Modules/clinic/_queuemodule.c.h

raw
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_NoKeywords()
11
12 PyDoc_STRVAR(simplequeue_new__doc__,
13 "SimpleQueue()\n"
14 "--\n"
15 "\n"
16 "Simple, unbounded, reentrant FIFO queue.");
17
18 static PyObject *
19 simplequeue_new_impl(PyTypeObject *type);
20
21 static PyObject *
22 simplequeue_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
23 {
24 PyObject *return_value = NULL;
25 PyTypeObject *base_tp = simplequeue_get_state_by_type(type)->SimpleQueueType;
26
27 if ((type == base_tp || type->tp_init == base_tp->tp_init) &&
28 !_PyArg_NoPositional("SimpleQueue", args)) {
29 goto exit;
30 }
31 if ((type == base_tp || type->tp_init == base_tp->tp_init) &&
32 !_PyArg_NoKeywords("SimpleQueue", kwargs)) {
33 goto exit;
34 }
35 return_value = simplequeue_new_impl(type);
36
37 exit:
38 return return_value;
39 }
40
41 PyDoc_STRVAR(_queue_SimpleQueue_put__doc__,
42 "put($self, /, item, block=True, timeout=None)\n"
43 "--\n"
44 "\n"
45 "Put the item on the queue.\n"
46 "\n"
47 "The optional \'block\' and \'timeout\' arguments are ignored, as this\n"
48 "method never blocks. They are provided for compatibility with the\n"
49 "Queue class.");
50
51 #define _QUEUE_SIMPLEQUEUE_PUT_METHODDEF \
52 {"put", _PyCFunction_CAST(_queue_SimpleQueue_put), METH_FASTCALL|METH_KEYWORDS, _queue_SimpleQueue_put__doc__},
53
54 static PyObject *
55 _queue_SimpleQueue_put_impl(simplequeueobject *self, PyObject *item,
56 int block, PyObject *timeout);
57
58 static PyObject *
59 _queue_SimpleQueue_put(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
60 {
61 PyObject *return_value = NULL;
62 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
63
64 #define NUM_KEYWORDS 3
65 static struct {
66 PyGC_Head _this_is_not_used;
67 PyObject_VAR_HEAD
68 Py_hash_t ob_hash;
69 PyObject *ob_item[NUM_KEYWORDS];
70 } _kwtuple = {
71 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
72 .ob_hash = -1,
73 .ob_item = { &_Py_ID(item), &_Py_ID(block), &_Py_ID(timeout), },
74 };
75 #undef NUM_KEYWORDS
76 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
77
78 #else // !Py_BUILD_CORE
79 # define KWTUPLE NULL
80 #endif // !Py_BUILD_CORE
81
82 static const char * const _keywords[] = {"item", "block", "timeout", NULL};
83 static _PyArg_Parser _parser = {
84 .keywords = _keywords,
85 .fname = "put",
86 .kwtuple = KWTUPLE,
87 };
88 #undef KWTUPLE
89 PyObject *argsbuf[3];
90 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
91 PyObject *item;
92 int block = 1;
93 PyObject *timeout = Py_None;
94
95 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
96 /*minpos*/ 1, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
97 if (!args) {
98 goto exit;
99 }
100 item = args[0];
101 if (!noptargs) {
102 goto skip_optional_pos;
103 }
104 if (args[1]) {
105 block = PyObject_IsTrue(args[1]);
106 if (block < 0) {
107 goto exit;
108 }
109 if (!--noptargs) {
110 goto skip_optional_pos;
111 }
112 }
113 timeout = args[2];
114 skip_optional_pos:
115 Py_BEGIN_CRITICAL_SECTION(self);
116 return_value = _queue_SimpleQueue_put_impl((simplequeueobject *)self, item, block, timeout);
117 Py_END_CRITICAL_SECTION();
118
119 exit:
120 return return_value;
121 }
122
123 PyDoc_STRVAR(_queue_SimpleQueue_put_nowait__doc__,
124 "put_nowait($self, /, item)\n"
125 "--\n"
126 "\n"
127 "Put an item into the queue without blocking.\n"
128 "\n"
129 "This is exactly equivalent to `put(item)` and is only provided\n"
130 "for compatibility with the Queue class.");
131
132 #define _QUEUE_SIMPLEQUEUE_PUT_NOWAIT_METHODDEF \
133 {"put_nowait", _PyCFunction_CAST(_queue_SimpleQueue_put_nowait), METH_FASTCALL|METH_KEYWORDS, _queue_SimpleQueue_put_nowait__doc__},
134
135 static PyObject *
136 _queue_SimpleQueue_put_nowait_impl(simplequeueobject *self, PyObject *item);
137
138 static PyObject *
139 _queue_SimpleQueue_put_nowait(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
140 {
141 PyObject *return_value = NULL;
142 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
143
144 #define NUM_KEYWORDS 1
145 static struct {
146 PyGC_Head _this_is_not_used;
147 PyObject_VAR_HEAD
148 Py_hash_t ob_hash;
149 PyObject *ob_item[NUM_KEYWORDS];
150 } _kwtuple = {
151 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
152 .ob_hash = -1,
153 .ob_item = { &_Py_ID(item), },
154 };
155 #undef NUM_KEYWORDS
156 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
157
158 #else // !Py_BUILD_CORE
159 # define KWTUPLE NULL
160 #endif // !Py_BUILD_CORE
161
162 static const char * const _keywords[] = {"item", NULL};
163 static _PyArg_Parser _parser = {
164 .keywords = _keywords,
165 .fname = "put_nowait",
166 .kwtuple = KWTUPLE,
167 };
168 #undef KWTUPLE
169 PyObject *argsbuf[1];
170 PyObject *item;
171
172 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
173 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
174 if (!args) {
175 goto exit;
176 }
177 item = args[0];
178 Py_BEGIN_CRITICAL_SECTION(self);
179 return_value = _queue_SimpleQueue_put_nowait_impl((simplequeueobject *)self, item);
180 Py_END_CRITICAL_SECTION();
181
182 exit:
183 return return_value;
184 }
185
186 PyDoc_STRVAR(_queue_SimpleQueue_get__doc__,
187 "get($self, /, block=True, timeout=None)\n"
188 "--\n"
189 "\n"
190 "Remove and return an item from the queue.\n"
191 "\n"
192 "If optional args \'block\' is true and \'timeout\' is None (the\n"
193 "default), block if necessary until an item is available. If\n"
194 "\'timeout\' is a non-negative number, it blocks at most \'timeout\'\n"
195 "seconds and raises the Empty exception if no item was available\n"
196 "within that time.\n"
197 "Otherwise (\'block\' is false), return an item if one is immediately\n"
198 "available, else raise the Empty exception (\'timeout\' is ignored\n"
199 "in that case).");
200
201 #define _QUEUE_SIMPLEQUEUE_GET_METHODDEF \
202 {"get", _PyCFunction_CAST(_queue_SimpleQueue_get), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _queue_SimpleQueue_get__doc__},
203
204 static PyObject *
205 _queue_SimpleQueue_get_impl(simplequeueobject *self, PyTypeObject *cls,
206 int block, PyObject *timeout_obj);
207
208 static PyObject *
209 _queue_SimpleQueue_get(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
210 {
211 PyObject *return_value = NULL;
212 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
213
214 #define NUM_KEYWORDS 2
215 static struct {
216 PyGC_Head _this_is_not_used;
217 PyObject_VAR_HEAD
218 Py_hash_t ob_hash;
219 PyObject *ob_item[NUM_KEYWORDS];
220 } _kwtuple = {
221 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
222 .ob_hash = -1,
223 .ob_item = { &_Py_ID(block), &_Py_ID(timeout), },
224 };
225 #undef NUM_KEYWORDS
226 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
227
228 #else // !Py_BUILD_CORE
229 # define KWTUPLE NULL
230 #endif // !Py_BUILD_CORE
231
232 static const char * const _keywords[] = {"block", "timeout", NULL};
233 static _PyArg_Parser _parser = {
234 .keywords = _keywords,
235 .fname = "get",
236 .kwtuple = KWTUPLE,
237 };
238 #undef KWTUPLE
239 PyObject *argsbuf[2];
240 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
241 int block = 1;
242 PyObject *timeout_obj = Py_None;
243
244 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
245 /*minpos*/ 0, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
246 if (!args) {
247 goto exit;
248 }
249 if (!noptargs) {
250 goto skip_optional_pos;
251 }
252 if (args[0]) {
253 block = PyObject_IsTrue(args[0]);
254 if (block < 0) {
255 goto exit;
256 }
257 if (!--noptargs) {
258 goto skip_optional_pos;
259 }
260 }
261 timeout_obj = args[1];
262 skip_optional_pos:
263 Py_BEGIN_CRITICAL_SECTION(self);
264 return_value = _queue_SimpleQueue_get_impl((simplequeueobject *)self, cls, block, timeout_obj);
265 Py_END_CRITICAL_SECTION();
266
267 exit:
268 return return_value;
269 }
270
271 PyDoc_STRVAR(_queue_SimpleQueue_get_nowait__doc__,
272 "get_nowait($self, /)\n"
273 "--\n"
274 "\n"
275 "Remove and return an item from the queue without blocking.\n"
276 "\n"
277 "Only get an item if one is immediately available. Otherwise\n"
278 "raise the Empty exception.");
279
280 #define _QUEUE_SIMPLEQUEUE_GET_NOWAIT_METHODDEF \
281 {"get_nowait", _PyCFunction_CAST(_queue_SimpleQueue_get_nowait), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _queue_SimpleQueue_get_nowait__doc__},
282
283 static PyObject *
284 _queue_SimpleQueue_get_nowait_impl(simplequeueobject *self,
285 PyTypeObject *cls);
286
287 static PyObject *
288 _queue_SimpleQueue_get_nowait(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
289 {
290 PyObject *return_value = NULL;
291
292 if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
293 PyErr_SetString(PyExc_TypeError, "get_nowait() takes no arguments");
294 goto exit;
295 }
296 Py_BEGIN_CRITICAL_SECTION(self);
297 return_value = _queue_SimpleQueue_get_nowait_impl((simplequeueobject *)self, cls);
298 Py_END_CRITICAL_SECTION();
299
300 exit:
301 return return_value;
302 }
303
304 PyDoc_STRVAR(_queue_SimpleQueue_empty__doc__,
305 "empty($self, /)\n"
306 "--\n"
307 "\n"
308 "Return True if the queue is empty, False otherwise (not reliable!).");
309
310 #define _QUEUE_SIMPLEQUEUE_EMPTY_METHODDEF \
311 {"empty", (PyCFunction)_queue_SimpleQueue_empty, METH_NOARGS, _queue_SimpleQueue_empty__doc__},
312
313 static int
314 _queue_SimpleQueue_empty_impl(simplequeueobject *self);
315
316 static PyObject *
317 _queue_SimpleQueue_empty(PyObject *self, PyObject *Py_UNUSED(ignored))
318 {
319 PyObject *return_value = NULL;
320 int _return_value;
321
322 Py_BEGIN_CRITICAL_SECTION(self);
323 _return_value = _queue_SimpleQueue_empty_impl((simplequeueobject *)self);
324 Py_END_CRITICAL_SECTION();
325 if ((_return_value == -1) && PyErr_Occurred()) {
326 goto exit;
327 }
328 return_value = PyBool_FromLong((long)_return_value);
329
330 exit:
331 return return_value;
332 }
333
334 PyDoc_STRVAR(_queue_SimpleQueue_qsize__doc__,
335 "qsize($self, /)\n"
336 "--\n"
337 "\n"
338 "Return the approximate size of the queue (not reliable!).");
339
340 #define _QUEUE_SIMPLEQUEUE_QSIZE_METHODDEF \
341 {"qsize", (PyCFunction)_queue_SimpleQueue_qsize, METH_NOARGS, _queue_SimpleQueue_qsize__doc__},
342
343 static Py_ssize_t
344 _queue_SimpleQueue_qsize_impl(simplequeueobject *self);
345
346 static PyObject *
347 _queue_SimpleQueue_qsize(PyObject *self, PyObject *Py_UNUSED(ignored))
348 {
349 PyObject *return_value = NULL;
350 Py_ssize_t _return_value;
351
352 Py_BEGIN_CRITICAL_SECTION(self);
353 _return_value = _queue_SimpleQueue_qsize_impl((simplequeueobject *)self);
354 Py_END_CRITICAL_SECTION();
355 if ((_return_value == -1) && PyErr_Occurred()) {
356 goto exit;
357 }
358 return_value = PyLong_FromSsize_t(_return_value);
359
360 exit:
361 return return_value;
362 }
363 /*[clinic end generated code: output=58cfee868040d297 input=a9049054013a1b77]*/