Skip to content

Return all 64 bits of the version from getversion() - #1607

Merged
asvetlov merged 4 commits into
aio-libs:masterfrom
asvetlov:getversion-64bit
Sep 26, 2026
Merged

asvetlov merged 4 commits into
aio-libs:masterfrom
asvetlov:getversion-64bit

Conversation

@asvetlov

Copy link
Copy Markdown
Member

What do these changes do?

getversion() built its result with PyLong_FromUnsignedLong(). unsigned long is 32 bits on every Windows build, 64-bit included, and on 32-bit platforms, so the uint64_t version came back truncated to its low 32 bits there. It now uses PyLong_FromUnsignedLongLong().

A test-only _setversion() hook, next to _freelist_clear(), lets the test set a version above 232 without making 232 mutations.

Are there changes in behavior for the user?

Yes, on Windows and 32-bit platforms: getversion() returns the full 64-bit version. Before, two different versions that shared their low 32 bits compared equal. That took about 4.3e9 mutations with the current global counter, but only about 16.7 million new multidicts once #1605 lands, since each multidict then takes a block of 256 versions. MultiDict_GetVersion() in the C API already returned the full uint64_t and is unchanged. The pure-Python implementation is not affected.

Is it a substantial burden for the maintainers to support this?

No. It is a one-call fix plus a test hook.

Related issue number

Found while reviewing #1605.

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes
  • If you provide code modification, please add yourself to CONTRIBUTORS.txt (N/A, existing contributor)
  • Add a new news fragment into the CHANGES/ folder
  • make doc-spelling passes and any new technical words are added to docs/spelling_wordlist.txt

Drafted with Claude Code (Claude Opus 5.5); reviewed by @asvetlov.

Agent run details (optional, for reviewers)

On Linux x86-64 unsigned long is 64 bits, so the bug does not show locally; the Windows CI jobs exercise it for real. To check that the test catches truncation, it was run against a build that simulates a 32-bit unsigned long with PyLong_FromUnsignedLong((uint32_t)load_version(md)): both parametrized cases fail there and pass with the fix.

Tests: pytest passes on 3.14.7, 3.14.7t, 3.10.17 and pure Python (3.13.2), each in its own tree copy and venv. The new test is skipped on the pure-Python leg through pytest.importorskip("multidict._multidict").
make doc-spelling: passes.

getversion() built its result with PyLong_FromUnsignedLong(), and
unsigned long is 32 bits on Windows and on 32-bit platforms, so the
uint64_t version was truncated there and two different versions could
compare equal. MultiDict_GetVersion() in the C API was not affected.

Add a test-only _setversion() hook so a test can put a version above
2**32 without making 2**32 mutations.
@pyba-chronographer pyba-chronographer Bot added the bot:chronographer:provided There is a change note present in this PR label Sep 26, 2026
@asvetlov
asvetlov marked this pull request as ready for review September 26, 2026 20:16
@asvetlov
asvetlov requested a review from webknjaz as a code owner September 26, 2026 20:16
@codspeed

codspeed Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 310 untouched benchmarks


Comparing asvetlov:getversion-64bit (c5a2dc1) with master (98b367f)

Open in CodSpeed

@greptile-apps

greptile-apps Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium risk] Fixes version tracking to use full 64-bit integers.

No outstanding findings block merging.

Reviews (3) · Last reviewed commit: "Merge remote-tracking branch 'origin/get..."

Comment thread tests/test_version.py Resolved
@greptile-apps

This comment has been minimized.

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
@codecov

codecov Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (98b367f) to head (c5a2dc1).

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #1607   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           43        43           
  Lines         7978      7986    +8     
  Branches       669       669           
=========================================
+ Hits          7978      7986    +8     
Flag Coverage Δ
CI-GHA 100.00% <100.00%> (ø)
pytest 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@asvetlov
asvetlov merged commit 0a4d2e0 into aio-libs:master Sep 26, 2026
61 of 62 checks passed
@asvetlov
asvetlov deleted the getversion-64bit branch September 26, 2026 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided There is a change note present in this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant