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 == &PySimpleQueueType) &&
20         !_PyArg_NoPositional("SimpleQueue", args)) {
21         goto exit;
22     }
23     if ((type == &PySimpleQueueType) &&
24         !_PyArg_NoKeywords("SimpleQueue", kwargs)) {
25         goto exit;
26     }
27     return_value = simplequeue_new_impl(type);
28 
29 exit:
30     return return_value;
31 }
32 
33 PyDoc_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 
45 static PyObject *
46 _queue_SimpleQueue_put_impl(simplequeueobject *self, PyObject *item,
47                             int block, PyObject *timeout);
48 
49 static PyObject *
_queue_SimpleQueue_put(simplequeueobject * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)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];
79 skip_optional_pos:
80     return_value = _queue_SimpleQueue_put_impl(self, item, block, timeout);
81 
82 exit:
83     return return_value;
84 }
85 
86 PyDoc_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 
98 static PyObject *
99 _queue_SimpleQueue_put_nowait_impl(simplequeueobject *self, PyObject *item);
100 
101 static PyObject *
_queue_SimpleQueue_put_nowait(simplequeueobject * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)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 
117 exit:
118     return return_value;
119 }
120 
121 PyDoc_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_FASTCALL|METH_KEYWORDS, _queue_SimpleQueue_get__doc__},
137 
138 static PyObject *
139 _queue_SimpleQueue_get_impl(simplequeueobject *self, int block,
140                             PyObject *timeout);
141 
142 static PyObject *
_queue_SimpleQueue_get(simplequeueobject * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)143 _queue_SimpleQueue_get(simplequeueobject *self, 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];
170 skip_optional_pos:
171     return_value = _queue_SimpleQueue_get_impl(self, block, timeout);
172 
173 exit:
174     return return_value;
175 }
176 
177 PyDoc_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)_queue_SimpleQueue_get_nowait, METH_NOARGS, _queue_SimpleQueue_get_nowait__doc__},
188 
189 static PyObject *
190 _queue_SimpleQueue_get_nowait_impl(simplequeueobject *self);
191 
192 static PyObject *
_queue_SimpleQueue_get_nowait(simplequeueobject * self,PyObject * Py_UNUSED (ignored))193 _queue_SimpleQueue_get_nowait(simplequeueobject *self, PyObject *Py_UNUSED(ignored))
194 {
195     return _queue_SimpleQueue_get_nowait_impl(self);
196 }
197 
198 PyDoc_STRVAR(_queue_SimpleQueue_empty__doc__,
199 "empty($self, /)\n"
200 "--\n"
201 "\n"
202 "Return True if the queue is empty, False otherwise (not reliable!).");
203 
204 #define _QUEUE_SIMPLEQUEUE_EMPTY_METHODDEF    \
205     {"empty", (PyCFunction)_queue_SimpleQueue_empty, METH_NOARGS, _queue_SimpleQueue_empty__doc__},
206 
207 static int
208 _queue_SimpleQueue_empty_impl(simplequeueobject *self);
209 
210 static PyObject *
_queue_SimpleQueue_empty(simplequeueobject * self,PyObject * Py_UNUSED (ignored))211 _queue_SimpleQueue_empty(simplequeueobject *self, PyObject *Py_UNUSED(ignored))
212 {
213     PyObject *return_value = NULL;
214     int _return_value;
215 
216     _return_value = _queue_SimpleQueue_empty_impl(self);
217     if ((_return_value == -1) && PyErr_Occurred()) {
218         goto exit;
219     }
220     return_value = PyBool_FromLong((long)_return_value);
221 
222 exit:
223     return return_value;
224 }
225 
226 PyDoc_STRVAR(_queue_SimpleQueue_qsize__doc__,
227 "qsize($self, /)\n"
228 "--\n"
229 "\n"
230 "Return the approximate size of the queue (not reliable!).");
231 
232 #define _QUEUE_SIMPLEQUEUE_QSIZE_METHODDEF    \
233     {"qsize", (PyCFunction)_queue_SimpleQueue_qsize, METH_NOARGS, _queue_SimpleQueue_qsize__doc__},
234 
235 static Py_ssize_t
236 _queue_SimpleQueue_qsize_impl(simplequeueobject *self);
237 
238 static PyObject *
_queue_SimpleQueue_qsize(simplequeueobject * self,PyObject * Py_UNUSED (ignored))239 _queue_SimpleQueue_qsize(simplequeueobject *self, PyObject *Py_UNUSED(ignored))
240 {
241     PyObject *return_value = NULL;
242     Py_ssize_t _return_value;
243 
244     _return_value = _queue_SimpleQueue_qsize_impl(self);
245     if ((_return_value == -1) && PyErr_Occurred()) {
246         goto exit;
247     }
248     return_value = PyLong_FromSsize_t(_return_value);
249 
250 exit:
251     return return_value;
252 }
253 /*[clinic end generated code: output=b4717e2974cbc909 input=a9049054013a1b77]*/
254