Skip to content
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

Add utf8_to_uv_or_die() #22846

Merged
merged 4 commits into from
Dec 16, 2024
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
14 changes: 9 additions & 5 deletions embed.fnc
Original file line number Diff line number Diff line change
Expand Up @@ -1241,7 +1241,7 @@ p |void |force_locale_unlock
Cp |void |force_out_malformed_utf8_message_ \
|NN const U8 * const p \
|NN const U8 * const e \
|const U32 flags \
|U32 flags \
|const bool die_here
Adfpv |char * |form |NN const char *pat \
|...
Expand Down Expand Up @@ -3757,29 +3757,33 @@ ATdmp |bool |utf8_to_uv_errors \
|NN const U8 * const e \
|NN UV *cp_p \
|NULLOK Size_t *advance_p \
|const U32 flags \
|U32 flags \
|NULLOK U32 *errors
ATdmp |bool |utf8_to_uv_flags \
|NN const U8 * const s \
|NN const U8 * const e \
|NN UV *cp_p \
|NULLOK Size_t *advance_p \
|const U32 flag
|U32 flags
ATdip |bool |utf8_to_uv_msgs|NN const U8 * const s0 \
|NN const U8 *e \
|NN UV *cp_p \
|NULLOK Size_t *advance_p \
|const U32 flags \
|U32 flags \
|NULLOK U32 *errors \
|NULLOK AV **msgs
CTp |bool |utf8_to_uv_msgs_helper_ \
|NN const U8 * const s0 \
|NN const U8 * const e \
|NN UV *cp_p \
|NULLOK Size_t *advance_p \
|const U32 flags \
|U32 flags \
|NULLOK U32 *errors \
|NULLOK AV **msgs
ATdip |UV |utf8_to_uv_or_die \
|NN const U8 * const s \
|NN const U8 *e \
|NULLOK Size_t *advance_p
CDbdp |UV |utf8_to_uvuni |NN const U8 *s \
|NULLOK STRLEN *retlen
: Used in perly.y
Expand Down
1 change: 1 addition & 0 deletions embed.h
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,7 @@
# define utf8_to_uv_flags Perl_utf8_to_uv_flags
# define utf8_to_uv_msgs Perl_utf8_to_uv_msgs
# define utf8_to_uv_msgs_helper_ Perl_utf8_to_uv_msgs_helper_
# define utf8_to_uv_or_die Perl_utf8_to_uv_or_die
# define utf8n_to_uvchr Perl_utf8n_to_uvchr
# define utf8n_to_uvchr_error Perl_utf8n_to_uvchr_error
# define utf8n_to_uvchr_msgs Perl_utf8n_to_uvchr_msgs
Expand Down
14 changes: 12 additions & 2 deletions inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -3053,7 +3053,7 @@ Perl_utf8_to_uv_msgs(const U8 * const s0,
const U8 * const e,
UV * cp_p,
Size_t *advance_p,
const U32 flags,
U32 flags,
U32 * errors,
AV ** msgs)
{
Expand Down Expand Up @@ -3138,11 +3138,21 @@ Perl_utf8_to_uv_msgs(const U8 * const s0,
return utf8_to_uv_msgs_helper_(s0, e, cp_p, advance_p, flags, errors, msgs);
}

PERL_STATIC_INLINE UV
Perl_utf8_to_uv_or_die(const U8 *s, const U8 *e, STRLEN *advance_p)
{
PERL_ARGS_ASSERT_UTF8_TO_UV_OR_DIE;

UV cp;
(void) utf8_to_uv_flags(s, e, &cp, advance_p, UTF8_DIE_IF_MALFORMED);
return cp;
}

PERL_STATIC_INLINE UV
Perl_utf8n_to_uvchr_msgs(const U8 * const s0,
STRLEN curlen,
STRLEN *retlen,
const U32 flags,
U32 flags,
U32 * errors,
AV ** msgs)
{
Expand Down
7 changes: 4 additions & 3 deletions pod/perldelta.pod
Original file line number Diff line number Diff line change
Expand Up @@ -436,9 +436,10 @@ New API functions are introduced to convert strings encoded in UTF-8 to
their ordinal code point equivalent. These are safe to use by default,
and generally more convenient to use than the existing ones.

L<perlapi/C<utf8_to_uv>> replaces L<perlapi/C<utf8_to_uvchr>> (which is
retained for backwards compatibility), but you should convert to use the
new form, as likely you aren't using the old one safely.
L<perlapi/C<utf8_to_uv>> and L<perlapi/C<utf8_to_uv_or_die>> replace
L<perlapi/C<utf8_to_uvchr>> (which is retained for backwards
compatibility), but you should convert to use the new forms, as likely
you aren't using the old one safely.

To convert in the opposite direction, you can now use
L<perlapi/C<uv_to_utf8>>. This is not a new function, but a new synonym
Expand Down
15 changes: 10 additions & 5 deletions proto.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading