summaryrefslogtreecommitdiffstats
path: root/Objects/exceptions.c
diff options
context:
space:
mode:
authorKristján Valur Jónsson <kristjan@ccpgames.com>2006-06-12 15:45:12 (GMT)
committerKristján Valur Jónsson <kristjan@ccpgames.com>2006-06-12 15:45:12 (GMT)
commitf608317061cc11de915f55da8c59880dc02e6d94 (patch)
treef018e0f56ed59b1fd2eb80f7bf5f9c0075712bdf /Objects/exceptions.c
parent81f444bb8eca9caedc884caf566c76233762077e (diff)
downloadcpython-f608317061cc11de915f55da8c59880dc02e6d94.zip
cpython-f608317061cc11de915f55da8c59880dc02e6d94.tar.gz
cpython-f608317061cc11de915f55da8c59880dc02e6d94.tar.bz2
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.
Diffstat (limited to 'Objects/exceptions.c')
-rw-r--r--Objects/exceptions.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/Objects/exceptions.c b/Objects/exceptions.c
index 369365b..38d7350 100644
--- a/Objects/exceptions.c
+++ b/Objects/exceptions.c
@@ -1967,6 +1967,29 @@ static PyMethodDef functions[] = {
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 @@ _PyExc_Init(void)
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 @@ _PyExc_Fini(void)
{
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
}