]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Use _getbytevalue() in init too.
authorGeorg Brandl <georg@python.org>
Wed, 16 Jul 2008 23:10:05 +0000 (23:10 +0000)
committerGeorg Brandl <georg@python.org>
Wed, 16 Jul 2008 23:10:05 +0000 (23:10 +0000)
Objects/bytearrayobject.c

index b1f696227fe7bae133a0ebd06cc6f3e8ceffb4da..31b58048711c0b87b00edf1baa9f6bedbf2908e9 100644 (file)
@@ -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)++;