Message 81321 - Python tracker (original) (raw)
I think the comment (an invalid fd would be a C program bug) misrepresents the facts. Please don't check it in as-is. An invalid file descriptor is not assertable. The authority on file descriptors, the POSIX standard, specifies for, say, write(2)
[...] Otherwise, -1 shall be returned and errno set to indicate the error. [...] [EBADF] The fildes argument is not a valid file descriptor open for writing.
This is consistent throughout the entire API: the behavior for invalid file descriptors is not undefined, and not even implementation-defined. If the CRT would conform to the relevant, long-existing specifications it tries to emulate, it would just set errno to EBADF, and be done.
There should be a global declaration of _Py_verify_fd. I would also suggest that it becomes a constant macro unless _MSC_VER is defined.