summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Include/bytes_methods.h2
-rw-r--r--Include/bytesobject.h28
-rw-r--r--Include/pythonrun.h4
-rw-r--r--Modules/_bsddb.c6
-rw-r--r--Modules/_ctypes/_ctypes.c2
-rw-r--r--Modules/_ctypes/cfield.c4
-rw-r--r--Modules/_dbmmodule.c10
-rw-r--r--Modules/_sqlite/cursor.c6
-rw-r--r--Modules/_sqlite/module.c2
-rw-r--r--Modules/_sqlite/statement.c2
-rw-r--r--Modules/_ssl.c12
-rw-r--r--Modules/_struct.c12
-rw-r--r--Modules/arraymodule.c4
-rw-r--r--Modules/mmapmodule.c10
-rw-r--r--Modules/ossaudiodev.c6
-rw-r--r--Modules/pyexpat.c4
-rw-r--r--Modules/zipimport.c22
-rw-r--r--Modules/zlibmodule.c62
-rw-r--r--Objects/bytesobject.c466
-rw-r--r--Objects/longobject.c6
-rw-r--r--Objects/memoryobject.c12
-rw-r--r--Objects/object.c2
-rw-r--r--Objects/stringobject.c6
-rw-r--r--Objects/unicodeobject.c62
-rw-r--r--PC/winreg.c2
-rw-r--r--Parser/tokenizer.c8
-rw-r--r--Python/bltinmodule.c10
-rw-r--r--Python/codecs.c4
-rw-r--r--Python/getargs.c6
-rw-r--r--Python/marshal.c8
-rw-r--r--Python/pythonrun.c4
31 files changed, 397 insertions, 397 deletions
diff --git a/Include/bytes_methods.h b/Include/bytes_methods.h
index 59873f2..37518d2 100644
--- a/Include/bytes_methods.h
+++ b/Include/bytes_methods.h
@@ -2,7 +2,7 @@
#define Py_BYTES_CTYPE_H
/*
- * The internal implementation behind PyString (bytes) and PyBytes (buffer)
+ * The internal implementation behind PyBytes (bytes) and PyByteArray (bytearray)
* methods of the given names, they operate on ASCII byte strings.
*/
extern PyObject* _Py_bytes_isspace(const char *cptr, Py_ssize_t len);
diff --git a/Include/bytesobject.h b/Include/bytesobject.h
index 49d1d38..2c0b734 100644
--- a/Include/bytesobject.h
+++ b/Include/bytesobject.h
@@ -8,7 +8,7 @@ extern "C" {
#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 @@ typedef struct {
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
}
diff --git a/Include/pythonrun.h b/Include/pythonrun.h
index e5baf94..ba602c5 100644
--- a/Include/pythonrun.h
+++ b/Include/pythonrun.h
@@ -126,7 +126,7 @@ PyAPI_FUNC(void) _PyExc_Init(void);
PyAPI_FUNC(void) _PyImportHooks_Init(void);
PyAPI_FUNC(int) _PyFrame_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);
@@ -139,7 +139,7 @@ PyAPI_FUNC(void) PyTuple_Fini(void);
PyAPI_FUNC(void) PyList_Fini(void);
PyAPI_FUNC(void) PySet_Fini(void);
PyAPI_FUNC(void) PyString_Fini(void);
-PyAPI_FUNC(void) PyBytes_Fini(void);
+PyAPI_FUNC(void) PyByteArray_Fini(void);
PyAPI_FUNC(void) PyFloat_Fini(void);
PyAPI_FUNC(void) PyOS_FiniInterrupts(void);
diff --git a/Modules/_bsddb.c b/Modules/_bsddb.c
index 02973aa..28f2caf 100644
--- a/Modules/_bsddb.c
+++ b/Modules/_bsddb.c
@@ -1174,14 +1174,14 @@ _db_associateCallback(DB* db, const DBT* priKey, const DBT* priData,
else if (PyLong_Check(result)) {
retval = PyLong_AsLong(result);
}
- else if (PyBytes_Check(result) || PyString_Check(result)) {
+ else if (PyByteArray_Check(result) || PyString_Check(result)) {
char* data;
Py_ssize_t size;
CLEAR_DBT(*secKey);
size = Py_SIZE(result);
- if (PyBytes_Check(result))
- data = PyBytes_AS_STRING(result);
+ if (PyByteArray_Check(result))
+ data = PyByteArray_AS_STRING(result);
else
data = PyString_AS_STRING(result);
secKey->flags = DB_DBT_APPMALLOC; /* DB will free */
diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c
index 98c609c..1d548dc 100644
--- a/Modules/_ctypes/_ctypes.c
+++ b/Modules/_ctypes/_ctypes.c
@@ -1596,7 +1596,7 @@ c_void_p_from_param(PyObject *type, PyObject *value)
return (PyObject *)parg;
}
/* bytes */
- if (PyBytes_Check(value)) {
+ if (PyByteArray_Check(value)) {
PyCArgObject *parg;
struct fielddesc *fd = getentry("z");
diff --git a/Modules/_ctypes/cfield.c b/Modules/_ctypes/cfield.c
index 4e02563..86f6b53 100644
--- a/Modules/_ctypes/cfield.c
+++ b/Modules/_ctypes/cfield.c
@@ -1172,8 +1172,8 @@ c_set(void *ptr, PyObject *value, Py_ssize_t size)
*(char *)ptr = PyString_AS_STRING(value)[0];
_RET(value);
}
- if (PyBytes_Check(value) && PyBytes_GET_SIZE(value) == 1) {
- *(char *)ptr = PyBytes_AS_STRING(value)[0];
+ if (PyByteArray_Check(value) && PyByteArray_GET_SIZE(value) == 1) {
+ *(char *)ptr = PyByteArray_AS_STRING(value)[0];
_RET(value);
}
if (PyLong_Check(value))
diff --git a/Modules/_dbmmodule.c b/Modules/_dbmmodule.c
index 1a49e24..8484d94 100644
--- a/Modules/_dbmmodule.c
+++ b/Modules/_dbmmodule.c
@@ -111,7 +111,7 @@ dbm_subscript(dbmobject *dp, register PyObject *key)
PyErr_SetString(DbmError, "");
return NULL;
}
- return PyBytes_FromStringAndSize(drec.dptr, drec.dsize);
+ return PyByteArray_FromStringAndSize(drec.dptr, drec.dsize);
}
static int
@@ -188,7 +188,7 @@ dbm_keys(register dbmobject *dp, PyObject *unused)
return NULL;
for (key = dbm_firstkey(dp->di_dbm); key.dptr;
key = dbm_nextkey(dp->di_dbm)) {
- item = PyBytes_FromStringAndSize(key.dptr, key.dsize);
+ item = PyByteArray_FromStringAndSize(key.dptr, key.dsize);
if (item == NULL) {
Py_DECREF(v);
return NULL;
@@ -260,7 +260,7 @@ dbm_get(register dbmobject *dp, PyObject *args)
check_dbmobject_open(dp);
val = dbm_fetch(dp->di_dbm, key);
if (val.dptr != NULL)
- return PyBytes_FromStringAndSize(val.dptr, val.dsize);
+ return PyByteArray_FromStringAndSize(val.dptr, val.dsize);
else {
Py_INCREF(defvalue);
return defvalue;
@@ -283,9 +283,9 @@ dbm_setdefault(register dbmobject *dp, PyObject *args)
check_dbmobject_open(dp);
val = dbm_fetch(dp->di_dbm, key);
if (val.dptr != NULL)
- return PyBytes_FromStringAndSize(val.dptr, val.dsize);
+ return PyByteArray_FromStringAndSize(val.dptr, val.dsize);
if (defvalue == NULL) {
- defvalue = PyBytes_FromStringAndSize(NULL, 0);
+ defvalue = PyByteArray_FromStringAndSize(NULL, 0);
if (defvalue == NULL)
return NULL;
val.dptr = NULL;
diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c
index 10ce2e1..4ab8461 100644
--- a/Modules/_sqlite/cursor.c
+++ b/Modules/_sqlite/cursor.c
@@ -352,7 +352,7 @@ PyObject* _pysqlite_fetch_one_row(pysqlite_Cursor* self)
}
PyOS_snprintf(buf, sizeof(buf) - 1, "Could not decode to UTF-8 column '%s' with text '%s'",
colname , val_str);
- buf_bytes = PyBytes_FromStringAndSize(buf, strlen(buf));
+ buf_bytes = PyByteArray_FromStringAndSize(buf, strlen(buf));
if (!buf_bytes) {
PyErr_SetString(pysqlite_OperationalError, "Could not decode to UTF-8");
} else {
@@ -368,8 +368,8 @@ PyObject* _pysqlite_fetch_one_row(pysqlite_Cursor* self)
}
} else if (self->connection->text_factory == (PyObject*)&PyString_Type) {
converted = PyString_FromString(val_str);
- } else if (self->connection->text_factory == (PyObject*)&PyBytes_Type) {
- converted = PyBytes_FromStringAndSize(val_str, strlen(val_str));
+ } else if (self->connection->text_factory == (PyObject*)&PyByteArray_Type) {
+ converted = PyByteArray_FromStringAndSize(val_str, strlen(val_str));
} else {
converted = PyObject_CallFunction(self->connection->text_factory, "y", val_str);
}
diff --git a/Modules/_sqlite/module.c b/Modules/_sqlite/module.c
index 2284eaa..1f8c63f 100644
--- a/Modules/_sqlite/module.c
+++ b/Modules/_sqlite/module.c
@@ -137,7 +137,7 @@ static PyObject* module_register_adapter(PyObject* self, PyObject* args, PyObjec
/* a basic type is adapted; there's a performance optimization if that's not the case
* (99 % of all usages) */
if (type == &PyLong_Type || type == &PyFloat_Type
- || type == &PyUnicode_Type || type == &PyBytes_Type) {
+ || type == &PyUnicode_Type || type == &PyByteArray_Type) {
pysqlite_BaseTypeAdapted = 1;
}
diff --git a/Modules/_sqlite/statement.c b/Modules/_sqlite/statement.c
index ebf948b..ddbb85e 100644
--- a/Modules/_sqlite/statement.c
+++ b/Modules/_sqlite/statement.c
@@ -167,7 +167,7 @@ static int _need_adapt(PyObject* obj)
}
if (PyLong_CheckExact(obj) || PyFloat_CheckExact(obj)
- || PyUnicode_CheckExact(obj) || PyBytes_CheckExact(obj)) {
+ || PyUnicode_CheckExact(obj) || PyByteArray_CheckExact(obj)) {
return 0;
} else {
return 1;
diff --git a/Modules/_ssl.c b/Modules/_ssl.c
index 296a425..beb212f 100644
--- a/Modules/_ssl.c
+++ b/Modules/_ssl.c
@@ -1263,16 +1263,16 @@ static PyObject *PySSL_SSLread(PySSLObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "|Oi:read", &buf, &count))
return NULL;
if ((buf == NULL) || (buf == Py_None)) {
- if (!(buf = PyBytes_FromStringAndSize((char *) 0, len)))
+ if (!(buf = PyByteArray_FromStringAndSize((char *) 0, len)))
return NULL;
} else if (PyLong_Check(buf)) {
len = PyLong_AS_LONG(buf);
- if (!(buf = PyBytes_FromStringAndSize((char *) 0, len)))
+ if (!(buf = PyByteArray_FromStringAndSize((char *) 0, len)))
return NULL;
} else {
- if (!PyBytes_Check(buf))
+ if (!PyByteArray_Check(buf))
return NULL;
- len = PyBytes_Size(buf);
+ len = PyByteArray_Size(buf);
if ((count > 0) && (count <= len))
len = count;
buf_passed = 1;
@@ -1313,7 +1313,7 @@ static PyObject *PySSL_SSLread(PySSLObject *self, PyObject *args)
do {
err = 0;
PySSL_BEGIN_ALLOW_THREADS
- count = SSL_read(self->ssl, PyBytes_AsString(buf), len);
+ count = SSL_read(self->ssl, PyByteArray_AsString(buf), len);
err = SSL_get_error(self->ssl, count);
PySSL_END_ALLOW_THREADS
if(PyErr_CheckSignals()) {
@@ -1357,7 +1357,7 @@ static PyObject *PySSL_SSLread(PySSLObject *self, PyObject *args)
done:
if (!buf_passed) {
PyObject *res = PyString_FromStringAndSize(
- PyBytes_AS_STRING(buf), count);
+ PyByteArray_AS_STRING(buf), count);
Py_DECREF(buf);
return res;
} else {
diff --git a/Modules/_struct.c b/Modules/_struct.c
index 13ffee7..c162e6d 100644
--- a/Modules/_struct.c
+++ b/Modules/_struct.c
@@ -1646,7 +1646,7 @@ s_pack_internal(PyStructObject *soself, PyObject *args, int offset, char* buf)
return -1;
}
isstring = PyString_Check(v);
- if (!isstring && !PyBytes_Check(v)) {
+ if (!isstring && !PyByteArray_Check(v)) {
PyErr_SetString(StructError,
"argument for 's' must be a string");
return -1;
@@ -1656,8 +1656,8 @@ s_pack_internal(PyStructObject *soself, PyObject *args, int offset, char* buf)
p = PyString_AS_STRING(v);
}
else {
- n = PyBytes_GET_SIZE(v);
- p = PyBytes_AS_STRING(v);
+ n = PyByteArray_GET_SIZE(v);
+ p = PyByteArray_AS_STRING(v);
}
if (n > code->size)
n = code->size;
@@ -1672,7 +1672,7 @@ s_pack_internal(PyStructObject *soself, PyObject *args, int offset, char* buf)
return -1;
}
isstring = PyString_Check(v);
- if (!isstring && !PyBytes_Check(v)) {
+ if (!isstring && !PyByteArray_Check(v)) {
PyErr_SetString(StructError,
"argument for 'p' must be a string");
return -1;
@@ -1682,8 +1682,8 @@ s_pack_internal(PyStructObject *soself, PyObject *args, int offset, char* buf)
p = PyString_AS_STRING(v);
}
else {
- n = PyBytes_GET_SIZE(v);
- p = PyBytes_AS_STRING(v);
+ n = PyByteArray_GET_SIZE(v);
+ p = PyByteArray_AS_STRING(v);
}
if (n > (code->size - 1))
n = code->size - 1;
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
index 240a372..a851212 100644
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -1855,7 +1855,7 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return NULL;
if (!(initial == NULL || PyList_Check(initial)
- || PyBytes_Check(initial)
+ || PyByteArray_Check(initial)
|| PyString_Check(initial)
|| PyTuple_Check(initial)
|| ((c=='u') && PyUnicode_Check(initial)))) {
@@ -1901,7 +1901,7 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
Py_DECREF(v);
}
}
- else if (initial != NULL && (PyBytes_Check(initial) ||
+ else if (initial != NULL && (PyByteArray_Check(initial) ||
PyString_Check(initial))) {
PyObject *t_initial, *v;
t_initial = PyTuple_Pack(1, initial);
diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c
index 469c531..a6cd50b 100644
--- a/Modules/mmapmodule.c
+++ b/Modules/mmapmodule.c
@@ -228,7 +228,7 @@ mmap_read_line_method(mmap_object *self,
else
++eol; /* we're interested in the position after the
newline. */
- result = PyBytes_FromStringAndSize(start, (eol - start));
+ result = PyByteArray_FromStringAndSize(start, (eol - start));
self->pos += (eol - start);
return result;
}
@@ -248,7 +248,7 @@ mmap_read_method(mmap_object *self,
if ((self->pos + num_bytes) > self->size) {
num_bytes -= (self->pos+num_bytes) - self->size;
}
- result = PyBytes_FromStringAndSize(self->data+self->pos, num_bytes);
+ result = PyByteArray_FromStringAndSize(self->data+self->pos, num_bytes);
self->pos += num_bytes;
return result;
}
@@ -679,7 +679,7 @@ mmap_item(mmap_object *self, Py_ssize_t i)
PyErr_SetString(PyExc_IndexError, "mmap index out of range");
return NULL;
}
- return PyBytes_FromStringAndSize(self->data + i, 1);
+ return PyByteArray_FromStringAndSize(self->data + i, 1);
}
static PyObject *
@@ -769,14 +769,14 @@ mmap_ass_item(mmap_object *self, Py_ssize_t i, PyObject *v)
"mmap object doesn't support item deletion");
return -1;
}
- if (! (PyBytes_Check(v) && PyBytes_Size(v)==1) ) {
+ if (! (PyByteArray_Check(v) && PyByteArray_Size(v)==1) ) {
PyErr_SetString(PyExc_IndexError,
"mmap assignment must be length-1 bytes()");
return -1;
}
if (!is_writable(self))
return -1;
- buf = PyBytes_AsString(v);
+ buf = PyByteArray_AsString(v);
self->data[i] = buf[0];
return 0;
}
diff --git a/Modules/ossaudiodev.c b/Modules/ossaudiodev.c
index 2bd79d5..b976873 100644
--- a/Modules/ossaudiodev.c
+++ b/Modules/ossaudiodev.c
@@ -366,10 +366,10 @@ oss_read(oss_audio_t *self, PyObject *args)
if (!PyArg_ParseTuple(args, "i:read", &size))
return NULL;
- rv = PyBytes_FromStringAndSize(NULL, size);
+ rv = PyByteArray_FromStringAndSize(NULL, size);
if (rv == NULL)
return NULL;
- cp = PyBytes_AS_STRING(rv);
+ cp = PyByteArray_AS_STRING(rv);
Py_BEGIN_ALLOW_THREADS
count = read(self->fd, cp, size);
@@ -381,7 +381,7 @@ oss_read(oss_audio_t *self, PyObject *args)
return NULL;
}
self->icount += count;
- PyBytes_Resize(rv, count);
+ PyByteArray_Resize(rv, count);
return rv;
}
diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c
index 0053201..852d093 100644
--- a/Modules/pyexpat.c
+++ b/Modules/pyexpat.c
@@ -866,8 +866,8 @@ readinst(char *buf, int buf_size, PyObject *meth)
if (PyString_Check(str))
ptr = PyString_AS_STRING(str);
- else if (PyBytes_Check(str))
- ptr = PyBytes_AS_STRING(str);
+ else if (PyByteArray_Check(str))
+ ptr = PyByteArray_AS_STRING(str);
else {
PyErr_Format(PyExc_TypeError,
"read() did not return a bytes object (type=%.400s)",
diff --git a/Modules/zipimport.c b/Modules/zipimport.c
index 9503643..4ad93d5 100644
--- a/Modules/zipimport.c
+++ b/Modules/zipimport.c
@@ -467,7 +467,7 @@ zipimporter_get_source(PyObject *obj, PyObject *args)
toc_entry = PyDict_GetItemString(self->files, path);
if (toc_entry != NULL) {
PyObject *bytes = get_data(PyUnicode_AsString(self->archive), toc_entry);
- PyObject *res = PyUnicode_FromString(PyBytes_AsString(bytes));
+ PyObject *res = PyUnicode_FromString(PyByteArray_AsString(bytes));
Py_XDECREF(bytes);
return res;
}
@@ -836,13 +836,13 @@ get_data(char *archive, PyObject *toc_entry)
bytes_size = compress == 0 ? data_size : data_size + 1;
if (bytes_size == 0)
bytes_size++;
- raw_data = PyBytes_FromStringAndSize((char *)NULL, bytes_size);
+ raw_data = PyByteArray_FromStringAndSize((char *)NULL, bytes_size);
if (raw_data == NULL) {
fclose(fp);
return NULL;
}
- buf = PyBytes_AsString(raw_data);
+ buf = PyByteArray_AsString(raw_data);
err = fseek(fp, file_offset, 0);
if (err == 0)
@@ -862,7 +862,7 @@ get_data(char *archive, PyObject *toc_entry)
buf[data_size] = '\0';
if (compress == 0) { /* data is not compressed */
- data = PyBytes_FromStringAndSize(buf, data_size);
+ data = PyByteArray_FromStringAndSize(buf, data_size);
Py_DECREF(raw_data);
return data;
}
@@ -903,8 +903,8 @@ static PyObject *
unmarshal_code(char *pathname, PyObject *data, time_t mtime)
{
PyObject *code;
- char *buf = PyBytes_AsString(data);
- Py_ssize_t size = PyBytes_Size(data);
+ char *buf = PyByteArray_AsString(data);
+ Py_ssize_t size = PyByteArray_Size(data);
if (size <= 9) {
PyErr_SetString(ZipImportError,
@@ -949,16 +949,16 @@ unmarshal_code(char *pathname, PyObject *data, time_t mtime)
static PyObject *
normalize_line_endings(PyObject *source)
{
- char *buf, *q, *p = PyBytes_AsString(source);
+ char *buf, *q, *p = PyByteArray_AsString(source);
PyObject *fixed_source;
int len = 0;
if (!p) {
- return PyBytes_FromStringAndSize("\n\0", 2);
+ return PyByteArray_FromStringAndSize("\n\0", 2);
}
/* one char extra for trailing \n and one for terminating \0 */
- buf = (char *)PyMem_Malloc(PyBytes_Size(source) + 2);
+ buf = (char *)PyMem_Malloc(PyByteArray_Size(source) + 2);
if (buf == NULL) {
PyErr_SetString(PyExc_MemoryError,
"zipimport: no memory to allocate "
@@ -978,7 +978,7 @@ normalize_line_endings(PyObject *source)
}
*q++ = '\n'; /* add trailing \n */
*q = '\0';
- fixed_source = PyBytes_FromStringAndSize(buf, len + 2);
+ fixed_source = PyByteArray_FromStringAndSize(buf, len + 2);
PyMem_Free(buf);
return fixed_source;
}
@@ -994,7 +994,7 @@ compile_source(char *pathname, PyObject *source)
if (fixed_source == NULL)
return NULL;
- code = Py_CompileString(PyBytes_AsString(fixed_source), pathname,
+ code = Py_CompileString(PyByteArray_AsString(fixed_source), pathname,
Py_file_input);
Py_DECREF(fixed_source);
return code;
diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c
index 4d941af..0be9d6f 100644
--- a/Modules/zlibmodule.c
+++ b/Modules/zlibmodule.c
@@ -96,12 +96,12 @@ newcompobject(PyTypeObject *type)
if (self == NULL)
return NULL;
self->is_initialised = 0;
- self->unused_data = PyBytes_FromStringAndSize("", 0);
+ self->unused_data = PyByteArray_FromStringAndSize("", 0);
if (self->unused_data == NULL) {
Py_DECREF(self);
return NULL;
}
- self->unconsumed_tail = PyBytes_FromStringAndSize("", 0);
+ self->unconsumed_tail = PyByteArray_FromStringAndSize("", 0);
if (self->unconsumed_tail == NULL) {
Py_DECREF(self);
return NULL;
@@ -174,7 +174,7 @@ PyZlib_compress(PyObject *self, PyObject *args)
err=deflateEnd(&zst);
if (err == Z_OK)
- ReturnVal = PyBytes_FromStringAndSize((char *)output,
+ ReturnVal = PyByteArray_FromStringAndSize((char *)output,
zst.total_out);
else
zlib_error(zst, err, "while finishing compression");
@@ -211,12 +211,12 @@ PyZlib_decompress(PyObject *self, PyObject *args)
zst.avail_in = length;
zst.avail_out = r_strlen;
- if (!(result_str = PyBytes_FromStringAndSize(NULL, r_strlen)))
+ if (!(result_str = PyByteArray_FromStringAndSize(NULL, r_strlen)))
return NULL;
zst.zalloc = (alloc_func)NULL;
zst.zfree = (free_func)Z_NULL;
- zst.next_out = (Byte *)PyBytes_AS_STRING(result_str);
+ zst.next_out = (Byte *)PyByteArray_AS_STRING(result_str);
zst.next_in = (Byte *)input;
err = inflateInit2(&zst, wsize);
@@ -256,12 +256,12 @@ PyZlib_decompress(PyObject *self, PyObject *args)
/* fall through */
case(Z_OK):
/* need more memory */
- if (PyBytes_Resize(result_str, r_strlen << 1) < 0) {
+ if (PyByteArray_Resize(result_str, r_strlen << 1) < 0) {
inflateEnd(&zst);
goto error;
}
zst.next_out =
- (unsigned char *)PyBytes_AS_STRING(result_str) + r_strlen;
+ (unsigned char *)PyByteArray_AS_STRING(result_str) + r_strlen;
zst.avail_out = r_strlen;
r_strlen = r_strlen << 1;
break;
@@ -278,7 +278,7 @@ PyZlib_decompress(PyObject *self, PyObject *args)
goto error;
}
- if (PyBytes_Resize(result_str, zst.total_out) < 0)
+ if (PyByteArray_Resize(result_str, zst.total_out) < 0)
goto error;
return result_str;
@@ -402,7 +402,7 @@ PyZlib_objcompress(compobject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "s#:compress", &input, &inplen))
return NULL;
- if (!(RetVal = PyBytes_FromStringAndSize(NULL, length)))
+ if (!(RetVal = PyByteArray_FromStringAndSize(NULL, length)))
return NULL;
ENTER_ZLIB
@@ -411,7 +411,7 @@ PyZlib_objcompress(compobject *self, PyObject *args)
self->zst.avail_in = inplen;
self->zst.next_in = input;
self->zst.avail_out = length;
- self->zst.next_out = (unsigned char *)PyBytes_AS_STRING(RetVal);
+ self->zst.next_out = (unsigned char *)PyByteArray_AS_STRING(RetVal);
Py_BEGIN_ALLOW_THREADS
err = deflate(&(self->zst), Z_NO_FLUSH);
@@ -420,13 +420,13 @@ PyZlib_objcompress(compobject *self, PyObject *args)
/* while Z_OK and the output buffer is full, there might be more output,
so extend the output buffer and try again */
while (err == Z_OK && self->zst.avail_out == 0) {
- if (PyBytes_Resize(RetVal, length << 1) < 0) {
+ if (PyByteArray_Resize(RetVal, length << 1) < 0) {
Py_DECREF(RetVal);
RetVal = NULL;
goto error;
}
self->zst.next_out =
- (unsigned char *)PyBytes_AS_STRING(RetVal) + length;
+ (unsigned char *)PyByteArray_AS_STRING(RetVal) + length;
self->zst.avail_out = length;
length = length << 1;
@@ -445,7 +445,7 @@ PyZlib_objcompress(compobject *self, PyObject *args)
RetVal = NULL;
goto error;
}
- if (PyBytes_Resize(RetVal, self->zst.total_out - start_total_out) < 0) {
+ if (PyByteArray_Resize(RetVal, self->zst.total_out - start_total_out) < 0) {
Py_DECREF(RetVal);
RetVal = NULL;
}
@@ -487,7 +487,7 @@ PyZlib_objdecompress(compobject *self, PyObject *args)
/* limit amount of data allocated to max_length */
if (max_length && length > max_length)
length = max_length;
- if (!(RetVal = PyBytes_FromStringAndSize(NULL, length)))
+ if (!(RetVal = PyByteArray_FromStringAndSize(NULL, length)))
return NULL;
ENTER_ZLIB
@@ -496,7 +496,7 @@ PyZlib_objdecompress(compobject *self, PyObject *args)
self->zst.avail_in = inplen;
self->zst.next_in = input;
self->zst.avail_out = length;
- self->zst.next_out = (unsigned char *)PyBytes_AS_STRING(RetVal);
+ self->zst.next_out = (unsigned char *)PyByteArray_AS_STRING(RetVal);
Py_BEGIN_ALLOW_THREADS
err = inflate(&(self->zst), Z_SYNC_FLUSH);
@@ -518,13 +518,13 @@ PyZlib_objdecompress(compobject *self, PyObject *args)
if (max_length && length > max_length)
length = max_length;
- if (PyBytes_Resize(RetVal, length) < 0) {
+ if (PyByteArray_Resize(RetVal, length) < 0) {
Py_DECREF(RetVal);
RetVal = NULL;
goto error;
}
self->zst.next_out =
- (unsigned char *)PyBytes_AS_STRING(RetVal) + old_length;
+ (unsigned char *)PyByteArray_AS_STRING(RetVal) + old_length;
self->zst.avail_out = length - old_length;
Py_BEGIN_ALLOW_THREADS
@@ -536,7 +536,7 @@ PyZlib_objdecompress(compobject *self, PyObject *args)
of specified size. Return the unconsumed tail in an attribute.*/
if(max_length) {
Py_DECREF(self->unconsumed_tail);
- self->unconsumed_tail = PyBytes_FromStringAndSize((char *)self->zst.next_in,
+ self->unconsumed_tail = PyByteArray_FromStringAndSize((char *)self->zst.next_in,
self->zst.avail_in);
if(!self->unconsumed_tail) {
Py_DECREF(RetVal);
@@ -553,7 +553,7 @@ PyZlib_objdecompress(compobject *self, PyObject *args)
*/
if (err == Z_STREAM_END) {
Py_XDECREF(self->unused_data); /* Free original empty string */
- self->unused_data = PyBytes_FromStringAndSize(
+ self->unused_data = PyByteArray_FromStringAndSize(
(char *)self->zst.next_in, self->zst.avail_in);
if (self->unused_data == NULL) {
Py_DECREF(RetVal);
@@ -570,7 +570,7 @@ PyZlib_objdecompress(compobject *self, PyObject *args)
goto error;
}
- if (PyBytes_Resize(RetVal, self->zst.total_out - start_total_out) < 0) {
+ if (PyByteArray_Resize(RetVal, self->zst.total_out - start_total_out) < 0) {
Py_DECREF(RetVal);
RetVal = NULL;
}
@@ -603,10 +603,10 @@ PyZlib_flush(compobject *self, PyObject *args)
/* Flushing with Z_NO_FLUSH is a no-op, so there's no point in
doing any work at all; just return an empty string. */
if (flushmode == Z_NO_FLUSH) {
- return PyBytes_FromStringAndSize(NULL, 0);
+ return PyByteArray_FromStringAndSize(NULL, 0);
}
- if (!(RetVal = PyBytes_FromStringAndSize(NULL, length)))
+ if (!(RetVal = PyByteArray_FromStringAndSize(NULL, length)))
return NULL;
ENTER_ZLIB
@@ -614,7 +614,7 @@ PyZlib_flush(compobject *self, PyObject *args)
start_total_out = self->zst.total_out;
self->zst.avail_in = 0;
self->zst.avail_out = length;
- self->zst.next_out = (unsigned char *)PyBytes_AS_STRING(RetVal);
+ self->zst.next_out = (unsigned char *)PyByteArray_AS_STRING(RetVal);
Py_BEGIN_ALLOW_THREADS
err = deflate(&(self->zst), flushmode);
@@ -623,13 +623,13 @@ PyZlib_flush(compobject *self, PyObject *args)
/* while Z_OK and the output buffer is full, there might be more output,
so extend the output buffer and try again */
while (err == Z_OK && self->zst.avail_out == 0) {
- if (PyBytes_Resize(RetVal, length << 1) < 0) {
+ if (PyByteArray_Resize(RetVal, length << 1) < 0) {
Py_DECREF(RetVal);
RetVal = NULL;
goto error;
}
self->zst.next_out =
- (unsigned char *)PyBytes_AS_STRING(RetVal) + length;
+ (unsigned char *)PyByteArray_AS_STRING(RetVal) + length;
self->zst.avail_out = length;
length = length << 1;
@@ -663,7 +663,7 @@ PyZlib_flush(compobject *self, PyObject *args)
goto error;
}
- if (PyBytes_Resize(RetVal, self->zst.total_out - start_total_out) < 0) {
+ if (PyByteArray_Resize(RetVal, self->zst.total_out - start_total_out) < 0) {
Py_DECREF(RetVal);
RetVal = NULL;
}
@@ -798,7 +798,7 @@ PyZlib_unflush(compobject *self, PyObject *args)
PyErr_SetString(PyExc_ValueError, "length must be greater than zero");
return NULL;
}
- if (!(retval = PyBytes_FromStringAndSize(NULL, length)))
+ if (!(retval = PyByteArray_FromStringAndSize(NULL, length)))
return NULL;
@@ -806,7 +806,7 @@ PyZlib_unflush(compobject *self, PyObject *args)
start_total_out = self->zst.total_out;
self->zst.avail_out = length;
- self->zst.next_out = (Byte *)PyBytes_AS_STRING(retval);
+ self->zst.next_out = (Byte *)PyByteArray_AS_STRING(retval);
Py_BEGIN_ALLOW_THREADS
err = inflate(&(self->zst), Z_FINISH);
@@ -815,12 +815,12 @@ PyZlib_unflush(compobject *self, PyObject *args)
/* while Z_OK and the output buffer is full, there might be more output,
so extend the output buffer and try again */
while ((err == Z_OK || err == Z_BUF_ERROR) && self->zst.avail_out == 0) {
- if (PyBytes_Resize(retval, length << 1) < 0) {
+ if (PyByteArray_Resize(retval, length << 1) < 0) {
Py_DECREF(retval);
retval = NULL;
goto error;
}
- self->zst.next_out = (Byte *)PyBytes_AS_STRING(retval) + length;
+ self->zst.next_out = (Byte *)PyByteArray_AS_STRING(retval) + length;
self->zst.avail_out = length;
length = length << 1;
@@ -842,7 +842,7 @@ PyZlib_unflush(compobject *self, PyObject *args)
goto error;
}
}
- if (PyBytes_Resize(retval, self->zst.total_out - start_total_out) < 0) {
+ if (PyByteArray_Resize(retval, self->zst.total_out - start_total_out) < 0) {
Py_DECREF(retval);
retval = NULL;
}
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c
index 385429c..98dc0f7 100644
--- a/Objects/bytesobject.c
+++ b/Objects/bytesobject.c
@@ -1,22 +1,22 @@
-/* PyBytes (bytearray) implementation */
+/* PyByteArray (bytearray) implementation */
#define PY_SSIZE_T_CLEAN
#include "Python.h"
#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;
@@ -50,7 +50,7 @@ _getbytevalue(PyObject* arg, int *value)
}
static int
-bytes_getbuffer(PyBytesObject *obj, Py_buffer *view, int flags)
+bytes_getbuffer(PyByteArrayObject *obj, Py_buffer *view, int flags)
{
int ret;
void *ptr;
@@ -70,7 +70,7 @@ bytes_getbuffer(PyBytesObject *obj, Py_buffer *view, int flags)
}
static void
-bytes_releasebuffer(PyBytesObject *obj, Py_buffer *view)
+bytes_releasebuffer(PyByteArrayObject *obj, Py_buffer *view)
{
obj->ob_exports--;
}
@@ -96,25 +96,25 @@ _getbuffer(PyObject *obj, Py_buffer *view)
/* 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;
@@ -141,31 +141,31 @@ PyBytes_FromStringAndSize(const char *bytes, Py_ssize_t size)
}
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) {
@@ -175,7 +175,7 @@ PyBytes_Resize(PyObject *self, Py_ssize_t size)
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) {
@@ -187,36 +187,36 @@ PyBytes_Resize(PyObject *self, Py_ssize_t size)
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;
@@ -233,7 +233,7 @@ PyBytes_Concat(PyObject *a, PyObject *b)
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);
@@ -250,13 +250,13 @@ PyBytes_Concat(PyObject *a, PyObject *b)
/* 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;
@@ -278,7 +278,7 @@ bytes_iconcat(PyBytesObject *self, PyObject *other)
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;
}
@@ -289,9 +289,9 @@ bytes_iconcat(PyBytesObject *self, PyObject *other)
}
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;
@@ -301,7 +301,7 @@ bytes_repeat(PyBytesObject *self, Py_ssize_t count)
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);
@@ -315,7 +315,7 @@ bytes_repeat(PyBytesObject *self, Py_ssize_t count)
}
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;
@@ -330,7 +330,7 @@ bytes_irepeat(PyBytesObject *self, Py_ssize_t count)
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)
@@ -346,7 +346,7 @@ bytes_irepeat(PyBytesObject *self, Py_ssize_t count)
}
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);
@@ -358,7 +358,7 @@ bytes_getitem(PyBytesObject *self, Py_ssize_t i)
}
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);
@@ -367,7 +367,7 @@ bytes_subscript(PyBytesObject *self, PyObject *item)
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");
@@ -378,19 +378,19 @@ bytes_subscript(PyBytesObject *self, PyObject *item)
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;
@@ -401,7 +401,7 @@ bytes_subscript(PyBytesObject *self, PyObject *item)
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;
}
@@ -413,7 +413,7 @@ bytes_subscript(PyBytesObject *self, PyObject *item)
}
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;
@@ -425,7 +425,7 @@ bytes_setslice(PyBytesObject *self, Py_ssize_t lo, Py_ssize_t hi,
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);
@@ -471,7 +471,7 @@ bytes_setslice(PyBytesObject *self, Py_ssize_t lo, Py_ssize_t hi,
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;
@@ -499,7 +499,7 @@ bytes_setslice(PyBytesObject *self, Py_ssize_t lo, Py_ssize_t hi,
}
static int
-bytes_setitem(PyBytesObject *self, Py_ssize_t i, PyObject *value)
+bytes_setitem(PyByteArrayObject *self, Py_ssize_t i, PyObject *value)
{
Py_ssize_t ival;
@@ -528,7 +528,7 @@ bytes_setitem(PyBytesObject *self, Py_ssize_t i, PyObject *value)
}
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;
@@ -540,7 +540,7 @@ bytes_ass_subscript(PyBytesObject *self, PyObject *item, PyObject *values)
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");
@@ -569,7 +569,7 @@ bytes_ass_subscript(PyBytesObject *self, PyObject *item, PyObject *values)
}
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;
}
@@ -583,10 +583,10 @@ bytes_ass_subscript(PyBytesObject *self, PyObject *item, PyObject *values)
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);
@@ -594,8 +594,8 @@ bytes_ass_subscript(PyBytesObject *self, PyObject *item, PyObject *values)
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. */
@@ -614,7 +614,7 @@ bytes_ass_subscript(PyBytesObject *self, PyObject *item, PyObject *values)
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) {
@@ -648,21 +648,21 @@ bytes_ass_subscript(PyBytesObject *self, PyObject *item, PyObject *values)
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;
@@ -686,7 +686,7 @@ bytes_ass_subscript(PyBytesObject *self, PyObject *item, PyObject *values)
}
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;
@@ -698,7 +698,7 @@ bytes_init(PyBytesObject *self, PyObject *args, PyObject *kwds)
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;
}
@@ -754,7 +754,7 @@ bytes_init(PyBytesObject *self, PyObject *args, PyObject *kwds)
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);
}
@@ -768,7 +768,7 @@ bytes_init(PyBytesObject *self, PyObject *args, PyObject *kwds)
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);
@@ -818,7 +818,7 @@ bytes_init(PyBytesObject *self, PyObject *args, PyObject *kwds)
/* 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;
}
@@ -836,7 +836,7 @@ bytes_init(PyBytesObject *self, PyObject *args, PyObject *kwds)
/* 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";
@@ -864,7 +864,7 @@ bytes_repr(PyBytesObject *self)
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 */
@@ -928,7 +928,7 @@ bytes_str(PyObject *op)
"str() on a bytearray instance", 1))
return NULL;
}
- return bytes_repr((PyBytesObject*)op);
+ return bytes_repr((PyByteArrayObject*)op);
}
static PyObject *
@@ -1007,7 +1007,7 @@ bytes_richcompare(PyObject *self, PyObject *other, int op)
}
static void
-bytes_dealloc(PyBytesObject *self)
+bytes_dealloc(PyByteArrayObject *self)
{
if (self->ob_bytes != 0) {
PyMem_Free(self->ob_bytes);
@@ -1021,11 +1021,11 @@ bytes_dealloc(PyBytesObject *self)
#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"
@@ -1056,7 +1056,7 @@ _adjust_indices(Py_ssize_t *start, Py_ssize_t *end, Py_ssize_t len)
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;
@@ -1070,11 +1070,11 @@ bytes_find_internal(PyBytesObject *self, PyObject *args, int dir)
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;
@@ -1090,7 +1090,7 @@ arguments start and end are interpreted as in slice notation.\n\
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)
@@ -1106,10 +1106,10 @@ bytes B[start:end]. Optional arguments start and end are interpreted\n\
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;
@@ -1121,7 +1121,7 @@ bytes_count(PyBytesObject *self, PyObject *args)
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 = PyLong_FromSsize_t(
stringlib_count(str + start, end - start, vsub.buf, vsub.len)
@@ -1137,7 +1137,7 @@ PyDoc_STRVAR(index__doc__,
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)
@@ -1161,7 +1161,7 @@ arguments start and end are interpreted as in slice notation.\n\
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)
@@ -1176,7 +1176,7 @@ PyDoc_STRVAR(rindex__doc__,
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)
@@ -1200,7 +1200,7 @@ bytes_contains(PyObject *self, PyObject *arg)
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;
@@ -1210,7 +1210,7 @@ bytes_contains(PyObject *self, PyObject *arg)
return -1;
}
- return memchr(PyBytes_AS_STRING(self), ival, Py_SIZE(self)) != NULL;
+ return memchr(PyByteArray_AS_STRING(self), ival, Py_SIZE(self)) != NULL;
}
@@ -1219,15 +1219,15 @@ bytes_contains(PyObject *self, PyObject *arg)
* -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;
@@ -1266,7 +1266,7 @@ With optional end, stop comparing B at that position.\n\
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;
@@ -1306,7 +1306,7 @@ With optional end, stop comparing B at that position.\n\
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;
@@ -1347,7 +1347,7 @@ characters have been mapped through the given translation\n\
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;
@@ -1386,12 +1386,12 @@ bytes_translate(PyBytesObject *self, PyObject *args)
}
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 */
@@ -1400,7 +1400,7 @@ bytes_translate(PyBytesObject *self, PyObject *args)
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);
@@ -1421,7 +1421,7 @@ bytes_translate(PyBytesObject *self, PyObject *args)
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;
@@ -1429,7 +1429,7 @@ bytes_translate(PyBytesObject *self, PyObject *args)
}
/* 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);
@@ -1456,16 +1456,16 @@ done:
/* 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)
@@ -1575,17 +1575,17 @@ countstring(const char *target, Py_ssize_t target_len,
/* 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;
@@ -1607,12 +1607,12 @@ replace_interleave(PyBytesObject *self,
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 */
@@ -1635,18 +1635,18 @@ replace_interleave(PyBytesObject *self,
/* 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) {
@@ -1656,10 +1656,10 @@ replace_delete_single_character(PyBytesObject *self,
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;
@@ -1678,8 +1678,8 @@ replace_delete_single_character(PyBytesObject *self,
/* 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)
{
@@ -1687,10 +1687,10 @@ replace_delete_substring(PyBytesObject *self,
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,
@@ -1705,11 +1705,11 @@ replace_delete_substring(PyBytesObject *self,
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;
@@ -1731,18 +1731,18 @@ replace_delete_substring(PyBytesObject *self,
}
/* 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);
@@ -1752,10 +1752,10 @@ replace_single_character_in_place(PyBytesObject *self,
}
/* 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 */
@@ -1776,8 +1776,8 @@ replace_single_character_in_place(PyBytesObject *self,
}
/* 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)
@@ -1785,12 +1785,12 @@ replace_substring_in_place(PyBytesObject *self,
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,
@@ -1801,10 +1801,10 @@ replace_substring_in_place(PyBytesObject *self,
}
/* 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 */
@@ -1827,8 +1827,8 @@ replace_substring_in_place(PyBytesObject *self,
}
/* 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)
@@ -1837,10 +1837,10 @@ replace_single_character(PyBytesObject *self,
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) {
@@ -1861,10 +1861,10 @@ replace_single_character(PyBytesObject *self,
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;
@@ -1894,8 +1894,8 @@ replace_single_character(PyBytesObject *self,
}
/* 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)
@@ -1904,10 +1904,10 @@ replace_substring(PyBytesObject *self,
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,
@@ -1930,10 +1930,10 @@ replace_substring(PyBytesObject *self,
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;
@@ -1965,15 +1965,15 @@ replace_substring(PyBytesObject *self,
}
-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);
}
@@ -1996,7 +1996,7 @@ replace(PyBytesObject *self,
/* 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);
}
@@ -2044,7 +2044,7 @@ old replaced by new. If the optional argument count is\n\
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;
@@ -2060,7 +2060,7 @@ bytes_replace(PyBytesObject *self, PyObject *args)
return NULL;
}
- res = (PyObject *)replace((PyBytesObject *) self,
+ res = (PyObject *)replace((PyByteArrayObject *) self,
vfrom.buf, vfrom.len,
vto.buf, vto.len, count);
@@ -2084,7 +2084,7 @@ bytes_replace(PyBytesObject *self, PyObject *args)
(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; \
@@ -2096,7 +2096,7 @@ bytes_replace(PyBytesObject *self, PyObject *args)
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; \
@@ -2195,11 +2195,11 @@ If sep is not given, B is split on ASCII whitespace characters\n\
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
@@ -2277,7 +2277,7 @@ make_nullbytes_unique(PyObject *result)
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;
@@ -2299,19 +2299,19 @@ the separator itself, and the part after it. If the separator is not\n\
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);
@@ -2327,19 +2327,19 @@ part after it. If the separator is not found, returns two empty\n\
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);
@@ -2430,11 +2430,11 @@ If sep is not given, B is split on ASCII whitespace characters\n\
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;
@@ -2496,7 +2496,7 @@ PyDoc_STRVAR(reverse__doc__,
\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);
@@ -2518,7 +2518,7 @@ PyDoc_STRVAR(insert__doc__,
\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);
@@ -2536,7 +2536,7 @@ bytes_insert(PyBytesObject *self, PyObject *args)
"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) {
@@ -2557,7 +2557,7 @@ PyDoc_STRVAR(append__doc__,
\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);
@@ -2569,7 +2569,7 @@ bytes_append(PyBytesObject *self, PyObject *arg)
"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;
@@ -2583,7 +2583,7 @@ PyDoc_STRVAR(extend__doc__,
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;
@@ -2605,10 +2605,10 @@ bytes_extend(PyBytesObject *self, PyObject *arg)
/* 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)) {
@@ -2622,20 +2622,20 @@ bytes_extend(PyBytesObject *self, PyObject *arg)
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;
}
@@ -2653,7 +2653,7 @@ PyDoc_STRVAR(pop__doc__,
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);
@@ -2675,7 +2675,7 @@ bytes_pop(PyBytesObject *self, PyObject *args)
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 PyLong_FromLong(value);
@@ -2686,7 +2686,7 @@ PyDoc_STRVAR(remove__doc__,
\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);
@@ -2704,7 +2704,7 @@ bytes_remove(PyBytesObject *self, PyObject *arg)
}
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;
@@ -2738,7 +2738,7 @@ PyDoc_STRVAR(strip__doc__,
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;
@@ -2765,7 +2765,7 @@ bytes_strip(PyBytesObject *self, PyObject *args)
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__,
@@ -2774,7 +2774,7 @@ PyDoc_STRVAR(lstrip__doc__,
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;
@@ -2798,7 +2798,7 @@ bytes_lstrip(PyBytesObject *self, PyObject *args)
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__,
@@ -2807,7 +2807,7 @@ PyDoc_STRVAR(rstrip__doc__,
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;
@@ -2831,7 +2831,7 @@ bytes_rstrip(PyBytesObject *self, PyObject *args)
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,
@@ -2863,7 +2863,7 @@ PyDoc_STRVAR(alloc_doc,
Returns the number of bytes actually allocated.");
static PyObject *
-bytes_alloc(PyBytesObject *self)
+bytes_alloc(PyByteArrayObject *self)
{
return PyLong_FromSsize_t(self->ob_alloc);
}
@@ -2874,7 +2874,7 @@ PyDoc_STRVAR(join_doc,
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);
@@ -2895,7 +2895,7 @@ bytes_join(PyBytesObject *self, PyObject *it)
/* 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')",
@@ -2913,16 +2913,16 @@ bytes_join(PyBytesObject *self, PyObject *it)
}
/* 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) {
@@ -2981,10 +2981,10 @@ bytes_fromhex(PyObject *cls, PyObject *args)
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] == ' ')
@@ -3001,7 +3001,7 @@ bytes_fromhex(PyObject *cls, PyObject *args)
}
buf[j++] = (top << 4) + bot;
}
- if (PyBytes_Resize(newbytes, j) < 0)
+ if (PyByteArray_Resize(newbytes, j) < 0)
goto error;
return newbytes;
@@ -3013,7 +3013,7 @@ bytes_fromhex(PyObject *cls, PyObject *args)
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)
@@ -3034,7 +3034,7 @@ bytes_reduce(PyBytesObject *self)
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 */
@@ -3139,10 +3139,10 @@ Construct a zero-initialized bytearray of the given length.");
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 */
@@ -3186,7 +3186,7 @@ PyTypeObject PyBytes_Type = {
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
@@ -3207,16 +3207,16 @@ bytesiter_traverse(bytesiterobject *it, visitproc visit, void *arg)
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 = PyLong_FromLong(
(unsigned char)seq->ob_bytes[it->it_index]);
if (item != NULL)
@@ -3234,7 +3234,7 @@ bytesiter_length_hint(bytesiterobject *it)
{
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 PyLong_FromSsize_t(len);
}
@@ -3247,7 +3247,7 @@ static PyMethodDef bytesiter_methods[] = {
{NULL, NULL} /* sentinel */
};
-PyTypeObject PyBytesIter_Type = {
+PyTypeObject PyByteArrayIter_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
"bytearray_iterator", /* tp_name */
sizeof(bytesiterobject), /* tp_basicsize */
@@ -3285,16 +3285,16 @@ bytes_iter(PyObject *seq)
{
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;
}
diff --git a/Objects/longobject.c b/Objects/longobject.c
index fa0142f..d2557df 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -3518,13 +3518,13 @@ long_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return PyLong_FromUnicode(PyUnicode_AS_UNICODE(x),
PyUnicode_GET_SIZE(x),
base);
- else if (PyBytes_Check(x) || PyString_Check(x)) {
+ else if (PyByteArray_Check(x) || PyString_Check(x)) {
/* Since PyLong_FromString doesn't have a length parameter,
* check here for possible NULs in the string. */
char *string;
int size = Py_SIZE(x);
- if (PyBytes_Check(x))
- string = PyBytes_AS_STRING(x);
+ if (PyByteArray_Check(x))
+ string = PyByteArray_AS_STRING(x);
else
string = PyString_AS_STRING(x);
if (strlen(string) != size) {
diff --git a/Objects/memoryobject.c b/Objects/memoryobject.c
index c60c53c..27ceb7a 100644
--- a/Objects/memoryobject.c
+++ b/Objects/memoryobject.c
@@ -254,12 +254,12 @@ PyMemoryView_GetContiguous(PyObject *obj, int buffertype, char fort)
"for a non-contiguousobject.");
return NULL;
}
- bytes = PyBytes_FromStringAndSize(NULL, view->len);
+ bytes = PyByteArray_FromStringAndSize(NULL, view->len);
if (bytes == NULL) {
PyObject_ReleaseBuffer(obj, view);
return NULL;
}
- dest = PyBytes_AS_STRING(bytes);
+ dest = PyByteArray_AS_STRING(bytes);
/* different copying strategy depending on whether
or not any pointer de-referencing is needed
*/
@@ -382,7 +382,7 @@ static PyGetSetDef memory_getsetlist[] ={
static PyObject *
memory_tobytes(PyMemoryViewObject *mem, PyObject *noargs)
{
- return PyBytes_FromObject((PyObject *)mem);
+ return PyByteArray_FromObject((PyObject *)mem);
}
static PyObject *
@@ -451,8 +451,8 @@ memory_str(PyMemoryViewObject *self)
if (PyObject_GetBuffer((PyObject *)self, &view, PyBUF_FULL) < 0)
return NULL;
- res = PyBytes_FromStringAndSize(NULL, view.len);
- PyBuffer_ToContiguous(PyBytes_AS_STRING(res), &view, view.len, 'C');
+ res = PyByteArray_FromStringAndSize(NULL, view.len);
+ PyBuffer_ToContiguous(PyByteArray_AS_STRING(res), &view, view.len, 'C');
PyObject_ReleaseBuffer((PyObject *)self, &view);
return res;
}
@@ -522,7 +522,7 @@ memory_subscript(PyMemoryViewObject *self, PyObject *key)
{
ptr = *((char **)ptr) + view->suboffsets[0];
}
- return PyBytes_FromStringAndSize(ptr, view->itemsize);
+ return PyByteArray_FromStringAndSize(ptr, view->itemsize);
}
else {
/* Return a new memory-view object */
diff --git a/Objects/object.c b/Objects/object.c
index 0d317b2..5dc3436 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -1495,7 +1495,7 @@ _Py_ReadyTypes(void)
if (PyType_Ready(&PyBool_Type) < 0)
Py_FatalError("Can't initialize 'bool'");
- if (PyType_Ready(&PyBytes_Type) < 0)
+ if (PyType_Ready(&PyByteArray_Type) < 0)
Py_FatalError("Can't initialize 'bytes'");
if (PyType_Ready(&PyString_Type) < 0)
diff --git a/Objects/stringobject.c b/Objects/stringobject.c
index 0cc48c3..70f3a6c 100644
--- a/Objects/stringobject.c
+++ b/Objects/stringobject.c
@@ -1469,7 +1469,7 @@ string_join(PyObject *self, PyObject *orig)
for (i = 0; i < seqlen; i++) {
const size_t old_sz = sz;
item = PySequence_Fast_GET_ITEM(seq, i);
- if (!PyString_Check(item) && !PyBytes_Check(item)) {
+ if (!PyString_Check(item) && !PyByteArray_Check(item)) {
PyErr_Format(PyExc_TypeError,
"sequence item %zd: expected bytes,"
" %.80s found",
@@ -1496,7 +1496,7 @@ string_join(PyObject *self, PyObject *orig)
}
/* Catenate everything. */
- /* I'm not worried about a PyBytes item growing because there's
+ /* I'm not worried about a PyByteArray item growing because there's
nowhere in this function where we release the GIL. */
p = PyString_AS_STRING(res);
for (i = 0; i < seqlen; ++i) {
@@ -1511,7 +1511,7 @@ string_join(PyObject *self, PyObject *orig)
if (PyString_Check(item))
q = PyString_AS_STRING(item);
else
- q = PyBytes_AS_STRING(item);
+ q = PyByteArray_AS_STRING(item);
Py_MEMCPY(p, q, n);
p += n;
}
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 8201c7e..445d56a 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -1764,11 +1764,11 @@ PyObject *PyUnicode_EncodeUTF7(const Py_UNICODE *s,
if (size == 0)
return PyString_FromStringAndSize(NULL, 0);
- v = PyBytes_FromStringAndSize(NULL, cbAllocated);
+ v = PyByteArray_FromStringAndSize(NULL, cbAllocated);
if (v == NULL)
return NULL;
- start = out = PyBytes_AS_STRING(v);
+ start = out = PyByteArray_AS_STRING(v);
for (;i < size; ++i) {
Py_UNICODE ch = s[i];
@@ -1834,7 +1834,7 @@ PyObject *PyUnicode_EncodeUTF7(const Py_UNICODE *s,
*out++ = '-';
}
- result = PyString_FromStringAndSize(PyBytes_AS_STRING(v), out - start);
+ result = PyString_FromStringAndSize(PyByteArray_AS_STRING(v), out - start);
Py_DECREF(v);
return result;
}
@@ -2385,12 +2385,12 @@ PyUnicode_EncodeUTF32(const Py_UNICODE *s,
0xDC00 <= s[i+1] && s[i+1] <= 0xDFFF)
pairs++;
#endif
- v = PyBytes_FromStringAndSize(NULL,
+ v = PyByteArray_FromStringAndSize(NULL,
4 * (size - pairs + (byteorder == 0)));
if (v == NULL)
return NULL;
- p = (unsigned char *)PyBytes_AS_STRING(v);
+ p = (unsigned char *)PyByteArray_AS_STRING(v);
if (byteorder == 0)
STORECHAR(0xFEFF);
if (size == 0)
@@ -2427,7 +2427,7 @@ PyUnicode_EncodeUTF32(const Py_UNICODE *s,
}
done:
- result = PyString_FromStringAndSize(PyBytes_AS_STRING(v), Py_SIZE(v));
+ result = PyString_FromStringAndSize(PyByteArray_AS_STRING(v), Py_SIZE(v));
Py_DECREF(v);
return result;
#undef STORECHAR
@@ -2654,12 +2654,12 @@ PyUnicode_EncodeUTF16(const Py_UNICODE *s,
if (s[i] >= 0x10000)
pairs++;
#endif
- v = PyBytes_FromStringAndSize(NULL,
+ v = PyByteArray_FromStringAndSize(NULL,
2 * (size + pairs + (byteorder == 0)));
if (v == NULL)
return NULL;
- p = (unsigned char *)PyBytes_AS_STRING(v);
+ p = (unsigned char *)PyByteArray_AS_STRING(v);
if (byteorder == 0)
STORECHAR(0xFEFF);
if (size == 0)
@@ -2691,7 +2691,7 @@ PyUnicode_EncodeUTF16(const Py_UNICODE *s,
}
done:
- result = PyString_FromStringAndSize(PyBytes_AS_STRING(v), Py_SIZE(v));
+ result = PyString_FromStringAndSize(PyByteArray_AS_STRING(v), Py_SIZE(v));
Py_DECREF(v);
return result;
#undef STORECHAR
@@ -3004,7 +3004,7 @@ PyObject *PyUnicode_EncodeUnicodeEscape(const Py_UNICODE *s,
escape.
*/
- repr = PyBytes_FromStringAndSize(NULL,
+ repr = PyByteArray_FromStringAndSize(NULL,
#ifdef Py_UNICODE_WIDE
+ 10*size
#else
@@ -3014,7 +3014,7 @@ PyObject *PyUnicode_EncodeUnicodeEscape(const Py_UNICODE *s,
if (repr == NULL)
return NULL;
- p = PyBytes_AS_STRING(repr);
+ p = PyByteArray_AS_STRING(repr);
while (size-- > 0) {
Py_UNICODE ch = *s++;
@@ -3106,8 +3106,8 @@ PyObject *PyUnicode_EncodeUnicodeEscape(const Py_UNICODE *s,
*p++ = (char) ch;
}
- result = PyString_FromStringAndSize(PyBytes_AS_STRING(repr),
- p - PyBytes_AS_STRING(repr));
+ result = PyString_FromStringAndSize(PyByteArray_AS_STRING(repr),
+ p - PyByteArray_AS_STRING(repr));
Py_DECREF(repr);
return result;
}
@@ -3124,8 +3124,8 @@ PyObject *PyUnicode_AsUnicodeEscapeString(PyObject *unicode)
if (!s)
return NULL;
- result = PyString_FromStringAndSize(PyBytes_AS_STRING(s),
- PyBytes_GET_SIZE(s));
+ result = PyString_FromStringAndSize(PyByteArray_AS_STRING(s),
+ PyByteArray_GET_SIZE(s));
Py_DECREF(s);
return result;
}
@@ -3257,16 +3257,16 @@ PyObject *PyUnicode_EncodeRawUnicodeEscape(const Py_UNICODE *s,
char *q;
#ifdef Py_UNICODE_WIDE
- repr = PyBytes_FromStringAndSize(NULL, 10 * size);
+ repr = PyByteArray_FromStringAndSize(NULL, 10 * size);
#else
- repr = PyBytes_FromStringAndSize(NULL, 6 * size);
+ repr = PyByteArray_FromStringAndSize(NULL, 6 * size);
#endif
if (repr == NULL)
return NULL;
if (size == 0)
goto done;
- p = q = PyBytes_AS_STRING(repr);
+ p = q = PyByteArray_AS_STRING(repr);
while (size-- > 0) {
Py_UNICODE ch = *s++;
#ifdef Py_UNICODE_WIDE
@@ -3327,7 +3327,7 @@ PyObject *PyUnicode_EncodeRawUnicodeEscape(const Py_UNICODE *s,
size = p - q;
done:
- result = PyString_FromStringAndSize(PyBytes_AS_STRING(repr), size);
+ result = PyString_FromStringAndSize(PyByteArray_AS_STRING(repr), size);
Py_DECREF(repr);
return result;
}
@@ -3344,8 +3344,8 @@ PyObject *PyUnicode_AsRawUnicodeEscapeString(PyObject *unicode)
if (!s)
return NULL;
- result = PyString_FromStringAndSize(PyBytes_AS_STRING(s),
- PyBytes_GET_SIZE(s));
+ result = PyString_FromStringAndSize(PyByteArray_AS_STRING(s),
+ PyByteArray_GET_SIZE(s));
Py_DECREF(s);
return result;
}
@@ -3578,10 +3578,10 @@ static PyObject *unicode_encode_ucs1(const Py_UNICODE *p,
replacements, if we need more, we'll resize */
if (size == 0)
return PyString_FromStringAndSize(NULL, 0);
- res = PyBytes_FromStringAndSize(NULL, size);
+ res = PyByteArray_FromStringAndSize(NULL, size);
if (res == NULL)
return NULL;
- str = PyBytes_AS_STRING(res);
+ str = PyByteArray_AS_STRING(res);
ressize = size;
while (p<endp) {
@@ -3631,7 +3631,7 @@ static PyObject *unicode_encode_ucs1(const Py_UNICODE *p,
p = collend;
break;
case 4: /* xmlcharrefreplace */
- respos = str - PyBytes_AS_STRING(res);
+ respos = str - PyByteArray_AS_STRING(res);
/* determine replacement size (temporarily (mis)uses p) */
for (p = collstart, repsize = 0; p < collend; ++p) {
if (*p<10)
@@ -3658,9 +3658,9 @@ static PyObject *unicode_encode_ucs1(const Py_UNICODE *p,
if (requiredsize > ressize) {
if (requiredsize<2*ressize)
requiredsize = 2*ressize;
- if (PyBytes_Resize(res, requiredsize))
+ if (PyByteArray_Resize(res, requiredsize))
goto onError;
- str = PyBytes_AS_STRING(res) + respos;
+ str = PyByteArray_AS_STRING(res) + respos;
ressize = requiredsize;
}
/* generate replacement (temporarily (mis)uses p) */
@@ -3678,17 +3678,17 @@ static PyObject *unicode_encode_ucs1(const Py_UNICODE *p,
/* need more space? (at least enough for what we
have+the replacement+the rest of the string, so
we won't have to check space for encodable characters) */
- respos = str - PyBytes_AS_STRING(res);
+ respos = str - PyByteArray_AS_STRING(res);
repsize = PyUnicode_GET_SIZE(repunicode);
requiredsize = respos+repsize+(endp-collend);
if (requiredsize > ressize) {
if (requiredsize<2*ressize)
requiredsize = 2*ressize;
- if (PyBytes_Resize(res, requiredsize)) {
+ if (PyByteArray_Resize(res, requiredsize)) {
Py_DECREF(repunicode);
goto onError;
}
- str = PyBytes_AS_STRING(res) + respos;
+ str = PyByteArray_AS_STRING(res) + respos;
ressize = requiredsize;
}
/* check if there is anything unencodable in the replacement
@@ -3708,8 +3708,8 @@ static PyObject *unicode_encode_ucs1(const Py_UNICODE *p,
}
}
}
- result = PyString_FromStringAndSize(PyBytes_AS_STRING(res),
- str - PyBytes_AS_STRING(res));
+ result = PyString_FromStringAndSize(PyByteArray_AS_STRING(res),
+ str - PyByteArray_AS_STRING(res));
onError:
Py_DECREF(res);
Py_XDECREF(errorHandler);
diff --git a/PC/winreg.c b/PC/winreg.c
index 1b141d3..8316f6c 100644
--- a/PC/winreg.c
+++ b/PC/winreg.c
@@ -908,7 +908,7 @@ Reg2Py(BYTE *retDataBuf, DWORD retDataSize, DWORD typ)
obData = Py_None;
}
else
- obData = PyBytes_FromStringAndSize(
+ obData = PyByteArray_FromStringAndSize(
(char *)retDataBuf, retDataSize);
break;
}
diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c
index 9de0846..550d224d 100644
--- a/Parser/tokenizer.c
+++ b/Parser/tokenizer.c
@@ -360,7 +360,7 @@ check_bom(int get_char(struct tok_state *),
1) NULL: need to call tok->decoding_readline to get a new line
2) PyUnicodeObject *: decoding_feof has called tok->decoding_readline and
stored the result in tok->decoding_buffer
- 3) PyBytesObject *: previous call to fp_readl did not have enough room
+ 3) PyByteArrayObject *: previous call to fp_readl did not have enough room
(in the s buffer) to copy entire contents of the line read
by tok->decoding_readline. tok->decoding_buffer has the overflow.
In this case, fp_readl is called in a loop (with an expanded buffer)
@@ -398,17 +398,17 @@ fp_readl(char *s, int size, struct tok_state *tok)
}
else
{
- buf = PyBytes_AsString(bufobj);
+ buf = PyByteArray_AsString(bufobj);
if (buf == NULL) {
goto error;
}
- buflen = PyBytes_GET_SIZE(bufobj);
+ buflen = PyByteArray_GET_SIZE(bufobj);
}
Py_XDECREF(tok->decoding_buffer);
if (buflen > size) {
/* Too many chars, the rest goes into tok->decoding_buffer */
- tok->decoding_buffer = PyBytes_FromStringAndSize(buf+size,
+ tok->decoding_buffer = PyByteArray_FromStringAndSize(buf+size,
buflen-size);
if (tok->decoding_buffer == NULL)
goto error;
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index 23e87b3..4ff0823 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -1377,11 +1377,11 @@ builtin_ord(PyObject *self, PyObject* obj)
}
#endif
}
- else if (PyBytes_Check(obj)) {
+ else if (PyByteArray_Check(obj)) {
/* XXX Hopefully this is temporary */
- size = PyBytes_GET_SIZE(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 PyLong_FromLong(ord);
}
}
@@ -1823,7 +1823,7 @@ builtin_sum(PyObject *self, PyObject *args)
Py_DECREF(iter);
return NULL;
}
- if (PyBytes_Check(result)) {
+ if (PyByteArray_Check(result)) {
PyErr_SetString(PyExc_TypeError,
"sum() can't sum bytes [use b''.join(seq) instead]");
Py_DECREF(iter);
@@ -2266,7 +2266,7 @@ _PyBuiltin_Init(void)
SETBUILTIN("True", Py_True);
SETBUILTIN("bool", &PyBool_Type);
SETBUILTIN("memoryview", &PyMemoryView_Type);
- SETBUILTIN("bytearray", &PyBytes_Type);
+ SETBUILTIN("bytearray", &PyByteArray_Type);
SETBUILTIN("bytes", &PyString_Type);
SETBUILTIN("classmethod", &PyClassMethod_Type);
#ifndef WITHOUT_COMPLEX
diff --git a/Python/codecs.c b/Python/codecs.c
index 86941b1..554c1d2 100644
--- a/Python/codecs.c
+++ b/Python/codecs.c
@@ -345,7 +345,7 @@ PyObject *PyCodec_Encode(PyObject *object,
goto onError;
}
v = PyTuple_GET_ITEM(result, 0);
- if (PyBytes_Check(v)) {
+ if (PyByteArray_Check(v)) {
char msg[100];
PyOS_snprintf(msg, sizeof(msg),
"encoder %s returned buffer instead of bytes",
@@ -354,7 +354,7 @@ PyObject *PyCodec_Encode(PyObject *object,
v = NULL;
goto onError;
}
- v = PyString_FromStringAndSize(PyBytes_AS_STRING(v), Py_SIZE(v));
+ v = PyString_FromStringAndSize(PyByteArray_AS_STRING(v), Py_SIZE(v));
}
else if (PyString_Check(v))
Py_INCREF(v);
diff --git a/Python/getargs.c b/Python/getargs.c
index 7ca7672..2289bb6 100644
--- a/Python/getargs.c
+++ b/Python/getargs.c
@@ -971,7 +971,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
/* Encode object */
if (!recode_strings &&
- (PyString_Check(arg) || PyBytes_Check(arg))) {
+ (PyString_Check(arg) || PyByteArray_Check(arg))) {
s = arg;
Py_INCREF(s);
if (PyObject_AsCharBuffer(s, &ptr, &size) < 0)
@@ -1123,9 +1123,9 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
break;
}
- case 'Y': { /* PyBytes object */
+ case 'Y': { /* PyByteArray object */
PyObject **p = va_arg(*p_va, PyObject **);
- if (PyBytes_Check(arg))
+ if (PyByteArray_Check(arg))
*p = arg;
else
return converterr("buffer", arg, msgbuf, bufsize);
diff --git a/Python/marshal.c b/Python/marshal.c
index ce828da..5672a06 100644
--- a/Python/marshal.c
+++ b/Python/marshal.c
@@ -1095,7 +1095,7 @@ PyMarshal_WriteObjectToString(PyObject *x, int version)
}
if (wf.str != NULL) {
/* XXX Quick hack -- need to do this differently */
- res = PyBytes_FromObject(wf.str);
+ res = PyByteArray_FromObject(wf.str);
Py_DECREF(wf.str);
}
return res;
@@ -1136,9 +1136,9 @@ marshal_load(PyObject *self, PyObject *f)
rf.ptr = PyString_AS_STRING(data);
rf.end = rf.ptr + PyString_GET_SIZE(data);
}
- else if (PyBytes_Check(data)) {
- rf.ptr = PyBytes_AS_STRING(data);
- rf.end = rf.ptr + PyBytes_GET_SIZE(data);
+ else if (PyByteArray_Check(data)) {
+ rf.ptr = PyByteArray_AS_STRING(data);
+ rf.end = rf.ptr + PyByteArray_GET_SIZE(data);
}
else {
PyErr_Format(PyExc_TypeError,
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index e2bddcb..7f6966a 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -175,7 +175,7 @@ Py_InitializeEx(int install_sigs)
if (!_PyLong_Init())
Py_FatalError("Py_Initialize: can't init longs");
- if (!PyBytes_Init())
+ if (!PyByteArray_Init())
Py_FatalError("Py_Initialize: can't init bytes");
_PyFloat_Init();
@@ -460,7 +460,7 @@ Py_Finalize(void)
PyList_Fini();
PySet_Fini();
PyString_Fini();
- PyBytes_Fini();
+ PyByteArray_Fini();
PyLong_Fini();
PyFloat_Fini();
PyDict_Fini();