GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-78502: Add a trackfd parameter to mmap.mmap() on Windows by serhiy-storchaka · Pull Request #138238 · python/cpython

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Aug 29, 2025 •
edited by github-actions Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

If trackfd is False, the file handle corresponding to fileno will not be duplicated.

  • Issue: mmap.mmap() should not necessarily clone the file descriptor #78502

📚 Documentation preview 📚: https://cpython-previews--138238.org.readthedocs.build/

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@serhiy-storchaka
pythongh-78502: AAdd a trackfd parameter to mmap.mmap() on Windows
d1ce256
If trackfd is False, the file handle corresponding to fileno
will not be duplicated.
@serhiy-storchaka
serhiy-storchaka requested review from encukou and zooba August 29, 2025 09:15
@serhiy-storchaka
serhiy-storchaka requested a review from AA-Turner as a code owner August 29, 2025 09:15
@bedevere-app bedevere-app Bot added the awaiting core review label Aug 29, 2025
@bedevere-app bedevere-app Bot mentioned this pull request Aug 29, 2025
mmap.mmap() should not necessarily clone the file descriptor #78502
Closed
@serhiy-storchaka
pythongh-78502: AAdd a trackfd parameter to mmap.mmap() on Windows
558beef
If trackfd is False, the file handle corresponding to fileno
will not be duplicated.
@serhiy-storchaka
serhiy-storchaka force-pushed the mmap-trackfd-win branch from d1ce256 to 558beef Compare August 29, 2025 15:47
@serhiy-storchaka serhiy-storchaka added the 🔨 test-with-refleak-buildbots Test PR w/ refleak buildbots; report in status section label Aug 29, 2025
@bedevere-bot

bedevere-bot commented Aug 29, 2025

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @serhiy-storchaka for commit 558beef 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F138238%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-refleak-buildbots label again.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the 🔨 test-with-refleak-buildbots Test PR w/ refleak buildbots; report in status section label Aug 29, 2025
@serhiy-storchaka serhiy-storchaka changed the title gh-78502: AAdd a trackfd parameter to mmap.mmap() on Windows gh-78502: Add a trackfd parameter to mmap.mmap() on Windows Aug 29, 2025
encukou
encukou approved these changes Sep 1, 2025
View reviewed changes

@encukou encukou left a comment

Copy link
Copy Markdown
Member

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.

I'm not much of a Windows expert, but, the code looks good to me! Thank you!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels Sep 1, 2025
zooba
zooba reviewed Sep 1, 2025
View reviewed changes

@zooba zooba left a comment

Copy link
Copy Markdown
Member

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.

Other than that condition, looks fine to me.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Modules/mmapmodule.c Outdated

#ifdef MS_WINDOWS
if (self->file_handle != INVALID_HANDLE_VALUE) {
if (self->file_handle != INVALID_HANDLE_VALUE || !self->trackfd) {

@zooba zooba Sep 1, 2025

Copy link
Copy Markdown
Member

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.

I don't like combining an error condition check with a state check like this, it gives us a way to call GetFileSize(INVALID_HANDLE_VALUE, ...).

Maybe this should be && self->trackfd instead?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@serhiy-storchaka serhiy-storchaka Sep 2, 2025

Copy link
Copy Markdown
Member Author

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.

They both are state checks. The behavior is consistent with Posix -- if trackfd is false, we get an OSError. We could raise a different error, but then we need to change the Posix code too. Is it fine to do this in this PR, or better open a separate PR?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@zooba zooba Sep 2, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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.

We should never deliberately pass INVALID_HANDLE_VALUE to a Win32 API, but we might in this case because of the or condition.

If trackfd is false, we should just raise an error directly, rather than relying on the OS to generate an error code for us.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

serhiy-storchaka reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@vstinner vstinner Sep 2, 2025

Copy link
Copy Markdown
Member

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.

If trackfd is false, we should just raise an error directly, rather than relying on the OS to generate an error code for us.

I agree with that.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
serhiy-storchaka added 2 commits September 2, 2025 17:40
@serhiy-storchaka
Merge remote-tracking branch 'refs/remotes/origin/mmap-tracefd-win' i…
55359e0
…nto mmap-trackfd-win
@serhiy-storchaka
Merge branch 'main' into mmap-trackfd-win
3a37550
vstinner
vstinner approved these changes Sep 2, 2025
View reviewed changes

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

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.

LGTM

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Modules/mmapmodule.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Modules/mmapmodule.c Outdated

#ifdef MS_WINDOWS
if (self->file_handle != INVALID_HANDLE_VALUE) {
if (self->file_handle != INVALID_HANDLE_VALUE || !self->trackfd) {

@vstinner vstinner Sep 2, 2025

Copy link
Copy Markdown
Member

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.

If trackfd is false, we should just raise an error directly, rather than relying on the OS to generate an error code for us.

I agree with that.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
serhiy-storchaka and others added 2 commits September 2, 2025 18:43
@serhiy-storchaka
Raise ValueError for size() with trackfd=False.
0ee3c86
@serhiy-storchaka @vstinner
Update Modules/mmapmodule.c
ea85b30
Co-authored-by: Victor Stinner <[email protected]>
@serhiy-storchaka

serhiy-storchaka commented Sep 2, 2025

Copy link
Copy Markdown
Member Author

Before merging this PR, it would be convenient to merge #24781.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@serhiy-storchaka serhiy-storchaka mentioned this pull request Sep 2, 2025
mmap.size() raises OSError on Unix for anonymous memory #87595
Closed
@serhiy-storchaka
Merge branch 'main' into mmap-trackfd-win
ebcb3e3
@serhiy-storchaka
serhiy-storchaka merged commit 7274d07 into python:main Sep 3, 2025
@bedevere-app bedevere-app Bot removed the awaiting merge label Sep 3, 2025
@serhiy-storchaka
serhiy-storchaka deleted the mmap-trackfd-win branch September 3, 2025 08:31
lkollar pushed a commit to lkollar/cpython that referenced this pull request Sep 9, 2025
@serhiy-storchaka @lkollar
pythongh-78502: Add a trackfd parameter to mmap.mmap() on Windows (py…
1a3e61d
…thonGH-138238)

If trackfd is False, the file handle corresponding to fileno
will not be duplicated.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@zooba zooba zooba left review comments
@vstinner vstinner vstinner approved these changes
@encukou encukou encukou approved these changes
@AA-Turner AA-Turner Awaiting requested review from AA-Turner AA-Turner is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@serhiy-storchaka @bedevere-bot @vstinner @encukou @zooba
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.