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
9ba3aa4d
Kaydet (Commit)
9ba3aa4d
authored
Haz 07, 2017
tarafından
Erik Bray
Kaydeden (comit)
Vinay Sajip
Haz 07, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
bpo-30353: Fix pass by value for structs on 64-bit Cygwin/MinGW (GH-1559)
üst
897bba75
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
65 additions
and
2 deletions
+65
-2
test_as_parameter.py
Lib/ctypes/test/test_as_parameter.py
+4
-0
test_structures.py
Lib/ctypes/test/test_structures.py
+22
-0
_ctypes_test.c
Modules/_ctypes/_ctypes_test.c
+18
-0
callproc.c
Modules/_ctypes/callproc.c
+21
-2
No files found.
Lib/ctypes/test/test_as_parameter.py
Dosyayı görüntüle @
9ba3aa4d
...
...
@@ -169,6 +169,10 @@ class BasicWrapTestCase(unittest.TestCase):
s2h
=
dll
.
ret_2h_func
(
self
.
wrap
(
inp
))
self
.
assertEqual
((
s2h
.
x
,
s2h
.
y
),
(
99
*
2
,
88
*
3
))
# Test also that the original struct was unmodified (i.e. was passed by
# value)
self
.
assertEqual
((
inp
.
x
,
inp
.
y
),
(
99
,
88
))
def
test_struct_return_8H
(
self
):
class
S8I
(
Structure
):
_fields_
=
[(
"a"
,
c_int
),
...
...
Lib/ctypes/test/test_structures.py
Dosyayı görüntüle @
9ba3aa4d
...
...
@@ -417,6 +417,28 @@ class StructureTestCase(unittest.TestCase):
self
.
assertEqual
(
s
.
second
,
0xcafebabe
)
self
.
assertEqual
(
s
.
third
,
0x0bad1dea
)
def
test_pass_by_value_in_register
(
self
):
class
X
(
Structure
):
_fields_
=
[
(
'first'
,
c_uint
),
(
'second'
,
c_uint
)
]
s
=
X
()
s
.
first
=
0xdeadbeef
s
.
second
=
0xcafebabe
dll
=
CDLL
(
_ctypes_test
.
__file__
)
func
=
dll
.
_testfunc_reg_struct_update_value
func
.
argtypes
=
(
X
,)
func
.
restype
=
None
func
(
s
)
self
.
assertEqual
(
s
.
first
,
0xdeadbeef
)
self
.
assertEqual
(
s
.
second
,
0xcafebabe
)
got
=
X
.
in_dll
(
dll
,
"last_tfrsuv_arg"
)
self
.
assertEqual
(
s
.
first
,
got
.
first
)
self
.
assertEqual
(
s
.
second
,
got
.
second
)
class
PointerMemberTestCase
(
unittest
.
TestCase
):
def
test
(
self
):
...
...
Modules/_ctypes/_ctypes_test.c
Dosyayı görüntüle @
9ba3aa4d
...
...
@@ -57,6 +57,24 @@ _testfunc_large_struct_update_value(Test in)
((
volatile
Test
*
)
&
in
)
->
third
=
0x0badf00d
;
}
typedef
struct
{
unsigned
int
first
;
unsigned
int
second
;
}
TestReg
;
EXPORT
(
TestReg
)
last_tfrsuv_arg
;
EXPORT
(
void
)
_testfunc_reg_struct_update_value
(
TestReg
in
)
{
last_tfrsuv_arg
=
in
;
((
volatile
TestReg
*
)
&
in
)
->
first
=
0x0badf00d
;
((
volatile
TestReg
*
)
&
in
)
->
second
=
0x0badf00d
;
}
EXPORT
(
void
)
testfunc_array
(
int
values
[
4
])
{
printf
(
"testfunc_array %d %d %d %d
\n
"
,
...
...
Modules/_ctypes/callproc.c
Dosyayı görüntüle @
9ba3aa4d
...
...
@@ -1039,6 +1039,13 @@ GetComError(HRESULT errcode, GUID *riid, IUnknown *pIunk)
}
#endif
#if (defined(__x86_64__) && (defined(__MINGW64__) || defined(__CYGWIN__))) || \
defined(__aarch64__)
#define CTYPES_PASS_BY_REF_HACK
#define POW2(x) (((x & ~(x - 1)) == x) ? x : 0)
#define IS_PASS_BY_REF(x) (x > 8 || !POW2(x))
#endif
/*
* Requirements, must be ensured by the caller:
* - argtuple is tuple of arguments
...
...
@@ -1136,8 +1143,20 @@ PyObject *_ctypes_callproc(PPROC pProc,
}
for
(
i
=
0
;
i
<
argcount
;
++
i
)
{
atypes
[
i
]
=
args
[
i
].
ffi_type
;
if
(
atypes
[
i
]
->
type
==
FFI_TYPE_STRUCT
)
#ifdef CTYPES_PASS_BY_REF_HACK
size_t
size
=
atypes
[
i
]
->
size
;
if
(
IS_PASS_BY_REF
(
size
))
{
void
*
tmp
=
alloca
(
size
);
if
(
atypes
[
i
]
->
type
==
FFI_TYPE_STRUCT
)
memcpy
(
tmp
,
args
[
i
].
value
.
p
,
size
);
else
memcpy
(
tmp
,
(
void
*
)
&
args
[
i
].
value
,
size
);
avalues
[
i
]
=
tmp
;
}
else
#endif
if
(
atypes
[
i
]
->
type
==
FFI_TYPE_STRUCT
)
avalues
[
i
]
=
(
void
*
)
args
[
i
].
value
.
p
;
else
avalues
[
i
]
=
(
void
*
)
&
args
[
i
].
value
;
...
...
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