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
e0f493b6
Commit
e0f493b6
authored
Dec 08, 2012
by
Éric Araujo
Browse files
Options
Browse Files
Download
Plain Diff
Branch merge
parents
ca9e4b35
a1c22d12
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
39 additions
and
4 deletions
+39
-4
Include/weakrefobject.h
Include/weakrefobject.h
+11
-1
Lib/test/test_weakref.py
Lib/test/test_weakref.py
+21
-0
Misc/ACKS
Misc/ACKS
+1
-0
Misc/NEWS
Misc/NEWS
+4
-0
Objects/weakrefobject.c
Objects/weakrefobject.c
+2
-3
No files found.
Include/weakrefobject.h
View file @
e0f493b6
...
...
@@ -70,7 +70,17 @@ PyAPI_FUNC(Py_ssize_t) _PyWeakref_GetWeakrefCount(PyWeakReference *head);
PyAPI_FUNC
(
void
)
_PyWeakref_ClearRef
(
PyWeakReference
*
self
);
#endif
#define PyWeakref_GET_OBJECT(ref) (((PyWeakReference *)(ref))->wr_object)
/* Explanation for the Py_REFCNT() check: when a weakref's target is part
of a long chain of deallocations which triggers the trashcan mechanism,
clearing the weakrefs can be delayed long after the target's refcount
has dropped to zero. In the meantime, code accessing the weakref will
be able to "see" the target object even though it is supposed to be
unreachable. See issue #16602. */
#define PyWeakref_GET_OBJECT(ref) \
(Py_REFCNT(((PyWeakReference *)(ref))->wr_object) > 0 \
? ((PyWeakReference *)(ref))->wr_object \
: Py_None)
#ifdef __cplusplus
...
...
Lib/test/test_weakref.py
View file @
e0f493b6
...
...
@@ -776,6 +776,27 @@ class ReferencesTestCase(TestBase):
self
.
assertEqual
(
hash
(
a
),
hash
(
42
))
self
.
assertRaises
(
TypeError
,
hash
,
b
)
def
test_trashcan_16602
(
self
):
# Issue #16602: when a weakref's target was part of a long
# deallocation chain, the trashcan mechanism could delay clearing
# of the weakref and make the target object visible from outside
# code even though its refcount had dropped to 0. A crash ensued.
class
C
:
def
__init__
(
self
,
parent
):
if
not
parent
:
return
wself
=
weakref
.
ref
(
self
)
def
cb
(
wparent
):
o
=
wself
()
self
.
wparent
=
weakref
.
ref
(
parent
,
cb
)
d
=
weakref
.
WeakKeyDictionary
()
root
=
c
=
C
(
None
)
for
n
in
range
(
100
):
d
[
c
]
=
c
=
C
(
c
)
del
root
gc
.
collect
()
class
SubclassableWeakrefTestCase
(
TestBase
):
...
...
Misc/ACKS
View file @
e0f493b6
...
...
@@ -1070,6 +1070,7 @@ Jim Tittsler
Frank J. Tobin
R Lindsay Todd
Bennett Todd
Eugene Toder
Erik Tollerud
Matias Torchinsky
Sandro Tosi
...
...
Misc/NEWS
View file @
e0f493b6
...
...
@@ -10,6 +10,10 @@ What's New in Python 3.2.4
Core and Builtins
-----------------
- Issue #16602: When a weakref's target was part of a long deallocation
chain, the object could remain reachable through its weakref even though
its refcount had dropped to zero.
- Issue #16416: On Mac OS X, operating system data are now always
encoded/decoded to/from UTF-8/surrogateescape, instead of the locale encoding
(which may be ASCII if no locale environment variable is set), to avoid
...
...
Objects/weakrefobject.c
View file @
e0f493b6
...
...
@@ -52,9 +52,8 @@ clear_weakref(PyWeakReference *self)
{
PyObject
*
callback
=
self
->
wr_callback
;
if
(
PyWeakref_GET_OBJECT
(
self
)
!=
Py_None
)
{
PyWeakReference
**
list
=
GET_WEAKREFS_LISTPTR
(
PyWeakref_GET_OBJECT
(
self
));
if
(
self
->
wr_object
!=
Py_None
)
{
PyWeakReference
**
list
=
GET_WEAKREFS_LISTPTR
(
self
->
wr_object
);
if
(
*
list
==
self
)
/* If 'self' is the end of the list (and thus self->wr_next == NULL)
...
...
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