develooper Front page | perl.perl5.porters | Postings from July 2001

bleadperl bug: regex re-entrance

Thread Next
From:
Jeff 'japhy/Marillion' Pinyan
Date:
July 24, 2001 21:39
Subject:
bleadperl bug: regex re-entrance
Message ID:
Pine.GSO.4.21.0107250027480.18222-100000@crusoe.crusoe.net
(Please note that this has not been sent via perlbug, but is
correspondance with Hugo, and I decided to let you all know about it.  It
seems there are severe problems in executing a regex inside another regex,
which leads me to believe that the engine really is NOT re-entrant for
pattern matching -- these problems don't necessarily exist for
substitutions, as I have seen Damian do regexes in the RHS of a s///g.)

Code:

  "baaz" =~ m{
    .*
    (?(?{ reverse("$`$&") =~ /^z.*a/ })
      (?=) | (?!)
    )
  }x;

This dumps core (or gives a bus error, or some other nastiness).  I
suspect the problem is based upon the need for ACTUAL EVALUATION of a
regex -- when we merely use /z/ or /za/, Perl can use an index()-like
approach -- but as soon as I make it work by employing regex-specific
notes, it breaks down.

This is shown here:

  "baaz" =~ m{
    .*
    (?(?{ reverse("$`$&") =~ /z/ })
      (?=) | (?!)
    )
  }x;

That succeeds.  The following make it break:

  /z/i
  /[zZ]/
  /z|Z/

Using the modifier /m or /s is not problem-inducing, but only because they
effect they have is never carried out, due to the fact that no anchors nor
the . are ever allowed in this embedded regex.

This strongly leads me to believe that Perl is not ACTUALLY doing an
internal regex, and is instead seeing that the regex can really be
optimized into a substring match.

-- 
Jeff "japhy" Pinyan      japhy@pobox.com      http://www.pobox.com/~japhy/
I am Marillion, the wielder of Ringril, known as Hesinaur, the Winter-Sun.
Are you a Monk?  http://www.perlmonks.com/     http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc.     http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter.         Brother #734
**      Manning Publications, Co, is publishing my Perl Regex book      **


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About