annotate cy_works/qu.pyx @ 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
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
68
eb91fd5d49b3 minimally changed to get Cython Queue example working, Cython version
Henry S Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
1 # distutils: sources = c-algorithms/src/queue.c
eb91fd5d49b3 minimally changed to get Cython Queue example working, Cython version
Henry S Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
2 # distutils: include_dirs = c-algorithms/src/
eb91fd5d49b3 minimally changed to get Cython Queue example working, Cython version
Henry S Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
3
eb91fd5d49b3 minimally changed to get Cython Queue example working, Cython version
Henry S Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
4 cimport cqu
eb91fd5d49b3 minimally changed to get Cython Queue example working, Cython version
Henry S Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
5
eb91fd5d49b3 minimally changed to get Cython Queue example working, Cython version
Henry S Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
6 cdef class Queue:
eb91fd5d49b3 minimally changed to get Cython Queue example working, Cython version
Henry S Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
7 cdef cqu.Queue* _c_queue
eb91fd5d49b3 minimally changed to get Cython Queue example working, Cython version
Henry S Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
8
eb91fd5d49b3 minimally changed to get Cython Queue example working, Cython version
Henry S Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
9 def __cinit__(self):
eb91fd5d49b3 minimally changed to get Cython Queue example working, Cython version
Henry S Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
10 self._c_queue = cqu.queue_new()
eb91fd5d49b3 minimally changed to get Cython Queue example working, Cython version
Henry S Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
11 if self._c_queue == NULL:
eb91fd5d49b3 minimally changed to get Cython Queue example working, Cython version
Henry S Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
12 raise MemoryError()
eb91fd5d49b3 minimally changed to get Cython Queue example working, Cython version
Henry S Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
13
eb91fd5d49b3 minimally changed to get Cython Queue example working, Cython version
Henry S Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
14 def __dealloc__(self):
eb91fd5d49b3 minimally changed to get Cython Queue example working, Cython version
Henry S Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
15 if self._c_queue != NULL:
eb91fd5d49b3 minimally changed to get Cython Queue example working, Cython version
Henry S Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
16 cqu.queue_free(self._c_queue)
eb91fd5d49b3 minimally changed to get Cython Queue example working, Cython version
Henry S Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
17
eb91fd5d49b3 minimally changed to get Cython Queue example working, Cython version
Henry S Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
18 cdef testMe():
eb91fd5d49b3 minimally changed to get Cython Queue example working, Cython version
Henry S Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
19 print('testing...')
eb91fd5d49b3 minimally changed to get Cython Queue example working, Cython version
Henry S Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
20 q = Queue()
eb91fd5d49b3 minimally changed to get Cython Queue example working, Cython version
Henry S Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
21 print(cqu.queue_is_empty(q._c_queue))
eb91fd5d49b3 minimally changed to get Cython Queue example working, Cython version
Henry S Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
22 print('tested')
eb91fd5d49b3 minimally changed to get Cython Queue example working, Cython version
Henry S Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
23
eb91fd5d49b3 minimally changed to get Cython Queue example working, Cython version
Henry S Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
24 testMe()