#ifndef Py_BUILD_CORE_BUILTIN #define Py_BUILD_CORE_MODULE … #endif #include "Python.h" #include "pycore_ceval.h" // Py_MakePendingCalls() #include "pycore_moduleobject.h" // _PyModule_GetState() #include "pycore_parking_lot.h" #include "pycore_time.h" // _PyTime_FromSecondsObject() #include <stdbool.h> #include <stddef.h> // offsetof() simplequeue_state; static simplequeue_state * simplequeue_get_state(PyObject *module) { … } static struct PyModuleDef queuemodule; #define simplequeue_get_state_by_type(type) … static const Py_ssize_t INITIAL_RING_BUF_CAPACITY = …; RingBuf; static int RingBuf_Init(RingBuf *buf) { … } static PyObject * RingBuf_At(RingBuf *buf, Py_ssize_t idx) { … } static void RingBuf_Fini(RingBuf *buf) { … } // Resize the underlying items array of buf to the new capacity and arrange // the items contiguously in the new items array. // // Returns -1 on allocation failure or 0 on success. static int resize_ringbuf(RingBuf *buf, Py_ssize_t capacity) { … } // Returns a strong reference from the head of the buffer. static PyObject * RingBuf_Get(RingBuf *buf) { … } // Returns 0 on success or -1 if the buffer failed to grow. // // Steals a reference to item. static int RingBuf_Put(RingBuf *buf, PyObject *item) { … } static Py_ssize_t RingBuf_Len(RingBuf *buf) { … } static bool RingBuf_IsEmpty(RingBuf *buf) { … } simplequeueobject; /*[clinic input] module _queue class _queue.SimpleQueue "simplequeueobject *" "simplequeue_get_state_by_type(type)->SimpleQueueType" [clinic start generated code]*/ /*[clinic end generated code: output=da39a3ee5e6b4b0d input=0a4023fe4d198c8d]*/ static int simplequeue_clear(simplequeueobject *self) { … } static void simplequeue_dealloc(simplequeueobject *self) { … } static int simplequeue_traverse(simplequeueobject *self, visitproc visit, void *arg) { … } /*[clinic input] @classmethod _queue.SimpleQueue.__new__ as simplequeue_new Simple, unbounded, reentrant FIFO queue. [clinic start generated code]*/ static PyObject * simplequeue_new_impl(PyTypeObject *type) /*[clinic end generated code: output=ba97740608ba31cd input=a0674a1643e3e2fb]*/ { … } HandoffData; static void maybe_handoff_item(HandoffData *data, PyObject **item, int has_more_waiters) { … } /*[clinic input] @critical_section _queue.SimpleQueue.put item: object block: bool = True timeout: object = None Put the item on the queue. The optional 'block' and 'timeout' arguments are ignored, as this method never blocks. They are provided for compatibility with the Queue class. [clinic start generated code]*/ static PyObject * _queue_SimpleQueue_put_impl(simplequeueobject *self, PyObject *item, int block, PyObject *timeout) /*[clinic end generated code: output=4333136e88f90d8b input=a16dbb33363c0fa8]*/ { … } /*[clinic input] @critical_section _queue.SimpleQueue.put_nowait item: object Put an item into the queue without blocking. This is exactly equivalent to `put(item)` and is only provided for compatibility with the Queue class. [clinic start generated code]*/ static PyObject * _queue_SimpleQueue_put_nowait_impl(simplequeueobject *self, PyObject *item) /*[clinic end generated code: output=0990536715efb1f1 input=ce949cc2cd8a4119]*/ { … } static PyObject * empty_error(PyTypeObject *cls) { … } /*[clinic input] @critical_section _queue.SimpleQueue.get cls: defining_class / block: bool = True timeout as timeout_obj: object = None Remove and return an item from the queue. If optional args 'block' is true and 'timeout' is None (the default), block if necessary until an item is available. If 'timeout' is a non-negative number, it blocks at most 'timeout' seconds and raises the Empty exception if no item was available within that time. Otherwise ('block' is false), return an item if one is immediately available, else raise the Empty exception ('timeout' is ignored in that case). [clinic start generated code]*/ static PyObject * _queue_SimpleQueue_get_impl(simplequeueobject *self, PyTypeObject *cls, int block, PyObject *timeout_obj) /*[clinic end generated code: output=5c2cca914cd1e55b input=f7836c65e5839c51]*/ { … } /*[clinic input] @critical_section _queue.SimpleQueue.get_nowait cls: defining_class / Remove and return an item from the queue without blocking. Only get an item if one is immediately available. Otherwise raise the Empty exception. [clinic start generated code]*/ static PyObject * _queue_SimpleQueue_get_nowait_impl(simplequeueobject *self, PyTypeObject *cls) /*[clinic end generated code: output=620c58e2750f8b8a input=d48be63633fefae9]*/ { … } /*[clinic input] @critical_section _queue.SimpleQueue.empty -> bool Return True if the queue is empty, False otherwise (not reliable!). [clinic start generated code]*/ static int _queue_SimpleQueue_empty_impl(simplequeueobject *self) /*[clinic end generated code: output=1a02a1b87c0ef838 input=96cb22df5a67d831]*/ { … } /*[clinic input] @critical_section _queue.SimpleQueue.qsize -> Py_ssize_t Return the approximate size of the queue (not reliable!). [clinic start generated code]*/ static Py_ssize_t _queue_SimpleQueue_qsize_impl(simplequeueobject *self) /*[clinic end generated code: output=f9dcd9d0a90e121e input=e218623cb8c16a79]*/ { … } static int queue_traverse(PyObject *m, visitproc visit, void *arg) { … } static int queue_clear(PyObject *m) { … } static void queue_free(void *m) { … } #include "clinic/_queuemodule.c.h" static PyMethodDef simplequeue_methods[] = …; static struct PyMemberDef simplequeue_members[] = …; static PyType_Slot simplequeue_slots[] = …; static PyType_Spec simplequeue_spec = …; /* Initialization function */ PyDoc_STRVAR(queue_module_doc, "C implementation of the Python queue module.\n\ This module is an implementation detail, please do not use it directly."); static int queuemodule_exec(PyObject *module) { … } static PyModuleDef_Slot queuemodule_slots[] = …; static struct PyModuleDef queuemodule = …; PyMODINIT_FUNC PyInit__queue(void) { … }