Skip to content

Conversation

serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Aug 29, 2025

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


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

If trackfd is False, the file handle corresponding to fileno
will not be duplicated.
If trackfd is False, the file handle corresponding to fileno
will not be duplicated.
@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
Copy link

🤖 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.

@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
Copy link
Member

@encukou encukou left a 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!

Copy link
Member

@zooba zooba left a 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.


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

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?

Copy link
Member Author

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?

Copy link
Member

@zooba zooba Sep 2, 2025

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.

Copy link
Member

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.

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM


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

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.

@serhiy-storchaka
Copy link
Member Author

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

@serhiy-storchaka serhiy-storchaka merged commit 7274d07 into python:main Sep 3, 2025
45 checks passed
@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
…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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants