-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
gh-142419: Add mmap.set_name method for user custom annotation #142480
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
corona10
wants to merge
23
commits into
python:main
Choose a base branch
from
corona10:gh-142419
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+132
−2
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
f19909e
gh-142419: Add mmap.set_name method for annotation
corona10 c65e691
Merge remote-tracking branch 'upstream/main' into gh-142419
corona10 d354eba
nit
corona10 91d4aea
nit
corona10 5919851
Add test
corona10 6c13efc
Update Docs
corona10 5586acd
Update
corona10 73ac4b9
nit
corona10 a931201
nit
corona10 831bd7e
lint
corona10 c7185f0
nit
corona10 3a2654d
Apply suggestions from code review
corona10 cc3cf8a
Update Doc/library/mmap.rst
corona10 bd02cc5
Address code review
corona10 fa52b0e
Addrss code review
corona10 73bf762
fix
corona10 94d0268
nit
corona10 a9df12f
Apply suggestions from code review
corona10 2d6d632
Address code review
corona10 ca4bcec
Fix test
corona10 987cf09
Apply suggestions from code review
corona10 2a5d9a4
Address code review
corona10 9adcf8e
Update Modules/mmapmodule.c
corona10 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1165,6 +1165,36 @@ def test_flush_parameters(self): | |
| m.flush(PAGESIZE) | ||
| m.flush(PAGESIZE, PAGESIZE) | ||
|
|
||
| @unittest.skipUnless(sys.platform == 'linux', 'Linux only') | ||
| @support.requires_linux_version(5, 17, 0) | ||
| def test_set_name(self): | ||
| # Test setting name on anonymous mmap | ||
| m = mmap.mmap(-1, PAGESIZE) | ||
| self.addCleanup(m.close) | ||
| result = m.set_name('test_mapping') | ||
| self.assertIsNone(result) | ||
corona10 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # Test name length limit (80 chars including prefix "cpython:mmap:") | ||
| # Prefix is 13 chars, so max name is 67 chars | ||
| long_name = 'x' * 67 | ||
| result = m.set_name(long_name) | ||
| self.assertIsNone(result) | ||
|
|
||
| # Test name too long | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a test with NUL bytes inside it? |
||
| too_long_name = 'x' * 68 | ||
| with self.assertRaises(ValueError): | ||
| m.set_name(too_long_name) | ||
|
|
||
| # Test that file-backed mmap raises error | ||
| with open(TESTFN, 'wb+') as f: | ||
| f.write(b'x' * PAGESIZE) | ||
| f.flush() | ||
| m2 = mmap.mmap(f.fileno(), PAGESIZE) | ||
| self.addCleanup(m2.close) | ||
|
|
||
| with self.assertRaises(ValueError): | ||
| m2.set_name('should_fail') | ||
|
|
||
|
|
||
| class LargeMmapTests(unittest.TestCase): | ||
|
|
||
|
|
||
3 changes: 3 additions & 0 deletions
3
Misc/NEWS.d/next/Library/2025-12-10-02-31-43.gh-issue-142419.C8_LES.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| :meth:`mmap.mmap.set_name` method added to annotate an anonymous memory map | ||
| if Linux kernel supports ``PR_SET_VMA_ANON_NAME`` (Linux 5.17 or newer). | ||
| Patch by Donghee Na. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.