Commits

mattip committed 3fdf597

update cffi, fix most win32 tests

  • Participants
  • Parent commits 366c6b1

Comments (0)

Files changed (6)

lib_pypy/cffi/vengine_cpy.py

     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))

pypy/module/test_lib_pypy/cffi_tests/test_function.py

     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
         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
         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);
         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)
 
             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)
 
         ffi.cdef("""
             int nonexistent();
         """)
-        m = ffi.dlopen("m")
+        m = ffi.dlopen(lib_m)
         assert not hasattr(m, 'nonexistent')
 
     def test_wraps_from_stdlib(self):
             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

pypy/module/test_lib_pypy/cffi_tests/test_parsing.py

                                  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))
 
         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)
 
         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>'
         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>'

pypy/module/test_lib_pypy/cffi_tests/test_unicode_literals.py

 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()
 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)
 

pypy/module/test_lib_pypy/cffi_tests/test_verify.py

 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
 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
 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
 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)]:

pypy/module/test_lib_pypy/cffi_tests/test_zdistutils.py

 
 
 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)
         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()
         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
         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:
         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():
         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()
             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]
 
         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)
 
         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)
 
         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:
     '''
         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()
         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)