classification
Title: ctypes cfield.c defines duplicate ffi_type_* symbols
Type: behavior Stage: patch review
Components: ctypes Versions: Python 3.11, Python 3.10, Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Roman Yurchak, christian.heimes, paul.moore, steve.dower, tim.golden, zach.ware
Priority: normal Keywords: patch

Created on 2021-11-25 11:57 by christian.heimes, last changed 2021-11-26 19:45 by steve.dower.

Pull Requests
URL Status Linked Edit
PR 29791 open christian.heimes, 2021-11-26 09:47
Messages (3)
msg406991 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2021-11-25 11:57
ctypes's cfield.c redefines a couple of symbols like ffi_type_void and others. The symbols are exported by ffi.h and libffi for more than 12 years: https://github.com/libffi/libffi/blame/e1539266e6c6dde3c99832323586f33f977d1dc0/include/ffi.h.in#L184

I think we can safely remove the symbols from the file. The idea is inspired by pyodide patch https://github.com/pyodide/pyodide/blob/main/cpython/patches/remove-duplicate-symbols-from-cfield.c.patch
msg407038 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2021-11-26 10:17
Windows tests are failing without ffi_type_ symbols:

cfield.obj : error LNK2001: unresolved external symbol _ffi_type_double [D:\a\cpython\cpython\PCbuild\_ctypes.vcxproj]
cfield.obj : error LNK2001: unresolved external symbol _ffi_type_float [D:\a\cpython\cpython\PCbuild\_ctypes.vcxproj]
cfield.obj : error LNK2001: unresolved external symbol _ffi_type_uint32 [D:\a\cpython\cpython\PCbuild\_ctypes.vcxproj]
cfield.obj : error LNK2001: unresolved external symbol _ffi_type_sint8 [D:\a\cpython\cpython\PCbuild\_ctypes.vcxproj]
cfield.obj : error LNK2001: unresolved external symbol _ffi_type_uint8 [D:\a\cpython\cpython\PCbuild\_ctypes.vcxproj]
cfield.obj : error LNK2001: unresolved external symbol _ffi_type_uint64 [D:\a\cpython\cpython\PCbuild\_ctypes.vcxproj]
cfield.obj : error LNK2001: unresolved external symbol _ffi_type_uint16 [D:\a\cpython\cpython\PCbuild\_ctypes.vcxproj]
cfield.obj : error LNK2001: unresolved external symbol _ffi_type_sint16 [D:\a\cpython\cpython\PCbuild\_ctypes.vcxproj]
msg407088 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2021-11-26 19:45
This is because we use libffi as a DLL and you can't statically reference dynamically loaded addresses on Windows.

You could change that format table to be initialised on first use, or resolve the FFI type lazily. Or change ctypes to statically link libffi (including updating our FFI build, which IIRC is the one that requires Cygwin, to generate static libraries instead of dynamic) - we can't backport this change, either, because it affects the layout on disk.
History
Date User Action Args
2021-11-26 19:45:13steve.dowersetmessages: + msg407088
2021-11-26 13:52:19Roman Yurchaksetnosy: + Roman Yurchak
2021-11-26 10:17:53christian.heimessetnosy: + paul.moore, tim.golden, zach.ware, steve.dower
messages: + msg407038
2021-11-26 09:47:47christian.heimessetkeywords: + patch
stage: patch review
pull_requests: + pull_request28026
2021-11-26 09:41:56christian.heimeslinkissue40280 dependencies
2021-11-25 11:57:40christian.heimescreate