Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
wjr-z committed Feb 3, 2024
1 parent dd2bdc5 commit eec2a3e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
33 changes: 17 additions & 16 deletions include/wjr/preprocessor/preview.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ template <typename Handler, typename... Args,
std::enable_if_t<std::is_invocable_v<Handler, Args...>, int> = 0>
WJR_COLD WJR_NOINLINE void __assert_fail(const char *expr, const char *file, int line,
Handler handler, Args &&...args) {
fprintf(stderr, "Assertion failed: %s", expr);
if (file != nullptr && file[0] != '\0') {
fprintf(stderr, ", file %s", file);
(void)fprintf(stderr, "Assertion failed: %s", expr);
if ((file != nullptr) && (file[0] != '\0')) {
(void)fprintf(stderr, ", file %s", file);
}
if (line != -1) {
fprintf(stderr, ", line %d", line);
(void)fprintf(stderr, ", line %d", line);
}
fprintf(stderr, "\n");
(void)fprintf(stderr, "\n");
__assert_fail(handler, std::forward<Args>(args)...);
}

Expand All @@ -67,29 +67,29 @@ struct __assert_t {

template <typename... Args>
void operator()(const char *fmt, Args &&...args) {
fprintf(stderr, "Additional message: ");
fprintf(stderr, fmt, std::forward<Args>(args)...);
fprintf(stderr, "\n");
(void)fprintf(stderr, "Additional message: ");
(void)fprintf(stderr, fmt, std::forward<Args>(args)...);
(void)fprintf(stderr, "\n");
}
};

inline constexpr __assert_t __assert{};

#define WJR_ASSERT_NOMESSAGE_FAIL(handler, exprstr) \
__assert_fail(exprstr, WJR_FILE, WJR_LINE, handler)
#define WJR_ASSERT_MESSAGE_FAIL(handler, exprstr, fmt, ...) \
__assert_fail(exprstr, WJR_FILE, WJR_LINE, handler, fmt, ##__VA_ARGS__)
#define WJR_ASSERT_MESSAGE_FAIL(handler, exprstr, ...) \
__assert_fail(exprstr, WJR_FILE, WJR_LINE, handler, __VA_ARGS__)

#define WJR_ASSERT_CHECK_I_NOMESSAGE(handler, expr) \
do { \
if (WJR_UNLIKELY(!(expr))) { \
WJR_ASSERT_NOMESSAGE_FAIL(handler, #expr); \
} \
} while (0)
#define WJR_ASSERT_CHECK_I_MESSAGE(handler, expr, fmt, ...) \
#define WJR_ASSERT_CHECK_I_MESSAGE(handler, expr, ...) \
do { \
if (WJR_UNLIKELY(!(expr))) { \
WJR_ASSERT_MESSAGE_FAIL(handler, #expr, fmt, ##__VA_ARGS__); \
WJR_ASSERT_MESSAGE_FAIL(handler, #expr, __VA_ARGS__); \
} \
} while (0)

Expand Down Expand Up @@ -125,11 +125,12 @@ inline constexpr __assert_t __assert{};
// level of assert is zero at default.
#define WJR_ALWAYS_ASSERT(...) WJR_ALWAYS_ASSERT_L(0, __VA_ARGS__)

#define WJR_ASSERT_ASSUME_L(level, expr, ...) \
WJR_ASSERT_L(level, expr, ##__VA_ARGS__); \
WJR_ASSUME(expr)
#define WJR_ASSERT_ASSUME_L(level, ...) \
WJR_ASSERT_L(level, __VA_ARGS__); \
__WJR_ASSERT_ASSUME_L_ASSUME(__VA_ARGS__)
#define __WJR_ASSERT_ASSUME_L_ASSUME(expr, ...) WJR_ASSUME(expr)

#define WJR_ASSERT_ASSUME(expr, ...) WJR_ASSERT_ASSUME_L(0, expr, ##__VA_ARGS__)
#define WJR_ASSERT_ASSUME(...) WJR_ASSERT_ASSUME_L(0, __VA_ARGS__)

// (a, b, c) -> f(a) f(b) f(c)
#define WJR_PP_TRANSFORM_PUT(queue, op) \
Expand Down
4 changes: 3 additions & 1 deletion include/wjr/span.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ struct __span_static_storage {
__span_static_storage(const __span_static_storage &) = default;
__span_static_storage &operator=(const __span_static_storage &) = default;

__span_static_storage(T *p, size_t s) : ptr(p) { WJR_ASSERT(s == size); }
__span_static_storage(T *p, WJR_MAYBE_UNUSED size_t s) : ptr(p) {
WJR_ASSERT(s == size);
}

T *ptr = nullptr;
static constexpr size_t size = Extent;
Expand Down
4 changes: 2 additions & 2 deletions include/wjr/stack_allocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class stack_alloc {
}

WJR_NODISCARD WJR_CONSTEXPR20 void *allocate(size_t n) {
if (WJR_UNLIKELY(m_node.end - m_node.ptr < n)) {
if (WJR_UNLIKELY(static_cast<size_t>(m_node.end - m_node.ptr) < n)) {

if (WJR_LIKELY(m_idx != -1ull)) {
m_stk[m_idx].ptr = m_node.ptr;
Expand All @@ -98,7 +98,7 @@ class stack_alloc {
return ret;
}

WJR_CONSTEXPR20 void deallocate(void *ptr, size_t n) {
WJR_CONSTEXPR20 void deallocate(void *ptr, WJR_MAYBE_UNUSED size_t n) {
WJR_ASSERT(m_node.ptr == static_cast<char *>(ptr) + n);

m_node.ptr = static_cast<char *>(ptr);
Expand Down

0 comments on commit eec2a3e

Please sign in to comment.