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
80448091
Commit
80448091
authored
8 years ago
by
Benjamin Peterson
Browse files
Options
Browse Files
Download
Plain Diff
merge 3.5 (#26617)
parents
fb12ce1c
8f657c35
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
12 deletions
+23
-12
Lib/test/test_weakref.py
Lib/test/test_weakref.py
+8
-0
Misc/NEWS
Misc/NEWS
+2
-0
Objects/typeobject.c
Objects/typeobject.c
+13
-12
No files found.
Lib/test/test_weakref.py
View file @
80448091
...
...
@@ -845,6 +845,14 @@ class ReferencesTestCase(TestBase):
with
self
.
assertRaises
(
AttributeError
):
ref1
.
__callback__
=
lambda
ref
:
None
def
test_callback_gcs
(
self
):
class
ObjectWithDel
(
Object
):
def
__del__
(
self
):
pass
x
=
ObjectWithDel
(
1
)
ref1
=
weakref
.
ref
(
x
,
lambda
ref
:
support
.
gc_collect
())
del
x
support
.
gc_collect
()
class
SubclassableWeakrefTestCase
(
TestBase
):
...
...
This diff is collapsed.
Click to expand it.
Misc/NEWS
View file @
80448091
...
...
@@ -10,6 +10,8 @@ What's New in Python 3.6.0 beta 2
Core and Builtins
-----------------
- Issue #26617: Fix crash when GC runs during weakref callbacks.
- Issue #27942: String constants now interned recursively in tuples and frozensets.
- Issue #21578: Fixed misleading error message when ImportError called with
...
...
This diff is collapsed.
Click to expand it.
Objects/typeobject.c
View file @
80448091
...
...
@@ -1136,11 +1136,6 @@ subtype_dealloc(PyObject *self)
Py_TRASHCAN_SAFE_BEGIN
(
self
);
--
_PyTrash_delete_nesting
;
--
tstate
->
trash_delete_nesting
;
/* DO NOT restore GC tracking at this point. weakref callbacks
* (if any, and whether directly here or indirectly in something we
* call) may trigger GC, and if self is tracked at that point, it
* will look like trash to GC and GC will try to delete self again.
*/
/* Find the nearest base with a different tp_dealloc */
base
=
type
;
...
...
@@ -1151,30 +1146,36 @@ subtype_dealloc(PyObject *self)
has_finalizer
=
type
->
tp_finalize
||
type
->
tp_del
;
/* Maybe call finalizer; exit early if resurrected */
if
(
has_finalizer
)
_PyObject_GC_TRACK
(
self
);
if
(
type
->
tp_finalize
)
{
_PyObject_GC_TRACK
(
self
);
if
(
PyObject_CallFinalizerFromDealloc
(
self
)
<
0
)
{
/* Resurrected */
goto
endlabel
;
}
_PyObject_GC_UNTRACK
(
self
);
}
/* If we added a weaklist, we clear it. Do this *before* calling
tp_del, clearing slots, or clearing the instance dict. */
/*
If we added a weaklist, we clear it. Do this *before* calling tp_del,
clearing slots, or clearing the instance dict.
GC tracking must be off at this point. weakref callbacks (if any, and
whether directly here or indirectly in something we call) may trigger GC,
and if self is tracked at that point, it will look like trash to GC and GC
will try to delete self again.
*/
if
(
type
->
tp_weaklistoffset
&&
!
base
->
tp_weaklistoffset
)
PyObject_ClearWeakRefs
(
self
);
if
(
type
->
tp_del
)
{
_PyObject_GC_TRACK
(
self
);
type
->
tp_del
(
self
);
if
(
self
->
ob_refcnt
>
0
)
{
/* Resurrected */
goto
endlabel
;
}
_PyObject_GC_UNTRACK
(
self
);
}
if
(
has_finalizer
)
{
_PyObject_GC_UNTRACK
(
self
);
/* New weakrefs could be created during the finalizer call.
If this occurs, clear them out without calling their
finalizers since they might rely on part of the object
...
...
This diff is collapsed.
Click to expand it.
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