Renamed PyBytes to PyByteArray

This commit is contained in:
Christian Heimes 2008-05-26 13:22:05 +00:00
parent 96d02f3c1e
commit 9c4756ea26
31 changed files with 397 additions and 397 deletions

View file

@ -2,7 +2,7 @@
#define Py_BYTES_CTYPE_H #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. * methods of the given names, they operate on ASCII byte strings.
*/ */
extern PyObject* _Py_bytes_isspace(const char *cptr, Py_ssize_t len); extern PyObject* _Py_bytes_isspace(const char *cptr, Py_ssize_t len);

View file

@ -8,7 +8,7 @@ extern "C" {
#include <stdarg.h> #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 Python API is that of a sequence;
* the bytes are mapped to ints in [0, 256). * the bytes are mapped to ints in [0, 256).
* Bytes are not characters; they may be used to encode characters. * Bytes are not characters; they may be used to encode characters.
@ -25,27 +25,27 @@ typedef struct {
int ob_exports; /* how many buffer exports */ int ob_exports; /* how many buffer exports */
Py_ssize_t ob_alloc; /* How many bytes allocated */ Py_ssize_t ob_alloc; /* How many bytes allocated */
char *ob_bytes; char *ob_bytes;
} PyBytesObject; } PyByteArrayObject;
/* Type object */ /* Type object */
PyAPI_DATA(PyTypeObject) PyBytes_Type; PyAPI_DATA(PyTypeObject) PyByteArray_Type;
PyAPI_DATA(PyTypeObject) PyBytesIter_Type; PyAPI_DATA(PyTypeObject) PyByteArrayIter_Type;
/* Type check macros */ /* Type check macros */
#define PyBytes_Check(self) PyObject_TypeCheck(self, &PyBytes_Type) #define PyByteArray_Check(self) PyObject_TypeCheck(self, &PyByteArray_Type)
#define PyBytes_CheckExact(self) (Py_TYPE(self) == &PyBytes_Type) #define PyByteArray_CheckExact(self) (Py_TYPE(self) == &PyByteArray_Type)
/* Direct API functions */ /* Direct API functions */
PyAPI_FUNC(PyObject *) PyBytes_FromObject(PyObject *); PyAPI_FUNC(PyObject *) PyByteArray_FromObject(PyObject *);
PyAPI_FUNC(PyObject *) PyBytes_Concat(PyObject *, PyObject *); PyAPI_FUNC(PyObject *) PyByteArray_Concat(PyObject *, PyObject *);
PyAPI_FUNC(PyObject *) PyBytes_FromStringAndSize(const char *, Py_ssize_t); PyAPI_FUNC(PyObject *) PyByteArray_FromStringAndSize(const char *, Py_ssize_t);
PyAPI_FUNC(Py_ssize_t) PyBytes_Size(PyObject *); PyAPI_FUNC(Py_ssize_t) PyByteArray_Size(PyObject *);
PyAPI_FUNC(char *) PyBytes_AsString(PyObject *); PyAPI_FUNC(char *) PyByteArray_AsString(PyObject *);
PyAPI_FUNC(int) PyBytes_Resize(PyObject *, Py_ssize_t); PyAPI_FUNC(int) PyByteArray_Resize(PyObject *, Py_ssize_t);
/* Macros, trading safety for speed */ /* Macros, trading safety for speed */
#define PyBytes_AS_STRING(self) (assert(PyBytes_Check(self)),((PyBytesObject *)(self))->ob_bytes) #define PyByteArray_AS_STRING(self) (assert(PyByteArray_Check(self)),((PyByteArrayObject *)(self))->ob_bytes)
#define PyBytes_GET_SIZE(self) (assert(PyBytes_Check(self)),Py_SIZE(self)) #define PyByteArray_GET_SIZE(self) (assert(PyByteArray_Check(self)),Py_SIZE(self))
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -126,7 +126,7 @@ PyAPI_FUNC(void) _PyExc_Init(void);
PyAPI_FUNC(void) _PyImportHooks_Init(void); PyAPI_FUNC(void) _PyImportHooks_Init(void);
PyAPI_FUNC(int) _PyFrame_Init(void); PyAPI_FUNC(int) _PyFrame_Init(void);
PyAPI_FUNC(void) _PyFloat_Init(void); PyAPI_FUNC(void) _PyFloat_Init(void);
PyAPI_FUNC(int) PyBytes_Init(void); PyAPI_FUNC(int) PyByteArray_Init(void);
/* Various internal finalizers */ /* Various internal finalizers */
PyAPI_FUNC(void) _PyExc_Fini(void); 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) PyList_Fini(void);
PyAPI_FUNC(void) PySet_Fini(void); PyAPI_FUNC(void) PySet_Fini(void);
PyAPI_FUNC(void) PyString_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) PyFloat_Fini(void);
PyAPI_FUNC(void) PyOS_FiniInterrupts(void); PyAPI_FUNC(void) PyOS_FiniInterrupts(void);

View file

@ -1174,14 +1174,14 @@ _db_associateCallback(DB* db, const DBT* priKey, const DBT* priData,
else if (PyLong_Check(result)) { else if (PyLong_Check(result)) {
retval = PyLong_AsLong(result); retval = PyLong_AsLong(result);
} }
else if (PyBytes_Check(result) || PyString_Check(result)) { else if (PyByteArray_Check(result) || PyString_Check(result)) {
char* data; char* data;
Py_ssize_t size; Py_ssize_t size;
CLEAR_DBT(*secKey); CLEAR_DBT(*secKey);
size = Py_SIZE(result); size = Py_SIZE(result);
if (PyBytes_Check(result)) if (PyByteArray_Check(result))
data = PyBytes_AS_STRING(result); data = PyByteArray_AS_STRING(result);
else else
data = PyString_AS_STRING(result); data = PyString_AS_STRING(result);
secKey->flags = DB_DBT_APPMALLOC; /* DB will free */ secKey->flags = DB_DBT_APPMALLOC; /* DB will free */

View file

@ -1596,7 +1596,7 @@ c_void_p_from_param(PyObject *type, PyObject *value)
return (PyObject *)parg; return (PyObject *)parg;
} }
/* bytes */ /* bytes */
if (PyBytes_Check(value)) { if (PyByteArray_Check(value)) {
PyCArgObject *parg; PyCArgObject *parg;
struct fielddesc *fd = getentry("z"); struct fielddesc *fd = getentry("z");

View file

@ -1172,8 +1172,8 @@ c_set(void *ptr, PyObject *value, Py_ssize_t size)
*(char *)ptr = PyString_AS_STRING(value)[0]; *(char *)ptr = PyString_AS_STRING(value)[0];
_RET(value); _RET(value);
} }
if (PyBytes_Check(value) && PyBytes_GET_SIZE(value) == 1) { if (PyByteArray_Check(value) && PyByteArray_GET_SIZE(value) == 1) {
*(char *)ptr = PyBytes_AS_STRING(value)[0]; *(char *)ptr = PyByteArray_AS_STRING(value)[0];
_RET(value); _RET(value);
} }
if (PyLong_Check(value)) if (PyLong_Check(value))

View file

@ -111,7 +111,7 @@ dbm_subscript(dbmobject *dp, register PyObject *key)
PyErr_SetString(DbmError, ""); PyErr_SetString(DbmError, "");
return NULL; return NULL;
} }
return PyBytes_FromStringAndSize(drec.dptr, drec.dsize); return PyByteArray_FromStringAndSize(drec.dptr, drec.dsize);
} }
static int static int
@ -188,7 +188,7 @@ dbm_keys(register dbmobject *dp, PyObject *unused)
return NULL; return NULL;
for (key = dbm_firstkey(dp->di_dbm); key.dptr; for (key = dbm_firstkey(dp->di_dbm); key.dptr;
key = dbm_nextkey(dp->di_dbm)) { key = dbm_nextkey(dp->di_dbm)) {
item = PyBytes_FromStringAndSize(key.dptr, key.dsize); item = PyByteArray_FromStringAndSize(key.dptr, key.dsize);
if (item == NULL) { if (item == NULL) {
Py_DECREF(v); Py_DECREF(v);
return NULL; return NULL;
@ -260,7 +260,7 @@ dbm_get(register dbmobject *dp, PyObject *args)
check_dbmobject_open(dp); check_dbmobject_open(dp);
val = dbm_fetch(dp->di_dbm, key); val = dbm_fetch(dp->di_dbm, key);
if (val.dptr != NULL) if (val.dptr != NULL)
return PyBytes_FromStringAndSize(val.dptr, val.dsize); return PyByteArray_FromStringAndSize(val.dptr, val.dsize);
else { else {
Py_INCREF(defvalue); Py_INCREF(defvalue);
return defvalue; return defvalue;
@ -283,9 +283,9 @@ dbm_setdefault(register dbmobject *dp, PyObject *args)
check_dbmobject_open(dp); check_dbmobject_open(dp);
val = dbm_fetch(dp->di_dbm, key); val = dbm_fetch(dp->di_dbm, key);
if (val.dptr != NULL) if (val.dptr != NULL)
return PyBytes_FromStringAndSize(val.dptr, val.dsize); return PyByteArray_FromStringAndSize(val.dptr, val.dsize);
if (defvalue == NULL) { if (defvalue == NULL) {
defvalue = PyBytes_FromStringAndSize(NULL, 0); defvalue = PyByteArray_FromStringAndSize(NULL, 0);
if (defvalue == NULL) if (defvalue == NULL)
return NULL; return NULL;
val.dptr = NULL; val.dptr = NULL;

View file

@ -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'", PyOS_snprintf(buf, sizeof(buf) - 1, "Could not decode to UTF-8 column '%s' with text '%s'",
colname , val_str); colname , val_str);
buf_bytes = PyBytes_FromStringAndSize(buf, strlen(buf)); buf_bytes = PyByteArray_FromStringAndSize(buf, strlen(buf));
if (!buf_bytes) { if (!buf_bytes) {
PyErr_SetString(pysqlite_OperationalError, "Could not decode to UTF-8"); PyErr_SetString(pysqlite_OperationalError, "Could not decode to UTF-8");
} else { } else {
@ -368,8 +368,8 @@ PyObject* _pysqlite_fetch_one_row(pysqlite_Cursor* self)
} }
} else if (self->connection->text_factory == (PyObject*)&PyString_Type) { } else if (self->connection->text_factory == (PyObject*)&PyString_Type) {
converted = PyString_FromString(val_str); converted = PyString_FromString(val_str);
} else if (self->connection->text_factory == (PyObject*)&PyBytes_Type) { } else if (self->connection->text_factory == (PyObject*)&PyByteArray_Type) {
converted = PyBytes_FromStringAndSize(val_str, strlen(val_str)); converted = PyByteArray_FromStringAndSize(val_str, strlen(val_str));
} else { } else {
converted = PyObject_CallFunction(self->connection->text_factory, "y", val_str); converted = PyObject_CallFunction(self->connection->text_factory, "y", val_str);
} }

View file

@ -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 /* a basic type is adapted; there's a performance optimization if that's not the case
* (99 % of all usages) */ * (99 % of all usages) */
if (type == &PyLong_Type || type == &PyFloat_Type if (type == &PyLong_Type || type == &PyFloat_Type
|| type == &PyUnicode_Type || type == &PyBytes_Type) { || type == &PyUnicode_Type || type == &PyByteArray_Type) {
pysqlite_BaseTypeAdapted = 1; pysqlite_BaseTypeAdapted = 1;
} }

View file

@ -167,7 +167,7 @@ static int _need_adapt(PyObject* obj)
} }
if (PyLong_CheckExact(obj) || PyFloat_CheckExact(obj) if (PyLong_CheckExact(obj) || PyFloat_CheckExact(obj)
|| PyUnicode_CheckExact(obj) || PyBytes_CheckExact(obj)) { || PyUnicode_CheckExact(obj) || PyByteArray_CheckExact(obj)) {
return 0; return 0;
} else { } else {
return 1; return 1;

View file

@ -1263,16 +1263,16 @@ static PyObject *PySSL_SSLread(PySSLObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "|Oi:read", &buf, &count)) if (!PyArg_ParseTuple(args, "|Oi:read", &buf, &count))
return NULL; return NULL;
if ((buf == NULL) || (buf == Py_None)) { if ((buf == NULL) || (buf == Py_None)) {
if (!(buf = PyBytes_FromStringAndSize((char *) 0, len))) if (!(buf = PyByteArray_FromStringAndSize((char *) 0, len)))
return NULL; return NULL;
} else if (PyLong_Check(buf)) { } else if (PyLong_Check(buf)) {
len = PyLong_AS_LONG(buf); len = PyLong_AS_LONG(buf);
if (!(buf = PyBytes_FromStringAndSize((char *) 0, len))) if (!(buf = PyByteArray_FromStringAndSize((char *) 0, len)))
return NULL; return NULL;
} else { } else {
if (!PyBytes_Check(buf)) if (!PyByteArray_Check(buf))
return NULL; return NULL;
len = PyBytes_Size(buf); len = PyByteArray_Size(buf);
if ((count > 0) && (count <= len)) if ((count > 0) && (count <= len))
len = count; len = count;
buf_passed = 1; buf_passed = 1;
@ -1313,7 +1313,7 @@ static PyObject *PySSL_SSLread(PySSLObject *self, PyObject *args)
do { do {
err = 0; err = 0;
PySSL_BEGIN_ALLOW_THREADS 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); err = SSL_get_error(self->ssl, count);
PySSL_END_ALLOW_THREADS PySSL_END_ALLOW_THREADS
if(PyErr_CheckSignals()) { if(PyErr_CheckSignals()) {
@ -1357,7 +1357,7 @@ static PyObject *PySSL_SSLread(PySSLObject *self, PyObject *args)
done: done:
if (!buf_passed) { if (!buf_passed) {
PyObject *res = PyString_FromStringAndSize( PyObject *res = PyString_FromStringAndSize(
PyBytes_AS_STRING(buf), count); PyByteArray_AS_STRING(buf), count);
Py_DECREF(buf); Py_DECREF(buf);
return res; return res;
} else { } else {

View file

@ -1646,7 +1646,7 @@ s_pack_internal(PyStructObject *soself, PyObject *args, int offset, char* buf)
return -1; return -1;
} }
isstring = PyString_Check(v); isstring = PyString_Check(v);
if (!isstring && !PyBytes_Check(v)) { if (!isstring && !PyByteArray_Check(v)) {
PyErr_SetString(StructError, PyErr_SetString(StructError,
"argument for 's' must be a string"); "argument for 's' must be a string");
return -1; return -1;
@ -1656,8 +1656,8 @@ s_pack_internal(PyStructObject *soself, PyObject *args, int offset, char* buf)
p = PyString_AS_STRING(v); p = PyString_AS_STRING(v);
} }
else { else {
n = PyBytes_GET_SIZE(v); n = PyByteArray_GET_SIZE(v);
p = PyBytes_AS_STRING(v); p = PyByteArray_AS_STRING(v);
} }
if (n > code->size) if (n > code->size)
n = code->size; n = code->size;
@ -1672,7 +1672,7 @@ s_pack_internal(PyStructObject *soself, PyObject *args, int offset, char* buf)
return -1; return -1;
} }
isstring = PyString_Check(v); isstring = PyString_Check(v);
if (!isstring && !PyBytes_Check(v)) { if (!isstring && !PyByteArray_Check(v)) {
PyErr_SetString(StructError, PyErr_SetString(StructError,
"argument for 'p' must be a string"); "argument for 'p' must be a string");
return -1; return -1;
@ -1682,8 +1682,8 @@ s_pack_internal(PyStructObject *soself, PyObject *args, int offset, char* buf)
p = PyString_AS_STRING(v); p = PyString_AS_STRING(v);
} }
else { else {
n = PyBytes_GET_SIZE(v); n = PyByteArray_GET_SIZE(v);
p = PyBytes_AS_STRING(v); p = PyByteArray_AS_STRING(v);
} }
if (n > (code->size - 1)) if (n > (code->size - 1))
n = code->size - 1; n = code->size - 1;

View file

@ -1855,7 +1855,7 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return NULL; return NULL;
if (!(initial == NULL || PyList_Check(initial) if (!(initial == NULL || PyList_Check(initial)
|| PyBytes_Check(initial) || PyByteArray_Check(initial)
|| PyString_Check(initial) || PyString_Check(initial)
|| PyTuple_Check(initial) || PyTuple_Check(initial)
|| ((c=='u') && PyUnicode_Check(initial)))) { || ((c=='u') && PyUnicode_Check(initial)))) {
@ -1901,7 +1901,7 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
Py_DECREF(v); Py_DECREF(v);
} }
} }
else if (initial != NULL && (PyBytes_Check(initial) || else if (initial != NULL && (PyByteArray_Check(initial) ||
PyString_Check(initial))) { PyString_Check(initial))) {
PyObject *t_initial, *v; PyObject *t_initial, *v;
t_initial = PyTuple_Pack(1, initial); t_initial = PyTuple_Pack(1, initial);

View file

@ -228,7 +228,7 @@ mmap_read_line_method(mmap_object *self,
else else
++eol; /* we're interested in the position after the ++eol; /* we're interested in the position after the
newline. */ newline. */
result = PyBytes_FromStringAndSize(start, (eol - start)); result = PyByteArray_FromStringAndSize(start, (eol - start));
self->pos += (eol - start); self->pos += (eol - start);
return result; return result;
} }
@ -248,7 +248,7 @@ mmap_read_method(mmap_object *self,
if ((self->pos + num_bytes) > self->size) { if ((self->pos + num_bytes) > self->size) {
num_bytes -= (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; self->pos += num_bytes;
return result; return result;
} }
@ -679,7 +679,7 @@ mmap_item(mmap_object *self, Py_ssize_t i)
PyErr_SetString(PyExc_IndexError, "mmap index out of range"); PyErr_SetString(PyExc_IndexError, "mmap index out of range");
return NULL; return NULL;
} }
return PyBytes_FromStringAndSize(self->data + i, 1); return PyByteArray_FromStringAndSize(self->data + i, 1);
} }
static PyObject * 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"); "mmap object doesn't support item deletion");
return -1; return -1;
} }
if (! (PyBytes_Check(v) && PyBytes_Size(v)==1) ) { if (! (PyByteArray_Check(v) && PyByteArray_Size(v)==1) ) {
PyErr_SetString(PyExc_IndexError, PyErr_SetString(PyExc_IndexError,
"mmap assignment must be length-1 bytes()"); "mmap assignment must be length-1 bytes()");
return -1; return -1;
} }
if (!is_writable(self)) if (!is_writable(self))
return -1; return -1;
buf = PyBytes_AsString(v); buf = PyByteArray_AsString(v);
self->data[i] = buf[0]; self->data[i] = buf[0];
return 0; return 0;
} }

View file

@ -366,10 +366,10 @@ oss_read(oss_audio_t *self, PyObject *args)
if (!PyArg_ParseTuple(args, "i:read", &size)) if (!PyArg_ParseTuple(args, "i:read", &size))
return NULL; return NULL;
rv = PyBytes_FromStringAndSize(NULL, size); rv = PyByteArray_FromStringAndSize(NULL, size);
if (rv == NULL) if (rv == NULL)
return NULL; return NULL;
cp = PyBytes_AS_STRING(rv); cp = PyByteArray_AS_STRING(rv);
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
count = read(self->fd, cp, size); count = read(self->fd, cp, size);
@ -381,7 +381,7 @@ oss_read(oss_audio_t *self, PyObject *args)
return NULL; return NULL;
} }
self->icount += count; self->icount += count;
PyBytes_Resize(rv, count); PyByteArray_Resize(rv, count);
return rv; return rv;
} }

View file

@ -866,8 +866,8 @@ readinst(char *buf, int buf_size, PyObject *meth)
if (PyString_Check(str)) if (PyString_Check(str))
ptr = PyString_AS_STRING(str); ptr = PyString_AS_STRING(str);
else if (PyBytes_Check(str)) else if (PyByteArray_Check(str))
ptr = PyBytes_AS_STRING(str); ptr = PyByteArray_AS_STRING(str);
else { else {
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
"read() did not return a bytes object (type=%.400s)", "read() did not return a bytes object (type=%.400s)",

View file

@ -467,7 +467,7 @@ zipimporter_get_source(PyObject *obj, PyObject *args)
toc_entry = PyDict_GetItemString(self->files, path); toc_entry = PyDict_GetItemString(self->files, path);
if (toc_entry != NULL) { if (toc_entry != NULL) {
PyObject *bytes = get_data(PyUnicode_AsString(self->archive), toc_entry); 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); Py_XDECREF(bytes);
return res; return res;
} }
@ -836,13 +836,13 @@ get_data(char *archive, PyObject *toc_entry)
bytes_size = compress == 0 ? data_size : data_size + 1; bytes_size = compress == 0 ? data_size : data_size + 1;
if (bytes_size == 0) if (bytes_size == 0)
bytes_size++; bytes_size++;
raw_data = PyBytes_FromStringAndSize((char *)NULL, bytes_size); raw_data = PyByteArray_FromStringAndSize((char *)NULL, bytes_size);
if (raw_data == NULL) { if (raw_data == NULL) {
fclose(fp); fclose(fp);
return NULL; return NULL;
} }
buf = PyBytes_AsString(raw_data); buf = PyByteArray_AsString(raw_data);
err = fseek(fp, file_offset, 0); err = fseek(fp, file_offset, 0);
if (err == 0) if (err == 0)
@ -862,7 +862,7 @@ get_data(char *archive, PyObject *toc_entry)
buf[data_size] = '\0'; buf[data_size] = '\0';
if (compress == 0) { /* data is not compressed */ if (compress == 0) { /* data is not compressed */
data = PyBytes_FromStringAndSize(buf, data_size); data = PyByteArray_FromStringAndSize(buf, data_size);
Py_DECREF(raw_data); Py_DECREF(raw_data);
return data; return data;
} }
@ -903,8 +903,8 @@ static PyObject *
unmarshal_code(char *pathname, PyObject *data, time_t mtime) unmarshal_code(char *pathname, PyObject *data, time_t mtime)
{ {
PyObject *code; PyObject *code;
char *buf = PyBytes_AsString(data); char *buf = PyByteArray_AsString(data);
Py_ssize_t size = PyBytes_Size(data); Py_ssize_t size = PyByteArray_Size(data);
if (size <= 9) { if (size <= 9) {
PyErr_SetString(ZipImportError, PyErr_SetString(ZipImportError,
@ -949,16 +949,16 @@ unmarshal_code(char *pathname, PyObject *data, time_t mtime)
static PyObject * static PyObject *
normalize_line_endings(PyObject *source) normalize_line_endings(PyObject *source)
{ {
char *buf, *q, *p = PyBytes_AsString(source); char *buf, *q, *p = PyByteArray_AsString(source);
PyObject *fixed_source; PyObject *fixed_source;
int len = 0; int len = 0;
if (!p) { 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 */ /* 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) { if (buf == NULL) {
PyErr_SetString(PyExc_MemoryError, PyErr_SetString(PyExc_MemoryError,
"zipimport: no memory to allocate " "zipimport: no memory to allocate "
@ -978,7 +978,7 @@ normalize_line_endings(PyObject *source)
} }
*q++ = '\n'; /* add trailing \n */ *q++ = '\n'; /* add trailing \n */
*q = '\0'; *q = '\0';
fixed_source = PyBytes_FromStringAndSize(buf, len + 2); fixed_source = PyByteArray_FromStringAndSize(buf, len + 2);
PyMem_Free(buf); PyMem_Free(buf);
return fixed_source; return fixed_source;
} }
@ -994,7 +994,7 @@ compile_source(char *pathname, PyObject *source)
if (fixed_source == NULL) if (fixed_source == NULL)
return NULL; return NULL;
code = Py_CompileString(PyBytes_AsString(fixed_source), pathname, code = Py_CompileString(PyByteArray_AsString(fixed_source), pathname,
Py_file_input); Py_file_input);
Py_DECREF(fixed_source); Py_DECREF(fixed_source);
return code; return code;

View file

@ -96,12 +96,12 @@ newcompobject(PyTypeObject *type)
if (self == NULL) if (self == NULL)
return NULL; return NULL;
self->is_initialised = 0; self->is_initialised = 0;
self->unused_data = PyBytes_FromStringAndSize("", 0); self->unused_data = PyByteArray_FromStringAndSize("", 0);
if (self->unused_data == NULL) { if (self->unused_data == NULL) {
Py_DECREF(self); Py_DECREF(self);
return NULL; return NULL;
} }
self->unconsumed_tail = PyBytes_FromStringAndSize("", 0); self->unconsumed_tail = PyByteArray_FromStringAndSize("", 0);
if (self->unconsumed_tail == NULL) { if (self->unconsumed_tail == NULL) {
Py_DECREF(self); Py_DECREF(self);
return NULL; return NULL;
@ -174,7 +174,7 @@ PyZlib_compress(PyObject *self, PyObject *args)
err=deflateEnd(&zst); err=deflateEnd(&zst);
if (err == Z_OK) if (err == Z_OK)
ReturnVal = PyBytes_FromStringAndSize((char *)output, ReturnVal = PyByteArray_FromStringAndSize((char *)output,
zst.total_out); zst.total_out);
else else
zlib_error(zst, err, "while finishing compression"); zlib_error(zst, err, "while finishing compression");
@ -211,12 +211,12 @@ PyZlib_decompress(PyObject *self, PyObject *args)
zst.avail_in = length; zst.avail_in = length;
zst.avail_out = r_strlen; zst.avail_out = r_strlen;
if (!(result_str = PyBytes_FromStringAndSize(NULL, r_strlen))) if (!(result_str = PyByteArray_FromStringAndSize(NULL, r_strlen)))
return NULL; return NULL;
zst.zalloc = (alloc_func)NULL; zst.zalloc = (alloc_func)NULL;
zst.zfree = (free_func)Z_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; zst.next_in = (Byte *)input;
err = inflateInit2(&zst, wsize); err = inflateInit2(&zst, wsize);
@ -256,12 +256,12 @@ PyZlib_decompress(PyObject *self, PyObject *args)
/* fall through */ /* fall through */
case(Z_OK): case(Z_OK):
/* need more memory */ /* need more memory */
if (PyBytes_Resize(result_str, r_strlen << 1) < 0) { if (PyByteArray_Resize(result_str, r_strlen << 1) < 0) {
inflateEnd(&zst); inflateEnd(&zst);
goto error; goto error;
} }
zst.next_out = 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; zst.avail_out = r_strlen;
r_strlen = r_strlen << 1; r_strlen = r_strlen << 1;
break; break;
@ -278,7 +278,7 @@ PyZlib_decompress(PyObject *self, PyObject *args)
goto error; goto error;
} }
if (PyBytes_Resize(result_str, zst.total_out) < 0) if (PyByteArray_Resize(result_str, zst.total_out) < 0)
goto error; goto error;
return result_str; return result_str;
@ -402,7 +402,7 @@ PyZlib_objcompress(compobject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "s#:compress", &input, &inplen)) if (!PyArg_ParseTuple(args, "s#:compress", &input, &inplen))
return NULL; return NULL;
if (!(RetVal = PyBytes_FromStringAndSize(NULL, length))) if (!(RetVal = PyByteArray_FromStringAndSize(NULL, length)))
return NULL; return NULL;
ENTER_ZLIB ENTER_ZLIB
@ -411,7 +411,7 @@ PyZlib_objcompress(compobject *self, PyObject *args)
self->zst.avail_in = inplen; self->zst.avail_in = inplen;
self->zst.next_in = input; self->zst.next_in = input;
self->zst.avail_out = length; 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 Py_BEGIN_ALLOW_THREADS
err = deflate(&(self->zst), Z_NO_FLUSH); 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, /* while Z_OK and the output buffer is full, there might be more output,
so extend the output buffer and try again */ so extend the output buffer and try again */
while (err == Z_OK && self->zst.avail_out == 0) { 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); Py_DECREF(RetVal);
RetVal = NULL; RetVal = NULL;
goto error; goto error;
} }
self->zst.next_out = self->zst.next_out =
(unsigned char *)PyBytes_AS_STRING(RetVal) + length; (unsigned char *)PyByteArray_AS_STRING(RetVal) + length;
self->zst.avail_out = length; self->zst.avail_out = length;
length = length << 1; length = length << 1;
@ -445,7 +445,7 @@ PyZlib_objcompress(compobject *self, PyObject *args)
RetVal = NULL; RetVal = NULL;
goto error; 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); Py_DECREF(RetVal);
RetVal = NULL; RetVal = NULL;
} }
@ -487,7 +487,7 @@ PyZlib_objdecompress(compobject *self, PyObject *args)
/* limit amount of data allocated to max_length */ /* limit amount of data allocated to max_length */
if (max_length && length > max_length) if (max_length && length > max_length)
length = max_length; length = max_length;
if (!(RetVal = PyBytes_FromStringAndSize(NULL, length))) if (!(RetVal = PyByteArray_FromStringAndSize(NULL, length)))
return NULL; return NULL;
ENTER_ZLIB ENTER_ZLIB
@ -496,7 +496,7 @@ PyZlib_objdecompress(compobject *self, PyObject *args)
self->zst.avail_in = inplen; self->zst.avail_in = inplen;
self->zst.next_in = input; self->zst.next_in = input;
self->zst.avail_out = length; 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 Py_BEGIN_ALLOW_THREADS
err = inflate(&(self->zst), Z_SYNC_FLUSH); err = inflate(&(self->zst), Z_SYNC_FLUSH);
@ -518,13 +518,13 @@ PyZlib_objdecompress(compobject *self, PyObject *args)
if (max_length && length > max_length) if (max_length && length > max_length)
length = max_length; length = max_length;
if (PyBytes_Resize(RetVal, length) < 0) { if (PyByteArray_Resize(RetVal, length) < 0) {
Py_DECREF(RetVal); Py_DECREF(RetVal);
RetVal = NULL; RetVal = NULL;
goto error; goto error;
} }
self->zst.next_out = 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; self->zst.avail_out = length - old_length;
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
@ -536,7 +536,7 @@ PyZlib_objdecompress(compobject *self, PyObject *args)
of specified size. Return the unconsumed tail in an attribute.*/ of specified size. Return the unconsumed tail in an attribute.*/
if(max_length) { if(max_length) {
Py_DECREF(self->unconsumed_tail); 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); self->zst.avail_in);
if(!self->unconsumed_tail) { if(!self->unconsumed_tail) {
Py_DECREF(RetVal); Py_DECREF(RetVal);
@ -553,7 +553,7 @@ PyZlib_objdecompress(compobject *self, PyObject *args)
*/ */
if (err == Z_STREAM_END) { if (err == Z_STREAM_END) {
Py_XDECREF(self->unused_data); /* Free original empty string */ 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); (char *)self->zst.next_in, self->zst.avail_in);
if (self->unused_data == NULL) { if (self->unused_data == NULL) {
Py_DECREF(RetVal); Py_DECREF(RetVal);
@ -570,7 +570,7 @@ PyZlib_objdecompress(compobject *self, PyObject *args)
goto error; 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); Py_DECREF(RetVal);
RetVal = NULL; 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 /* 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. */ doing any work at all; just return an empty string. */
if (flushmode == Z_NO_FLUSH) { 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; return NULL;
ENTER_ZLIB ENTER_ZLIB
@ -614,7 +614,7 @@ PyZlib_flush(compobject *self, PyObject *args)
start_total_out = self->zst.total_out; start_total_out = self->zst.total_out;
self->zst.avail_in = 0; self->zst.avail_in = 0;
self->zst.avail_out = length; 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 Py_BEGIN_ALLOW_THREADS
err = deflate(&(self->zst), flushmode); 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, /* while Z_OK and the output buffer is full, there might be more output,
so extend the output buffer and try again */ so extend the output buffer and try again */
while (err == Z_OK && self->zst.avail_out == 0) { 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); Py_DECREF(RetVal);
RetVal = NULL; RetVal = NULL;
goto error; goto error;
} }
self->zst.next_out = self->zst.next_out =
(unsigned char *)PyBytes_AS_STRING(RetVal) + length; (unsigned char *)PyByteArray_AS_STRING(RetVal) + length;
self->zst.avail_out = length; self->zst.avail_out = length;
length = length << 1; length = length << 1;
@ -663,7 +663,7 @@ PyZlib_flush(compobject *self, PyObject *args)
goto error; 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); Py_DECREF(RetVal);
RetVal = NULL; RetVal = NULL;
} }
@ -798,7 +798,7 @@ PyZlib_unflush(compobject *self, PyObject *args)
PyErr_SetString(PyExc_ValueError, "length must be greater than zero"); PyErr_SetString(PyExc_ValueError, "length must be greater than zero");
return NULL; return NULL;
} }
if (!(retval = PyBytes_FromStringAndSize(NULL, length))) if (!(retval = PyByteArray_FromStringAndSize(NULL, length)))
return NULL; return NULL;
@ -806,7 +806,7 @@ PyZlib_unflush(compobject *self, PyObject *args)
start_total_out = self->zst.total_out; start_total_out = self->zst.total_out;
self->zst.avail_out = length; 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 Py_BEGIN_ALLOW_THREADS
err = inflate(&(self->zst), Z_FINISH); 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, /* while Z_OK and the output buffer is full, there might be more output,
so extend the output buffer and try again */ so extend the output buffer and try again */
while ((err == Z_OK || err == Z_BUF_ERROR) && self->zst.avail_out == 0) { 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); Py_DECREF(retval);
retval = NULL; retval = NULL;
goto error; 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; self->zst.avail_out = length;
length = length << 1; length = length << 1;
@ -842,7 +842,7 @@ PyZlib_unflush(compobject *self, PyObject *args)
goto error; 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); Py_DECREF(retval);
retval = NULL; retval = NULL;
} }

File diff suppressed because it is too large Load diff

View file

@ -3518,13 +3518,13 @@ long_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return PyLong_FromUnicode(PyUnicode_AS_UNICODE(x), return PyLong_FromUnicode(PyUnicode_AS_UNICODE(x),
PyUnicode_GET_SIZE(x), PyUnicode_GET_SIZE(x),
base); 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, /* Since PyLong_FromString doesn't have a length parameter,
* check here for possible NULs in the string. */ * check here for possible NULs in the string. */
char *string; char *string;
int size = Py_SIZE(x); int size = Py_SIZE(x);
if (PyBytes_Check(x)) if (PyByteArray_Check(x))
string = PyBytes_AS_STRING(x); string = PyByteArray_AS_STRING(x);
else else
string = PyString_AS_STRING(x); string = PyString_AS_STRING(x);
if (strlen(string) != size) { if (strlen(string) != size) {

View file

@ -254,12 +254,12 @@ PyMemoryView_GetContiguous(PyObject *obj, int buffertype, char fort)
"for a non-contiguousobject."); "for a non-contiguousobject.");
return NULL; return NULL;
} }
bytes = PyBytes_FromStringAndSize(NULL, view->len); bytes = PyByteArray_FromStringAndSize(NULL, view->len);
if (bytes == NULL) { if (bytes == NULL) {
PyObject_ReleaseBuffer(obj, view); PyObject_ReleaseBuffer(obj, view);
return NULL; return NULL;
} }
dest = PyBytes_AS_STRING(bytes); dest = PyByteArray_AS_STRING(bytes);
/* different copying strategy depending on whether /* different copying strategy depending on whether
or not any pointer de-referencing is needed or not any pointer de-referencing is needed
*/ */
@ -382,7 +382,7 @@ static PyGetSetDef memory_getsetlist[] ={
static PyObject * static PyObject *
memory_tobytes(PyMemoryViewObject *mem, PyObject *noargs) memory_tobytes(PyMemoryViewObject *mem, PyObject *noargs)
{ {
return PyBytes_FromObject((PyObject *)mem); return PyByteArray_FromObject((PyObject *)mem);
} }
static PyObject * static PyObject *
@ -451,8 +451,8 @@ memory_str(PyMemoryViewObject *self)
if (PyObject_GetBuffer((PyObject *)self, &view, PyBUF_FULL) < 0) if (PyObject_GetBuffer((PyObject *)self, &view, PyBUF_FULL) < 0)
return NULL; return NULL;
res = PyBytes_FromStringAndSize(NULL, view.len); res = PyByteArray_FromStringAndSize(NULL, view.len);
PyBuffer_ToContiguous(PyBytes_AS_STRING(res), &view, view.len, 'C'); PyBuffer_ToContiguous(PyByteArray_AS_STRING(res), &view, view.len, 'C');
PyObject_ReleaseBuffer((PyObject *)self, &view); PyObject_ReleaseBuffer((PyObject *)self, &view);
return res; return res;
} }
@ -522,7 +522,7 @@ memory_subscript(PyMemoryViewObject *self, PyObject *key)
{ {
ptr = *((char **)ptr) + view->suboffsets[0]; ptr = *((char **)ptr) + view->suboffsets[0];
} }
return PyBytes_FromStringAndSize(ptr, view->itemsize); return PyByteArray_FromStringAndSize(ptr, view->itemsize);
} }
else { else {
/* Return a new memory-view object */ /* Return a new memory-view object */

View file

@ -1495,7 +1495,7 @@ _Py_ReadyTypes(void)
if (PyType_Ready(&PyBool_Type) < 0) if (PyType_Ready(&PyBool_Type) < 0)
Py_FatalError("Can't initialize 'bool'"); Py_FatalError("Can't initialize 'bool'");
if (PyType_Ready(&PyBytes_Type) < 0) if (PyType_Ready(&PyByteArray_Type) < 0)
Py_FatalError("Can't initialize 'bytes'"); Py_FatalError("Can't initialize 'bytes'");
if (PyType_Ready(&PyString_Type) < 0) if (PyType_Ready(&PyString_Type) < 0)

View file

@ -1469,7 +1469,7 @@ string_join(PyObject *self, PyObject *orig)
for (i = 0; i < seqlen; i++) { for (i = 0; i < seqlen; i++) {
const size_t old_sz = sz; const size_t old_sz = sz;
item = PySequence_Fast_GET_ITEM(seq, i); 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, PyErr_Format(PyExc_TypeError,
"sequence item %zd: expected bytes," "sequence item %zd: expected bytes,"
" %.80s found", " %.80s found",
@ -1496,7 +1496,7 @@ string_join(PyObject *self, PyObject *orig)
} }
/* Catenate everything. */ /* 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. */ nowhere in this function where we release the GIL. */
p = PyString_AS_STRING(res); p = PyString_AS_STRING(res);
for (i = 0; i < seqlen; ++i) { for (i = 0; i < seqlen; ++i) {
@ -1511,7 +1511,7 @@ string_join(PyObject *self, PyObject *orig)
if (PyString_Check(item)) if (PyString_Check(item))
q = PyString_AS_STRING(item); q = PyString_AS_STRING(item);
else else
q = PyBytes_AS_STRING(item); q = PyByteArray_AS_STRING(item);
Py_MEMCPY(p, q, n); Py_MEMCPY(p, q, n);
p += n; p += n;
} }

View file

@ -1764,11 +1764,11 @@ PyObject *PyUnicode_EncodeUTF7(const Py_UNICODE *s,
if (size == 0) if (size == 0)
return PyString_FromStringAndSize(NULL, 0); return PyString_FromStringAndSize(NULL, 0);
v = PyBytes_FromStringAndSize(NULL, cbAllocated); v = PyByteArray_FromStringAndSize(NULL, cbAllocated);
if (v == NULL) if (v == NULL)
return NULL; return NULL;
start = out = PyBytes_AS_STRING(v); start = out = PyByteArray_AS_STRING(v);
for (;i < size; ++i) { for (;i < size; ++i) {
Py_UNICODE ch = s[i]; Py_UNICODE ch = s[i];
@ -1834,7 +1834,7 @@ PyObject *PyUnicode_EncodeUTF7(const Py_UNICODE *s,
*out++ = '-'; *out++ = '-';
} }
result = PyString_FromStringAndSize(PyBytes_AS_STRING(v), out - start); result = PyString_FromStringAndSize(PyByteArray_AS_STRING(v), out - start);
Py_DECREF(v); Py_DECREF(v);
return result; return result;
} }
@ -2385,12 +2385,12 @@ PyUnicode_EncodeUTF32(const Py_UNICODE *s,
0xDC00 <= s[i+1] && s[i+1] <= 0xDFFF) 0xDC00 <= s[i+1] && s[i+1] <= 0xDFFF)
pairs++; pairs++;
#endif #endif
v = PyBytes_FromStringAndSize(NULL, v = PyByteArray_FromStringAndSize(NULL,
4 * (size - pairs + (byteorder == 0))); 4 * (size - pairs + (byteorder == 0)));
if (v == NULL) if (v == NULL)
return NULL; return NULL;
p = (unsigned char *)PyBytes_AS_STRING(v); p = (unsigned char *)PyByteArray_AS_STRING(v);
if (byteorder == 0) if (byteorder == 0)
STORECHAR(0xFEFF); STORECHAR(0xFEFF);
if (size == 0) if (size == 0)
@ -2427,7 +2427,7 @@ PyUnicode_EncodeUTF32(const Py_UNICODE *s,
} }
done: done:
result = PyString_FromStringAndSize(PyBytes_AS_STRING(v), Py_SIZE(v)); result = PyString_FromStringAndSize(PyByteArray_AS_STRING(v), Py_SIZE(v));
Py_DECREF(v); Py_DECREF(v);
return result; return result;
#undef STORECHAR #undef STORECHAR
@ -2654,12 +2654,12 @@ PyUnicode_EncodeUTF16(const Py_UNICODE *s,
if (s[i] >= 0x10000) if (s[i] >= 0x10000)
pairs++; pairs++;
#endif #endif
v = PyBytes_FromStringAndSize(NULL, v = PyByteArray_FromStringAndSize(NULL,
2 * (size + pairs + (byteorder == 0))); 2 * (size + pairs + (byteorder == 0)));
if (v == NULL) if (v == NULL)
return NULL; return NULL;
p = (unsigned char *)PyBytes_AS_STRING(v); p = (unsigned char *)PyByteArray_AS_STRING(v);
if (byteorder == 0) if (byteorder == 0)
STORECHAR(0xFEFF); STORECHAR(0xFEFF);
if (size == 0) if (size == 0)
@ -2691,7 +2691,7 @@ PyUnicode_EncodeUTF16(const Py_UNICODE *s,
} }
done: done:
result = PyString_FromStringAndSize(PyBytes_AS_STRING(v), Py_SIZE(v)); result = PyString_FromStringAndSize(PyByteArray_AS_STRING(v), Py_SIZE(v));
Py_DECREF(v); Py_DECREF(v);
return result; return result;
#undef STORECHAR #undef STORECHAR
@ -3004,7 +3004,7 @@ PyObject *PyUnicode_EncodeUnicodeEscape(const Py_UNICODE *s,
escape. escape.
*/ */
repr = PyBytes_FromStringAndSize(NULL, repr = PyByteArray_FromStringAndSize(NULL,
#ifdef Py_UNICODE_WIDE #ifdef Py_UNICODE_WIDE
+ 10*size + 10*size
#else #else
@ -3014,7 +3014,7 @@ PyObject *PyUnicode_EncodeUnicodeEscape(const Py_UNICODE *s,
if (repr == NULL) if (repr == NULL)
return NULL; return NULL;
p = PyBytes_AS_STRING(repr); p = PyByteArray_AS_STRING(repr);
while (size-- > 0) { while (size-- > 0) {
Py_UNICODE ch = *s++; Py_UNICODE ch = *s++;
@ -3106,8 +3106,8 @@ PyObject *PyUnicode_EncodeUnicodeEscape(const Py_UNICODE *s,
*p++ = (char) ch; *p++ = (char) ch;
} }
result = PyString_FromStringAndSize(PyBytes_AS_STRING(repr), result = PyString_FromStringAndSize(PyByteArray_AS_STRING(repr),
p - PyBytes_AS_STRING(repr)); p - PyByteArray_AS_STRING(repr));
Py_DECREF(repr); Py_DECREF(repr);
return result; return result;
} }
@ -3124,8 +3124,8 @@ PyObject *PyUnicode_AsUnicodeEscapeString(PyObject *unicode)
if (!s) if (!s)
return NULL; return NULL;
result = PyString_FromStringAndSize(PyBytes_AS_STRING(s), result = PyString_FromStringAndSize(PyByteArray_AS_STRING(s),
PyBytes_GET_SIZE(s)); PyByteArray_GET_SIZE(s));
Py_DECREF(s); Py_DECREF(s);
return result; return result;
} }
@ -3257,16 +3257,16 @@ PyObject *PyUnicode_EncodeRawUnicodeEscape(const Py_UNICODE *s,
char *q; char *q;
#ifdef Py_UNICODE_WIDE #ifdef Py_UNICODE_WIDE
repr = PyBytes_FromStringAndSize(NULL, 10 * size); repr = PyByteArray_FromStringAndSize(NULL, 10 * size);
#else #else
repr = PyBytes_FromStringAndSize(NULL, 6 * size); repr = PyByteArray_FromStringAndSize(NULL, 6 * size);
#endif #endif
if (repr == NULL) if (repr == NULL)
return NULL; return NULL;
if (size == 0) if (size == 0)
goto done; goto done;
p = q = PyBytes_AS_STRING(repr); p = q = PyByteArray_AS_STRING(repr);
while (size-- > 0) { while (size-- > 0) {
Py_UNICODE ch = *s++; Py_UNICODE ch = *s++;
#ifdef Py_UNICODE_WIDE #ifdef Py_UNICODE_WIDE
@ -3327,7 +3327,7 @@ PyObject *PyUnicode_EncodeRawUnicodeEscape(const Py_UNICODE *s,
size = p - q; size = p - q;
done: done:
result = PyString_FromStringAndSize(PyBytes_AS_STRING(repr), size); result = PyString_FromStringAndSize(PyByteArray_AS_STRING(repr), size);
Py_DECREF(repr); Py_DECREF(repr);
return result; return result;
} }
@ -3344,8 +3344,8 @@ PyObject *PyUnicode_AsRawUnicodeEscapeString(PyObject *unicode)
if (!s) if (!s)
return NULL; return NULL;
result = PyString_FromStringAndSize(PyBytes_AS_STRING(s), result = PyString_FromStringAndSize(PyByteArray_AS_STRING(s),
PyBytes_GET_SIZE(s)); PyByteArray_GET_SIZE(s));
Py_DECREF(s); Py_DECREF(s);
return result; return result;
} }
@ -3578,10 +3578,10 @@ static PyObject *unicode_encode_ucs1(const Py_UNICODE *p,
replacements, if we need more, we'll resize */ replacements, if we need more, we'll resize */
if (size == 0) if (size == 0)
return PyString_FromStringAndSize(NULL, 0); return PyString_FromStringAndSize(NULL, 0);
res = PyBytes_FromStringAndSize(NULL, size); res = PyByteArray_FromStringAndSize(NULL, size);
if (res == NULL) if (res == NULL)
return NULL; return NULL;
str = PyBytes_AS_STRING(res); str = PyByteArray_AS_STRING(res);
ressize = size; ressize = size;
while (p<endp) { while (p<endp) {
@ -3631,7 +3631,7 @@ static PyObject *unicode_encode_ucs1(const Py_UNICODE *p,
p = collend; p = collend;
break; break;
case 4: /* xmlcharrefreplace */ case 4: /* xmlcharrefreplace */
respos = str - PyBytes_AS_STRING(res); respos = str - PyByteArray_AS_STRING(res);
/* determine replacement size (temporarily (mis)uses p) */ /* determine replacement size (temporarily (mis)uses p) */
for (p = collstart, repsize = 0; p < collend; ++p) { for (p = collstart, repsize = 0; p < collend; ++p) {
if (*p<10) if (*p<10)
@ -3658,9 +3658,9 @@ static PyObject *unicode_encode_ucs1(const Py_UNICODE *p,
if (requiredsize > ressize) { if (requiredsize > ressize) {
if (requiredsize<2*ressize) if (requiredsize<2*ressize)
requiredsize = 2*ressize; requiredsize = 2*ressize;
if (PyBytes_Resize(res, requiredsize)) if (PyByteArray_Resize(res, requiredsize))
goto onError; goto onError;
str = PyBytes_AS_STRING(res) + respos; str = PyByteArray_AS_STRING(res) + respos;
ressize = requiredsize; ressize = requiredsize;
} }
/* generate replacement (temporarily (mis)uses p) */ /* 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 /* need more space? (at least enough for what we
have+the replacement+the rest of the string, so have+the replacement+the rest of the string, so
we won't have to check space for encodable characters) */ 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); repsize = PyUnicode_GET_SIZE(repunicode);
requiredsize = respos+repsize+(endp-collend); requiredsize = respos+repsize+(endp-collend);
if (requiredsize > ressize) { if (requiredsize > ressize) {
if (requiredsize<2*ressize) if (requiredsize<2*ressize)
requiredsize = 2*ressize; requiredsize = 2*ressize;
if (PyBytes_Resize(res, requiredsize)) { if (PyByteArray_Resize(res, requiredsize)) {
Py_DECREF(repunicode); Py_DECREF(repunicode);
goto onError; goto onError;
} }
str = PyBytes_AS_STRING(res) + respos; str = PyByteArray_AS_STRING(res) + respos;
ressize = requiredsize; ressize = requiredsize;
} }
/* check if there is anything unencodable in the replacement /* 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), result = PyString_FromStringAndSize(PyByteArray_AS_STRING(res),
str - PyBytes_AS_STRING(res)); str - PyByteArray_AS_STRING(res));
onError: onError:
Py_DECREF(res); Py_DECREF(res);
Py_XDECREF(errorHandler); Py_XDECREF(errorHandler);

View file

@ -908,7 +908,7 @@ Reg2Py(BYTE *retDataBuf, DWORD retDataSize, DWORD typ)
obData = Py_None; obData = Py_None;
} }
else else
obData = PyBytes_FromStringAndSize( obData = PyByteArray_FromStringAndSize(
(char *)retDataBuf, retDataSize); (char *)retDataBuf, retDataSize);
break; break;
} }

View file

@ -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 1) NULL: need to call tok->decoding_readline to get a new line
2) PyUnicodeObject *: decoding_feof has called tok->decoding_readline and 2) PyUnicodeObject *: decoding_feof has called tok->decoding_readline and
stored the result in tok->decoding_buffer 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 (in the s buffer) to copy entire contents of the line read
by tok->decoding_readline. tok->decoding_buffer has the overflow. by tok->decoding_readline. tok->decoding_buffer has the overflow.
In this case, fp_readl is called in a loop (with an expanded buffer) 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 else
{ {
buf = PyBytes_AsString(bufobj); buf = PyByteArray_AsString(bufobj);
if (buf == NULL) { if (buf == NULL) {
goto error; goto error;
} }
buflen = PyBytes_GET_SIZE(bufobj); buflen = PyByteArray_GET_SIZE(bufobj);
} }
Py_XDECREF(tok->decoding_buffer); Py_XDECREF(tok->decoding_buffer);
if (buflen > size) { if (buflen > size) {
/* Too many chars, the rest goes into tok->decoding_buffer */ /* 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); buflen-size);
if (tok->decoding_buffer == NULL) if (tok->decoding_buffer == NULL)
goto error; goto error;

View file

@ -1377,11 +1377,11 @@ builtin_ord(PyObject *self, PyObject* obj)
} }
#endif #endif
} }
else if (PyBytes_Check(obj)) { else if (PyByteArray_Check(obj)) {
/* XXX Hopefully this is temporary */ /* XXX Hopefully this is temporary */
size = PyBytes_GET_SIZE(obj); size = PyByteArray_GET_SIZE(obj);
if (size == 1) { if (size == 1) {
ord = (long)((unsigned char)*PyBytes_AS_STRING(obj)); ord = (long)((unsigned char)*PyByteArray_AS_STRING(obj));
return PyLong_FromLong(ord); return PyLong_FromLong(ord);
} }
} }
@ -1823,7 +1823,7 @@ builtin_sum(PyObject *self, PyObject *args)
Py_DECREF(iter); Py_DECREF(iter);
return NULL; return NULL;
} }
if (PyBytes_Check(result)) { if (PyByteArray_Check(result)) {
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
"sum() can't sum bytes [use b''.join(seq) instead]"); "sum() can't sum bytes [use b''.join(seq) instead]");
Py_DECREF(iter); Py_DECREF(iter);
@ -2266,7 +2266,7 @@ _PyBuiltin_Init(void)
SETBUILTIN("True", Py_True); SETBUILTIN("True", Py_True);
SETBUILTIN("bool", &PyBool_Type); SETBUILTIN("bool", &PyBool_Type);
SETBUILTIN("memoryview", &PyMemoryView_Type); SETBUILTIN("memoryview", &PyMemoryView_Type);
SETBUILTIN("bytearray", &PyBytes_Type); SETBUILTIN("bytearray", &PyByteArray_Type);
SETBUILTIN("bytes", &PyString_Type); SETBUILTIN("bytes", &PyString_Type);
SETBUILTIN("classmethod", &PyClassMethod_Type); SETBUILTIN("classmethod", &PyClassMethod_Type);
#ifndef WITHOUT_COMPLEX #ifndef WITHOUT_COMPLEX

View file

@ -345,7 +345,7 @@ PyObject *PyCodec_Encode(PyObject *object,
goto onError; goto onError;
} }
v = PyTuple_GET_ITEM(result, 0); v = PyTuple_GET_ITEM(result, 0);
if (PyBytes_Check(v)) { if (PyByteArray_Check(v)) {
char msg[100]; char msg[100];
PyOS_snprintf(msg, sizeof(msg), PyOS_snprintf(msg, sizeof(msg),
"encoder %s returned buffer instead of bytes", "encoder %s returned buffer instead of bytes",
@ -354,7 +354,7 @@ PyObject *PyCodec_Encode(PyObject *object,
v = NULL; v = NULL;
goto onError; 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)) else if (PyString_Check(v))
Py_INCREF(v); Py_INCREF(v);

View file

@ -971,7 +971,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
/* Encode object */ /* Encode object */
if (!recode_strings && if (!recode_strings &&
(PyString_Check(arg) || PyBytes_Check(arg))) { (PyString_Check(arg) || PyByteArray_Check(arg))) {
s = arg; s = arg;
Py_INCREF(s); Py_INCREF(s);
if (PyObject_AsCharBuffer(s, &ptr, &size) < 0) 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; break;
} }
case 'Y': { /* PyBytes object */ case 'Y': { /* PyByteArray object */
PyObject **p = va_arg(*p_va, PyObject **); PyObject **p = va_arg(*p_va, PyObject **);
if (PyBytes_Check(arg)) if (PyByteArray_Check(arg))
*p = arg; *p = arg;
else else
return converterr("buffer", arg, msgbuf, bufsize); return converterr("buffer", arg, msgbuf, bufsize);

View file

@ -1095,7 +1095,7 @@ PyMarshal_WriteObjectToString(PyObject *x, int version)
} }
if (wf.str != NULL) { if (wf.str != NULL) {
/* XXX Quick hack -- need to do this differently */ /* XXX Quick hack -- need to do this differently */
res = PyBytes_FromObject(wf.str); res = PyByteArray_FromObject(wf.str);
Py_DECREF(wf.str); Py_DECREF(wf.str);
} }
return res; return res;
@ -1136,9 +1136,9 @@ marshal_load(PyObject *self, PyObject *f)
rf.ptr = PyString_AS_STRING(data); rf.ptr = PyString_AS_STRING(data);
rf.end = rf.ptr + PyString_GET_SIZE(data); rf.end = rf.ptr + PyString_GET_SIZE(data);
} }
else if (PyBytes_Check(data)) { else if (PyByteArray_Check(data)) {
rf.ptr = PyBytes_AS_STRING(data); rf.ptr = PyByteArray_AS_STRING(data);
rf.end = rf.ptr + PyBytes_GET_SIZE(data); rf.end = rf.ptr + PyByteArray_GET_SIZE(data);
} }
else { else {
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,

View file

@ -175,7 +175,7 @@ Py_InitializeEx(int install_sigs)
if (!_PyLong_Init()) if (!_PyLong_Init())
Py_FatalError("Py_Initialize: can't init longs"); Py_FatalError("Py_Initialize: can't init longs");
if (!PyBytes_Init()) if (!PyByteArray_Init())
Py_FatalError("Py_Initialize: can't init bytes"); Py_FatalError("Py_Initialize: can't init bytes");
_PyFloat_Init(); _PyFloat_Init();
@ -460,7 +460,7 @@ Py_Finalize(void)
PyList_Fini(); PyList_Fini();
PySet_Fini(); PySet_Fini();
PyString_Fini(); PyString_Fini();
PyBytes_Fini(); PyByteArray_Fini();
PyLong_Fini(); PyLong_Fini();
PyFloat_Fini(); PyFloat_Fini();
PyDict_Fini(); PyDict_Fini();