GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — gh-138205: Remove the resize method on mmap object on platforms don't support it by aisk · Pull Request #138276 · python/cpython Conversation
|
| @unittest.skipUnless(hasattr(mmap.mmap, 'resize'), 'requires mmap.resize') | ||
| def test_resize(self): | ||
| # Create a file to be mmap'ed. | ||
| f = open(TESTFN, 'bw+') |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
We can simply use with open(...) as f.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| f = open(TESTFN, 'rb') | ||
| try: |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
with
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| try: | ||
| m.resize(2*mapsize) | ||
| except SystemError: # resize is not universally supported | ||
| except AttributeError: # resize is not universally supported |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
- # Ensuring that readonly mmap can't be resized - try: - m.resize(2*mapsize) - except SystemError: # resize is not universally supported - pass - except TypeError: - pass - else: - self.fail("Able to resize readonly memory map") + if hasattr(m, 'resize'): + # Ensuring that readonly mmap can't be resized + with self.assertRaises(TypeError): + m.resize(2*mapsize)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| try: | ||
| m.resize(512) | ||
| except SystemError: | ||
| except AttributeError: |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Simply use if hasattr(m, 'resize').
- # Try resizing map - try: + if hasattr(m, 'resize'): m.resize(512) - except SystemError: - pass - else: - # resize() is supported
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| return 0; | ||
|
|
||
| } | ||
| #endif /* defined(MS_WINDOWS) || defined(HAVE_MREMAP) */ |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
We usually write this simpler:
| #endif /* defined(MS_WINDOWS) || defined(HAVE_MREMAP) */ | |
| #endif /* MS_WINDOWS || HAVE_MREMAP */ |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| #endif /* UNIX */ | ||
| } | ||
| } | ||
| #endif /* defined(MS_WINDOWS) || defined(HAVE_MREMAP) */ |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
As above.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| pagefile) will silently create a new map with the original data copied over | ||
| up to the length of the new size. | ||
|
|
||
| .. availability:: Linux, Windows |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
It is also available on other platforms (e.g. FreeBSD).
See how this is documented for madvise().
Sorry, something went wrong.
There was an error while loading. Please reload this page.
91cda99 to
b1241ab
Compare
|
Sorry for the force-push. I messed up the conflict resolution during the merge and had to redo the merge after the push. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM. 👍
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Co-authored-by: Serhiy Storchaka <[email protected]>
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Co-authored-by: Victor Stinner <[email protected]>
Co-authored-by: Victor Stinner <[email protected]>
…orms don't support it (python#138276) Co-authored-by: Serhiy Storchaka <[email protected]> Co-authored-by: Victor Stinner <[email protected]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.