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
d59ca8f3
Kaydet (Commit)
d59ca8f3
authored
Mar 20, 2006
tarafından
Thomas Heller
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Accessing unaligned structure fields works now on all architectures.
Including unittest.
üst
6c2f9138
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
88 additions
and
38 deletions
+88
-38
test_byteswap.py
Lib/ctypes/test/test_byteswap.py
+43
-38
test_unaligned_structures.py
Lib/ctypes/test/test_unaligned_structures.py
+45
-0
cfield.c
Modules/_ctypes/cfield.c
+0
-0
No files found.
Lib/ctypes/test/test_byteswap.py
Dosyayı görüntüle @
d59ca8f3
...
@@ -2,7 +2,6 @@ import sys, unittest, struct, math
...
@@ -2,7 +2,6 @@ import sys, unittest, struct, math
from
binascii
import
hexlify
from
binascii
import
hexlify
from
ctypes
import
*
from
ctypes
import
*
from
ctypes.test
import
is_resource_enabled
def
bin
(
s
):
def
bin
(
s
):
return
hexlify
(
buffer
(
s
))
.
upper
()
return
hexlify
(
buffer
(
s
))
.
upper
()
...
@@ -222,54 +221,60 @@ class Test(unittest.TestCase):
...
@@ -222,54 +221,60 @@ class Test(unittest.TestCase):
s2
=
struct
.
pack
(
fmt
,
0x12
,
0x1234
,
0x12345678
,
3.14
)
s2
=
struct
.
pack
(
fmt
,
0x12
,
0x1234
,
0x12345678
,
3.14
)
self
.
failUnlessEqual
(
bin
(
s1
),
bin
(
s2
))
self
.
failUnlessEqual
(
bin
(
s1
),
bin
(
s2
))
if
is_resource_enabled
(
"unaligned_access"
):
def
test_unaligned_nonnative_struct_fields
(
self
):
if
sys
.
byteorder
==
"little"
:
def
test_unaligned_nonnative_struct_fields
(
self
):
base
=
BigEndianStructure
if
sys
.
byteorder
==
"little"
:
fmt
=
">b h xi xd"
base
=
BigEndianStructure
else
:
fmt
=
">b h xi xd"
base
=
LittleEndianStructure
else
:
fmt
=
"<b h xi xd"
base
=
LittleEndianStructure
fmt
=
"<b h xi xd"
class
S
(
base
):
class
S
(
base
):
_pack_
=
1
_pack_
=
1
_fields_
=
[(
"b"
,
c_byte
),
_fields_
=
[(
"b"
,
c_byte
),
(
"h"
,
c_short
),
(
"h"
,
c_short
),
(
"_1"
,
c_byte
),
(
"_1"
,
c_byte
),
(
"i"
,
c_int
),
(
"i"
,
c_int
),
(
"_2"
,
c_byte
),
(
"_2"
,
c_byte
),
(
"d"
,
c_double
)]
(
"d"
,
c_double
)]
s1
=
S
(
0x12
,
0x1234
,
0
,
0x12345678
,
0
,
3.14
)
s1
=
S
()
s2
=
struct
.
pack
(
fmt
,
0x12
,
0x1234
,
0x12345678
,
3.14
)
s1
.
b
=
0x12
self
.
failUnlessEqual
(
bin
(
s1
),
bin
(
s2
))
s1
.
h
=
0x1234
s1
.
i
=
0x12345678
s1
.
d
=
3.14
s2
=
struct
.
pack
(
fmt
,
0x12
,
0x1234
,
0x12345678
,
3.14
)
self
.
failUnlessEqual
(
bin
(
s1
),
bin
(
s2
))
def
test_unaligned_native_struct_fields
(
self
):
def
test_unaligned_native_struct_fields
(
self
):
if
sys
.
byteorder
==
"little"
:
if
sys
.
byteorder
==
"little"
:
fmt
=
"<b h xi xd"
fmt
=
"<b h xi xd"
else
:
else
:
base
=
LittleEndianStructure
base
=
LittleEndianStructure
fmt
=
">b h xi xd"
fmt
=
">b h xi xd"
class
S
(
Structure
):
class
S
(
Structure
):
_pack_
=
1
_pack_
=
1
_fields_
=
[(
"b"
,
c_byte
),
_fields_
=
[(
"b"
,
c_byte
),
(
"h"
,
c_short
),
(
"h"
,
c_short
),
(
"_1"
,
c_byte
),
(
"_1"
,
c_byte
),
(
"i"
,
c_int
),
(
"i"
,
c_int
),
(
"_2"
,
c_byte
),
(
"_2"
,
c_byte
),
(
"d"
,
c_double
)]
(
"d"
,
c_double
)]
s1
=
S
(
0x12
,
0x1234
,
0
,
0x12345678
,
0
,
3.14
)
s1
=
S
()
s2
=
struct
.
pack
(
fmt
,
0x12
,
0x1234
,
0x12345678
,
3.14
)
s1
.
b
=
0x12
self
.
failUnlessEqual
(
bin
(
s1
),
bin
(
s2
))
s1
.
h
=
0x1234
s1
.
i
=
0x12345678
s1
.
d
=
3.14
s2
=
struct
.
pack
(
fmt
,
0x12
,
0x1234
,
0x12345678
,
3.14
)
self
.
failUnlessEqual
(
bin
(
s1
),
bin
(
s2
))
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
unittest
.
main
()
unittest
.
main
()
Lib/ctypes/test/test_unaligned_structures.py
0 → 100644
Dosyayı görüntüle @
d59ca8f3
import
sys
,
unittest
from
ctypes
import
*
structures
=
[]
byteswapped_structures
=
[]
if
sys
.
byteorder
==
"little"
:
SwappedStructure
=
BigEndianStructure
else
:
SwappedStructure
=
LittleEndianStructure
for
typ
in
[
c_short
,
c_int
,
c_long
,
c_longlong
,
c_float
,
c_double
,
c_ushort
,
c_uint
,
c_ulong
,
c_ulonglong
]:
class
X
(
Structure
):
_pack_
=
1
_fields_
=
[(
"pad"
,
c_byte
),
(
"value"
,
typ
)]
class
Y
(
SwappedStructure
):
_pack_
=
1
_fields_
=
[(
"pad"
,
c_byte
),
(
"value"
,
typ
)]
structures
.
append
(
X
)
byteswapped_structures
.
append
(
Y
)
class
TestStructures
(
unittest
.
TestCase
):
def
test_native
(
self
):
for
typ
in
structures
:
## print typ.value
self
.
failUnlessEqual
(
typ
.
value
.
offset
,
1
)
o
=
typ
()
o
.
value
=
4
self
.
failUnlessEqual
(
o
.
value
,
4
)
def
test_swapped
(
self
):
for
typ
in
byteswapped_structures
:
## print >> sys.stderr, typ.value
self
.
failUnlessEqual
(
typ
.
value
.
offset
,
1
)
o
=
typ
()
o
.
value
=
4
self
.
failUnlessEqual
(
o
.
value
,
4
)
if
__name__
==
'__main__'
:
unittest
.
main
()
Modules/_ctypes/cfield.c
Dosyayı görüntüle @
d59ca8f3
This diff is collapsed.
Click to expand it.
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