Conversation
for more information, see https://pre-commit.ci
…nto global-state
Co-authored-by: J. Nick Koston <[email protected]>
for more information, see https://pre-commit.ci
Co-authored-by: J. Nick Koston <[email protected]>
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Pull request overview
This PR updates multidict’s global version counter to be atomic (supporting CPython free-threading) and adds an isolated regression test to detect lost increments under concurrent mutation.
Changes:
- Make
mod_state.global_versionan atomic and updateNEXT_VERSION()to useatomic_fetch_add_explicit(..., memory_order_relaxed). - Add an isolated free-threading test that asserts the version delta matches the number of concurrent writes.
- Adjust build configuration to add C11 atomics flags for MSVC via a custom
build_ext.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
multidict/_multilib/state.h |
Switches the module-level global counter to an atomic and updates increment logic. |
tests/isolated/multidict_global_counter.py |
New isolated regression test for concurrent version increments (free-threaded builds). |
tests/test_leaks.py |
Registers the new isolated script in the isolated-script runner list. |
setup.py |
Introduces custom build_ext to apply platform-specific C compile flags (incl. MSVC C11 atomics). |
CHANGES/1328.bugfix.rst |
Adds a changelog entry for the atomic counter bugfix. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| for flag in BASE_CFLAGS: | ||
| # XXX: MSVC Doesn't have a /O3 flag only O2 is possible... | ||
| ext.extra_compile_args.append("/O2" if flag == "O3" else f"/{flag}") | ||
| else: |
There was a problem hiding this comment.
MSVC handling currently prefixes BASE_CFLAGS values with / (e.g. O0 -> /O0, g3 -> /g3). These aren't valid MSVC flags (/Od and /Zi//Z7 are the usual equivalents), so Windows builds with MULTIDICT_DEBUG_BUILD=1 will fail. Consider defining a separate MSVC-specific debug/release flag list instead of reusing BASE_CFLAGS verbatim.
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
|
Looks like the tests still need some work |
What do these changes do?
These changes are based off @devdanzin's second fuzzer for freethreading mode which noted using a global atomic counter system instead of a normal
uint64_tvalue I did however make one small nitpick/change from that original design to just recast(_Atomic(uint64_t)*)&state->global_versionwhich was not in the original suggestion mainly due to my code editor misbehaving on me when I would go to set it into the actual structure.Are there changes in behavior for the user?
Just bug fixes.
Related issue number
#1321
Checklist