Skip to content

Commit

Permalink
Merge 1a61ae0 into 61d18b6
Browse files Browse the repository at this point in the history
  • Loading branch information
Leont committed May 4, 2021
2 parents 61d18b6 + 1a61ae0 commit d3e6a43
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion embed.fnc
Expand Up @@ -3095,7 +3095,7 @@ S |int |sv_2iuv_non_preserve |NN SV *const sv
SR |STRLEN |expect_number |NN const char **const pattern
ST |STRLEN |sv_pos_u2b_forwards|NN const U8 *const start \
|NN const U8 *const send|NN STRLEN *const uoffset \
|NN bool *const at_end
|NN bool *const at_end|NN bool *canonical_position
ST |STRLEN |sv_pos_u2b_midway|NN const U8 *const start \
|NN const U8 *send|STRLEN uoffset|const STRLEN uend
S |STRLEN |sv_pos_u2b_cached|NN SV *const sv|NN MAGIC **const mgp \
Expand Down
4 changes: 2 additions & 2 deletions proto.h
Expand Up @@ -6382,9 +6382,9 @@ STATIC STRLEN S_sv_pos_b2u_midway(pTHX_ const U8 *const s, const U8 *const targe
STATIC STRLEN S_sv_pos_u2b_cached(pTHX_ SV *const sv, MAGIC **const mgp, const U8 *const start, const U8 *const send, STRLEN uoffset, STRLEN uoffset0, STRLEN boffset0);
#define PERL_ARGS_ASSERT_SV_POS_U2B_CACHED \
assert(sv); assert(mgp); assert(start); assert(send)
STATIC STRLEN S_sv_pos_u2b_forwards(const U8 *const start, const U8 *const send, STRLEN *const uoffset, bool *const at_end);
STATIC STRLEN S_sv_pos_u2b_forwards(const U8 *const start, const U8 *const send, STRLEN *const uoffset, bool *const at_end, bool *canonical_position);
#define PERL_ARGS_ASSERT_SV_POS_U2B_FORWARDS \
assert(start); assert(send); assert(uoffset); assert(at_end)
assert(start); assert(send); assert(uoffset); assert(at_end); assert(canonical_position)
STATIC STRLEN S_sv_pos_u2b_midway(const U8 *const start, const U8 *send, STRLEN uoffset, const STRLEN uend);
#define PERL_ARGS_ASSERT_SV_POS_U2B_MIDWAY \
assert(start); assert(send)
Expand Down
13 changes: 9 additions & 4 deletions sv.c
Expand Up @@ -7225,7 +7225,8 @@ Perl_sv_len_utf8_nomg(pTHX_ SV * const sv)
offset. */
static STRLEN
S_sv_pos_u2b_forwards(const U8 *const start, const U8 *const send,
STRLEN *const uoffset_p, bool *const at_end)
STRLEN *const uoffset_p, bool *const at_end,
bool* canonical_position)
{
const U8 *s = start;
STRLEN uoffset = *uoffset_p;
Expand All @@ -7245,6 +7246,7 @@ S_sv_pos_u2b_forwards(const U8 *const start, const U8 *const send,
it's actually a bounds error */
s = send;
}
*canonical_position = (uoffset == 0);
*uoffset_p -= uoffset;
return s - start;
}
Expand Down Expand Up @@ -7298,6 +7300,7 @@ S_sv_pos_u2b_cached(pTHX_ SV *const sv, MAGIC **const mgp, const U8 *const start
STRLEN boffset = 0; /* Actually always set, but let's keep gcc happy. */
bool found = FALSE;
bool at_end = FALSE;
bool canonical_position = FALSE;

PERL_ARGS_ASSERT_SV_POS_U2B_CACHED;

Expand Down Expand Up @@ -7338,7 +7341,8 @@ S_sv_pos_u2b_cached(pTHX_ SV *const sv, MAGIC **const mgp, const U8 *const start
uoffset -= uoffset0;
boffset = boffset0
+ sv_pos_u2b_forwards(start + boffset0,
send, &uoffset, &at_end);
send, &uoffset, &at_end,
&canonical_position);
uoffset += uoffset0;
}
}
Expand Down Expand Up @@ -7380,7 +7384,8 @@ S_sv_pos_u2b_cached(pTHX_ SV *const sv, MAGIC **const mgp, const U8 *const start
STRLEN real_boffset;
uoffset -= uoffset0;
real_boffset = boffset0 + sv_pos_u2b_forwards(start + boffset0,
send, &uoffset, &at_end);
send, &uoffset, &at_end,
&canonical_position);
uoffset += uoffset0;

if (found && PL_utf8cache < 0)
Expand All @@ -7389,7 +7394,7 @@ S_sv_pos_u2b_cached(pTHX_ SV *const sv, MAGIC **const mgp, const U8 *const start
boffset = real_boffset;
}

if (PL_utf8cache && !SvGMAGICAL(sv) && SvPOK(sv)) {
if (PL_utf8cache && canonical_position && !SvGMAGICAL(sv) && SvPOK(sv)) {
if (at_end)
utf8_mg_len_cache_update(sv, mgp, uoffset);
else
Expand Down
10 changes: 9 additions & 1 deletion t/op/index.t
Expand Up @@ -8,7 +8,7 @@ BEGIN {
}

use strict;
plan( tests => 414 );
plan( tests => 415 );

run_tests() unless caller;

Expand Down Expand Up @@ -358,4 +358,12 @@ $x;
EOS
}

{
my $s = "abc";
my $len = length($s);
utf8::upgrade($s);
length($s);
is(index($s, "", $len+1), 3, 'Overlong index doesn\'t confuse utf8 cache');
}

} # end of sub run_tests

0 comments on commit d3e6a43

Please sign in to comment.