This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: ctypes cfield.c defines duplicate ffi_type_* symbols
Type: behavior Stage: resolved
Components: ctypes Versions: Python 3.11
process
Status: closed Resolution: fixed
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 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 29791 merged christian.heimes, 2021-11-26 09:47
Messages (5)
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.
msg413936 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2022-02-24 19:52
New changeset 38f331d4656394ae0f425568e26790ace778e076 by Christian Heimes in branch 'main':
bpo-45898: Remove duplicate symbols from _ctypes/cfield.c (GH-29791)
https://github.com/python/cpython/commit/38f331d4656394ae0f425568e26790ace778e076
msg413937 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2022-02-24 20:00
I have applied the patch to main branch (3.11). The workaround for Windows turned out to be more elaborate than initially anticipated. I'm not going to backport the fix to 3.10 and 3.9.
History
Date User Action Args
2022-04-11 14:59:52adminsetgithub: 90056
2022-02-24 20:00:27christian.heimessetstatus: open -> closed
versions: - Python 3.9, Python 3.10
messages: + msg413937

resolution: fixed
stage: patch review -> resolved
2022-02-24 19:52:08christian.heimessetmessages: + msg413936
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