Fix free-threaded Python 3.14t support in C extension#352
Merged
jensens merged 1 commit intozopefoundation:masterfrom Feb 17, 2026
Merged
Fix free-threaded Python 3.14t support in C extension#352jensens merged 1 commit intozopefoundation:masterfrom
jensens merged 1 commit intozopefoundation:masterfrom
Conversation
- Declare Py_mod_gil_not_used so the GIL is not re-enabled on import - Replace PyDict_GetItem() borrowed refs with PyDict_GetItemRef() strong refs in cache lookups to prevent use-after-free races - Use Py_TYPE() macro instead of direct ob_type struct access - Add 3.14t to CI and tox envlist Refs zopefoundation#332
This was referenced Feb 16, 2026
tseaver
approved these changes
Feb 17, 2026
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.
Summary
Py_mod_gil_not_usedin module slots so the GIL is not re-enabled on import under free-threaded Python 3.14t (PEP 703)PyDict_GetItem()borrowed references withPyDict_GetItemRef()strong references in all cache lookup functions (_subcache,_getcache,_lookup,_lookup1,_lookupAll,_subscriptions,implementedBy). This prevents use-after-free when another thread clears the cache between the dict lookup return andPy_INCREF().Py_TYPE()macro instead of directob_typestruct access (incompatible with atomic type lookups in free-threaded builds)PyDict_GetItemRefpolyfill for Python < 3.13 (compiles to the samePyDict_GetItem+Py_INCREFpattern, zero overhead)Tested locally on both Python 3.14 (1358 tests pass) and Python 3.14t (1358 tests pass, no GIL re-enable warning). Benchmark shows zero regression on cached adapter lookups (~109ns/call before vs ~106ns/call after).
Refs #332