Mailing List Archive

[interchange] Fix loop interpolation bug on Perl 5.28
commit 7e36bbb3fd067fca72c883b1e048f42581bbd41c
Author: Jon Jensen <jon@endpoint.com>
Date: Tue Sep 18 12:57:51 2018 -0600

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.

lib/Vend/Interpolate.pm | 5 ++++-
1 files changed, 4 insertions(+), 1 deletions(-)
---
diff --git a/lib/Vend/Interpolate.pm b/lib/Vend/Interpolate.pm
index 38677e6..4f051b3 100644
--- a/lib/Vend/Interpolate.pm
+++ b/lib/Vend/Interpolate.pm
@@ -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;
}

_______________________________________________
interchange-cvs mailing list
interchange-cvs@icdevgroup.org
http://www.icdevgroup.org/mailman/listinfo/interchange-cvs