[Python-checkins] r63672 - in python/trunk: Include/Python.h Include/bytearrayobject.h Include/bytesobject.h Include/pythonrun.h Include/stringobject.h Objects/bytesobject.c Objects/object.c Objects/stringobject.c Objects/unicodeobject.c Python/bltinmodule.c Python/pythonrun.c

christian.heimes python-checkins at python.org
Mon May 26 14:29:15 CEST 2008


Author: christian.heimes
Date: Mon May 26 14:29:14 2008
New Revision: 63672

Log:
First step of the C API rename:
renamed Include/bytesobject.h to Include/bytearrayobject.h
renamed Include/stringobject.h to Include/bytesobject.h
added Include/stringobject.h with aliases

Added:
   python/trunk/Include/bytearrayobject.h
      - copied, changed from r63659, /python/trunk/Include/bytesobject.h
   python/trunk/Include/bytesobject.h
      - copied unchanged from r63659, /python/trunk/Include/stringobject.h
   python/trunk/Include/stringobject.h   (contents, props changed)
Modified:
   python/trunk/Include/Python.h
   python/trunk/Include/pythonrun.h
   python/trunk/Objects/bytesobject.c
   python/trunk/Objects/object.c
   python/trunk/Objects/stringobject.c
   python/trunk/Objects/unicodeobject.c
   python/trunk/Python/bltinmodule.c
   python/trunk/Python/pythonrun.c

Modified: python/trunk/Include/Python.h
==============================================================================
--- python/trunk/Include/Python.h	(original)
+++ python/trunk/Include/Python.h	Mon May 26 14:29:14 2008
@@ -94,6 +94,7 @@
 /* #include "memoryobject.h" */
 #include "bufferobject.h"
 #include "bytesobject.h"
+#include "bytearrayobject.h"
 #include "tupleobject.h"
 #include "listobject.h"
 #include "dictobject.h"

Copied: python/trunk/Include/bytearrayobject.h (from r63659, /python/trunk/Include/bytesobject.h)
==============================================================================
--- /python/trunk/Include/bytesobject.h	(original)
+++ python/trunk/Include/bytearrayobject.h	Mon May 26 14:29:14 2008
@@ -8,7 +8,7 @@
 
 #include <stdarg.h>
 
-/* Type PyBytesObject represents a mutable array of bytes.
+/* Type PyByteArrayObject represents a mutable array of bytes.
  * The Python API is that of a sequence;
  * the bytes are mapped to ints in [0, 256).
  * Bytes are not characters; they may be used to encode characters.
@@ -25,27 +25,27 @@
     int ob_exports; /* how many buffer exports */
     Py_ssize_t ob_alloc; /* How many bytes allocated */
     char *ob_bytes;
-} PyBytesObject;
+} PyByteArrayObject;
 
 /* Type object */
-PyAPI_DATA(PyTypeObject) PyBytes_Type;
-PyAPI_DATA(PyTypeObject) PyBytesIter_Type;
+PyAPI_DATA(PyTypeObject) PyByteArray_Type;
+PyAPI_DATA(PyTypeObject) PyByteArrayIter_Type;
 
 /* Type check macros */
-#define PyBytes_Check(self) PyObject_TypeCheck(self, &PyBytes_Type)
-#define PyBytes_CheckExact(self) (Py_TYPE(self) == &PyBytes_Type)
+#define PyByteArray_Check(self) PyObject_TypeCheck(self, &PyByteArray_Type)
+#define PyByteArray_CheckExact(self) (Py_TYPE(self) == &PyByteArray_Type)
 
 /* Direct API functions */
-PyAPI_FUNC(PyObject *) PyBytes_FromObject(PyObject *);
-PyAPI_FUNC(PyObject *) PyBytes_Concat(PyObject *, PyObject *);
-PyAPI_FUNC(PyObject *) PyBytes_FromStringAndSize(const char *, Py_ssize_t);
-PyAPI_FUNC(Py_ssize_t) PyBytes_Size(PyObject *);
-PyAPI_FUNC(char *) PyBytes_AsString(PyObject *);
-PyAPI_FUNC(int) PyBytes_Resize(PyObject *, Py_ssize_t);
+PyAPI_FUNC(PyObject *) PyByteArray_FromObject(PyObject *);
+PyAPI_FUNC(PyObject *) PyByteArray_Concat(PyObject *, PyObject *);
+PyAPI_FUNC(PyObject *) PyByteArray_FromStringAndSize(const char *, Py_ssize_t);
+PyAPI_FUNC(Py_ssize_t) PyByteArray_Size(PyObject *);
+PyAPI_FUNC(char *) PyByteArray_AsString(PyObject *);
+PyAPI_FUNC(int) PyByteArray_Resize(PyObject *, Py_ssize_t);
 
 /* Macros, trading safety for speed */
-#define PyBytes_AS_STRING(self) (assert(PyBytes_Check(self)),((PyBytesObject *)(self))->ob_bytes)
-#define PyBytes_GET_SIZE(self)  (assert(PyBytes_Check(self)),Py_SIZE(self))
+#define PyByteArray_AS_STRING(self) (assert(PyByteArray_Check(self)),((PyByteArrayObject *)(self))->ob_bytes)
+#define PyByteArray_GET_SIZE(self)  (assert(PyByteArray_Check(self)),Py_SIZE(self))
 
 #ifdef __cplusplus
 }

Modified: python/trunk/Include/pythonrun.h
==============================================================================
--- python/trunk/Include/pythonrun.h	(original)
+++ python/trunk/Include/pythonrun.h	Mon May 26 14:29:14 2008
@@ -124,7 +124,7 @@
 PyAPI_FUNC(int) _PyFrame_Init(void);
 PyAPI_FUNC(int) _PyInt_Init(void);
 PyAPI_FUNC(void) _PyFloat_Init(void);
-PyAPI_FUNC(int) PyBytes_Init(void);
+PyAPI_FUNC(int) PyByteArray_Init(void);
 
 /* Various internal finalizers */
 PyAPI_FUNC(void) _PyExc_Fini(void);
@@ -140,7 +140,7 @@
 PyAPI_FUNC(void) PyInt_Fini(void);
 PyAPI_FUNC(void) PyFloat_Fini(void);
 PyAPI_FUNC(void) PyOS_FiniInterrupts(void);
-PyAPI_FUNC(void) PyBytes_Fini(void);
+PyAPI_FUNC(void) PyByteArray_Fini(void);
 
 /* Stuff with no proper home (yet) */
 PyAPI_FUNC(char *) PyOS_Readline(FILE *, FILE *, char *);

Added: python/trunk/Include/stringobject.h
==============================================================================
--- (empty file)
+++ python/trunk/Include/stringobject.h	Mon May 26 14:29:14 2008
@@ -0,0 +1,36 @@
+#define PyBytesObject PyStringObject
+#define PyBytes_Type PyString_Type
+
+#define PyBytes_Check PyString_Check
+#define PyBytes_CheckExact PyString_CheckExact 
+#define PyBytes_CHECK_INTERNED PyString_CHECK_INTERNED
+#define PyBytes_AS_STRING PyString_AS_STRING
+#define PyBytes_GET_SIZE PyString_GET_SIZE
+#define Py_TPFLAGS_BYTES_SUBCLASS Py_TPFLAGS_STRING_SUBCLASS
+
+#define PyBytes_FromStringAndSize PyString_FromStringAndSize
+#define PyBytes_FromString PyString_FromString
+#define PyBytes_FromFormatV PyString_FromFormatV
+#define PyBytes_FromFormat PyString_FromFormat
+#define PyBytes_Size PyString_Size
+#define PyBytes_AsString PyString_AsString
+#define PyBytes_Repr PyString_Repr
+#define PyBytes_Concat PyString_Concat
+#define PyBytes_ConcatAndDel PyString_ConcatAndDel
+#define _PyBytes_Resize _PyString_Resize
+#define _PyBytes_Eq _PyString_Eq
+#define PyBytes_Format PyString_Format
+#define _PyBytes_FormatLong _PyString_FormatLong
+#define PyBytes_DecodeEscape PyString_DecodeEscape
+#define PyBytes_InternInPlace PyString_InternInPlace
+#define PyBytes_InternImmortal PyString_InternImmortal
+#define PyBytes_InternFromString PyString_InternFromString
+#define _PyBytes_Join _PyString_Join
+#define PyBytes_Decode PyString_Decode
+#define PyBytes_Encode PyString_Encode
+#define PyBytes_AsEncodedObject PyString_AsEncodedObject
+#define PyBytes_AsEncodedString PyString_AsEncodedString
+#define PyBytes_AsDecodedObject PyString_AsDecodedObject
+#define PyBytes_AsDecodedString PyString_AsDecodedString
+#define PyBytes_AsStringAndSize PyString_AsStringAndSize
+#define _PyBytes_InsertThousandsGrouping _PyString_InsertThousandsGrouping

Modified: python/trunk/Objects/bytesobject.c
==============================================================================
--- python/trunk/Objects/bytesobject.c	(original)
+++ python/trunk/Objects/bytesobject.c	Mon May 26 14:29:14 2008
@@ -5,18 +5,18 @@
 #include "structmember.h"
 #include "bytes_methods.h"
 
-static PyBytesObject *nullbytes = NULL;
+static PyByteArrayObject *nullbytes = NULL;
 
 void
-PyBytes_Fini(void)
+PyByteArray_Fini(void)
 {
     Py_CLEAR(nullbytes);
 }
 
 int
-PyBytes_Init(void)
+PyByteArray_Init(void)
 {
-    nullbytes = PyObject_New(PyBytesObject, &PyBytes_Type);
+    nullbytes = PyObject_New(PyByteArrayObject, &PyByteArray_Type);
     if (nullbytes == NULL)
         return 0;
     nullbytes->ob_bytes = NULL;
@@ -58,7 +58,7 @@
 }
 
 static Py_ssize_t
-bytes_buffer_getreadbuf(PyBytesObject *self, Py_ssize_t index, const void **ptr)
+bytes_buffer_getreadbuf(PyByteArrayObject *self, Py_ssize_t index, const void **ptr)
 {
     if ( index != 0 ) {
         PyErr_SetString(PyExc_SystemError,
@@ -70,7 +70,7 @@
 }
 
 static Py_ssize_t
-bytes_buffer_getwritebuf(PyBytesObject *self, Py_ssize_t index, const void **ptr)
+bytes_buffer_getwritebuf(PyByteArrayObject *self, Py_ssize_t index, const void **ptr)
 {
     if ( index != 0 ) {
         PyErr_SetString(PyExc_SystemError,
@@ -82,7 +82,7 @@
 }
 
 static Py_ssize_t
-bytes_buffer_getsegcount(PyBytesObject *self, Py_ssize_t *lenp)
+bytes_buffer_getsegcount(PyByteArrayObject *self, Py_ssize_t *lenp)
 {
     if ( lenp )
         *lenp = Py_SIZE(self);
@@ -90,7 +90,7 @@
 }
 
 static Py_ssize_t
-bytes_buffer_getcharbuf(PyBytesObject *self, Py_ssize_t index, const char **ptr)
+bytes_buffer_getcharbuf(PyByteArrayObject *self, Py_ssize_t index, const char **ptr)
 {
     if ( index != 0 ) {
         PyErr_SetString(PyExc_SystemError,
@@ -102,7 +102,7 @@
 }
 
 static int
-bytes_getbuffer(PyBytesObject *obj, Py_buffer *view, int flags)
+bytes_getbuffer(PyByteArrayObject *obj, Py_buffer *view, int flags)
 {
         int ret;
         void *ptr;
@@ -122,7 +122,7 @@
 }
 
 static void
-bytes_releasebuffer(PyBytesObject *obj, Py_buffer *view)
+bytes_releasebuffer(PyByteArrayObject *obj, Py_buffer *view)
 {
         obj->ob_exports--;
 }
@@ -148,25 +148,25 @@
 /* Direct API functions */
 
 PyObject *
-PyBytes_FromObject(PyObject *input)
+PyByteArray_FromObject(PyObject *input)
 {
-    return PyObject_CallFunctionObjArgs((PyObject *)&PyBytes_Type,
+    return PyObject_CallFunctionObjArgs((PyObject *)&PyByteArray_Type,
                                         input, NULL);
 }
 
 PyObject *
-PyBytes_FromStringAndSize(const char *bytes, Py_ssize_t size)
+PyByteArray_FromStringAndSize(const char *bytes, Py_ssize_t size)
 {
-    PyBytesObject *new;
+    PyByteArrayObject *new;
     Py_ssize_t alloc;
 
     if (size < 0) {
         PyErr_SetString(PyExc_SystemError,
-            "Negative size passed to PyBytes_FromStringAndSize");
+            "Negative size passed to PyByteArray_FromStringAndSize");
         return NULL;
     }
 
-    new = PyObject_New(PyBytesObject, &PyBytes_Type);
+    new = PyObject_New(PyByteArrayObject, &PyByteArray_Type);
     if (new == NULL)
         return NULL;
 
@@ -193,31 +193,31 @@
 }
 
 Py_ssize_t
-PyBytes_Size(PyObject *self)
+PyByteArray_Size(PyObject *self)
 {
     assert(self != NULL);
-    assert(PyBytes_Check(self));
+    assert(PyByteArray_Check(self));
 
-    return PyBytes_GET_SIZE(self);
+    return PyByteArray_GET_SIZE(self);
 }
 
 char  *
-PyBytes_AsString(PyObject *self)
+PyByteArray_AsString(PyObject *self)
 {
     assert(self != NULL);
-    assert(PyBytes_Check(self));
+    assert(PyByteArray_Check(self));
 
-    return PyBytes_AS_STRING(self);
+    return PyByteArray_AS_STRING(self);
 }
 
 int
-PyBytes_Resize(PyObject *self, Py_ssize_t size)
+PyByteArray_Resize(PyObject *self, Py_ssize_t size)
 {
     void *sval;
-    Py_ssize_t alloc = ((PyBytesObject *)self)->ob_alloc;
+    Py_ssize_t alloc = ((PyByteArrayObject *)self)->ob_alloc;
 
     assert(self != NULL);
-    assert(PyBytes_Check(self));
+    assert(PyByteArray_Check(self));
     assert(size >= 0);
 
     if (size < alloc / 2) {
@@ -227,7 +227,7 @@
     else if (size < alloc) {
         /* Within allocated size; quick exit */
         Py_SIZE(self) = size;
-        ((PyBytesObject *)self)->ob_bytes[size] = '\0'; /* Trailing null */
+        ((PyByteArrayObject *)self)->ob_bytes[size] = '\0'; /* Trailing null */
         return 0;
     }
     else if (size <= alloc * 1.125) {
@@ -239,36 +239,36 @@
         alloc = size + 1;
     }
 
-    if (((PyBytesObject *)self)->ob_exports > 0) {
+    if (((PyByteArrayObject *)self)->ob_exports > 0) {
             /*
-            fprintf(stderr, "%d: %s", ((PyBytesObject *)self)->ob_exports,
-                    ((PyBytesObject *)self)->ob_bytes);
+            fprintf(stderr, "%d: %s", ((PyByteArrayObject *)self)->ob_exports,
+                    ((PyByteArrayObject *)self)->ob_bytes);
             */
             PyErr_SetString(PyExc_BufferError,
                     "Existing exports of data: object cannot be re-sized");
             return -1;
     }
 
-    sval = PyMem_Realloc(((PyBytesObject *)self)->ob_bytes, alloc);
+    sval = PyMem_Realloc(((PyByteArrayObject *)self)->ob_bytes, alloc);
     if (sval == NULL) {
         PyErr_NoMemory();
         return -1;
     }
 
-    ((PyBytesObject *)self)->ob_bytes = sval;
+    ((PyByteArrayObject *)self)->ob_bytes = sval;
     Py_SIZE(self) = size;
-    ((PyBytesObject *)self)->ob_alloc = alloc;
-    ((PyBytesObject *)self)->ob_bytes[size] = '\0'; /* Trailing null byte */
+    ((PyByteArrayObject *)self)->ob_alloc = alloc;
+    ((PyByteArrayObject *)self)->ob_bytes[size] = '\0'; /* Trailing null byte */
 
     return 0;
 }
 
 PyObject *
-PyBytes_Concat(PyObject *a, PyObject *b)
+PyByteArray_Concat(PyObject *a, PyObject *b)
 {
     Py_ssize_t size;
     Py_buffer va, vb;
-    PyBytesObject *result = NULL;
+    PyByteArrayObject *result = NULL;
 
     va.len = -1;
     vb.len = -1;
@@ -285,7 +285,7 @@
             goto done;
     }
 
-    result = (PyBytesObject *) PyBytes_FromStringAndSize(NULL, size);
+    result = (PyByteArrayObject *) PyByteArray_FromStringAndSize(NULL, size);
     if (result != NULL) {
         memcpy(result->ob_bytes, va.buf, va.len);
         memcpy(result->ob_bytes + va.len, vb.buf, vb.len);
@@ -302,13 +302,13 @@
 /* Functions stuffed into the type object */
 
 static Py_ssize_t
-bytes_length(PyBytesObject *self)
+bytes_length(PyByteArrayObject *self)
 {
     return Py_SIZE(self);
 }
 
 static PyObject *
-bytes_iconcat(PyBytesObject *self, PyObject *other)
+bytes_iconcat(PyByteArrayObject *self, PyObject *other)
 {
     Py_ssize_t mysize;
     Py_ssize_t size;
@@ -330,7 +330,7 @@
         Py_SIZE(self) = size;
         self->ob_bytes[Py_SIZE(self)] = '\0'; /* Trailing null byte */
     }
-    else if (PyBytes_Resize((PyObject *)self, size) < 0) {
+    else if (PyByteArray_Resize((PyObject *)self, size) < 0) {
         PyObject_ReleaseBuffer(other, &vo);
         return NULL;
     }
@@ -341,9 +341,9 @@
 }
 
 static PyObject *
-bytes_repeat(PyBytesObject *self, Py_ssize_t count)
+bytes_repeat(PyByteArrayObject *self, Py_ssize_t count)
 {
-    PyBytesObject *result;
+    PyByteArrayObject *result;
     Py_ssize_t mysize;
     Py_ssize_t size;
 
@@ -353,7 +353,7 @@
     size = mysize * count;
     if (count != 0 && size / count != mysize)
         return PyErr_NoMemory();
-    result = (PyBytesObject *)PyBytes_FromStringAndSize(NULL, size);
+    result = (PyByteArrayObject *)PyByteArray_FromStringAndSize(NULL, size);
     if (result != NULL && size != 0) {
         if (mysize == 1)
             memset(result->ob_bytes, self->ob_bytes[0], size);
@@ -367,7 +367,7 @@
 }
 
 static PyObject *
-bytes_irepeat(PyBytesObject *self, Py_ssize_t count)
+bytes_irepeat(PyByteArrayObject *self, Py_ssize_t count)
 {
     Py_ssize_t mysize;
     Py_ssize_t size;
@@ -382,7 +382,7 @@
         Py_SIZE(self) = size;
         self->ob_bytes[Py_SIZE(self)] = '\0'; /* Trailing null byte */
     }
-    else if (PyBytes_Resize((PyObject *)self, size) < 0)
+    else if (PyByteArray_Resize((PyObject *)self, size) < 0)
         return NULL;
 
     if (mysize == 1)
@@ -398,7 +398,7 @@
 }
 
 static PyObject *
-bytes_getitem(PyBytesObject *self, Py_ssize_t i)
+bytes_getitem(PyByteArrayObject *self, Py_ssize_t i)
 {
     if (i < 0)
         i += Py_SIZE(self);
@@ -410,7 +410,7 @@
 }
 
 static PyObject *
-bytes_subscript(PyBytesObject *self, PyObject *item)
+bytes_subscript(PyByteArrayObject *self, PyObject *item)
 {
     if (PyIndex_Check(item)) {
         Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError);
@@ -419,7 +419,7 @@
             return NULL;
 
         if (i < 0)
-            i += PyBytes_GET_SIZE(self);
+            i += PyByteArray_GET_SIZE(self);
 
         if (i < 0 || i >= Py_SIZE(self)) {
             PyErr_SetString(PyExc_IndexError, "bytearray index out of range");
@@ -430,19 +430,19 @@
     else if (PySlice_Check(item)) {
         Py_ssize_t start, stop, step, slicelength, cur, i;
         if (PySlice_GetIndicesEx((PySliceObject *)item,
-                                 PyBytes_GET_SIZE(self),
+                                 PyByteArray_GET_SIZE(self),
                                  &start, &stop, &step, &slicelength) < 0) {
             return NULL;
         }
 
         if (slicelength <= 0)
-            return PyBytes_FromStringAndSize("", 0);
+            return PyByteArray_FromStringAndSize("", 0);
         else if (step == 1) {
-            return PyBytes_FromStringAndSize(self->ob_bytes + start,
+            return PyByteArray_FromStringAndSize(self->ob_bytes + start,
                                              slicelength);
         }
         else {
-            char *source_buf = PyBytes_AS_STRING(self);
+            char *source_buf = PyByteArray_AS_STRING(self);
             char *result_buf = (char *)PyMem_Malloc(slicelength);
             PyObject *result;
 
@@ -453,7 +453,7 @@
                  cur += step, i++) {
                      result_buf[i] = source_buf[cur];
             }
-            result = PyBytes_FromStringAndSize(result_buf, slicelength);
+            result = PyByteArray_FromStringAndSize(result_buf, slicelength);
             PyMem_Free(result_buf);
             return result;
         }
@@ -465,7 +465,7 @@
 }
 
 static int
-bytes_setslice(PyBytesObject *self, Py_ssize_t lo, Py_ssize_t hi,
+bytes_setslice(PyByteArrayObject *self, Py_ssize_t lo, Py_ssize_t hi,
                PyObject *values)
 {
     Py_ssize_t avail, needed;
@@ -477,7 +477,7 @@
     if (values == (PyObject *)self) {
         /* Make a copy and call this function recursively */
         int err;
-        values = PyBytes_FromObject(values);
+        values = PyByteArray_FromObject(values);
         if (values == NULL)
             return -1;
         err = bytes_setslice(self, lo, hi, values);
@@ -523,7 +523,7 @@
                     Py_SIZE(self) - hi);
         }
         /* XXX(nnorwitz): need to verify this can't overflow! */
-        if (PyBytes_Resize((PyObject *)self,
+        if (PyByteArray_Resize((PyObject *)self,
                            Py_SIZE(self) + needed - avail) < 0) {
                 res = -1;
                 goto finish;
@@ -551,7 +551,7 @@
 }
 
 static int
-bytes_setitem(PyBytesObject *self, Py_ssize_t i, PyObject *value)
+bytes_setitem(PyByteArrayObject *self, Py_ssize_t i, PyObject *value)
 {
     int ival;
 
@@ -574,7 +574,7 @@
 }
 
 static int
-bytes_ass_subscript(PyBytesObject *self, PyObject *item, PyObject *values)
+bytes_ass_subscript(PyByteArrayObject *self, PyObject *item, PyObject *values)
 {
     Py_ssize_t start, stop, step, slicelen, needed;
     char *bytes;
@@ -586,7 +586,7 @@
             return -1;
 
         if (i < 0)
-            i += PyBytes_GET_SIZE(self);
+            i += PyByteArray_GET_SIZE(self);
 
         if (i < 0 || i >= Py_SIZE(self)) {
             PyErr_SetString(PyExc_IndexError, "bytearray index out of range");
@@ -620,7 +620,7 @@
     }
     else if (PySlice_Check(item)) {
         if (PySlice_GetIndicesEx((PySliceObject *)item,
-                                 PyBytes_GET_SIZE(self),
+                                 PyByteArray_GET_SIZE(self),
                                  &start, &stop, &step, &slicelen) < 0) {
             return -1;
         }
@@ -634,10 +634,10 @@
         bytes = NULL;
         needed = 0;
     }
-    else if (values == (PyObject *)self || !PyBytes_Check(values)) {
+    else if (values == (PyObject *)self || !PyByteArray_Check(values)) {
         /* Make a copy an call this function recursively */
         int err;
-        values = PyBytes_FromObject(values);
+        values = PyByteArray_FromObject(values);
         if (values == NULL)
             return -1;
         err = bytes_ass_subscript(self, item, values);
@@ -645,8 +645,8 @@
         return err;
     }
     else {
-        assert(PyBytes_Check(values));
-        bytes = ((PyBytesObject *)values)->ob_bytes;
+        assert(PyByteArray_Check(values));
+        bytes = ((PyByteArrayObject *)values)->ob_bytes;
         needed = Py_SIZE(values);
     }
     /* Make sure b[5:2] = ... inserts before 5, not before 2. */
@@ -665,7 +665,7 @@
                 memmove(self->ob_bytes + start + needed, self->ob_bytes + stop,
                         Py_SIZE(self) - stop);
             }
-            if (PyBytes_Resize((PyObject *)self,
+            if (PyByteArray_Resize((PyObject *)self,
                                Py_SIZE(self) + needed - slicelen) < 0)
                 return -1;
             if (slicelen < needed) {
@@ -699,21 +699,21 @@
                  i < slicelen; cur += step, i++) {
                 Py_ssize_t lim = step - 1;
 
-                if (cur + step >= PyBytes_GET_SIZE(self))
-                    lim = PyBytes_GET_SIZE(self) - cur - 1;
+                if (cur + step >= PyByteArray_GET_SIZE(self))
+                    lim = PyByteArray_GET_SIZE(self) - cur - 1;
 
                 memmove(self->ob_bytes + cur - i,
                         self->ob_bytes + cur + 1, lim);
             }
             /* Move the tail of the bytes, in one chunk */
             cur = start + slicelen*step;
-            if (cur < PyBytes_GET_SIZE(self)) {
+            if (cur < PyByteArray_GET_SIZE(self)) {
                 memmove(self->ob_bytes + cur - slicelen,
                         self->ob_bytes + cur,
-                        PyBytes_GET_SIZE(self) - cur);
+                        PyByteArray_GET_SIZE(self) - cur);
             }
-            if (PyBytes_Resize((PyObject *)self,
-                               PyBytes_GET_SIZE(self) - slicelen) < 0)
+            if (PyByteArray_Resize((PyObject *)self,
+                               PyByteArray_GET_SIZE(self) - slicelen) < 0)
                 return -1;
 
             return 0;
@@ -737,7 +737,7 @@
 }
 
 static int
-bytes_init(PyBytesObject *self, PyObject *args, PyObject *kwds)
+bytes_init(PyByteArrayObject *self, PyObject *args, PyObject *kwds)
 {
     static char *kwlist[] = {"source", "encoding", "errors", 0};
     PyObject *arg = NULL;
@@ -749,7 +749,7 @@
 
     if (Py_SIZE(self) != 0) {
         /* Empty previous contents (yes, do this first of all!) */
-        if (PyBytes_Resize((PyObject *)self, 0) < 0)
+        if (PyByteArray_Resize((PyObject *)self, 0) < 0)
             return -1;
     }
 
@@ -825,7 +825,7 @@
             return -1;
         }
         if (count > 0) {
-            if (PyBytes_Resize((PyObject *)self, count))
+            if (PyByteArray_Resize((PyObject *)self, count))
                 return -1;
             memset(self->ob_bytes, 0, count);
         }
@@ -839,7 +839,7 @@
         if (PyObject_GetBuffer(arg, &view, PyBUF_FULL_RO) < 0)
             return -1;
         size = view.len;
-        if (PyBytes_Resize((PyObject *)self, size) < 0) goto fail;
+        if (PyByteArray_Resize((PyObject *)self, size) < 0) goto fail;
         if (PyBuffer_ToContiguous(self->ob_bytes, &view, size, 'C') < 0)
                 goto fail;
         PyObject_ReleaseBuffer(arg, &view);
@@ -889,7 +889,7 @@
         /* Append the byte */
         if (Py_SIZE(self) < self->ob_alloc)
             Py_SIZE(self)++;
-        else if (PyBytes_Resize((PyObject *)self, Py_SIZE(self)+1) < 0)
+        else if (PyByteArray_Resize((PyObject *)self, Py_SIZE(self)+1) < 0)
             goto error;
         self->ob_bytes[Py_SIZE(self)-1] = value;
     }
@@ -907,7 +907,7 @@
 /* Mostly copied from string_repr, but without the
    "smart quote" functionality. */
 static PyObject *
-bytes_repr(PyBytesObject *self)
+bytes_repr(PyByteArrayObject *self)
 {
     static const char *hexdigits = "0123456789abcdef";
     const char *quote_prefix = "bytearray(b";
@@ -935,7 +935,7 @@
         quote = '\'';
         {
             char *test, *start;
-            start = PyBytes_AS_STRING(self);
+            start = PyByteArray_AS_STRING(self);
             for (test = start; test < start+length; ++test) {
                 if (*test == '"') {
                     quote = '\''; /* back to single */
@@ -1000,9 +1000,9 @@
                  "str() on a bytearray instance", 1))
             return NULL;
     }
-    return bytes_repr((PyBytesObject*)op);
+    return bytes_repr((PyByteArrayObject*)op);
 #endif
-    return PyString_FromStringAndSize(((PyBytesObject*)op)->ob_bytes, Py_SIZE(op));
+    return PyString_FromStringAndSize(((PyByteArrayObject*)op)->ob_bytes, Py_SIZE(op));
 }
 
 static PyObject *
@@ -1081,7 +1081,7 @@
 }
 
 static void
-bytes_dealloc(PyBytesObject *self)
+bytes_dealloc(PyByteArrayObject *self)
 {
     if (self->ob_bytes != 0) {
         PyMem_Free(self->ob_bytes);
@@ -1095,11 +1095,11 @@
 
 #define STRINGLIB_CHAR char
 #define STRINGLIB_CMP memcmp
-#define STRINGLIB_LEN PyBytes_GET_SIZE
-#define STRINGLIB_STR PyBytes_AS_STRING
-#define STRINGLIB_NEW PyBytes_FromStringAndSize
+#define STRINGLIB_LEN PyByteArray_GET_SIZE
+#define STRINGLIB_STR PyByteArray_AS_STRING
+#define STRINGLIB_NEW PyByteArray_FromStringAndSize
 #define STRINGLIB_EMPTY nullbytes
-#define STRINGLIB_CHECK_EXACT PyBytes_CheckExact
+#define STRINGLIB_CHECK_EXACT PyByteArray_CheckExact
 #define STRINGLIB_MUTABLE 1
 
 #include "stringlib/fastsearch.h"
@@ -1130,7 +1130,7 @@
 
 
 Py_LOCAL_INLINE(Py_ssize_t)
-bytes_find_internal(PyBytesObject *self, PyObject *args, int dir)
+bytes_find_internal(PyByteArrayObject *self, PyObject *args, int dir)
 {
     PyObject *subobj;
     Py_buffer subbuf;
@@ -1144,11 +1144,11 @@
         return -2;
     if (dir > 0)
         res = stringlib_find_slice(
-            PyBytes_AS_STRING(self), PyBytes_GET_SIZE(self),
+            PyByteArray_AS_STRING(self), PyByteArray_GET_SIZE(self),
             subbuf.buf, subbuf.len, start, end);
     else
         res = stringlib_rfind_slice(
-            PyBytes_AS_STRING(self), PyBytes_GET_SIZE(self),
+            PyByteArray_AS_STRING(self), PyByteArray_GET_SIZE(self),
             subbuf.buf, subbuf.len, start, end);
     PyObject_ReleaseBuffer(subobj, &subbuf);
     return res;
@@ -1164,7 +1164,7 @@
 Return -1 on failure.");
 
 static PyObject *
-bytes_find(PyBytesObject *self, PyObject *args)
+bytes_find(PyByteArrayObject *self, PyObject *args)
 {
     Py_ssize_t result = bytes_find_internal(self, args, +1);
     if (result == -2)
@@ -1180,10 +1180,10 @@
 as in slice notation.");
 
 static PyObject *
-bytes_count(PyBytesObject *self, PyObject *args)
+bytes_count(PyByteArrayObject *self, PyObject *args)
 {
     PyObject *sub_obj;
-    const char *str = PyBytes_AS_STRING(self);
+    const char *str = PyByteArray_AS_STRING(self);
     Py_ssize_t start = 0, end = PY_SSIZE_T_MAX;
     Py_buffer vsub;
     PyObject *count_obj;
@@ -1195,7 +1195,7 @@
     if (_getbuffer(sub_obj, &vsub) < 0)
         return NULL;
 
-    _adjust_indices(&start, &end, PyBytes_GET_SIZE(self));
+    _adjust_indices(&start, &end, PyByteArray_GET_SIZE(self));
 
     count_obj = PyInt_FromSsize_t(
         stringlib_count(str + start, end - start, vsub.buf, vsub.len)
@@ -1211,7 +1211,7 @@
 Like B.find() but raise ValueError when the subsection is not found.");
 
 static PyObject *
-bytes_index(PyBytesObject *self, PyObject *args)
+bytes_index(PyByteArrayObject *self, PyObject *args)
 {
     Py_ssize_t result = bytes_find_internal(self, args, +1);
     if (result == -2)
@@ -1235,7 +1235,7 @@
 Return -1 on failure.");
 
 static PyObject *
-bytes_rfind(PyBytesObject *self, PyObject *args)
+bytes_rfind(PyByteArrayObject *self, PyObject *args)
 {
     Py_ssize_t result = bytes_find_internal(self, args, -1);
     if (result == -2)
@@ -1250,7 +1250,7 @@
 Like B.rfind() but raise ValueError when the subsection is not found.");
 
 static PyObject *
-bytes_rindex(PyBytesObject *self, PyObject *args)
+bytes_rindex(PyByteArrayObject *self, PyObject *args)
 {
     Py_ssize_t result = bytes_find_internal(self, args, -1);
     if (result == -2)
@@ -1274,7 +1274,7 @@
         PyErr_Clear();
         if (_getbuffer(arg, &varg) < 0)
             return -1;
-        pos = stringlib_find(PyBytes_AS_STRING(self), Py_SIZE(self),
+        pos = stringlib_find(PyByteArray_AS_STRING(self), Py_SIZE(self),
                              varg.buf, varg.len, 0);
         PyObject_ReleaseBuffer(arg, &varg);
         return pos >= 0;
@@ -1284,7 +1284,7 @@
         return -1;
     }
 
-    return memchr(PyBytes_AS_STRING(self), ival, Py_SIZE(self)) != NULL;
+    return memchr(PyByteArray_AS_STRING(self), ival, Py_SIZE(self)) != NULL;
 }
 
 
@@ -1293,15 +1293,15 @@
  * -1 on error, 0 if not found and 1 if found.
  */
 Py_LOCAL(int)
-_bytes_tailmatch(PyBytesObject *self, PyObject *substr, Py_ssize_t start,
+_bytes_tailmatch(PyByteArrayObject *self, PyObject *substr, Py_ssize_t start,
                  Py_ssize_t end, int direction)
 {
-    Py_ssize_t len = PyBytes_GET_SIZE(self);
+    Py_ssize_t len = PyByteArray_GET_SIZE(self);
     const char* str;
     Py_buffer vsubstr;
     int rv = 0;
 
-    str = PyBytes_AS_STRING(self);
+    str = PyByteArray_AS_STRING(self);
 
     if (_getbuffer(substr, &vsubstr) < 0)
         return -1;
@@ -1340,7 +1340,7 @@
 prefix can also be a tuple of strings to try.");
 
 static PyObject *
-bytes_startswith(PyBytesObject *self, PyObject *args)
+bytes_startswith(PyByteArrayObject *self, PyObject *args)
 {
     Py_ssize_t start = 0;
     Py_ssize_t end = PY_SSIZE_T_MAX;
@@ -1380,7 +1380,7 @@
 suffix can also be a tuple of strings to try.");
 
 static PyObject *
-bytes_endswith(PyBytesObject *self, PyObject *args)
+bytes_endswith(PyByteArrayObject *self, PyObject *args)
 {
     Py_ssize_t start = 0;
     Py_ssize_t end = PY_SSIZE_T_MAX;
@@ -1421,7 +1421,7 @@
 table, which must be a bytes object of length 256.");
 
 static PyObject *
-bytes_translate(PyBytesObject *self, PyObject *args)
+bytes_translate(PyByteArrayObject *self, PyObject *args)
 {
     register char *input, *output;
     register const char *table;
@@ -1460,12 +1460,12 @@
     }
 
     table = (const char *)vtable.buf;
-    inlen = PyBytes_GET_SIZE(input_obj);
-    result = PyBytes_FromStringAndSize((char *)NULL, inlen);
+    inlen = PyByteArray_GET_SIZE(input_obj);
+    result = PyByteArray_FromStringAndSize((char *)NULL, inlen);
     if (result == NULL)
         goto done;
-    output_start = output = PyBytes_AsString(result);
-    input = PyBytes_AS_STRING(input_obj);
+    output_start = output = PyByteArray_AsString(result);
+    input = PyByteArray_AS_STRING(input_obj);
 
     if (vdel.len == 0) {
         /* If no deletions are required, use faster code */
@@ -1474,7 +1474,7 @@
             if (Py_CHARMASK((*output++ = table[c])) != c)
                 changed = 1;
         }
-        if (changed || !PyBytes_CheckExact(input_obj))
+        if (changed || !PyByteArray_CheckExact(input_obj))
             goto done;
         Py_DECREF(result);
         Py_INCREF(input_obj);
@@ -1495,7 +1495,7 @@
                     continue;
         changed = 1;
     }
-    if (!changed && PyBytes_CheckExact(input_obj)) {
+    if (!changed && PyByteArray_CheckExact(input_obj)) {
         Py_DECREF(result);
         Py_INCREF(input_obj);
         result = input_obj;
@@ -1503,7 +1503,7 @@
     }
     /* Fix the size of the resulting string */
     if (inlen > 0)
-        PyBytes_Resize(result, output - output_start);
+        PyByteArray_Resize(result, output - output_start);
 
 done:
     PyObject_ReleaseBuffer(tableobj, &vtable);
@@ -1530,16 +1530,16 @@
 
 /* Bytes ops must return a string.  */
 /* If the object is subclass of bytes, create a copy */
-Py_LOCAL(PyBytesObject *)
-return_self(PyBytesObject *self)
+Py_LOCAL(PyByteArrayObject *)
+return_self(PyByteArrayObject *self)
 {
-    if (PyBytes_CheckExact(self)) {
+    if (PyByteArray_CheckExact(self)) {
         Py_INCREF(self);
-        return (PyBytesObject *)self;
+        return (PyByteArrayObject *)self;
     }
-    return (PyBytesObject *)PyBytes_FromStringAndSize(
-            PyBytes_AS_STRING(self),
-            PyBytes_GET_SIZE(self));
+    return (PyByteArrayObject *)PyByteArray_FromStringAndSize(
+            PyByteArray_AS_STRING(self),
+            PyByteArray_GET_SIZE(self));
 }
 
 Py_LOCAL_INLINE(Py_ssize_t)
@@ -1649,17 +1649,17 @@
 /* Algorithms for different cases of string replacement */
 
 /* len(self)>=1, from="", len(to)>=1, maxcount>=1 */
-Py_LOCAL(PyBytesObject *)
-replace_interleave(PyBytesObject *self,
+Py_LOCAL(PyByteArrayObject *)
+replace_interleave(PyByteArrayObject *self,
                    const char *to_s, Py_ssize_t to_len,
                    Py_ssize_t maxcount)
 {
     char *self_s, *result_s;
     Py_ssize_t self_len, result_len;
     Py_ssize_t count, i, product;
-    PyBytesObject *result;
+    PyByteArrayObject *result;
 
-    self_len = PyBytes_GET_SIZE(self);
+    self_len = PyByteArray_GET_SIZE(self);
 
     /* 1 at the end plus 1 after every character */
     count = self_len+1;
@@ -1681,12 +1681,12 @@
         return NULL;
     }
 
-    if (! (result = (PyBytesObject *)
-                     PyBytes_FromStringAndSize(NULL, result_len)) )
+    if (! (result = (PyByteArrayObject *)
+                     PyByteArray_FromStringAndSize(NULL, result_len)) )
         return NULL;
 
-    self_s = PyBytes_AS_STRING(self);
-    result_s = PyBytes_AS_STRING(result);
+    self_s = PyByteArray_AS_STRING(self);
+    result_s = PyByteArray_AS_STRING(result);
 
     /* TODO: special case single character, which doesn't need memcpy */
 
@@ -1709,18 +1709,18 @@
 
 /* Special case for deleting a single character */
 /* len(self)>=1, len(from)==1, to="", maxcount>=1 */
-Py_LOCAL(PyBytesObject *)
-replace_delete_single_character(PyBytesObject *self,
+Py_LOCAL(PyByteArrayObject *)
+replace_delete_single_character(PyByteArrayObject *self,
                                 char from_c, Py_ssize_t maxcount)
 {
     char *self_s, *result_s;
     char *start, *next, *end;
     Py_ssize_t self_len, result_len;
     Py_ssize_t count;
-    PyBytesObject *result;
+    PyByteArrayObject *result;
 
-    self_len = PyBytes_GET_SIZE(self);
-    self_s = PyBytes_AS_STRING(self);
+    self_len = PyByteArray_GET_SIZE(self);
+    self_s = PyByteArray_AS_STRING(self);
 
     count = countchar(self_s, self_len, from_c, maxcount);
     if (count == 0) {
@@ -1730,10 +1730,10 @@
     result_len = self_len - count;  /* from_len == 1 */
     assert(result_len>=0);
 
-    if ( (result = (PyBytesObject *)
-                    PyBytes_FromStringAndSize(NULL, result_len)) == NULL)
+    if ( (result = (PyByteArrayObject *)
+                    PyByteArray_FromStringAndSize(NULL, result_len)) == NULL)
         return NULL;
-    result_s = PyBytes_AS_STRING(result);
+    result_s = PyByteArray_AS_STRING(result);
 
     start = self_s;
     end = self_s + self_len;
@@ -1752,8 +1752,8 @@
 
 /* len(self)>=1, len(from)>=2, to="", maxcount>=1 */
 
-Py_LOCAL(PyBytesObject *)
-replace_delete_substring(PyBytesObject *self,
+Py_LOCAL(PyByteArrayObject *)
+replace_delete_substring(PyByteArrayObject *self,
                          const char *from_s, Py_ssize_t from_len,
                          Py_ssize_t maxcount)
 {
@@ -1761,10 +1761,10 @@
     char *start, *next, *end;
     Py_ssize_t self_len, result_len;
     Py_ssize_t count, offset;
-    PyBytesObject *result;
+    PyByteArrayObject *result;
 
-    self_len = PyBytes_GET_SIZE(self);
-    self_s = PyBytes_AS_STRING(self);
+    self_len = PyByteArray_GET_SIZE(self);
+    self_s = PyByteArray_AS_STRING(self);
 
     count = countstring(self_s, self_len,
                         from_s, from_len,
@@ -1779,11 +1779,11 @@
     result_len = self_len - (count * from_len);
     assert (result_len>=0);
 
-    if ( (result = (PyBytesObject *)
-        PyBytes_FromStringAndSize(NULL, result_len)) == NULL )
+    if ( (result = (PyByteArrayObject *)
+        PyByteArray_FromStringAndSize(NULL, result_len)) == NULL )
             return NULL;
 
-    result_s = PyBytes_AS_STRING(result);
+    result_s = PyByteArray_AS_STRING(result);
 
     start = self_s;
     end = self_s + self_len;
@@ -1805,18 +1805,18 @@
 }
 
 /* len(self)>=1, len(from)==len(to)==1, maxcount>=1 */
-Py_LOCAL(PyBytesObject *)
-replace_single_character_in_place(PyBytesObject *self,
+Py_LOCAL(PyByteArrayObject *)
+replace_single_character_in_place(PyByteArrayObject *self,
                                   char from_c, char to_c,
                                   Py_ssize_t maxcount)
 {
         char *self_s, *result_s, *start, *end, *next;
         Py_ssize_t self_len;
-        PyBytesObject *result;
+        PyByteArrayObject *result;
 
         /* The result string will be the same size */
-        self_s = PyBytes_AS_STRING(self);
-        self_len = PyBytes_GET_SIZE(self);
+        self_s = PyByteArray_AS_STRING(self);
+        self_len = PyByteArray_GET_SIZE(self);
 
         next = findchar(self_s, self_len, from_c);
 
@@ -1826,10 +1826,10 @@
         }
 
         /* Need to make a new bytes */
-        result = (PyBytesObject *) PyBytes_FromStringAndSize(NULL, self_len);
+        result = (PyByteArrayObject *) PyByteArray_FromStringAndSize(NULL, self_len);
         if (result == NULL)
                 return NULL;
-        result_s = PyBytes_AS_STRING(result);
+        result_s = PyByteArray_AS_STRING(result);
         Py_MEMCPY(result_s, self_s, self_len);
 
         /* change everything in-place, starting with this one */
@@ -1850,8 +1850,8 @@
 }
 
 /* len(self)>=1, len(from)==len(to)>=2, maxcount>=1 */
-Py_LOCAL(PyBytesObject *)
-replace_substring_in_place(PyBytesObject *self,
+Py_LOCAL(PyByteArrayObject *)
+replace_substring_in_place(PyByteArrayObject *self,
                            const char *from_s, Py_ssize_t from_len,
                            const char *to_s, Py_ssize_t to_len,
                            Py_ssize_t maxcount)
@@ -1859,12 +1859,12 @@
     char *result_s, *start, *end;
     char *self_s;
     Py_ssize_t self_len, offset;
-    PyBytesObject *result;
+    PyByteArrayObject *result;
 
     /* The result bytes will be the same size */
 
-    self_s = PyBytes_AS_STRING(self);
-    self_len = PyBytes_GET_SIZE(self);
+    self_s = PyByteArray_AS_STRING(self);
+    self_len = PyByteArray_GET_SIZE(self);
 
     offset = findstring(self_s, self_len,
                         from_s, from_len,
@@ -1875,10 +1875,10 @@
     }
 
     /* Need to make a new bytes */
-    result = (PyBytesObject *) PyBytes_FromStringAndSize(NULL, self_len);
+    result = (PyByteArrayObject *) PyByteArray_FromStringAndSize(NULL, self_len);
     if (result == NULL)
         return NULL;
-    result_s = PyBytes_AS_STRING(result);
+    result_s = PyByteArray_AS_STRING(result);
     Py_MEMCPY(result_s, self_s, self_len);
 
     /* change everything in-place, starting with this one */
@@ -1901,8 +1901,8 @@
 }
 
 /* len(self)>=1, len(from)==1, len(to)>=2, maxcount>=1 */
-Py_LOCAL(PyBytesObject *)
-replace_single_character(PyBytesObject *self,
+Py_LOCAL(PyByteArrayObject *)
+replace_single_character(PyByteArrayObject *self,
                          char from_c,
                          const char *to_s, Py_ssize_t to_len,
                          Py_ssize_t maxcount)
@@ -1911,10 +1911,10 @@
     char *start, *next, *end;
     Py_ssize_t self_len, result_len;
     Py_ssize_t count, product;
-    PyBytesObject *result;
+    PyByteArrayObject *result;
 
-    self_s = PyBytes_AS_STRING(self);
-    self_len = PyBytes_GET_SIZE(self);
+    self_s = PyByteArray_AS_STRING(self);
+    self_len = PyByteArray_GET_SIZE(self);
 
     count = countchar(self_s, self_len, from_c, maxcount);
     if (count == 0) {
@@ -1935,10 +1935,10 @@
             return NULL;
     }
 
-    if ( (result = (PyBytesObject *)
-          PyBytes_FromStringAndSize(NULL, result_len)) == NULL)
+    if ( (result = (PyByteArrayObject *)
+          PyByteArray_FromStringAndSize(NULL, result_len)) == NULL)
             return NULL;
-    result_s = PyBytes_AS_STRING(result);
+    result_s = PyByteArray_AS_STRING(result);
 
     start = self_s;
     end = self_s + self_len;
@@ -1968,8 +1968,8 @@
 }
 
 /* len(self)>=1, len(from)>=2, len(to)>=2, maxcount>=1 */
-Py_LOCAL(PyBytesObject *)
-replace_substring(PyBytesObject *self,
+Py_LOCAL(PyByteArrayObject *)
+replace_substring(PyByteArrayObject *self,
                   const char *from_s, Py_ssize_t from_len,
                   const char *to_s, Py_ssize_t to_len,
                   Py_ssize_t maxcount)
@@ -1978,10 +1978,10 @@
     char *start, *next, *end;
     Py_ssize_t self_len, result_len;
     Py_ssize_t count, offset, product;
-    PyBytesObject *result;
+    PyByteArrayObject *result;
 
-    self_s = PyBytes_AS_STRING(self);
-    self_len = PyBytes_GET_SIZE(self);
+    self_s = PyByteArray_AS_STRING(self);
+    self_len = PyByteArray_GET_SIZE(self);
 
     count = countstring(self_s, self_len,
                         from_s, from_len,
@@ -2004,10 +2004,10 @@
         return NULL;
     }
 
-    if ( (result = (PyBytesObject *)
-          PyBytes_FromStringAndSize(NULL, result_len)) == NULL)
+    if ( (result = (PyByteArrayObject *)
+          PyByteArray_FromStringAndSize(NULL, result_len)) == NULL)
         return NULL;
-    result_s = PyBytes_AS_STRING(result);
+    result_s = PyByteArray_AS_STRING(result);
 
     start = self_s;
     end = self_s + self_len;
@@ -2039,15 +2039,15 @@
 }
 
 
-Py_LOCAL(PyBytesObject *)
-replace(PyBytesObject *self,
+Py_LOCAL(PyByteArrayObject *)
+replace(PyByteArrayObject *self,
         const char *from_s, Py_ssize_t from_len,
         const char *to_s, Py_ssize_t to_len,
         Py_ssize_t maxcount)
 {
     if (maxcount < 0) {
         maxcount = PY_SSIZE_T_MAX;
-    } else if (maxcount == 0 || PyBytes_GET_SIZE(self) == 0) {
+    } else if (maxcount == 0 || PyByteArray_GET_SIZE(self) == 0) {
         /* nothing to do; return the original bytes */
         return return_self(self);
     }
@@ -2070,7 +2070,7 @@
     /* Except for "".replace("", "A") == "A" there is no way beyond this */
     /* point for an empty self bytes to generate a non-empty bytes */
     /* Special case so the remaining code always gets a non-empty bytes */
-    if (PyBytes_GET_SIZE(self) == 0) {
+    if (PyByteArray_GET_SIZE(self) == 0) {
         return return_self(self);
     }
 
@@ -2118,7 +2118,7 @@
 given, only the first count occurrences are replaced.");
 
 static PyObject *
-bytes_replace(PyBytesObject *self, PyObject *args)
+bytes_replace(PyByteArrayObject *self, PyObject *args)
 {
     Py_ssize_t count = -1;
     PyObject *from, *to, *res;
@@ -2134,7 +2134,7 @@
         return NULL;
     }
 
-    res = (PyObject *)replace((PyBytesObject *) self,
+    res = (PyObject *)replace((PyByteArrayObject *) self,
                               vfrom.buf, vfrom.len,
                               vto.buf, vto.len, count);
 
@@ -2158,7 +2158,7 @@
     (maxsplit >= MAX_PREALLOC ? MAX_PREALLOC : maxsplit+1)
 
 #define SPLIT_APPEND(data, left, right)                         \
-    str = PyBytes_FromStringAndSize((data) + (left),       \
+    str = PyByteArray_FromStringAndSize((data) + (left),       \
                                      (right) - (left));     \
     if (str == NULL)                                        \
         goto onError;                                   \
@@ -2170,7 +2170,7 @@
         Py_DECREF(str);
 
 #define SPLIT_ADD(data, left, right) {                          \
-    str = PyBytes_FromStringAndSize((data) + (left),       \
+    str = PyByteArray_FromStringAndSize((data) + (left),       \
                                      (right) - (left));     \
     if (str == NULL)                                        \
         goto onError;                                   \
@@ -2269,11 +2269,11 @@
 If maxsplit is given, at most maxsplit splits are done.");
 
 static PyObject *
-bytes_split(PyBytesObject *self, PyObject *args)
+bytes_split(PyByteArrayObject *self, PyObject *args)
 {
-    Py_ssize_t len = PyBytes_GET_SIZE(self), n, i, j;
+    Py_ssize_t len = PyByteArray_GET_SIZE(self), n, i, j;
     Py_ssize_t maxsplit = -1, count = 0;
-    const char *s = PyBytes_AS_STRING(self), *sub;
+    const char *s = PyByteArray_AS_STRING(self), *sub;
     PyObject *list, *str, *subobj = Py_None;
     Py_buffer vsub;
 #ifdef USE_FAST
@@ -2351,7 +2351,7 @@
         assert(PyTuple_GET_SIZE(result) == 3);
         for (i = 0; i < 3; i++) {
             if (PyTuple_GET_ITEM(result, i) == (PyObject *)nullbytes) {
-                PyObject *new = PyBytes_FromStringAndSize(NULL, 0);
+                PyObject *new = PyByteArray_FromStringAndSize(NULL, 0);
                 if (new == NULL) {
                     Py_DECREF(result);
                     result = NULL;
@@ -2373,19 +2373,19 @@
 found, returns B and two empty bytearray objects.");
 
 static PyObject *
-bytes_partition(PyBytesObject *self, PyObject *sep_obj)
+bytes_partition(PyByteArrayObject *self, PyObject *sep_obj)
 {
     PyObject *bytesep, *result;
 
-    bytesep = PyBytes_FromObject(sep_obj);
+    bytesep = PyByteArray_FromObject(sep_obj);
     if (! bytesep)
         return NULL;
 
     result = stringlib_partition(
             (PyObject*) self,
-            PyBytes_AS_STRING(self), PyBytes_GET_SIZE(self),
+            PyByteArray_AS_STRING(self), PyByteArray_GET_SIZE(self),
             bytesep,
-            PyBytes_AS_STRING(bytesep), PyBytes_GET_SIZE(bytesep)
+            PyByteArray_AS_STRING(bytesep), PyByteArray_GET_SIZE(bytesep)
             );
 
     Py_DECREF(bytesep);
@@ -2401,19 +2401,19 @@
 bytearray objects and B.");
 
 static PyObject *
-bytes_rpartition(PyBytesObject *self, PyObject *sep_obj)
+bytes_rpartition(PyByteArrayObject *self, PyObject *sep_obj)
 {
     PyObject *bytesep, *result;
 
-    bytesep = PyBytes_FromObject(sep_obj);
+    bytesep = PyByteArray_FromObject(sep_obj);
     if (! bytesep)
         return NULL;
 
     result = stringlib_rpartition(
             (PyObject*) self,
-            PyBytes_AS_STRING(self), PyBytes_GET_SIZE(self),
+            PyByteArray_AS_STRING(self), PyByteArray_GET_SIZE(self),
             bytesep,
-            PyBytes_AS_STRING(bytesep), PyBytes_GET_SIZE(bytesep)
+            PyByteArray_AS_STRING(bytesep), PyByteArray_GET_SIZE(bytesep)
             );
 
     Py_DECREF(bytesep);
@@ -2504,11 +2504,11 @@
 If maxsplit is given, at most maxsplit splits are done.");
 
 static PyObject *
-bytes_rsplit(PyBytesObject *self, PyObject *args)
+bytes_rsplit(PyByteArrayObject *self, PyObject *args)
 {
-    Py_ssize_t len = PyBytes_GET_SIZE(self), n, i, j;
+    Py_ssize_t len = PyByteArray_GET_SIZE(self), n, i, j;
     Py_ssize_t maxsplit = -1, count = 0;
-    const char *s = PyBytes_AS_STRING(self), *sub;
+    const char *s = PyByteArray_AS_STRING(self), *sub;
     PyObject *list, *str, *subobj = Py_None;
     Py_buffer vsub;
 
@@ -2570,7 +2570,7 @@
 \n\
 Reverse the order of the values in B in place.");
 static PyObject *
-bytes_reverse(PyBytesObject *self, PyObject *unused)
+bytes_reverse(PyByteArrayObject *self, PyObject *unused)
 {
     char swap, *head, *tail;
     Py_ssize_t i, j, n = Py_SIZE(self);
@@ -2592,7 +2592,7 @@
 \n\
 Insert a single item into the bytearray before the given index.");
 static PyObject *
-bytes_insert(PyBytesObject *self, PyObject *args)
+bytes_insert(PyByteArrayObject *self, PyObject *args)
 {
     int value;
     Py_ssize_t where, n = Py_SIZE(self);
@@ -2610,7 +2610,7 @@
                         "byte must be in range(0, 256)");
         return NULL;
     }
-    if (PyBytes_Resize((PyObject *)self, n + 1) < 0)
+    if (PyByteArray_Resize((PyObject *)self, n + 1) < 0)
         return NULL;
 
     if (where < 0) {
@@ -2631,7 +2631,7 @@
 \n\
 Append a single item to the end of B.");
 static PyObject *
-bytes_append(PyBytesObject *self, PyObject *arg)
+bytes_append(PyByteArrayObject *self, PyObject *arg)
 {
     int value;
     Py_ssize_t n = Py_SIZE(self);
@@ -2643,7 +2643,7 @@
                         "cannot add more objects to bytes");
         return NULL;
     }
-    if (PyBytes_Resize((PyObject *)self, n + 1) < 0)
+    if (PyByteArray_Resize((PyObject *)self, n + 1) < 0)
         return NULL;
 
     self->ob_bytes[n] = value;
@@ -2657,7 +2657,7 @@
 Append all the elements from the iterator or sequence to the\n\
 end of B.");
 static PyObject *
-bytes_extend(PyBytesObject *self, PyObject *arg)
+bytes_extend(PyByteArrayObject *self, PyObject *arg)
 {
     PyObject *it, *item, *bytes_obj;
     Py_ssize_t buf_size = 0, len = 0;
@@ -2679,10 +2679,10 @@
     /* Try to determine the length of the argument. 32 is abitrary. */
     buf_size = _PyObject_LengthHint(arg, 32);
 
-    bytes_obj = PyBytes_FromStringAndSize(NULL, buf_size);
+    bytes_obj = PyByteArray_FromStringAndSize(NULL, buf_size);
     if (bytes_obj == NULL)
         return NULL;
-    buf = PyBytes_AS_STRING(bytes_obj);
+    buf = PyByteArray_AS_STRING(bytes_obj);
 
     while ((item = PyIter_Next(it)) != NULL) {
         if (! _getbytevalue(item, &value)) {
@@ -2696,20 +2696,20 @@
 
         if (len >= buf_size) {
             buf_size = len + (len >> 1) + 1;
-            if (PyBytes_Resize((PyObject *)bytes_obj, buf_size) < 0) {
+            if (PyByteArray_Resize((PyObject *)bytes_obj, buf_size) < 0) {
                 Py_DECREF(it);
                 Py_DECREF(bytes_obj);
                 return NULL;
             }
             /* Recompute the `buf' pointer, since the resizing operation may
                have invalidated it. */
-            buf = PyBytes_AS_STRING(bytes_obj);
+            buf = PyByteArray_AS_STRING(bytes_obj);
         }
     }
     Py_DECREF(it);
 
     /* Resize down to exact size. */
-    if (PyBytes_Resize((PyObject *)bytes_obj, len) < 0) {
+    if (PyByteArray_Resize((PyObject *)bytes_obj, len) < 0) {
         Py_DECREF(bytes_obj);
         return NULL;
     }
@@ -2727,7 +2727,7 @@
 Remove and return a single item from B. If no index\n\
 argument is give, will pop the last value.");
 static PyObject *
-bytes_pop(PyBytesObject *self, PyObject *args)
+bytes_pop(PyByteArrayObject *self, PyObject *args)
 {
     int value;
     Py_ssize_t where = -1, n = Py_SIZE(self);
@@ -2749,7 +2749,7 @@
 
     value = self->ob_bytes[where];
     memmove(self->ob_bytes + where, self->ob_bytes + where + 1, n - where);
-    if (PyBytes_Resize((PyObject *)self, n - 1) < 0)
+    if (PyByteArray_Resize((PyObject *)self, n - 1) < 0)
         return NULL;
 
     return PyInt_FromLong(value);
@@ -2760,7 +2760,7 @@
 \n\
 Remove the first occurance of a value in B.");
 static PyObject *
-bytes_remove(PyBytesObject *self, PyObject *arg)
+bytes_remove(PyByteArrayObject *self, PyObject *arg)
 {
     int value;
     Py_ssize_t where, n = Py_SIZE(self);
@@ -2778,7 +2778,7 @@
     }
 
     memmove(self->ob_bytes + where, self->ob_bytes + where + 1, n - where);
-    if (PyBytes_Resize((PyObject *)self, n - 1) < 0)
+    if (PyByteArray_Resize((PyObject *)self, n - 1) < 0)
         return NULL;
 
     Py_RETURN_NONE;
@@ -2812,7 +2812,7 @@
 Strip leading and trailing bytes contained in the argument.\n\
 If the argument is omitted, strip ASCII whitespace.");
 static PyObject *
-bytes_strip(PyBytesObject *self, PyObject *args)
+bytes_strip(PyByteArrayObject *self, PyObject *args)
 {
     Py_ssize_t left, right, mysize, argsize;
     void *myptr, *argptr;
@@ -2839,7 +2839,7 @@
         right = rstrip_helper(myptr, mysize, argptr, argsize);
     if (arg != Py_None)
         PyObject_ReleaseBuffer(arg, &varg);
-    return PyBytes_FromStringAndSize(self->ob_bytes + left, right - left);
+    return PyByteArray_FromStringAndSize(self->ob_bytes + left, right - left);
 }
 
 PyDoc_STRVAR(lstrip__doc__,
@@ -2848,7 +2848,7 @@
 Strip leading bytes contained in the argument.\n\
 If the argument is omitted, strip leading ASCII whitespace.");
 static PyObject *
-bytes_lstrip(PyBytesObject *self, PyObject *args)
+bytes_lstrip(PyByteArrayObject *self, PyObject *args)
 {
     Py_ssize_t left, right, mysize, argsize;
     void *myptr, *argptr;
@@ -2872,7 +2872,7 @@
     right = mysize;
     if (arg != Py_None)
         PyObject_ReleaseBuffer(arg, &varg);
-    return PyBytes_FromStringAndSize(self->ob_bytes + left, right - left);
+    return PyByteArray_FromStringAndSize(self->ob_bytes + left, right - left);
 }
 
 PyDoc_STRVAR(rstrip__doc__,
@@ -2881,7 +2881,7 @@
 Strip trailing bytes contained in the argument.\n\
 If the argument is omitted, strip trailing ASCII whitespace.");
 static PyObject *
-bytes_rstrip(PyBytesObject *self, PyObject *args)
+bytes_rstrip(PyByteArrayObject *self, PyObject *args)
 {
     Py_ssize_t left, right, mysize, argsize;
     void *myptr, *argptr;
@@ -2905,7 +2905,7 @@
     right = rstrip_helper(myptr, mysize, argptr, argsize);
     if (arg != Py_None)
         PyObject_ReleaseBuffer(arg, &varg);
-    return PyBytes_FromStringAndSize(self->ob_bytes + left, right - left);
+    return PyByteArray_FromStringAndSize(self->ob_bytes + left, right - left);
 }
 
 PyDoc_STRVAR(decode_doc,
@@ -2937,7 +2937,7 @@
 Returns the number of bytes actually allocated.");
 
 static PyObject *
-bytes_alloc(PyBytesObject *self)
+bytes_alloc(PyByteArrayObject *self)
 {
     return PyInt_FromSsize_t(self->ob_alloc);
 }
@@ -2948,7 +2948,7 @@
 Concatenates any number of bytearray objects, with B in between each pair.");
 
 static PyObject *
-bytes_join(PyBytesObject *self, PyObject *it)
+bytes_join(PyByteArrayObject *self, PyObject *it)
 {
     PyObject *seq;
     Py_ssize_t mysize = Py_SIZE(self);
@@ -2969,7 +2969,7 @@
     /* XXX Shouldn't we use _getbuffer() on these items instead? */
     for (i = 0; i < n; i++) {
         PyObject *obj = items[i];
-        if (!PyBytes_Check(obj) && !PyString_Check(obj)) {
+        if (!PyByteArray_Check(obj) && !PyString_Check(obj)) {
             PyErr_Format(PyExc_TypeError,
                          "can only join an iterable of bytes "
                          "(item %ld has type '%.100s')",
@@ -2987,16 +2987,16 @@
     }
 
     /* Allocate the result, and copy the bytes */
-    result = PyBytes_FromStringAndSize(NULL, totalsize);
+    result = PyByteArray_FromStringAndSize(NULL, totalsize);
     if (result == NULL)
         goto error;
-    dest = PyBytes_AS_STRING(result);
+    dest = PyByteArray_AS_STRING(result);
     for (i = 0; i < n; i++) {
         PyObject *obj = items[i];
         Py_ssize_t size = Py_SIZE(obj);
         char *buf;
-        if (PyBytes_Check(obj))
-           buf = PyBytes_AS_STRING(obj);
+        if (PyByteArray_Check(obj))
+           buf = PyByteArray_AS_STRING(obj);
         else
            buf = PyString_AS_STRING(obj);
         if (i) {
@@ -3055,10 +3055,10 @@
     hexlen = PyUnicode_GET_SIZE(hexobj);
     hex = PyUnicode_AS_UNICODE(hexobj);
     byteslen = hexlen/2; /* This overestimates if there are spaces */
-    newbytes = PyBytes_FromStringAndSize(NULL, byteslen);
+    newbytes = PyByteArray_FromStringAndSize(NULL, byteslen);
     if (!newbytes)
         return NULL;
-    buf = PyBytes_AS_STRING(newbytes);
+    buf = PyByteArray_AS_STRING(newbytes);
     for (i = j = 0; i < hexlen; i += 2) {
         /* skip over spaces in the input */
         while (hex[i] == ' ')
@@ -3075,7 +3075,7 @@
         }
         buf[j++] = (top << 4) + bot;
     }
-    if (PyBytes_Resize(newbytes, j) < 0)
+    if (PyByteArray_Resize(newbytes, j) < 0)
         goto error;
     return newbytes;
 
@@ -3087,7 +3087,7 @@
 PyDoc_STRVAR(reduce_doc, "Return state information for pickling.");
 
 static PyObject *
-bytes_reduce(PyBytesObject *self)
+bytes_reduce(PyByteArrayObject *self)
 {
     PyObject *latin1, *dict;
     if (self->ob_bytes)
@@ -3108,7 +3108,7 @@
 
 static PySequenceMethods bytes_as_sequence = {
     (lenfunc)bytes_length,              /* sq_length */
-    (binaryfunc)PyBytes_Concat,         /* sq_concat */
+    (binaryfunc)PyByteArray_Concat,         /* sq_concat */
     (ssizeargfunc)bytes_repeat,         /* sq_repeat */
     (ssizeargfunc)bytes_getitem,        /* sq_item */
     0,                                  /* sq_slice */
@@ -3217,10 +3217,10 @@
 
 static PyObject *bytes_iter(PyObject *seq);
 
-PyTypeObject PyBytes_Type = {
+PyTypeObject PyByteArray_Type = {
     PyVarObject_HEAD_INIT(&PyType_Type, 0)
     "bytearray",
-    sizeof(PyBytesObject),
+    sizeof(PyByteArrayObject),
     0,
     (destructor)bytes_dealloc,          /* tp_dealloc */
     0,                                  /* tp_print */
@@ -3265,7 +3265,7 @@
 typedef struct {
     PyObject_HEAD
     Py_ssize_t it_index;
-    PyBytesObject *it_seq; /* Set to NULL when iterator is exhausted */
+    PyByteArrayObject *it_seq; /* Set to NULL when iterator is exhausted */
 } bytesiterobject;
 
 static void
@@ -3286,16 +3286,16 @@
 static PyObject *
 bytesiter_next(bytesiterobject *it)
 {
-    PyBytesObject *seq;
+    PyByteArrayObject *seq;
     PyObject *item;
 
     assert(it != NULL);
     seq = it->it_seq;
     if (seq == NULL)
         return NULL;
-    assert(PyBytes_Check(seq));
+    assert(PyByteArray_Check(seq));
 
-    if (it->it_index < PyBytes_GET_SIZE(seq)) {
+    if (it->it_index < PyByteArray_GET_SIZE(seq)) {
         item = PyInt_FromLong(
             (unsigned char)seq->ob_bytes[it->it_index]);
         if (item != NULL)
@@ -3313,7 +3313,7 @@
 {
     Py_ssize_t len = 0;
     if (it->it_seq)
-        len = PyBytes_GET_SIZE(it->it_seq) - it->it_index;
+        len = PyByteArray_GET_SIZE(it->it_seq) - it->it_index;
     return PyInt_FromSsize_t(len);
 }
 
@@ -3326,7 +3326,7 @@
     {NULL, NULL} /* sentinel */
 };
 
-PyTypeObject PyBytesIter_Type = {
+PyTypeObject PyByteArrayIter_Type = {
     PyVarObject_HEAD_INIT(&PyType_Type, 0)
     "bytearray_iterator",              /* tp_name */
     sizeof(bytesiterobject),           /* tp_basicsize */
@@ -3364,16 +3364,16 @@
 {
     bytesiterobject *it;
 
-    if (!PyBytes_Check(seq)) {
+    if (!PyByteArray_Check(seq)) {
         PyErr_BadInternalCall();
         return NULL;
     }
-    it = PyObject_GC_New(bytesiterobject, &PyBytesIter_Type);
+    it = PyObject_GC_New(bytesiterobject, &PyByteArrayIter_Type);
     if (it == NULL)
         return NULL;
     it->it_index = 0;
     Py_INCREF(seq);
-    it->it_seq = (PyBytesObject *)seq;
+    it->it_seq = (PyByteArrayObject *)seq;
     _PyObject_GC_TRACK(it);
     return (PyObject *)it;
 }

Modified: python/trunk/Objects/object.c
==============================================================================
--- python/trunk/Objects/object.c	(original)
+++ python/trunk/Objects/object.c	Mon May 26 14:29:14 2008
@@ -1986,7 +1986,7 @@
 	if (PyType_Ready(&PyString_Type) < 0)
 		Py_FatalError("Can't initialize 'str'");
 
-	if (PyType_Ready(&PyBytes_Type) < 0)
+	if (PyType_Ready(&PyByteArray_Type) < 0)
 		Py_FatalError("Can't initialize 'bytes'");
 
 	if (PyType_Ready(&PyList_Type) < 0)

Modified: python/trunk/Objects/stringobject.c
==============================================================================
--- python/trunk/Objects/stringobject.c	(original)
+++ python/trunk/Objects/stringobject.c	Mon May 26 14:29:14 2008
@@ -961,8 +961,8 @@
 		if (PyUnicode_Check(bb))
 		    return PyUnicode_Concat((PyObject *)a, bb);
 #endif
-		if (PyBytes_Check(bb))
-		    return PyBytes_Concat((PyObject *)a, bb);
+		if (PyByteArray_Check(bb))
+		    return PyByteArray_Concat((PyObject *)a, bb);
 		PyErr_Format(PyExc_TypeError,
 			     "cannot concatenate 'str' and '%.200s' objects",
 			     Py_TYPE(bb)->tp_name);

Modified: python/trunk/Objects/unicodeobject.c
==============================================================================
--- python/trunk/Objects/unicodeobject.c	(original)
+++ python/trunk/Objects/unicodeobject.c	Mon May 26 14:29:14 2008
@@ -1084,7 +1084,7 @@
 	    s = PyString_AS_STRING(obj);
 	    len = PyString_GET_SIZE(obj);
     }
-    else if (PyBytes_Check(obj)) {
+    else if (PyByteArray_Check(obj)) {
         /* Python 2.x specific */
         PyErr_Format(PyExc_TypeError,
                      "decoding bytearray is not supported");

Modified: python/trunk/Python/bltinmodule.c
==============================================================================
--- python/trunk/Python/bltinmodule.c	(original)
+++ python/trunk/Python/bltinmodule.c	Mon May 26 14:29:14 2008
@@ -1498,10 +1498,10 @@
 			ord = (long)((unsigned char)*PyString_AS_STRING(obj));
 			return PyInt_FromLong(ord);
 		}
-	} else if (PyBytes_Check(obj)) {
-		size = PyBytes_GET_SIZE(obj);
+	} else if (PyByteArray_Check(obj)) {
+		size = PyByteArray_GET_SIZE(obj);
 		if (size == 1) {
-			ord = (long)((unsigned char)*PyBytes_AS_STRING(obj));
+			ord = (long)((unsigned char)*PyByteArray_AS_STRING(obj));
 			return PyInt_FromLong(ord);
 		}
 
@@ -2618,7 +2618,7 @@
 	SETBUILTIN("basestring",	&PyBaseString_Type);
 	SETBUILTIN("bool",		&PyBool_Type);
 	/*	SETBUILTIN("memoryview",        &PyMemoryView_Type); */
-	SETBUILTIN("bytearray",		&PyBytes_Type);
+	SETBUILTIN("bytearray",		&PyByteArray_Type);
 	SETBUILTIN("bytes",		&PyString_Type);
 	SETBUILTIN("buffer",		&PyBuffer_Type);
 	SETBUILTIN("classmethod",	&PyClassMethod_Type);

Modified: python/trunk/Python/pythonrun.c
==============================================================================
--- python/trunk/Python/pythonrun.c	(original)
+++ python/trunk/Python/pythonrun.c	Mon May 26 14:29:14 2008
@@ -169,7 +169,7 @@
 	if (!_PyInt_Init())
 		Py_FatalError("Py_Initialize: can't init ints");
 
-	if (!PyBytes_Init())
+	if (!PyByteArray_Init())
 		Py_FatalError("Py_Initialize: can't init bytearray");
 
 	_PyFloat_Init();
@@ -451,7 +451,7 @@
 	PyList_Fini();
 	PySet_Fini();
 	PyString_Fini();
-	PyBytes_Fini();
+	PyByteArray_Fini();
 	PyInt_Fini();
 	PyFloat_Fini();
 	PyDict_Fini();


More information about the Python-checkins mailing list