r46894 - in python/trunk: Modules/timemodule.c Objects/exceptions.c Objects/fileobject.c
Author: kristjan.jonsson Date: Mon Jun 12 17:45:12 2006 New Revision: 46894 Modified: python/trunk/Modules/timemodule.c python/trunk/Objects/exceptions.c python/trunk/Objects/fileobject.c Log: Fix the CRT argument error handling for VisualStudio .NET 2005. Install a CRT error handler and disable the assertion for debug builds. This causes CRT to set errno to EINVAL. This update fixes crash cases in the test suite where the default CRT error handler would cause process exit. Modified: python/trunk/Modules/timemodule.c ============================================================================== --- python/trunk/Modules/timemodule.c (original) +++ python/trunk/Modules/timemodule.c Mon Jun 12 17:45:12 2006 @@ -467,6 +467,14 @@ return ret; } free(outbuf); +#if defined _MSC_VER && _MSC_VER >= 1400 + /* VisualStudio .NET 2005 does this properly */ + if (buflen == 0 && errno == EINVAL) { + PyErr_SetString(PyExc_ValueError, "Invalid format string"); + return 0; + } +#endif + } } Modified: python/trunk/Objects/exceptions.c ============================================================================== --- python/trunk/Objects/exceptions.c (original) +++ python/trunk/Objects/exceptions.c Mon Jun 12 17:45:12 2006 @@ -1967,6 +1967,29 @@ if (PyDict_SetItemString(bdict, # TYPE, PyExc_ ## TYPE)) \ Py_FatalError("Module dictionary insertion problem."); +#if defined _MSC_VER && _MSC_VER >= 1400 +/* crt variable checking in VisualStudio .NET 2005 */ +#include <crtdbg.h> + +static int prevCrtReportMode; +static _invalid_parameter_handler prevCrtHandler; + +/* Invalid parameter handler. Sets a ValueError exception */ +static void +InvalidParameterHandler( + const wchar_t * expression, + const wchar_t * function, + const wchar_t * file, + unsigned int line, + uintptr_t pReserved) +{ + /* Do nothing, allow execution to continue. Usually this + * means that the CRT will set errno to EINVAL + */ +} +#endif + + PyMODINIT_FUNC _PyExc_Init(void) { @@ -2096,6 +2119,13 @@ Py_FatalError("Cannot pre-allocate MemoryError instance\n"); Py_DECREF(bltinmod); + +#if defined _MSC_VER && _MSC_VER >= 1400 + /* Set CRT argument error handler */ + prevCrtHandler = _set_invalid_parameter_handler(InvalidParameterHandler); + /* turn off assertions in debug mode */ + prevCrtReportMode = _CrtSetReportMode(_CRT_ASSERT, 0); +#endif } void @@ -2103,4 +2133,9 @@ { Py_XDECREF(PyExc_MemoryErrorInst); PyExc_MemoryErrorInst = NULL; +#if defined _MSC_VER && _MSC_VER >= 1400 + /* reset CRT error handling */ + _set_invalid_parameter_handler(prevCrtHandler); + _CrtSetReportMode(_CRT_ASSERT, prevCrtReportMode); +#endif } Modified: python/trunk/Objects/fileobject.c ============================================================================== --- python/trunk/Objects/fileobject.c (original) +++ python/trunk/Objects/fileobject.c Mon Jun 12 17:45:12 2006 @@ -241,13 +241,15 @@ } if (f->f_fp == NULL) { -#ifdef _MSC_VER +#if defined _MSC_VER && _MSC_VER < 1400 /* MSVC 6 (Microsoft) leaves errno at 0 for bad mode strings, * across all Windows flavors. When it sets EINVAL varies * across Windows flavors, the exact conditions aren't * documented, and the answer lies in the OS's implementation * of Win32's CreateFile function (whose source is secret). * Seems the best we can do is map EINVAL to ENOENT. + * Starting with Visual Studio .NET 2005, EINVAL is correctly + * set by our CRT error handler (set in exceptions.c.) */ if (errno == 0) /* bad mode string */ errno = EINVAL;
kristjan.jonsson schrieb:
Author: kristjan.jonsson Date: Mon Jun 12 17:45:12 2006 New Revision: 46894
Modified: python/trunk/Modules/timemodule.c python/trunk/Objects/exceptions.c python/trunk/Objects/fileobject.c Log: Fix the CRT argument error handling for VisualStudio .NET 2005. Install a CRT error handler and disable the assertion for debug builds. This causes CRT to set errno to EINVAL. This update fixes crash cases in the test suite where the default CRT error handler would cause process exit. ... Modified: python/trunk/Objects/exceptions.c ============================================================================== --- python/trunk/Objects/exceptions.c (original) +++ python/trunk/Objects/exceptions.c Mon Jun 12 17:45:12 2006 @@ -1967,6 +1967,29 @@ if (PyDict_SetItemString(bdict, # TYPE, PyExc_ ## TYPE)) \ Py_FatalError("Module dictionary insertion problem.");
+#if defined _MSC_VER && _MSC_VER >= 1400 +/* crt variable checking in VisualStudio .NET 2005 */ +#include <crtdbg.h> + +static int prevCrtReportMode; +static _invalid_parameter_handler prevCrtHandler; + +/* Invalid parameter handler. Sets a ValueError exception */ +static void +InvalidParameterHandler( + const wchar_t * expression, + const wchar_t * function, + const wchar_t * file, + unsigned int line, + uintptr_t pReserved) +{ + /* Do nothing, allow execution to continue. Usually this + * means that the CRT will set errno to EINVAL + */ +} +#endif + + PyMODINIT_FUNC _PyExc_Init(void) { @@ -2096,6 +2119,13 @@ Py_FatalError("Cannot pre-allocate MemoryError instance\n");
Py_DECREF(bltinmod); + +#if defined _MSC_VER && _MSC_VER >= 1400 + /* Set CRT argument error handler */ + prevCrtHandler = _set_invalid_parameter_handler(InvalidParameterHandler); + /* turn off assertions in debug mode */ + prevCrtReportMode = _CrtSetReportMode(_CRT_ASSERT, 0); +#endif }
void @@ -2103,4 +2133,9 @@ { Py_XDECREF(PyExc_MemoryErrorInst); PyExc_MemoryErrorInst = NULL; +#if defined _MSC_VER && _MSC_VER >= 1400 + /* reset CRT error handling */ + _set_invalid_parameter_handler(prevCrtHandler); + _CrtSetReportMode(_CRT_ASSERT, prevCrtReportMode); +#endif } ...
These changes to Objects/exceptions.c break the build for Windows AMD64. Apparently the amd64 compiler from the Server 2003 SP1 SDK has _MSC_VER >= 1400, but does not know about this new error handling. The compiler identifies itself in this way: C:\Program Files\Microsoft Platform SDK>cl Microsoft (R) C/C++ Optimizing Compiler Version 14.00.40310.41 for AMD64 Copyright (C) Microsoft Corporation. All rights reserved. usage: cl [ option... ] filename... [ /link linkoption... ] C:\Program Files\Microsoft Platform SDK> Thomas
Copying Kristján directly since he may not be subscribed to python-checkins. On 6/30/06, Thomas Heller <theller@python.net> wrote:
kristjan.jonsson schrieb:
Author: kristjan.jonsson Date: Mon Jun 12 17:45:12 2006 New Revision: 46894
Modified: python/trunk/Modules/timemodule.c python/trunk/Objects/exceptions.c python/trunk/Objects/fileobject.c Log: Fix the CRT argument error handling for VisualStudio .NET 2005. Install a CRT error handler and disable the assertion for debug builds. This causes CRT to set errno to EINVAL. This update fixes crash cases in the test suite where the default CRT error handler would cause process exit. ... Modified: python/trunk/Objects/exceptions.c ============================================================================== --- python/trunk/Objects/exceptions.c (original) +++ python/trunk/Objects/exceptions.c Mon Jun 12 17:45:12 2006 @@ -1967,6 +1967,29 @@ if (PyDict_SetItemString(bdict, # TYPE, PyExc_ ## TYPE)) \ Py_FatalError("Module dictionary insertion problem.");
+#if defined _MSC_VER && _MSC_VER >= 1400 +/* crt variable checking in VisualStudio .NET 2005 */ +#include <crtdbg.h> + +static int prevCrtReportMode; +static _invalid_parameter_handler prevCrtHandler; + +/* Invalid parameter handler. Sets a ValueError exception */ +static void +InvalidParameterHandler( + const wchar_t * expression, + const wchar_t * function, + const wchar_t * file, + unsigned int line, + uintptr_t pReserved) +{ + /* Do nothing, allow execution to continue. Usually this + * means that the CRT will set errno to EINVAL + */ +} +#endif + + PyMODINIT_FUNC _PyExc_Init(void) { @@ -2096,6 +2119,13 @@ Py_FatalError("Cannot pre-allocate MemoryError instance\n");
Py_DECREF(bltinmod); + +#if defined _MSC_VER && _MSC_VER >= 1400 + /* Set CRT argument error handler */ + prevCrtHandler = _set_invalid_parameter_handler(InvalidParameterHandler); + /* turn off assertions in debug mode */ + prevCrtReportMode = _CrtSetReportMode(_CRT_ASSERT, 0); +#endif }
void @@ -2103,4 +2133,9 @@ { Py_XDECREF(PyExc_MemoryErrorInst); PyExc_MemoryErrorInst = NULL; +#if defined _MSC_VER && _MSC_VER >= 1400 + /* reset CRT error handling */ + _set_invalid_parameter_handler(prevCrtHandler); + _CrtSetReportMode(_CRT_ASSERT, prevCrtReportMode); +#endif } ...
These changes to Objects/exceptions.c break the build for Windows AMD64. Apparently the amd64 compiler from the Server 2003 SP1 SDK has _MSC_VER >= 1400, but does not know about this new error handling.
The compiler identifies itself in this way:
C:\Program Files\Microsoft Platform SDK>cl Microsoft (R) C/C++ Optimizing Compiler Version 14.00.40310.41 for AMD64 Copyright (C) Microsoft Corporation. All rights reserved.
usage: cl [ option... ] filename... [ /link linkoption... ]
C:\Program Files\Microsoft Platform SDK>
Thomas
_______________________________________________ Python-checkins mailing list Python-checkins@python.org http://mail.python.org/mailman/listinfo/python-checkins
Tim Peters schrieb:
Copying Kristján directly since he may not be subscribed to python-checkins.
[off-topic, sorry] I would have done this myself, but I cannot log into the starship to send or receive mail. Does anyone know what's up? Thomas
Thomas Heller <theller@python.net> writes:
Tim Peters schrieb:
Copying Kristján directly since he may not be subscribed to python-checkins.
[off-topic, sorry]
I would have done this myself, but I cannot log into the starship to send or receive mail. Does anyone know what's up?
The server moved. It should work now (unless your ISP has been fooled by the overly long TTL that was on the python.net DNS record until too recently; the new IP address is 87.106.17.236). Cheers, mwh -- There are two ways of constructing a software design: one way is to make it so simple that there are obviously no deficiencies and the other way is to make it so complicated that there are no obvious deficiencies. -- C. A. R. Hoare
Thomas Heller wrote:
These changes to Objects/exceptions.c break the build for Windows AMD64. Apparently the amd64 compiler from the Server 2003 SP1 SDK has _MSC_VER >= 1400, but does not know about this new error handling.
I've a pending patch on my machine to fix that; no time yet to commit it. That patch got included into the 2.5b1 binaries that I created for AMD64. Regards, Martin
participants (5)
-
"Martin v. Löwis"
-
kristjan.jonsson
-
Michael Hudson
-
Thomas Heller
-
Tim Peters