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
a57df2cf
Commit
a57df2cf
authored
Mar 31, 2010
by
Antoine Pitrou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #8268: Old-style classes (not just instances) now support weak
references.
parent
26cc99da
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
29 additions
and
2 deletions
+29
-2
Include/classobject.h
Include/classobject.h
+1
-0
Lib/test/test_sys.py
Lib/test/test_sys.py
+1
-1
Lib/test/test_weakref.py
Lib/test/test_weakref.py
+20
-0
Misc/NEWS
Misc/NEWS
+3
-0
Objects/classobject.c
Objects/classobject.c
+4
-1
No files found.
Include/classobject.h
View file @
a57df2cf
...
...
@@ -18,6 +18,7 @@ typedef struct {
PyObject
*
cl_getattr
;
PyObject
*
cl_setattr
;
PyObject
*
cl_delattr
;
PyObject
*
cl_weakreflist
;
/* List of weak references */
}
PyClassObject
;
typedef
struct
{
...
...
Lib/test/test_sys.py
View file @
a57df2cf
...
...
@@ -544,7 +544,7 @@ class SizeofTest(unittest.TestCase):
class
class_oldstyle
():
def
method
():
pass
check
(
class_oldstyle
,
size
(
h
+
'
6
P'
))
check
(
class_oldstyle
,
size
(
h
+
'
7
P'
))
# instance (old-style class)
check
(
class_oldstyle
(),
size
(
h
+
'3P'
))
# instancemethod (old-style class)
...
...
Lib/test/test_weakref.py
View file @
a57df2cf
...
...
@@ -685,6 +685,26 @@ class ReferencesTestCase(TestBase):
# No exception should be raised here
gc
.
collect
()
def
test_classes
(
self
):
# Check that both old-style classes and new-style classes
# are weakrefable.
class
A
(
object
):
pass
class
B
:
pass
l
=
[]
weakref
.
ref
(
int
)
a
=
weakref
.
ref
(
A
,
l
.
append
)
A
=
None
gc
.
collect
()
self
.
assertEqual
(
a
(),
None
)
self
.
assertEqual
(
l
,
[
a
])
b
=
weakref
.
ref
(
B
,
l
.
append
)
B
=
None
gc
.
collect
()
self
.
assertEqual
(
b
(),
None
)
self
.
assertEqual
(
l
,
[
a
,
b
])
class
SubclassableWeakrefTestCase
(
TestBase
):
...
...
Misc/NEWS
View file @
a57df2cf
...
...
@@ -12,6 +12,9 @@ What's New in Python 2.7 beta 1?
Core and Builtins
-----------------
- Issue #8268: Old-style classes (not just instances) now support weak
references.
- Issue #8211: Save/restore CFLAGS around AC_PROG_CC in configure.in, compiler
optimizations are disabled when --with-pydebug is used.
...
...
Objects/classobject.c
View file @
a57df2cf
...
...
@@ -123,6 +123,7 @@ alloc_error:
op
->
cl_dict
=
dict
;
Py_XINCREF
(
name
);
op
->
cl_name
=
name
;
op
->
cl_weakreflist
=
NULL
;
op
->
cl_getattr
=
class_lookup
(
op
,
getattrstr
,
&
dummy
);
op
->
cl_setattr
=
class_lookup
(
op
,
setattrstr
,
&
dummy
);
...
...
@@ -188,6 +189,8 @@ static void
class_dealloc
(
PyClassObject
*
op
)
{
_PyObject_GC_UNTRACK
(
op
);
if
(
op
->
cl_weakreflist
!=
NULL
)
PyObject_ClearWeakRefs
((
PyObject
*
)
op
);
Py_DECREF
(
op
->
cl_bases
);
Py_DECREF
(
op
->
cl_dict
);
Py_XDECREF
(
op
->
cl_name
);
...
...
@@ -454,7 +457,7 @@ PyTypeObject PyClass_Type = {
(
traverseproc
)
class_traverse
,
/* tp_traverse */
0
,
/* tp_clear */
0
,
/* tp_richcompare */
0
,
/* tp_weaklistoffset */
offsetof
(
PyClassObject
,
cl_weakreflist
),
/* tp_weaklistoffset */
0
,
/* tp_iter */
0
,
/* tp_iternext */
0
,
/* tp_methods */
...
...
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