[pypy-commit] cffi default: hg merge win32-ownlib: enable test_ownlib to run on Windows, and
arigo
noreply at buildbot.pypy.org
Mon Jan 19 21:13:25 CET 2015
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r1640:b1c3d82a14a8
Date: 2015-01-19 21:10 +0100
http://bitbucket.org/cffi/cffi/changeset/b1c3d82a14a8/
Log: hg merge win32-ownlib: enable test_ownlib to run on Windows, and add
a test with many arguments that may still fail on some platforms
with a broken libffi
diff --git a/.hgignore b/.hgignore
--- a/.hgignore
+++ b/.hgignore
@@ -6,6 +6,7 @@
demo/__pycache__
__pycache__
_cffi_backend*.so
+_cffi_backend.pyd
doc/build
build
dist
diff --git a/testing/test_ownlib.py b/testing/test_ownlib.py
--- a/testing/test_ownlib.py
+++ b/testing/test_ownlib.py
@@ -7,34 +7,133 @@
SOURCE = """\
#include <errno.h>
-int test_getting_errno(void) {
+#ifdef _WIN32
+#define EXPORT __declspec(dllexport)
+#else
+#define EXPORT
+#endif
+
+EXPORT int test_getting_errno(void) {
errno = 123;
return -1;
}
-int test_setting_errno(void) {
+EXPORT int test_setting_errno(void) {
return errno;
+};
+
+typedef struct {
+ long x;
+ long y;
+} POINT;
+
+typedef struct {
+ long left;
+ long top;
+ long right;
+ long bottom;
+} RECT;
+
+
+EXPORT int PointInRect(RECT *prc, POINT pt)
+{
+ if (pt.x < prc->left)
+ return 0;
+ if (pt.x > prc->right)
+ return 0;
+ if (pt.y < prc->top)
+ return 0;
+ if (pt.y > prc->bottom)
+ return 0;
+ return 1;
+};
+
+EXPORT long left = 10;
+EXPORT long top = 20;
+EXPORT long right = 30;
+EXPORT long bottom = 40;
+
+EXPORT RECT ReturnRect(int i, RECT ar, RECT* br, POINT cp, RECT dr,
+ RECT *er, POINT fp, RECT gr)
+{
+ /*Check input */
+ if (ar.left + br->left + dr.left + er->left + gr.left != left * 5)
+ {
+ ar.left = 100;
+ return ar;
+ }
+ if (ar.right + br->right + dr.right + er->right + gr.right != right * 5)
+ {
+ ar.right = 100;
+ return ar;
+ }
+ if (cp.x != fp.x)
+ {
+ ar.left = -100;
+ }
+ if (cp.y != fp.y)
+ {
+ ar.left = -200;
+ }
+ switch(i)
+ {
+ case 0:
+ return ar;
+ break;
+ case 1:
+ return dr;
+ break;
+ case 2:
+ return gr;
+ break;
+
+ }
+ return ar;
}
-int my_array[7] = {0, 1, 2, 3, 4, 5, 6};
+EXPORT int my_array[7] = {0, 1, 2, 3, 4, 5, 6};
"""
class TestOwnLib(object):
Backend = CTypesBackend
def setup_class(cls):
- if sys.platform == 'win32':
- return
+ cls.module = None
from testing.udir import udir
udir.join('testownlib.c').write(SOURCE)
- subprocess.check_call(
- 'gcc testownlib.c -shared -fPIC -o testownlib.so',
- cwd=str(udir), shell=True)
- cls.module = str(udir.join('testownlib.so'))
+ if sys.platform == 'win32':
+ import os
+ # did we already build it?
+ if os.path.exists(str(udir.join('testownlib.dll'))):
+ cls.module = str(udir.join('testownlib.dll'))
+ return
+ # try (not too hard) to find the version used to compile this python
+ # no mingw
+ from distutils.msvc9compiler import get_build_version
+ version = get_build_version()
+ toolskey = "VS%0.f0COMNTOOLS" % version
+ toolsdir = os.environ.get(toolskey, None)
+ if toolsdir is None:
+ return
+ productdir = os.path.join(toolsdir, os.pardir, os.pardir, "VC")
+ productdir = os.path.abspath(productdir)
+ vcvarsall = os.path.join(productdir, "vcvarsall.bat")
+ if os.path.isfile(vcvarsall):
+ cmd = '"%s"' % vcvarsall + ' & cl.exe testownlib.c ' \
+ ' /LD /Fetestownlib.dll'
+ subprocess.check_call(cmd, cwd = str(udir), shell=True)
+ cls.module = str(udir.join('testownlib.dll'))
+ else:
+ subprocess.check_call(
+ 'gcc testownlib.c -shared -fPIC -o testownlib.so',
+ cwd=str(udir), shell=True)
+ cls.module = str(udir.join('testownlib.so'))
def test_getting_errno(self):
+ if self.module is None:
+ py.test.skip("fix the auto-generation of the tiny test lib")
if sys.platform == 'win32':
- py.test.skip("fix the auto-generation of the tiny test lib")
+ py.test.skip("fails, errno at multiple addresses")
ffi = FFI(backend=self.Backend())
ffi.cdef("""
int test_getting_errno(void);
@@ -45,8 +144,10 @@
assert ffi.errno == 123
def test_setting_errno(self):
+ if self.module is None:
+ py.test.skip("fix the auto-generation of the tiny test lib")
if sys.platform == 'win32':
- py.test.skip("fix the auto-generation of the tiny test lib")
+ py.test.skip("fails, errno at multiple addresses")
if self.Backend is CTypesBackend and '__pypy__' in sys.modules:
py.test.skip("XXX errno issue with ctypes on pypy?")
ffi = FFI(backend=self.Backend())
@@ -60,7 +161,7 @@
assert ffi.errno == 42
def test_my_array_7(self):
- if sys.platform == 'win32':
+ if self.module is None:
py.test.skip("fix the auto-generation of the tiny test lib")
ffi = FFI(backend=self.Backend())
ffi.cdef("""
@@ -80,7 +181,7 @@
assert ownlib.my_array[i] == i
def test_my_array_no_length(self):
- if sys.platform == 'win32':
+ if self.module is None:
py.test.skip("fix the auto-generation of the tiny test lib")
if self.Backend is CTypesBackend:
py.test.skip("not supported by the ctypes backend")
@@ -100,7 +201,7 @@
assert ownlib.my_array[i] == i
def test_keepalive_lib(self):
- if sys.platform == 'win32':
+ if self.module is None:
py.test.skip("fix the auto-generation of the tiny test lib")
ffi = FFI(backend=self.Backend())
ffi.cdef("""
@@ -118,7 +219,7 @@
assert res == -1
def test_keepalive_ffi(self):
- if sys.platform == 'win32':
+ if self.module is None:
py.test.skip("fix the auto-generation of the tiny test lib")
ffi = FFI(backend=self.Backend())
ffi.cdef("""
@@ -134,4 +235,46 @@
assert ownlib_r() is not None # kept alive by ffi
res = func()
assert res == -1
- assert ffi.errno == 123
+ if sys.platform != 'win32': # else, errno at multiple addresses
+ assert ffi.errno == 123
+
+ def test_struct_by_value(self):
+ if self.module is None:
+ py.test.skip("fix the auto-generation of the tiny test lib")
+ ffi = FFI(backend=self.Backend())
+ ffi.cdef("""
+ typedef struct {
+ long x;
+ long y;
+ } POINT;
+
+ typedef struct {
+ long left;
+ long top;
+ long right;
+ long bottom;
+ } RECT;
+
+ long left, top, right, bottom;
+
+ RECT ReturnRect(int i, RECT ar, RECT* br, POINT cp, RECT dr,
+ RECT *er, POINT fp, RECT gr);
+ """)
+ ownlib = ffi.dlopen(self.module)
+
+ rect = ffi.new('RECT[1]')
+ pt = ffi.new('POINT[1]')
+ pt[0].x = 15
+ pt[0].y = 25
+ rect[0].left = ownlib.left
+ rect[0].right = ownlib.right
+ rect[0].top = ownlib.top
+ rect[0].bottom = ownlib.bottom
+
+ for i in range(4):
+ ret = ownlib.ReturnRect(i, rect[0], rect, pt[0], rect[0],
+ rect, pt[0], rect[0])
+ assert ret.left == ownlib.left
+ assert ret.right == ownlib.right
+ assert ret.top == ownlib.top
+ assert ret.bottom == ownlib.bottom
More information about the pypy-commit
mailing list