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