Skip to content

Use union to convert between jerryx_arg_int_option_t and uintptr_t #2718

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
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
8 changes: 6 additions & 2 deletions jerry-ext/arg/arg-transform-functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,12 @@ jerryx_arg_helper_process_double (double *d, /**< [in, out] the number to be pro
return rv; \
} \
jerry_release_value (rv); \
jerryx_arg_int_option_t *options_p = (jerryx_arg_int_option_t *) &c_arg_p->extra_info; \
rv = jerryx_arg_helper_process_double (&tmp, min, max, *options_p); \
union \
{ \
jerryx_arg_int_option_t int_option; \
uintptr_t extra_info; \
} u = { .extra_info = c_arg_p->extra_info }; \
rv = jerryx_arg_helper_process_double (&tmp, min, max, u.int_option); \
if (jerry_value_is_error (rv)) \
{ \
return rv; \
Expand Down
8 changes: 6 additions & 2 deletions jerry-ext/include/jerryscript-ext/arg.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,16 @@ typedef struct
func = jerryx_arg_transform_ ## type; \
} \
} \
const jerryx_arg_int_option_t int_option = { .round = (uint8_t) round_flag, .clamp = (uint8_t) clamp_flag }; \
union \
{ \
jerryx_arg_int_option_t int_option; \
uintptr_t extra_info; \
} u = { .int_option = { .round = (uint8_t) round_flag, .clamp = (uint8_t) clamp_flag } }; \
return (jerryx_arg_t) \
{ \
.func = func, \
.dest = (void *) dest, \
.extra_info = *(uintptr_t *) &int_option \
.extra_info = u.extra_info \
}; \
}

Expand Down