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