Commits

Vincent Bernat  committed f3dabd5

Link math tests using `sin()` to `libm`

While this linking seems to be done indirectly on most platforms, it
fails to work correctly on Sparc and S390x where an inappropriate
version of `sin()` is used. This should additional occurrences of bug #68.

Tests are passing on amd64, sparc and s390x Debian Linux platforms. Both
Python 2.x and Python 3.x.

  • Participants
  • Parent commits 8d9e0e9
  • Branches fix/sinl

Comments (0)

Files changed (2)

File testing/test_verify.py

 def test_simple_case():
     ffi = FFI()
     ffi.cdef("double sin(double x);")
-    lib = ffi.verify('#include <math.h>')
+    lib = ffi.verify('#include <math.h>', libraries=["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>')
+    lib = ffi.verify('#include <math.h>', libraries=["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>')
+    lib = ffi.verify('#include <math.h>', libraries=["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>')
+    lib = ffi.verify('#include <math.h>', libraries=["m"])
     for input in [1.23,
                   ffi.cast("double", 1.23),
                   ffi.cast("long double", 1.23)]:

File testing/test_zdistutils.py

         ffi = FFI()
         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)
+        v = Verifier(ffi, csrc, force_generic_engine=self.generic,
+                     libraries=["m"])
         v.write_source()
         with open(v.sourcefilename, 'r') as f:
             data = f.read()
         ffi = FFI()
         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)
+        v = Verifier(ffi, csrc, force_generic_engine=self.generic,
+                     libraries=["m"])
         v.sourcefilename = filename = str(udir.join('write_source.c'))
         v.write_source()
         assert filename == v.sourcefilename
         ffi = FFI()
         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)
+        v = Verifier(ffi, csrc, force_generic_engine=self.generic,
+                     libraries=["m"])
         try:
             from StringIO import StringIO
         except ImportError:
         ffi = FFI()
         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)
+        v = Verifier(ffi, csrc, force_generic_engine=self.generic,
+                     libraries=["m"])
         v.compile_module()
         assert v.get_module_name().startswith('_cffi_')
         if v.generates_python_module():
         ffi = FFI()
         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)
+        v = Verifier(ffi, csrc, force_generic_engine=self.generic,
+                     libraries=["m"])
         basename = self.__class__.__name__ + 'test_compile_module'
         v.modulefilename = filename = str(udir.join(basename + '.so'))
         v.compile_module()
             ffi = FFI()
             ffi.cdef("%s sin(double x);" % csrc)
             v = Verifier(ffi, "#include <math.h>",
-                         force_generic_engine=self.generic)
+                         force_generic_engine=self.generic,
+                         libraries=["m"])
             names.append(v.get_module_name())
         assert names[0] == names[1] != names[2]
 
         ffi = FFI()
         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)
+        v = Verifier(ffi, csrc, force_generic_engine=self.generic,
+                     libraries=["m"])
         library = v.load_library()
         assert library.sin(12.3) == math.sin(12.3)
 
         csrc = '/*hi there %s!4*/#include "test_verifier_args.h"\n' % self
         udir.join('test_verifier_args.h').write('#include <math.h>\n')
         v = Verifier(ffi, csrc, include_dirs=[str(udir)],
-                     force_generic_engine=self.generic)
+                     force_generic_engine=self.generic,
+                     libraries=["m"])
         library = v.load_library()
         assert library.sin(12.3) == math.sin(12.3)
 
         ffi = FFI()
         ffi.cdef("double sin(double x);")
         csrc = "/*6%s*/\n#include <math.h>" % self
-        lib = ffi.verify(csrc, force_generic_engine=self.generic)
+        lib = ffi.verify(csrc, force_generic_engine=self.generic,
+                         libraries=["m"])
         assert lib.sin(12.3) == math.sin(12.3)
         assert isinstance(ffi.verifier, Verifier)
         with open(ffi.verifier.sourcefilename, 'r') as f:
     #endif
     '''
         lib = ffi.verify(csrc, define_macros=[('TEST_EXTENSION_OBJECT', '1')],
-                         force_generic_engine=self.generic)
+                         force_generic_engine=self.generic,
+                         libraries=["m"])
         assert lib.sin(12.3) == math.sin(12.3)
         v = ffi.verifier
         ext = v.get_extension()
         ffi = FFI()
         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)
+        v = Verifier(ffi, csrc, force_generic_engine=self.generic,
+                     libraries=["m"])
         assert not os.path.exists(v.sourcefilename)
         v.get_extension()
         assert os.path.exists(v.sourcefilename)