Skip to content

Commit 1aa4599

Browse files
stinosdpgeorge
authored andcommitted
windows/msvc: Nicer handling of asserts and 'invalid' parameters
The default bahaviour for debug builds is to show dialog boxes for asserts and invalid parameter handling. This is not so nice in general and causes the Appveyor debug builds to hang because the io\file_seek.py test passes a closed file descriptor to lseek. Disable this behaviour by printing assert messages to the output instead of showing the dialog, and by disabling 'invalid' parameter handling which causes the affected functions to just return an error and set errno appropriately.
1 parent bbe8d51 commit 1aa4599

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

windows/init.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,31 @@
2727
#include <stdlib.h>
2828
#include <stdio.h>
2929
#include <windows.h>
30+
#ifdef _MSC_VER
31+
#include <crtdbg.h>
32+
#endif
3033
#include "sleep.h"
3134

3235
extern BOOL WINAPI console_sighandler(DWORD evt);
3336

37+
#ifdef _MSC_VER
38+
void invalid_param_handler(const wchar_t *expr, const wchar_t *fun, const wchar_t *file, unsigned int line, uintptr_t p) {
39+
}
40+
#endif
41+
3442
void init() {
43+
#ifdef _MSC_VER
44+
// Disable the 'Debug Error!' dialog for assertions failures and the likes,
45+
// instead write messages to the debugger output and terminate.
46+
_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG);
47+
_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_DEBUG);
48+
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_DEBUG);
49+
50+
// Disable 'invalid parameter handling' which is for instance invoked when
51+
// passing invalid file descriptors to functions like lseek() and make the
52+
// functions called behave properly by setting errno to EBADF/EINVAL/..
53+
_set_invalid_parameter_handler(invalid_param_handler);
54+
#endif
3555
SetConsoleCtrlHandler(console_sighandler, TRUE);
3656
init_sleep();
3757
#ifdef __MINGW32__

0 commit comments

Comments
 (0)