Turn assert functionality standard-conforming in jerry-libc

Introducing the `assert.h` public header with the `assert(x)` macro
and already making use of it in jerry-libc sources. These newly
introduced ISO C-conforming features replace the non-conforming
`LIBC_ASSERT` and `LIBC_NDEBUG` at no cost, and they also have the
benefit that we can expose `assert` in a public header and make it
useful to jerry-libc users.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
This commit is contained in:
Akos Kiss
2016-04-13 21:24:53 +02:00
parent ecfd478df0
commit ff185dc57e
7 changed files with 92 additions and 116 deletions
+1 -27
View File
@@ -1,4 +1,4 @@
/* Copyright 2015 Samsung Electronics Co., Ltd.
/* Copyright 2015-2016 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,30 +28,4 @@
#define __attr_noreturn___ __attribute__((noreturn))
#define __attr_noinline___ __attribute__((noinline))
/**
* Assertions
*/
extern void __attr_noreturn___
libc_fatal (const char *msg,
const char *file_name,
const char *function_name,
const unsigned int line_number);
#ifndef LIBC_NDEBUG
# define LIBC_ASSERT(x) do { if (__builtin_expect (!(x), 0)) { \
libc_fatal (#x, __FILE__, __func__, __LINE__); } } while (0)
# define LIBC_UNREACHABLE() \
do \
{ \
libc_fatal ("Code is unreachable", __FILE__, __func__, __LINE__); \
} while (0)
#else /* !LIBC_NDEBUG */
# define LIBC_ASSERT(x) do { if (false) { (void) (x); } } while (0)
# define LIBC_UNREACHABLE() \
do \
{ \
libc_fatal (NULL, NULL, NULL, 0); \
} while (0)
#endif /* !LIBC_NDEBUG */
#endif /* !DEFS_H */