diff Objects/bytesobject.c @ 46130:6192d5b12b6a legacy-trunk

Fix bytes so it works on 64-bit platforms. (Also remove some #if 0 code that is already handled in _getbytevalue.)
author Neal Norwitz <nnorwitz@gmail.com>
date Thu, 27 Mar 2008 03:49:54 +0000
parents 5341b30b1812
children d740c71f02ff
line wrap: on
line diff
--- a/Objects/bytesobject.c	Thu Mar 27 01:38:47 2008 +0000
+++ b/Objects/bytesobject.c	Thu Mar 27 03:49:54 2008 +0000
@@ -549,7 +549,7 @@
 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 @@
 
     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 @@
         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;