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
796cc6e3
Commit
796cc6e3
authored
Mar 28, 2019
by
Thomas Perl
Committed by
Inada Naoki
Mar 28, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-36452: dictiter: track maximum iteration count (GH-12596)
parent
738cb42a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
0 deletions
+16
-0
Lib/test/test_dict.py
Lib/test/test_dict.py
+9
-0
Misc/NEWS.d/next/Core and Builtins/2019-03-27-23-53-00.bpo-36452.xhK2lT.rst
...ore and Builtins/2019-03-27-23-53-00.bpo-36452.xhK2lT.rst
+1
-0
Objects/dictobject.c
Objects/dictobject.c
+6
-0
No files found.
Lib/test/test_dict.py
View file @
796cc6e3
...
...
@@ -470,6 +470,15 @@ class DictTest(unittest.TestCase):
for
i
in
d
:
d
[
i
+
1
]
=
1
def
test_mutating_iteration_delete
(
self
):
# change dict content during iteration
d
=
{}
d
[
0
]
=
0
with
self
.
assertRaises
(
RuntimeError
):
for
i
in
d
:
del
d
[
0
]
d
[
1
]
=
1
def
test_mutating_lookup
(
self
):
# changing dict during a lookup (issue #14417)
class
NastyKey
:
...
...
Misc/NEWS.d/next/Core and Builtins/2019-03-27-23-53-00.bpo-36452.xhK2lT.rst
0 → 100644
View file @
796cc6e3
Changing `dict` keys during iteration will now be detected in certain corner cases where the number of keys isn't changed (but they keys themselves are), and a `RuntimeError` will be raised.
\ No newline at end of file
Objects/dictobject.c
View file @
796cc6e3
...
...
@@ -3543,6 +3543,12 @@ dictiter_iternextkey(dictiterobject *di)
goto
fail
;
key
=
entry_ptr
->
me_key
;
}
// We found an element (key), but did not expect it
if
(
di
->
len
==
0
)
{
PyErr_SetString
(
PyExc_RuntimeError
,
"dictionary keys changed during iteration"
);
goto
fail
;
}
di
->
di_pos
=
i
+
1
;
di
->
len
--
;
Py_INCREF
(
key
);
...
...
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