-
-
Notifications
You must be signed in to change notification settings - Fork 32.6k
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!
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?
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) |
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()
andBufferWrapper.__init__()
.Changes
Heap._validate_size(size, _maxsize=sys.maxsize)
.malloc()
andBufferWrapper.__init__()
to use this method.sys.maxsize
at definition time to avoid repeated global lookups.Impact