Author: Matti Picus <[email protected]>
Branch:
Changeset: r1470:023010b338a2
Date: 2014-03-02 17:33 +0200
http://bitbucket.org/cffi/cffi/changeset/023010b338a2/
Log: fix for win32
diff --git a/testing/test_function.py b/testing/test_function.py
--- a/testing/test_function.py
+++ b/testing/test_function.py
@@ -34,6 +34,12 @@
def getvalue(self):
return self._value
+lib_m = 'm'
+if sys.platform == 'win32':
+ #there is a small chance this fails on Mingw via environ $CC
+ import distutils.ccompiler
+ if distutils.ccompiler.get_default_compiler() == 'msvc':
+ lib_m = 'msvcrt'
class TestFunction(object):
Backend = CTypesBackend
@@ -43,18 +49,16 @@
ffi.cdef("""
double sin(double x);
""")
- m = ffi.dlopen("m")
+ m = ffi.dlopen(lib_m)
x = m.sin(1.23)
assert x == math.sin(1.23)
def test_sinf(self):
- if sys.platform == 'win32':
- py.test.skip("no 'sinf'")
ffi = FFI(backend=self.Backend())
ffi.cdef("""
float sinf(float x);
""")
- m = ffi.dlopen("m")
+ m = ffi.dlopen(lib_m)
x = m.sinf(1.23)
assert type(x) is float
assert x != math.sin(1.23) # rounding effects
@@ -66,14 +70,14 @@
ffi.cdef("""
void sin(double x);
""")
- m = ffi.dlopen("m")
+ m = ffi.dlopen(lib_m)
x = m.sin(1.23)
assert x is None
def test_dlopen_filename(self):
- path = ctypes.util.find_library("m")
+ path = ctypes.util.find_library(lib_m)
if not path:
- py.test.skip("libm not found")
+ py.test.skip("%s not found" % lib_m)
ffi = FFI(backend=self.Backend())
ffi.cdef("""
double cos(double x);
@@ -91,7 +95,7 @@
ffi.cdef("""
double cos(double x);
""")
- m = ffi.dlopen("m", ffi.RTLD_LAZY | ffi.RTLD_LOCAL)
+ m = ffi.dlopen(lib_m, ffi.RTLD_LAZY | ffi.RTLD_LOCAL)
x = m.cos(1.23)
assert x == math.cos(1.23)
@@ -292,7 +296,7 @@
typedef double func_t(double);
func_t sin;
""")
- m = ffi.dlopen("m")
+ m = ffi.dlopen(lib_m)
x = m.sin(1.23)
assert x == math.sin(1.23)
@@ -355,7 +359,7 @@
ffi.cdef("""
int nonexistent();
""")
- m = ffi.dlopen("m")
+ m = ffi.dlopen(lib_m)
assert not hasattr(m, 'nonexistent')
def test_wraps_from_stdlib(self):
@@ -369,7 +373,7 @@
def wrapper(*args):
return f(*args) + 100
return wrapper
- m = ffi.dlopen("m")
+ m = ffi.dlopen(lib_m)
sin100 = my_decorator(m.sin)
x = sin100(1.23)
assert x == math.sin(1.23) + 100
diff --git a/testing/test_parsing.py b/testing/test_parsing.py
--- a/testing/test_parsing.py
+++ b/testing/test_parsing.py
@@ -36,7 +36,7 @@
totalsize=-1, totalalignment=-1, sflags=0):
assert isinstance(s, FakeStruct)
s.fields = fields
-
+
def new_array_type(self, ptrtype, length):
return FakeType('<array %s x %s>' % (ptrtype, length))
@@ -60,7 +60,7 @@
return ', '.join([str(y) + str(x) for x, y, z in self.fields])
class FakeLibrary(object):
-
+
def load_function(self, BType, name):
return FakeFunction(BType, name)
@@ -70,11 +70,17 @@
self.BType = str(BType)
self.name = name
+lib_m = "m"
+if sys.platform == 'win32':
+ #there is a small chance this fails on Mingw via environ $CC
+ import distutils.ccompiler
+ if distutils.ccompiler.get_default_compiler() == 'msvc':
+ lib_m = 'msvcrt'
def test_simple():
ffi = FFI(backend=FakeBackend())
ffi.cdef("double sin(double x);")
- m = ffi.dlopen("m")
+ m = ffi.dlopen(lib_m)
func = m.sin # should be a callable on real backends
assert func.name == 'sin'
assert func.BType == '<func (<double>), <double>, False>'
@@ -148,7 +154,7 @@
x, double/*several*//*comment*/y) /*on the same line*/
;
""")
- m = ffi.dlopen("m")
+ m = ffi.dlopen(lib_m)
func = m.sin
assert func.name == 'sin'
assert func.BType == '<func (<double>, <double>), <double>, False>'
diff --git a/testing/test_unicode_literals.py b/testing/test_unicode_literals.py
--- a/testing/test_unicode_literals.py
+++ b/testing/test_unicode_literals.py
@@ -10,6 +10,13 @@
import sys, math
from cffi import FFI
+lib_m = "m"
+if sys.platform == 'win32':
+ #there is a small chance this fails on Mingw via environ $CC
+ import distutils.ccompiler
+ if distutils.ccompiler.get_default_compiler() == 'msvc':
+ lib_m = 'msvcrt'
+
def test_cast():
ffi = FFI()
@@ -55,7 +62,7 @@
def test_dlopen():
ffi = FFI()
ffi.cdef("double sin(double x);")
- m = ffi.dlopen("m") # unicode literal
+ m = ffi.dlopen(lib_m) # unicode literal
x = m.sin(1.23)
assert x == math.sin(1.23)
diff --git a/testing/test_verify.py b/testing/test_verify.py
--- a/testing/test_verify.py
+++ b/testing/test_verify.py
@@ -4,7 +4,12 @@
from testing.support import *
+lib_m = ['m']
if sys.platform == 'win32':
+ #there is a small chance this fails on Mingw via environ $CC
+ import distutils.ccompiler
+ if distutils.ccompiler.get_default_compiler() == 'msvc':
+ lib_m = ['msvcrt']
pass # no obvious -Werror equivalent on MSVC
else:
if (sys.platform == 'darwin' and
@@ -63,13 +68,13 @@
def test_simple_case():
ffi = FFI()
ffi.cdef("double sin(double x);")
- lib = ffi.verify('#include <math.h>', libraries=["m"])
+ lib = ffi.verify('#include <math.h>', libraries=lib_m)
assert lib.sin(1.23) == math.sin(1.23)
def test_rounding_1():
ffi = FFI()
ffi.cdef("float sin(double x);")
- lib = ffi.verify('#include <math.h>', libraries=["m"])
+ lib = ffi.verify('#include <math.h>', libraries=lib_m)
res = lib.sin(1.23)
assert res != math.sin(1.23) # not exact, because of double->float
assert abs(res - math.sin(1.23)) < 1E-5
@@ -77,7 +82,7 @@
def test_rounding_2():
ffi = FFI()
ffi.cdef("double sin(float x);")
- lib = ffi.verify('#include <math.h>', libraries=["m"])
+ lib = ffi.verify('#include <math.h>', libraries=lib_m)
res = lib.sin(1.23)
assert res != math.sin(1.23) # not exact, because of double->float
assert abs(res - math.sin(1.23)) < 1E-5
@@ -103,7 +108,7 @@
def test_longdouble():
ffi = FFI()
ffi.cdef("long double sinl(long double x);")
- lib = ffi.verify('#include <math.h>', libraries=["m"])
+ lib = ffi.verify('#include <math.h>', libraries=lib_m)
for input in [1.23,
ffi.cast("double", 1.23),
ffi.cast("long double", 1.23)]:
diff --git a/testing/test_zdistutils.py b/testing/test_zdistutils.py
--- a/testing/test_zdistutils.py
+++ b/testing/test_zdistutils.py
@@ -7,6 +7,13 @@
class DistUtilsTest(object):
+ def setup_class(self):
+ self.lib_m = "m"
+ if sys.platform == 'win32':
+ #there is a small chance this fails on Mingw via environ $CC
+ import distutils.ccompiler
+ if distutils.ccompiler.get_default_compiler() == 'msvc':
+ self.lib_m = 'msvcrt'
def test_locate_engine_class(self):
cls = _locate_engine_class(FFI(), self.generic)
@@ -26,7 +33,7 @@
ffi.cdef("double sin(double x);")
csrc = '/*hi there %s!*/\n#include <math.h>\n' % self
v = Verifier(ffi, csrc, force_generic_engine=self.generic,
- libraries=["m"])
+ libraries=[self.lib_m])
v.write_source()
with open(v.sourcefilename, 'r') as f:
data = f.read()
@@ -37,7 +44,7 @@
ffi.cdef("double sin(double x);")
csrc = '/*hi there %s!*/\n#include <math.h>\n' % self
v = Verifier(ffi, csrc, force_generic_engine=self.generic,
- libraries=["m"])
+ libraries=[self.lib_m])
v.sourcefilename = filename = str(udir.join('write_source.c'))
v.write_source()
assert filename == v.sourcefilename
@@ -50,7 +57,7 @@
ffi.cdef("double sin(double x);")
csrc = '/*hi there %s!*/\n#include <math.h>\n' % self
v = Verifier(ffi, csrc, force_generic_engine=self.generic,
- libraries=["m"])
+ libraries=[self.lib_m])
try:
from StringIO import StringIO
except ImportError:
@@ -64,7 +71,7 @@
ffi.cdef("double sin(double x);")
csrc = '/*hi there %s!*/\n#include <math.h>\n' % self
v = Verifier(ffi, csrc, force_generic_engine=self.generic,
- libraries=["m"])
+ libraries=[self.lib_m])
v.compile_module()
assert v.get_module_name().startswith('_cffi_')
if v.generates_python_module():
@@ -76,7 +83,7 @@
ffi.cdef("double sin(double x);")
csrc = '/*hi there %s!2*/\n#include <math.h>\n' % self
v = Verifier(ffi, csrc, force_generic_engine=self.generic,
- libraries=["m"])
+ libraries=[self.lib_m])
basename = self.__class__.__name__ + 'test_compile_module'
v.modulefilename = filename = str(udir.join(basename + '.so'))
v.compile_module()
@@ -93,7 +100,7 @@
ffi.cdef("%s sin(double x);" % csrc)
v = Verifier(ffi, "#include <math.h>",
force_generic_engine=self.generic,
- libraries=["m"])
+ libraries=[self.lib_m])
names.append(v.get_module_name())
assert names[0] == names[1] != names[2]
@@ -111,7 +118,7 @@
ffi.cdef("double sin(double x);")
csrc = '/*hi there %s!3*/\n#include <math.h>\n' % self
v = Verifier(ffi, csrc, force_generic_engine=self.generic,
- libraries=["m"])
+ libraries=[self.lib_m])
library = v.load_library()
assert library.sin(12.3) == math.sin(12.3)
@@ -122,7 +129,7 @@
udir.join('test_verifier_args.h').write('#include <math.h>\n')
v = Verifier(ffi, csrc, include_dirs=[str(udir)],
force_generic_engine=self.generic,
- libraries=["m"])
+ libraries=[self.lib_m])
library = v.load_library()
assert library.sin(12.3) == math.sin(12.3)
@@ -131,7 +138,7 @@
ffi.cdef("double sin(double x);")
csrc = "/*6%s*/\n#include <math.h>" % self
lib = ffi.verify(csrc, force_generic_engine=self.generic,
- libraries=["m"])
+ libraries=[self.lib_m])
assert lib.sin(12.3) == math.sin(12.3)
assert isinstance(ffi.verifier, Verifier)
with open(ffi.verifier.sourcefilename, 'r') as f:
@@ -149,7 +156,7 @@
'''
lib = ffi.verify(csrc, define_macros=[('TEST_EXTENSION_OBJECT', '1')],
force_generic_engine=self.generic,
- libraries=["m"])
+ libraries=[self.lib_m])
assert lib.sin(12.3) == math.sin(12.3)
v = ffi.verifier
ext = v.get_extension()
@@ -163,7 +170,7 @@
ffi.cdef("double sin(double x);")
csrc = '/*hi there9!%s*/\n#include <math.h>\n' % self
v = Verifier(ffi, csrc, force_generic_engine=self.generic,
- libraries=["m"])
+ libraries=[self.lib_m])
assert not os.path.exists(v.sourcefilename)
v.get_extension()
assert os.path.exists(v.sourcefilename)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit