Issue #25554: Got rid of circular references in regular expression parsing.
authorSerhiy Storchaka <storchaka@gmail.com>
Thu, 5 Nov 2015 15:49:26 +0000 (17:49 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Thu, 5 Nov 2015 15:49:26 +0000 (17:49 +0200)
Lib/sre_parse.py
Misc/NEWS

index 67f84e940f5f03987aa832e0523664eb23dffe65..f6a88517dfc3b5a4e34501d9175c0a48bcff2478 100644 (file)
@@ -70,14 +70,14 @@ class Pattern:
     def __init__(self):
         self.flags = 0
         self.groupdict = {}
-        self.subpatterns = [None]  # group 0
+        self.groupwidths = [None]  # group 0
         self.lookbehindgroups = None
     @property
     def groups(self):
-        return len(self.subpatterns)
+        return len(self.groupwidths)
     def opengroup(self, name=None):
         gid = self.groups
-        self.subpatterns.append(None)
+        self.groupwidths.append(None)
         if self.groups > MAXGROUPS:
             raise error("too many groups")
         if name is not None:
@@ -88,9 +88,9 @@ class Pattern:
             self.groupdict[name] = gid
         return gid
     def closegroup(self, gid, p):
-        self.subpatterns[gid] = p
+        self.groupwidths[gid] = p.getwidth()
     def checkgroup(self, gid):
-        return gid < self.groups and self.subpatterns[gid] is not None
+        return gid < self.groups and self.groupwidths[gid] is not None
 
     def checklookbehindgroup(self, gid, source):
         if self.lookbehindgroups is not None:
@@ -195,7 +195,7 @@ class SubPattern:
                 lo = lo + 1
                 hi = hi + 1
             elif op is GROUPREF:
-                i, j = self.pattern.subpatterns[av].getwidth()
+                i, j = self.pattern.groupwidths[av]
                 lo = lo + i
                 hi = hi + j
             elif op is GROUPREF_EXISTS:
index 8d427446d97b4871ed17910b2531dfa3aae561d6..f2ce94afe691e7a14b47b444de0298f2cfecac43 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -54,6 +54,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #25554: Got rid of circular references in regular expression parsing.
+
 - Issue #25510: fileinput.FileInput.readline() now returns b'' instead of ''
   at the end if the FileInput was opened with binary mode.
   Patch by Ryosuke Ito.