Skip to content

Commit

Permalink
use additional get_condition_dor when DOR op and next is NEXTSTATE
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Nov 20, 2024
1 parent 336541c commit 049d299
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
31 changes: 25 additions & 6 deletions Cover.xs
Original file line number Diff line number Diff line change
Expand Up @@ -703,11 +703,9 @@ static OP *find_skipped_conditional(pTHX_ OP *o) {
}
#endif

/* NOTE: caller must protect get_condition calls by locking DC_mutex */

/* NOTE: caller must protect get_condition* calls by locking DC_mutex */
static OP *get_condition(pTHX) {
SV **pc = hv_fetch(Pending_conditionals, get_key(PL_op), KEY_SZ, 0);

if (pc && SvROK(*pc)) {
dSP;
int true_ish;
Expand All @@ -724,10 +722,29 @@ static OP *get_condition(pTHX) {
PL_op, (void *)PL_op->op_targ, pc, hex_key(get_key(PL_op))));
dump_conditions(aTHX);
NDEB(svdump(Pending_conditionals));
/* croak("urgh"); */
exit(1);
}

return PL_op;
}
static OP *get_condition_dor(pTHX) {
SV **pc = hv_fetch(Pending_conditionals, get_key(PL_op), KEY_SZ, 0);
if (pc && SvROK(*pc)) {
dSP;
int true_ish;
NDEB(D(L, "get_condition_dor from %p, %p: %p (%s)\n",
PL_op, (void *)PL_op->op_targ, pc, hex_key(get_key(PL_op))));
/* dump_conditions(aTHX); */
NDEB(svdump(Pending_conditionals));
true_ish = SvOK(TOPs);
NDEB(D(L, " get_condition_dor true_ish=%d\n", true_ish));
add_condition(aTHX_ *pc, true_ish ? 2 : 1);
} else {
PDEB(D(L, "All is lost, I know not where to go from %p, %p: %p (%s)\n",
PL_op, (void *)PL_op->op_targ, pc, hex_key(get_key(PL_op))));
dump_conditions(aTHX);
NDEB(svdump(Pending_conditionals));
exit(1);
}
return PL_op;
}

Expand Down Expand Up @@ -919,7 +936,9 @@ static void cover_logop(pTHX) {
NDEB(op_dump(PL_op));
NDEB(op_dump(next));

next->op_ppaddr = get_condition;
next->op_ppaddr = (next->op_type == OP_NEXTSTATE && (
PL_op->op_type == OP_DOR || PL_op->op_type == OP_DORASSIGN))
? get_condition_dor : get_condition;
MUTEX_UNLOCK(&DC_mutex);
}
} else {
Expand Down
11 changes: 7 additions & 4 deletions test_output/cover/overload_bool.5.012000
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ Reading database from ...
------------------- ------ ------ ------ ------ ------
File stmt bran cond sub total
------------------- ------ ------ ------ ------ ------
tests/overload_bool 63.6 50.0 50.0 25.0 52.6
Total 63.6 50.0 50.0 25.0 52.6
tests/overload_bool 69.2 50.0 50.0 25.0 56.5
Total 69.2 50.0 50.0 25.0 56.5
------------------- ------ ------ ------ ------ ------


Expand Down Expand Up @@ -45,8 +45,10 @@ line err stmt bran cond sub code
21
22 1 my $boolobj = bless {}, 'Foo';
23 *** 1 * 50 $boolobj //= 5;
24
25 1;
24 *** 1 * 50 my $var; $var //= bless {}, "Foo";
1
25
26 1;


Branches
Expand All @@ -65,6 +67,7 @@ or 2 conditions
line err % l !l expr
----- --- ------ ------ ------ ----
23 *** 50 1 0 $boolobj //= 5
24 *** 50 0 1 $var //= bless({}, "Foo")


Covered Subroutines
Expand Down
1 change: 1 addition & 0 deletions tests/overload_bool
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ bless {}, 'Foo' if $foo;

my $boolobj = bless {}, 'Foo';
$boolobj //= 5;
my $var; $var //= bless {}, "Foo";

1;

0 comments on commit 049d299

Please sign in to comment.