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
6 years ago
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:
...
@@ -38,11 +38,9 @@ cdef class Queue:
self
.
append
(
value
)
self
.
append
(
value
)
cdef
extend_ints
(
self
,
int
*
values
,
size_t
count
):
cdef
extend_ints
(
self
,
int
*
values
,
size_t
count
):
cdef
size_t
i
cdef
int
value
for
i
in
range
(
count
):
for
value
in
values
[:
count
]:
# It is possible to slice pointers in Cython.
if
not
cqueue
.
queue_push_tail
(
self
.
append
(
value
)
self
.
_c_queue
,
<
void
*>
values
[
i
]):
raise
MemoryError
()
cpdef
int
peek
(
self
)
except
?
-
1
:
cpdef
int
peek
(
self
)
except
?
-
1
:
cdef
int
value
=
<
Py_ssize_t
>
cqueue
.
queue_peek_head
(
self
.
_c_queue
)
cdef
int
value
=
<
Py_ssize_t
>
cqueue
.
queue_peek_head
(
self
.
_c_queue
)
...
...
This diff is collapsed.
Click to expand it.
docs/src/tutorial/clibraries.rst
View file @
d5e107a9
...
@@ -342,11 +342,9 @@ Adding an ``extend()`` method should now be straight forward::
...
@@ -342,11 +342,9 @@ Adding an ``extend()`` method should now be straight forward::
cdef extend(self, int* values, size_t count):
cdef extend(self, int* values, size_t count):
"""Append all ints to the queue.
"""Append all ints to the queue.
"""
"""
cdef size_t i
cdef int value
for i in range(count):
for value in values[:count]: # It is possible to slice pointers in Cython.
if not cqueue.queue_push_tail(
self.append(value)
self._c_queue, <void*>values[i]):
raise MemoryError()
This becomes handy when reading values from a C array, for example.
This becomes handy when reading values from a C array, for example.
...
...
This diff is collapsed.
Click to expand it.
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