[Python-checkins] r80128 - in python/branches/py3k: Lib/test/test_bytes.py Misc/NEWS Objects/bytearrayobject.c Objects/bytesobject.c
benjamin.peterson
python-checkins at python.org
Sat Apr 17 00:51:37 CEST 2010
Author: benjamin.peterson
Date: Sat Apr 17 00:51:37 2010
New Revision: 80128
Log:
Merged revisions 80126 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r80126 | benjamin.peterson | 2010-04-16 17:35:38 -0500 (Fri, 16 Apr 2010) | 1 line
have a clear error when passing something > sys.maxsize to bytearray
........
Modified:
python/branches/py3k/ (props changed)
python/branches/py3k/Lib/test/test_bytes.py
python/branches/py3k/Misc/NEWS
python/branches/py3k/Objects/bytearrayobject.c
python/branches/py3k/Objects/bytesobject.c
Modified: python/branches/py3k/Lib/test/test_bytes.py
==============================================================================
--- python/branches/py3k/Lib/test/test_bytes.py (original)
+++ python/branches/py3k/Lib/test/test_bytes.py Sat Apr 17 00:51:37 2010
@@ -75,6 +75,7 @@
self.assertEqual(self.type2test('0', 'ascii'), b'0')
self.assertEqual(self.type2test(b'0'), b'0')
+ self.assertRaises(OverflowError, self.type2test, sys.maxsize + 1)
def test_constructor_type_errors(self):
self.assertRaises(TypeError, self.type2test, 0.0)
Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS (original)
+++ python/branches/py3k/Misc/NEWS Sat Apr 17 00:51:37 2010
@@ -12,6 +12,9 @@
Core and Builtins
-----------------
+- Issue #8417: Raise an OverflowError when an integer larger than sys.maxsize is
+ passed to bytes or bytearray.
+
- Issue #7301: Add environment variable $PYTHONWARNINGS.
- Issue #8329: Don't return the same lists from select.select when no fds are
Modified: python/branches/py3k/Objects/bytearrayobject.c
==============================================================================
--- python/branches/py3k/Objects/bytearrayobject.c (original)
+++ python/branches/py3k/Objects/bytearrayobject.c Sat Apr 17 00:51:37 2010
@@ -753,14 +753,18 @@
}
/* Is it an int? */
- count = PyNumber_AsSsize_t(arg, PyExc_ValueError);
- if (count == -1 && PyErr_Occurred())
- PyErr_Clear();
- else {
- if (count < 0) {
- PyErr_SetString(PyExc_ValueError, "negative count");
+ count = PyNumber_AsSsize_t(arg, PyExc_OverflowError);
+ if (count == -1 && PyErr_Occurred()) {
+ if (PyErr_ExceptionMatches(PyExc_OverflowError))
return -1;
- }
+ else
+ PyErr_Clear();
+ }
+ else if (count < 0) {
+ PyErr_SetString(PyExc_ValueError, "negative count");
+ return -1;
+ }
+ else {
if (count > 0) {
if (PyByteArray_Resize((PyObject *)self, count))
return -1;
Modified: python/branches/py3k/Objects/bytesobject.c
==============================================================================
--- python/branches/py3k/Objects/bytesobject.c (original)
+++ python/branches/py3k/Objects/bytesobject.c Sat Apr 17 00:51:37 2010
@@ -2545,15 +2545,17 @@
return new;
}
/* Is it an integer? */
- size = PyNumber_AsSsize_t(x, PyExc_ValueError);
+ size = PyNumber_AsSsize_t(x, PyExc_OverflowError);
if (size == -1 && PyErr_Occurred()) {
+ if (PyErr_ExceptionMatches(PyExc_OverflowError))
+ return NULL;
PyErr_Clear();
}
+ else if (size < 0) {
+ PyErr_SetString(PyExc_ValueError, "negative count");
+ return NULL;
+ }
else {
- if (size < 0) {
- PyErr_SetString(PyExc_ValueError, "negative count");
- return NULL;
- }
new = PyBytes_FromStringAndSize(NULL, size);
if (new == NULL) {
return NULL;
More information about the Python-checkins
mailing list