Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
554fc77b
Commit
554fc77b
authored
Aug 05, 2016
by
Vinay Sajip
Browse files
Options
Browse Files
Download
Plain Diff
Issue #20160: Merged fix from 3.3.
parents
4c437917
7d1bbaec
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
65 additions
and
2 deletions
+65
-2
Lib/ctypes/test/test_callbacks.py
Lib/ctypes/test/test_callbacks.py
+35
-0
Modules/_ctypes/_ctypes_test.c
Modules/_ctypes/_ctypes_test.c
+18
-0
Modules/_ctypes/libffi_msvc/ffi.c
Modules/_ctypes/libffi_msvc/ffi.c
+12
-2
No files found.
Lib/ctypes/test/test_callbacks.py
View file @
554fc77b
import
functools
import
unittest
import
unittest
from
ctypes
import
*
from
ctypes
import
*
from
ctypes.test
import
need_symbol
from
ctypes.test
import
need_symbol
...
@@ -240,6 +241,40 @@ class SampleCallbacksTestCase(unittest.TestCase):
...
@@ -240,6 +241,40 @@ class SampleCallbacksTestCase(unittest.TestCase):
self
.
assertEqual
(
result
,
self
.
assertEqual
(
result
,
callback
(
1.1
*
1.1
,
2.2
*
2.2
,
3.3
*
3.3
,
4.4
*
4.4
,
5.5
*
5.5
))
callback
(
1.1
*
1.1
,
2.2
*
2.2
,
3.3
*
3.3
,
4.4
*
4.4
,
5.5
*
5.5
))
def
test_callback_large_struct
(
self
):
class
Check
:
pass
class
X
(
Structure
):
_fields_
=
[
(
'first'
,
c_ulong
),
(
'second'
,
c_ulong
),
(
'third'
,
c_ulong
),
]
def
callback
(
check
,
s
):
check
.
first
=
s
.
first
check
.
second
=
s
.
second
check
.
third
=
s
.
third
check
=
Check
()
s
=
X
()
s
.
first
=
0xdeadbeef
s
.
second
=
0xcafebabe
s
.
third
=
0x0bad1dea
CALLBACK
=
CFUNCTYPE
(
None
,
X
)
dll
=
CDLL
(
_ctypes_test
.
__file__
)
func
=
dll
.
_testfunc_cbk_large_struct
func
.
argtypes
=
(
X
,
CALLBACK
)
func
.
restype
=
None
# the function just calls the callback with the passed structure
func
(
s
,
CALLBACK
(
functools
.
partial
(
callback
,
check
)))
self
.
assertEqual
(
check
.
first
,
s
.
first
)
self
.
assertEqual
(
check
.
second
,
s
.
second
)
self
.
assertEqual
(
check
.
third
,
s
.
third
)
self
.
assertEqual
(
check
.
first
,
0xdeadbeef
)
self
.
assertEqual
(
check
.
second
,
0xcafebabe
)
self
.
assertEqual
(
check
.
third
,
0x0bad1dea
)
################################################################
################################################################
...
...
Modules/_ctypes/_ctypes_test.c
View file @
554fc77b
...
@@ -26,6 +26,24 @@ _testfunc_cbk_reg_double(double a, double b, double c, double d, double e,
...
@@ -26,6 +26,24 @@ _testfunc_cbk_reg_double(double a, double b, double c, double d, double e,
return
func
(
a
*
a
,
b
*
b
,
c
*
c
,
d
*
d
,
e
*
e
);
return
func
(
a
*
a
,
b
*
b
,
c
*
c
,
d
*
d
,
e
*
e
);
}
}
/*
* This structure should be the same as in test_callbacks.py and the
* method test_callback_large_struct. See issues 17310 and 20160: the
* structure must be larger than 8 bytes long.
*/
typedef
struct
{
unsigned
long
first
;
unsigned
long
second
;
unsigned
long
third
;
}
Test
;
EXPORT
(
void
)
_testfunc_cbk_large_struct
(
Test
in
,
void
(
*
func
)(
Test
))
{
func
(
in
);
}
EXPORT
(
void
)
testfunc_array
(
int
values
[
4
])
EXPORT
(
void
)
testfunc_array
(
int
values
[
4
])
{
{
printf
(
"testfunc_array %d %d %d %d
\n
"
,
printf
(
"testfunc_array %d %d %d %d
\n
"
,
...
...
Modules/_ctypes/libffi_msvc/ffi.c
View file @
554fc77b
...
@@ -359,7 +359,7 @@ ffi_prep_incoming_args_SYSV(char *stack, void **rvalue,
...
@@ -359,7 +359,7 @@ ffi_prep_incoming_args_SYSV(char *stack, void **rvalue,
if
(
cif
->
rtype
->
type
==
FFI_TYPE_STRUCT
)
{
if
(
cif
->
rtype
->
type
==
FFI_TYPE_STRUCT
)
{
*
rvalue
=
*
(
void
**
)
argp
;
*
rvalue
=
*
(
void
**
)
argp
;
argp
+=
4
;
argp
+=
sizeof
(
void
*
)
;
}
}
p_argv
=
avalue
;
p_argv
=
avalue
;
...
@@ -370,13 +370,23 @@ ffi_prep_incoming_args_SYSV(char *stack, void **rvalue,
...
@@ -370,13 +370,23 @@ ffi_prep_incoming_args_SYSV(char *stack, void **rvalue,
/* Align if necessary */
/* Align if necessary */
if
((
sizeof
(
char
*
)
-
1
)
&
(
size_t
)
argp
)
{
if
((
sizeof
(
char
*
)
-
1
)
&
(
size_t
)
argp
)
{
argp
=
(
char
*
)
ALIGN
(
argp
,
sizeof
(
char
*
));
argp
=
(
char
*
)
ALIGN
(
argp
,
sizeof
(
char
*
));
}
}
z
=
(
*
p_arg
)
->
size
;
z
=
(
*
p_arg
)
->
size
;
/* because we're little endian, this is what it turns into. */
/* because we're little endian, this is what it turns into. */
#ifdef _WIN64
if
(
z
>
8
)
{
/* On Win64, if a single argument takes more than 8 bytes,
* then it is always passed by reference.
*/
*
p_argv
=
*
((
void
**
)
argp
);
z
=
8
;
}
else
#endif
*
p_argv
=
(
void
*
)
argp
;
*
p_argv
=
(
void
*
)
argp
;
p_argv
++
;
p_argv
++
;
...
...
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