make soft asserts better by allowing them to be used in expressions

This commit is contained in:
Simon Arlott 2017-07-29 17:37:53 +01:00
parent 3ec3b44c7e
commit b5ad4cdfde
No known key found for this signature in database
GPG key ID: C8975F2043CA5D24
2 changed files with 26 additions and 27 deletions

View file

@ -28,37 +28,37 @@
#include "defaults.h"
#ifdef SOFT_ASSERT
#include "logger.h"
#include "send.h"
#include "snomask.h"
#ifdef __GNUC__
#define s_assert(expr) do \
if(!(expr)) { \
#define ss_assert(expr) ( \
((expr)) || ( \
ilog(L_MAIN, \
"file: %s line: %d (%s): Assertion failed: (%s)", \
__FILE__, __LINE__, __PRETTY_FUNCTION__, #expr); \
__FILE__, __LINE__, __PRETTY_FUNCTION__, #expr), 0) || (\
sendto_realops_snomask(SNO_GENERAL, L_ALL, \
"file: %s line: %d (%s): Assertion failed: (%s)", \
__FILE__, __LINE__, __PRETTY_FUNCTION__, #expr); \
} \
while(0)
__FILE__, __LINE__, __PRETTY_FUNCTION__, #expr), 0) \
)
#else
#define s_assert(expr) do \
if(!(expr)) { \
#define ss_assert(expr) ( \
((expr)) || ( \
ilog(L_MAIN, \
"file: %s line: %d: Assertion failed: (%s)", \
__FILE__, __LINE__, #expr); \
__FILE__, __LINE__, #expr), 0) || ( \
sendto_realops_snomask(SNO_GENERAL, L_ALL, \
"file: %s line: %d: Assertion failed: (%s)" \
__FILE__, __LINE__, #expr); \
} \
while(0)
__FILE__, __LINE__, #expr), 0) \
)
#endif
/* evaluates to true if assertion fails */
#ifdef SOFT_ASSERT
#define s_assert(expr) (!ss_assert(expr))
#else
#define s_assert(expr) assert(expr)
#define s_assert(expr) (assert(ss_assert(expr)), 0)
#endif
#endif /* INCLUDED_s_assert_h */

View file

@ -128,27 +128,26 @@ char *rb_strerror(int error);
#endif
#ifdef __GNUC__
#define slrb_assert(expr) do \
if(rb_unlikely(!(expr))) { \
#define slrb_assert(expr) ( \
rb_likely((expr)) || ( \
rb_lib_log( \
"file: %s line: %d (%s): Assertion failed: (%s)", \
__FILE__, __LINE__, __PRETTY_FUNCTION__, #expr); \
} \
while(0)
__FILE__, __LINE__, __PRETTY_FUNCTION__, #expr), 0) \
)
#else
#define slrb_assert(expr) do \
if(rb_unlikely(!(expr))) { \
#define slrb_assert(expr) ( \
rb_likely((expr)) || ( \
rb_lib_log( \
"file: %s line: %d: Assertion failed: (%s)", \
__FILE__, __LINE__, #expr); \
} \
while(0)
__FILE__, __LINE__, #expr), 0) \
)
#endif
/* evaluates to true if assertion fails */
#ifdef SOFT_ASSERT
#define lrb_assert(expr) slrb_assert(expr)
#define lrb_assert(expr) (!slrb_assert(expr))
#else
#define lrb_assert(expr) do { slrb_assert(expr); assert(expr); } while(0)
#define lrb_assert(expr) (assert(slrb_assert(expr)), 0)
#endif
#ifdef RB_SOCKADDR_HAS_SA_LEN