Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppresses the tcheck_version test's abort dialog on Windows #477

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions test/tcheck_version.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@

#include "h5test.h"

#ifdef H5_HAVE_WIN32_API
#include <crtdbg.h>
#endif

#define progname "tcheck_version"

/* prototypes */
Expand Down Expand Up @@ -108,12 +112,31 @@ abort_intercept(int H5_ATTR_UNUSED sig)
HDexit(6);
}

#ifdef H5_HAVE_WIN32_API
/* Turns off the modal dialog that is raised when the Windows CRT calls abort().
*
* Returning TRUE here lets Windows know that we've handled the abort() and that there
* is no need to alert the user with a modal dialog box.
*/
int __cdecl
handle_crt_abort(int reportType, char *message, int *returnValue)
{
return TRUE;
}
#endif

int
main(int ac, char **av)
{
#ifdef H5_HAVE_WIN32_API
(void)_CrtSetReportHook2(_CRT_RPTHOOK_INSTALL, handle_crt_abort);
#endif
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to check the return value since the test will be correct (albeit with the modal dialog box popping up) even if this call fails for some reason.

parse(ac, av);
HDsignal(SIGABRT, &abort_intercept);
H5check_version(major, minor, release);
HDsignal(SIGABRT, SIG_DFL);
#ifdef H5_HAVE_WIN32_API
(void)_CrtSetReportHook2(_CRT_RPTHOOK_REMOVE, handle_crt_abort);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uninstalling the handler is overkill in this simple program, but that's the pattern to use on the off chance this gets cut-n-pasted someplace else.

#endif
return 0;
}