mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
Patch #1680015: Don't modify __slots__ tuple if it contains an unicode
name. Remove a reference leak that happened if the name could not be converted to string. Will backport.
This commit is contained in:
parent
f66b6039c1
commit
71436f0229
3 changed files with 46 additions and 16 deletions
|
@ -1226,6 +1226,29 @@ def slots():
|
|||
class C(object):
|
||||
__slots__ = ["a", "a_b", "_a", "A0123456789Z"]
|
||||
|
||||
# Test unicode slot names
|
||||
try:
|
||||
unichr
|
||||
except NameError:
|
||||
pass
|
||||
else:
|
||||
# _unicode_to_string used to modify slots in certain circumstances
|
||||
slots = (unicode("foo"), unicode("bar"))
|
||||
class C(object):
|
||||
__slots__ = slots
|
||||
x = C()
|
||||
x.foo = 5
|
||||
vereq(x.foo, 5)
|
||||
veris(type(slots[0]), unicode)
|
||||
# this used to leak references
|
||||
try:
|
||||
class C(object):
|
||||
__slots__ = [unichr(128)]
|
||||
except (TypeError, UnicodeEncodeError):
|
||||
pass
|
||||
else:
|
||||
raise TestFailed, "[unichr(128)] slots not caught"
|
||||
|
||||
# Test leaks
|
||||
class Counted(object):
|
||||
counter = 0 # counts the number of instances alive
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue