2020-01-18 09:38:21 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
|
2021-12-14 17:44:43 +01:00
|
|
|
#ifndef _ASSERT_H
|
|
|
|
|
# define _ASSERT_H
|
|
|
|
|
|
2022-10-17 00:06:11 +02:00
|
|
|
# define __stringify_helper(x) #x
|
2021-12-14 17:44:43 +01:00
|
|
|
# define __stringify(x) __stringify_helper(x)
|
|
|
|
|
|
|
|
|
|
# ifndef __cplusplus
|
|
|
|
|
# define static_assert _Static_assert
|
|
|
|
|
# endif
|
|
|
|
|
#endif
|
2018-10-28 09:36:21 +01:00
|
|
|
|
2018-10-31 02:09:11 +01:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
|
|
2021-12-14 17:44:43 +01:00
|
|
|
#undef assert
|
|
|
|
|
|
2018-10-31 02:09:11 +01:00
|
|
|
__BEGIN_DECLS
|
2018-10-28 09:36:21 +01:00
|
|
|
|
2021-07-12 01:15:22 -06:00
|
|
|
#ifndef NDEBUG
|
2022-04-01 20:58:27 +03:00
|
|
|
__attribute__((noreturn)) void __assertion_failed(char const* msg);
|
2021-07-12 21:37:31 +01:00
|
|
|
# define assert(expr) \
|
|
|
|
|
(__builtin_expect(!(expr), 0) \
|
|
|
|
|
? __assertion_failed(#expr "\n" __FILE__ ":" __stringify(__LINE__)) \
|
2021-07-13 19:02:20 +01:00
|
|
|
: (void)0)
|
2021-07-12 21:37:31 +01:00
|
|
|
|
2019-04-23 21:52:02 +02:00
|
|
|
#else
|
2020-12-23 21:23:41 +01:00
|
|
|
# define assert(expr) ((void)(0))
|
2019-04-23 21:52:02 +02:00
|
|
|
#endif
|
|
|
|
|
|
2018-10-31 02:09:11 +01:00
|
|
|
__END_DECLS
|