Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
d5e107a9
Commit
d5e107a9
authored
Jun 22, 2018
by
gabrieldemarmiesse
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring of the extend function to make it simpler.
parent
b9f7a142
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
10 deletions
+6
-10
docs/examples/tutorial/clibraries/queue3.pyx
docs/examples/tutorial/clibraries/queue3.pyx
+3
-5
docs/src/tutorial/clibraries.rst
docs/src/tutorial/clibraries.rst
+3
-5
No files found.
docs/examples/tutorial/clibraries/queue3.pyx
View file @
d5e107a9
...
...
@@ -38,11 +38,9 @@ cdef class Queue:
self
.
append
(
value
)
cdef
extend_ints
(
self
,
int
*
values
,
size_t
count
):
cdef
size_t
i
for
i
in
range
(
count
):
if
not
cqueue
.
queue_push_tail
(
self
.
_c_queue
,
<
void
*>
values
[
i
]):
raise
MemoryError
()
cdef
int
value
for
value
in
values
[:
count
]:
# It is possible to slice pointers in Cython.
self
.
append
(
value
)
cpdef
int
peek
(
self
)
except
?
-
1
:
cdef
int
value
=
<
Py_ssize_t
>
cqueue
.
queue_peek_head
(
self
.
_c_queue
)
...
...
docs/src/tutorial/clibraries.rst
View file @
d5e107a9
...
...
@@ -342,11 +342,9 @@ Adding an ``extend()`` method should now be straight forward::
cdef extend(self, int* values, size_t count):
"""Append all ints to the queue.
"""
cdef size_t i
for i in range(count):
if not cqueue.queue_push_tail(
self._c_queue, <void*>values[i]):
raise MemoryError()
cdef int value
for value in values[:count]: # It is possible to slice pointers in Cython.
self.append(value)
This becomes handy when reading values from a C array, for example.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment