Skip to content

Commit

Permalink
Renamed PyBytes to PyByteArray
Browse files Browse the repository at this point in the history
  • Loading branch information
tiran committed May 26, 2008
1 parent 96d02f3 commit 9c4756e
Show file tree
Hide file tree
Showing 31 changed files with 397 additions and 397 deletions.
2 changes: 1 addition & 1 deletion Include/bytes_methods.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
28 changes: 14 additions & 14 deletions Include/bytesobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions Include/pythonrun.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

Expand Down
6 changes: 3 additions & 3 deletions Modules/_bsddb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion Modules/_ctypes/_ctypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
4 changes: 2 additions & 2 deletions Modules/_ctypes/cfield.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
10 changes: 5 additions & 5 deletions Modules/_dbmmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions Modules/_sqlite/cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion Modules/_sqlite/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion Modules/_sqlite/statement.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions Modules/_ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions Modules/_struct.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions Modules/arraymodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)))) {
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions Modules/mmapmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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 *
Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions Modules/ossaudiodev.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions Modules/pyexpat.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
Loading

0 comments on commit 9c4756e

Please sign in to comment.