Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix loop interpolation bug on Perl 5.28
Without this fix, the Strap demo [if-item-field] ... [/if-item-field]
loop tags are broken on the flypage and elsewhere.

This bug shows that Perl 5.28 no longer processes string concatenation
from left to right such that it is safe to autoincrement a variable that
is referred to elsewhere in the concatenation as well.

I have not seen any other reports of people running into this problem, but
the new behavior can be inferred from the "perl5280delta" documentation
which notes under "Performance Enhancements":

    Many string concatenation expressions are now considerably faster,
    due to the introduction internally of a "multiconcat" opcode which
    combines multiple concatenations, and optionally a "=" or ".=", into
    a single action.

The perlop documentation for "Auto-increment and Auto-decrement" reads:

    "++" and "--" work as in C. [...]

    Note that just as in C, Perl doesn't define when the variable is
    incremented or decremented. You just know it will be done sometime
    before or after the value is returned. This also means that modifying a
    variable twice in the same statement will lead to undefined behavior.
    Avoid statements like:

        $i = $i ++;
        print ++ $i + $i ++;

    Perl will not guarantee what the result of the above statements is.

That does not address changing the variable once and referring to it in
other places, but now it should.
  • Loading branch information
jonjensen committed Sep 18, 2018
1 parent cedd541 commit 7e36bbb
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/Vend/Interpolate.pm
Expand Up @@ -4028,7 +4028,10 @@ my $rit = 1;
sub resolve_nested_if {
my ($where, $what) = @_;
$where =~ s~\[$what\s+(?!.*\[$what\s)(.*?)\[/$what\]~
'[' . $what . $rit . " $1" . '[/' . $what . $rit++ . ']'~seg;
my $out = '[' . $what . $rit . ' ' . $1 . '[/' . $what . $rit . ']';
++$rit;
$out
~seg;
#::logDebug("resolved?\n$where\n");
return $where;
}
Expand Down

0 comments on commit 7e36bbb

Please sign in to comment.