This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
pp_match(): clarify intuit parens behaviour
authorDavid Mitchell <davem@iabyn.com>
Tue, 22 May 2012 09:40:55 +0000 (10:40 +0100)
committerDavid Mitchell <davem@iabyn.com>
Wed, 13 Jun 2012 12:32:53 +0000 (13:32 +0100)
There was some dodgy code, (flagged by dmq), that as well
as setting RX_LASTPAREN(rx),  RX_LASTCLOSEPAREN(rx) to zero,
also set RX_NPARENS(rx) to zero.

The actual logic is that if we reach that point, the pattern shouldn't
have any capturing parentheses, so instead of assigning zero to it, assert
that RX_NPARENS(rx) is zero.

pp_hot.c

index 93d5a1f..17d1e8f 100644 (file)
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -1527,9 +1527,9 @@ yup:                                      /* Confirmed by INTUIT */
        RX_OFFS(rx)[0].start = s - truebase;
        RX_OFFS(rx)[0].end = s - truebase + RX_MINLENRET(rx);
     }
        RX_OFFS(rx)[0].start = s - truebase;
        RX_OFFS(rx)[0].end = s - truebase + RX_MINLENRET(rx);
     }
-    /* including RX_NPARENS(rx) in the below code seems highly suspicious.
-       -dmq */
-    RX_NPARENS(rx) = RX_LASTPAREN(rx) = RX_LASTCLOSEPAREN(rx) = 0;     /* used by @-, @+, and $^N */
+    /* match via INTUIT shouldn't have any captures. Let @-, @+, $^N know */
+    assert(!RX_NPARENS(rx));
+    RX_LASTPAREN(rx) = RX_LASTCLOSEPAREN(rx) = 0;
     LEAVE_SCOPE(oldsave);
     RETPUSHYES;
 
     LEAVE_SCOPE(oldsave);
     RETPUSHYES;