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
4dcdb78c
Kaydet (Commit)
4dcdb78c
authored
Nis 14, 2003
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Close off the "Verre Carlo hack" as discussed on python-dev.
üst
2fd02eb8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
0 deletions
+39
-0
test_descr.py
Lib/test/test_descr.py
+17
-0
typeobject.c
Objects/typeobject.c
+22
-0
No files found.
Lib/test/test_descr.py
Dosyayı görüntüle @
4dcdb78c
...
...
@@ -3840,6 +3840,22 @@ def proxysuper():
p
=
Proxy
(
obj
)
vereq
(
C
.
__dict__
[
"f"
](
p
),
"B.f->C.f"
)
def
verrecarlo
():
if
verbose
:
print
"Testing prohibition of Verre Carlo's hack..."
try
:
object
.
__setattr__
(
str
,
"foo"
,
42
)
except
TypeError
:
pass
else
:
raise
TestFailed
,
"Verre Carlo __setattr__ suceeded!"
try
:
object
.
__delattr__
(
str
,
"lower"
)
except
TypeError
:
pass
else
:
raise
TestFailed
,
"Verre Carlo __delattr__ succeeded!"
def
test_main
():
do_this_first
()
...
...
@@ -3929,6 +3945,7 @@ def test_main():
meth_class_get
()
isinst_isclass
()
proxysuper
()
verrecarlo
()
if
verbose
:
print
"All OK"
...
...
Objects/typeobject.c
Dosyayı görüntüle @
4dcdb78c
...
...
@@ -3574,6 +3574,24 @@ wrap_cmpfunc(PyObject *self, PyObject *args, void *wrapped)
return
PyInt_FromLong
((
long
)
res
);
}
/* Helper to check for object.__setattr__ or __delattr__ applied to a type.
This is called the Verre Carlo hack after its discoverer. */
static
int
hackcheck
(
PyObject
*
self
,
setattrofunc
func
,
char
*
what
)
{
PyTypeObject
*
type
=
self
->
ob_type
;
while
(
type
&&
type
->
tp_flags
&
Py_TPFLAGS_HEAPTYPE
)
type
=
type
->
tp_base
;
if
(
type
->
tp_setattro
!=
func
)
{
PyErr_Format
(
PyExc_TypeError
,
"can't apply this %s to %s object"
,
what
,
type
->
tp_name
);
return
0
;
}
return
1
;
}
static
PyObject
*
wrap_setattr
(
PyObject
*
self
,
PyObject
*
args
,
void
*
wrapped
)
{
...
...
@@ -3583,6 +3601,8 @@ wrap_setattr(PyObject *self, PyObject *args, void *wrapped)
if
(
!
PyArg_ParseTuple
(
args
,
"OO"
,
&
name
,
&
value
))
return
NULL
;
if
(
!
hackcheck
(
self
,
func
,
"__setattr__"
))
return
NULL
;
res
=
(
*
func
)(
self
,
name
,
value
);
if
(
res
<
0
)
return
NULL
;
...
...
@@ -3599,6 +3619,8 @@ wrap_delattr(PyObject *self, PyObject *args, void *wrapped)
if
(
!
PyArg_ParseTuple
(
args
,
"O"
,
&
name
))
return
NULL
;
if
(
!
hackcheck
(
self
,
func
,
"__delattr__"
))
return
NULL
;
res
=
(
*
func
)(
self
,
name
,
NULL
);
if
(
res
<
0
)
return
NULL
;
...
...
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