2023-08-13 01:44:39 -07:00
|
|
|
#ifdef _ASSERT_H
|
|
|
|
#undef _ASSERT_H
|
|
|
|
#undef assert
|
2023-08-13 20:31:27 -07:00
|
|
|
#ifdef _COSMO_SOURCE
|
2023-08-13 01:44:39 -07:00
|
|
|
#undef unassert
|
|
|
|
#undef npassert
|
|
|
|
#ifndef NDEBUG
|
|
|
|
#undef __assert_macro
|
|
|
|
#endif /* NDEBUG */
|
2023-08-13 20:31:27 -07:00
|
|
|
#endif /* _COSMO_SOURCE */
|
2023-08-13 01:44:39 -07:00
|
|
|
#endif /* _ASSERT_H */
|
|
|
|
|
|
|
|
#ifndef _ASSERT_H
|
|
|
|
#define _ASSERT_H
|
2020-06-15 07:18:57 -07:00
|
|
|
COSMOPOLITAN_C_START_
|
|
|
|
|
2024-01-09 01:26:03 -08:00
|
|
|
void __assert_fail(const char *, const char *, int) libcesque;
|
|
|
|
void unassert(const char *, const char *, int) libcesque;
|
2020-06-15 07:18:57 -07:00
|
|
|
|
|
|
|
#ifdef NDEBUG
|
2022-09-14 21:29:50 -07:00
|
|
|
#define assert(x) ((void)0)
|
2020-06-15 07:18:57 -07:00
|
|
|
#else
|
2022-09-14 21:29:50 -07:00
|
|
|
#define assert(x) ((void)((x) || (__assert_fail(#x, __FILE__, __LINE__), 0)))
|
2020-06-15 07:18:57 -07:00
|
|
|
#endif
|
|
|
|
|
2023-08-13 01:44:39 -07:00
|
|
|
#if __STDC_VERSION__ >= 201112L && !defined(__cplusplus)
|
|
|
|
#undef static_assert
|
2021-03-05 20:32:25 -08: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 05:51:41 -07:00
|
|
|
#endif
|
2021-03-05 20:32:25 -08:00
|
|
|
|
2023-08-13 20:31:27 -07:00
|
|
|
#ifdef _COSMO_SOURCE
|
2023-05-18 19:05:08 -07:00
|
|
|
#ifndef NDEBUG
|
2023-07-26 13:54:49 -07:00
|
|
|
#define unassert(x) __assert_macro(x, #x)
|
|
|
|
#define npassert(x) __assert_macro(x, #x)
|
2023-11-16 23:26:05 -08:00
|
|
|
#define __assert_macro(x, s) \
|
|
|
|
({ \
|
|
|
|
if (__builtin_expect(!(x), 0)) { \
|
|
|
|
(unassert)(s, __FILE__, __LINE__); \
|
|
|
|
__asm__("nop"); \
|
|
|
|
__builtin_unreachable(); \
|
|
|
|
} \
|
|
|
|
(void)0; \
|
2023-05-18 19:05:08 -07:00
|
|
|
})
|
|
|
|
#else
|
2023-07-26 13:54:49 -07:00
|
|
|
#define npassert(x) \
|
2022-11-06 01:16:29 -07:00
|
|
|
({ \
|
2022-10-09 13:00:46 -07:00
|
|
|
if (__builtin_expect(!(x), 0)) { \
|
2023-06-10 15:50:01 -07:00
|
|
|
__builtin_trap(); \
|
2022-10-09 13:00:46 -07:00
|
|
|
} \
|
2022-10-09 22:38:28 -07:00
|
|
|
(void)0; \
|
|
|
|
})
|
2023-07-26 13:54:49 -07:00
|
|
|
#define unassert(x) \
|
2022-11-06 01:16:29 -07:00
|
|
|
({ \
|
2022-10-09 22:38:28 -07:00
|
|
|
if (__builtin_expect(!(x), 0)) { \
|
2023-06-10 15:50:01 -07:00
|
|
|
__builtin_unreachable(); \
|
2022-10-09 22:38:28 -07:00
|
|
|
} \
|
|
|
|
(void)0; \
|
|
|
|
})
|
2023-07-03 02:47:05 -07:00
|
|
|
#endif /* NDEBUG */
|
2023-08-13 20:31:27 -07:00
|
|
|
#endif /* _COSMO_SOURCE */
|
2022-09-14 21:29:50 -07:00
|
|
|
|
2020-06-15 07:18:57 -07:00
|
|
|
COSMOPOLITAN_C_END_
|
2023-08-13 01:44:39 -07:00
|
|
|
#endif /* _ASSERT_H */
|