-
-
Notifications
You must be signed in to change notification settings - Fork 32.7k
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
base: main
Are you sure you want to change the base?
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just two random thoughts!
Lib/multiprocessing/heap.py
Outdated
raise ValueError("Size {0:n} out of range".format(size)) | ||
if sys.maxsize <= size: | ||
raise OverflowError("Size {0:n} too large".format(size)) | ||
Heap._validate_size(size) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it's better to move the _validate_size
to the module level, to avoid coupling between BufferWrapper
and a private method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that was one of the options I had in mind. Thinking it over, moving it to the module level does reduce the coupling. I'll update the PR accordingly.
Lib/multiprocessing/heap.py
Outdated
raise ValueError("Size {0:n} out of range".format(size)) | ||
if sys.maxsize <= size: | ||
raise OverflowError("Size {0:n} too large".format(size)) | ||
Heap._validate_size(size) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heap._validate_size(size) | |
self._validate_size(size) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will no longer apply when moving it to the module level, but thanks for the suggestion
gh-137928: Refactor to centralize size validation in multiprocessing.heap
Summary
This PR refactors the
multiprocessing.heap
module by centralizing size validation into a module-level helper function (_validate_size
).Previously, the same validation logic was duplicated in both
Heap.malloc()
andBufferWrapper.__init__()
.Changes
_validate_size(size)
at module level.Heap.malloc()
andBufferWrapper.__init__()
to use this helper instead of duplicating the validation logic.Impact