summaryrefslogtreecommitdiffstats
path: root/Modules/_ctypes
diff options
context:
space:
mode:
authorVinay Sajip <vinay_sajip@yahoo.co.uk>2016-08-05 20:24:27 (GMT)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>2016-08-05 20:24:27 (GMT)
commit6f25003291610fd7696aa09b725742a499d6b2cf (patch)
tree22c0152c8e156f2ea2e6df4dd331388be042083c /Modules/_ctypes
parentfb7929044af4a8560e0da8f88905f4617b9042f5 (diff)
downloadcpython-6f25003291610fd7696aa09b725742a499d6b2cf.zip
cpython-6f25003291610fd7696aa09b725742a499d6b2cf.tar.gz
cpython-6f25003291610fd7696aa09b725742a499d6b2cf.tar.bz2
Issue #20160: Handled passing of large structs to callbacks correctly.
Diffstat (limited to 'Modules/_ctypes')
-rw-r--r--Modules/_ctypes/_ctypes_test.c18
-rw-r--r--Modules/_ctypes/libffi_msvc/ffi.c14
2 files changed, 30 insertions, 2 deletions
diff --git a/Modules/_ctypes/_ctypes_test.c b/Modules/_ctypes/_ctypes_test.c
index 3a6845f..a273ee7 100644
--- a/Modules/_ctypes/_ctypes_test.c
+++ b/Modules/_ctypes/_ctypes_test.c
@@ -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);
}
+/*
+ * 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])
{
printf("testfunc_array %d %d %d %d\n",
diff --git a/Modules/_ctypes/libffi_msvc/ffi.c b/Modules/_ctypes/libffi_msvc/ffi.c
index 6e595e9..00ef97f 100644
--- a/Modules/_ctypes/libffi_msvc/ffi.c
+++ b/Modules/_ctypes/libffi_msvc/ffi.c
@@ -340,7 +340,7 @@ ffi_prep_incoming_args_SYSV(char *stack, void **rvalue,
if ( cif->rtype->type == FFI_TYPE_STRUCT ) {
*rvalue = *(void **) argp;
- argp += 4;
+ argp += sizeof(void *);
}
p_argv = avalue;
@@ -351,13 +351,23 @@ ffi_prep_incoming_args_SYSV(char *stack, void **rvalue,
/* Align if necessary */
if ((sizeof(char *) - 1) & (size_t) argp) {
- argp = (char *) ALIGN(argp, sizeof(char*));
+ argp = (char *) ALIGN(argp, sizeof(char*));
}
z = (*p_arg)->size;
/* 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++;