Repository navigation
3.10.22.x: build ctypes against libffi 3.5+ on Windows (bpo-45898, gh-92356) - #118
Merged
Merged
Conversation
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. _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.
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.10.22.2) will carry it, and Platform can then drop inventory patch6f617895.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.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 cherry-picks cleanly.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,_ctypes.pydimportslibffi-8.dll,test_ctypespasses (498 tests, 31 skipped), and a probe of structures,c_wchar, callbacks throughqsortandwindllworks.test_ctypespasses.6f617895on 3.10.22.2.