Blame SOURCES/99999-python-2.7.5-issues-17979-17998.patch

f350fc
f350fc
# HG changeset patch
f350fc
# User Serhiy Storchaka <storchaka@gmail.com>
f350fc
# Date 1369166013 -10800
f350fc
# Node ID 8408eed151ebee1c546414f1f40be46c1ad76077
f350fc
# Parent  7fce9186accb10122e45d975f4b380c2ed0fae35
f350fc
Issue #17979: Fixed the re module in build with --disable-unicode.
f350fc
f350fc
diff --git a/Modules/sre.h b/Modules/sre.h
f350fc
--- a/Modules/sre.h
f350fc
+++ b/Modules/sre.h
f350fc
@@ -23,8 +23,8 @@
f350fc
 #  define SRE_MAXREPEAT ((SRE_CODE)PY_SSIZE_T_MAX + 1u)
f350fc
 # endif
f350fc
 #else
f350fc
-# define SRE_CODE unsigned long
f350fc
-# if SIZEOF_SIZE_T > SIZEOF_LONG
f350fc
+# define SRE_CODE unsigned int
f350fc
+# if SIZEOF_SIZE_T > SIZEOF_INT
f350fc
 #  define SRE_MAXREPEAT (~(SRE_CODE)0)
f350fc
 # else
f350fc
 #  define SRE_MAXREPEAT ((SRE_CODE)PY_SSIZE_T_MAX + 1u)
f350fc
f350fc
f350fc
# HG changeset patch
f350fc
# User Serhiy Storchaka <storchaka@gmail.com>
f350fc
# Date 1375547193 -10800
f350fc
# Node ID e5e425fd1e4f7e859abdced43621203cdfa87a16
f350fc
# Parent  8205e72b5cfcdb7a3450c80f3368eff610bc650c
f350fc
Issue #17998: Fix an internal error in regular expression engine.
f350fc
f350fc
diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py
f350fc
--- a/Lib/test/test_re.py
f350fc
+++ b/Lib/test/test_re.py
f350fc
@@ -907,6 +907,16 @@ class ReTests(unittest.TestCase):
f350fc
                 self.assertEqual(m.group(1), "")
f350fc
                 self.assertEqual(m.group(2), "y")
f350fc
 
f350fc
+    def test_issue17998(self):
f350fc
+        for reps in '*', '+', '?', '{1}':
f350fc
+            for mod in '', '?':
f350fc
+                pattern = '.' + reps + mod + 'yz'
f350fc
+                self.assertEqual(re.compile(pattern, re.S).findall('xyz'),
f350fc
+                                 ['xyz'], msg=pattern)
f350fc
+                pattern = pattern.encode()
f350fc
+                self.assertEqual(re.compile(pattern, re.S).findall(b'xyz'),
f350fc
+                                 [b'xyz'], msg=pattern)
f350fc
+
f350fc
 
f350fc
 
f350fc
 def run_re_tests():
f350fc
diff --git a/Modules/_sre.c b/Modules/_sre.c
f350fc
--- a/Modules/_sre.c
f350fc
+++ b/Modules/_sre.c
f350fc
@@ -1028,7 +1028,7 @@ entrance:
f350fc
             TRACE(("|%p|%p|REPEAT_ONE %d %d\n", ctx->pattern, ctx->ptr,
f350fc
                    ctx->pattern[1], ctx->pattern[2]));
f350fc
 
f350fc
-            if (ctx->pattern[1] > end - ctx->ptr)
f350fc
+            if ((Py_ssize_t) ctx->pattern[1] > end - ctx->ptr)
f350fc
                 RETURN_FAILURE; /* cannot match */
f350fc
 
f350fc
             state->ptr = ctx->ptr;
f350fc
@@ -1111,7 +1111,7 @@ entrance:
f350fc
             TRACE(("|%p|%p|MIN_REPEAT_ONE %d %d\n", ctx->pattern, ctx->ptr,
f350fc
                    ctx->pattern[1], ctx->pattern[2]));
f350fc
 
f350fc
-            if (ctx->pattern[1] > end - ctx->ptr)
f350fc
+            if ((Py_ssize_t) ctx->pattern[1] > end - ctx->ptr)
f350fc
                 RETURN_FAILURE; /* cannot match */
f350fc
 
f350fc
             state->ptr = ctx->ptr;
f350fc
@@ -1210,7 +1210,7 @@ entrance:
f350fc
             TRACE(("|%p|%p|MAX_UNTIL %d\n", ctx->pattern,
f350fc
                    ctx->ptr, ctx->count));
f350fc
 
f350fc
-            if (ctx->count < ctx->u.rep->pattern[1]) {
f350fc
+            if (ctx->count < (Py_ssize_t) ctx->u.rep->pattern[1]) {
f350fc
                 /* not enough matches */
f350fc
                 ctx->u.rep->count = ctx->count;
f350fc
                 DO_JUMP(JUMP_MAX_UNTIL_1, jump_max_until_1,
f350fc
@@ -1224,7 +1224,7 @@ entrance:
f350fc
                 RETURN_FAILURE;
f350fc
             }
f350fc
 
f350fc
-            if ((ctx->count < ctx->u.rep->pattern[2] ||
f350fc
+            if ((ctx->count < (Py_ssize_t) ctx->u.rep->pattern[2] ||
f350fc
                 ctx->u.rep->pattern[2] == SRE_MAXREPEAT) &&
f350fc
                 state->ptr != ctx->u.rep->last_ptr) {
f350fc
                 /* we may have enough matches, but if we can
f350fc
@@ -1273,7 +1273,7 @@ entrance:
f350fc
             TRACE(("|%p|%p|MIN_UNTIL %d %p\n", ctx->pattern,
f350fc
                    ctx->ptr, ctx->count, ctx->u.rep->pattern));
f350fc
 
f350fc
-            if (ctx->count < ctx->u.rep->pattern[1]) {
f350fc
+            if (ctx->count < (Py_ssize_t) ctx->u.rep->pattern[1]) {
f350fc
                 /* not enough matches */
f350fc
                 ctx->u.rep->count = ctx->count;
f350fc
                 DO_JUMP(JUMP_MIN_UNTIL_1, jump_min_until_1,
f350fc
@@ -1302,7 +1302,7 @@ entrance:
f350fc
 
f350fc
             LASTMARK_RESTORE();
f350fc
 
f350fc
-            if ((ctx->count >= ctx->u.rep->pattern[2]
f350fc
+            if ((ctx->count >= (Py_ssize_t) ctx->u.rep->pattern[2]
f350fc
                 && ctx->u.rep->pattern[2] != SRE_MAXREPEAT) ||
f350fc
                 state->ptr == ctx->u.rep->last_ptr)
f350fc
                 RETURN_FAILURE;
f350fc
diff --git a/Modules/sre.h b/Modules/sre.h
f350fc
--- a/Modules/sre.h
f350fc
+++ b/Modules/sre.h
f350fc
@@ -20,14 +20,14 @@
f350fc
 # if SIZEOF_SIZE_T > 4
f350fc
 #  define SRE_MAXREPEAT (~(SRE_CODE)0)
f350fc
 # else
f350fc
-#  define SRE_MAXREPEAT ((SRE_CODE)PY_SSIZE_T_MAX + 1u)
f350fc
+#  define SRE_MAXREPEAT ((SRE_CODE)PY_SSIZE_T_MAX)
f350fc
 # endif
f350fc
 #else
f350fc
 # define SRE_CODE unsigned int
f350fc
 # if SIZEOF_SIZE_T > SIZEOF_INT
f350fc
 #  define SRE_MAXREPEAT (~(SRE_CODE)0)
f350fc
 # else
f350fc
-#  define SRE_MAXREPEAT ((SRE_CODE)PY_SSIZE_T_MAX + 1u)
f350fc
+#  define SRE_MAXREPEAT ((SRE_CODE)PY_SSIZE_T_MAX)
f350fc
 # endif
f350fc
 #endif
f350fc
 
f350fc