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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
3227fb94
Commit
3227fb94
authored
Aug 28, 2020
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Protect the cypclass dict against active iterators being invalidated
parent
839ae2b7
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
240 additions
and
64 deletions
+240
-64
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+6
-0
Cython/Includes/libcythonplus/dict.pxd
Cython/Includes/libcythonplus/dict.pxd
+97
-62
tests/run/cypclass_builtin_dict.pyx
tests/run/cypclass_builtin_dict.pyx
+137
-2
No files found.
Cython/Compiler/ExprNodes.py
View file @
3227fb94
...
...
@@ -2979,6 +2979,12 @@ class CppIteratorNode(ExprNode):
code
.
putln
(
"++%s;"
%
self
.
result
())
def
generate_disposal_code
(
self
,
code
):
# clean-up the iterator by assigning end to it
# this is only required if the iterator holds resources that must be released once iteration is complete
code
.
putln
(
"%s = %s%send();"
%
(
self
.
result
(),
self
.
cpp_sequence_cname
or
self
.
sequence
.
result
(),
self
.
cpp_attribute_op
))
if
self
.
cpp_sequence_cname
and
self
.
sequence
.
type
.
is_cyp_class
:
code
.
put_decref
(
self
.
cpp_sequence_cname
,
self
.
sequence
.
type
)
super
(
CppIteratorNode
,
self
).
generate_disposal_code
(
code
)
...
...
Cython/Includes/libcythonplus/dict.pxd
View file @
3227fb94
This diff is collapsed.
Click to expand it.
tests/run/cypclass_builtin_dict.pyx
View file @
3227fb94
...
...
@@ -136,8 +136,8 @@ def test_getitem_exception():
'Getting nonexistent item'
1
"""
d
=
cypdict
[
Index
,
Value
]()
try
:
d
=
cypdict
[
Index
,
Value
]()
with
nogil
:
v
=
d
[
Index
()]
with
gil
:
...
...
@@ -152,8 +152,8 @@ def test_delitem_exception():
'Deleting nonexistent item'
1
"""
d
=
cypdict
[
Index
,
Value
]()
try
:
d
=
cypdict
[
Index
,
Value
]()
with
nogil
:
del
d
[
Index
()]
with
gil
:
...
...
@@ -162,3 +162,138 @@ def test_delitem_exception():
print
(
e
)
return
1
def
test_setitem_exception_dict_iterator
():
"""
>>> test_setitem_exception_dict_iterator()
Modifying a dictionary with active iterators
1
"""
d
=
cypdict
[
Index
,
Value
]()
iterator
=
d
.
begin
()
try
:
with
nogil
:
d
[
Index
()]
=
Value
()
with
gil
:
return
0
except
RuntimeError
as
e
:
print
(
e
)
return
1
def
test_setitem_exception_dict_keys_iterator
():
"""
>>> test_setitem_exception_dict_keys_iterator()
Modifying a dictionary with active iterators
1
"""
d
=
cypdict
[
Index
,
Value
]()
iterator
=
d
.
keys
().
begin
()
try
:
with
nogil
:
d
[
Index
()]
=
Value
()
with
gil
:
return
0
except
RuntimeError
as
e
:
print
(
e
)
return
1
def
test_setitem_exception_dict_values_iterator
():
"""
>>> test_setitem_exception_dict_values_iterator()
Modifying a dictionary with active iterators
1
"""
d
=
cypdict
[
Index
,
Value
]()
iterator
=
d
.
values
().
begin
()
try
:
with
nogil
:
d
[
Index
()]
=
Value
()
with
gil
:
return
0
except
RuntimeError
as
e
:
print
(
e
)
return
1
def
test_setitem_exception_dict_items_iterator
():
"""
>>> test_setitem_exception_dict_items_iterator()
Modifying a dictionary with active iterators
1
"""
d
=
cypdict
[
Index
,
Value
]()
iterator
=
d
.
items
().
begin
()
try
:
with
nogil
:
d
[
Index
()]
=
Value
()
with
gil
:
return
0
except
RuntimeError
as
e
:
print
(
e
)
return
1
def
test_setitem_after_dict_iterator
():
"""
>>> test_setitem_after_dict_iterator()
1
"""
d
=
cypdict
[
Index
,
Value
]()
for
key
in
d
:
pass
try
:
with
nogil
:
d
[
Index
()]
=
Value
()
with
gil
:
return
1
except
RuntimeError
as
e
:
print
(
e
)
return
0
def
test_setitem_after_dict_keys_iterator
():
"""
>>> test_setitem_after_dict_keys_iterator()
1
"""
d
=
cypdict
[
Index
,
Value
]()
for
key
in
d
.
keys
():
pass
try
:
with
nogil
:
d
[
Index
()]
=
Value
()
with
gil
:
return
1
except
RuntimeError
as
e
:
print
(
e
)
return
0
def
test_setitem_after_dict_values_iterator
():
"""
>>> test_setitem_after_dict_values_iterator()
1
"""
d
=
cypdict
[
Index
,
Value
]()
for
value
in
d
.
values
():
pass
try
:
with
nogil
:
d
[
Index
()]
=
Value
()
with
gil
:
return
1
except
RuntimeError
as
e
:
print
(
e
)
return
0
def
test_setitem_after_dict_items_iterator
():
"""
>>> test_setitem_after_dict_items_iterator()
1
"""
d
=
cypdict
[
Index
,
Value
]()
for
item
in
d
.
items
():
pass
try
:
with
nogil
:
d
[
Index
()]
=
Value
()
with
gil
:
return
1
except
RuntimeError
as
e
:
print
(
e
)
return
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