Repository navigation
3.9.25.x: build ctypes against libffi 3.5+ on Windows (bpo-45898, gh-92356) - #119
Merged
Merged
Conversation
…9791) (cherry picked from commit 38f331d) 3.9.25.x: 3.9's format table keeps the 'u'/'U'/'Z' entries under #ifdef CTYPES_UNICODE, so the conflict in formattable and in _ctypes_get_fielddesc() was resolved with upstream's NULL-initialised table and _ctypes_init_fielddesc() call, and the matching cases in _ctypes_init_fielddesc() are guarded the same way. Needed on Windows once the build uses libffi 3.5 or later, whose ffi.h always declares the ffi_type_* symbols dllimport, so the static table no longer compiles (C2099).
Merged
manoelc-dev
self-requested a review
October 29, 2026 22:37
ezequielp-activestate
approved these changes
Oct 29, 2026
ezequielp-activestate
left a comment
There was a problem hiding this comment.
Approving.
- bpo-45898 and pythongh-92356 match upstream 3.11 (
38f331d465,adcb6a6055) line for line. The one exception is theCTYPES_UNICODEguards on 3.9, and the conflict resolution there is correct: the'u'/'U'/'Z'table entries and their_ctypes_init_fielddesc()cases are guarded the same way. _ctypes_get_fielddesc()setsinitialized, so the table is filled once.- Nothing else in
Modules/_ctypestakes the address of anffi_type_*in a static initializer. - Upstream has no later follow-ups to either change.
🟡 Non-blocking: besides dropping FFI_BUILDING, the _ctypes.vcxproj change defines USING_MALLOC_CLOSURE_DOT_C=1. On Windows, callback thunks then come from malloc_closure.c free-list pages rather than libffi's ffi_closure_alloc, because HAVE_FFI_CLOSURE_ALLOC isn't defined there. Upstream 3.11+ does the same, so this isn't a problem, but it is a runtime change beyond the build fix, and the release notes could mention it.
manoelc-dev
removed their request for review
October 29, 2026 22:43
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backports upstream's ctypes change from 3.11 so
_ctypesbuilds on Windows against libffi 3.5 or later. The next release on this line (after 3.9.25.3) will carry it, and Platform can then drop inventory patch29f5e6b0.Why
ffi.halways declares theffi_type_*symbols__declspec(dllimport)under MSVC. TheFFI_BUILDINGdefine that_ctypes.vcxprojsets no longer turns that off.cfield.ctakes their addresses in a static table, which MSVC rejects for imported symbols:cfield.c(1475): error C2099: initializer is not a constant.shared/ffi3.8.0. 3.9 has the same code, and its Platform build now uses libffi 3.8.0 too. 3.11+ isn't affected.What
pffi_typepointers at runtime in_ctypes_init_fielddesc(), dropscfield.c's own copies of theffi_type_*definitions, and changes_ctypes.vcxprojfromFFI_BUILDINGtoUSING_MALLOC_CLOSURE_DOT_C=1, as in 3.11. On this line it conflicts; resolved keeping 3.9's#ifdef CTYPES_UNICODEguards on the'u'/'U'/'Z'entries and the matching cases in_ctypes_init_fielddesc().initializedflag, so the table isn't rebuilt on every lookup (a ctypes call-overhead regression).Testing
shared/ffi3.8.0 artifact (libffi-8.dll):_ctypesbuilds,test_ctypespasses (498 tests, 31 skipped), and a probe of structures,c_wchar, callbacks throughqsortandwindllworks.test_ctypespasses.29f5e6b0on 3.9.25.3.