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
a63cc212
Commit
a63cc212
authored
Apr 13, 2015
by
Antoine Pitrou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #23726: Don't enable GC for user subclasses of non-GC types that don't add any new fields.
Patch by Eugene Toder.
parent
56452eea
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
5 deletions
+27
-5
Lib/test/test_descr.py
Lib/test/test_descr.py
+0
-2
Lib/test/test_gc.py
Lib/test/test_gc.py
+20
-0
Misc/NEWS
Misc/NEWS
+3
-0
Objects/typeobject.c
Objects/typeobject.c
+4
-3
No files found.
Lib/test/test_descr.py
View file @
a63cc212
...
...
@@ -3020,8 +3020,6 @@ order (MRO) for bases """
cant
(
object
(),
list
)
cant
(
list
(),
object
)
class
Int
(
int
):
__slots__
=
[]
cant
(
2
,
Int
)
cant
(
Int
(),
int
)
cant
(
True
,
int
)
cant
(
2
,
bool
)
o
=
object
()
...
...
Lib/test/test_gc.py
View file @
a63cc212
...
...
@@ -546,11 +546,31 @@ class GCTests(unittest.TestCase):
class
UserClass
:
pass
class
UserInt
(
int
):
pass
# Base class is object; no extra fields.
class
UserClassSlots
:
__slots__
=
()
# Base class is fixed size larger than object; no extra fields.
class
UserFloatSlots
(
float
):
__slots__
=
()
# Base class is variable size; no extra fields.
class
UserIntSlots
(
int
):
__slots__
=
()
self
.
assertTrue
(
gc
.
is_tracked
(
gc
))
self
.
assertTrue
(
gc
.
is_tracked
(
UserClass
))
self
.
assertTrue
(
gc
.
is_tracked
(
UserClass
()))
self
.
assertTrue
(
gc
.
is_tracked
(
UserInt
()))
self
.
assertTrue
(
gc
.
is_tracked
([]))
self
.
assertTrue
(
gc
.
is_tracked
(
set
()))
self
.
assertFalse
(
gc
.
is_tracked
(
UserClassSlots
()))
self
.
assertFalse
(
gc
.
is_tracked
(
UserFloatSlots
()))
self
.
assertFalse
(
gc
.
is_tracked
(
UserIntSlots
()))
def
test_bug1055820b
(
self
):
# Corresponds to temp2b.py in the bug report.
...
...
Misc/NEWS
View file @
a63cc212
...
...
@@ -10,6 +10,9 @@ Release date: XXX
Core and Builtins
-----------------
- Issue #23726: Don'
t
enable
GC
for
user
subclasses
of
non
-
GC
types
that
don
't add any new fields. Patch by Eugene Toder.
- Issue #23309: Avoid a deadlock at shutdown if a daemon thread is aborted
while it is holding a lock to a buffered I/O object, and the main thread
tries to use the same I/O object (typically stdout or stderr). A fatal
...
...
Objects/typeobject.c
View file @
a63cc212
...
...
@@ -2645,9 +2645,10 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
}
type
->
tp_dealloc
=
subtype_dealloc
;
/* Enable GC unless there are really no instance variables possible */
if
(
!
(
type
->
tp_basicsize
==
sizeof
(
PyObject
)
&&
type
->
tp_itemsize
==
0
))
/* Enable GC unless this class is not adding new instance variables and
the base class did not use GC. */
if
((
base
->
tp_flags
&
Py_TPFLAGS_HAVE_GC
)
||
type
->
tp_basicsize
>
base
->
tp_basicsize
)
type
->
tp_flags
|=
Py_TPFLAGS_HAVE_GC
;
/* Always override allocation strategy to use regular heap */
...
...
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