# HG changeset patch # User Henry S Thompson # Date 1737128636 0 # Node ID eb91fd5d49b302e4108106e22102c5e0b2b5405c # Parent eb4be545fcc84ae3f12046cd3a3eaa71e9a47b97 minimally changed to get Cython Queue example working, Cython version diff -r eb4be545fcc8 -r eb91fd5d49b3 cy_works/cqu.pxd --- /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) diff -r eb4be545fcc8 -r eb91fd5d49b3 cy_works/qu.pyx --- /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() diff -r eb4be545fcc8 -r eb91fd5d49b3 cy_works/setup.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cy_works/setup.py Fri Jan 17 15:43:56 2025 +0000 @@ -0,0 +1,6 @@ +from setuptools import Extension, setup +from Cython.Build import cythonize + +setup( + ext_modules = cythonize([Extension("qu", ["qu.pyx"])]) +)