2018-01-15 19:27:16 -04:00
|
|
|
/*[clinic input]
|
|
|
|
preserve
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
2022-08-11 18:25:49 -03:00
|
|
|
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
|
|
|
# include "pycore_gc.h" // PyGC_Head
|
|
|
|
# include "pycore_runtime.h" // _Py_ID()
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2018-01-15 19:27:16 -04:00
|
|
|
PyDoc_STRVAR(simplequeue_new__doc__,
|
|
|
|
"SimpleQueue()\n"
|
|
|
|
"--\n"
|
|
|
|
"\n"
|
|
|
|
"Simple, unbounded, reentrant FIFO queue.");
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
simplequeue_new_impl(PyTypeObject *type);
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
simplequeue_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
|
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
|
|
|
|
2021-09-12 07:27:50 -03:00
|
|
|
if ((type == simplequeue_get_state_by_type(type)->SimpleQueueType ||
|
|
|
|
type->tp_init == simplequeue_get_state_by_type(type)->SimpleQueueType->tp_init) &&
|
2018-01-15 19:27:16 -04:00
|
|
|
!_PyArg_NoPositional("SimpleQueue", args)) {
|
|
|
|
goto exit;
|
|
|
|
}
|
2021-09-12 07:27:50 -03:00
|
|
|
if ((type == simplequeue_get_state_by_type(type)->SimpleQueueType ||
|
|
|
|
type->tp_init == simplequeue_get_state_by_type(type)->SimpleQueueType->tp_init) &&
|
2018-01-15 19:27:16 -04:00
|
|
|
!_PyArg_NoKeywords("SimpleQueue", kwargs)) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
return_value = simplequeue_new_impl(type);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
PyDoc_STRVAR(_queue_SimpleQueue_put__doc__,
|
|
|
|
"put($self, /, item, block=True, timeout=None)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n"
|
|
|
|
"Put the item on the queue.\n"
|
|
|
|
"\n"
|
|
|
|
"The optional \'block\' and \'timeout\' arguments are ignored, as this method\n"
|
|
|
|
"never blocks. They are provided for compatibility with the Queue class.");
|
|
|
|
|
|
|
|
#define _QUEUE_SIMPLEQUEUE_PUT_METHODDEF \
|
2022-05-03 15:25:41 -03:00
|
|
|
{"put", _PyCFunction_CAST(_queue_SimpleQueue_put), METH_FASTCALL|METH_KEYWORDS, _queue_SimpleQueue_put__doc__},
|
2018-01-15 19:27:16 -04:00
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_queue_SimpleQueue_put_impl(simplequeueobject *self, PyObject *item,
|
|
|
|
int block, PyObject *timeout);
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_queue_SimpleQueue_put(simplequeueobject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
2022-08-13 07:09:40 -03:00
|
|
|
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
2022-08-11 18:25:49 -03:00
|
|
|
|
2022-08-13 07:09:40 -03:00
|
|
|
#define NUM_KEYWORDS 3
|
2022-08-11 18:25:49 -03:00
|
|
|
static struct {
|
|
|
|
PyGC_Head _this_is_not_used;
|
|
|
|
PyObject_VAR_HEAD
|
|
|
|
PyObject *ob_item[NUM_KEYWORDS];
|
|
|
|
} _kwtuple = {
|
|
|
|
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
|
|
|
|
.ob_item = { &_Py_ID(item), &_Py_ID(block), &_Py_ID(timeout), },
|
|
|
|
};
|
|
|
|
#undef NUM_KEYWORDS
|
2022-08-13 07:09:40 -03:00
|
|
|
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
|
|
|
|
|
|
|
|
#else // !Py_BUILD_CORE
|
|
|
|
# define KWTUPLE NULL
|
|
|
|
#endif // !Py_BUILD_CORE
|
2022-08-11 18:25:49 -03:00
|
|
|
|
2018-01-15 19:27:16 -04:00
|
|
|
static const char * const _keywords[] = {"item", "block", "timeout", NULL};
|
2022-08-11 18:25:49 -03:00
|
|
|
static _PyArg_Parser _parser = {
|
|
|
|
.keywords = _keywords,
|
|
|
|
.fname = "put",
|
|
|
|
.kwtuple = KWTUPLE,
|
|
|
|
};
|
|
|
|
#undef KWTUPLE
|
2019-03-14 05:32:22 -03:00
|
|
|
PyObject *argsbuf[3];
|
|
|
|
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
|
2018-01-15 19:27:16 -04:00
|
|
|
PyObject *item;
|
|
|
|
int block = 1;
|
|
|
|
PyObject *timeout = Py_None;
|
|
|
|
|
2019-03-14 05:32:22 -03:00
|
|
|
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
|
|
|
|
if (!args) {
|
2018-01-15 19:27:16 -04:00
|
|
|
goto exit;
|
|
|
|
}
|
2019-03-14 05:32:22 -03:00
|
|
|
item = args[0];
|
|
|
|
if (!noptargs) {
|
|
|
|
goto skip_optional_pos;
|
|
|
|
}
|
|
|
|
if (args[1]) {
|
|
|
|
block = PyObject_IsTrue(args[1]);
|
|
|
|
if (block < 0) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
if (!--noptargs) {
|
|
|
|
goto skip_optional_pos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
timeout = args[2];
|
|
|
|
skip_optional_pos:
|
2018-01-15 19:27:16 -04:00
|
|
|
return_value = _queue_SimpleQueue_put_impl(self, item, block, timeout);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
PyDoc_STRVAR(_queue_SimpleQueue_put_nowait__doc__,
|
|
|
|
"put_nowait($self, /, item)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n"
|
|
|
|
"Put an item into the queue without blocking.\n"
|
|
|
|
"\n"
|
|
|
|
"This is exactly equivalent to `put(item)` and is only provided\n"
|
|
|
|
"for compatibility with the Queue class.");
|
|
|
|
|
|
|
|
#define _QUEUE_SIMPLEQUEUE_PUT_NOWAIT_METHODDEF \
|
2022-05-03 15:25:41 -03:00
|
|
|
{"put_nowait", _PyCFunction_CAST(_queue_SimpleQueue_put_nowait), METH_FASTCALL|METH_KEYWORDS, _queue_SimpleQueue_put_nowait__doc__},
|
2018-01-15 19:27:16 -04:00
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_queue_SimpleQueue_put_nowait_impl(simplequeueobject *self, PyObject *item);
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_queue_SimpleQueue_put_nowait(simplequeueobject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
2022-08-13 07:09:40 -03:00
|
|
|
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
2022-08-11 18:25:49 -03:00
|
|
|
|
2022-08-13 07:09:40 -03:00
|
|
|
#define NUM_KEYWORDS 1
|
2022-08-11 18:25:49 -03:00
|
|
|
static struct {
|
|
|
|
PyGC_Head _this_is_not_used;
|
|
|
|
PyObject_VAR_HEAD
|
|
|
|
PyObject *ob_item[NUM_KEYWORDS];
|
|
|
|
} _kwtuple = {
|
|
|
|
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
|
|
|
|
.ob_item = { &_Py_ID(item), },
|
|
|
|
};
|
|
|
|
#undef NUM_KEYWORDS
|
2022-08-13 07:09:40 -03:00
|
|
|
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
|
|
|
|
|
|
|
|
#else // !Py_BUILD_CORE
|
|
|
|
# define KWTUPLE NULL
|
|
|
|
#endif // !Py_BUILD_CORE
|
2022-08-11 18:25:49 -03:00
|
|
|
|
2018-01-15 19:27:16 -04:00
|
|
|
static const char * const _keywords[] = {"item", NULL};
|
2022-08-11 18:25:49 -03:00
|
|
|
static _PyArg_Parser _parser = {
|
|
|
|
.keywords = _keywords,
|
|
|
|
.fname = "put_nowait",
|
|
|
|
.kwtuple = KWTUPLE,
|
|
|
|
};
|
|
|
|
#undef KWTUPLE
|
2019-03-14 05:32:22 -03:00
|
|
|
PyObject *argsbuf[1];
|
2018-01-15 19:27:16 -04:00
|
|
|
PyObject *item;
|
|
|
|
|
2019-03-14 05:32:22 -03:00
|
|
|
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
|
|
|
|
if (!args) {
|
2018-01-15 19:27:16 -04:00
|
|
|
goto exit;
|
|
|
|
}
|
2019-03-14 05:32:22 -03:00
|
|
|
item = args[0];
|
2018-01-15 19:27:16 -04:00
|
|
|
return_value = _queue_SimpleQueue_put_nowait_impl(self, item);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
PyDoc_STRVAR(_queue_SimpleQueue_get__doc__,
|
|
|
|
"get($self, /, block=True, timeout=None)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n"
|
|
|
|
"Remove and return an item from the queue.\n"
|
|
|
|
"\n"
|
|
|
|
"If optional args \'block\' is true and \'timeout\' is None (the default),\n"
|
|
|
|
"block if necessary until an item is available. If \'timeout\' is\n"
|
|
|
|
"a non-negative number, it blocks at most \'timeout\' seconds and raises\n"
|
|
|
|
"the Empty exception if no item was available within that time.\n"
|
|
|
|
"Otherwise (\'block\' is false), return an item if one is immediately\n"
|
|
|
|
"available, else raise the Empty exception (\'timeout\' is ignored\n"
|
|
|
|
"in that case).");
|
|
|
|
|
|
|
|
#define _QUEUE_SIMPLEQUEUE_GET_METHODDEF \
|
2022-05-03 15:25:41 -03:00
|
|
|
{"get", _PyCFunction_CAST(_queue_SimpleQueue_get), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _queue_SimpleQueue_get__doc__},
|
2018-01-15 19:27:16 -04:00
|
|
|
|
|
|
|
static PyObject *
|
2020-11-07 15:18:37 -04:00
|
|
|
_queue_SimpleQueue_get_impl(simplequeueobject *self, PyTypeObject *cls,
|
2021-10-01 08:29:25 -03:00
|
|
|
int block, PyObject *timeout_obj);
|
2018-01-15 19:27:16 -04:00
|
|
|
|
|
|
|
static PyObject *
|
2020-11-07 15:18:37 -04:00
|
|
|
_queue_SimpleQueue_get(simplequeueobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
2018-01-15 19:27:16 -04:00
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
2022-08-13 07:09:40 -03:00
|
|
|
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
2022-08-11 18:25:49 -03:00
|
|
|
|
2022-08-13 07:09:40 -03:00
|
|
|
#define NUM_KEYWORDS 2
|
2022-08-11 18:25:49 -03:00
|
|
|
static struct {
|
|
|
|
PyGC_Head _this_is_not_used;
|
|
|
|
PyObject_VAR_HEAD
|
|
|
|
PyObject *ob_item[NUM_KEYWORDS];
|
|
|
|
} _kwtuple = {
|
|
|
|
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
|
|
|
|
.ob_item = { &_Py_ID(block), &_Py_ID(timeout), },
|
|
|
|
};
|
|
|
|
#undef NUM_KEYWORDS
|
2022-08-13 07:09:40 -03:00
|
|
|
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
|
|
|
|
|
|
|
|
#else // !Py_BUILD_CORE
|
|
|
|
# define KWTUPLE NULL
|
|
|
|
#endif // !Py_BUILD_CORE
|
2022-08-11 18:25:49 -03:00
|
|
|
|
2018-01-15 19:27:16 -04:00
|
|
|
static const char * const _keywords[] = {"block", "timeout", NULL};
|
2022-08-11 18:25:49 -03:00
|
|
|
static _PyArg_Parser _parser = {
|
|
|
|
.keywords = _keywords,
|
|
|
|
.fname = "get",
|
|
|
|
.kwtuple = KWTUPLE,
|
|
|
|
};
|
|
|
|
#undef KWTUPLE
|
2022-04-30 07:15:02 -03:00
|
|
|
PyObject *argsbuf[2];
|
|
|
|
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
|
2018-01-15 19:27:16 -04:00
|
|
|
int block = 1;
|
2021-10-01 08:29:25 -03:00
|
|
|
PyObject *timeout_obj = Py_None;
|
2018-01-15 19:27:16 -04:00
|
|
|
|
2022-04-30 07:15:02 -03:00
|
|
|
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf);
|
|
|
|
if (!args) {
|
2018-01-15 19:27:16 -04:00
|
|
|
goto exit;
|
|
|
|
}
|
2022-04-30 07:15:02 -03:00
|
|
|
if (!noptargs) {
|
|
|
|
goto skip_optional_pos;
|
|
|
|
}
|
|
|
|
if (args[0]) {
|
|
|
|
block = PyObject_IsTrue(args[0]);
|
|
|
|
if (block < 0) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
if (!--noptargs) {
|
|
|
|
goto skip_optional_pos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
timeout_obj = args[1];
|
|
|
|
skip_optional_pos:
|
2021-10-01 08:29:25 -03:00
|
|
|
return_value = _queue_SimpleQueue_get_impl(self, cls, block, timeout_obj);
|
2018-01-15 19:27:16 -04:00
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
PyDoc_STRVAR(_queue_SimpleQueue_get_nowait__doc__,
|
|
|
|
"get_nowait($self, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n"
|
|
|
|
"Remove and return an item from the queue without blocking.\n"
|
|
|
|
"\n"
|
|
|
|
"Only get an item if one is immediately available. Otherwise\n"
|
|
|
|
"raise the Empty exception.");
|
|
|
|
|
|
|
|
#define _QUEUE_SIMPLEQUEUE_GET_NOWAIT_METHODDEF \
|
2022-05-03 15:25:41 -03:00
|
|
|
{"get_nowait", _PyCFunction_CAST(_queue_SimpleQueue_get_nowait), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _queue_SimpleQueue_get_nowait__doc__},
|
2018-01-15 19:27:16 -04:00
|
|
|
|
|
|
|
static PyObject *
|
2020-11-07 15:18:37 -04:00
|
|
|
_queue_SimpleQueue_get_nowait_impl(simplequeueobject *self,
|
|
|
|
PyTypeObject *cls);
|
2018-01-15 19:27:16 -04:00
|
|
|
|
|
|
|
static PyObject *
|
2020-11-07 15:18:37 -04:00
|
|
|
_queue_SimpleQueue_get_nowait(simplequeueobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
2018-01-15 19:27:16 -04:00
|
|
|
{
|
2022-04-30 07:15:02 -03:00
|
|
|
if (nargs) {
|
|
|
|
PyErr_SetString(PyExc_TypeError, "get_nowait() takes no arguments");
|
|
|
|
return NULL;
|
2020-11-07 15:18:37 -04:00
|
|
|
}
|
2022-04-30 07:15:02 -03:00
|
|
|
return _queue_SimpleQueue_get_nowait_impl(self, cls);
|
2018-01-15 19:27:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
PyDoc_STRVAR(_queue_SimpleQueue_empty__doc__,
|
|
|
|
"empty($self, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n"
|
|
|
|
"Return True if the queue is empty, False otherwise (not reliable!).");
|
|
|
|
|
|
|
|
#define _QUEUE_SIMPLEQUEUE_EMPTY_METHODDEF \
|
|
|
|
{"empty", (PyCFunction)_queue_SimpleQueue_empty, METH_NOARGS, _queue_SimpleQueue_empty__doc__},
|
|
|
|
|
|
|
|
static int
|
|
|
|
_queue_SimpleQueue_empty_impl(simplequeueobject *self);
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_queue_SimpleQueue_empty(simplequeueobject *self, PyObject *Py_UNUSED(ignored))
|
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
|
|
|
int _return_value;
|
|
|
|
|
|
|
|
_return_value = _queue_SimpleQueue_empty_impl(self);
|
|
|
|
if ((_return_value == -1) && PyErr_Occurred()) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
return_value = PyBool_FromLong((long)_return_value);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
PyDoc_STRVAR(_queue_SimpleQueue_qsize__doc__,
|
|
|
|
"qsize($self, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n"
|
|
|
|
"Return the approximate size of the queue (not reliable!).");
|
|
|
|
|
|
|
|
#define _QUEUE_SIMPLEQUEUE_QSIZE_METHODDEF \
|
|
|
|
{"qsize", (PyCFunction)_queue_SimpleQueue_qsize, METH_NOARGS, _queue_SimpleQueue_qsize__doc__},
|
|
|
|
|
|
|
|
static Py_ssize_t
|
|
|
|
_queue_SimpleQueue_qsize_impl(simplequeueobject *self);
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_queue_SimpleQueue_qsize(simplequeueobject *self, PyObject *Py_UNUSED(ignored))
|
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
|
|
|
Py_ssize_t _return_value;
|
|
|
|
|
|
|
|
_return_value = _queue_SimpleQueue_qsize_impl(self);
|
|
|
|
if ((_return_value == -1) && PyErr_Occurred()) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
return_value = PyLong_FromSsize_t(_return_value);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
2022-08-13 07:09:40 -03:00
|
|
|
/*[clinic end generated code: output=628e992d38f50aac input=a9049054013a1b77]*/
|