Skip to content

Commit

Permalink
Fixes to bytes_to_utf8-type functions
Browse files Browse the repository at this point in the history
This commit turns bytes_to_utf8() back into an (inline) function, and
changes the type of a parameter in bytes_to_utf8_free_me() to void*,
which is a more accurate type for it.

Fixes #22902
  • Loading branch information
khwilliamson committed Jan 20, 2025
1 parent 655e53c commit eb63198
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 11 deletions.
4 changes: 2 additions & 2 deletions embed.fnc
Original file line number Diff line number Diff line change
Expand Up @@ -794,12 +794,12 @@ Adp |int |bytes_cmp_utf8 |NN const U8 *b \
Adp |U8 * |bytes_from_utf8|NN const U8 *s \
|NN STRLEN *lenp \
|NN bool *is_utf8p
Admp |U8 * |bytes_to_utf8 |NN const U8 *s \
Adip |U8 * |bytes_to_utf8 |NN const U8 *s \
|NN STRLEN *lenp
Adp |U8 * |bytes_to_utf8_free_me \
|NN const U8 *s \
|NN STRLEN *lenp \
|NULLOK const U8 **free_me
|NULLOK void **free_me
AOdp |SSize_t|call_argv |NN const char *sub_name \
|I32 flags \
|NN char **argv
Expand Down
2 changes: 1 addition & 1 deletion embed.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
# define block_start(a) Perl_block_start(aTHX_ a)
# define bytes_cmp_utf8(a,b,c,d) Perl_bytes_cmp_utf8(aTHX_ a,b,c,d)
# define bytes_from_utf8(a,b,c) Perl_bytes_from_utf8(aTHX_ a,b,c)
# define bytes_to_utf8(a,b) Perl_bytes_to_utf8(aTHX,a,b)
# define bytes_to_utf8(a,b) Perl_bytes_to_utf8(aTHX_ a,b)
# define bytes_to_utf8_free_me(a,b,c) Perl_bytes_to_utf8_free_me(aTHX_ a,b,c)
# define c9strict_utf8_to_uv Perl_c9strict_utf8_to_uv
# define call_argv(a,b,c) Perl_call_argv(aTHX_ a,b,c)
Expand Down
7 changes: 6 additions & 1 deletion inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,6 @@ in lvalue context.
=cut
*/


PERL_STATIC_INLINE bool
Perl_rpp_is_lone(pTHX_ SV *sv)
{
Expand Down Expand Up @@ -1231,6 +1230,12 @@ Perl_append_utf8_from_native_byte(const U8 byte, U8** dest)
}
}

PERL_STATIC_INLINE U8 *
Perl_bytes_to_utf8(pTHX_ const U8 *s, STRLEN *lenp)
{
return bytes_to_utf8_free_me(s, lenp, NULL);
}

/*
=for apidoc valid_utf8_to_uvchr
Like C<L<perlapi/utf8_to_uvchr_buf>>, but should only be called when it is
Expand Down
10 changes: 6 additions & 4 deletions proto.h

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

4 changes: 2 additions & 2 deletions utf8.c
Original file line number Diff line number Diff line change
Expand Up @@ -3269,7 +3269,7 @@ But when it is a non-NULL pointer, C<bytes_to_utf8_free_me> stores into it
either NULL if no memory was allocated; or a pointer to that new memory. This
allows the following convenient paradigm:
U8 * free_me;
void * free_me;
U8 converted = bytes_to_utf8_free_me(string, &len, &free_me);
...
Expand All @@ -3292,7 +3292,7 @@ EBCDIC), see L</sv_recode_to_utf8>().

U8*
Perl_bytes_to_utf8_free_me(pTHX_ const U8 *s, Size_t *lenp,
const U8 ** free_me_ptr)
void ** free_me_ptr)
{
PERL_ARGS_ASSERT_BYTES_TO_UTF8_FREE_ME;
PERL_UNUSED_CONTEXT;
Expand Down
1 change: 0 additions & 1 deletion utf8.h
Original file line number Diff line number Diff line change
Expand Up @@ -1330,7 +1330,6 @@ point's representation.

#define Perl_is_utf8_char_buf(buf, buf_end) isUTF8_CHAR(buf, buf_end)

#define Perl_bytes_to_utf8(mTHX, s, lenp) Perl_bytes_to_utf8_free_me(aTHX_ s, lenp, NULL)
typedef enum {
PL_utf8_to_bytes_overwrite = 0,
PL_utf8_to_bytes_new_memory,
Expand Down

0 comments on commit eb63198

Please sign in to comment.