Enable exceptions raising on assert on Win32

This patch changes the Win32 version to call RaiseException instead of abort
(which eventually calls TerminateProcess). This allows crash dumps to be sent
correctly instead of the process disappearing.

Signed-off-by: Paul Betts <paul@paulbetts.org>
This commit is contained in:
Paul Betts 2011-10-27 11:48:58 +02:00 committed by Martin Sustrik
parent b3cda2ad60
commit 1b706ac028
2 changed files with 27 additions and 12 deletions

View File

@ -62,6 +62,19 @@ const char *zmq::errno_to_string (int errno_)
}
}
void zmq::zmq_abort(const char *errmsg_)
{
#if defined ZMQ_HAVE_WINDOWS
// Raise STATUS_FATAL_APP_EXIT.
ULONG_PTR extra_info [1];
extra_info [0] = (ULONG_PTR) errmsg_;
RaiseException (0x40000015, EXCEPTION_NONCONTINUABLE, 1, extra_info);
#else
abort ();
#endif
}
#ifdef ZMQ_HAVE_WINDOWS
const char *zmq::wsa_error()

View File

@ -42,6 +42,7 @@
namespace zmq
{
const char *errno_to_string (int errno_);
void zmq_abort (const char *errmsg_);
}
#ifdef ZMQ_HAVE_WINDOWS
@ -62,7 +63,7 @@ namespace zmq
if (errstr != NULL) {\
fprintf (stderr, "Assertion failed: %s (%s:%d)\n", errstr, \
__FILE__, __LINE__);\
abort ();\
zmq::zmq_abort (errstr);\
}\
}\
} while (false)
@ -74,7 +75,7 @@ namespace zmq
if (errstr != NULL) {\
fprintf (stderr, "Assertion failed: %s (%s:%d)\n", errstr, \
__FILE__, __LINE__);\
abort ();\
zmq::zmq_abort (errstr);\
}\
} while (false)
@ -86,7 +87,7 @@ namespace zmq
zmq::win_error (errstr, 256);\
fprintf (stderr, "Assertion failed: %s (%s:%d)\n", errstr, \
__FILE__, __LINE__);\
abort ();\
zmq::zmq_abort (errstr);\
}\
} while (false)
@ -100,7 +101,7 @@ namespace zmq
if (unlikely (!(x))) {\
fprintf (stderr, "Assertion failed: %s (%s:%d)\n", #x, \
__FILE__, __LINE__);\
abort ();\
zmq::zmq_abort (#x);\
}\
} while (false)
@ -108,9 +109,9 @@ namespace zmq
#define errno_assert(x) \
do {\
if (unlikely (!(x))) {\
perror (NULL);\
fprintf (stderr, "%s (%s:%d)\n", #x, __FILE__, __LINE__);\
abort ();\
const char *errstr = strerror (errno);\
fprintf (stderr, "%s (%s:%d)\n", errstr, __FILE__, __LINE__);\
zmq::zmq_abort (errstr);\
}\
} while (false)
@ -118,8 +119,9 @@ namespace zmq
#define posix_assert(x) \
do {\
if (unlikely (x)) {\
fprintf (stderr, "%s (%s:%d)\n", strerror (x), __FILE__, __LINE__);\
abort ();\
const char *errstr = strerror (x);\
fprintf (stderr, "%s (%s:%d)\n", errstr, __FILE__, __LINE__);\
zmq::zmq_abort (errstr);\
}\
} while (false)
@ -129,7 +131,7 @@ namespace zmq
if (unlikely (x)) {\
const char *errstr = gai_strerror (x);\
fprintf (stderr, "%s (%s:%d)\n", errstr, __FILE__, __LINE__);\
abort ();\
zmq::zmq_abort (errstr);\
}\
} while (false)
@ -139,7 +141,7 @@ namespace zmq
if (unlikely (!x)) {\
fprintf (stderr, "FATAL ERROR: OUT OF MEMORY (%s:%d)\n",\
__FILE__, __LINE__);\
abort ();\
zmq::zmq_abort ("FATAL ERROR: OUT OF MEMORY");\
}\
} while (false)