[issue4804] Python on Windows disables all C runtime library assertions

Kristján Valur Jónsson report at bugs.python.org
Mon Feb 9 16:17:29 CET 2009


Kristján Valur Jónsson <kristjan at ccpgames.com> added the comment:

Ok, how about this comment, Martin?

/* Microsoft CRT in VS2005 and higher will verify that a filehandle is
 * valid and throw an assertion if it isn't.
 * Normally, an invalid fd is likely to be a C program error and 
therefore
 * an assertion can be useful, but it does contradict the POSIX standard
 * which for write(2) states:
 *    "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."
 * Furthermore, python allows the user to enter any old integer
 * as a fd and should merely raise a python exception on error.
 * The Microsoft CRT doesn't provide an official way to check for the
 * validity of a file descriptor, but we can emulate its internal 
behaviour
 * by using the exported __pinfo data member and knowledge of the 
 * internal structures involved.
 * The structures below must be updated for each version of visual 
studio
 * according to the file internal.h in the CRT source, until MS comes
 * up with a less hacky way to do this.
 * (all of this is to avoid globally modifying the CRT behaviour using
 * _set_invalid_parameter_handler() and _CrtSetReportMode())
 */

Also, I've added the following to fileobject.h, not coming up with a 
better place:

#if defined _MSC_VER && _MSC_VER >= 1400
/* A routine to check if a file descriptor is valid on Windows.  
Returns 0
 * and sets errno to EBADF if it isn't.  This is to avoid Assertions
 * from various functions in the Windows CRT beginning with
 * Visual Studio 2005
 */
int _PyVerify_fd(int fd);
#else
#define _PyVerify_fd(A) (1) /* dummy */
#endif

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4804>
_______________________________________


More information about the Python-bugs-list mailing list