Skip to content

Commit c2e5b9b

Browse files
committed
C: Simplify RX and add xpvlvsect
only set the SvANY(REGEXP *re) once. This fixes the remaining REGEXP tests 1431, 1432, t/issue143.t
1 parent 70d6c34 commit c2e5b9b

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

lib/B/C.pm

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3444,18 +3444,19 @@ sub B::REGEXP::save {
34443444
return $sym if defined $sym;
34453445
my $pv = $sv->PV;
34463446
my $cur = $sv->CUR;
3447+
my $is_utf8 = $sv->FLAGS & SVf_UTF8;
34473448
# construct original PV
34483449
$pv =~ s/^(\(\?\^[adluimsx-]*\:)(.*)\)$/$2/;
34493450
$cur -= length($sv->PV) - length($pv);
34503451
my $cstr = cstring($pv);
3452+
# The SvPV field: since df6b4bd56551f2d39f7c again the PV, before the RX
3453+
my $rx_or_pv = (!$CPERL51 and $] < 5.027003) or ($CPERL51 and $] < 5.027002) ? 1 : 0;
34513454
# Unfortunately this XPV is needed temp. Later replaced by struct regexp.
34523455
$xpvsect->add(sprintf("%s{0}, %u, %u", $PERL514 ? "Nullhv, " : "", $cur, 0 ) );
34533456
$svsect->add(sprintf("&xpv_list[%d], $u32fmt, 0x%x, {%s}",
3454-
$xpvsect->index, $sv->REFCNT, $sv->FLAGS, $] > 5.017006 ? "NULL" : $cstr));
3457+
$xpvsect->index, $sv->REFCNT, $sv->FLAGS, $] > 5.017006 ? "NULL" : $cstr));
34553458
my $ix = $svsect->index;
34563459
warn "Saving RX $cstr to sv_list[$ix]\n" if $debug{rx} or $debug{sv};
3457-
# The SvPV field: since df6b4bd56551f2d39f7c again the PV, before the RX
3458-
my $rx_or_pv = (!$CPERL51 and $] < 5.027003) or ($CPERL51 and $] < 5.027002) ? 1 : 0;
34593460
my $initpm = $init;
34603461
if ($] > 5.011) {
34613462
my $pmflags = $PERL522 ? $sv->compflags : $sv->EXTFLAGS;
@@ -3464,14 +3465,16 @@ sub B::REGEXP::save {
34643465
$initpm->add("PL_hints |= HINT_RE_EVAL;");
34653466
}
34663467
$initpm->add("{",
3467-
sprintf(" SV* sv = newSVpvn(%s, %d);", $cstr, $cur),
3468-
# replace sv_any->XPV with struct regexp. need pv and extflags
3469-
sprintf(" sv_list[$ix].sv_any = SvANY(CALLREGCOMP(sv, 0x%x));",
3470-
$pmflags),
3471-
$rx_or_pv
3472-
# and set the pv or rx field
3473-
? " sv_list[$ix].sv_u.svu_rx = (struct regexp*)SvANY(&sv_list[$ix]);"
3474-
: " sv_list[$ix].sv_u.svu_pv = sv->sv_u.svu_pv;",
3468+
sprintf(" SV* sv = newSVpvn_flags(%s, %d, %d);", $cstr, $cur, $is_utf8),
3469+
# need pv and extflags
3470+
sprintf(" REGEXP *re = CALLREGCOMP(sv, 0x%x);", $pmflags),
3471+
# replace sv_any->XPV with struct regexp or pv.
3472+
((!$rx_or_pv and $sv->FLAGS & SVt_PVLV)
3473+
? " Copy(re, &sv_list[$ix], sizeof(REGEXP), char);"
3474+
: " struct regexp *rx = (struct regexp *)SvANY(re);\n\t"
3475+
. ($] < 5.017006
3476+
? " SvANY(&sv_list[$ix]) = rx;"
3477+
: " SvANY(&sv_list[$ix]) = (&sv_list[$ix])->sv_u.svu_rx = rx;")),
34753478
"}");
34763479
if ($PERL518 and $sv->EXTFLAGS & RXf_EVAL_SEEN) {
34773480
$initpm->add("PL_hints &= ~HINT_RE_EVAL;");
@@ -3481,11 +3484,6 @@ sub B::REGEXP::save {
34813484
# since 5.17.6 the SvLEN stores RX_WRAPPED(rx)
34823485
$init->add(sprintf("SvCUR(&sv_list[%d]) = %d;", $ix, $cur),
34833486
"SvLEN(&sv_list[$ix]) = 0;");
3484-
} elsif (!$rx_or_pv and $sv->FLAGS & SVt_PVLV) { # since df6b4bd56551f2d39f7c
3485-
# $init->add("sv_list[$ix].sv_u.svu_pv = (char*)sv_list[$ix].sv_any;");
3486-
$initpm->add("{ struct regexp* rx = (struct regexp*)sv_list[$ix].sv_any;",
3487-
" rx->xpv_len_u.xpvlenu_rx = (struct regexp*)sv_list[$ix].sv_any;",
3488-
"}");
34893487
}
34903488
$svsect->debug( $fullname, $sv->flagspv ) if $debug{flags};
34913489
$sym = savesym( $sv, sprintf( "&sv_list[%d]", $ix ) );

0 commit comments

Comments
 (0)