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
2a48a6eb
Commit
2a48a6eb
authored
Jul 04, 2015
by
Benjamin Peterson
Browse files
Options
Browse Files
Download
Plain Diff
merge 3.3 (#24407)
parents
09e60588
a82f77fb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
7 deletions
+35
-7
Lib/test/test_dict.py
Lib/test/test_dict.py
+14
-0
Misc/NEWS
Misc/NEWS
+2
-0
Objects/dictobject.c
Objects/dictobject.c
+19
-7
No files found.
Lib/test/test_dict.py
View file @
2a48a6eb
...
...
@@ -937,6 +937,20 @@ class DictTest(unittest.TestCase):
d
.
popitem
()
self
.
check_reentrant_insertion
(
mutate
)
def
test_merge_and_mutate
(
self
):
class
X
:
def
__hash__
(
self
):
return
0
def
__eq__
(
self
,
o
):
other
.
clear
()
return
False
l
=
[(
i
,
0
)
for
i
in
range
(
1
,
1337
)]
other
=
dict
(
l
)
other
[
X
()]
=
0
d
=
{
X
():
0
,
1
:
1
}
self
.
assertRaises
(
RuntimeError
,
d
.
update
,
other
)
from
test
import
mapping_tests
...
...
Misc/NEWS
View file @
2a48a6eb
...
...
@@ -32,6 +32,8 @@ Core and Builtins
-
Issue
#
23757
:
PySequence_Tuple
()
incorrectly
called
the
concrete
list
API
when
the
data
was
a
list
subclass
.
-
Issue
#
24407
:
Fix
crash
when
dict
is
mutated
while
being
updated
.
-
Issue
#
24096
:
Make
warnings
.
warn_explicit
more
robust
against
mutation
of
the
warnings
.
filters
list
.
...
...
Objects/dictobject.c
View file @
2a48a6eb
...
...
@@ -1973,20 +1973,32 @@ PyDict_Merge(PyObject *a, PyObject *b, int override)
if
(
dictresize
(
mp
,
(
mp
->
ma_used
+
other
->
ma_used
)
*
2
)
!=
0
)
return
-
1
;
for
(
i
=
0
,
n
=
DK_SIZE
(
other
->
ma_keys
);
i
<
n
;
i
++
)
{
PyObject
*
value
;
PyObject
*
key
,
*
value
;
Py_hash_t
hash
;
entry
=
&
other
->
ma_keys
->
dk_entries
[
i
];
key
=
entry
->
me_key
;
hash
=
entry
->
me_hash
;
if
(
other
->
ma_values
)
value
=
other
->
ma_values
[
i
];
else
value
=
entry
->
me_value
;
if
(
value
!=
NULL
&&
(
override
||
PyDict_GetItem
(
a
,
entry
->
me_key
)
==
NULL
))
{
if
(
insertdict
(
mp
,
entry
->
me_key
,
entry
->
me_hash
,
value
)
!=
0
)
if
(
value
!=
NULL
)
{
int
err
=
0
;
Py_INCREF
(
key
);
Py_INCREF
(
value
);
if
(
override
||
PyDict_GetItem
(
a
,
key
)
==
NULL
)
err
=
insertdict
(
mp
,
key
,
hash
,
value
);
Py_DECREF
(
value
);
Py_DECREF
(
key
);
if
(
err
!=
0
)
return
-
1
;
if
(
n
!=
DK_SIZE
(
other
->
ma_keys
))
{
PyErr_SetString
(
PyExc_RuntimeError
,
"dict mutated during update"
);
return
-
1
;
}
}
}
}
...
...
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