In perl.git, the branch smoke-me/jkeenan/134371-gconvert has been updated

<https://perl5.git.perl.org/perl.git/commitdiff/cbe855980207aeda6b23f7e7e29dcbfaacd0bee1?hp=a9425c441038c158f8c7ad2195c13345098385be>

  discards  a9425c441038c158f8c7ad2195c13345098385be (commit)
  discards  74cd64c71e837fea3e6a758bb50eaa09570f40d7 (commit)
- Log -----------------------------------------------------------------
commit cbe855980207aeda6b23f7e7e29dcbfaacd0bee1
Author: Andy Dougherty <[email protected]>
Date:   Sun Aug 18 22:02:59 2019 -0400

    Change Gconvert checkit() prototype for [perl #134371].
    
    In the checkit() routine inside Configure, clang++ was taking the
    if (strcmp(expect, got)) branch even though the 'expect' and 'got' strings
    were identical.  A first step in debugging this was to realize that
    the checkit() function never returned a value, so relabel it as void.
    With clang version 7.0.1-8 (tags/RELEASE_701/final) (Debian),
    this change seems to work around the strcmp issue.

commit 9a8b32d8f9202f3e5e5ac4732e458744bb2df3fa
Author: James E Keenan <[email protected]>
Date:   Sun Aug 18 13:16:56 2019 +0000

    Reset xxx_convert to empty string if none of 3 utilities is found
    
    This will cause Configure to enter the WHOA block and default to using
    sprintf.
    
    For RT # 134371

-----------------------------------------------------------------------

Summary of changes:
 pod/perldelta.pod   |  7 +++++++
 pod/perldiag.pod    |  5 +++++
 regcomp.c           | 42 +++++++++++++++++++++++++++++++-----------
 t/lib/croak/regcomp |  9 +++++++++
 4 files changed, 52 insertions(+), 11 deletions(-)

diff --git a/pod/perldelta.pod b/pod/perldelta.pod
index fb3c2cd532..7588464322 100644
--- a/pod/perldelta.pod
+++ b/pod/perldelta.pod
@@ -57,6 +57,13 @@ as strings so ranges like C< "00" .. "03" > produced C< 
"00", "01",
 
 [perl #133695]
 
+=head2 C<\K> now disallowed in look-ahead and look-behind assertions
+
+This was disallowed because it causes unexpected behaviour, and no-one
+could define what the desired behaviour was.
+
+[perl #124256]
+
 =head1 Deprecations
 
 XXX Any deprecated features, syntax, modules etc. should be listed here.
diff --git a/pod/perldiag.pod b/pod/perldiag.pod
index f9c023d148..2fa4b62257 100644
--- a/pod/perldiag.pod
+++ b/pod/perldiag.pod
@@ -3277,6 +3277,11 @@ line.  See L<perlrun> for more details.
 
 (P) The regular expression parser is confused.
 
+=item \K not permitted in lookahead/lookbehind in regex; marked by <-- HERE in 
m/%s/
+
+(F) Your regular expression used C<\K> in a lookhead or lookbehind
+assertion, which isn't permitted.
+
 =item Label not found for "last %s"
 
 (F) You named a loop to break out of, but you're not currently in a loop
diff --git a/regcomp.c b/regcomp.c
index cf9246473f..aba6648da5 100644
--- a/regcomp.c
+++ b/regcomp.c
@@ -182,6 +182,7 @@ struct RExC_state_t {
                                            through */
     U32         study_chunk_recursed_bytes;  /* bytes in bitmap */
     I32                in_lookbehind;
+    I32                in_lookahead;
     I32                contains_locale;
     I32                override_recoding;
 #ifdef EBCDIC
@@ -273,6 +274,7 @@ struct RExC_state_t {
 #define RExC_study_chunk_recursed_bytes  \
                                    (pRExC_state->study_chunk_recursed_bytes)
 #define RExC_in_lookbehind     (pRExC_state->in_lookbehind)
+#define RExC_in_lookahead      (pRExC_state->in_lookahead)
 #define RExC_contains_locale   (pRExC_state->contains_locale)
 #ifdef EBCDIC
 #   define RExC_recode_x_to_native (pRExC_state->recode_x_to_native)
@@ -7622,6 +7624,7 @@ Perl_re_op_compile(pTHX_ SV ** const patternp, int 
pat_count,
     RExC_seen = 0;
     RExC_maxlen = 0;
     RExC_in_lookbehind = 0;
+    RExC_in_lookahead = 0;
     RExC_seen_zerolen = *exp == '^' ? -1 : 0;
 #ifdef EBCDIC
     RExC_recode_x_to_native = 0;
@@ -11078,6 +11081,13 @@ S_reg(pTHX_ RExC_state_t *pRExC_state, I32 paren, I32 
*flagp, U32 depth)
 
     *flagp = 0;                                /* Tentatively. */
 
+    if (RExC_in_lookbehind) {
+       RExC_in_lookbehind++;
+    }
+    if (RExC_in_lookahead) {
+        RExC_in_lookahead++;
+    }
+
     /* Having this true makes it feasible to have a lot fewer tests for the
      * parse pointer being in scope.  For example, we can write
      *      while(isFOO(*RExC_parse)) RExC_parse++;
@@ -11542,10 +11552,11 @@ S_reg(pTHX_ RExC_state_t *pRExC_state, I32 paren, I32 
*flagp, U32 depth)
                 if (RExC_parse >= RExC_end) {
                     vFAIL("Sequence (?... not terminated");
                 }
-
-                /* FALLTHROUGH */
+                RExC_seen_zerolen++;
+                break;
            case '=':           /* (?=...) */
                RExC_seen_zerolen++;
+                RExC_in_lookahead++;
                 break;
            case '!':           /* (?!...) */
                RExC_seen_zerolen++;
@@ -12344,6 +12355,9 @@ S_reg(pTHX_ RExC_state_t *pRExC_state, I32 paren, I32 
*flagp, U32 depth)
     if (RExC_in_lookbehind) {
        RExC_in_lookbehind--;
     }
+    if (RExC_in_lookahead) {
+        RExC_in_lookahead--;
+    }
     if (after_freeze > RExC_npar)
         RExC_npar = after_freeze;
     return(ret);
@@ -13429,15 +13443,21 @@ S_regatom(pTHX_ RExC_state_t *pRExC_state, I32 
*flagp, U32 depth)
            *flagp |= SIMPLE;
            goto finish_meta_pat;
        case 'K':
-           RExC_seen_zerolen++;
-           ret = reg_node(pRExC_state, KEEPS);
-           *flagp |= SIMPLE;
-           /* XXX:dmq : disabling in-place substitution seems to
-            * be necessary here to avoid cases of memory corruption, as
-            * with: C<$_="x" x 80; s/x\K/y/> -- rgs
-            */
-            RExC_seen |= REG_LOOKBEHIND_SEEN;
-           goto finish_meta_pat;
+            if (!RExC_in_lookbehind && !RExC_in_lookahead) {
+                RExC_seen_zerolen++;
+                ret = reg_node(pRExC_state, KEEPS);
+                *flagp |= SIMPLE;
+                /* XXX:dmq : disabling in-place substitution seems to
+                 * be necessary here to avoid cases of memory corruption, as
+                 * with: C<$_="x" x 80; s/x\K/y/> -- rgs
+                 */
+                RExC_seen |= REG_LOOKBEHIND_SEEN;
+                goto finish_meta_pat;
+            }
+            else {
+                ++RExC_parse; /* advance past the 'K' */
+                vFAIL("\\K not permitted in lookahead/lookbehind");
+            }
        case 'Z':
            ret = reg_node(pRExC_state, SEOL);
            *flagp |= SIMPLE;
diff --git a/t/lib/croak/regcomp b/t/lib/croak/regcomp
index 0ba705e915..fc410829b6 100644
--- a/t/lib/croak/regcomp
+++ b/t/lib/croak/regcomp
@@ -70,3 +70,12 @@ qr/((a))/;
 EXPECT
 Too many nested open parens in regex; marked by <-- HERE in m/(( <-- HERE a))/ 
at - line 3.
 ########
+# NAME \K not permitted in lookahead
+$x =~ /(?=a\Ka)a/;
+EXPECT
+\K not permitted in lookahead/lookbehind in regex; marked by <-- HERE in 
m/(?=a\K <-- HERE a)a/ at - line 1.
+########
+# NAME \K not permitted in lookbehind
+$x =~ /(?<=a\Ka)a/;
+EXPECT
+\K not permitted in lookahead/lookbehind in regex; marked by <-- HERE in 
m/(?<=a\K <-- HERE a)a/ at - line 1.

-- 
Perl5 Master Repository

Reply via email to