Bug 2336935

Summary: python-cffi fails to build with Python 3.14: TestNewFFI1.test_import_from_lib: TypeError: bad argument type for built-in operation + multiple Warnings
Product: [Fedora] Fedora Reporter: Karolina Surma <ksurma>
Component: python-cffiAssignee: Miro Hrončok <mhroncok>
Status: CLOSED NOTABUG QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: rawhideCC: ksurma, lbalhar, mhroncok, python-packagers-sig
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2025-01-29 13:45:09 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 2322407    

Description Karolina Surma 2025-01-10 14:53:48 UTC
python-cffi fails to build with Python 3.14.0a3.

_______________________ TestNewFFI1.test_import_from_lib _______________________

self = <testing.cffi1.test_new_ffi_1.TestNewFFI1 object at 0x7f89157a6080>

    def test_import_from_lib(self):
        ffi2 = cffi.FFI()
        ffi2.cdef("int myfunc(int); extern int myvar;\n#define MYFOO ...\n")
        outputfilename = recompile(ffi2, "_test_import_from_lib",
                                   "int myfunc(int x) { return x + 1; }\n"
                                   "int myvar = -5;\n"
                                   "#define MYFOO 42", tmpdir=str(udir))
        load_dynamic("_test_import_from_lib", outputfilename)
        from _test_import_from_lib.lib import myfunc, myvar, MYFOO
        assert MYFOO == 42
        assert myfunc(43) == 44
        assert myvar == -5     # but can't be changed, so not very useful
        with pytest.raises(ImportError):
>           from _test_import_from_lib.lib import bar
E           TypeError: bad argument type for built-in operation

testing/cffi1/test_new_ffi_1.py:1799: TypeError
----------------------------- Captured stdout call -----------------------------
generating /tmp/ffi-0/_test_import_from_lib.c
setting the current directory to '/tmp/ffi-0'
------------------------------ Captured log call -------------------------------
INFO     root:dist.py:970 running build_ext
INFO     root:build_ext.py:530 building '_test_import_from_lib' extension
INFO     root:spawn.py:60 gcc -fno-strict-overflow -Wsign-compare -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -fcf-protection -fexceptions -fcf-protection -fexceptions -fcf-protection -fexceptions -O3 -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -march=x86-64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -mtls-dialect=gnu2 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fPIC -I/usr/include/python3.14 -c _test_import_from_lib.c -o ./_test_import_from_lib.o
INFO     root:spawn.py:60 gcc -shared -Wl,-z,relro -Wl,--as-needed -Wl,-z,pack-relative-relocs -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -Wl,--build-id=sha1 -specs=/usr/lib/rpm/redhat/redhat-package-notes -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -march=x86-64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -mtls-dialect=gnu2 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer ./_test_import_from_lib.o -L/usr/lib64 -o ./_test_import_from_lib.cpython-314-x86_64-linux-gnu.so
=============================== warnings summary ===============================
src/c/test_c.py::test_callback_return_type
  /usr/lib/python3.14/site-packages/_pytest/unraisableexception.py:85: PytestUnraisableExceptionWarning: Exception ignored from cffi callback <function test_callback_return_type.<locals>.cb at 0x7f8913fbbc10>, trying to convert the result back to C: None
  
  Traceback (most recent call last):
    File "/builddir/build/BUILD/python-cffi-1.17.1-build/cffi-1.17.1/src/c/test_c.py", line 1453, in test_callback_return_type
      assert f(max) == 42
             ~^^^^^
  OverflowError: int too big to convert
  
    warnings.warn(pytest.PytestUnraisableExceptionWarning(msg))

src/c/test_c.py::test_callback_returning_wchar_t
  /usr/lib/python3.14/site-packages/_pytest/unraisableexception.py:85: PytestUnraisableExceptionWarning: Exception ignored from cffi callback <function test_callback_returning_wchar_t.<locals>.cb at 0x7f8913f5d9b0>: None
  
  Traceback (most recent call last):
    File "/builddir/build/BUILD/python-cffi-1.17.1-build/cffi-1.17.1/src/c/test_c.py", line 1748, in cb
      raise ValueError
  ValueError
  
    warnings.warn(pytest.PytestUnraisableExceptionWarning(msg))

src/c/test_c.py::test_cast_with_functionptr
  /builddir/build/BUILD/python-cffi-1.17.1-build/cffi-1.17.1/src/c/test_c.py:2166: UserWarning: implicit cast from 'char *' to a different pointer type: will be forbidden in the future (check that the types are as you expect; use an explicit ffi.cast() if they are correct)
    newp(BStructPtr, [cast(BCharP, 0)])

testing/cffi0/test_ffi_backend.py::TestFFI::test_callback_crash
  /usr/lib/python3.14/site-packages/_pytest/unraisableexception.py:85: PytestUnraisableExceptionWarning: Exception ignored from cffi callback <function BackendTests.test_callback_crash.<locals>.cb at 0x7f8913eb7cc0>: None
  
  Traceback (most recent call last):
    File "/builddir/build/BUILD/python-cffi-1.17.1-build/cffi-1.17.1/testing/cffi0/backend_tests.py", line 848, in cb
      raise Exception
  Exception
  
    warnings.warn(pytest.PytestUnraisableExceptionWarning(msg))

testing/cffi0/test_ffi_backend.py::TestFFI::test_callback_decorator
  /usr/lib/python3.14/site-packages/_pytest/unraisableexception.py:85: PytestUnraisableExceptionWarning: Exception ignored from cffi callback <function BackendTests.test_callback_decorator.<locals>.cb at 0x7f8913e8e560>, trying to convert the result back to C: None
  
  Traceback (most recent call last):
    File "/builddir/build/BUILD/python-cffi-1.17.1-build/cffi-1.17.1/testing/cffi0/backend_tests.py", line 1390, in test_callback_decorator
      assert cb((1 << (sz*8-1)) - 1, -10) == 42
             ~~^^^^^^^^^^^^^^^^^^^^^^^^^^
  OverflowError: int too big to convert
  
    warnings.warn(pytest.PytestUnraisableExceptionWarning(msg))

testing/cffi0/test_parsing.py::test_missing_newline_bug
  /builddir/build/BUILD/python-cffi-1.17.1-build/cffi-1.17.1/src/c/../cffi/cparser.py:436: UserWarning: #pragma in cdef() are entirely ignored. They should be removed for now, otherwise your code might behave differently in a future version of CFFI if #pragma support gets added. Note that '#pragma pack' needs to be replaced with the 'packed' keyword argument to cdef().
    warnings.warn(

testing/cffi1/test_ffi_obj.py::test_ffi_callback
  /usr/lib/python3.14/site-packages/_pytest/unraisableexception.py:85: PytestUnraisableExceptionWarning: Exception ignored from cffi callback <function test_ffi_callback.<locals>.<lambda> at 0x7f8914909bc0>: None
  
  Traceback (most recent call last):
    File "/builddir/build/BUILD/python-cffi-1.17.1-build/cffi-1.17.1/testing/cffi1/test_ffi_obj.py", line 130, in <lambda>
      assert ffi.callback("int(int)", lambda x: x + "", error=-66)(10) == -66
                                                ~~^~~~
  TypeError: unsupported operand type(s) for +: 'int' and 'str'
  
    warnings.warn(pytest.PytestUnraisableExceptionWarning(msg))

testing/cffi1/test_ffi_obj.py::test_ffi_callback_decorator
  /usr/lib/python3.14/site-packages/_pytest/unraisableexception.py:85: PytestUnraisableExceptionWarning: Exception ignored from cffi callback <function test_ffi_callback_decorator.<locals>.<lambda> at 0x7f8916d91b10>: None
  
  Traceback (most recent call last):
    File "/builddir/build/BUILD/python-cffi-1.17.1-build/cffi-1.17.1/testing/cffi1/test_ffi_obj.py", line 136, in <lambda>
      assert deco(lambda x: x + "")(10) == -66
                            ~~^~~~
  TypeError: unsupported operand type(s) for +: 'int' and 'str'
  
    warnings.warn(pytest.PytestUnraisableExceptionWarning(msg))

testing/cffi1/test_new_ffi_1.py::TestNewFFI1::test_callback_crash
  /usr/lib/python3.14/site-packages/_pytest/unraisableexception.py:85: PytestUnraisableExceptionWarning: Exception ignored from cffi callback <function TestNewFFI1.test_callback_crash.<locals>.cb at 0x7f8914c10eb0>: None
  
  Traceback (most recent call last):
    File "/builddir/build/BUILD/python-cffi-1.17.1-build/cffi-1.17.1/testing/cffi1/test_new_ffi_1.py", line 863, in cb
      raise Exception
  Exception
  
    warnings.warn(pytest.PytestUnraisableExceptionWarning(msg))

testing/cffi1/test_new_ffi_1.py::TestNewFFI1::test_callback_decorator
  /usr/lib/python3.14/site-packages/_pytest/unraisableexception.py:85: PytestUnraisableExceptionWarning: Exception ignored from cffi callback <function TestNewFFI1.test_callback_decorator.<locals>.cb at 0x7f8914ba1d20>, trying to convert the result back to C: None
  
  Traceback (most recent call last):
    File "/builddir/build/BUILD/python-cffi-1.17.1-build/cffi-1.17.1/testing/cffi1/test_new_ffi_1.py", line 1341, in test_callback_decorator
      assert cb((1 << (sz*8-1)) - 1, -10) == 42
             ~~^^^^^^^^^^^^^^^^^^^^^^^^^^
  OverflowError: int too big to convert
  
    warnings.warn(pytest.PytestUnraisableExceptionWarning(msg))

testing/cffi1/test_recompiler.py::test_macro_var_callback
  /usr/lib/python3.14/site-packages/_pytest/unraisableexception.py:85: PytestUnraisableExceptionWarning: Exception ignored from cffi callback <function test_macro_var_callback.<locals>.get_my_value at 0x7f89150e12d0>, trying to convert the result back to C: None
  
  Traceback (most recent call last):
    File "/usr/lib/python3.14/site-packages/_pytest/python_api.py", line 976, in raises
      func(*args[1:], **kwargs)
      ~~~~^^^^^^^^^^^^^^^^^^^^^
  TypeError: initializer for ctype 'int *' must be a cdata pointer, not str
  
    warnings.warn(pytest.PytestUnraisableExceptionWarning(msg))

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=========================== short test summary info ============================
FAILED testing/cffi1/test_new_ffi_1.py::TestNewFFI1::test_import_from_lib - T...

https://docs.python.org/3.14/whatsnew/3.14.html

For the build logs, see:
https://copr-be.cloud.fedoraproject.org/results/@python/python3.14/fedora-rawhide-x86_64/08480186-python-cffi/

For all our attempts to build python-cffi with Python 3.14, see:
https://copr.fedorainfracloud.org/coprs/g/python/python3.14/package/python-cffi/

Testing and mass rebuild of packages is happening in copr.
You can follow these instructions to test locally in mock if your package builds with Python 3.14:
https://copr.fedorainfracloud.org/coprs/g/python/python3.14/

Let us know here if you have any questions.

Python 3.14 is planned to be included in Fedora 43.
To make that update smoother, we're building Fedora packages with all pre-releases of Python 3.14.
A build failure prevents us from testing all dependent packages (transitive [Build]Requires),
so if this package is required a lot, it's important for us to get it fixed soon.

We'd appreciate help from the people who know this package best,
but if you don't want to work on this now, let us know so we can try to work around it on our side.

Comment 1 Miro Hrončok 2025-01-29 13:45:09 UTC
This no longer happens with 3.14.0a4.