Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
57a8689b
Commit
57a8689b
authored
Jan 25, 2011
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue 11004: Fix edge case for deque.count().
parent
51581de1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
4 deletions
+18
-4
Lib/test/test_deque.py
Lib/test/test_deque.py
+9
-0
Misc/NEWS
Misc/NEWS
+2
-0
Modules/_collectionsmodule.c
Modules/_collectionsmodule.c
+7
-4
No files found.
Lib/test/test_deque.py
View file @
57a8689b
...
@@ -137,6 +137,15 @@ class TestBasic(unittest.TestCase):
...
@@ -137,6 +137,15 @@ class TestBasic(unittest.TestCase):
m
.
d
=
d
m
.
d
=
d
self
.
assertRaises
(
RuntimeError
,
d
.
count
,
3
)
self
.
assertRaises
(
RuntimeError
,
d
.
count
,
3
)
# test issue11004
# block advance failed after rotation aligned elements on right side of block
d
=
deque
([
None
]
*
16
)
for
i
in
range
(
len
(
d
)):
d
.
rotate
(
-
1
)
d
.
rotate
(
1
)
self
.
assertEqual
(
d
.
count
(
1
),
0
)
self
.
assertEqual
(
d
.
count
(
None
),
16
)
def
test_comparisons
(
self
):
def
test_comparisons
(
self
):
d
=
deque
(
'xabc'
);
d
.
popleft
()
d
=
deque
(
'xabc'
);
d
.
popleft
()
for
e
in
[
d
,
deque
(
'abc'
),
deque
(
'ab'
),
deque
(),
list
(
d
)]:
for
e
in
[
d
,
deque
(
'abc'
),
deque
(
'ab'
),
deque
(),
list
(
d
)]:
...
...
Misc/NEWS
View file @
57a8689b
...
@@ -19,6 +19,8 @@ Core and Builtins
...
@@ -19,6 +19,8 @@ Core and Builtins
non-Python managed memory while it is being modified by another thread.
non-Python managed memory while it is being modified by another thread.
Patch by Matt Bandy.
Patch by Matt Bandy.
- Issue #11004: Repaired edge case in deque.count().
- Issue #8278: On Windows and with a NTFS filesystem, os.stat() and os.utime()
- Issue #8278: On Windows and with a NTFS filesystem, os.stat() and os.utime()
can now handle dates after 2038.
can now handle dates after 2038.
...
...
Modules/_collectionsmodule.c
View file @
57a8689b
...
@@ -485,7 +485,8 @@ deque_reverse(dequeobject *deque, PyObject *unused)
...
@@ -485,7 +485,8 @@ deque_reverse(dequeobject *deque, PyObject *unused)
/* Advance left block/index pair */
/* Advance left block/index pair */
leftindex
++
;
leftindex
++
;
if
(
leftindex
==
BLOCKLEN
)
{
if
(
leftindex
==
BLOCKLEN
)
{
assert
(
leftblock
->
rightlink
!=
NULL
);
if
(
leftblock
->
rightlink
==
NULL
)
break
;
leftblock
=
leftblock
->
rightlink
;
leftblock
=
leftblock
->
rightlink
;
leftindex
=
0
;
leftindex
=
0
;
}
}
...
@@ -493,7 +494,8 @@ deque_reverse(dequeobject *deque, PyObject *unused)
...
@@ -493,7 +494,8 @@ deque_reverse(dequeobject *deque, PyObject *unused)
/* Step backwards with the right block/index pair */
/* Step backwards with the right block/index pair */
rightindex
--
;
rightindex
--
;
if
(
rightindex
==
-
1
)
{
if
(
rightindex
==
-
1
)
{
assert
(
rightblock
->
leftlink
!=
NULL
);
if
(
rightblock
->
leftlink
==
NULL
)
break
;
rightblock
=
rightblock
->
leftlink
;
rightblock
=
rightblock
->
leftlink
;
rightindex
=
BLOCKLEN
-
1
;
rightindex
=
BLOCKLEN
-
1
;
}
}
...
@@ -509,7 +511,7 @@ deque_count(dequeobject *deque, PyObject *v)
...
@@ -509,7 +511,7 @@ deque_count(dequeobject *deque, PyObject *v)
{
{
block
*
leftblock
=
deque
->
leftblock
;
block
*
leftblock
=
deque
->
leftblock
;
Py_ssize_t
leftindex
=
deque
->
leftindex
;
Py_ssize_t
leftindex
=
deque
->
leftindex
;
Py_ssize_t
n
=
(
deque
->
len
)
;
Py_ssize_t
n
=
deque
->
len
;
Py_ssize_t
i
;
Py_ssize_t
i
;
Py_ssize_t
count
=
0
;
Py_ssize_t
count
=
0
;
PyObject
*
item
;
PyObject
*
item
;
...
@@ -533,7 +535,8 @@ deque_count(dequeobject *deque, PyObject *v)
...
@@ -533,7 +535,8 @@ deque_count(dequeobject *deque, PyObject *v)
/* Advance left block/index pair */
/* Advance left block/index pair */
leftindex
++
;
leftindex
++
;
if
(
leftindex
==
BLOCKLEN
)
{
if
(
leftindex
==
BLOCKLEN
)
{
assert
(
leftblock
->
rightlink
!=
NULL
);
if
(
leftblock
->
rightlink
==
NULL
)
/* can occur when i==n-1 */
break
;
leftblock
=
leftblock
->
rightlink
;
leftblock
=
leftblock
->
rightlink
;
leftindex
=
0
;
leftindex
=
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