[pypy-commit] cffi win32-stdcall: Fix test
arigo
noreply at buildbot.pypy.org
Tue Oct 6 11:00:00 CEST 2015
Author: Armin Rigo <arigo at tunes.org>
Branch: win32-stdcall
Changeset: r2313:af9fbe2cfe29
Date: 2015-10-06 10:48 +0200
http://bitbucket.org/cffi/cffi/changeset/af9fbe2cfe29/
Log: Fix test
diff --git a/testing/cffi0/test_verify.py b/testing/cffi0/test_verify.py
--- a/testing/cffi0/test_verify.py
+++ b/testing/cffi0/test_verify.py
@@ -2257,9 +2257,9 @@
int __stdcall cb2(int x) { return x * 3; }
int __cdecl call1(int(__cdecl *cb)(int)) {
+ int i, result = 0;
printf("here1\n");
printf("cb = %p, cb1 = %p\n", cb, (void *)cb1);
- int i, result = 0;
for (i = 0; i < 1000; i++)
result += cb(i);
printf("result = %d\n", result);
@@ -2286,9 +2286,13 @@
# automatically corrected. But this does not apply to the 'cb'
# function pointer argument.
ffi = FFI()
- ffi.cdef("int __stdcall call1(int(*cb)(int)); int cb1(int);")
- ffi.cdef("int call2(int(__stdcall *cb)(int)); int __stdcall cb2(int);")
- lib = verify(ffi, 'test_win32_calling_convention_2', """
+ ffi.cdef("""
+ int __stdcall call1(int(__cdecl *cb)(int));
+ int __cdecl call2(int(__stdcall *cb)(int));
+ int (__cdecl *const cb1)(int);
+ int (__stdcall *const cb2)(int);
+ """)
+ lib = ffi.verify(r"""
int __cdecl call1(int(__cdecl *cb)(int)) {
int i, result = 0;
for (i = 0; i < 1000; i++)
@@ -2301,33 +2305,31 @@
result += cb(-i);
return result;
}
- int __stdcall cb1(int x) { return x * 2; }
- int __cdecl cb2(int x) { return x * 3; }
+ int __cdecl cb1(int x) { return x * 2; }
+ int __stdcall cb2(int x) { return x * 3; }
""")
- ptr_call1 = ffi.addressof(lib, 'call1')
- ptr_call2 = ffi.addressof(lib, 'call2')
- py.test.raises(TypeError, lib.call1, ffi.addressof(lib, 'cb2'))
- py.test.raises(TypeError, ptr_call1, ffi.addressof(lib, 'cb2'))
- py.test.raises(TypeError, lib.call2, ffi.addressof(lib, 'cb1'))
- py.test.raises(TypeError, ptr_call2, ffi.addressof(lib, 'cb1'))
- assert lib.call1(ffi.addressof(lib, 'cb1')) == 500*999*2
- assert ptr_call1(ffi.addressof(lib, 'cb1')) == 500*999*2
- assert lib.call2(ffi.addressof(lib, 'cb2')) == -500*999*3
- assert ptr_call2(ffi.addressof(lib, 'cb2')) == -500*999*3
+ py.test.raises(TypeError, lib.call1, lib.cb2)
+ py.test.raises(TypeError, lib.call2, lib.cb1)
+ assert lib.call1(lib.cb1) == 500*999*2
+ assert lib.call2(lib.cb2) == -500*999*3
def test_win32_calling_convention_3():
if sys.platform != 'win32':
py.test.skip("Windows only")
ffi = FFI()
- ffi.cdef("struct point { int x, y; };")
- ffi.cdef("struct point __stdcall call1(int(*__cdecl cb)(struct point)); "
- "int cb1(struct point);", calling_conv="cdecl")
- ffi.cdef("struct point call2(int(*cb)(struct point)); "
- "int cb2(struct point);", calling_conv="stdcall")
- lib = verify(ffi, 'test_win32_calling_convention_3', r"""
+ ffi.cdef("""
struct point { int x, y; };
- int __stdcall cb1(struct point pt) { return pt.x + 10 * pt.y; }
- int __cdecl cb2(struct point pt) { return pt.x + 100 * pt.y; }
+
+ int (*const cb1)(struct point);
+ int (__stdcall *const cb2)(struct point);
+
+ struct point __stdcall call1(int(*cb)(struct point));
+ struct point call2(int(__stdcall *cb)(struct point));
+ """)
+ lib = ffi.verify(r"""
+ struct point { int x, y; };
+ int cb1(struct point pt) { return pt.x + 10 * pt.y; }
+ int __stdcall cb2(struct point pt) { return pt.x + 100 * pt.y; }
struct point __stdcall call1(int(__cdecl *cb)(struct point)) {
int i;
struct point result = { 0, 0 };
@@ -2353,18 +2355,9 @@
return result;
}
""")
- ptr_call1 = ffi.addressof(lib, 'call1')
- ptr_call2 = ffi.addressof(lib, 'call2')
- py.test.raises(TypeError, lib.call1, ffi.addressof(lib, 'cb2'))
- py.test.raises(TypeError, ptr_call1, ffi.addressof(lib, 'cb2'))
- py.test.raises(TypeError, lib.call2, ffi.addressof(lib, 'cb1'))
- py.test.raises(TypeError, ptr_call2, ffi.addressof(lib, 'cb1'))
- print '<<< cb1 =', ffi.addressof(lib, 'cb1')
- pt = lib.call1(ffi.addressof(lib, 'cb1'))
+ py.test.raises(TypeError, lib.call1, lib.cb2)
+ py.test.raises(TypeError, lib.call2, lib.cb1)
+ pt = lib.call1(lib.cb1)
assert (pt.x, pt.y) == (-9*500*999, 9*500*999)
- pt = ptr_call1(ffi.addressof(lib, 'cb1'))
- assert (pt.x, pt.y) == (-9*500*999, 9*500*999)
- pt = lib.call2(ffi.addressof(lib, 'cb2'))
+ pt = lib.call2(lib.cb2)
assert (pt.x, pt.y) == (99*500*999, -99*500*999)
- pt = ptr_call2(ffi.addressof(lib, 'cb2'))
- assert (pt.x, pt.y) == (99*500*999, -99*500*999)
More information about the pypy-commit
mailing list