pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/python/cpython/commit/a63cc212348e276c8ede32773313c60ff7fda651

aa60c69660fa.css" /> Issue #23726: Don't enable GC for user subclasses of non-GC types tha… · python/cpython@a63cc21 · GitHub
Skip to content

Commit a63cc21

Browse files
committed
Issue #23726: Don't enable GC for user subclasses of non-GC types that don't add any new fields.
Patch by Eugene Toder.
1 parent 56452ee commit a63cc21

4 files changed

Lines changed: 27 additions & 5 deletions

File tree

Lib/test/test_descr.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3020,8 +3020,6 @@ def cant(x, C):
30203020
cant(object(), list)
30213021
cant(list(), object)
30223022
class Int(int): __slots__ = []
3023-
cant(2, Int)
3024-
cant(Int(), int)
30253023
cant(True, int)
30263024
cant(2, bool)
30273025
o = object()

Lib/test/test_gc.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,11 +546,31 @@ def test_is_tracked(self):
546546

547547
class UserClass:
548548
pass
549+
550+
class UserInt(int):
551+
pass
552+
553+
# Base class is object; no extra fields.
554+
class UserClassSlots:
555+
__slots__ = ()
556+
557+
# Base class is fixed size larger than object; no extra fields.
558+
class UserFloatSlots(float):
559+
__slots__ = ()
560+
561+
# Base class is variable size; no extra fields.
562+
class UserIntSlots(int):
563+
__slots__ = ()
564+
549565
self.assertTrue(gc.is_tracked(gc))
550566
self.assertTrue(gc.is_tracked(UserClass))
551567
self.assertTrue(gc.is_tracked(UserClass()))
568+
self.assertTrue(gc.is_tracked(UserInt()))
552569
self.assertTrue(gc.is_tracked([]))
553570
self.assertTrue(gc.is_tracked(set()))
571+
self.assertFalse(gc.is_tracked(UserClassSlots()))
572+
self.assertFalse(gc.is_tracked(UserFloatSlots()))
573+
self.assertFalse(gc.is_tracked(UserIntSlots()))
554574

555575
def test_bug1055820b(self):
556576
# Corresponds to temp2b.py in the bug report.

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ Release date: XXX
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #23726: Don't enable GC for user subclasses of non-GC types that
14+
don't add any new fields. Patch by Eugene Toder.
15+
1316
- Issue #23309: Avoid a deadlock at shutdown if a daemon thread is aborted
1417
while it is holding a lock to a buffered I/O object, and the main thread
1518
tries to use the same I/O object (typically stdout or stderr). A fatal

Objects/typeobject.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2645,9 +2645,10 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
26452645
}
26462646
type->tp_dealloc = subtype_dealloc;
26472647

2648-
/* Enable GC unless there are really no instance variables possible */
2649-
if (!(type->tp_basicsize == sizeof(PyObject) &&
2650-
type->tp_itemsize == 0))
2648+
/* Enable GC unless this class is not adding new instance variables and
2649+
the base class did not use GC. */
2650+
if ((base->tp_flags & Py_TPFLAGS_HAVE_GC) ||
2651+
type->tp_basicsize > base->tp_basicsize)
26512652
type->tp_flags |= Py_TPFLAGS_HAVE_GC;
26522653

26532654
/* Always override allocation strategy to use regular heap */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy