blob: 8741f7d9aff881096a2184dcd2bdede576e8e001 [file] [log] [blame]
Antoine Pitrou94e16962018-01-16 00:27:16 +01001/*[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
Erlend Egeberg Aasland01c6aa42020-11-07 20:18:37 +010019 if ((type == simplequeue_get_state_by_type(type)->SimpleQueueType) &&
Antoine Pitrou94e16962018-01-16 00:27:16 +010020 !_PyArg_NoPositional("SimpleQueue", args)) {
21 goto exit;
22 }
Erlend Egeberg Aasland01c6aa42020-11-07 20:18:37 +010023 if ((type == simplequeue_get_state_by_type(type)->SimpleQueueType) &&
Antoine Pitrou94e16962018-01-16 00:27:16 +010024 !_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 \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +020043 {"put", (PyCFunction)(void(*)(void))_queue_SimpleQueue_put, METH_FASTCALL|METH_KEYWORDS, _queue_SimpleQueue_put__doc__},
Antoine Pitrou94e16962018-01-16 00:27:16 +010044
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};
Serhiy Storchaka31913912019-03-14 10:32:22 +020054 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;
Antoine Pitrou94e16962018-01-16 00:27:16 +010057 PyObject *item;
58 int block = 1;
59 PyObject *timeout = Py_None;
60
Serhiy Storchaka31913912019-03-14 10:32:22 +020061 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
62 if (!args) {
Antoine Pitrou94e16962018-01-16 00:27:16 +010063 goto exit;
64 }
Serhiy Storchaka31913912019-03-14 10:32:22 +020065 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:
Antoine Pitrou94e16962018-01-16 00:27:16 +010080 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 \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +020096 {"put_nowait", (PyCFunction)(void(*)(void))_queue_SimpleQueue_put_nowait, METH_FASTCALL|METH_KEYWORDS, _queue_SimpleQueue_put_nowait__doc__},
Antoine Pitrou94e16962018-01-16 00:27:16 +010097
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};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200106 static _PyArg_Parser _parser = {NULL, _keywords, "put_nowait", 0};
107 PyObject *argsbuf[1];
Antoine Pitrou94e16962018-01-16 00:27:16 +0100108 PyObject *item;
109
Serhiy Storchaka31913912019-03-14 10:32:22 +0200110 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
111 if (!args) {
Antoine Pitrou94e16962018-01-16 00:27:16 +0100112 goto exit;
113 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200114 item = args[0];
Antoine Pitrou94e16962018-01-16 00:27:16 +0100115 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 \
Erlend Egeberg Aasland01c6aa42020-11-07 20:18:37 +0100136 {"get", (PyCFunction)(void(*)(void))_queue_SimpleQueue_get, METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _queue_SimpleQueue_get__doc__},
Antoine Pitrou94e16962018-01-16 00:27:16 +0100137
138static PyObject *
Erlend Egeberg Aasland01c6aa42020-11-07 20:18:37 +0100139_queue_SimpleQueue_get_impl(simplequeueobject *self, PyTypeObject *cls,
140 int block, PyObject *timeout);
Antoine Pitrou94e16962018-01-16 00:27:16 +0100141
142static PyObject *
Erlend Egeberg Aasland01c6aa42020-11-07 20:18:37 +0100143_queue_SimpleQueue_get(simplequeueobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Antoine Pitrou94e16962018-01-16 00:27:16 +0100144{
145 PyObject *return_value = NULL;
146 static const char * const _keywords[] = {"block", "timeout", NULL};
Erlend Egeberg Aasland01c6aa42020-11-07 20:18:37 +0100147 static _PyArg_Parser _parser = {"|pO:get", _keywords, 0};
Antoine Pitrou94e16962018-01-16 00:27:16 +0100148 int block = 1;
149 PyObject *timeout = Py_None;
150
Erlend Egeberg Aasland01c6aa42020-11-07 20:18:37 +0100151 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
152 &block, &timeout)) {
Antoine Pitrou94e16962018-01-16 00:27:16 +0100153 goto exit;
154 }
Erlend Egeberg Aasland01c6aa42020-11-07 20:18:37 +0100155 return_value = _queue_SimpleQueue_get_impl(self, cls, block, timeout);
Antoine Pitrou94e16962018-01-16 00:27:16 +0100156
157exit:
158 return return_value;
159}
160
161PyDoc_STRVAR(_queue_SimpleQueue_get_nowait__doc__,
162"get_nowait($self, /)\n"
163"--\n"
164"\n"
165"Remove and return an item from the queue without blocking.\n"
166"\n"
167"Only get an item if one is immediately available. Otherwise\n"
168"raise the Empty exception.");
169
170#define _QUEUE_SIMPLEQUEUE_GET_NOWAIT_METHODDEF \
Erlend Egeberg Aasland01c6aa42020-11-07 20:18:37 +0100171 {"get_nowait", (PyCFunction)(void(*)(void))_queue_SimpleQueue_get_nowait, METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _queue_SimpleQueue_get_nowait__doc__},
Antoine Pitrou94e16962018-01-16 00:27:16 +0100172
173static PyObject *
Erlend Egeberg Aasland01c6aa42020-11-07 20:18:37 +0100174_queue_SimpleQueue_get_nowait_impl(simplequeueobject *self,
175 PyTypeObject *cls);
Antoine Pitrou94e16962018-01-16 00:27:16 +0100176
177static PyObject *
Erlend Egeberg Aasland01c6aa42020-11-07 20:18:37 +0100178_queue_SimpleQueue_get_nowait(simplequeueobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Antoine Pitrou94e16962018-01-16 00:27:16 +0100179{
Erlend Egeberg Aasland01c6aa42020-11-07 20:18:37 +0100180 PyObject *return_value = NULL;
181 static const char * const _keywords[] = { NULL};
182 static _PyArg_Parser _parser = {":get_nowait", _keywords, 0};
183
184 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser
185 )) {
186 goto exit;
187 }
188 return_value = _queue_SimpleQueue_get_nowait_impl(self, cls);
189
190exit:
191 return return_value;
Antoine Pitrou94e16962018-01-16 00:27:16 +0100192}
193
194PyDoc_STRVAR(_queue_SimpleQueue_empty__doc__,
195"empty($self, /)\n"
196"--\n"
197"\n"
198"Return True if the queue is empty, False otherwise (not reliable!).");
199
200#define _QUEUE_SIMPLEQUEUE_EMPTY_METHODDEF \
201 {"empty", (PyCFunction)_queue_SimpleQueue_empty, METH_NOARGS, _queue_SimpleQueue_empty__doc__},
202
203static int
204_queue_SimpleQueue_empty_impl(simplequeueobject *self);
205
206static PyObject *
207_queue_SimpleQueue_empty(simplequeueobject *self, PyObject *Py_UNUSED(ignored))
208{
209 PyObject *return_value = NULL;
210 int _return_value;
211
212 _return_value = _queue_SimpleQueue_empty_impl(self);
213 if ((_return_value == -1) && PyErr_Occurred()) {
214 goto exit;
215 }
216 return_value = PyBool_FromLong((long)_return_value);
217
218exit:
219 return return_value;
220}
221
222PyDoc_STRVAR(_queue_SimpleQueue_qsize__doc__,
223"qsize($self, /)\n"
224"--\n"
225"\n"
226"Return the approximate size of the queue (not reliable!).");
227
228#define _QUEUE_SIMPLEQUEUE_QSIZE_METHODDEF \
229 {"qsize", (PyCFunction)_queue_SimpleQueue_qsize, METH_NOARGS, _queue_SimpleQueue_qsize__doc__},
230
231static Py_ssize_t
232_queue_SimpleQueue_qsize_impl(simplequeueobject *self);
233
234static PyObject *
235_queue_SimpleQueue_qsize(simplequeueobject *self, PyObject *Py_UNUSED(ignored))
236{
237 PyObject *return_value = NULL;
238 Py_ssize_t _return_value;
239
240 _return_value = _queue_SimpleQueue_qsize_impl(self);
241 if ((_return_value == -1) && PyErr_Occurred()) {
242 goto exit;
243 }
244 return_value = PyLong_FromSsize_t(_return_value);
245
246exit:
247 return return_value;
248}
Erlend Egeberg Aasland01c6aa42020-11-07 20:18:37 +0100249/*[clinic end generated code: output=ce56b46fac150909 input=a9049054013a1b77]*/