Skip to content

Commit 9bc0f2f

Browse files
authored
Unify asserts in jerry-ext (#4488)
Some components of the jerry-ext library re-declared their own assert and/or static assert macros. No need to re-invent the wheel all the time. This patch makes all components use the assert macros defined in jext-common.h. This also makes maintenance easier. JerryScript-DCO-1.0-Signed-off-by: Akos Kiss [email protected]
1 parent 11894a6 commit 9bc0f2f

File tree

5 files changed

+8
-29
lines changed

5 files changed

+8
-29
lines changed

jerry-ext/arg/arg.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,14 @@
1313
* limitations under the License.
1414
*/
1515

16-
#include "arg-internal.h"
1716
#include "jerryscript-ext/arg.h"
1817
#include "jerryscript.h"
19-
20-
#define JERRYX_STATIC_ASSERT(x, msg) \
21-
enum { static_assertion_failed_ ## msg = 1 / (!!(x)) }
18+
#include "arg-internal.h"
19+
#include "jext-common.h"
2220

2321
JERRYX_STATIC_ASSERT (sizeof (jerryx_arg_int_option_t) <= sizeof (((jerryx_arg_t *) 0)->extra_info),
2422
jerryx_arg_number_options_t_must_fit_into_extra_info);
2523

26-
#undef JERRYX_STATIC_ASSERT
27-
2824
/**
2925
* Validate the JS arguments and assign them to the native arguments.
3026
*

jerry-ext/handle-scope/handle-scope-allocator.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include <stdlib.h>
1717
#include "handle-scope-internal.h"
18+
#include "jext-common.h"
1819

1920
static jerryx_handle_scope_t jerryx_handle_scope_root =
2021
{
@@ -157,7 +158,7 @@ jerryx_handle_scope_alloc (void)
157158
else
158159
{
159160
jerryx_handle_scope_dynamic_t *dy_scope = malloc (sizeof (jerryx_handle_scope_dynamic_t));
160-
JERRYX_HANDLE_SCOPE_ASSERT (dy_scope != NULL);
161+
JERRYX_ASSERT (dy_scope != NULL);
161162
dy_scope->child = NULL;
162163

163164
if (jerryx_handle_scope_pool.count != JERRYX_SCOPE_PRELIST_SIZE)

jerry-ext/handle-scope/handle-scope-internal.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,6 @@ extern "C"
2525
{
2626
#endif /* __cplusplus */
2727

28-
#define JERRYX_HANDLE_SCOPE_ASSERT(x) \
29-
do \
30-
{ \
31-
if (!(x)) \
32-
{ \
33-
jerry_port_log (JERRY_LOG_LEVEL_ERROR, \
34-
"JerryXHandleScope: Assertion '%s' failed at %s(%s):%lu.\n", \
35-
#x, \
36-
__FILE__, \
37-
__func__, \
38-
(unsigned long) __LINE__); \
39-
jerry_port_fatal (ERR_FAILED_INTERNAL_ASSERTION); \
40-
} \
41-
} while (0)
42-
4328
/** MARK: - handle-scope-allocator.c */
4429
typedef struct jerryx_handle_scope_pool_s jerryx_handle_scope_pool_t;
4530
/**

jerry-ext/handle-scope/handle-scope.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515

1616
#include <stdlib.h>
1717
#include "handle-scope-internal.h"
18+
#include "jext-common.h"
19+
20+
JERRYX_STATIC_ASSERT (JERRYX_SCOPE_PRELIST_SIZE < 32, JERRYX_SCOPE_PRELIST_SIZE_MUST_BE_LESS_THAN_SIZE_OF_UINT8_T);
1821

1922
/**
2023
* Opens a new handle scope and attach it to current global scope as a child scope.
@@ -339,7 +342,7 @@ jerryx_create_handle_in_scope (jerry_value_t jval, jerryx_handle_scope scope)
339342
return jval;
340343
}
341344
jerryx_handle_t *handle = malloc (sizeof (jerryx_handle_t));
342-
JERRYX_HANDLE_SCOPE_ASSERT (handle != NULL);
345+
JERRYX_ASSERT (handle != NULL);
343346
handle->jval = jval;
344347

345348
handle->sibling = scope->handle_ptr;

jerry-ext/include/jerryscript-ext/handle-scope.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,6 @@ extern "C"
3131
#define JERRYX_SCOPE_PRELIST_SIZE 20
3232
#endif
3333

34-
#define STATIC_ASSERT(COND,MSG) typedef char static_assertion_##MSG[(COND)?1:-1]
35-
36-
STATIC_ASSERT (JERRYX_SCOPE_PRELIST_SIZE < 32, JERRYX_SCOPE_PRELIST_SIZE_must_be_less_than_size_of_uint8_t);
37-
38-
#undef STATIC_ASSERT
39-
4034
typedef struct jerryx_handle_t jerryx_handle_t;
4135
/**
4236
* Dynamically allocated handle in the scopes.

0 commit comments

Comments
 (0)