Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Objects/bytearrayobject.c

    r2 r391  
    66#include "bytes_methods.h"
    77
    8 static PyByteArrayObject *nullbytes = NULL;
    98char _PyByteArray_empty_string[] = "";
    109
     
    1211PyByteArray_Fini(void)
    1312{
    14     Py_CLEAR(nullbytes);
    1513}
    1614
     
    1816PyByteArray_Init(void)
    1917{
    20     nullbytes = PyObject_New(PyByteArrayObject, &PyByteArray_Type);
    21     if (nullbytes == NULL)
    22         return 0;
    23     nullbytes->ob_bytes = NULL;
    24     Py_SIZE(nullbytes) = nullbytes->ob_alloc = 0;
    25     nullbytes->ob_exports = 0;
    2618    return 1;
    2719}
     
    6961
    7062static Py_ssize_t
    71 bytes_buffer_getreadbuf(PyByteArrayObject *self, Py_ssize_t index, const void **ptr)
     63bytearray_buffer_getreadbuf(PyByteArrayObject *self, Py_ssize_t index, const void **ptr)
    7264{
    7365    if ( index != 0 ) {
     
    8173
    8274static Py_ssize_t
    83 bytes_buffer_getwritebuf(PyByteArrayObject *self, Py_ssize_t index, const void **ptr)
     75bytearray_buffer_getwritebuf(PyByteArrayObject *self, Py_ssize_t index, const void **ptr)
    8476{
    8577    if ( index != 0 ) {
     
    9385
    9486static Py_ssize_t
    95 bytes_buffer_getsegcount(PyByteArrayObject *self, Py_ssize_t *lenp)
     87bytearray_buffer_getsegcount(PyByteArrayObject *self, Py_ssize_t *lenp)
    9688{
    9789    if ( lenp )
     
    10193
    10294static Py_ssize_t
    103 bytes_buffer_getcharbuf(PyByteArrayObject *self, Py_ssize_t index, const char **ptr)
     95bytearray_buffer_getcharbuf(PyByteArrayObject *self, Py_ssize_t index, const char **ptr)
    10496{
    10597    if ( index != 0 ) {
     
    113105
    114106static int
    115 bytes_getbuffer(PyByteArrayObject *obj, Py_buffer *view, int flags)
    116 {
    117         int ret;
    118         void *ptr;
    119         if (view == NULL) {
    120                 obj->ob_exports++;
    121                 return 0;
    122         }
    123         ptr = (void *) PyByteArray_AS_STRING(obj);
    124         ret = PyBuffer_FillInfo(view, (PyObject*)obj, ptr, Py_SIZE(obj), 0, flags);
    125         if (ret >= 0) {
    126                 obj->ob_exports++;
    127         }
    128         return ret;
     107bytearray_getbuffer(PyByteArrayObject *obj, Py_buffer *view, int flags)
     108{
     109    int ret;
     110    void *ptr;
     111    if (view == NULL) {
     112        obj->ob_exports++;
     113        return 0;
     114    }
     115    ptr = (void *) PyByteArray_AS_STRING(obj);
     116    ret = PyBuffer_FillInfo(view, (PyObject*)obj, ptr, Py_SIZE(obj), 0, flags);
     117    if (ret >= 0) {
     118        obj->ob_exports++;
     119    }
     120    return ret;
    129121}
    130122
    131123static void
    132 bytes_releasebuffer(PyByteArrayObject *obj, Py_buffer *view)
    133 {
    134         obj->ob_exports--;
     124bytearray_releasebuffer(PyByteArrayObject *obj, Py_buffer *view)
     125{
     126    obj->ob_exports--;
    135127}
    136128
     
    297289    size = va.len + vb.len;
    298290    if (size < 0) {
    299             return PyErr_NoMemory();
     291            PyErr_NoMemory();
    300292            goto done;
    301293    }
     
    318310
    319311static Py_ssize_t
    320 bytes_length(PyByteArrayObject *self)
     312bytearray_length(PyByteArrayObject *self)
    321313{
    322314    return Py_SIZE(self);
     
    324316
    325317static PyObject *
    326 bytes_iconcat(PyByteArrayObject *self, PyObject *other)
     318bytearray_iconcat(PyByteArrayObject *self, PyObject *other)
    327319{
    328320    Py_ssize_t mysize;
     
    357349
    358350static PyObject *
    359 bytes_repeat(PyByteArrayObject *self, Py_ssize_t count)
     351bytearray_repeat(PyByteArrayObject *self, Py_ssize_t count)
    360352{
    361353    PyByteArrayObject *result;
     
    383375
    384376static PyObject *
    385 bytes_irepeat(PyByteArrayObject *self, Py_ssize_t count)
     377bytearray_irepeat(PyByteArrayObject *self, Py_ssize_t count)
    386378{
    387379    Py_ssize_t mysize;
     
    414406
    415407static PyObject *
    416 bytes_getitem(PyByteArrayObject *self, Py_ssize_t i)
     408bytearray_getitem(PyByteArrayObject *self, Py_ssize_t i)
    417409{
    418410    if (i < 0)
     
    426418
    427419static PyObject *
    428 bytes_subscript(PyByteArrayObject *self, PyObject *index)
     420bytearray_subscript(PyByteArrayObject *self, PyObject *index)
    429421{
    430422    if (PyIndex_Check(index)) {
     
    481473
    482474static int
    483 bytes_setslice(PyByteArrayObject *self, Py_ssize_t lo, Py_ssize_t hi,
     475bytearray_setslice(PyByteArrayObject *self, Py_ssize_t lo, Py_ssize_t hi,
    484476               PyObject *values)
    485477{
     
    496488        if (values == NULL)
    497489            return -1;
    498         err = bytes_setslice(self, lo, hi, values);
     490        err = bytearray_setslice(self, lo, hi, values);
    499491        Py_DECREF(values);
    500492        return err;
     
    571563
    572564static int
    573 bytes_setitem(PyByteArrayObject *self, Py_ssize_t i, PyObject *value)
     565bytearray_setitem(PyByteArrayObject *self, Py_ssize_t i, PyObject *value)
    574566{
    575567    int ival;
     
    584576
    585577    if (value == NULL)
    586         return bytes_setslice(self, i, i+1, NULL);
     578        return bytearray_setslice(self, i, i+1, NULL);
    587579
    588580    if (!_getbytevalue(value, &ival))
     
    594586
    595587static int
    596 bytes_ass_subscript(PyByteArrayObject *self, PyObject *index, PyObject *values)
     588bytearray_ass_subscript(PyByteArrayObject *self, PyObject *index, PyObject *values)
    597589{
    598590    Py_ssize_t start, stop, step, slicelen, needed;
     
    645637    }
    646638    else if (values == (PyObject *)self || !PyByteArray_Check(values)) {
    647         /* Make a copy an call this function recursively */
    648639        int err;
     640        if (PyNumber_Check(values) || PyUnicode_Check(values)) {
     641            PyErr_SetString(PyExc_TypeError,
     642                            "can assign only bytes, buffers, or iterables "
     643                            "of ints in range(0, 256)");
     644            return -1;
     645        }
     646        /* Make a copy and call this function recursively */
    649647        values = PyByteArray_FromObject(values);
    650648        if (values == NULL)
    651649            return -1;
    652         err = bytes_ass_subscript(self, index, values);
     650        err = bytearray_ass_subscript(self, index, values);
    653651        Py_DECREF(values);
    654652        return err;
     
    752750
    753751static int
    754 bytes_init(PyByteArrayObject *self, PyObject *args, PyObject *kwds)
     752bytearray_init(PyByteArrayObject *self, PyObject *args, PyObject *kwds)
    755753{
    756754    static char *kwlist[] = {"source", "encoding", "errors", 0};
     
    795793            Py_INCREF(arg);
    796794        }
    797         new = bytes_iconcat(self, arg);
     795        new = bytearray_iconcat(self, arg);
    798796        Py_DECREF(encoded);
    799797        if (new == NULL)
     
    803801    }
    804802
     803#ifdef Py_USING_UNICODE
    805804    if (PyUnicode_Check(arg)) {
    806805        /* Encode via the codec registry */
     
    815814            return -1;
    816815        assert(PyBytes_Check(encoded));
    817         new = bytes_iconcat(self, encoded);
     816        new = bytearray_iconcat(self, encoded);
    818817        Py_DECREF(encoded);
    819818        if (new == NULL)
     
    822821        return 0;
    823822    }
     823#endif
    824824
    825825    /* If it's not unicode, there can't be encoding or errors */
     
    831831
    832832    /* Is it an int? */
    833     count = PyNumber_AsSsize_t(arg, PyExc_ValueError);
    834     if (count == -1 && PyErr_Occurred())
     833    count = PyNumber_AsSsize_t(arg, PyExc_OverflowError);
     834    if (count == -1 && PyErr_Occurred()) {
     835        if (PyErr_ExceptionMatches(PyExc_OverflowError))
     836            return -1;
    835837        PyErr_Clear();
     838    }
     839    else if (count < 0) {
     840        PyErr_SetString(PyExc_ValueError, "negative count");
     841        return -1;
     842    }
    836843    else {
    837         if (count < 0) {
    838             PyErr_SetString(PyExc_ValueError, "negative count");
    839             return -1;
    840         }
    841844        if (count > 0) {
    842845            if (PyByteArray_Resize((PyObject *)self, count))
     
    915918   "smart quote" functionality. */
    916919static PyObject *
    917 bytes_repr(PyByteArrayObject *self)
     920bytearray_repr(PyByteArrayObject *self)
    918921{
    919922    static const char *hexdigits = "0123456789abcdef";
     
    930933    }
    931934    newsize = 14 + 4 * length;
    932     v = PyUnicode_FromUnicode(NULL, newsize);
     935    v = PyString_FromStringAndSize(NULL, newsize);
    933936    if (v == NULL) {
    934937        return NULL;
     
    936939    else {
    937940        register Py_ssize_t i;
    938         register Py_UNICODE c;
    939         register Py_UNICODE *p;
     941        register char c;
     942        register char *p;
    940943        int quote;
    941944
     
    957960        }
    958961
    959         p = PyUnicode_AS_UNICODE(v);
     962        p = PyString_AS_STRING(v);
    960963        while (*quote_prefix)
    961964            *p++ = *quote_prefix++;
     
    965968            /* There's at least enough room for a hex escape
    966969               and a closing quote. */
    967             assert(newsize - (p - PyUnicode_AS_UNICODE(v)) >= 5);
     970            assert(newsize - (p - PyString_AS_STRING(v)) >= 5);
    968971            c = self->ob_bytes[i];
    969972            if (c == '\'' || c == '\\')
     
    986989                *p++ = c;
    987990        }
    988         assert(newsize - (p - PyUnicode_AS_UNICODE(v)) >= 1);
     991        assert(newsize - (p - PyString_AS_STRING(v)) >= 1);
    989992        *p++ = quote;
    990993        while (*quote_postfix) {
     
    992995        }
    993996        *p = '\0';
    994         if (PyUnicode_Resize(&v, (p - PyUnicode_AS_UNICODE(v)))) {
     997        if (_PyString_Resize(&v, (p - PyString_AS_STRING(v)))) {
    995998            Py_DECREF(v);
    996999            return NULL;
     
    10011004
    10021005static PyObject *
    1003 bytes_str(PyObject *op)
     1006bytearray_str(PyObject *op)
    10041007{
    10051008#if 0
     
    10091012            return NULL;
    10101013    }
    1011     return bytes_repr((PyByteArrayObject*)op);
     1014    return bytearray_repr((PyByteArrayObject*)op);
    10121015#endif
    10131016    return PyBytes_FromStringAndSize(((PyByteArrayObject*)op)->ob_bytes, Py_SIZE(op));
     
    10151018
    10161019static PyObject *
    1017 bytes_richcompare(PyObject *self, PyObject *other, int op)
     1020bytearray_richcompare(PyObject *self, PyObject *other, int op)
    10181021{
    10191022    Py_ssize_t self_size, other_size;
     
    10261029       buffer API.  Except that a comparison with Unicode is always an
    10271030       error, even if the comparison is for equality. */
     1031#ifdef Py_USING_UNICODE
    10281032    if (PyObject_IsInstance(self, (PyObject*)&PyUnicode_Type) ||
    10291033        PyObject_IsInstance(other, (PyObject*)&PyUnicode_Type)) {
     
    10371041        return Py_NotImplemented;
    10381042    }
     1043#endif
    10391044
    10401045    self_size = _getbuffer(self, &self_bytes);
     
    10901095
    10911096static void
    1092 bytes_dealloc(PyByteArrayObject *self)
    1093 {
    1094         if (self->ob_exports > 0) {
    1095                 PyErr_SetString(PyExc_SystemError,
     1097bytearray_dealloc(PyByteArrayObject *self)
     1098{
     1099    if (self->ob_exports > 0) {
     1100        PyErr_SetString(PyExc_SystemError,
    10961101                        "deallocated bytearray object has exported buffers");
    1097                 PyErr_Print();
    1098         }
     1102        PyErr_Print();
     1103    }
    10991104    if (self->ob_bytes != 0) {
    11001105        PyMem_Free(self->ob_bytes);
     
    11081113
    11091114#define STRINGLIB_CHAR char
    1110 #define STRINGLIB_CMP memcmp
    11111115#define STRINGLIB_LEN PyByteArray_GET_SIZE
    11121116#define STRINGLIB_STR PyByteArray_AS_STRING
    11131117#define STRINGLIB_NEW PyByteArray_FromStringAndSize
    1114 #define STRINGLIB_EMPTY nullbytes
     1118#define STRINGLIB_ISSPACE Py_ISSPACE
     1119#define STRINGLIB_ISLINEBREAK(x) ((x == '\n') || (x == '\r'))
    11151120#define STRINGLIB_CHECK_EXACT PyByteArray_CheckExact
    11161121#define STRINGLIB_MUTABLE 1
    1117 #define FROM_BYTEARRAY 1
    11181122
    11191123#include "stringlib/fastsearch.h"
     
    11211125#include "stringlib/find.h"
    11221126#include "stringlib/partition.h"
     1127#include "stringlib/split.h"
    11231128#include "stringlib/ctype.h"
    11241129#include "stringlib/transmogrify.h"
     
    11281133were copied from the old char* style string object. */
    11291134
    1130 Py_LOCAL_INLINE(void)
    1131 _adjust_indices(Py_ssize_t *start, Py_ssize_t *end, Py_ssize_t len)
    1132 {
    1133     if (*end > len)
    1134         *end = len;
    1135     else if (*end < 0)
    1136         *end += len;
    1137     if (*end < 0)
    1138         *end = 0;
    1139     if (*start < 0)
    1140         *start += len;
    1141     if (*start < 0)
    1142         *start = 0;
    1143 }
    1144 
     1135/* helper macro to fixup start/end slice values */
     1136#define ADJUST_INDICES(start, end, len)         \
     1137    if (end > len)                              \
     1138        end = len;                              \
     1139    else if (end < 0) {                         \
     1140        end += len;                             \
     1141        if (end < 0)                            \
     1142            end = 0;                            \
     1143    }                                           \
     1144    if (start < 0) {                            \
     1145        start += len;                           \
     1146        if (start < 0)                          \
     1147            start = 0;                          \
     1148    }
    11451149
    11461150Py_LOCAL_INLINE(Py_ssize_t)
    1147 bytes_find_internal(PyByteArrayObject *self, PyObject *args, int dir)
     1151bytearray_find_internal(PyByteArrayObject *self, PyObject *args, int dir)
    11481152{
    11491153    PyObject *subobj;
     
    11521156    Py_ssize_t res;
    11531157
    1154     if (!PyArg_ParseTuple(args, "O|O&O&:find/rfind/index/rindex", &subobj,
    1155         _PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end))
     1158    if (!stringlib_parse_args_finds("find/rfind/index/rindex",
     1159                                    args, &subobj, &start, &end))
    11561160        return -2;
    11571161    if (_getbuffer(subobj, &subbuf) < 0)
     
    11731177\n\
    11741178Return the lowest index in B where subsection sub is found,\n\
    1175 such that sub is contained within s[start,end].  Optional\n\
     1179such that sub is contained within B[start,end].  Optional\n\
    11761180arguments start and end are interpreted as in slice notation.\n\
    11771181\n\
     
    11791183
    11801184static PyObject *
    1181 bytes_find(PyByteArrayObject *self, PyObject *args)
    1182 {
    1183     Py_ssize_t result = bytes_find_internal(self, args, +1);
     1185bytearray_find(PyByteArrayObject *self, PyObject *args)
     1186{
     1187    Py_ssize_t result = bytearray_find_internal(self, args, +1);
    11841188    if (result == -2)
    11851189        return NULL;
     
    11951199
    11961200static PyObject *
    1197 bytes_count(PyByteArrayObject *self, PyObject *args)
     1201bytearray_count(PyByteArrayObject *self, PyObject *args)
    11981202{
    11991203    PyObject *sub_obj;
     
    12031207    PyObject *count_obj;
    12041208
    1205     if (!PyArg_ParseTuple(args, "O|O&O&:count", &sub_obj,
    1206         _PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end))
     1209    if (!stringlib_parse_args_finds("count", args, &sub_obj, &start, &end))
    12071210        return NULL;
    12081211
     
    12101213        return NULL;
    12111214
    1212     _adjust_indices(&start, &end, PyByteArray_GET_SIZE(self));
     1215    ADJUST_INDICES(start, end, PyByteArray_GET_SIZE(self));
    12131216
    12141217    count_obj = PyInt_FromSsize_t(
    1215         stringlib_count(str + start, end - start, vsub.buf, vsub.len)
     1218        stringlib_count(str + start, end - start, vsub.buf, vsub.len, PY_SSIZE_T_MAX)
    12161219        );
    12171220    PyBuffer_Release(&vsub);
     
    12261229
    12271230static PyObject *
    1228 bytes_index(PyByteArrayObject *self, PyObject *args)
    1229 {
    1230     Py_ssize_t result = bytes_find_internal(self, args, +1);
     1231bytearray_index(PyByteArrayObject *self, PyObject *args)
     1232{
     1233    Py_ssize_t result = bytearray_find_internal(self, args, +1);
    12311234    if (result == -2)
    12321235        return NULL;
     
    12441247\n\
    12451248Return the highest index in B where subsection sub is found,\n\
    1246 such that sub is contained within s[start,end].  Optional\n\
     1249such that sub is contained within B[start,end].  Optional\n\
    12471250arguments start and end are interpreted as in slice notation.\n\
    12481251\n\
     
    12501253
    12511254static PyObject *
    1252 bytes_rfind(PyByteArrayObject *self, PyObject *args)
    1253 {
    1254     Py_ssize_t result = bytes_find_internal(self, args, -1);
     1255bytearray_rfind(PyByteArrayObject *self, PyObject *args)
     1256{
     1257    Py_ssize_t result = bytearray_find_internal(self, args, -1);
    12551258    if (result == -2)
    12561259        return NULL;
     
    12651268
    12661269static PyObject *
    1267 bytes_rindex(PyByteArrayObject *self, PyObject *args)
    1268 {
    1269     Py_ssize_t result = bytes_find_internal(self, args, -1);
     1270bytearray_rindex(PyByteArrayObject *self, PyObject *args)
     1271{
     1272    Py_ssize_t result = bytearray_find_internal(self, args, -1);
    12701273    if (result == -2)
    12711274        return NULL;
     
    12801283
    12811284static int
    1282 bytes_contains(PyObject *self, PyObject *arg)
     1285bytearray_contains(PyObject *self, PyObject *arg)
    12831286{
    12841287    Py_ssize_t ival = PyNumber_AsSsize_t(arg, PyExc_ValueError);
     
    13081311 */
    13091312Py_LOCAL(int)
    1310 _bytes_tailmatch(PyByteArrayObject *self, PyObject *substr, Py_ssize_t start,
     1313_bytearray_tailmatch(PyByteArrayObject *self, PyObject *substr, Py_ssize_t start,
    13111314                 Py_ssize_t end, int direction)
    13121315{
     
    13211324        return -1;
    13221325
    1323     _adjust_indices(&start, &end, len);
     1326    ADJUST_INDICES(start, end, len);
    13241327
    13251328    if (direction < 0) {
     
    13551358
    13561359static PyObject *
    1357 bytes_startswith(PyByteArrayObject *self, PyObject *args)
     1360bytearray_startswith(PyByteArrayObject *self, PyObject *args)
    13581361{
    13591362    Py_ssize_t start = 0;
     
    13621365    int result;
    13631366
    1364     if (!PyArg_ParseTuple(args, "O|O&O&:startswith", &subobj,
    1365         _PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end))
     1367    if (!stringlib_parse_args_finds("startswith", args, &subobj, &start, &end))
    13661368        return NULL;
    13671369    if (PyTuple_Check(subobj)) {
    13681370        Py_ssize_t i;
    13691371        for (i = 0; i < PyTuple_GET_SIZE(subobj); i++) {
    1370             result = _bytes_tailmatch(self,
     1372            result = _bytearray_tailmatch(self,
    13711373                                      PyTuple_GET_ITEM(subobj, i),
    13721374                                      start, end, -1);
     
    13791381        Py_RETURN_FALSE;
    13801382    }
    1381     result = _bytes_tailmatch(self, subobj, start, end, -1);
     1383    result = _bytearray_tailmatch(self, subobj, start, end, -1);
    13821384    if (result == -1)
    13831385        return NULL;
     
    13951397
    13961398static PyObject *
    1397 bytes_endswith(PyByteArrayObject *self, PyObject *args)
     1399bytearray_endswith(PyByteArrayObject *self, PyObject *args)
    13981400{
    13991401    Py_ssize_t start = 0;
     
    14021404    int result;
    14031405
    1404     if (!PyArg_ParseTuple(args, "O|O&O&:endswith", &subobj,
    1405         _PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end))
     1406    if (!stringlib_parse_args_finds("endswith", args, &subobj, &start, &end))
    14061407        return NULL;
    14071408    if (PyTuple_Check(subobj)) {
    14081409        Py_ssize_t i;
    14091410        for (i = 0; i < PyTuple_GET_SIZE(subobj); i++) {
    1410             result = _bytes_tailmatch(self,
     1411            result = _bytearray_tailmatch(self,
    14111412                                      PyTuple_GET_ITEM(subobj, i),
    14121413                                      start, end, +1);
     
    14191420        Py_RETURN_FALSE;
    14201421    }
    1421     result = _bytes_tailmatch(self, subobj, start, end, +1);
     1422    result = _bytearray_tailmatch(self, subobj, start, end, +1);
    14221423    if (result == -1)
    14231424        return NULL;
     
    14361437
    14371438static PyObject *
    1438 bytes_translate(PyByteArrayObject *self, PyObject *args)
     1439bytearray_translate(PyByteArrayObject *self, PyObject *args)
    14391440{
    14401441    register char *input, *output;
     
    14441445    const char *output_start;
    14451446    Py_ssize_t inlen;
    1446     PyObject *result;
     1447    PyObject *result = NULL;
    14471448    int trans_table[256];
    1448     PyObject *tableobj, *delobj = NULL;
     1449    PyObject *tableobj = NULL, *delobj = NULL;
    14491450    Py_buffer vtable, vdel;
    14501451
     
    14531454          return NULL;
    14541455
    1455     if (_getbuffer(tableobj, &vtable) < 0)
    1456         return NULL;
    1457 
    1458     if (vtable.len != 256) {
    1459         PyErr_SetString(PyExc_ValueError,
    1460                         "translation table must be 256 characters long");
    1461         PyBuffer_Release(&vtable);
    1462         return NULL;
     1456    if (tableobj == Py_None) {
     1457        table = NULL;
     1458        tableobj = NULL;
     1459    } else if (_getbuffer(tableobj, &vtable) < 0) {
     1460        return NULL;
     1461    } else {
     1462        if (vtable.len != 256) {
     1463            PyErr_SetString(PyExc_ValueError,
     1464                            "translation table must be 256 characters long");
     1465            PyBuffer_Release(&vtable);
     1466            return NULL;
     1467        }
     1468        table = (const char*)vtable.buf;
    14631469    }
    14641470
    14651471    if (delobj != NULL) {
    14661472        if (_getbuffer(delobj, &vdel) < 0) {
    1467             PyBuffer_Release(&vtable);
    1468             return NULL;
     1473            if (tableobj != NULL)
     1474                PyBuffer_Release(&vtable);
     1475            return NULL;
    14691476        }
    14701477    }
     
    14741481    }
    14751482
    1476     table = (const char *)vtable.buf;
    14771483    inlen = PyByteArray_GET_SIZE(input_obj);
    14781484    result = PyByteArray_FromStringAndSize((char *)NULL, inlen);
     
    14821488    input = PyByteArray_AS_STRING(input_obj);
    14831489
    1484     if (vdel.len == 0) {
     1490    if (vdel.len == 0 && table != NULL) {
    14851491        /* If no deletions are required, use faster code */
    14861492        for (i = inlen; --i >= 0; ) {
     
    14901496        goto done;
    14911497    }
    1492    
    1493     for (i = 0; i < 256; i++)
    1494         trans_table[i] = Py_CHARMASK(table[i]);
     1498
     1499    if (table == NULL) {
     1500        for (i = 0; i < 256; i++)
     1501            trans_table[i] = Py_CHARMASK(i);
     1502    } else {
     1503        for (i = 0; i < 256; i++)
     1504            trans_table[i] = Py_CHARMASK(table[i]);
     1505    }
    14951506
    14961507    for (i = 0; i < vdel.len; i++)
     
    15081519
    15091520done:
    1510     PyBuffer_Release(&vtable);
     1521    if (tableobj != NULL)
     1522        PyBuffer_Release(&vtable);
    15111523    if (delobj != NULL)
    15121524        PyBuffer_Release(&vdel);
     
    15151527
    15161528
    1517 #define FORWARD 1
    1518 #define REVERSE -1
    1519 
    15201529/* find and count characters and substrings */
    15211530
    15221531#define findchar(target, target_len, c)                         \
    15231532  ((char *)memchr((const void *)(target), c, target_len))
    1524 
    1525 /* Don't call if length < 2 */
    1526 #define Py_STRING_MATCH(target, offset, pattern, length)        \
    1527   (target[offset] == pattern[0] &&                              \
    1528    target[offset+length-1] == pattern[length-1] &&              \
    1529    !memcmp(target+offset+1, pattern+1, length-2) )
    15301533
    15311534
     
    15511554            break;
    15521555        start += 1;
    1553     }
    1554     return count;
    1555 }
    1556 
    1557 Py_LOCAL(Py_ssize_t)
    1558 findstring(const char *target, Py_ssize_t target_len,
    1559            const char *pattern, Py_ssize_t pattern_len,
    1560            Py_ssize_t start,
    1561            Py_ssize_t end,
    1562            int direction)
    1563 {
    1564     if (start < 0) {
    1565         start += target_len;
    1566         if (start < 0)
    1567             start = 0;
    1568     }
    1569     if (end > target_len) {
    1570         end = target_len;
    1571     } else if (end < 0) {
    1572         end += target_len;
    1573         if (end < 0)
    1574             end = 0;
    1575     }
    1576 
    1577     /* zero-length substrings always match at the first attempt */
    1578     if (pattern_len == 0)
    1579         return (direction > 0) ? start : end;
    1580 
    1581     end -= pattern_len;
    1582 
    1583     if (direction < 0) {
    1584         for (; end >= start; end--)
    1585             if (Py_STRING_MATCH(target, end, pattern, pattern_len))
    1586                 return end;
    1587     } else {
    1588         for (; start <= end; start++)
    1589             if (Py_STRING_MATCH(target, start, pattern, pattern_len))
    1590                 return start;
    1591     }
    1592     return -1;
    1593 }
    1594 
    1595 Py_LOCAL_INLINE(Py_ssize_t)
    1596 countstring(const char *target, Py_ssize_t target_len,
    1597             const char *pattern, Py_ssize_t pattern_len,
    1598             Py_ssize_t start,
    1599             Py_ssize_t end,
    1600             int direction, Py_ssize_t maxcount)
    1601 {
    1602     Py_ssize_t count=0;
    1603 
    1604     if (start < 0) {
    1605         start += target_len;
    1606         if (start < 0)
    1607             start = 0;
    1608     }
    1609     if (end > target_len) {
    1610         end = target_len;
    1611     } else if (end < 0) {
    1612         end += target_len;
    1613         if (end < 0)
    1614             end = 0;
    1615     }
    1616 
    1617     /* zero-length substrings match everywhere */
    1618     if (pattern_len == 0 || maxcount == 0) {
    1619         if (target_len+1 < maxcount)
    1620             return target_len+1;
    1621         return maxcount;
    1622     }
    1623 
    1624     end -= pattern_len;
    1625     if (direction < 0) {
    1626         for (; (end >= start); end--)
    1627             if (Py_STRING_MATCH(target, end, pattern, pattern_len)) {
    1628                 count++;
    1629                 if (--maxcount <= 0) break;
    1630                 end -= pattern_len-1;
    1631             }
    1632     } else {
    1633         for (; (start <= end); start++)
    1634             if (Py_STRING_MATCH(target, start, pattern, pattern_len)) {
    1635                 count++;
    1636                 if (--maxcount <= 0)
    1637                     break;
    1638                 start += pattern_len-1;
    1639             }
    16401556    }
    16411557    return count;
     
    17631679    self_s = PyByteArray_AS_STRING(self);
    17641680
    1765     count = countstring(self_s, self_len,
    1766                         from_s, from_len,
    1767                         0, self_len, 1,
    1768                         maxcount);
     1681    count = stringlib_count(self_s, self_len,
     1682                            from_s, from_len,
     1683                            maxcount);
    17691684
    17701685    if (count == 0) {
     
    17851700    end = self_s + self_len;
    17861701    while (count-- > 0) {
    1787         offset = findstring(start, end-start,
    1788                             from_s, from_len,
    1789                             0, end-start, FORWARD);
     1702        offset = stringlib_find(start, end-start,
     1703                                from_s, from_len,
     1704                                0);
    17901705        if (offset == -1)
    17911706            break;
     
    18071722                                  Py_ssize_t maxcount)
    18081723{
    1809         char *self_s, *result_s, *start, *end, *next;
    1810         Py_ssize_t self_len;
    1811         PyByteArrayObject *result;
    1812 
    1813         /* The result string will be the same size */
    1814         self_s = PyByteArray_AS_STRING(self);
    1815         self_len = PyByteArray_GET_SIZE(self);
    1816 
    1817         next = findchar(self_s, self_len, from_c);
    1818 
    1819         if (next == NULL) {
    1820                 /* No matches; return the original bytes */
    1821                 return return_self(self);
    1822         }
    1823 
    1824         /* Need to make a new bytes */
    1825         result = (PyByteArrayObject *) PyByteArray_FromStringAndSize(NULL, self_len);
    1826         if (result == NULL)
    1827                 return NULL;
    1828         result_s = PyByteArray_AS_STRING(result);
    1829         Py_MEMCPY(result_s, self_s, self_len);
    1830 
    1831         /* change everything in-place, starting with this one */
    1832         start =  result_s + (next-self_s);
    1833         *start = to_c;
    1834         start++;
    1835         end = result_s + self_len;
    1836 
    1837         while (--maxcount > 0) {
    1838                 next = findchar(start, end-start, from_c);
    1839                 if (next == NULL)
    1840                         break;
    1841                 *next = to_c;
    1842                 start = next+1;
    1843         }
    1844 
    1845         return result;
     1724    char *self_s, *result_s, *start, *end, *next;
     1725    Py_ssize_t self_len;
     1726    PyByteArrayObject *result;
     1727
     1728    /* The result string will be the same size */
     1729    self_s = PyByteArray_AS_STRING(self);
     1730    self_len = PyByteArray_GET_SIZE(self);
     1731
     1732    next = findchar(self_s, self_len, from_c);
     1733
     1734    if (next == NULL) {
     1735        /* No matches; return the original bytes */
     1736        return return_self(self);
     1737    }
     1738
     1739    /* Need to make a new bytes */
     1740    result = (PyByteArrayObject *) PyByteArray_FromStringAndSize(NULL, self_len);
     1741    if (result == NULL)
     1742        return NULL;
     1743    result_s = PyByteArray_AS_STRING(result);
     1744    Py_MEMCPY(result_s, self_s, self_len);
     1745
     1746    /* change everything in-place, starting with this one */
     1747    start =  result_s + (next-self_s);
     1748    *start = to_c;
     1749    start++;
     1750    end = result_s + self_len;
     1751
     1752    while (--maxcount > 0) {
     1753        next = findchar(start, end-start, from_c);
     1754        if (next == NULL)
     1755            break;
     1756        *next = to_c;
     1757        start = next+1;
     1758    }
     1759
     1760    return result;
    18461761}
    18471762
     
    18631778    self_len = PyByteArray_GET_SIZE(self);
    18641779
    1865     offset = findstring(self_s, self_len,
    1866                         from_s, from_len,
    1867                         0, self_len, FORWARD);
     1780    offset = stringlib_find(self_s, self_len,
     1781                            from_s, from_len,
     1782                            0);
    18681783    if (offset == -1) {
    18691784        /* No matches; return the original bytes */
     
    18851800
    18861801    while ( --maxcount > 0) {
    1887         offset = findstring(start, end-start,
    1888                             from_s, from_len,
    1889                             0, end-start, FORWARD);
     1802        offset = stringlib_find(start, end-start,
     1803                                from_s, from_len,
     1804                                0);
    18901805        if (offset==-1)
    18911806            break;
     
    19801895    self_len = PyByteArray_GET_SIZE(self);
    19811896
    1982     count = countstring(self_s, self_len,
    1983                         from_s, from_len,
    1984                         0, self_len, FORWARD, maxcount);
     1897    count = stringlib_count(self_s, self_len,
     1898                            from_s, from_len,
     1899                            maxcount);
     1900
    19851901    if (count == 0) {
    19861902        /* no matches, return unchanged */
     
    20091925    end = self_s + self_len;
    20101926    while (count-- > 0) {
    2011         offset = findstring(start, end-start,
    2012                             from_s, from_len,
    2013                             0, end-start, FORWARD);
     1927        offset = stringlib_find(start, end-start,
     1928                                from_s, from_len,
     1929                                0);
    20141930        if (offset == -1)
    20151931            break;
     
    21152031
    21162032static PyObject *
    2117 bytes_replace(PyByteArrayObject *self, PyObject *args)
     2033bytearray_replace(PyByteArrayObject *self, PyObject *args)
    21182034{
    21192035    Py_ssize_t count = -1;
     
    21382054    PyBuffer_Release(&vto);
    21392055    return res;
    2140 }
    2141 
    2142 
    2143 /* Overallocate the initial list to reduce the number of reallocs for small
    2144    split sizes.  Eg, "A A A A A A A A A A".split() (10 elements) has three
    2145    resizes, to sizes 4, 8, then 16.  Most observed string splits are for human
    2146    text (roughly 11 words per line) and field delimited data (usually 1-10
    2147    fields).  For large strings the split algorithms are bandwidth limited
    2148    so increasing the preallocation likely will not improve things.*/
    2149 
    2150 #define MAX_PREALLOC 12
    2151 
    2152 /* 5 splits gives 6 elements */
    2153 #define PREALLOC_SIZE(maxsplit) \
    2154     (maxsplit >= MAX_PREALLOC ? MAX_PREALLOC : maxsplit+1)
    2155 
    2156 #define SPLIT_APPEND(data, left, right)                         \
    2157     str = PyByteArray_FromStringAndSize((data) + (left),       \
    2158                                      (right) - (left));     \
    2159     if (str == NULL)                                        \
    2160         goto onError;                                   \
    2161     if (PyList_Append(list, str)) {                         \
    2162         Py_DECREF(str);                                 \
    2163         goto onError;                                   \
    2164     }                                                       \
    2165     else                                                    \
    2166         Py_DECREF(str);
    2167 
    2168 #define SPLIT_ADD(data, left, right) {                          \
    2169     str = PyByteArray_FromStringAndSize((data) + (left),       \
    2170                                      (right) - (left));     \
    2171     if (str == NULL)                                        \
    2172         goto onError;                                   \
    2173     if (count < MAX_PREALLOC) {                             \
    2174         PyList_SET_ITEM(list, count, str);              \
    2175     } else {                                                \
    2176         if (PyList_Append(list, str)) {                 \
    2177             Py_DECREF(str);                         \
    2178             goto onError;                           \
    2179         }                                               \
    2180         else                                            \
    2181             Py_DECREF(str);                         \
    2182     }                                                       \
    2183     count++; }
    2184 
    2185 /* Always force the list to the expected size. */
    2186 #define FIX_PREALLOC_SIZE(list) Py_SIZE(list) = count
    2187 
    2188 
    2189 Py_LOCAL_INLINE(PyObject *)
    2190 split_char(const char *s, Py_ssize_t len, char ch, Py_ssize_t maxcount)
    2191 {
    2192     register Py_ssize_t i, j, count = 0;
    2193     PyObject *str;
    2194     PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
    2195 
    2196     if (list == NULL)
    2197         return NULL;
    2198 
    2199     i = j = 0;
    2200     while ((j < len) && (maxcount-- > 0)) {
    2201         for(; j < len; j++) {
    2202             /* I found that using memchr makes no difference */
    2203             if (s[j] == ch) {
    2204                 SPLIT_ADD(s, i, j);
    2205                 i = j = j + 1;
    2206                 break;
    2207             }
    2208         }
    2209     }
    2210     if (i <= len) {
    2211         SPLIT_ADD(s, i, len);
    2212     }
    2213     FIX_PREALLOC_SIZE(list);
    2214     return list;
    2215 
    2216   onError:
    2217     Py_DECREF(list);
    2218     return NULL;
    2219 }
    2220 
    2221 
    2222 Py_LOCAL_INLINE(PyObject *)
    2223 split_whitespace(const char *s, Py_ssize_t len, Py_ssize_t maxcount)
    2224 {
    2225     register Py_ssize_t i, j, count = 0;
    2226     PyObject *str;
    2227     PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
    2228 
    2229     if (list == NULL)
    2230         return NULL;
    2231 
    2232     for (i = j = 0; i < len; ) {
    2233         /* find a token */
    2234         while (i < len && ISSPACE(s[i]))
    2235             i++;
    2236         j = i;
    2237         while (i < len && !ISSPACE(s[i]))
    2238             i++;
    2239         if (j < i) {
    2240             if (maxcount-- <= 0)
    2241                 break;
    2242             SPLIT_ADD(s, j, i);
    2243             while (i < len && ISSPACE(s[i]))
    2244                 i++;
    2245             j = i;
    2246         }
    2247     }
    2248     if (j < len) {
    2249         SPLIT_ADD(s, j, len);
    2250     }
    2251     FIX_PREALLOC_SIZE(list);
    2252     return list;
    2253 
    2254   onError:
    2255     Py_DECREF(list);
    2256     return NULL;
    22572056}
    22582057
     
    22662065
    22672066static PyObject *
    2268 bytes_split(PyByteArrayObject *self, PyObject *args)
    2269 {
    2270     Py_ssize_t len = PyByteArray_GET_SIZE(self), n, i, j;
    2271     Py_ssize_t maxsplit = -1, count = 0;
     2067bytearray_split(PyByteArrayObject *self, PyObject *args)
     2068{
     2069    Py_ssize_t len = PyByteArray_GET_SIZE(self), n;
     2070    Py_ssize_t maxsplit = -1;
    22722071    const char *s = PyByteArray_AS_STRING(self), *sub;
    2273     PyObject *list, *str, *subobj = Py_None;
     2072    PyObject *list, *subobj = Py_None;
    22742073    Py_buffer vsub;
    2275 #ifdef USE_FAST
    2276     Py_ssize_t pos;
    2277 #endif
    22782074
    22792075    if (!PyArg_ParseTuple(args, "|On:split", &subobj, &maxsplit))
     
    22832079
    22842080    if (subobj == Py_None)
    2285         return split_whitespace(s, len, maxsplit);
     2081        return stringlib_split_whitespace((PyObject*) self, s, len, maxsplit);
    22862082
    22872083    if (_getbuffer(subobj, &vsub) < 0)
     
    22902086    n = vsub.len;
    22912087
    2292     if (n == 0) {
    2293         PyErr_SetString(PyExc_ValueError, "empty separator");
    2294         PyBuffer_Release(&vsub);
    2295         return NULL;
    2296     }
    2297     if (n == 1) {
    2298         list = split_char(s, len, sub[0], maxsplit);
    2299         PyBuffer_Release(&vsub);
    2300         return list;
    2301     }
    2302 
    2303     list = PyList_New(PREALLOC_SIZE(maxsplit));
    2304     if (list == NULL) {
    2305         PyBuffer_Release(&vsub);
    2306         return NULL;
    2307     }
    2308 
    2309 #ifdef USE_FAST
    2310     i = j = 0;
    2311     while (maxsplit-- > 0) {
    2312         pos = fastsearch(s+i, len-i, sub, n, FAST_SEARCH);
    2313         if (pos < 0)
    2314                 break;
    2315         j = i+pos;
    2316         SPLIT_ADD(s, i, j);
    2317         i = j + n;
    2318     }
    2319 #else
    2320     i = j = 0;
    2321     while ((j+n <= len) && (maxsplit-- > 0)) {
    2322         for (; j+n <= len; j++) {
    2323             if (Py_STRING_MATCH(s, j, sub, n)) {
    2324                 SPLIT_ADD(s, i, j);
    2325                 i = j = j + n;
    2326                 break;
    2327             }
    2328         }
    2329     }
    2330 #endif
    2331     SPLIT_ADD(s, i, len);
    2332     FIX_PREALLOC_SIZE(list);
     2088    list = stringlib_split(
     2089        (PyObject*) self, s, len, sub, n, maxsplit
     2090        );
    23332091    PyBuffer_Release(&vsub);
    23342092    return list;
    2335 
    2336   onError:
    2337     Py_DECREF(list);
    2338     PyBuffer_Release(&vsub);
    2339     return NULL;
    2340 }
    2341 
    2342 /* stringlib's partition shares nullbytes in some cases.
    2343    undo this, we don't want the nullbytes to be shared. */
    2344 static PyObject *
    2345 make_nullbytes_unique(PyObject *result)
    2346 {
    2347     if (result != NULL) {
    2348         int i;
    2349         assert(PyTuple_Check(result));
    2350         assert(PyTuple_GET_SIZE(result) == 3);
    2351         for (i = 0; i < 3; i++) {
    2352             if (PyTuple_GET_ITEM(result, i) == (PyObject *)nullbytes) {
    2353                 PyObject *new = PyByteArray_FromStringAndSize(NULL, 0);
    2354                 if (new == NULL) {
    2355                     Py_DECREF(result);
    2356                     result = NULL;
    2357                     break;
    2358                 }
    2359                 Py_DECREF(nullbytes);
    2360                 PyTuple_SET_ITEM(result, i, new);
    2361             }
    2362         }
    2363     }
    2364     return result;
    23652093}
    23662094
     
    23732101
    23742102static PyObject *
    2375 bytes_partition(PyByteArrayObject *self, PyObject *sep_obj)
     2103bytearray_partition(PyByteArrayObject *self, PyObject *sep_obj)
    23762104{
    23772105    PyObject *bytesep, *result;
     
    23892117
    23902118    Py_DECREF(bytesep);
    2391     return make_nullbytes_unique(result);
     2119    return result;
    23922120}
    23932121
     
    24012129
    24022130static PyObject *
    2403 bytes_rpartition(PyByteArrayObject *self, PyObject *sep_obj)
     2131bytearray_rpartition(PyByteArrayObject *self, PyObject *sep_obj)
    24042132{
    24052133    PyObject *bytesep, *result;
     
    24172145
    24182146    Py_DECREF(bytesep);
    2419     return make_nullbytes_unique(result);
    2420 }
    2421 
    2422 Py_LOCAL_INLINE(PyObject *)
    2423 rsplit_char(const char *s, Py_ssize_t len, char ch, Py_ssize_t maxcount)
    2424 {
    2425     register Py_ssize_t i, j, count=0;
    2426     PyObject *str;
    2427     PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
    2428 
    2429     if (list == NULL)
    2430         return NULL;
    2431 
    2432     i = j = len - 1;
    2433     while ((i >= 0) && (maxcount-- > 0)) {
    2434         for (; i >= 0; i--) {
    2435             if (s[i] == ch) {
    2436                 SPLIT_ADD(s, i + 1, j + 1);
    2437                 j = i = i - 1;
    2438                 break;
    2439             }
    2440         }
    2441     }
    2442     if (j >= -1) {
    2443         SPLIT_ADD(s, 0, j + 1);
    2444     }
    2445     FIX_PREALLOC_SIZE(list);
    2446     if (PyList_Reverse(list) < 0)
    2447         goto onError;
    2448 
    2449     return list;
    2450 
    2451   onError:
    2452     Py_DECREF(list);
    2453     return NULL;
    2454 }
    2455 
    2456 Py_LOCAL_INLINE(PyObject *)
    2457 rsplit_whitespace(const char *s, Py_ssize_t len, Py_ssize_t maxcount)
    2458 {
    2459     register Py_ssize_t i, j, count = 0;
    2460     PyObject *str;
    2461     PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
    2462 
    2463     if (list == NULL)
    2464         return NULL;
    2465 
    2466     for (i = j = len - 1; i >= 0; ) {
    2467         /* find a token */
    2468         while (i >= 0 && ISSPACE(s[i]))
    2469             i--;
    2470         j = i;
    2471         while (i >= 0 && !ISSPACE(s[i]))
    2472             i--;
    2473         if (j > i) {
    2474             if (maxcount-- <= 0)
    2475                 break;
    2476             SPLIT_ADD(s, i + 1, j + 1);
    2477             while (i >= 0 && ISSPACE(s[i]))
    2478                 i--;
    2479             j = i;
    2480         }
    2481     }
    2482     if (j >= 0) {
    2483         SPLIT_ADD(s, 0, j + 1);
    2484     }
    2485     FIX_PREALLOC_SIZE(list);
    2486     if (PyList_Reverse(list) < 0)
    2487         goto onError;
    2488 
    2489     return list;
    2490 
    2491   onError:
    2492     Py_DECREF(list);
    2493     return NULL;
     2147    return result;
    24942148}
    24952149
     
    25042158
    25052159static PyObject *
    2506 bytes_rsplit(PyByteArrayObject *self, PyObject *args)
    2507 {
    2508     Py_ssize_t len = PyByteArray_GET_SIZE(self), n, i, j;
    2509     Py_ssize_t maxsplit = -1, count = 0;
     2160bytearray_rsplit(PyByteArrayObject *self, PyObject *args)
     2161{
     2162    Py_ssize_t len = PyByteArray_GET_SIZE(self), n;
     2163    Py_ssize_t maxsplit = -1;
    25102164    const char *s = PyByteArray_AS_STRING(self), *sub;
    2511     PyObject *list, *str, *subobj = Py_None;
     2165    PyObject *list, *subobj = Py_None;
    25122166    Py_buffer vsub;
    25132167
     
    25182172
    25192173    if (subobj == Py_None)
    2520         return rsplit_whitespace(s, len, maxsplit);
     2174        return stringlib_rsplit_whitespace((PyObject*) self, s, len, maxsplit);
    25212175
    25222176    if (_getbuffer(subobj, &vsub) < 0)
     
    25252179    n = vsub.len;
    25262180
    2527     if (n == 0) {
    2528         PyErr_SetString(PyExc_ValueError, "empty separator");
    2529         PyBuffer_Release(&vsub);
    2530         return NULL;
    2531     }
    2532     else if (n == 1) {
    2533         list = rsplit_char(s, len, sub[0], maxsplit);
    2534         PyBuffer_Release(&vsub);
    2535         return list;
    2536     }
    2537 
    2538     list = PyList_New(PREALLOC_SIZE(maxsplit));
    2539     if (list == NULL) {
    2540         PyBuffer_Release(&vsub);
    2541         return NULL;
    2542     }
    2543 
    2544     j = len;
    2545     i = j - n;
    2546 
    2547     while ( (i >= 0) && (maxsplit-- > 0) ) {
    2548         for (; i>=0; i--) {
    2549             if (Py_STRING_MATCH(s, i, sub, n)) {
    2550                 SPLIT_ADD(s, i + n, j);
    2551                 j = i;
    2552                 i -= n;
    2553                 break;
    2554             }
    2555         }
    2556     }
    2557     SPLIT_ADD(s, 0, j);
    2558     FIX_PREALLOC_SIZE(list);
    2559     if (PyList_Reverse(list) < 0)
    2560         goto onError;
     2181    list = stringlib_rsplit(
     2182        (PyObject*) self, s, len, sub, n, maxsplit
     2183        );
    25612184    PyBuffer_Release(&vsub);
    25622185    return list;
    2563 
    2564 onError:
    2565     Py_DECREF(list);
    2566     PyBuffer_Release(&vsub);
    2567     return NULL;
    25682186}
    25692187
     
    25732191Reverse the order of the values in B in place.");
    25742192static PyObject *
    2575 bytes_reverse(PyByteArrayObject *self, PyObject *unused)
     2193bytearray_reverse(PyByteArrayObject *self, PyObject *unused)
    25762194{
    25772195    char swap, *head, *tail;
     
    25952213Insert a single item into the bytearray before the given index.");
    25962214static PyObject *
    2597 bytes_insert(PyByteArrayObject *self, PyObject *args)
     2215bytearray_insert(PyByteArrayObject *self, PyObject *args)
    25982216{
    25992217    PyObject *value;
     
    26322250Append a single item to the end of B.");
    26332251static PyObject *
    2634 bytes_append(PyByteArrayObject *self, PyObject *arg)
     2252bytearray_append(PyByteArrayObject *self, PyObject *arg)
    26352253{
    26362254    int value;
     
    26582276end of B.");
    26592277static PyObject *
    2660 bytes_extend(PyByteArrayObject *self, PyObject *arg)
    2661 {
    2662     PyObject *it, *item, *bytes_obj;
     2278bytearray_extend(PyByteArrayObject *self, PyObject *arg)
     2279{
     2280    PyObject *it, *item, *bytearray_obj;
    26632281    Py_ssize_t buf_size = 0, len = 0;
    26642282    int value;
    26652283    char *buf;
    26662284
    2667     /* bytes_setslice code only accepts something supporting PEP 3118. */
     2285    /* bytearray_setslice code only accepts something supporting PEP 3118. */
    26682286    if (PyObject_CheckBuffer(arg)) {
    2669         if (bytes_setslice(self, Py_SIZE(self), Py_SIZE(self), arg) == -1)
     2287        if (bytearray_setslice(self, Py_SIZE(self), Py_SIZE(self), arg) == -1)
    26702288            return NULL;
    26712289
     
    26772295        return NULL;
    26782296
    2679     /* Try to determine the length of the argument. 32 is abitrary. */
     2297    /* Try to determine the length of the argument. 32 is arbitrary. */
    26802298    buf_size = _PyObject_LengthHint(arg, 32);
    26812299    if (buf_size == -1) {
     
    26842302    }
    26852303
    2686     bytes_obj = PyByteArray_FromStringAndSize(NULL, buf_size);
    2687     if (bytes_obj == NULL)
    2688         return NULL;
    2689     buf = PyByteArray_AS_STRING(bytes_obj);
     2304    bytearray_obj = PyByteArray_FromStringAndSize(NULL, buf_size);
     2305    if (bytearray_obj == NULL) {
     2306        Py_DECREF(it);
     2307        return NULL;
     2308    }
     2309    buf = PyByteArray_AS_STRING(bytearray_obj);
    26902310
    26912311    while ((item = PyIter_Next(it)) != NULL) {
     
    26932313            Py_DECREF(item);
    26942314            Py_DECREF(it);
    2695             Py_DECREF(bytes_obj);
     2315            Py_DECREF(bytearray_obj);
    26962316            return NULL;
    26972317        }
     
    27012321        if (len >= buf_size) {
    27022322            buf_size = len + (len >> 1) + 1;
    2703             if (PyByteArray_Resize((PyObject *)bytes_obj, buf_size) < 0) {
     2323            if (PyByteArray_Resize((PyObject *)bytearray_obj, buf_size) < 0) {
    27042324                Py_DECREF(it);
    2705                 Py_DECREF(bytes_obj);
     2325                Py_DECREF(bytearray_obj);
    27062326                return NULL;
    27072327            }
    27082328            /* Recompute the `buf' pointer, since the resizing operation may
    27092329               have invalidated it. */
    2710             buf = PyByteArray_AS_STRING(bytes_obj);
     2330            buf = PyByteArray_AS_STRING(bytearray_obj);
    27112331        }
    27122332    }
     
    27142334
    27152335    /* Resize down to exact size. */
    2716     if (PyByteArray_Resize((PyObject *)bytes_obj, len) < 0) {
    2717         Py_DECREF(bytes_obj);
    2718         return NULL;
    2719     }
    2720 
    2721     if (bytes_setslice(self, Py_SIZE(self), Py_SIZE(self), bytes_obj) == -1)
    2722         return NULL;
    2723     Py_DECREF(bytes_obj);
     2336    if (PyByteArray_Resize((PyObject *)bytearray_obj, len) < 0) {
     2337        Py_DECREF(bytearray_obj);
     2338        return NULL;
     2339    }
     2340
     2341    if (bytearray_setslice(self, Py_SIZE(self), Py_SIZE(self), bytearray_obj) == -1) {
     2342        Py_DECREF(bytearray_obj);
     2343        return NULL;
     2344    }
     2345    Py_DECREF(bytearray_obj);
    27242346
    27252347    Py_RETURN_NONE;
     
    27322354argument is given, will pop the last value.");
    27332355static PyObject *
    2734 bytes_pop(PyByteArrayObject *self, PyObject *args)
     2356bytearray_pop(PyByteArrayObject *self, PyObject *args)
    27352357{
    27362358    int value;
     
    27412363
    27422364    if (n == 0) {
    2743         PyErr_SetString(PyExc_OverflowError,
    2744                         "cannot pop an empty bytearray");
     2365        PyErr_SetString(PyExc_IndexError,
     2366                        "pop from empty bytearray");
    27452367        return NULL;
    27462368    }
     
    27672389Remove the first occurance of a value in B.");
    27682390static PyObject *
    2769 bytes_remove(PyByteArrayObject *self, PyObject *arg)
     2391bytearray_remove(PyByteArrayObject *self, PyObject *arg)
    27702392{
    27712393    int value;
     
    28212443If the argument is omitted, strip ASCII whitespace.");
    28222444static PyObject *
    2823 bytes_strip(PyByteArrayObject *self, PyObject *args)
     2445bytearray_strip(PyByteArrayObject *self, PyObject *args)
    28242446{
    28252447    Py_ssize_t left, right, mysize, argsize;
     
    28572479If the argument is omitted, strip leading ASCII whitespace.");
    28582480static PyObject *
    2859 bytes_lstrip(PyByteArrayObject *self, PyObject *args)
     2481bytearray_lstrip(PyByteArrayObject *self, PyObject *args)
    28602482{
    28612483    Py_ssize_t left, right, mysize, argsize;
     
    28902512If the argument is omitted, strip trailing ASCII whitespace.");
    28912513static PyObject *
    2892 bytes_rstrip(PyByteArrayObject *self, PyObject *args)
     2514bytearray_rstrip(PyByteArrayObject *self, PyObject *args)
    28932515{
    28942516    Py_ssize_t left, right, mysize, argsize;
     
    29282550
    29292551static PyObject *
    2930 bytes_decode(PyObject *self, PyObject *args)
     2552bytearray_decode(PyObject *self, PyObject *args, PyObject *kwargs)
    29312553{
    29322554    const char *encoding = NULL;
    29332555    const char *errors = NULL;
    2934 
    2935     if (!PyArg_ParseTuple(args, "|ss:decode", &encoding, &errors))
    2936         return NULL;
    2937     if (encoding == NULL)
     2556    static char *kwlist[] = {"encoding", "errors", 0};
     2557
     2558    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|ss:decode", kwlist, &encoding, &errors))
     2559        return NULL;
     2560    if (encoding == NULL) {
     2561#ifdef Py_USING_UNICODE
    29382562        encoding = PyUnicode_GetDefaultEncoding();
     2563#else
     2564        PyErr_SetString(PyExc_ValueError, "no encoding specified");
     2565        return NULL;
     2566#endif
     2567    }
    29392568    return PyCodec_Decode(self, encoding, errors);
    29402569}
     
    29462575
    29472576static PyObject *
    2948 bytes_alloc(PyByteArrayObject *self)
     2577bytearray_alloc(PyByteArrayObject *self)
    29492578{
    29502579    return PyInt_FromSsize_t(self->ob_alloc);
     
    29572586
    29582587static PyObject *
    2959 bytes_join(PyByteArrayObject *self, PyObject *it)
     2588bytearray_join(PyByteArrayObject *self, PyObject *it)
    29602589{
    29612590    PyObject *seq;
     
    30262655}
    30272656
     2657PyDoc_STRVAR(splitlines__doc__,
     2658"B.splitlines(keepends=False) -> list of lines\n\
     2659\n\
     2660Return a list of the lines in B, breaking at line boundaries.\n\
     2661Line breaks are not included in the resulting list unless keepends\n\
     2662is given and true.");
     2663
     2664static PyObject*
     2665bytearray_splitlines(PyObject *self, PyObject *args)
     2666{
     2667    int keepends = 0;
     2668
     2669    if (!PyArg_ParseTuple(args, "|i:splitlines", &keepends))
     2670        return NULL;
     2671
     2672    return stringlib_splitlines(
     2673        (PyObject*) self, PyByteArray_AS_STRING(self),
     2674        PyByteArray_GET_SIZE(self), keepends
     2675        );
     2676}
     2677
    30282678PyDoc_STRVAR(fromhex_doc,
    30292679"bytearray.fromhex(string) -> bytearray\n\
     
    30342684
    30352685static int
    3036 hex_digit_to_int(Py_UNICODE c)
    3037 {
    3038     if (c >= 128)
    3039         return -1;
    3040     if (ISDIGIT(c))
     2686hex_digit_to_int(char c)
     2687{
     2688    if (Py_ISDIGIT(c))
    30412689        return c - '0';
    30422690    else {
    3043         if (ISUPPER(c))
    3044             c = TOLOWER(c);
     2691        if (Py_ISUPPER(c))
     2692            c = Py_TOLOWER(c);
    30452693        if (c >= 'a' && c <= 'f')
    30462694            return c - 'a' + 10;
     
    30502698
    30512699static PyObject *
    3052 bytes_fromhex(PyObject *cls, PyObject *args)
    3053 {
    3054     PyObject *newbytes, *hexobj;
     2700bytearray_fromhex(PyObject *cls, PyObject *args)
     2701{
     2702    PyObject *newbytes;
    30552703    char *buf;
    3056     Py_UNICODE *hex;
     2704    char *hex;
    30572705    Py_ssize_t hexlen, byteslen, i, j;
    30582706    int top, bot;
    30592707
    3060     if (!PyArg_ParseTuple(args, "U:fromhex", &hexobj))
    3061         return NULL;
    3062     assert(PyUnicode_Check(hexobj));
    3063     hexlen = PyUnicode_GET_SIZE(hexobj);
    3064     hex = PyUnicode_AS_UNICODE(hexobj);
     2708    if (!PyArg_ParseTuple(args, "s#:fromhex", &hex, &hexlen))
     2709        return NULL;
    30652710    byteslen = hexlen/2; /* This overestimates if there are spaces */
    30662711    newbytes = PyByteArray_FromStringAndSize(NULL, byteslen);
     
    30962741
    30972742static PyObject *
    3098 bytes_reduce(PyByteArrayObject *self)
     2743bytearray_reduce(PyByteArrayObject *self)
    30992744{
    31002745    PyObject *latin1, *dict;
    31012746    if (self->ob_bytes)
     2747#ifdef Py_USING_UNICODE
    31022748        latin1 = PyUnicode_DecodeLatin1(self->ob_bytes,
    31032749                                        Py_SIZE(self), NULL);
     2750#else
     2751        latin1 = PyString_FromStringAndSize(self->ob_bytes, Py_SIZE(self));
     2752#endif
    31042753    else
     2754#ifdef Py_USING_UNICODE
    31052755        latin1 = PyUnicode_FromString("");
     2756#else
     2757        latin1 = PyString_FromString("");
     2758#endif
    31062759
    31072760    dict = PyObject_GetAttrString((PyObject *)self, "__dict__");
     
    31202773Returns the size of B in memory, in bytes");
    31212774static PyObject *
    3122 bytes_sizeof(PyByteArrayObject *self)
     2775bytearray_sizeof(PyByteArrayObject *self)
    31232776{
    31242777    Py_ssize_t res;
     
    31282781}
    31292782
    3130 static PySequenceMethods bytes_as_sequence = {
    3131     (lenfunc)bytes_length,              /* sq_length */
     2783static PySequenceMethods bytearray_as_sequence = {
     2784    (lenfunc)bytearray_length,              /* sq_length */
    31322785    (binaryfunc)PyByteArray_Concat,         /* sq_concat */
    3133     (ssizeargfunc)bytes_repeat,         /* sq_repeat */
    3134     (ssizeargfunc)bytes_getitem,        /* sq_item */
    3135     0,                                  /* sq_slice */
    3136     (ssizeobjargproc)bytes_setitem,     /* sq_ass_item */
    3137     0,                                  /* sq_ass_slice */
    3138     (objobjproc)bytes_contains,         /* sq_contains */
    3139     (binaryfunc)bytes_iconcat,          /* sq_inplace_concat */
    3140     (ssizeargfunc)bytes_irepeat,        /* sq_inplace_repeat */
     2786    (ssizeargfunc)bytearray_repeat,         /* sq_repeat */
     2787    (ssizeargfunc)bytearray_getitem,        /* sq_item */
     2788    0,                                      /* sq_slice */
     2789    (ssizeobjargproc)bytearray_setitem,     /* sq_ass_item */
     2790    0,                                      /* sq_ass_slice */
     2791    (objobjproc)bytearray_contains,         /* sq_contains */
     2792    (binaryfunc)bytearray_iconcat,          /* sq_inplace_concat */
     2793    (ssizeargfunc)bytearray_irepeat,        /* sq_inplace_repeat */
    31412794};
    31422795
    3143 static PyMappingMethods bytes_as_mapping = {
    3144     (lenfunc)bytes_length,
    3145     (binaryfunc)bytes_subscript,
    3146     (objobjargproc)bytes_ass_subscript,
     2796static PyMappingMethods bytearray_as_mapping = {
     2797    (lenfunc)bytearray_length,
     2798    (binaryfunc)bytearray_subscript,
     2799    (objobjargproc)bytearray_ass_subscript,
    31472800};
    31482801
    3149 static PyBufferProcs bytes_as_buffer = {
    3150     (readbufferproc)bytes_buffer_getreadbuf,
    3151     (writebufferproc)bytes_buffer_getwritebuf,
    3152     (segcountproc)bytes_buffer_getsegcount,
    3153     (charbufferproc)bytes_buffer_getcharbuf,
    3154     (getbufferproc)bytes_getbuffer,
    3155     (releasebufferproc)bytes_releasebuffer,
     2802static PyBufferProcs bytearray_as_buffer = {
     2803    (readbufferproc)bytearray_buffer_getreadbuf,
     2804    (writebufferproc)bytearray_buffer_getwritebuf,
     2805    (segcountproc)bytearray_buffer_getsegcount,
     2806    (charbufferproc)bytearray_buffer_getcharbuf,
     2807    (getbufferproc)bytearray_getbuffer,
     2808    (releasebufferproc)bytearray_releasebuffer,
    31562809};
    31572810
    31582811static PyMethodDef
    3159 bytes_methods[] = {
    3160     {"__alloc__", (PyCFunction)bytes_alloc, METH_NOARGS, alloc_doc},
    3161     {"__reduce__", (PyCFunction)bytes_reduce, METH_NOARGS, reduce_doc},
    3162     {"__sizeof__", (PyCFunction)bytes_sizeof, METH_NOARGS, sizeof_doc},
    3163     {"append", (PyCFunction)bytes_append, METH_O, append__doc__},
     2812bytearray_methods[] = {
     2813    {"__alloc__", (PyCFunction)bytearray_alloc, METH_NOARGS, alloc_doc},
     2814    {"__reduce__", (PyCFunction)bytearray_reduce, METH_NOARGS, reduce_doc},
     2815    {"__sizeof__", (PyCFunction)bytearray_sizeof, METH_NOARGS, sizeof_doc},
     2816    {"append", (PyCFunction)bytearray_append, METH_O, append__doc__},
    31642817    {"capitalize", (PyCFunction)stringlib_capitalize, METH_NOARGS,
    31652818     _Py_capitalize__doc__},
    31662819    {"center", (PyCFunction)stringlib_center, METH_VARARGS, center__doc__},
    3167     {"count", (PyCFunction)bytes_count, METH_VARARGS, count__doc__},
    3168     {"decode", (PyCFunction)bytes_decode, METH_VARARGS, decode_doc},
    3169     {"endswith", (PyCFunction)bytes_endswith, METH_VARARGS, endswith__doc__},
     2820    {"count", (PyCFunction)bytearray_count, METH_VARARGS, count__doc__},
     2821    {"decode", (PyCFunction)bytearray_decode, METH_VARARGS | METH_KEYWORDS, decode_doc},
     2822    {"endswith", (PyCFunction)bytearray_endswith, METH_VARARGS, endswith__doc__},
    31702823    {"expandtabs", (PyCFunction)stringlib_expandtabs, METH_VARARGS,
    31712824     expandtabs__doc__},
    3172     {"extend", (PyCFunction)bytes_extend, METH_O, extend__doc__},
    3173     {"find", (PyCFunction)bytes_find, METH_VARARGS, find__doc__},
    3174     {"fromhex", (PyCFunction)bytes_fromhex, METH_VARARGS|METH_CLASS,
     2825    {"extend", (PyCFunction)bytearray_extend, METH_O, extend__doc__},
     2826    {"find", (PyCFunction)bytearray_find, METH_VARARGS, find__doc__},
     2827    {"fromhex", (PyCFunction)bytearray_fromhex, METH_VARARGS|METH_CLASS,
    31752828     fromhex_doc},
    3176     {"index", (PyCFunction)bytes_index, METH_VARARGS, index__doc__},
    3177     {"insert", (PyCFunction)bytes_insert, METH_VARARGS, insert__doc__},
     2829    {"index", (PyCFunction)bytearray_index, METH_VARARGS, index__doc__},
     2830    {"insert", (PyCFunction)bytearray_insert, METH_VARARGS, insert__doc__},
    31782831    {"isalnum", (PyCFunction)stringlib_isalnum, METH_NOARGS,
    31792832     _Py_isalnum__doc__},
     
    31902843    {"isupper", (PyCFunction)stringlib_isupper, METH_NOARGS,
    31912844     _Py_isupper__doc__},
    3192     {"join", (PyCFunction)bytes_join, METH_O, join_doc},
     2845    {"join", (PyCFunction)bytearray_join, METH_O, join_doc},
    31932846    {"ljust", (PyCFunction)stringlib_ljust, METH_VARARGS, ljust__doc__},
    31942847    {"lower", (PyCFunction)stringlib_lower, METH_NOARGS, _Py_lower__doc__},
    3195     {"lstrip", (PyCFunction)bytes_lstrip, METH_VARARGS, lstrip__doc__},
    3196     {"partition", (PyCFunction)bytes_partition, METH_O, partition__doc__},
    3197     {"pop", (PyCFunction)bytes_pop, METH_VARARGS, pop__doc__},
    3198     {"remove", (PyCFunction)bytes_remove, METH_O, remove__doc__},
    3199     {"replace", (PyCFunction)bytes_replace, METH_VARARGS, replace__doc__},
    3200     {"reverse", (PyCFunction)bytes_reverse, METH_NOARGS, reverse__doc__},
    3201     {"rfind", (PyCFunction)bytes_rfind, METH_VARARGS, rfind__doc__},
    3202     {"rindex", (PyCFunction)bytes_rindex, METH_VARARGS, rindex__doc__},
     2848    {"lstrip", (PyCFunction)bytearray_lstrip, METH_VARARGS, lstrip__doc__},
     2849    {"partition", (PyCFunction)bytearray_partition, METH_O, partition__doc__},
     2850    {"pop", (PyCFunction)bytearray_pop, METH_VARARGS, pop__doc__},
     2851    {"remove", (PyCFunction)bytearray_remove, METH_O, remove__doc__},
     2852    {"replace", (PyCFunction)bytearray_replace, METH_VARARGS, replace__doc__},
     2853    {"reverse", (PyCFunction)bytearray_reverse, METH_NOARGS, reverse__doc__},
     2854    {"rfind", (PyCFunction)bytearray_rfind, METH_VARARGS, rfind__doc__},
     2855    {"rindex", (PyCFunction)bytearray_rindex, METH_VARARGS, rindex__doc__},
    32032856    {"rjust", (PyCFunction)stringlib_rjust, METH_VARARGS, rjust__doc__},
    3204     {"rpartition", (PyCFunction)bytes_rpartition, METH_O, rpartition__doc__},
    3205     {"rsplit", (PyCFunction)bytes_rsplit, METH_VARARGS, rsplit__doc__},
    3206     {"rstrip", (PyCFunction)bytes_rstrip, METH_VARARGS, rstrip__doc__},
    3207     {"split", (PyCFunction)bytes_split, METH_VARARGS, split__doc__},
    3208     {"splitlines", (PyCFunction)stringlib_splitlines, METH_VARARGS,
     2857    {"rpartition", (PyCFunction)bytearray_rpartition, METH_O, rpartition__doc__},
     2858    {"rsplit", (PyCFunction)bytearray_rsplit, METH_VARARGS, rsplit__doc__},
     2859    {"rstrip", (PyCFunction)bytearray_rstrip, METH_VARARGS, rstrip__doc__},
     2860    {"split", (PyCFunction)bytearray_split, METH_VARARGS, split__doc__},
     2861    {"splitlines", (PyCFunction)bytearray_splitlines, METH_VARARGS,
    32092862     splitlines__doc__},
    3210     {"startswith", (PyCFunction)bytes_startswith, METH_VARARGS ,
     2863    {"startswith", (PyCFunction)bytearray_startswith, METH_VARARGS ,
    32112864     startswith__doc__},
    3212     {"strip", (PyCFunction)bytes_strip, METH_VARARGS, strip__doc__},
     2865    {"strip", (PyCFunction)bytearray_strip, METH_VARARGS, strip__doc__},
    32132866    {"swapcase", (PyCFunction)stringlib_swapcase, METH_NOARGS,
    32142867     _Py_swapcase__doc__},
    32152868    {"title", (PyCFunction)stringlib_title, METH_NOARGS, _Py_title__doc__},
    3216     {"translate", (PyCFunction)bytes_translate, METH_VARARGS,
     2869    {"translate", (PyCFunction)bytearray_translate, METH_VARARGS,
    32172870     translate__doc__},
    32182871    {"upper", (PyCFunction)stringlib_upper, METH_NOARGS, _Py_upper__doc__},
     
    32212874};
    32222875
    3223 PyDoc_STRVAR(bytes_doc,
     2876PyDoc_STRVAR(bytearray_doc,
    32242877"bytearray(iterable_of_ints) -> bytearray.\n\
    32252878bytearray(string, encoding[, errors]) -> bytearray.\n\
     
    32382891
    32392892
    3240 static PyObject *bytes_iter(PyObject *seq);
     2893static PyObject *bytearray_iter(PyObject *seq);
    32412894
    32422895PyTypeObject PyByteArray_Type = {
     
    32452898    sizeof(PyByteArrayObject),
    32462899    0,
    3247     (destructor)bytes_dealloc,          /* tp_dealloc */
     2900    (destructor)bytearray_dealloc,       /* tp_dealloc */
    32482901    0,                                  /* tp_print */
    32492902    0,                                  /* tp_getattr */
    32502903    0,                                  /* tp_setattr */
    32512904    0,                                  /* tp_compare */
    3252     (reprfunc)bytes_repr,               /* tp_repr */
     2905    (reprfunc)bytearray_repr,           /* tp_repr */
    32532906    0,                                  /* tp_as_number */
    3254     &bytes_as_sequence,                 /* tp_as_sequence */
    3255     &bytes_as_mapping,                  /* tp_as_mapping */
     2907    &bytearray_as_sequence,             /* tp_as_sequence */
     2908    &bytearray_as_mapping,              /* tp_as_mapping */
    32562909    0,                                  /* tp_hash */
    32572910    0,                                  /* tp_call */
    3258     bytes_str,                          /* tp_str */
     2911    bytearray_str,                      /* tp_str */
    32592912    PyObject_GenericGetAttr,            /* tp_getattro */
    32602913    0,                                  /* tp_setattro */
    3261     &bytes_as_buffer,                   /* tp_as_buffer */
     2914    &bytearray_as_buffer,               /* tp_as_buffer */
    32622915    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
    32632916    Py_TPFLAGS_HAVE_NEWBUFFER,          /* tp_flags */
    3264     bytes_doc,                          /* tp_doc */
     2917    bytearray_doc,                      /* tp_doc */
    32652918    0,                                  /* tp_traverse */
    32662919    0,                                  /* tp_clear */
    3267     (richcmpfunc)bytes_richcompare,    /* tp_richcompare */
     2920    (richcmpfunc)bytearray_richcompare, /* tp_richcompare */
    32682921    0,                                  /* tp_weaklistoffset */
    3269     bytes_iter,                         /* tp_iter */
     2922    bytearray_iter,                     /* tp_iter */
    32702923    0,                                  /* tp_iternext */
    3271     bytes_methods,                      /* tp_methods */
     2924    bytearray_methods,                  /* tp_methods */
    32722925    0,                                  /* tp_members */
    32732926    0,                                  /* tp_getset */
     
    32772930    0,                                  /* tp_descr_set */
    32782931    0,                                  /* tp_dictoffset */
    3279     (initproc)bytes_init,               /* tp_init */
     2932    (initproc)bytearray_init,           /* tp_init */
    32802933    PyType_GenericAlloc,                /* tp_alloc */
    32812934    PyType_GenericNew,                  /* tp_new */
     
    32922945
    32932946static void
    3294 bytesiter_dealloc(bytesiterobject *it)
     2947bytearrayiter_dealloc(bytesiterobject *it)
    32952948{
    32962949    _PyObject_GC_UNTRACK(it);
     
    33002953
    33012954static int
    3302 bytesiter_traverse(bytesiterobject *it, visitproc visit, void *arg)
     2955bytearrayiter_traverse(bytesiterobject *it, visitproc visit, void *arg)
    33032956{
    33042957    Py_VISIT(it->it_seq);
     
    33072960
    33082961static PyObject *
    3309 bytesiter_next(bytesiterobject *it)
     2962bytearrayiter_next(bytesiterobject *it)
    33102963{
    33112964    PyByteArrayObject *seq;
     
    33322985
    33332986static PyObject *
    3334 bytesiter_length_hint(bytesiterobject *it)
     2987bytesarrayiter_length_hint(bytesiterobject *it)
    33352988{
    33362989    Py_ssize_t len = 0;
     
    33432996    "Private method returning an estimate of len(list(it)).");
    33442997
    3345 static PyMethodDef bytesiter_methods[] = {
    3346     {"__length_hint__", (PyCFunction)bytesiter_length_hint, METH_NOARGS,
     2998static PyMethodDef bytearrayiter_methods[] = {
     2999    {"__length_hint__", (PyCFunction)bytesarrayiter_length_hint, METH_NOARGS,
    33473000     length_hint_doc},
    33483001    {NULL, NULL} /* sentinel */
     
    33553008    0,                                 /* tp_itemsize */
    33563009    /* methods */
    3357     (destructor)bytesiter_dealloc,    /* tp_dealloc */
     3010    (destructor)bytearrayiter_dealloc, /* tp_dealloc */
    33583011    0,                                 /* tp_print */
    33593012    0,                                 /* tp_getattr */
     
    33723025    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */
    33733026    0,                                 /* tp_doc */
    3374     (traverseproc)bytesiter_traverse,  /* tp_traverse */
     3027    (traverseproc)bytearrayiter_traverse,  /* tp_traverse */
    33753028    0,                                 /* tp_clear */
    33763029    0,                                 /* tp_richcompare */
    33773030    0,                                 /* tp_weaklistoffset */
    33783031    PyObject_SelfIter,                 /* tp_iter */
    3379     (iternextfunc)bytesiter_next,      /* tp_iternext */
    3380     bytesiter_methods,                 /* tp_methods */
     3032    (iternextfunc)bytearrayiter_next,  /* tp_iternext */
     3033    bytearrayiter_methods,             /* tp_methods */
    33813034    0,
    33823035};
    33833036
    33843037static PyObject *
    3385 bytes_iter(PyObject *seq)
     3038bytearray_iter(PyObject *seq)
    33863039{
    33873040    bytesiterobject *it;
Note: See TracChangeset for help on using the changeset viewer.