1. Nick Coghlan
  2. cpython_sandbox

Commits

Nick Coghlan  committed b006ce2

Extract helper to special case binary data

  • Participants
  • Parent commits 3ce08b9
  • Branches bytes_migration_experiment

Comments (0)

Files changed (6)

File Include/longobject.h

View file
 PyAPI_FUNC(unsigned long) PyLong_AsUnsignedLongMask(PyObject *);
 #ifndef Py_LIMITED_API
 PyAPI_FUNC(int) _PyLong_AsInt(PyObject *);
+PyAPI_FUNC(PyObject *) _PyBytesLong_FromLong(long);
 #endif
 PyAPI_FUNC(PyObject *) PyLong_GetInfo(void);
 

File Objects/abstract.c

View file
     view->readonly = readonly;
     view->itemsize = 1;
     view->format = NULL;
+    /* TODO in Python 3.5: Define & use 'C' as a temp transition format */
+    /* TODO in Python 3.6: Use 'c' instead of 'B' as the default format */
     if ((flags & PyBUF_FORMAT) == PyBUF_FORMAT)
         view->format = "B";
     view->ndim = 1;

File Objects/bytearrayobject.c

View file
         PyErr_SetString(PyExc_IndexError, "bytearray index out of range");
         return NULL;
     }
-    return PyLong_FromLong((unsigned char)(PyByteArray_AS_STRING(self)[i]));
+    return _PyBytesLong_FromLong((unsigned char)(PyByteArray_AS_STRING(self)[i]));
 }
 
 static PyObject *
             PyErr_SetString(PyExc_IndexError, "bytearray index out of range");
             return NULL;
         }
-        return PyLong_FromLong((unsigned char)(PyByteArray_AS_STRING(self)[i]));
+        return _PyBytesLong_FromLong((unsigned char)(PyByteArray_AS_STRING(self)[i]));
     }
     else if (PySlice_Check(index)) {
         Py_ssize_t start, stop, step, slicelength, cur, i;
     if (PyByteArray_Resize((PyObject *)self, n - 1) < 0)
         return NULL;
 
-    return PyLong_FromLong((unsigned char)value);
+    return _PyBytesLong_FromLong((unsigned char)value);
 }
 
 PyDoc_STRVAR(remove__doc__,
     assert(PyByteArray_Check(seq));
 
     if (it->it_index < PyByteArray_GET_SIZE(seq)) {
-        item = PyLong_FromLong(
+        item = _PyBytesLong_FromLong(
             (unsigned char)PyByteArray_AS_STRING(seq)[it->it_index]);
         if (item != NULL)
             ++it->it_index;

File Objects/bytesobject.c

View file
         PyErr_SetString(PyExc_IndexError, "index out of range");
         return NULL;
     }
-    return PyLong_FromLong((unsigned char)a->ob_sval[i]);
+    return _PyBytesLong_FromLong((unsigned char)a->ob_sval[i]);
 }
 
 Py_LOCAL(int)
                             "index out of range");
             return NULL;
         }
-        return PyLong_FromLong((unsigned char)self->ob_sval[i]);
+        return _PyBytesLong_FromLong((unsigned char)self->ob_sval[i]);
     }
     else if (PySlice_Check(item)) {
         Py_ssize_t start, stop, step, slicelength, cur, i;
     assert(PyBytes_Check(seq));
 
     if (it->it_index < PyBytes_GET_SIZE(seq)) {
-        item = PyLong_FromLong(
+        item = _PyBytesLong_FromLong(
             (unsigned char)seq->ob_sval[it->it_index]);
         if (item != NULL)
             ++it->it_index;

File Objects/longobject.c

View file
     }
 #endif
 }
+
+
+PyObject *
+_PyBytesLong_FromLong(long ival)
+{
+    /*TODO: Return a long subclass instead of a normal long object */
+    return PyLong_FromLong(ival);
+}

File Objects/memoryobject.c

View file
     void *p;
 
     switch (fmt[0]) {
+    /* TODO: Temp 'C' format char for default 'B' -> 'c' migration */
 
     /* signed integers and fast path for 'B' */
     case 'B': uc = *((unsigned char *)ptr); goto convert_uc;