Skip to content

Commit

Permalink
alter code so it can compile in c++ as well (#395)
Browse files Browse the repository at this point in the history
* Alter header code so it can compile in c++ as well
* Allow constant expressions in AWS_ASSERT
  • Loading branch information
graebm authored May 30, 2019
1 parent 07bcb2c commit 0bebfbc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
40 changes: 23 additions & 17 deletions include/aws/common/assert.inl
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,35 @@ void aws_backtrace_print(FILE *fp, void *call_site_data);
AWS_EXTERN_C_END

#if defined(CBMC)
# include <assert.h>
# define AWS_ASSERT(cond) assert(cond)
#elif defined(DEBUG_BUILD)
# define AWS_ASSERT(cond) \
# define AWS_FATAL_ASSERT(cond) \
if (!(cond)) { \
aws_fatal_assert(#cond, __FILE__, __LINE__); \
abort(); \
}
#else
# if defined(_MSC_VER)
# define AWS_FATAL_ASSERT(cond) \
__pragma(warning(push)) __pragma(warning(disable : 4127)) /* conditional expression is constant */ \
if (!(cond)) { \
aws_fatal_assert(#cond, __FILE__, __LINE__); \
} \
__pragma(warning(pop))
# else
# define AWS_FATAL_ASSERT(cond) \
if (!(cond)) { \
aws_fatal_assert(#cond, __FILE__, __LINE__); \
}
# endif
#endif

#if defined(CBMC)
# include <assert.h>
# define AWS_ASSERT(cond) assert(cond)
#elif defined(DEBUG_BUILD)
# define AWS_ASSERT(cond) AWS_FATAL_ASSERT(cond)
#else
# define AWS_ASSERT(cond)
#endif

#define AWS_STATIC_ASSERT0(cond, msg) typedef char AWS_CONCAT(static_assertion_, msg)[(!!(cond)) * 2 - 1]
#define AWS_STATIC_ASSERT1(cond, line) AWS_STATIC_ASSERT0(cond, AWS_CONCAT(at_line_, line))
#define AWS_STATIC_ASSERT(cond) AWS_STATIC_ASSERT1(cond, __LINE__)

#if defined(CBMC)
# define AWS_FATAL_ASSERT(cond) \
if (!(cond)) { \
abort(); \
}
#else
#define AWS_FATAL_ASSERT(cond) \
if (!(cond)) { \
aws_fatal_assert(#cond, __FILE__, __LINE__); \
}
#endif
10 changes: 5 additions & 5 deletions include/aws/testing/aws_test_harness.h
Original file line number Diff line number Diff line change
Expand Up @@ -451,11 +451,11 @@ static inline int enable_vt_mode(void) {
AWS_MUTEX_INIT, \
}; \
static struct aws_allocator name##_allocator = { \
.mem_acquire = s_mem_acquire_malloc, \
.mem_release = s_mem_release_free, \
.mem_realloc = NULL, \
.mem_calloc = NULL, \
.impl = &name##_alloc_impl, \
s_mem_acquire_malloc, \
s_mem_release_free, \
NULL, \
NULL, \
&name##_alloc_impl, \
};

#define AWS_TEST_CASE_SUPRESSION(name, fn, s) \
Expand Down

0 comments on commit 0bebfbc

Please sign in to comment.