Author: Armin Rigo <[email protected]>
Branch: win32-stdcall
Changeset: r2312:6d47c080e372
Date: 2015-10-06 10:37 +0200
http://bitbucket.org/cffi/cffi/changeset/6d47c080e372/

Log:    start to fix tests

diff --git a/testing/cffi0/test_function.py b/testing/cffi0/test_function.py
--- a/testing/cffi0/test_function.py
+++ b/testing/cffi0/test_function.py
@@ -444,24 +444,24 @@
         #
         ffi = FFI(backend=self.Backend())
         ffi.cdef("""
-            BOOL QueryPerformanceFrequency(LONGLONG *lpFrequency);
-        """, calling_conv="cdecl")
+            BOOL __cdecl QueryPerformanceFrequency(LONGLONG *lpFrequency);
+        """)
         m = ffi.dlopen("Kernel32.dll")
         tpc = ffi.typeof(m.QueryPerformanceFrequency)
         assert tpc is tp
         #
         ffi = FFI(backend=self.Backend())
         ffi.cdef("""
-            BOOL QueryPerformanceFrequency(LONGLONG *lpFrequency);
-        """, calling_conv="stdcall")
+            BOOL WINAPI QueryPerformanceFrequency(LONGLONG *lpFrequency);
+        """)
         m = ffi.dlopen("Kernel32.dll")
         tps = ffi.typeof(m.QueryPerformanceFrequency)
         assert tps is not tpc
         assert str(tps) == "<ctype 'int(__stdcall *)(long long *)'>"
         #
         ffi = FFI(backend=self.Backend())
-        ffi.cdef("typedef int (*fnc_t)(int);", calling_conv="cdecl")
-        ffi.cdef("typedef int (*fns_t)(int);", calling_conv="stdcall")
+        ffi.cdef("typedef int (__cdecl *fnc_t)(int);")
+        ffi.cdef("typedef int (__stdcall *fns_t)(int);")
         tpc = ffi.typeof("fnc_t")
         tps = ffi.typeof("fns_t")
         assert str(tpc) == "<ctype 'int(*)(int)'>"
@@ -478,10 +478,8 @@
         if sys.platform == 'win32':
             py.test.skip("not-Windows-only test")
         ffi = FFI(backend=self.Backend())
-        ffi.cdef("""
-            int QueryPerformanceFrequency(long long *lpFrequency);
-        """, calling_conv="stdcall")
-        m = ffi.dlopen(None)
-        e = py.test.raises(CDefError, getattr, m, 'QueryPerformanceFrequency')
-        assert str(e.value) == (
-            "<int(__stdcall *)(long long *)>: '__stdcall' only for Windows")
+        ffi.cdef("double __stdcall sin(double x);")     # stdcall ignored
+        m = ffi.dlopen(lib_m)
+        assert "double(*)(double)" in str(ffi.typeof(m.sin))
+        x = m.sin(1.23)
+        assert x == math.sin(1.23)
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
@@ -2246,9 +2246,16 @@
     if sys.platform != 'win32':
         py.test.skip("Windows only")
     ffi = FFI()
-    ffi.cdef("int call1(int(*cb)(int));", calling_conv="cdecl")
-    ffi.cdef("int call2(int(*cb)(int));", calling_conv="stdcall")
+    ffi.cdef("""
+        int __cdecl   call1(int(__cdecl   *cb)(int));
+        int __stdcall call2(int(__stdcall *cb)(int));
+        int (__cdecl   *const cb1)(int);
+        int (__stdcall *const cb2)(int);
+    """)
     lib = ffi.verify(r"""
+        int __cdecl   cb1(int x) { return x * 2; }
+        int __stdcall cb2(int x) { return x * 3; }
+
         int __cdecl call1(int(__cdecl *cb)(int)) {
             printf("here1\n");
             printf("cb = %p, cb1 = %p\n", cb, (void *)cb1);
@@ -2268,13 +2275,8 @@
             return result;
         }
     """)
-    assert lib.call1(ffi.addressof(lib, 'cb1')) == 500*999*2
-    ...
-    print '<<< cb2 =', ffi.addressof(lib, 'cb2')
-    ptr_call2 = ffi.addressof(lib, 'call2')
-    assert lib.call2(ffi.addressof(lib, 'cb2')) == -500*999*3
-    assert ptr_call2(ffi.addressof(lib, 'cb2')) == -500*999*3
-    print '<<< done'
+    assert lib.call1(lib.cb1) == 500*999*2
+    assert lib.call2(lib.cb2) == -500*999*3
 
 def test_win32_calling_convention_2():
     if sys.platform != 'win32':
@@ -2284,16 +2286,16 @@
     # automatically corrected.  But this does not apply to the 'cb'
     # function pointer argument.
     ffi = FFI()
-    ffi.cdef("int call1(int(*cb)(int)); int cb1(int);", calling_conv="cdecl")
-    ffi.cdef("int call2(int(*cb)(int)); int cb2(int);", calling_conv="stdcall")
+    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', """
-        int __stdcall call1(int(__cdecl *cb)(int)) {
+        int __cdecl call1(int(__cdecl *cb)(int)) {
             int i, result = 0;
             for (i = 0; i < 1000; i++)
                 result += cb(i);
             return result;
         }
-        int __cdecl call2(int(__stdcall *cb)(int)) {
+        int __stdcall call2(int(__stdcall *cb)(int)) {
             int i, result = 0;
             for (i = 0; i < 1000; i++)
                 result += cb(-i);
@@ -2318,7 +2320,7 @@
         py.test.skip("Windows only")
     ffi = FFI()
     ffi.cdef("struct point { int x, y; };")
-    ffi.cdef("struct point call1(int(*cb)(struct point)); "
+    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")
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to