2023-08-13 08:44:39 +00:00
|
|
|
#ifdef _ASSERT_H
|
|
|
|
#undef _ASSERT_H
|
|
|
|
#undef assert
|
2023-08-14 03:31:27 +00:00
|
|
|
#ifdef _COSMO_SOURCE
|
2023-08-13 08:44:39 +00:00
|
|
|
#undef unassert
|
|
|
|
#undef npassert
|
|
|
|
#ifndef NDEBUG
|
|
|
|
#undef __assert_macro
|
|
|
|
#endif /* NDEBUG */
|
2023-08-14 03:31:27 +00:00
|
|
|
#endif /* _COSMO_SOURCE */
|
2023-08-13 08:44:39 +00:00
|
|
|
#endif /* _ASSERT_H */
|
|
|
|
|
|
|
|
#ifndef _ASSERT_H
|
|
|
|
#define _ASSERT_H
|
2020-06-15 14:18:57 +00:00
|
|
|
COSMOPOLITAN_C_START_
|
|
|
|
|
2024-01-09 09:26:03 +00:00
|
|
|
void __assert_fail(const char *, const char *, int) libcesque;
|
|
|
|
void unassert(const char *, const char *, int) libcesque;
|
2020-06-15 14:18:57 +00:00
|
|
|
|
|
|
|
#ifdef NDEBUG
|
2022-09-15 04:29:50 +00:00
|
|
|
#define assert(x) ((void)0)
|
2020-06-15 14:18:57 +00:00
|
|
|
#else
|
2022-09-15 04:29:50 +00:00
|
|
|
#define assert(x) ((void)((x) || (__assert_fail(#x, __FILE__, __LINE__), 0)))
|
2020-06-15 14:18:57 +00:00
|
|
|
#endif
|
|
|
|
|
2023-08-13 08:44:39 +00:00
|
|
|
#if __STDC_VERSION__ >= 201112L && !defined(__cplusplus)
|
|
|
|
#undef static_assert
|
2021-03-06 04:32:25 +00:00
|
|
|
#define static_assert _Static_assert
|
Import C++ Standard Template Library
You can now use the hardest fastest and most dangerous language there is
with Cosmopolitan. So far about 75% of LLVM libcxx has been added. A few
breaking changes needed to be made to help this go smoothly.
- Rename nothrow to dontthrow
- Rename nodiscard to dontdiscard
- Add some libm functions, e.g. lgamma, nan, etc.
- Change intmax_t from int128 to int64 like everything else
- Introduce %jjd formatting directive for int128_t
- Introduce strtoi128(), strtou128(), etc.
- Rename bsrmax() to bsr128()
Some of the templates that should be working currently are std::vector,
std::string, std::map, std::set, std::deque, etc.
2022-03-22 12:51:41 +00:00
|
|
|
#endif
|
2021-03-06 04:32:25 +00:00
|
|
|
|
2023-08-14 03:31:27 +00:00
|
|
|
#ifdef _COSMO_SOURCE
|
2023-05-19 02:05:08 +00:00
|
|
|
#ifndef NDEBUG
|
2023-07-26 20:54:49 +00:00
|
|
|
#define unassert(x) __assert_macro(x, #x)
|
|
|
|
#define npassert(x) __assert_macro(x, #x)
|
2023-11-17 07:26:05 +00:00
|
|
|
#define __assert_macro(x, s) \
|
|
|
|
({ \
|
|
|
|
if (__builtin_expect(!(x), 0)) { \
|
|
|
|
(unassert)(s, __FILE__, __LINE__); \
|
|
|
|
__asm__("nop"); \
|
|
|
|
__builtin_unreachable(); \
|
|
|
|
} \
|
|
|
|
(void)0; \
|
2023-05-19 02:05:08 +00:00
|
|
|
})
|
|
|
|
#else
|
2023-07-26 20:54:49 +00:00
|
|
|
#define npassert(x) \
|
2022-11-06 08:16:29 +00:00
|
|
|
({ \
|
2022-10-09 20:00:46 +00:00
|
|
|
if (__builtin_expect(!(x), 0)) { \
|
2023-06-10 22:50:01 +00:00
|
|
|
__builtin_trap(); \
|
2022-10-09 20:00:46 +00:00
|
|
|
} \
|
2022-10-10 05:38:28 +00:00
|
|
|
(void)0; \
|
|
|
|
})
|
2023-07-26 20:54:49 +00:00
|
|
|
#define unassert(x) \
|
2022-11-06 08:16:29 +00:00
|
|
|
({ \
|
2022-10-10 05:38:28 +00:00
|
|
|
if (__builtin_expect(!(x), 0)) { \
|
2023-06-10 22:50:01 +00:00
|
|
|
__builtin_unreachable(); \
|
2022-10-10 05:38:28 +00:00
|
|
|
} \
|
|
|
|
(void)0; \
|
|
|
|
})
|
2023-07-03 09:47:05 +00:00
|
|
|
#endif /* NDEBUG */
|
2023-08-14 03:31:27 +00:00
|
|
|
#endif /* _COSMO_SOURCE */
|
2022-09-15 04:29:50 +00:00
|
|
|
|
2020-06-15 14:18:57 +00:00
|
|
|
COSMOPOLITAN_C_END_
|
2023-08-13 08:44:39 +00:00
|
|
|
#endif /* _ASSERT_H */
|