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

refcounted_he_(new|fetch)_pvn: Don't roll-own code #22638

Open
wants to merge 27 commits into
base: blead
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
d602b15
utf8.c: Move declaration to first use
khwilliamson Oct 23, 2024
ef094c4
utf8.c: White-space only
khwilliamson Oct 23, 2024
50be063
utf8_to_bytes() Move failure code out of loop
khwilliamson Oct 23, 2024
662e80f
utf8_to_bytes: Refactor loop
khwilliamson Oct 23, 2024
9055913
utf8_to_bytes: Update and fix comments.
khwilliamson Oct 23, 2024
43df601
utf8_to_bytes: Rename variable
khwilliamson Oct 23, 2024
8150a3c
Add preliminary utf8_to_bytes_()
khwilliamson Oct 24, 2024
aaee005
utf8_to_bytes_: Add const
khwilliamson Oct 24, 2024
62a4328
utf8_to_bytes_: Add argument, macro
khwilliamson Oct 24, 2024
8bfe955
utf8_to_bytes_: Slight refactor
khwilliamson Oct 24, 2024
63b234f
utf8_to_bytes_: Add non-destructive write option
khwilliamson Oct 26, 2024
39c7af9
utf8_to_bytes_: Calculate needed malloc size
khwilliamson Oct 24, 2024
0a06b72
utf8_to_bytes_: Add ability to return a mortalized pv
khwilliamson Oct 26, 2024
9aeb0aa
Document new utf8_to_bytes() variants
khwilliamson Oct 24, 2024
fedcb20
pp_sys
khwilliamson Oct 12, 2024
9d1cb08
locale1
khwilliamson Oct 12, 2024
3a46442
locale2
khwilliamson Oct 12, 2024
b653137
doio
khwilliamson Oct 12, 2024
96a823d
pp1
khwilliamson Oct 12, 2024
9c7e3a4
pp2
khwilliamson Oct 12, 2024
786157e
sv
khwilliamson Oct 12, 2024
92d12ab
hv.c: White-space only
khwilliamson Oct 12, 2024
d37edf0
hv1
khwilliamson Oct 12, 2024
1144d5a
hv2
khwilliamson Oct 12, 2024
5fb351c
hv3
khwilliamson Oct 12, 2024
73bceda
hv4
khwilliamson Oct 12, 2024
6d240a9
hv5
khwilliamson Oct 28, 2024
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
23 changes: 5 additions & 18 deletions doio.c
Original file line number Diff line number Diff line change
Expand Up @@ -2215,35 +2215,23 @@ Perl_do_print(pTHX_ SV *sv, PerlIO *fp)
STRLEN len;
/* Do this first to trigger any overloading. */
const char *tmps = SvPV_const(sv, len);
U8 *tmpbuf = NULL;
bool happy = TRUE;

if (PerlIO_isutf8(fp)) { /* If the stream is utf8 ... */
if (!SvUTF8(sv)) { /* Convert to utf8 if necessary */
/* We don't modify the original scalar. */
tmpbuf = bytes_to_utf8((const U8*) tmps, &len);
tmps = (char *) tmpbuf;
tmps = (char *) bytes_to_utf8((const U8*) tmps, &len);
SAVEFREEPV(tmps);
}
else if (ckWARN4_d(WARN_UTF8, WARN_SURROGATE, WARN_NON_UNICODE, WARN_NONCHAR)) {
(void) check_utf8_print((const U8*) tmps, len);
}
} /* else stream isn't utf8 */
else if (DO_UTF8(sv)) { /* But if is utf8 internally, attempt to
convert to bytes */
STRLEN tmplen = len;
bool utf8 = TRUE;
U8 * const result = bytes_from_utf8((const U8*) tmps, &tmplen, &utf8);
if (!utf8) {

/* Here, succeeded in downgrading from utf8. Set up to below
* output the converted value */
tmpbuf = result;
tmps = (char *) tmpbuf;
len = tmplen;
}
else { /* Non-utf8 output stream, but string only representable in
utf8 */
assert((char *)result == tmps);
if (! utf8_to_bytes_temp_pv((const U8**) &tmps, &len)) {
/* Non-utf8 output stream, but string only representable in
utf8 */
Perl_ck_warner_d(aTHX_ packWARN(WARN_UTF8),
"Wide character in %s",
PL_op ? OP_DESC(PL_op) : "print"
Expand All @@ -2261,7 +2249,6 @@ Perl_do_print(pTHX_ SV *sv, PerlIO *fp)
* io the write failure can be delayed until the flush/close. --jhi */
if (len && (PerlIO_write(fp,tmps,len) == 0))
happy = FALSE;
Safefree(tmpbuf);
return happy ? !PerlIO_error(fp) : FALSE;
}
}
Expand Down
14 changes: 14 additions & 0 deletions embed.fnc
Original file line number Diff line number Diff line change
Expand Up @@ -3697,6 +3697,20 @@ CDbdp |UV |utf8n_to_uvuni |NN const U8 *s \
|U32 flags
Adpx |U8 * |utf8_to_bytes |NN U8 *s \
|NN STRLEN *lenp
Cp |bool |utf8_to_bytes_ |NN U8 **s_ptr \
|NN STRLEN *lenp \
|NN U8 **free_me \
|Perl_utf8_to_bytes_arg result_as
Admp |bool |utf8_to_bytes_new_pv \
|NN U8 const **s_ptr \
|NN STRLEN *lenp \
|NN U8 *free_me
Admp |bool |utf8_to_bytes_overwrite \
|NN U8 **s_ptr \
|NN STRLEN *lenp
Admp |bool |utf8_to_bytes_temp_pv \
|NN U8 const **s_ptr \
|NN STRLEN *lenp
EMXp |U8 * |utf16_to_utf8 |NN U8 *p \
|NN U8 *d \
|Size_t bytelen \
Expand Down
4 changes: 4 additions & 0 deletions embed.h
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,10 @@
# define utf8_hop_safe Perl_utf8_hop_safe
# define utf8_length(a,b) Perl_utf8_length(aTHX_ a,b)
# define utf8_to_bytes(a,b) Perl_utf8_to_bytes(aTHX_ a,b)
# define utf8_to_bytes_(a,b,c,d) Perl_utf8_to_bytes_(aTHX_ a,b,c,d)
# define utf8_to_bytes_new_pv(a,b,c) Perl_utf8_to_bytes_new_pv(aTHX,a,b,c)
# define utf8_to_bytes_overwrite(a,b) Perl_utf8_to_bytes_overwrite(aTHX,a,b)
# define utf8_to_bytes_temp_pv(a,b) Perl_utf8_to_bytes_temp_pv(aTHX,a,b)
# define utf8_to_uvchr_buf_helper(a,b,c) Perl_utf8_to_uvchr_buf_helper(aTHX_ a,b,c)
# define utf8n_to_uvchr_msgs Perl_utf8n_to_uvchr_msgs
# define uvchr_to_utf8(a,b) Perl_uvchr_to_utf8(aTHX,a,b)
Expand Down
Loading
Loading