Skip to content

Fix JerryScript build with clang-6.0 #2610

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions docs/02.API-REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -3421,24 +3421,25 @@ jerry_create_string_sz (const jerry_char_t *str_p,
**Summary**

Returns a jerry_value_t RegExp object or an error, if the construction of the object fails.
Optional flags can be set using [jerry_regexp_flags_t](#jerry_regexp_flags_t);
Optional flags can be set using [jerry_regexp_flags_t](#jerry_regexp_flags_t).
These flags can be combined together with the binary OR operator or used on their own as enum values.

**Prototype**
```c
jerry_value_t
jerry_create_regexp (const jerry_char_t *pattern_p, jerry_regexp_flags_t flags);
jerry_create_regexp (const jerry_char_t *pattern_p, uint16_t flags);
```

- `pattern_p` - the RegExp pattern as a zero-terminated UTF-8 string
- `flags` - optional flags for the RegExp object
- `flags` - optional flags for the RegExp object, see [jerry_regexp_flags_t](#jerry_regexp_flags_t)
- return value - the RegExp object as a `jerry_value_t`

**Example**

```c
{
jerry_char_t pattern_p = "[cgt]gggtaaa|tttaccc[acg]";
jerry_regexp_flags_t pattern_flags = JERRY_REGEXP_FLAG_IGNORE_CASE;
uint16_t pattern_flags = JERRY_REGEXP_FLAG_IGNORE_CASE;

jerry_value_t regexp = jerry_create_regexp (pattern_p, pattern_flags);

Expand All @@ -3454,17 +3455,18 @@ jerry_create_regexp (const jerry_char_t *pattern_p, jerry_regexp_flags_t flags);
**Summary**

Returns a jerry_value_t RegExp object or an error, if the construction of the object fails.
Optional flags can be set using [jerry_regexp_flags_t](#jerry_regexp_flags_t);
Optional flags can be set using [jerry_regexp_flags_t](#jerry_regexp_flags_t).
These flags can be combined together with the binary OR operator or used on their own as enum values.

**Prototype**
```c
jerry_value_t
jerry_create_regexp_sz (const jerry_char_t *pattern_p, jerry_size_t pattern_size, jerry_regexp_flags_t flags);
jerry_create_regexp_sz (const jerry_char_t *pattern_p, jerry_size_t pattern_size, uint16_t flags);
```

- `pattern_p` - the RegExp pattern as a zero-terminated UTF-8 string
- `pattern_size` - size of the `pattern`
- `flags` - optional flags for the RegExp object
- `flags` - optional flags for the RegExp object, see [jerry_regexp_flags_t](#jerry_regexp_flags_t)
- return value - the RegExp object as a `jerry_value_t`

**Example**
Expand All @@ -3473,7 +3475,7 @@ jerry_create_regexp_sz (const jerry_char_t *pattern_p, jerry_size_t pattern_size
{
jerry_char_t pattern_p = "[cgt]gggtaaa|tttaccc[acg]";
jerry_size_t pattern_size = sizeof (pattern_p) - 1;
jerry_regexp_flags_t pattern_flags = JERRY_REGEXP_FLAG_IGNORE_CASE;
uint16_t pattern_flags = JERRY_REGEXP_FLAG_IGNORE_CASE;

jerry_value_t regexp = jerry_create_regexp_sz (pattern_p, pattern_size, pattern_flags);

Expand Down
4 changes: 2 additions & 2 deletions jerry-core/api/jerry.c
Original file line number Diff line number Diff line change
Expand Up @@ -1500,7 +1500,7 @@ jerry_create_string_sz (const jerry_char_t *str_p, /**< pointer to string */
*/
jerry_value_t
jerry_create_regexp (const jerry_char_t *pattern_p, /**< zero-terminated UTF-8 string as RegExp pattern */
jerry_regexp_flags_t flags) /**< optional RegExp flags */
uint16_t flags) /**< optional RegExp flags */
{
return jerry_create_regexp_sz (pattern_p, lit_zt_utf8_string_size (pattern_p), flags);
} /* jerry_create_regexp */
Expand All @@ -1513,7 +1513,7 @@ jerry_create_regexp (const jerry_char_t *pattern_p, /**< zero-terminated UTF-8 s
jerry_value_t
jerry_create_regexp_sz (const jerry_char_t *pattern_p, /**< zero-terminated UTF-8 string as RegExp pattern */
jerry_size_t pattern_size, /**< length of the pattern */
jerry_regexp_flags_t flags) /**< optional RegExp flags */
uint16_t flags) /**< optional RegExp flags */
{
jerry_assert_api_available ();

Expand Down
5 changes: 2 additions & 3 deletions jerry-core/include/jerryscript-core.h
Original file line number Diff line number Diff line change
Expand Up @@ -458,9 +458,8 @@ jerry_value_t jerry_create_number_nan (void);
jerry_value_t jerry_create_null (void);
jerry_value_t jerry_create_object (void);
jerry_value_t jerry_create_promise (void);
jerry_value_t jerry_create_regexp (const jerry_char_t *pattern, jerry_regexp_flags_t flags);
jerry_value_t jerry_create_regexp_sz (const jerry_char_t *pattern, jerry_size_t pattern_size,
jerry_regexp_flags_t flags);
jerry_value_t jerry_create_regexp (const jerry_char_t *pattern, uint16_t flags);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reasion why this is limited to 16 bits? Usually this takes a register regardless of type. I would use a 32 bit value.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use a 32 bit value, however that would go way out of the scope of this patch.
In that case we must change everything related to ecma_op_create_regexp_object. I would like to leave it as it is in this patch, and create a follow up, that changes every related function's parameters to 32 bit values.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @DanielBallaSZTE is right here. The API mirrors the internals.

On the other hand, if the goal is to break away from the internals, then I'd suggest not to use a bitwidth-fixed (e.g., 32 bit) type, but a simple (unsigned?) int instead. Actually, that should be the fastest and easiest and most future-proof type on any machine.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@akosthekiss Using an unsigned int requires you to cast it to unsigned short int (uint16_t) when calling the ecma_op_create_regexp_object. I already have a patch prepared that changes all the internal parameters to uint32_t, so I would like to leave it as an uint16_t for now and submit the patch if this one lands.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I was not pushing for a change here. I was only reflecting to @zherczeg 's proposal to change this to uint32_t. And my comment was that if we wanted a change (i.e., to have an API type that was different from the internal type) then we should go for a non-sized type.

jerry_value_t jerry_create_regexp_sz (const jerry_char_t *pattern, jerry_size_t pattern_size, uint16_t flags);
jerry_value_t jerry_create_string_from_utf8 (const jerry_char_t *str_p);
jerry_value_t jerry_create_string_sz_from_utf8 (const jerry_char_t *str_p, jerry_size_t str_size);
jerry_value_t jerry_create_string (const jerry_char_t *str_p);
Expand Down
2 changes: 1 addition & 1 deletion tests/unit-core/test-regexp.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ main (void)
jerry_value_t global_obj_val = jerry_get_global_object ();

jerry_char_t pattern[] = "[^.]+";
jerry_regexp_flags_t flags = JERRY_REGEXP_FLAG_GLOBAL | JERRY_REGEXP_FLAG_MULTILINE;
uint16_t flags = JERRY_REGEXP_FLAG_GLOBAL | JERRY_REGEXP_FLAG_MULTILINE;
jerry_value_t regex_obj = jerry_create_regexp (pattern, flags);
TEST_ASSERT (jerry_value_is_object (regex_obj));

Expand Down