diff options
author | Neal Norwitz <nnorwitz@gmail.com> | 2008-03-27 03:49:54 (GMT) |
---|---|---|
committer | Neal Norwitz <nnorwitz@gmail.com> | 2008-03-27 03:49:54 (GMT) |
commit | 0bcd613e9fbe5ddb042680b49225f99d1fd07338 (patch) | |
tree | 44279cd53def88697422bea6157d2cc96a95352e | |
parent | 9a960c601518c22434777d4fe5685efd0872c489 (diff) | |
download | cpython-0bcd613e9fbe5ddb042680b49225f99d1fd07338.zip cpython-0bcd613e9fbe5ddb042680b49225f99d1fd07338.tar.gz cpython-0bcd613e9fbe5ddb042680b49225f99d1fd07338.tar.bz2 |
Fix bytes so it works on 64-bit platforms.
(Also remove some #if 0 code that is already handled in _getbytevalue.)
-rw-r--r-- | Objects/bytesobject.c | 19 |
1 files changed, 5 insertions, 14 deletions
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c index 86d58e1..90990a7 100644 --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -549,7 +549,7 @@ bytes_setslice(PyBytesObject *self, Py_ssize_t lo, Py_ssize_t hi, static int bytes_setitem(PyBytesObject *self, Py_ssize_t i, PyObject *value) { - Py_ssize_t ival; + int ival; if (i < 0) i += Py_SIZE(self); @@ -564,16 +564,6 @@ bytes_setitem(PyBytesObject *self, Py_ssize_t i, PyObject *value) if (!_getbytevalue(value, &ival)) return -1; -#if 0 - ival = PyNumber_AsSsize_t(value, PyExc_ValueError); - if (ival == -1 && PyErr_Occurred()) - return -1; - - if (ival < 0 || ival >= 256) { - PyErr_SetString(PyExc_ValueError, "byte must be in range(0, 256)"); - return -1; - } -#endif self->ob_bytes[i] = ival; return 0; @@ -609,12 +599,13 @@ bytes_ass_subscript(PyBytesObject *self, PyObject *item, PyObject *values) else { Py_ssize_t ival = PyNumber_AsSsize_t(values, PyExc_ValueError); if (ival == -1 && PyErr_Occurred()) { + int int_value; /* Also accept str of size 1 in 2.x */ PyErr_Clear(); - if (!_getbytevalue(values, &ival)) + if (!_getbytevalue(values, &int_value)) return -1; - } - if (ival < 0 || ival >= 256) { + ival = (int) int_value; + } else if (ival < 0 || ival >= 256) { PyErr_SetString(PyExc_ValueError, "byte must be in range(0, 256)"); return -1; |