Skip to content

gh-137928: Centralize size validation in multiprocessing.heap #137929

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

acabelloj
Copy link

gh-137928: Refactor to centralize size validation in multiprocessing.heap

Summary

This PR refactors the multiprocessing.heap module by centralizing size validation into a private static method (Heap._validate_size).
Previously, the same validation logic was duplicated in both Heap.malloc() and BufferWrapper.__init__().

Changes

  • Introduced Heap._validate_size(size, _maxsize=sys.maxsize).
  • Updated malloc() and BufferWrapper.__init__() to use this method.
  • Bound sys.maxsize at definition time to avoid repeated global lookups.

Impact

  • No behavior or API changes.
  • Internal refactor only: reduces duplication, improves maintainability, and ensures consistent validation across the module.
  • Existing tests already cover these code paths.

@acabelloj acabelloj requested a review from gpshead as a code owner August 18, 2025 21:43
@python-cla-bot
Copy link

python-cla-bot bot commented Aug 18, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app

This comment was marked as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting review skip news type-refactor Code refactoring (with no changes in behavior)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants