Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
d896985b
Kaydet (Commit)
d896985b
authored
May 20, 2017
tarafından
Serhiy Storchaka
Kaydeden (comit)
GitHub
May 20, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
bpo-25794: Fix `type.__setattr__()` for non-interned attribute names. (#1652)
Based on patch by Eryk Sun.
üst
3378b206
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
6 deletions
+63
-6
test_class.py
Lib/test/test_class.py
+27
-0
NEWS
Misc/NEWS
+3
-0
typeobject.c
Objects/typeobject.c
+33
-6
No files found.
Lib/test/test_class.py
Dosyayı görüntüle @
d896985b
...
...
@@ -568,5 +568,32 @@ class ClassTests(unittest.TestCase):
a
=
A
(
hash
(
A
.
f
)
^
(
-
1
))
hash
(
a
.
f
)
def
testSetattrWrapperNameIntern
(
self
):
# Issue #25794: __setattr__ should intern the attribute name
class
A
:
pass
def
add
(
self
,
other
):
return
'summa'
name
=
str
(
b
'__add__'
,
'ascii'
)
# shouldn't be optimized
self
.
assertIsNot
(
name
,
'__add__'
)
# not interned
type
.
__setattr__
(
A
,
name
,
add
)
self
.
assertEqual
(
A
()
+
1
,
'summa'
)
name2
=
str
(
b
'__add__'
,
'ascii'
)
self
.
assertIsNot
(
name2
,
'__add__'
)
self
.
assertIsNot
(
name2
,
name
)
type
.
__delattr__
(
A
,
name2
)
with
self
.
assertRaises
(
TypeError
):
A
()
+
1
def
testSetattrNonStringName
(
self
):
class
A
:
pass
with
self
.
assertRaises
(
TypeError
):
type
.
__setattr__
(
A
,
b
'x'
,
None
)
if
__name__
==
'__main__'
:
unittest
.
main
()
Misc/NEWS
Dosyayı görüntüle @
d896985b
...
...
@@ -10,6 +10,9 @@ What's New in Python 3.7.0 alpha 1?
Core and Builtins
-----------------
- bpo-25794: Fixed type.__setattr__() and type.__delattr__() for
non-interned attribute names. Based on patch by Eryk Sun.
- bpo-30039: If a KeyboardInterrupt happens when the interpreter is in
the middle of resuming a chain of nested '
yield
from
' or '
await
'
calls, it'
s
now
correctly
delivered
to
the
innermost
frame
.
...
...
Objects/typeobject.c
Dosyayı görüntüle @
d896985b
...
...
@@ -3138,10 +3138,35 @@ type_setattro(PyTypeObject *type, PyObject *name, PyObject *value)
type
->
tp_name
);
return
-
1
;
}
if
(
_PyObject_GenericSetAttrWithDict
((
PyObject
*
)
type
,
name
,
value
,
NULL
)
<
0
)
return
-
1
;
res
=
update_slot
(
type
,
name
);
assert
(
_PyType_CheckConsistency
(
type
));
if
(
PyUnicode_Check
(
name
))
{
if
(
PyUnicode_CheckExact
(
name
))
{
if
(
PyUnicode_READY
(
name
)
==
-
1
)
return
-
1
;
Py_INCREF
(
name
);
}
else
{
name
=
_PyUnicode_Copy
(
name
);
if
(
name
==
NULL
)
return
-
1
;
}
PyUnicode_InternInPlace
(
&
name
);
if
(
!
PyUnicode_CHECK_INTERNED
(
name
))
{
PyErr_SetString
(
PyExc_MemoryError
,
"Out of memory interning an attribute name"
);
Py_DECREF
(
name
);
return
-
1
;
}
}
else
{
/* Will fail in _PyObject_GenericSetAttrWithDict. */
Py_INCREF
(
name
);
}
res
=
_PyObject_GenericSetAttrWithDict
((
PyObject
*
)
type
,
name
,
value
,
NULL
);
if
(
res
==
0
)
{
res
=
update_slot
(
type
,
name
);
assert
(
_PyType_CheckConsistency
(
type
));
}
Py_DECREF
(
name
);
return
res
;
}
...
...
@@ -7065,7 +7090,7 @@ init_slotdefs(void)
/* Slots must be ordered by their offset in the PyHeapTypeObject. */
assert
(
!
p
[
1
].
name
||
p
->
offset
<=
p
[
1
].
offset
);
p
->
name_strobj
=
PyUnicode_InternFromString
(
p
->
name
);
if
(
!
p
->
name_strobj
)
if
(
!
p
->
name_strobj
||
!
PyUnicode_CHECK_INTERNED
(
p
->
name_strobj
)
)
Py_FatalError
(
"Out of memory interning slotdef names"
);
}
slotdefs_initialized
=
1
;
...
...
@@ -7090,6 +7115,9 @@ update_slot(PyTypeObject *type, PyObject *name)
slotdef
**
pp
;
int
offset
;
assert
(
PyUnicode_CheckExact
(
name
));
assert
(
PyUnicode_CHECK_INTERNED
(
name
));
/* Clear the VALID_VERSION flag of 'type' and all its
subclasses. This could possibly be unified with the
update_subclasses() recursion below, but carefully:
...
...
@@ -7100,7 +7128,6 @@ update_slot(PyTypeObject *type, PyObject *name)
init_slotdefs
();
pp
=
ptrs
;
for
(
p
=
slotdefs
;
p
->
name
;
p
++
)
{
/* XXX assume name is interned! */
if
(
p
->
name_strobj
==
name
)
*
pp
++
=
p
;
}
...
...
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