This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eryksun
Recipients christian.heimes, eryksun, vstinner
Date 2021-11-28.18:25:34
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1638123934.19.0.140847870252.issue45915@roundup.psfhosted.org>
In-reply-to
Content
In Windows, GetFileType((HANDLE)_get_osfhandle(fd)) is several times faster than close(dup(fd)). For example:

#if defined(MS_WINDOWS)
    int type;
    _Py_BEGIN_SUPPRESS_IPH
    type = GetFileType((HANDLE)_get_osfhandle(fd));
    _Py_END_SUPPRESS_IPH
    return type != FILE_TYPE_UNKNOWN;
#endif

If the C file descriptor isn't assigned and flagged FOPEN, then _get_osfhandle() returns (intptr_t)-1. This is the pseudohandle value for the current process, so GetFileType() will fail with an invalid handle error, as expected.
History
Date User Action Args
2021-11-28 19:23:14eryksununlinkissue45915 messages
2021-11-28 18:25:34eryksunsetrecipients: + eryksun, vstinner, christian.heimes
2021-11-28 18:25:34eryksunsetmessageid: <1638123934.19.0.140847870252.issue45915@roundup.psfhosted.org>
2021-11-28 18:25:34eryksunlinkissue45915 messages
2021-11-28 18:25:34eryksuncreate