Author: Matti Picus <[email protected]>
Branch:
Changeset: r69616:3fdf59785f44
Date: 2014-03-02 18:04 +0200
http://bitbucket.org/pypy/pypy/changeset/3fdf59785f44/
Log: update cffi, fix most win32 tests
diff --git a/lib_pypy/cffi/vengine_cpy.py b/lib_pypy/cffi/vengine_cpy.py
--- a/lib_pypy/cffi/vengine_cpy.py
+++ b/lib_pypy/cffi/vengine_cpy.py
@@ -897,11 +897,13 @@
if (c_api_object == NULL)
return;
if (!PyCapsule_CheckExact(c_api_object)) {
+ Py_DECREF(c_api_object);
PyErr_SetNone(PyExc_ImportError);
return;
}
memcpy(_cffi_exports, PyCapsule_GetPointer(c_api_object, "cffi"),
_CFFI_NUM_EXPORTS * sizeof(void *));
+ Py_DECREF(c_api_object);
}
#define _cffi_type(num) ((CTypeDescrObject *)PyList_GET_ITEM(_cffi_types, num))
diff --git a/pypy/module/test_lib_pypy/cffi_tests/test_function.py
b/pypy/module/test_lib_pypy/cffi_tests/test_function.py
--- a/pypy/module/test_lib_pypy/cffi_tests/test_function.py
+++ b/pypy/module/test_lib_pypy/cffi_tests/test_function.py
@@ -35,6 +35,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
@@ -44,18 +50,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
@@ -67,14 +71,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);
@@ -92,7 +96,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)
@@ -293,7 +297,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)
@@ -356,7 +360,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):
@@ -370,7 +374,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/pypy/module/test_lib_pypy/cffi_tests/test_parsing.py
b/pypy/module/test_lib_pypy/cffi_tests/test_parsing.py
--- a/pypy/module/test_lib_pypy/cffi_tests/test_parsing.py
+++ b/pypy/module/test_lib_pypy/cffi_tests/test_parsing.py
@@ -37,7 +37,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))
@@ -61,7 +61,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)
@@ -71,11 +71,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>'
@@ -149,7 +155,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/pypy/module/test_lib_pypy/cffi_tests/test_unicode_literals.py
b/pypy/module/test_lib_pypy/cffi_tests/test_unicode_literals.py
--- a/pypy/module/test_lib_pypy/cffi_tests/test_unicode_literals.py
+++ b/pypy/module/test_lib_pypy/cffi_tests/test_unicode_literals.py
@@ -11,6 +11,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()
@@ -56,7 +63,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/pypy/module/test_lib_pypy/cffi_tests/test_verify.py
b/pypy/module/test_lib_pypy/cffi_tests/test_verify.py
--- a/pypy/module/test_lib_pypy/cffi_tests/test_verify.py
+++ b/pypy/module/test_lib_pypy/cffi_tests/test_verify.py
@@ -5,7 +5,12 @@
from pypy.module.test_lib_pypy.cffi_tests.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
@@ -64,13 +69,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
@@ -78,7 +83,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
@@ -104,7 +109,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/pypy/module/test_lib_pypy/cffi_tests/test_zdistutils.py
b/pypy/module/test_lib_pypy/cffi_tests/test_zdistutils.py
--- a/pypy/module/test_lib_pypy/cffi_tests/test_zdistutils.py
+++ b/pypy/module/test_lib_pypy/cffi_tests/test_zdistutils.py
@@ -8,6 +8,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)
@@ -27,7 +34,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()
@@ -38,7 +45,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
@@ -51,7 +58,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:
@@ -65,7 +72,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():
@@ -77,7 +84,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()
@@ -94,7 +101,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]
@@ -112,7 +119,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)
@@ -123,7 +130,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)
@@ -132,7 +139,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:
@@ -150,7 +157,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()
@@ -164,7 +171,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