Skip to content

"too many values to unpack" when there are extension modules in pyproject.toml #246

@ltfish

Description

@ltfish

When calling ffi.verify("#include <string.h>") in a Python project, cffi threw the following exception:

  /workspace/cle/tests/test_clemory.py(22)test_cclemory()
     20         int memcmp(const void* s1, const void* s2, size_t n);
     21     """)
---> 22     c = ffi.verify("""
     23         #include <string.h>
     24     """)
  /workspace/angr-venv/lib/python3.14/site-packages/cffi/api.py(468)verify()
    466         # Make a Verifier() and use it to load the library.
    467         self.verifier = Verifier(self, source, tmpdir, **kwargs)
--> 468         lib = self.verifier.load_library()
    469         #
    470         # Save the loaded library for keep-alive purposes, even
  /workspace/angr-venv/lib/python3.14/site-packages/cffi/verifier.py(105)load_library()
    103                     if not self._has_source:
    104                         self._write_source()
--> 105                     self._compile_module()
    106             return self._load_library()
    107
  /workspace/angr-venv/lib/python3.14/site-packages/cffi/verifier.py(201)_compile_module()
    199         # compile this C source
    200         tmpdir = os.path.dirname(self.sourcefilename)
--> 201         outputfilename = ffiplatform.compile(tmpdir, self.get_extension())
    202         try:
    203             same = ffiplatform.samefile(outputfilename, self.modulefilename)
  /workspace/angr-venv/lib/python3.14/site-packages/cffi/ffiplatform.py(20)compile()
     18     saved_environ = os.environ.copy()
     19     try:
---> 20         outputfilename = _build(tmpdir, ext, compiler_verbose, debug)
     21         outputfilename = os.path.abspath(outputfilename)
     22     finally:
> /workspace/angr-venv/lib/python3.14/site-packages/cffi/ffiplatform.py(50)_build()
     48             dist.run_command('build_ext')
     49             cmd_obj = dist.get_command_obj('build_ext')
---> 50             [soname] = cmd_obj.get_outputs()
     51         finally:
     52             set_threshold(old_level)

cmd_obj.get_outputs() returns:

ipdb> pp cmd_obj.get_outputs()
['/workspace/cle/tests/__pycache__/_cffi__x4038f167x5672c41f.cpython-314-x86_64-linux-gnu.so',
 '/workspace/cle/tests/__pycache__/uefi_firmware/efi_compressor.cpython-314-x86_64-linux-gnu.so']

Looks like this is because I have another native extension in this project, and _build() does not expect other extensions to exist. My local workaround is changing [soname] = cmd_obj.get_outputs() to soname = cmd_obj.get_outputs()[0].

Please let me know if this is a workaround that you are comfortable with, and I can submit a PR if you like!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions