Antoine Pitrou | 94e1696 | 2018-01-16 00:27:16 +0100 | [diff] [blame] | 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 * |
| 15 | simplequeue_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
| 16 | { |
| 17 | PyObject *return_value = NULL; |
| 18 | |
Erlend Egeberg Aasland | 01c6aa4 | 2020-11-07 20:18:37 +0100 | [diff] [blame] | 19 | if ((type == simplequeue_get_state_by_type(type)->SimpleQueueType) && |
Antoine Pitrou | 94e1696 | 2018-01-16 00:27:16 +0100 | [diff] [blame] | 20 | !_PyArg_NoPositional("SimpleQueue", args)) { |
| 21 | goto exit; |
| 22 | } |
Erlend Egeberg Aasland | 01c6aa4 | 2020-11-07 20:18:37 +0100 | [diff] [blame] | 23 | if ((type == simplequeue_get_state_by_type(type)->SimpleQueueType) && |
Antoine Pitrou | 94e1696 | 2018-01-16 00:27:16 +0100 | [diff] [blame] | 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 \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 43 | {"put", (PyCFunction)(void(*)(void))_queue_SimpleQueue_put, METH_FASTCALL|METH_KEYWORDS, _queue_SimpleQueue_put__doc__}, |
Antoine Pitrou | 94e1696 | 2018-01-16 00:27:16 +0100 | [diff] [blame] | 44 | |
| 45 | static PyObject * |
| 46 | _queue_SimpleQueue_put_impl(simplequeueobject *self, PyObject *item, |
| 47 | int block, PyObject *timeout); |
| 48 | |
| 49 | static 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 Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 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; |
Antoine Pitrou | 94e1696 | 2018-01-16 00:27:16 +0100 | [diff] [blame] | 57 | PyObject *item; |
| 58 | int block = 1; |
| 59 | PyObject *timeout = Py_None; |
| 60 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 61 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf); |
| 62 | if (!args) { |
Antoine Pitrou | 94e1696 | 2018-01-16 00:27:16 +0100 | [diff] [blame] | 63 | goto exit; |
| 64 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 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: |
Antoine Pitrou | 94e1696 | 2018-01-16 00:27:16 +0100 | [diff] [blame] | 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 \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 96 | {"put_nowait", (PyCFunction)(void(*)(void))_queue_SimpleQueue_put_nowait, METH_FASTCALL|METH_KEYWORDS, _queue_SimpleQueue_put_nowait__doc__}, |
Antoine Pitrou | 94e1696 | 2018-01-16 00:27:16 +0100 | [diff] [blame] | 97 | |
| 98 | static PyObject * |
| 99 | _queue_SimpleQueue_put_nowait_impl(simplequeueobject *self, PyObject *item); |
| 100 | |
| 101 | static 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 Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 106 | static _PyArg_Parser _parser = {NULL, _keywords, "put_nowait", 0}; |
| 107 | PyObject *argsbuf[1]; |
Antoine Pitrou | 94e1696 | 2018-01-16 00:27:16 +0100 | [diff] [blame] | 108 | PyObject *item; |
| 109 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 110 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 111 | if (!args) { |
Antoine Pitrou | 94e1696 | 2018-01-16 00:27:16 +0100 | [diff] [blame] | 112 | goto exit; |
| 113 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 114 | item = args[0]; |
Antoine Pitrou | 94e1696 | 2018-01-16 00:27:16 +0100 | [diff] [blame] | 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 \ |
Erlend Egeberg Aasland | 01c6aa4 | 2020-11-07 20:18:37 +0100 | [diff] [blame] | 136 | {"get", (PyCFunction)(void(*)(void))_queue_SimpleQueue_get, METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _queue_SimpleQueue_get__doc__}, |
Antoine Pitrou | 94e1696 | 2018-01-16 00:27:16 +0100 | [diff] [blame] | 137 | |
| 138 | static PyObject * |
Erlend Egeberg Aasland | 01c6aa4 | 2020-11-07 20:18:37 +0100 | [diff] [blame] | 139 | _queue_SimpleQueue_get_impl(simplequeueobject *self, PyTypeObject *cls, |
| 140 | int block, PyObject *timeout); |
Antoine Pitrou | 94e1696 | 2018-01-16 00:27:16 +0100 | [diff] [blame] | 141 | |
| 142 | static PyObject * |
Erlend Egeberg Aasland | 01c6aa4 | 2020-11-07 20:18:37 +0100 | [diff] [blame] | 143 | _queue_SimpleQueue_get(simplequeueobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Antoine Pitrou | 94e1696 | 2018-01-16 00:27:16 +0100 | [diff] [blame] | 144 | { |
| 145 | PyObject *return_value = NULL; |
| 146 | static const char * const _keywords[] = {"block", "timeout", NULL}; |
Erlend Egeberg Aasland | 01c6aa4 | 2020-11-07 20:18:37 +0100 | [diff] [blame] | 147 | static _PyArg_Parser _parser = {"|pO:get", _keywords, 0}; |
Antoine Pitrou | 94e1696 | 2018-01-16 00:27:16 +0100 | [diff] [blame] | 148 | int block = 1; |
| 149 | PyObject *timeout = Py_None; |
| 150 | |
Erlend Egeberg Aasland | 01c6aa4 | 2020-11-07 20:18:37 +0100 | [diff] [blame] | 151 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
| 152 | &block, &timeout)) { |
Antoine Pitrou | 94e1696 | 2018-01-16 00:27:16 +0100 | [diff] [blame] | 153 | goto exit; |
| 154 | } |
Erlend Egeberg Aasland | 01c6aa4 | 2020-11-07 20:18:37 +0100 | [diff] [blame] | 155 | return_value = _queue_SimpleQueue_get_impl(self, cls, block, timeout); |
Antoine Pitrou | 94e1696 | 2018-01-16 00:27:16 +0100 | [diff] [blame] | 156 | |
| 157 | exit: |
| 158 | return return_value; |
| 159 | } |
| 160 | |
| 161 | PyDoc_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 Aasland | 01c6aa4 | 2020-11-07 20:18:37 +0100 | [diff] [blame] | 171 | {"get_nowait", (PyCFunction)(void(*)(void))_queue_SimpleQueue_get_nowait, METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _queue_SimpleQueue_get_nowait__doc__}, |
Antoine Pitrou | 94e1696 | 2018-01-16 00:27:16 +0100 | [diff] [blame] | 172 | |
| 173 | static PyObject * |
Erlend Egeberg Aasland | 01c6aa4 | 2020-11-07 20:18:37 +0100 | [diff] [blame] | 174 | _queue_SimpleQueue_get_nowait_impl(simplequeueobject *self, |
| 175 | PyTypeObject *cls); |
Antoine Pitrou | 94e1696 | 2018-01-16 00:27:16 +0100 | [diff] [blame] | 176 | |
| 177 | static PyObject * |
Erlend Egeberg Aasland | 01c6aa4 | 2020-11-07 20:18:37 +0100 | [diff] [blame] | 178 | _queue_SimpleQueue_get_nowait(simplequeueobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Antoine Pitrou | 94e1696 | 2018-01-16 00:27:16 +0100 | [diff] [blame] | 179 | { |
Erlend Egeberg Aasland | 01c6aa4 | 2020-11-07 20:18:37 +0100 | [diff] [blame] | 180 | 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 | |
| 190 | exit: |
| 191 | return return_value; |
Antoine Pitrou | 94e1696 | 2018-01-16 00:27:16 +0100 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | PyDoc_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 | |
| 203 | static int |
| 204 | _queue_SimpleQueue_empty_impl(simplequeueobject *self); |
| 205 | |
| 206 | static 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 | |
| 218 | exit: |
| 219 | return return_value; |
| 220 | } |
| 221 | |
| 222 | PyDoc_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 | |
| 231 | static Py_ssize_t |
| 232 | _queue_SimpleQueue_qsize_impl(simplequeueobject *self); |
| 233 | |
| 234 | static 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 | |
| 246 | exit: |
| 247 | return return_value; |
| 248 | } |
Erlend Egeberg Aasland | 01c6aa4 | 2020-11-07 20:18:37 +0100 | [diff] [blame] | 249 | /*[clinic end generated code: output=ce56b46fac150909 input=a9049054013a1b77]*/ |