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
02ec289f
Kaydet (Commit)
02ec289f
authored
Ock 16, 2008
tarafından
Thomas Heller
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Raise a TypeError if conflicting positional and named arguments are
passed to a Structure or Union constructor.
üst
902d3075
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
0 deletions
+27
-0
test_structures.py
Lib/ctypes/test/test_structures.py
+9
-0
NEWS
Misc/NEWS
+3
-0
_ctypes.c
Modules/_ctypes/_ctypes.c
+15
-0
No files found.
Lib/ctypes/test/test_structures.py
Dosyayı görüntüle @
02ec289f
...
...
@@ -215,6 +215,15 @@ class StructureTestCase(unittest.TestCase):
# too long
self
.
assertRaises
(
ValueError
,
Person
,
"1234567"
,
5
)
def
test_conflicting_initializers
(
self
):
class
POINT
(
Structure
):
_fields_
=
[(
"x"
,
c_int
),
(
"y"
,
c_int
)]
# conflicting positional and keyword args
self
.
assertRaises
(
TypeError
,
POINT
,
2
,
3
,
x
=
4
)
self
.
assertRaises
(
TypeError
,
POINT
,
2
,
3
,
y
=
4
)
# Should this raise TypeError instead?
self
.
assertRaises
(
ValueError
,
POINT
,
2
,
3
,
4
)
def
test_keyword_initializers
(
self
):
class
POINT
(
Structure
):
...
...
Misc/NEWS
Dosyayı görüntüle @
02ec289f
...
...
@@ -364,6 +364,9 @@ Core and builtins
Library
-------
- Issue #1831: ctypes now raises a TypeError if conflicting positional
and named arguments are passed to a Structure or Union initializer.
- Convert the internal ctypes array type cache to a WeakValueDict so
that array types do not live longer than needed.
...
...
Modules/_ctypes/_ctypes.c
Dosyayı görüntüle @
02ec289f
...
...
@@ -3578,6 +3578,21 @@ Struct_init(PyObject *self, PyObject *args, PyObject *kwds)
return
IBUG
(
"_fields_[i][0] failed"
);
}
if
(
kwds
&&
PyDict_GetItem
(
kwds
,
name
))
{
char
*
field
=
PyString_AsString
(
name
);
if
(
field
==
NULL
)
{
PyErr_Clear
();
field
=
"???"
;
}
PyErr_Format
(
PyExc_TypeError
,
"duplicate values for field %s"
,
field
);
Py_DECREF
(
pair
);
Py_DECREF
(
name
);
Py_DECREF
(
fields
);
return
-
1
;
}
val
=
PyTuple_GET_ITEM
(
args
,
i
);
if
(
-
1
==
PyObject_SetAttr
(
self
,
name
,
val
))
{
Py_DECREF
(
pair
);
...
...
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