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