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
b952ab43
Commit
b952ab43
authored
Jun 01, 2015
by
Eric Snow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #24359: Check for changed OrderedDict size during iteration.
parent
d1719756
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
4 deletions
+12
-4
Lib/test/test_collections.py
Lib/test/test_collections.py
+0
-4
Misc/NEWS
Misc/NEWS
+2
-0
Objects/odictobject.c
Objects/odictobject.c
+10
-0
No files found.
Lib/test/test_collections.py
View file @
b952ab43
...
...
@@ -1746,10 +1746,6 @@ class OrderedDictTests:
self
.
assertEqual
(
list
(
reversed
(
od
.
items
())),
list
(
reversed
(
pairs
)))
def
test_detect_deletion_during_iteration
(
self
):
# XXX This test should also work under cOrderedDict.
if
self
.
module
is
c_coll
:
raise
unittest
.
SkipTest
(
"only valid for pure Python OrderedDict"
)
OrderedDict
=
self
.
module
.
OrderedDict
od
=
OrderedDict
.
fromkeys
(
'abc'
)
it
=
iter
(
od
)
...
...
Misc/NEWS
View file @
b952ab43
...
...
@@ -19,6 +19,8 @@ Library
- Issue #24348: Drop superfluous incref/decref.
- Issue #24359: Check for changed OrderedDict size during iteration.
What'
s
New
in
Python
3.5.0
beta
2
?
==================================
...
...
Objects/odictobject.c
View file @
b952ab43
...
...
@@ -1796,6 +1796,7 @@ typedef struct {
PyObject_HEAD
int
kind
;
PyODictObject
*
di_odict
;
Py_ssize_t
di_size
;
PyObject
*
di_current
;
PyObject
*
di_result
;
/* reusable result tuple for iteritems */
}
odictiterobject
;
...
...
@@ -1835,6 +1836,14 @@ odictiter_nextkey(odictiterobject *di)
if
(
di
->
di_current
==
NULL
)
goto
done
;
/* We're already done. */
/* Check for unsupported changes. */
if
(
di
->
di_size
!=
PyODict_SIZE
(
di
->
di_odict
))
{
PyErr_SetString
(
PyExc_RuntimeError
,
"OrderedDict changed size during iteration"
);
di
->
di_size
=
-
1
;
/* Make this state sticky */
return
NULL
;
}
/* Get the key. */
node
=
_odict_find_node
(
di
->
di_odict
,
di
->
di_current
);
if
(
node
==
NULL
)
{
...
...
@@ -2033,6 +2042,7 @@ odictiter_new(PyODictObject *od, int kind)
node
=
reversed
?
_odict_LAST
(
od
)
:
_odict_FIRST
(
od
);
di
->
di_current
=
node
?
_odictnode_KEY
(
node
)
:
NULL
;
Py_XINCREF
(
di
->
di_current
);
di
->
di_size
=
PyODict_SIZE
(
od
);
di
->
di_odict
=
od
;
Py_INCREF
(
od
);
...
...
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