[pypy-svn] pypy default: Fix for issue #627: extend the zero-width match protection to
arigo
commits-noreply at bitbucket.org
Wed Jan 26 16:54:03 CET 2011
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r41357:ff94cd12b5e5
Date: 2011-01-26 16:53 +0100
http://bitbucket.org/pypy/pypy/changeset/ff94cd12b5e5/
Log: Fix for issue #627: extend the zero-width match protection to try
the next match instead of just dropping all future matches.
diff --git a/pypy/rlib/rsre/rsre_core.py b/pypy/rlib/rsre/rsre_core.py
--- a/pypy/rlib/rsre/rsre_core.py
+++ b/pypy/rlib/rsre/rsre_core.py
@@ -385,10 +385,13 @@
marks = p.marks
enum = p.enum.move_to_next_result(ctx)
#
+ # zero-width match protection
min = ctx.pat(ppos+1)
- if (enum is not None and
- (ptr != ctx.match_end or self.num_pending < min)):
- # ^^^^^^^^^^ zero-width match protection
+ if self.num_pending >= min:
+ while enum is not None and ptr == ctx.match_end:
+ enum = enum.move_to_next_result(ctx)
+ #
+ if enum is not None:
# matched one more 'item'. record it and continue.
self.pending = Pending(ptr, marks, enum, self.pending)
self.num_pending += 1
@@ -436,12 +439,15 @@
if max == 65535 or self.num_pending < max:
# try to match one more 'item'
enum = sre_match(ctx, ppos + 3, ptr, marks)
+ #
+ # zero-width match protection
+ if self.num_pending >= min:
+ while enum is not None and ptr == ctx.match_end:
+ enum = enum.move_to_next_result(ctx)
else:
enum = None # 'max' reached, no more matches
- while (enum is None or
- (ptr == ctx.match_end and self.num_pending >= min)):
- # ^^^^^^^^^^ zero-width match protection
+ while enum is None:
# 'item' does not match; try to get further results from
# the 'pending' list.
p = self.pending
More information about the Pypy-commit
mailing list