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
14eefe35
Commit
14eefe35
authored
Nov 01, 2015
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #25395: Fixed crash when highly nested OrderedDict structures were
garbage collected.
parent
964ec8b2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
3 deletions
+41
-3
Lib/test/test_collections.py
Lib/test/test_collections.py
+24
-0
Misc/NEWS
Misc/NEWS
+3
-0
Objects/odictobject.c
Objects/odictobject.c
+14
-3
No files found.
Lib/test/test_collections.py
View file @
14eefe35
...
...
@@ -2025,6 +2025,30 @@ class OrderedDictTests:
items
=
[(
'a'
,
1
),
(
'c'
,
3
),
(
'b'
,
2
)]
self
.
assertEqual
(
list
(
MyOD
(
items
).
items
()),
items
)
def
test_highly_nested
(
self
):
# Issue 25395: crashes during garbage collection
OrderedDict
=
self
.
module
.
OrderedDict
obj
=
None
for
_
in
range
(
1000
):
obj
=
OrderedDict
([(
None
,
obj
)])
del
obj
support
.
gc_collect
()
def
test_highly_nested_subclass
(
self
):
# Issue 25395: crashes during garbage collection
OrderedDict
=
self
.
module
.
OrderedDict
deleted
=
[]
class
MyOD
(
OrderedDict
):
def
__del__
(
self
):
deleted
.
append
(
self
.
i
)
obj
=
None
for
i
in
range
(
100
):
obj
=
MyOD
([(
None
,
obj
)])
obj
.
i
=
i
del
obj
support
.
gc_collect
()
self
.
assertEqual
(
deleted
,
list
(
reversed
(
range
(
100
))))
class
PurePythonOrderedDictTests
(
OrderedDictTests
,
unittest
.
TestCase
):
...
...
Misc/NEWS
View file @
14eefe35
...
...
@@ -11,6 +11,9 @@ Release date: TBA
Core and Builtins
-----------------
- Issue #25395: Fixed crash when highly nested OrderedDict structures were
garbage collected.
- Issue #25274: sys.setrecursionlimit() now raises a RecursionError if the new
recursion limit is too low depending at the current recursion depth. Modify
also the "lower-water mark" formula to make it monotonic. This mark is used
...
...
Objects/odictobject.c
View file @
14eefe35
...
...
@@ -1431,17 +1431,28 @@ static PyMemberDef odict_members[] = {
static
void
odict_dealloc
(
PyODictObject
*
self
)
{
PyThreadState
*
tstate
=
PyThreadState_GET
();
PyObject_GC_UnTrack
(
self
);
Py_TRASHCAN_SAFE_BEGIN
(
self
);
Py_TRASHCAN_SAFE_BEGIN
(
self
)
Py_XDECREF
(
self
->
od_inst_dict
);
if
(
self
->
od_weakreflist
!=
NULL
)
PyObject_ClearWeakRefs
((
PyObject
*
)
self
);
_odict_clear_nodes
(
self
);
Py_TRASHCAN_SAFE_END
(
self
);
/* must be last */
/* Call the base tp_dealloc(). Since it too uses the trashcan mechanism,
* temporarily decrement trash_delete_nesting to prevent triggering it
* and putting the partially deallocated object on the trashcan's
* to-be-deleted-later list.
*/
--
tstate
->
trash_delete_nesting
;
assert
(
_tstate
->
trash_delete_nesting
<
PyTrash_UNWIND_LEVEL
);
PyDict_Type
.
tp_dealloc
((
PyObject
*
)
self
);
++
tstate
->
trash_delete_nesting
;
Py_TRASHCAN_SAFE_END
(
self
)
};
/* tp_repr */
...
...
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