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
f3c0559b
Kaydet (Commit)
f3c0559b
authored
Mar 05, 2008
tarafından
Thomas Heller
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue 1872: Changed the struct module typecode from 't' to '?', for
compatibility with PEP3118.
üst
78b8f445
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
41 additions
and
29 deletions
+41
-29
struct.rst
Doc/library/struct.rst
+3
-3
__init__.py
Lib/ctypes/__init__.py
+1
-1
test_struct.py
Lib/test/test_struct.py
+14
-14
NEWS
Misc/NEWS
+3
-0
_ctypes.c
Modules/_ctypes/_ctypes.c
+1
-1
_ctypes_test.c
Modules/_ctypes/_ctypes_test.c
+9
-0
cfield.c
Modules/_ctypes/cfield.c
+7
-7
_struct.c
Modules/_struct.c
+3
-3
No files found.
Doc/library/struct.rst
Dosyayı görüntüle @
f3c0559b
...
@@ -77,7 +77,7 @@ Python values should be obvious given their types:
...
@@ -77,7 +77,7 @@ Python values should be obvious given their types:
+--------+-------------------------+--------------------+-------+
+--------+-------------------------+--------------------+-------+
| ``B`` | :ctype:`unsigned char` | integer | |
| ``B`` | :ctype:`unsigned char` | integer | |
+--------+-------------------------+--------------------+-------+
+--------+-------------------------+--------------------+-------+
| ``
t
`` | :ctype:`_Bool` | bool | \(1) |
| ``
?
`` | :ctype:`_Bool` | bool | \(1) |
+--------+-------------------------+--------------------+-------+
+--------+-------------------------+--------------------+-------+
| ``h`` | :ctype:`short` | integer | |
| ``h`` | :ctype:`short` | integer | |
+--------+-------------------------+--------------------+-------+
+--------+-------------------------+--------------------+-------+
...
@@ -110,7 +110,7 @@ Python values should be obvious given their types:
...
@@ -110,7 +110,7 @@ Python values should be obvious given their types:
Notes:
Notes:
(1)
(1)
The ``'
t
'`` conversion code corresponds to the :ctype:`_Bool` type defined by
The ``'
?
'`` conversion code corresponds to the :ctype:`_Bool` type defined by
C99. If this type is not available, it is simulated using a :ctype:`char`. In
C99. If this type is not available, it is simulated using a :ctype:`char`. In
standard mode, it is always represented by one byte.
standard mode, it is always represented by one byte.
...
@@ -158,7 +158,7 @@ may be used. For example, the Alpha and Merced processors use 64-bit pointer
...
@@ -158,7 +158,7 @@ may be used. For example, the Alpha and Merced processors use 64-bit pointer
values, meaning a Python long integer will be used to hold the pointer; other
values, meaning a Python long integer will be used to hold the pointer; other
platforms use 32-bit pointers and will use a Python integer.
platforms use 32-bit pointers and will use a Python integer.
For the ``'
t
'`` format character, the return value is either :const:`True` or
For the ``'
?
'`` format character, the return value is either :const:`True` or
:const:`False`. When packing, the truth value of the argument object is used.
:const:`False`. When packing, the truth value of the argument object is used.
Either 0 or 1 in the native or standard bool representation will be packed, and
Either 0 or 1 in the native or standard bool representation will be packed, and
any non-zero value will be True when unpacking.
any non-zero value will be True when unpacking.
...
...
Lib/ctypes/__init__.py
Dosyayı görüntüle @
f3c0559b
...
@@ -240,7 +240,7 @@ c_voidp = c_void_p # backwards compatibility (to a bug)
...
@@ -240,7 +240,7 @@ c_voidp = c_void_p # backwards compatibility (to a bug)
_check_size
(
c_void_p
)
_check_size
(
c_void_p
)
class
c_bool
(
_SimpleCData
):
class
c_bool
(
_SimpleCData
):
_type_
=
"
t
"
_type_
=
"
?
"
# This cache maps types to pointers to them.
# This cache maps types to pointers to them.
_pointer_type_cache
=
{}
_pointer_type_cache
=
{}
...
...
Lib/test/test_struct.py
Dosyayı görüntüle @
f3c0559b
...
@@ -84,8 +84,8 @@ sz = struct.calcsize('i')
...
@@ -84,8 +84,8 @@ sz = struct.calcsize('i')
if
sz
*
3
!=
struct
.
calcsize
(
'iii'
):
if
sz
*
3
!=
struct
.
calcsize
(
'iii'
):
raise
TestFailed
,
'inconsistent sizes'
raise
TestFailed
,
'inconsistent sizes'
fmt
=
'cbxxxxxxhhhhiillffd
t
'
fmt
=
'cbxxxxxxhhhhiillffd
?
'
fmt3
=
'3c3b18x12h6i6l6f3d3
t
'
fmt3
=
'3c3b18x12h6i6l6f3d3
?
'
sz
=
struct
.
calcsize
(
fmt
)
sz
=
struct
.
calcsize
(
fmt
)
sz3
=
struct
.
calcsize
(
fmt3
)
sz3
=
struct
.
calcsize
(
fmt3
)
if
sz
*
3
!=
sz3
:
if
sz
*
3
!=
sz3
:
...
@@ -111,7 +111,7 @@ d = 3.1415
...
@@ -111,7 +111,7 @@ d = 3.1415
t
=
True
t
=
True
for
prefix
in
(
''
,
'@'
,
'<'
,
'>'
,
'='
,
'!'
):
for
prefix
in
(
''
,
'@'
,
'<'
,
'>'
,
'='
,
'!'
):
for
format
in
(
'xcbhilfd
t'
,
'xcBHILfdt
'
):
for
format
in
(
'xcbhilfd
?'
,
'xcBHILfd?
'
):
format
=
prefix
+
format
format
=
prefix
+
format
if
verbose
:
if
verbose
:
print
"trying:"
,
format
print
"trying:"
,
format
...
@@ -160,11 +160,11 @@ tests = [
...
@@ -160,11 +160,11 @@ tests = [
(
'f'
,
-
2.0
,
'
\300\000\000\000
'
,
'
\000\000\000\300
'
,
0
),
(
'f'
,
-
2.0
,
'
\300\000\000\000
'
,
'
\000\000\000\300
'
,
0
),
(
'd'
,
-
2.0
,
'
\300\000\000\000\000\000\000\000
'
,
(
'd'
,
-
2.0
,
'
\300\000\000\000\000\000\000\000
'
,
'
\000\000\000\000\000\000\000\300
'
,
0
),
'
\000\000\000\000\000\000\000\300
'
,
0
),
(
'
t
'
,
0
,
'
\0
'
,
'
\0
'
,
0
),
(
'
?
'
,
0
,
'
\0
'
,
'
\0
'
,
0
),
(
'
t
'
,
3
,
'
\1
'
,
'
\1
'
,
1
),
(
'
?
'
,
3
,
'
\1
'
,
'
\1
'
,
1
),
(
'
t
'
,
True
,
'
\1
'
,
'
\1
'
,
0
),
(
'
?
'
,
True
,
'
\1
'
,
'
\1
'
,
0
),
(
'
t
'
,
[],
'
\0
'
,
'
\0
'
,
1
),
(
'
?
'
,
[],
'
\0
'
,
'
\0
'
,
1
),
(
'
t
'
,
(
1
,),
'
\1
'
,
'
\1
'
,
1
),
(
'
?
'
,
(
1
,),
'
\1
'
,
'
\1
'
,
1
),
]
]
for
fmt
,
arg
,
big
,
lil
,
asy
in
tests
:
for
fmt
,
arg
,
big
,
lil
,
asy
in
tests
:
...
@@ -633,13 +633,13 @@ def test_bool():
...
@@ -633,13 +633,13 @@ def test_bool():
false
=
(),
[],
[],
''
,
0
false
=
(),
[],
[],
''
,
0
true
=
[
1
],
'test'
,
5
,
-
1
,
0xffffffff
L
+
1
,
0xffffffff
/
2
true
=
[
1
],
'test'
,
5
,
-
1
,
0xffffffff
L
+
1
,
0xffffffff
/
2
falseFormat
=
prefix
+
'
t
'
*
len
(
false
)
falseFormat
=
prefix
+
'
?
'
*
len
(
false
)
if
verbose
:
if
verbose
:
print
'trying bool pack/unpack on'
,
false
,
'using format'
,
falseFormat
print
'trying bool pack/unpack on'
,
false
,
'using format'
,
falseFormat
packedFalse
=
struct
.
pack
(
falseFormat
,
*
false
)
packedFalse
=
struct
.
pack
(
falseFormat
,
*
false
)
unpackedFalse
=
struct
.
unpack
(
falseFormat
,
packedFalse
)
unpackedFalse
=
struct
.
unpack
(
falseFormat
,
packedFalse
)
trueFormat
=
prefix
+
'
t
'
*
len
(
true
)
trueFormat
=
prefix
+
'
?
'
*
len
(
true
)
if
verbose
:
if
verbose
:
print
'trying bool pack/unpack on'
,
true
,
'using format'
,
trueFormat
print
'trying bool pack/unpack on'
,
true
,
'using format'
,
trueFormat
packedTrue
=
struct
.
pack
(
trueFormat
,
*
true
)
packedTrue
=
struct
.
pack
(
trueFormat
,
*
true
)
...
@@ -658,10 +658,10 @@ def test_bool():
...
@@ -658,10 +658,10 @@ def test_bool():
raise
TestFailed
(
'
%
r did not unpack as false'
%
t
)
raise
TestFailed
(
'
%
r did not unpack as false'
%
t
)
if
prefix
and
verbose
:
if
prefix
and
verbose
:
print
'trying size of bool with format
%
r'
%
(
prefix
+
'
t
'
)
print
'trying size of bool with format
%
r'
%
(
prefix
+
'
?
'
)
packed
=
struct
.
pack
(
prefix
+
'
t
'
,
1
)
packed
=
struct
.
pack
(
prefix
+
'
?
'
,
1
)
if
len
(
packed
)
!=
struct
.
calcsize
(
prefix
+
'
t
'
):
if
len
(
packed
)
!=
struct
.
calcsize
(
prefix
+
'
?
'
):
raise
TestFailed
(
'packed length is not equal to calculated size'
)
raise
TestFailed
(
'packed length is not equal to calculated size'
)
if
len
(
packed
)
!=
1
and
prefix
:
if
len
(
packed
)
!=
1
and
prefix
:
...
@@ -670,7 +670,7 @@ def test_bool():
...
@@ -670,7 +670,7 @@ def test_bool():
print
'size of bool in native format is
%
i'
%
(
len
(
packed
))
print
'size of bool in native format is
%
i'
%
(
len
(
packed
))
for
c
in
'
\x01\x7f\xff\x0f\xf0
'
:
for
c
in
'
\x01\x7f\xff\x0f\xf0
'
:
if
struct
.
unpack
(
'>
t
'
,
c
)[
0
]
is
not
True
:
if
struct
.
unpack
(
'>
?
'
,
c
)[
0
]
is
not
True
:
raise
TestFailed
(
'
%
c did not unpack as True'
%
c
)
raise
TestFailed
(
'
%
c did not unpack as True'
%
c
)
test_bool
()
test_bool
()
Misc/NEWS
Dosyayı görüntüle @
f3c0559b
...
@@ -18,6 +18,9 @@ Core and builtins
...
@@ -18,6 +18,9 @@ Core and builtins
Library
Library
-------
-------
- Issue #1872: The struct module typecode for _Bool has been changed
from 't' to '?'.
- The bundled libffi copy is now in sync with the recently released
- The bundled libffi copy is now in sync with the recently released
libffi3.0.4 version, apart from some small changes to
libffi3.0.4 version, apart from some small changes to
Modules/_ctypes/libffi/configure.ac.
Modules/_ctypes/libffi/configure.ac.
...
...
Modules/_ctypes/_ctypes.c
Dosyayı görüntüle @
f3c0559b
...
@@ -1242,7 +1242,7 @@ _type_ attribute.
...
@@ -1242,7 +1242,7 @@ _type_ attribute.
*/
*/
static
char
*
SIMPLE_TYPE_CHARS
=
"cbBhHiIlLdfuzZqQPXOv
t
g"
;
static
char
*
SIMPLE_TYPE_CHARS
=
"cbBhHiIlLdfuzZqQPXOv
?
g"
;
static
PyObject
*
static
PyObject
*
c_wchar_p_from_param
(
PyObject
*
type
,
PyObject
*
value
)
c_wchar_p_from_param
(
PyObject
*
type
,
PyObject
*
value
)
...
...
Modules/_ctypes/_ctypes_test.c
Dosyayı görüntüle @
f3c0559b
...
@@ -25,6 +25,15 @@
...
@@ -25,6 +25,15 @@
/* some functions handy for testing */
/* some functions handy for testing */
EXPORT
(
void
)
testfunc_array
(
int
values
[
4
])
{
printf
(
"testfunc_array %d %d %d %d
\n
"
,
values
[
0
],
values
[
1
],
values
[
2
],
values
[
3
]);
}
EXPORT
(
long
double
)
testfunc_Ddd
(
double
a
,
double
b
)
EXPORT
(
long
double
)
testfunc_Ddd
(
double
a
,
double
b
)
{
{
long
double
result
=
(
long
double
)(
a
*
b
);
long
double
result
=
(
long
double
)(
a
*
b
);
...
...
Modules/_ctypes/cfield.c
Dosyayı görüntüle @
f3c0559b
...
@@ -726,7 +726,7 @@ vBOOL_get(void *ptr, Py_ssize_t size)
...
@@ -726,7 +726,7 @@ vBOOL_get(void *ptr, Py_ssize_t size)
#endif
#endif
static
PyObject
*
static
PyObject
*
t
_set
(
void
*
ptr
,
PyObject
*
value
,
Py_ssize_t
size
)
bool
_set
(
void
*
ptr
,
PyObject
*
value
,
Py_ssize_t
size
)
{
{
switch
(
PyObject_IsTrue
(
value
))
{
switch
(
PyObject_IsTrue
(
value
))
{
case
-
1
:
case
-
1
:
...
@@ -741,7 +741,7 @@ t_set(void *ptr, PyObject *value, Py_ssize_t size)
...
@@ -741,7 +741,7 @@ t_set(void *ptr, PyObject *value, Py_ssize_t size)
}
}
static
PyObject
*
static
PyObject
*
t
_get
(
void
*
ptr
,
Py_ssize_t
size
)
bool
_get
(
void
*
ptr
,
Py_ssize_t
size
)
{
{
return
PyBool_FromLong
((
long
)
*
(
BOOL_TYPE
*
)
ptr
);
return
PyBool_FromLong
((
long
)
*
(
BOOL_TYPE
*
)
ptr
);
}
}
...
@@ -1645,15 +1645,15 @@ static struct fielddesc formattable[] = {
...
@@ -1645,15 +1645,15 @@ static struct fielddesc formattable[] = {
{
'v'
,
vBOOL_set
,
vBOOL_get
,
&
ffi_type_sshort
},
{
'v'
,
vBOOL_set
,
vBOOL_get
,
&
ffi_type_sshort
},
#endif
#endif
#if SIZEOF__BOOL == 1
#if SIZEOF__BOOL == 1
{
'
t'
,
t_set
,
t
_get
,
&
ffi_type_uchar
},
/* Also fallback for no native _Bool support */
{
'
?'
,
bool_set
,
bool
_get
,
&
ffi_type_uchar
},
/* Also fallback for no native _Bool support */
#elif SIZEOF__BOOL == SIZEOF_SHORT
#elif SIZEOF__BOOL == SIZEOF_SHORT
{
'
t'
,
t_set
,
t
_get
,
&
ffi_type_ushort
},
{
'
?'
,
bool_set
,
bool
_get
,
&
ffi_type_ushort
},
#elif SIZEOF__BOOL == SIZEOF_INT
#elif SIZEOF__BOOL == SIZEOF_INT
{
'
t'
,
t_set
,
t
_get
,
&
ffi_type_uint
,
I_set_sw
,
I_get_sw
},
{
'
?'
,
bool_set
,
bool
_get
,
&
ffi_type_uint
,
I_set_sw
,
I_get_sw
},
#elif SIZEOF__BOOL == SIZEOF_LONG
#elif SIZEOF__BOOL == SIZEOF_LONG
{
'
t'
,
t_set
,
t
_get
,
&
ffi_type_ulong
,
L_set_sw
,
L_get_sw
},
{
'
?'
,
bool_set
,
bool
_get
,
&
ffi_type_ulong
,
L_set_sw
,
L_get_sw
},
#elif SIZEOF__BOOL == SIZEOF_LONG_LONG
#elif SIZEOF__BOOL == SIZEOF_LONG_LONG
{
'
t'
,
t_set
,
t
_get
,
&
ffi_type_ulong
,
Q_set_sw
,
Q_get_sw
},
{
'
?'
,
bool_set
,
bool
_get
,
&
ffi_type_ulong
,
Q_set_sw
,
Q_get_sw
},
#endif
/* SIZEOF__BOOL */
#endif
/* SIZEOF__BOOL */
{
'O'
,
O_set
,
O_get
,
&
ffi_type_pointer
},
{
'O'
,
O_set
,
O_get
,
&
ffi_type_pointer
},
{
0
,
NULL
,
NULL
,
NULL
},
{
0
,
NULL
,
NULL
,
NULL
},
...
...
Modules/_struct.c
Dosyayı görüntüle @
f3c0559b
...
@@ -799,7 +799,7 @@ static formatdef native_table[] = {
...
@@ -799,7 +799,7 @@ static formatdef native_table[] = {
{
'q'
,
sizeof
(
PY_LONG_LONG
),
LONG_LONG_ALIGN
,
nu_longlong
,
np_longlong
},
{
'q'
,
sizeof
(
PY_LONG_LONG
),
LONG_LONG_ALIGN
,
nu_longlong
,
np_longlong
},
{
'Q'
,
sizeof
(
PY_LONG_LONG
),
LONG_LONG_ALIGN
,
nu_ulonglong
,
np_ulonglong
},
{
'Q'
,
sizeof
(
PY_LONG_LONG
),
LONG_LONG_ALIGN
,
nu_ulonglong
,
np_ulonglong
},
#endif
#endif
{
'
t
'
,
sizeof
(
BOOL_TYPE
),
BOOL_ALIGN
,
nu_bool
,
np_bool
},
{
'
?
'
,
sizeof
(
BOOL_TYPE
),
BOOL_ALIGN
,
nu_bool
,
np_bool
},
{
'f'
,
sizeof
(
float
),
FLOAT_ALIGN
,
nu_float
,
np_float
},
{
'f'
,
sizeof
(
float
),
FLOAT_ALIGN
,
nu_float
,
np_float
},
{
'd'
,
sizeof
(
double
),
DOUBLE_ALIGN
,
nu_double
,
np_double
},
{
'd'
,
sizeof
(
double
),
DOUBLE_ALIGN
,
nu_double
,
np_double
},
{
'P'
,
sizeof
(
void
*
),
VOID_P_ALIGN
,
nu_void_p
,
np_void_p
},
{
'P'
,
sizeof
(
void
*
),
VOID_P_ALIGN
,
nu_void_p
,
np_void_p
},
...
@@ -1036,7 +1036,7 @@ static formatdef bigendian_table[] = {
...
@@ -1036,7 +1036,7 @@ static formatdef bigendian_table[] = {
{
'L'
,
4
,
0
,
bu_uint
,
bp_uint
},
{
'L'
,
4
,
0
,
bu_uint
,
bp_uint
},
{
'q'
,
8
,
0
,
bu_longlong
,
bp_longlong
},
{
'q'
,
8
,
0
,
bu_longlong
,
bp_longlong
},
{
'Q'
,
8
,
0
,
bu_ulonglong
,
bp_ulonglong
},
{
'Q'
,
8
,
0
,
bu_ulonglong
,
bp_ulonglong
},
{
'
t
'
,
1
,
0
,
bu_bool
,
bp_bool
},
{
'
?
'
,
1
,
0
,
bu_bool
,
bp_bool
},
{
'f'
,
4
,
0
,
bu_float
,
bp_float
},
{
'f'
,
4
,
0
,
bu_float
,
bp_float
},
{
'd'
,
8
,
0
,
bu_double
,
bp_double
},
{
'd'
,
8
,
0
,
bu_double
,
bp_double
},
{
0
}
{
0
}
...
@@ -1255,7 +1255,7 @@ static formatdef lilendian_table[] = {
...
@@ -1255,7 +1255,7 @@ static formatdef lilendian_table[] = {
{
'L'
,
4
,
0
,
lu_uint
,
lp_uint
},
{
'L'
,
4
,
0
,
lu_uint
,
lp_uint
},
{
'q'
,
8
,
0
,
lu_longlong
,
lp_longlong
},
{
'q'
,
8
,
0
,
lu_longlong
,
lp_longlong
},
{
'Q'
,
8
,
0
,
lu_ulonglong
,
lp_ulonglong
},
{
'Q'
,
8
,
0
,
lu_ulonglong
,
lp_ulonglong
},
{
'
t
'
,
1
,
0
,
bu_bool
,
bp_bool
},
/* Std rep not endian dep,
{
'
?
'
,
1
,
0
,
bu_bool
,
bp_bool
},
/* Std rep not endian dep,
but potentially different from native rep -- reuse bx_bool funcs. */
but potentially different from native rep -- reuse bx_bool funcs. */
{
'f'
,
4
,
0
,
lu_float
,
lp_float
},
{
'f'
,
4
,
0
,
lu_float
,
lp_float
},
{
'd'
,
8
,
0
,
lu_double
,
lp_double
},
{
'd'
,
8
,
0
,
lu_double
,
lp_double
},
...
...
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