[Python-checkins] cpython (3.3): Issues #23363, #23364, #23365, #23366: Fixed itertools overflow tests.
serhiy.storchaka
python-checkins at python.org
Tue Feb 3 01:05:57 CET 2015
https://hg.python.org/cpython/rev/356ed025dbae
changeset: 94476:356ed025dbae
branch: 3.3
parent: 94471:5c730d30ffbc
user: Serhiy Storchaka <storchaka at gmail.com>
date: Tue Feb 03 01:34:09 2015 +0200
summary:
Issues #23363, #23364, #23365, #23366: Fixed itertools overflow tests.
Used PyMem_New to check overflow.
files:
Lib/test/test_itertools.py | 12 +++++-------
Modules/itertoolsmodule.c | 26 ++++++--------------------
2 files changed, 11 insertions(+), 27 deletions(-)
diff --git a/Lib/test/test_itertools.py b/Lib/test/test_itertools.py
--- a/Lib/test/test_itertools.py
+++ b/Lib/test/test_itertools.py
@@ -260,7 +260,7 @@
@support.bigaddrspacetest
def test_combinations_overflow(self):
- with self.assertRaises(OverflowError):
+ with self.assertRaises((OverflowError, MemoryError)):
combinations("AA", 2**29)
# Test implementation detail: tuple re-use
@@ -346,7 +346,7 @@
@support.bigaddrspacetest
def test_combinations_with_replacement_overflow(self):
- with self.assertRaises(OverflowError):
+ with self.assertRaises((OverflowError, MemoryError)):
combinations_with_replacement("AA", 2**30)
# Test implementation detail: tuple re-use
@@ -420,10 +420,8 @@
@support.bigaddrspacetest
def test_permutations_overflow(self):
- with self.assertRaises(OverflowError):
+ with self.assertRaises((OverflowError, MemoryError)):
permutations("A", 2**30)
- with self.assertRaises(OverflowError):
- permutations("A", 2, 2**30)
@support.impl_detail("tuple resuse is CPython specific")
def test_permutations_tuple_reuse(self):
@@ -939,8 +937,8 @@
@support.bigaddrspacetest
def test_product_overflow(self):
- with self.assertRaises(OverflowError):
- product(["a"]*(2**16), repeat=2**16)
+ with self.assertRaises((OverflowError, MemoryError)):
+ product(*(['ab']*2**5), repeat=2**25)
@support.impl_detail("tuple reuse is specific to CPython")
def test_product_tuple_reuse(self):
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c
--- a/Modules/itertoolsmodule.c
+++ b/Modules/itertoolsmodule.c
@@ -2003,15 +2003,14 @@
nargs = 0;
} else {
nargs = PyTuple_GET_SIZE(args);
- if (repeat > PY_SSIZE_T_MAX/sizeof(Py_ssize_t) ||
- nargs > PY_SSIZE_T_MAX/(repeat * sizeof(Py_ssize_t))) {
+ if ((size_t)nargs > PY_SSIZE_T_MAX/sizeof(Py_ssize_t)/repeat) {
PyErr_SetString(PyExc_OverflowError, "repeat argument too large");
return NULL;
}
}
npools = nargs * repeat;
- indices = PyMem_Malloc(npools * sizeof(Py_ssize_t));
+ indices = PyMem_New(Py_ssize_t, npools);
if (indices == NULL) {
PyErr_NoMemory();
goto error;
@@ -2335,11 +2334,7 @@
goto error;
}
- if (r > PY_SSIZE_T_MAX/sizeof(Py_ssize_t)) {
- PyErr_SetString(PyExc_OverflowError, "r is too big");
- goto error;
- }
- indices = PyMem_Malloc(r * sizeof(Py_ssize_t));
+ indices = PyMem_New(Py_ssize_t, r);
if (indices == NULL) {
PyErr_NoMemory();
goto error;
@@ -2668,11 +2663,7 @@
goto error;
}
- if (r > PY_SSIZE_T_MAX/sizeof(Py_ssize_t)) {
- PyErr_SetString(PyExc_OverflowError, "r is too big");
- goto error;
- }
- indices = PyMem_Malloc(r * sizeof(Py_ssize_t));
+ indices = PyMem_New(Py_ssize_t, r);
if (indices == NULL) {
PyErr_NoMemory();
goto error;
@@ -3001,13 +2992,8 @@
goto error;
}
- if (n > PY_SSIZE_T_MAX/sizeof(Py_ssize_t) ||
- r > PY_SSIZE_T_MAX/sizeof(Py_ssize_t)) {
- PyErr_SetString(PyExc_OverflowError, "parameters too large");
- goto error;
- }
- indices = PyMem_Malloc(n * sizeof(Py_ssize_t));
- cycles = PyMem_Malloc(r * sizeof(Py_ssize_t));
+ indices = PyMem_New(Py_ssize_t, n);
+ cycles = PyMem_New(Py_ssize_t, r);
if (indices == NULL || cycles == NULL) {
PyErr_NoMemory();
goto error;
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list