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