1. Python CFFI
  2. Untitled project
  3. cffi
Issue #121 wontfix

test_strlen_approximate fails on Python 2.7

Dirkjan Ochtman
created an issue

I just tried packaging 0.8 for Gentoo. The tests pass on 3.2, but not on 2.7:

============================================= FAILURES =============================================
_____________________________________ test_strlen_approximate ______________________________________

    def test_strlen_approximate():
        ffi = FFI()
        ffi.cdef("int strlen(char *s);")
>       lib = ffi.verify("#include <string.h>")

testing/test_verify.py:94: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <testing.test_verify.FFI object at 0x491da50>, args = ('#include <string.h>',), kwds = {}

    def verify(self, *args, **kwds):
        return super(FFI, self).verify(
>           *args, extra_compile_args=extra_compile_args, **kwds)

testing/test_verify.py:22: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <testing.test_verify.FFI object at 0x491da50>, source = '#include <string.h>'
tmpdir = '/var/tmp/portage/dev-python/cffi-0.8/work/cffi-0.8/testing/__pycache__'
kwargs = {'extra_compile_args': ['-Werror']}, Verifier = <class 'cffi.verifier.Verifier'>
_caller_dir_pycache = <function _caller_dir_pycache at 0x444a5f0>

    def verify(self, source='', tmpdir=None, **kwargs):
        """Verify that the current ffi signatures compile on this
            machine, and return a dynamic library object.  The dynamic
            library can be used to call functions and access global
            variables declared in this 'ffi'.  The library is compiled
            by the C compiler: it gives you C-level API compatibility
            (including calling macros).  This is unlike 'ffi.dlopen()',
            which requires binary compatibility in the signatures.
            """
        from .verifier import Verifier, _caller_dir_pycache
        tmpdir = tmpdir or _caller_dir_pycache()
        self.verifier = Verifier(self, source, tmpdir, **kwargs)
>       lib = self.verifier.load_library()

cffi/api.py:339: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <cffi.verifier.Verifier object at 0x48ec710>

    def load_library(self):
        """Get a C module from this Verifier instance.
            Returns an instance of a FFILibrary class that behaves like the
            objects returned by ffi.dlopen(), but that delegates all
            operations to the C module.  If necessary, the C code is written
            and compiled first.
            """
        with self.ffi._lock:
            if not self._has_module:
                self._locate_module()
                if not self._has_module:
                    if not self._has_source:
                        self._write_source()
>                   self._compile_module()

cffi/verifier.py:74: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <cffi.verifier.Verifier object at 0x48ec710>

    def _compile_module(self):
        # compile this C source
        tmpdir = os.path.dirname(self.sourcefilename)
>       outputfilename = ffiplatform.compile(tmpdir, self.get_extension())

cffi/verifier.py:139: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

tmpdir = '/var/tmp/portage/dev-python/cffi-0.8/work/cffi-0.8/testing/__pycache__'
ext = <distutils.extension.Extension instance at 0x48e6680>

    def compile(tmpdir, ext):
        """Compile a C extension module using distutils."""

        saved_environ = os.environ.copy()
        try:
>           outputfilename = _build(tmpdir, ext)

cffi/ffiplatform.py:25: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

tmpdir = '/var/tmp/portage/dev-python/cffi-0.8/work/cffi-0.8/testing/__pycache__'
ext = <distutils.extension.Extension instance at 0x48e6680>

    def _build(tmpdir, ext):
        # XXX compact but horrible :-(
        from distutils.core import Distribution
        import distutils.errors
        #
        dist = Distribution({'ext_modules': [ext]})
        options = dist.get_option_dict('build_ext')
        options['force'] = ('ffiplatform', True)
        options['build_lib'] = ('ffiplatform', tmpdir)
        options['build_temp'] = ('ffiplatform', tmpdir)
        #
        try:
            dist.run_command('build_ext')
        except (distutils.errors.CompileError,
                distutils.errors.LinkError) as e:
>           raise VerificationError('%s: %s' % (e.__class__.__name__, e))
E           VerificationError: CompileError: command 'x86_64-pc-linux-gnu-gcc' failed with exit status 1

cffi/ffiplatform.py:50: VerificationError
----------------------------------------- Captured stderr ------------------------------------------
x86_64-pc-linux-gnu-gcc: error: testing/__pycache__/_cffi__xda70491cxf82c170d.c: No such file or directory
x86_64-pc-linux-gnu-gcc: fatal error: no input files
compilation terminated.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
======================== 1 failed, 490 passed, 38 skipped in 21.56 seconds =========================

Comments (5)

  1. Armin Rigo

    In the same directory? Yes. You could create two copies of the repo if you want to run the tests in parallel. We could also fix it by making sure that running the tests creates files in "/tmp/some-unique-number/" and doesn't change at all the local files; but I don't think there is motivation for doing that.

  2. Log in to comment