Commit a8362abf authored by Martin Sustrik's avatar Martin Sustrik

Enable exceptions raising on assert on Win32

Signed-off-by: 's avatarMartin Sustrik <sustrik@250bpm.com>
parent a70bea01
...@@ -62,6 +62,19 @@ const char *zmq::errno_to_string (int errno_) ...@@ -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 #ifdef ZMQ_HAVE_WINDOWS
const char *zmq::wsa_error() const char *zmq::wsa_error()
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
namespace zmq namespace zmq
{ {
const char *errno_to_string (int errno_); const char *errno_to_string (int errno_);
void zmq_abort (const char *errmsg_);
} }
#ifdef ZMQ_HAVE_WINDOWS #ifdef ZMQ_HAVE_WINDOWS
...@@ -51,7 +52,7 @@ namespace zmq ...@@ -51,7 +52,7 @@ namespace zmq
const char *wsa_error (); const char *wsa_error ();
const char *wsa_error_no (int no_); const char *wsa_error_no (int no_);
void win_error (char *buffer_, size_t buffer_size_); void win_error (char *buffer_, size_t buffer_size_);
void wsa_error_to_errno (); void wsa_error_to_errno ();
} }
// Provides convenient way to check WSA-style errors on Windows. // Provides convenient way to check WSA-style errors on Windows.
...@@ -62,7 +63,7 @@ namespace zmq ...@@ -62,7 +63,7 @@ namespace zmq
if (errstr != NULL) {\ if (errstr != NULL) {\
fprintf (stderr, "Assertion failed: %s (%s:%d)\n", errstr, \ fprintf (stderr, "Assertion failed: %s (%s:%d)\n", errstr, \
__FILE__, __LINE__);\ __FILE__, __LINE__);\
abort ();\ zmq::zmq_abort (errstr);\
}\ }\
}\ }\
} while (false) } while (false)
...@@ -74,7 +75,7 @@ namespace zmq ...@@ -74,7 +75,7 @@ namespace zmq
if (errstr != NULL) {\ if (errstr != NULL) {\
fprintf (stderr, "Assertion failed: %s (%s:%d)\n", errstr, \ fprintf (stderr, "Assertion failed: %s (%s:%d)\n", errstr, \
__FILE__, __LINE__);\ __FILE__, __LINE__);\
abort ();\ zmq::zmq_abort (errstr);\
}\ }\
} while (false) } while (false)
...@@ -86,7 +87,7 @@ namespace zmq ...@@ -86,7 +87,7 @@ namespace zmq
zmq::win_error (errstr, 256);\ zmq::win_error (errstr, 256);\
fprintf (stderr, "Assertion failed: %s (%s:%d)\n", errstr, \ fprintf (stderr, "Assertion failed: %s (%s:%d)\n", errstr, \
__FILE__, __LINE__);\ __FILE__, __LINE__);\
abort ();\ zmq::zmq_abort (errstr);\
}\ }\
} while (false) } while (false)
...@@ -100,7 +101,7 @@ namespace zmq ...@@ -100,7 +101,7 @@ namespace zmq
if (unlikely (!(x))) {\ if (unlikely (!(x))) {\
fprintf (stderr, "Assertion failed: %s (%s:%d)\n", #x, \ fprintf (stderr, "Assertion failed: %s (%s:%d)\n", #x, \
__FILE__, __LINE__);\ __FILE__, __LINE__);\
abort ();\ zmq::zmq_abort (#x);\
}\ }\
} while (false) } while (false)
...@@ -108,9 +109,9 @@ namespace zmq ...@@ -108,9 +109,9 @@ namespace zmq
#define errno_assert(x) \ #define errno_assert(x) \
do {\ do {\
if (unlikely (!(x))) {\ if (unlikely (!(x))) {\
perror (NULL);\ const char *errstr = strerror (errno);\
fprintf (stderr, "%s (%s:%d)\n", #x, __FILE__, __LINE__);\ fprintf (stderr, "%s (%s:%d)\n", errstr, __FILE__, __LINE__);\
abort ();\ zmq::zmq_abort (errstr);\
}\ }\
} while (false) } while (false)
...@@ -118,8 +119,9 @@ namespace zmq ...@@ -118,8 +119,9 @@ namespace zmq
#define posix_assert(x) \ #define posix_assert(x) \
do {\ do {\
if (unlikely (x)) {\ if (unlikely (x)) {\
fprintf (stderr, "%s (%s:%d)\n", strerror (x), __FILE__, __LINE__);\ const char *errstr = strerror (x);\
abort ();\ fprintf (stderr, "%s (%s:%d)\n", errstr, __FILE__, __LINE__);\
zmq::zmq_abort (errstr);\
}\ }\
} while (false) } while (false)
...@@ -129,7 +131,7 @@ namespace zmq ...@@ -129,7 +131,7 @@ namespace zmq
if (unlikely (x)) {\ if (unlikely (x)) {\
const char *errstr = gai_strerror (x);\ const char *errstr = gai_strerror (x);\
fprintf (stderr, "%s (%s:%d)\n", errstr, __FILE__, __LINE__);\ fprintf (stderr, "%s (%s:%d)\n", errstr, __FILE__, __LINE__);\
abort ();\ zmq::zmq_abort (errstr);\
}\ }\
} while (false) } while (false)
...@@ -139,7 +141,7 @@ namespace zmq ...@@ -139,7 +141,7 @@ namespace zmq
if (unlikely (!x)) {\ if (unlikely (!x)) {\
fprintf (stderr, "FATAL ERROR: OUT OF MEMORY (%s:%d)\n",\ fprintf (stderr, "FATAL ERROR: OUT OF MEMORY (%s:%d)\n",\
__FILE__, __LINE__);\ __FILE__, __LINE__);\
abort ();\ zmq::zmq_abort ("FATAL ERROR: OUT OF MEMORY");\
}\ }\
} while (false) } while (false)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment