Mercurial > hg > python
changeset 68:eb91fd5d49b3
minimally changed to get Cython Queue example working, Cython version
author | Henry S Thompson <ht@inf.ed.ac.uk> |
---|---|
date | Fri, 17 Jan 2025 15:43:56 +0000 |
parents | eb4be545fcc8 |
children | 157f012ffab7 |
files | cy_works/cqu.pxd cy_works/qu.pyx cy_works/setup.py |
diffstat | 3 files changed, 47 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cy_works/cqu.pxd Fri Jan 17 15:43:56 2025 +0000 @@ -0,0 +1,17 @@ +cdef extern from "c-algorithms/src/queue.h": + ctypedef struct Queue: + pass + ctypedef void* QueueValue + + Queue* queue_new() + void queue_free(Queue* queue) + + int queue_push_head(Queue* queue, QueueValue data) + QueueValue queue_pop_head(Queue* queue) + QueueValue queue_peek_head(Queue* queue) + + int queue_push_tail(Queue* queue, QueueValue data) + QueueValue queue_pop_tail(Queue* queue) + QueueValue queue_peek_tail(Queue* queue) + + bint queue_is_empty(Queue* queue)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cy_works/qu.pyx Fri Jan 17 15:43:56 2025 +0000 @@ -0,0 +1,24 @@ +# distutils: sources = c-algorithms/src/queue.c +# distutils: include_dirs = c-algorithms/src/ + +cimport cqu + +cdef class Queue: + cdef cqu.Queue* _c_queue + + def __cinit__(self): + self._c_queue = cqu.queue_new() + if self._c_queue == NULL: + raise MemoryError() + + def __dealloc__(self): + if self._c_queue != NULL: + cqu.queue_free(self._c_queue) + +cdef testMe(): + print('testing...') + q = Queue() + print(cqu.queue_is_empty(q._c_queue)) + print('tested') + +testMe()