[pypy-commit] pypy unicode-utf8: (ronan, arigo)

arigo pypy.commits at gmail.com
Sun Mar 18 12:19:04 EDT 2018


Author: Armin Rigo <arigo at tunes.org>
Branch: unicode-utf8
Changeset: r93990:52a945178f9b
Date: 2018-03-18 17:18 +0100
http://bitbucket.org/pypy/pypy/changeset/52a945178f9b/

Log:	(ronan, arigo)

	Attempt to fix the merge for module/_sre

diff --git a/pypy/module/_sre/interp_sre.py b/pypy/module/_sre/interp_sre.py
--- a/pypy/module/_sre/interp_sre.py
+++ b/pypy/module/_sre/interp_sre.py
@@ -156,18 +156,21 @@
             return rsre_core.BufMatchContext(self.code, buf,
                                              pos, endpos, self.flags)
 
-    def fresh_copy(self, ctx, start):
+    def fresh_copy(self, ctx):
         if isinstance(ctx, rsre_utf8.Utf8MatchContext):
             result = rsre_utf8.Utf8MatchContext(
-                ctx.pattern, ctx._utf8, start, ctx.end, ctx.flags)
+                ctx.pattern, ctx._utf8, ctx.match_start, ctx.end, ctx.flags)
             result.w_unicode_obj = ctx.w_unicode_obj
-            return result
-        if isinstance(ctx, rsre_core.StrMatchContext):
-            return self._make_str_match_context(ctx._string, start, ctx.end)
-        if isinstance(ctx, rsre_core.BufMatchContext):
-            return rsre_core.BufMatchContext(
-                ctx.pattern, ctx._buffer, start, ctx.end, ctx.flags)
-        raise AssertionError("bad ctx type")
+        elif isinstance(ctx, rsre_core.StrMatchContext):
+            result = self._make_str_match_context(
+                ctx._string, ctx.match_start, ctx.end)
+        elif isinstance(ctx, rsre_core.BufMatchContext):
+            result = rsre_core.BufMatchContext(
+                ctx.pattern, ctx._buffer, ctx.match_start, ctx.end, ctx.flags)
+        else:
+            raise AssertionError("bad ctx type")
+        result.match_end = ctx.match_end
+        return result
 
     def _make_str_match_context(self, str, pos, endpos):
         # for tests to override
@@ -343,7 +346,7 @@
                 if filter_is_callable:
                     w_match = self.getmatch(ctx, True)
                     # make a copy of 'ctx'; see test_sub_matches_stay_valid
-                    ctx = ctx.fresh_copy(start) # match_start/match_end dropped
+                    ctx = self.fresh_copy(ctx)
                     w_piece = space.call_function(w_filter, w_match)
                     if not space.is_w(w_piece, space.w_None):
                         assert strbuilder is None
@@ -720,7 +723,8 @@
             if exhausted:
                 self.ctx = None
             else:
-                self.ctx = self.srepat.fresh_copy(ctx, nextstart)
+                self.ctx = self.srepat.fresh_copy(ctx)
+                self.ctx.match_start = nextstart
             match = W_SRE_Match(self.srepat, ctx)
             return match
         else:
diff --git a/rpython/rlib/rsre/rsre_core.py b/rpython/rlib/rsre/rsre_core.py
--- a/rpython/rlib/rsre/rsre_core.py
+++ b/rpython/rlib/rsre/rsre_core.py
@@ -92,8 +92,6 @@
 class AbstractMatchContext(object):
     """Abstract base class"""
     _immutable_fields_ = ['pattern[*]', 'flags', 'end']
-    match_start = 0
-    match_end = 0
     match_marks = None
     match_marks_flat = None
     fullmatch_only = False
@@ -105,6 +103,7 @@
         check_nonneg(end)
         self.pattern = pattern
         self.match_start = match_start
+        self.match_end = self.ZERO
         self.end = end
         self.flags = flags
         # check we don't get the old value of MAXREPEAT
@@ -309,9 +308,6 @@
     def get_single_byte(self, base_position, index):
         return self.str(base_position + index)
 
-    def fresh_copy(self, start):
-        return UnicodeMatchContext(self.pattern, self._unicodestr, start,
-                                   self.end, self.flags)
 
 # ____________________________________________________________
 
diff --git a/rpython/rlib/rsre/test/support.py b/rpython/rlib/rsre/test/support.py
--- a/rpython/rlib/rsre/test/support.py
+++ b/rpython/rlib/rsre/test/support.py
@@ -106,10 +106,6 @@
         assert isinstance(index, int)
         return Position(base_position._p + index)
 
-    def fresh_copy(self, start):
-        return MatchContextForTests(self.pattern, self._string, start,
-                                    self.end, self.flags)
-
 
 def match(pattern, string, start=0, end=sys.maxint, flags=0, fullmatch=False):
     start, end = _adjust(start, end, len(string))


More information about the pypy-commit mailing list