summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--c/libffi_msvc/ffi.c5
-rw-r--r--testing/cffi1/test_function_args.py13
2 files changed, 14 insertions, 4 deletions
diff --git a/c/libffi_msvc/ffi.c b/c/libffi_msvc/ffi.c
index 8a56c87..b9e324f 100644
--- a/c/libffi_msvc/ffi.c
+++ b/c/libffi_msvc/ffi.c
@@ -451,6 +451,11 @@ ffi_prep_closure_loc (ffi_closure* closure,
|| cif->arg_types[3]->type == FFI_TYPE_DOUBLE))
mask |= 8;
+ /* if we return a non-small struct, then the first argument is a pointer
+ * to the return area, and all real arguments are shifted by one */
+ if (cif->flags == FFI_TYPE_STRUCT)
+ mask = (mask & ~8) << 1;
+
/* 41 BB ---- mov r11d,mask */
BYTES("\x41\xBB"); INT(mask);
diff --git a/testing/cffi1/test_function_args.py b/testing/cffi1/test_function_args.py
index 84c47bb..202015b 100644
--- a/testing/cffi1/test_function_args.py
+++ b/testing/cffi1/test_function_args.py
@@ -1,9 +1,10 @@
-import pytest
+import pytest, sys
try:
# comment out the following line to run this test.
# the latest on x86-64 linux: https://github.com/libffi/libffi/issues/574
- raise ImportError("this test is skipped because it keeps finding "
- "failures in libffi, instead of cffi")
+ if sys.platform != 'win32':
+ raise ImportError("this test is skipped because it keeps finding "
+ "failures in libffi, instead of cffi")
from hypothesis import given, settings, example
from hypothesis import strategies as st
@@ -120,6 +121,7 @@ else:
f.write('lib.testfargs(%s)\n' % aliststr)
f.write('ffi.addressof(lib, "testfargs")(%s)\n' % aliststr)
f.close()
+ print("checking for segfault for direct call...")
rc = subprocess.call([sys.executable, 'run1.py'], cwd=str(udir))
assert rc == 0, rc
@@ -142,6 +144,7 @@ else:
write(ffi.addressof(lib, 'testfargs_result'), returned_value)
## CALL forcing libffi
+ print("CALL forcing libffi")
received_return = ffi.addressof(lib, 'testfargs')(*passed_args)
##
@@ -183,8 +186,9 @@ else:
f.write('def callback(*args): return ffi.new("%s *")[0]\n' % result)
f.write('fptr = ffi.callback("%s(%s)", callback)\n' % (result,
','.join(args)))
- f.write('lib.testfcallback(fptr)\n')
+ f.write('print(lib.testfcallback(fptr))\n')
f.close()
+ print("checking for segfault for callback...")
rc = subprocess.call([sys.executable, 'run1.py'], cwd=str(udir))
assert rc == 0, rc
@@ -194,6 +198,7 @@ else:
return returned_value
fptr = ffi.callback("%s(%s)" % (result, ','.join(args)), callback)
+ print("CALL with callback")
received_return = lib.testfcallback(fptr)
assert len(seen_args) == 1