Conversion to '_cffi_wchar_t' from 'int' may change the sign of the result

Issue #337 resolved
Sean Marlow
created an issue

Building version 1.11.0 from PyPi against ARM aarch64 with gcc-4.8.5 most tests in the module, testing/cffi1/test_verify1.py, are failing with:

[  902s] ----------------------------- Captured stderr call -----------------------------
[  902s] verify3.c: In function '_cffi_from_c_char32_t':
[  902s] verify3.c:437:9: error: conversion to '_cffi_wchar_t' from 'int' may change the sign of the result [-Werror=sign-conversion]
[  902s]          return _cffi_from_c_wchar_t(x);
[  902s]          ^
[  902s] cc1: all warnings being treated as errors

Is there a minimum GCC version requirement?

Comments (11)

  1. Sean Marlow reporter

    Many of them are failing here is the full trace of one test:

    [ 2726s] ________________________________ test_macro_var ________________________________
    [ 2726s] 
    [ 2726s]     def test_macro_var():
    [ 2726s]         ffi = FFI()
    [ 2727s]         ffi.cdef("int myarray[50], my_value;")
    [ 2727s]         lib = ffi.verify("""
    [ 2727s]             int myarray[50];
    [ 2727s]             int *get_my_value(void) {
    [ 2727s]                 static int index = 0;
    [ 2727s]                 return &myarray[index++];
    [ 2727s]             }
    [ 2727s]             #define my_value (*get_my_value())
    [ 2727s] >       """)
    [ 2727s] 
    [ 2727s] testing/cffi1/test_verify1.py:2255: 
    [ 2727s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
    [ 2727s] testing/cffi1/test_verify1.py:42: in verify
    [ 2727s]     **kwds)
    [ 2727s] cffi/recompiler.py:1537: in _verify
    [ 2727s]     outputfilename = recompile(ffi, module_name, preamble, *args, **kwds)
    [ 2727s] cffi/recompiler.py:1513: in recompile
    [ 2727s]     compiler_verbose, debug)
    [ 2727s] cffi/ffiplatform.py:22: in compile
    [ 2727s]     outputfilename = _build(tmpdir, ext, compiler_verbose, debug)
    [ 2727s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
    [ 2727s] 
    [ 2727s] tmpdir = '.', ext = <setuptools.extension.Extension instance at 0xffff85c301b8>
    [ 2727s] compiler_verbose = 1, debug = 0
    [ 2727s] 
    [ 2727s]     def _build(tmpdir, ext, compiler_verbose=0, debug=None):
    [ 2727s]         # XXX compact but horrible :-(
    [ 2727s]         from distutils.core import Distribution
    [ 2727s]         import distutils.errors, distutils.log
    [ 2727s]         #
    [ 2727s]         dist = Distribution({'ext_modules': [ext]})
    [ 2727s]         dist.parse_config_files()
    [ 2727s]         options = dist.get_option_dict('build_ext')
    [ 2727s]         if debug is None:
    [ 2727s]             debug = sys.flags.debug
    [ 2727s]         options['debug'] = ('ffiplatform', debug)
    [ 2727s]         options['force'] = ('ffiplatform', True)
    [ 2727s]         options['build_lib'] = ('ffiplatform', tmpdir)
    [ 2727s]         options['build_temp'] = ('ffiplatform', tmpdir)
    [ 2727s]         #
    [ 2727s]         try:
    [ 2727s]             old_level = distutils.log.set_threshold(0) or 0
    [ 2727s]             try:
    [ 2727s]                 distutils.log.set_verbosity(compiler_verbose)
    [ 2727s]                 dist.run_command('build_ext')
    [ 2727s]                 cmd_obj = dist.get_command_obj('build_ext')
    [ 2727s]                 [soname] = cmd_obj.get_outputs()
    [ 2727s]             finally:
    [ 2727s]                 distutils.log.set_threshold(old_level)
    [ 2727s]         except (distutils.errors.CompileError,
    [ 2727s]                 distutils.errors.LinkError) as e:
    [ 2727s] >           raise VerificationError('%s: %s' % (e.__class__.__name__, e))
    [ 2727s] E           VerificationError: CompileError: command 'gcc' failed with exit status 1
    [ 2727s] 
    [ 2727s] cffi/ffiplatform.py:58: VerificationError
    [ 2727s] ----------------------------- Captured stdout call -----------------------------
    [ 2727s] generating /tmp/ffi-0/verify270.c
    [ 2727s] setting the current directory to '/tmp/ffi-0'
    [ 2727s] running build_ext
    [ 2727s] building 'verify270' extension
    [ 2727s] gcc -pthread -fno-strict-aliasing -fmessage-length=0 -grecord-gcc-switches -fstack-protector -O2 -Wall -D_FORTIFY_SOURCE=2 -funwind-tables -fasynchronous-unwind-tables -g -DNDEBUG -fmessage-length=0 -grecord-gcc-switches -fstack-protector -O2 -Wall -D_FORTIFY_SOURCE=2 -funwind-tables -fasynchronous-unwind-tables -g -DOPENSSL_LOAD_CONF -fPIC -I/usr/include/python2.7 -c verify270.c -o ./verify270.o -Werror -Wall -Wextra -Wconversion
    [ 2727s] ----------------------------- Captured stderr call -----------------------------
    [ 2727s] verify270.c: In function '_cffi_from_c_char32_t':
    [ 2727s] verify270.c:437:9: error: conversion to '_cffi_wchar_t' from 'int' may change the sign of the result [-Werror=sign-conversion]
    [ 2727s]          return _cffi_from_c_wchar_t(x);
    [ 2727s]          ^
    [ 2727s] cc1: all warnings being treated as errors
    

    The pytest status for module:

    [ 2409s] testing/cffi1/test_verify1.py ..F.....FFF.FFFF.FFFFFFFFFFFFsFFFFFFF.FFFFFFFF.FFFFFFFFFFFFFFFFFFFFFFF.FFFFFFFFFFFFFFFFFFFF.FF.FFFFFFFFFsFFFFFxxxFFFFxF.FFFFFFFFFFFFFFFFFFFFsF.FsFFF.sFFFsFss
    

    Digging into the failures there's one in the c/test_c.py module, this is an issue with the same type 'wchar_t':

    [ 2573s] __________________________________ test_wchar __________________________________
    [ 2573s] 
    [ 2573s]     def test_wchar():
    [ 2573s]         _test_wchar_variant("wchar_t")
    [ 2573s]         if sys.platform.startswith("linux"):
    [ 2573s]             BWChar = new_primitive_type("wchar_t")
    [ 2573s]             assert sizeof(BWChar) == 4
    [ 2573s] >           assert int(cast(BWChar, -1)) == -1        # signed, on linux
    [ 2573s] E           AssertionError: assert 4294967295 == -1
    [ 2573s] E            +  where 4294967295 = int(<cdata 'wchar_t' u'\Uffffffff'>)
    [ 2573s] E            +    where <cdata 'wchar_t' u'\Uffffffff'> = cast(<ctype 'wchar_t'>, -1)
    [ 2573s] 
    [ 2573s] c/test_c.py:2113: AssertionError
    
  2. Sean Marlow reporter

    Possible patch for the assertion error?

    --- cffi-1.11.0.orig/c/test_c.py
    +++ cffi-1.11.0/c/test_c.py
    @@ -11,6 +11,7 @@ from _cffi_backend import _testfunc, _ge
    
     # ____________________________________________________________
    
    +import platform
     import sys
     assert __version__ == "1.11.0", ("This test_c.py file is for testing a version"
                                      " of cffi that differs from the one that we"
    @@ -2110,7 +2111,10 @@ def test_wchar():
         if sys.platform.startswith("linux"):
             BWChar = new_primitive_type("wchar_t")
             assert sizeof(BWChar) == 4
    -        assert int(cast(BWChar, -1)) == -1        # signed, on linux
    +        if platform.machine().startswith(('arm', 'aarch64')):
    +            assert int(cast(BWChar, -1)) == 4294967295 # unsigned, on ARM
    +        else:
    +            assert int(cast(BWChar, -1)) == -1         # signed, on linux
    
  3. Sean Marlow reporter

    And to fix the conversion warnings, not sure this is the best solution:

    --- cffi-1.11.0.orig/testing/cffi1/test_verify1.py
    +++ cffi-1.11.0/testing/cffi1/test_verify1.py
    @@ -1,4 +1,4 @@
    -import os, sys, math, py
    +import os, sys, math, platform, py
     from cffi import FFI, FFIError, VerificationError, VerificationMissing, model
     from cffi import CDefError
     from cffi import recompiler
    @@ -19,6 +19,9 @@ else:
             extra_compile_args = ['-Werror', '-Wall', '-Wextra', '-Wconversion']
             # special things for clang
             extra_compile_args.append('-Qunused-arguments')
    +    elif platform.machine().startswith(('arm', 'aarch64')):
    +        # no conversion warnings on ARM
    +        extra_compile_args = ['-Werror', '-Wall', '-Wextra']
         else:
             # assume a standard gcc
             extra_compile_args = ['-Werror', '-Wall', '-Wextra', '-Wconversion']
    

    Edit: Ah yes, this breaks the Wconversion tests.

  4. Log in to comment