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
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
cython
Commits
f00fd1de
Commit
f00fd1de
authored
Feb 16, 2013
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix accidental double wrap-around of negative indices in pop() optimisation
parent
d45bf003
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
14 deletions
+9
-14
Cython/Utility/Optimize.c
Cython/Utility/Optimize.c
+6
-5
tests/run/list_pop.pyx
tests/run/list_pop.pyx
+3
-9
No files found.
Cython/Utility/Optimize.c
View file @
f00fd1de
...
...
@@ -90,14 +90,15 @@ static PyObject* __Pyx_PyObject_PopIndex(PyObject* L, Py_ssize_t ix) {
if
(
likely
(
PyList_CheckExact
(
L
)))
{
Py_ssize_t
size
=
PyList_GET_SIZE
(
L
);
if
(
likely
(
size
>
(((
PyListObject
*
)
L
)
->
allocated
>>
1
)))
{
if
(
ix
<
0
)
{
ix
+=
size
;
Py_ssize_t
cix
=
ix
;
if
(
cix
<
0
)
{
cix
+=
size
;
}
if
(
likely
(
0
<=
ix
&&
ix
<
size
))
{
PyObject
*
v
=
PyList_GET_ITEM
(
L
,
ix
);
if
(
likely
(
0
<=
cix
&&
c
ix
<
size
))
{
PyObject
*
v
=
PyList_GET_ITEM
(
L
,
c
ix
);
Py_SIZE
(
L
)
-=
1
;
size
-=
1
;
memmove
(
&
PyList_GET_ITEM
(
L
,
ix
),
&
PyList_GET_ITEM
(
L
,
ix
+
1
),
(
size
-
ix
)
*
sizeof
(
PyObject
*
));
memmove
(
&
PyList_GET_ITEM
(
L
,
cix
),
&
PyList_GET_ITEM
(
L
,
cix
+
1
),
(
size
-
c
ix
)
*
sizeof
(
PyObject
*
));
return
v
;
}
}
...
...
tests/run/list_pop.pyx
View file @
f00fd1de
...
...
@@ -24,7 +24,6 @@ def simple_pop(L):
[]
>>> simple_pop(L)
Traceback (most recent call last):
...
IndexError: pop from empty list
>>> simple_pop(A())
...
...
@@ -50,7 +49,6 @@ def simple_pop_typed(list L):
[]
>>> simple_pop_typed(L)
Traceback (most recent call last):
...
IndexError: pop from empty list
"""
return
L
.
pop
()
...
...
@@ -63,17 +61,18 @@ def index_pop(L, int i):
>>> L = list(range(10))
>>> index_pop(L, 2)
2
>>> index_pop(L, -10)
Traceback (most recent call last):
IndexError: pop index out of range
>>> index_pop(L, -2)
8
>>> L
[0, 1, 3, 4, 5, 6, 7, 9]
>>> index_pop(L, 100)
Traceback (most recent call last):
...
IndexError: pop index out of range
>>> index_pop(L, -100)
Traceback (most recent call last):
...
IndexError: pop index out of range
>>> while L:
...
...
@@ -84,7 +83,6 @@ def index_pop(L, int i):
>>> index_pop(L, 0)
Traceback (most recent call last):
...
IndexError: pop from empty list
>>> index_pop(A(), 3)
...
...
@@ -105,11 +103,9 @@ def index_pop_typed(list L, int i):
[0, 1, 3, 4, 5, 6, 7, 9]
>>> index_pop_typed(L, 100)
Traceback (most recent call last):
...
IndexError: pop index out of range
>>> index_pop_typed(L, -100)
Traceback (most recent call last):
...
IndexError: pop index out of range
>>> while L:
...
...
@@ -120,7 +116,6 @@ def index_pop_typed(list L, int i):
>>> index_pop_typed(L, 0)
Traceback (most recent call last):
...
IndexError: pop from empty list
"""
return
L
.
pop
(
i
)
...
...
@@ -143,7 +138,6 @@ def index_pop_literal(list L):
>>> index_pop_literal(L)
Traceback (most recent call last):
...
IndexError: pop from empty list
"""
return
L
.
pop
(
0
)
...
...
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