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 mloskot
Recipients V.E.O, amaury.forgeotdarc, brian.curtin, christian.heimes, m_python, mloskot, pitrou, tim.golden, tim.peters, vstinner
Date 2013-09-11.23:49:27
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <CABUeae8ivnk+RW6snfQaMS6z1LU-9q3GBW9KzYHqcV-YCStVrA@mail.gmail.com>
In-reply-to <1378940779.37.0.366976705889.issue17797@psf.upfronthosting.co.za>
Content
On 12 September 2013 00:06, Antoine Pitrou <report@bugs.python.org> wrote:
>> Shortly, is_valid_fd always returns true because fd < 0 is always
>> false as my tests with Visual Studio 2012
>
> Well, that's not all there is, is_valid_fd() does other checks before returning true.

Given the function:

is_valid_fd(int fd)
{
    int dummy_fd;
    if (fd < 0 || !_PyVerify_fd(fd))
        return 0;
    dummy_fd = dup(fd);
    if (dummy_fd < 0)
        return 0;
    close(dummy_fd);
    return 1;
}

for fd values of 0, 1 or 2

1. fd < 0 is always false
2. _PyVerify_fd(fd) is always true. Given the current definition:
#define _PyVerify_fd(fd) (_get_osfhandle(fd) >= 0)
for those values of fd _get_osfhandle(fd) >= 0, always.
3. for those fd values, dup() never returns fd < 0
History
Date User Action Args
2013-09-11 23:49:27mloskotsetrecipients: + mloskot, tim.peters, amaury.forgeotdarc, pitrou, vstinner, christian.heimes, tim.golden, brian.curtin, V.E.O, m_python
2013-09-11 23:49:27mloskotlinkissue17797 messages
2013-09-11 23:49:27mloskotcreate