summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2012-12-02 11:52:36 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2012-12-02 11:52:36 (GMT)
commitb83575b0a5a798301a85a602a8d888329da0cf88 (patch)
tree28e0145d0a58bb0c893421c95374c6c8c156259f
parent4fc00826024016f1a81ee4453902aa15e1a3ba75 (diff)
downloadcpython-b83575b0a5a798301a85a602a8d888329da0cf88.zip
cpython-b83575b0a5a798301a85a602a8d888329da0cf88.tar.gz
cpython-b83575b0a5a798301a85a602a8d888329da0cf88.tar.bz2
Issue #10182: The re module doesn't truncate indices to 32 bits anymore.
Patch by Serhiy Storchaka.
-rw-r--r--Lib/test/test_re.py16
-rw-r--r--Misc/NEWS3
-rw-r--r--Modules/_sre.c10
3 files changed, 24 insertions, 5 deletions
diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py
index ff2c953..befe0e8 100644
--- a/Lib/test/test_re.py
+++ b/Lib/test/test_re.py
@@ -1,4 +1,5 @@
from test.test_support import verbose, run_unittest, import_module
+from test.test_support import precisionbigmemtest, _2G
import re
from re import Scanner
import sys
@@ -819,6 +820,21 @@ class ReTests(unittest.TestCase):
# Test behaviour when not given a string or pattern as parameter
self.assertRaises(TypeError, re.compile, 0)
+ # The huge memuse is because of re.sub() using a list and a join()
+ # to create the replacement result.
+ @precisionbigmemtest(size=_2G, memuse=20)
+ def test_large(self, size):
+ # Issue #10182: indices were 32-bit-truncated.
+ s = 'a' * size
+ m = re.search('$', s)
+ self.assertIsNotNone(m)
+ self.assertEqual(m.start(), size)
+ self.assertEqual(m.end(), size)
+ r, n = re.subn('', '', s)
+ self.assertEqual(r, s)
+ self.assertEqual(n, size + 1)
+
+
def run_re_tests():
from test.re_tests import tests, SUCCEED, FAIL, SYNTAX_ERROR
if verbose:
diff --git a/Misc/NEWS b/Misc/NEWS
index 89f7e22..3d49637 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -154,6 +154,9 @@ Core and Builtins
Library
-------
+- Issue #10182: The re module doesn't truncate indices to 32 bits anymore.
+ Patch by Serhiy Storchaka.
+
- Issue #16573: In 2to3, treat enumerate() like a consuming call, so superfluous
list() calls aren't added to filter(), map(), and zip() which are directly
passed enumerate().
diff --git a/Modules/_sre.c b/Modules/_sre.c
index ab4f269..baf5f6a 100644
--- a/Modules/_sre.c
+++ b/Modules/_sre.c
@@ -1636,7 +1636,7 @@ static PyObject*pattern_scanner(PatternObject*, PyObject*);
static PyObject *
sre_codesize(PyObject* self, PyObject *unused)
{
- return Py_BuildValue("l", sizeof(SRE_CODE));
+ return PyLong_FromSize_t(sizeof(SRE_CODE));
}
static PyObject *
@@ -2448,7 +2448,7 @@ next:
return NULL;
if (subn)
- return Py_BuildValue("Ni", item, n);
+ return Py_BuildValue("Nn", item, n);
return item;
@@ -3389,7 +3389,7 @@ match_start(MatchObject* self, PyObject* args)
}
/* mark is -1 if group is undefined */
- return Py_BuildValue("i", self->mark[index*2]);
+ return PyLong_FromSsize_t(self->mark[index*2]);
}
static PyObject*
@@ -3412,7 +3412,7 @@ match_end(MatchObject* self, PyObject* args)
}
/* mark is -1 if group is undefined */
- return Py_BuildValue("i", self->mark[index*2+1]);
+ return PyLong_FromSsize_t(self->mark[index*2+1]);
}
LOCAL(PyObject*)
@@ -3562,7 +3562,7 @@ static PyObject *
match_lastindex_get(MatchObject *self)
{
if (self->lastindex >= 0)
- return Py_BuildValue("i", self->lastindex);
+ return PyLong_FromSsize_t(self->lastindex);
Py_INCREF(Py_None);
return Py_None;
}