summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2008-07-16 23:10:05 (GMT)
committerGeorg Brandl <georg@python.org>2008-07-16 23:10:05 (GMT)
commit3e75846cf60218db698c9046ac3ae2632403f141 (patch)
tree37946901831d5c8cf5c6c0f38d9f87679a99179e
parent3e483f643de3d38125a7ca04bb424323cf736762 (diff)
downloadcpython-3e75846cf60218db698c9046ac3ae2632403f141.zip
cpython-3e75846cf60218db698c9046ac3ae2632403f141.tar.gz
cpython-3e75846cf60218db698c9046ac3ae2632403f141.tar.bz2
Use _getbytevalue() in init too.
-rw-r--r--Objects/bytearrayobject.c13
1 files changed, 3 insertions, 10 deletions
diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c
index b1f6962..31b5804 100644
--- a/Objects/bytearrayobject.c
+++ b/Objects/bytearrayobject.c
@@ -860,7 +860,7 @@ bytes_init(PyByteArrayObject *self, PyObject *args, PyObject *kwds)
/* Run the iterator to exhaustion */
for (;;) {
PyObject *item;
- Py_ssize_t value;
+ int rc, value;
/* Get the next item */
item = iternext(it);
@@ -874,18 +874,11 @@ bytes_init(PyByteArrayObject *self, PyObject *args, PyObject *kwds)
}
/* Interpret it as an int (__index__) */
- value = PyNumber_AsSsize_t(item, PyExc_ValueError);
+ rc = _getbytevalue(item, &value);
Py_DECREF(item);
- if (value == -1 && PyErr_Occurred())
+ if (!rc)
goto error;
- /* Range check */
- if (value < 0 || value >= 256) {
- PyErr_SetString(PyExc_ValueError,
- "bytes must be in range(0, 256)");
- goto error;
- }
-
/* Append the byte */
if (Py_SIZE(self) < self->ob_alloc)
Py_SIZE(self)++;