1/*[clinic input]
2preserve
3[clinic start generated code]*/
4
5PyDoc_STRVAR(simplequeue_new__doc__,
6"SimpleQueue()\n"
7"--\n"
8"\n"
9"Simple, unbounded, reentrant FIFO queue.");
10
11static PyObject *
12simplequeue_new_impl(PyTypeObject *type);
13
14static PyObject *
15simplequeue_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
16{
17 PyObject *return_value = NULL;
18
19 if ((type == simplequeue_get_state_by_type(type)->SimpleQueueType) &&
20 !_PyArg_NoPositional("SimpleQueue", args)) {
21 goto exit;
22 }
23 if ((type == simplequeue_get_state_by_type(type)->SimpleQueueType) &&
24 !_PyArg_NoKeywords("SimpleQueue", kwargs)) {
25 goto exit;
26 }
27 return_value = simplequeue_new_impl(type);
28
29exit:
30 return return_value;
31}
32
33PyDoc_STRVAR(_queue_SimpleQueue_put__doc__,
34"put($self, /, item, block=True, timeout=None)\n"
35"--\n"
36"\n"
37"Put the item on the queue.\n"
38"\n"
39"The optional \'block\' and \'timeout\' arguments are ignored, as this method\n"
40"never blocks. They are provided for compatibility with the Queue class.");
41
42#define _QUEUE_SIMPLEQUEUE_PUT_METHODDEF \
43 {"put", (PyCFunction)(void(*)(void))_queue_SimpleQueue_put, METH_FASTCALL|METH_KEYWORDS, _queue_SimpleQueue_put__doc__},
44
45static PyObject *
46_queue_SimpleQueue_put_impl(simplequeueobject *self, PyObject *item,
47 int block, PyObject *timeout);
48
49static PyObject *
50_queue_SimpleQueue_put(simplequeueobject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
51{
52 PyObject *return_value = NULL;
53 static const char * const _keywords[] = {"item", "block", "timeout", NULL};
54 static _PyArg_Parser _parser = {NULL, _keywords, "put", 0};
55 PyObject *argsbuf[3];
56 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
57 PyObject *item;
58 int block = 1;
59 PyObject *timeout = Py_None;
60
61 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
62 if (!args) {
63 goto exit;
64 }
65 item = args[0];
66 if (!noptargs) {
67 goto skip_optional_pos;
68 }
69 if (args[1]) {
70 block = PyObject_IsTrue(args[1]);
71 if (block < 0) {
72 goto exit;
73 }
74 if (!--noptargs) {
75 goto skip_optional_pos;
76 }
77 }
78 timeout = args[2];
79skip_optional_pos:
80 return_value = _queue_SimpleQueue_put_impl(self, item, block, timeout);
81
82exit:
83 return return_value;
84}
85
86PyDoc_STRVAR(_queue_SimpleQueue_put_nowait__doc__,
87"put_nowait($self, /, item)\n"
88"--\n"
89"\n"
90"Put an item into the queue without blocking.\n"
91"\n"
92"This is exactly equivalent to `put(item)` and is only provided\n"
93"for compatibility with the Queue class.");
94
95#define _QUEUE_SIMPLEQUEUE_PUT_NOWAIT_METHODDEF \
96 {"put_nowait", (PyCFunction)(void(*)(void))_queue_SimpleQueue_put_nowait, METH_FASTCALL|METH_KEYWORDS, _queue_SimpleQueue_put_nowait__doc__},
97
98static PyObject *
99_queue_SimpleQueue_put_nowait_impl(simplequeueobject *self, PyObject *item);
100
101static PyObject *
102_queue_SimpleQueue_put_nowait(simplequeueobject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
103{
104 PyObject *return_value = NULL;
105 static const char * const _keywords[] = {"item", NULL};
106 static _PyArg_Parser _parser = {NULL, _keywords, "put_nowait", 0};
107 PyObject *argsbuf[1];
108 PyObject *item;
109
110 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
111 if (!args) {
112 goto exit;
113 }
114 item = args[0];
115 return_value = _queue_SimpleQueue_put_nowait_impl(self, item);
116
117exit:
118 return return_value;
119}
120
121PyDoc_STRVAR(_queue_SimpleQueue_get__doc__,
122"get($self, /, block=True, timeout=None)\n"
123"--\n"
124"\n"
125"Remove and return an item from the queue.\n"
126"\n"
127"If optional args \'block\' is true and \'timeout\' is None (the default),\n"
128"block if necessary until an item is available. If \'timeout\' is\n"
129"a non-negative number, it blocks at most \'timeout\' seconds and raises\n"
130"the Empty exception if no item was available within that time.\n"
131"Otherwise (\'block\' is false), return an item if one is immediately\n"
132"available, else raise the Empty exception (\'timeout\' is ignored\n"
133"in that case).");
134
135#define _QUEUE_SIMPLEQUEUE_GET_METHODDEF \
136 {"get", (PyCFunction)(void(*)(void))_queue_SimpleQueue_get, METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _queue_SimpleQueue_get__doc__},
137
138static PyObject *
139_queue_SimpleQueue_get_impl(simplequeueobject *self, PyTypeObject *cls,
140 int block, PyObject *timeout);
141
142static PyObject *
143_queue_SimpleQueue_get(simplequeueobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
144{
145 PyObject *return_value = NULL;
146 static const char * const _keywords[] = {"block", "timeout", NULL};
147 static _PyArg_Parser _parser = {NULL, _keywords, "get", 0};
148 PyObject *argsbuf[2];
149 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
150 int block = 1;
151 PyObject *timeout = Py_None;
152
153 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf);
154 if (!args) {
155 goto exit;
156 }
157 if (!noptargs) {
158 goto skip_optional_pos;
159 }
160 if (args[0]) {
161 block = PyObject_IsTrue(args[0]);
162 if (block < 0) {
163 goto exit;
164 }
165 if (!--noptargs) {
166 goto skip_optional_pos;
167 }
168 }
169 timeout = args[1];
170skip_optional_pos:
171 return_value = _queue_SimpleQueue_get_impl(self, cls, block, timeout);
172
173exit:
174 return return_value;
175}
176
177PyDoc_STRVAR(_queue_SimpleQueue_get_nowait__doc__,
178"get_nowait($self, /)\n"
179"--\n"
180"\n"
181"Remove and return an item from the queue without blocking.\n"
182"\n"
183"Only get an item if one is immediately available. Otherwise\n"
184"raise the Empty exception.");
185
186#define _QUEUE_SIMPLEQUEUE_GET_NOWAIT_METHODDEF \
187 {"get_nowait", (PyCFunction)(void(*)(void))_queue_SimpleQueue_get_nowait, METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _queue_SimpleQueue_get_nowait__doc__},
188
189static PyObject *
190_queue_SimpleQueue_get_nowait_impl(simplequeueobject *self,
191 PyTypeObject *cls);
192
193static PyObject *
194_queue_SimpleQueue_get_nowait(simplequeueobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
195{
196 if (nargs) {
197 PyErr_SetString(PyExc_TypeError, "get_nowait() takes no arguments");
198 return NULL;
199 }
200 return _queue_SimpleQueue_get_nowait_impl(self, cls);
201}
202
203PyDoc_STRVAR(_queue_SimpleQueue_empty__doc__,
204"empty($self, /)\n"
205"--\n"
206"\n"
207"Return True if the queue is empty, False otherwise (not reliable!).");
208
209#define _QUEUE_SIMPLEQUEUE_EMPTY_METHODDEF \
210 {"empty", (PyCFunction)_queue_SimpleQueue_empty, METH_NOARGS, _queue_SimpleQueue_empty__doc__},
211
212static int
213_queue_SimpleQueue_empty_impl(simplequeueobject *self);
214
215static PyObject *
216_queue_SimpleQueue_empty(simplequeueobject *self, PyObject *Py_UNUSED(ignored))
217{
218 PyObject *return_value = NULL;
219 int _return_value;
220
221 _return_value = _queue_SimpleQueue_empty_impl(self);
222 if ((_return_value == -1) && PyErr_Occurred()) {
223 goto exit;
224 }
225 return_value = PyBool_FromLong((long)_return_value);
226
227exit:
228 return return_value;
229}
230
231PyDoc_STRVAR(_queue_SimpleQueue_qsize__doc__,
232"qsize($self, /)\n"
233"--\n"
234"\n"
235"Return the approximate size of the queue (not reliable!).");
236
237#define _QUEUE_SIMPLEQUEUE_QSIZE_METHODDEF \
238 {"qsize", (PyCFunction)_queue_SimpleQueue_qsize, METH_NOARGS, _queue_SimpleQueue_qsize__doc__},
239
240static Py_ssize_t
241_queue_SimpleQueue_qsize_impl(simplequeueobject *self);
242
243static PyObject *
244_queue_SimpleQueue_qsize(simplequeueobject *self, PyObject *Py_UNUSED(ignored))
245{
246 PyObject *return_value = NULL;
247 Py_ssize_t _return_value;
248
249 _return_value = _queue_SimpleQueue_qsize_impl(self);
250 if ((_return_value == -1) && PyErr_Occurred()) {
251 goto exit;
252 }
253 return_value = PyLong_FromSsize_t(_return_value);
254
255exit:
256 return return_value;
257}
258/*[clinic end generated code: output=a9d567e8a64e6170 input=a9049054013a1b77]*/
259