Cleanup jerry's assert-like routines and macros
Until now, jerry had 3 different assert-like routines: `jerry_assert_fail`, `jerry_unreachable`, and `jerry_unimplemented`, and 3 corresponding macros (`JERRY_ASSERT`, `JERRY_UNREACHABLE`, and `JERRY_UNIMPLEMENTED`). They had some irregularities, namely: * All of them had a string parameter, although `jerry_unreachable` never got anything there but NULL. * Both `jerry_unreachable` and `jerry_unimplemented` checked its string parameter for NULL, although it was always NULL for the first one and never NULL for the second. * `jerry_unreachable` is just a regular assert with a fixed error message (i.e., control should not have got here), however, the expansion of its corresponding macro in debug and release modes differs from the behaviour of `JERRY_ASSERT`: `JERRY_ASSERT` is a no-op in release, however, `JERRY_UNREACHABLE` was triggering a crash even there. * Moreover, `JERRY_UNIMPLEMENTED` was almost never used anymore but in a few places (where often an `#ifdef` selected between `JERRY_UNIMPLEMENTED` and `JERRY_UNREACHABLE`). Because of the above, this patch makes the following changes: * Drops `JERRY_UNIMPLEMENTED` completely and whereever it was still used, replaces it with `JERRY_UNREACHABLE`. As a consequence, the `jerry_unimplemented` function and the `ERR_UNIMPLEMENTED_CASE` fatal error code are also removed. * Makes `JERRY_UNREACHABLE` expand to no-op in release builds. (Actually, to `__builtin_unreachable ()` to avoid warnings.) As a consequence, makes both `jerry_assert_fail` and `jerry_unreachable` be guarded by `#ifndef JERRY_NDEBUG`. Also, changes `jerry_unreachable` not to expect a string parameter. * Rewrites `TEST_ASSERT` not to rely on `jerry_assert_fail` as `TEST_ASSERT` has to work in release builds as well. This also allows changing the error message not to mention "ICE", which would misleadingly suggest an assert within the engine, but "TEST" instead. As a side-effect of the cleanup, some refactorings happened in jrt.h: * Removed the definition of the unnecessary `__extension__` macro. * Re-used `JERRY_UNUSED` and `unlikely` where possible. * Moved some parts of the file around. * Fixed some comments (`/**` should only be used for the docstring of a single entity, for groups header comments, the regular `/*` should be used). JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
This commit is contained in:
@@ -51,11 +51,6 @@ jerry_fatal (jerry_fatal_code_t code) /**< status code */
|
||||
jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Error: ERR_REF_COUNT_LIMIT\n");
|
||||
break;
|
||||
}
|
||||
case ERR_UNIMPLEMENTED_CASE:
|
||||
{
|
||||
jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Error: ERR_UNIMPLEMENTED_CASE\n");
|
||||
break;
|
||||
}
|
||||
case ERR_FAILED_INTERNAL_ASSERTION:
|
||||
{
|
||||
jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Error: ERR_FAILED_INTERNAL_ASSERTION\n");
|
||||
@@ -72,6 +67,7 @@ jerry_fatal (jerry_fatal_code_t code) /**< status code */
|
||||
}
|
||||
} /* jerry_fatal */
|
||||
|
||||
#ifndef JERRY_NDEBUG
|
||||
/**
|
||||
* Handle failed assertion
|
||||
*/
|
||||
@@ -81,19 +77,12 @@ jerry_assert_fail (const char *assertion, /**< assertion condition string */
|
||||
const char *function, /**< function name */
|
||||
const uint32_t line) /**< line */
|
||||
{
|
||||
#ifndef JERRY_NDEBUG
|
||||
jerry_port_log (JERRY_LOG_LEVEL_ERROR,
|
||||
"ICE: Assertion '%s' failed at %s(%s):%lu.\n",
|
||||
assertion,
|
||||
file,
|
||||
function,
|
||||
(unsigned long) line);
|
||||
#else /* JERRY_NDEBUG */
|
||||
(void) assertion;
|
||||
(void) file;
|
||||
(void) function;
|
||||
(void) line;
|
||||
#endif /* !JERRY_NDEBUG */
|
||||
|
||||
jerry_fatal (ERR_FAILED_INTERNAL_ASSERTION);
|
||||
} /* jerry_assert_fail */
|
||||
@@ -102,62 +91,16 @@ jerry_assert_fail (const char *assertion, /**< assertion condition string */
|
||||
* Handle execution of control path that should be unreachable
|
||||
*/
|
||||
void __noreturn
|
||||
jerry_unreachable (const char *comment, /**< comment to unreachable mark if exists,
|
||||
NULL - otherwise */
|
||||
const char *file, /**< file name */
|
||||
jerry_unreachable (const char *file, /**< file name */
|
||||
const char *function, /**< function name */
|
||||
const uint32_t line) /**< line */
|
||||
{
|
||||
#ifndef JERRY_NDEBUG
|
||||
jerry_port_log (JERRY_LOG_LEVEL_ERROR,
|
||||
"ICE: Unreachable control path at %s(%s):%lu was executed",
|
||||
"ICE: Unreachable control path at %s(%s):%lu was executed.\n",
|
||||
file,
|
||||
function,
|
||||
(unsigned long) line);
|
||||
#else /* JERRY_NDEBUG */
|
||||
(void) file;
|
||||
(void) function;
|
||||
(void) line;
|
||||
#endif /* !JERRY_NDEBUG */
|
||||
|
||||
if (comment != NULL)
|
||||
{
|
||||
jerry_port_log (JERRY_LOG_LEVEL_ERROR, "(%s)", comment);
|
||||
}
|
||||
|
||||
jerry_port_log (JERRY_LOG_LEVEL_ERROR, ".\n");
|
||||
|
||||
jerry_fatal (ERR_FAILED_INTERNAL_ASSERTION);
|
||||
} /* jerry_unreachable */
|
||||
|
||||
/**
|
||||
* Handle unimplemented case execution
|
||||
*/
|
||||
void __noreturn
|
||||
jerry_unimplemented (const char *comment, /**< comment to unimplemented mark if exists,
|
||||
NULL - otherwise */
|
||||
const char *file, /**< file name */
|
||||
const char *function, /**< function name */
|
||||
const uint32_t line) /**< line */
|
||||
{
|
||||
#ifndef JERRY_NDEBUG
|
||||
jerry_port_log (JERRY_LOG_LEVEL_ERROR,
|
||||
"SORRY: Unimplemented case at %s(%s):%lu was executed",
|
||||
file,
|
||||
function,
|
||||
(unsigned long) line);
|
||||
#else /* JERRY_NDEBUG */
|
||||
(void) file;
|
||||
(void) function;
|
||||
(void) line;
|
||||
#endif /* !JERRY_NDEBUG */
|
||||
|
||||
if (comment != NULL)
|
||||
{
|
||||
jerry_port_log (JERRY_LOG_LEVEL_ERROR, "(%s)", comment);
|
||||
}
|
||||
|
||||
jerry_port_log (JERRY_LOG_LEVEL_ERROR, ".\n");
|
||||
|
||||
jerry_fatal (ERR_UNIMPLEMENTED_CASE);
|
||||
} /* jerry_unimplemented */
|
||||
|
||||
Reference in New Issue
Block a user