Skip to content

Commit

Permalink
Renamed PyString to PyBytes
Browse files Browse the repository at this point in the history
  • Loading branch information
tiran committed May 26, 2008
1 parent 9c4756e commit 72b710a
Show file tree
Hide file tree
Showing 78 changed files with 983 additions and 983 deletions.
2 changes: 1 addition & 1 deletion Include/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ given type object has a specified feature.
#define Py_TPFLAGS_LONG_SUBCLASS (1L<<24)
#define Py_TPFLAGS_LIST_SUBCLASS (1L<<25)
#define Py_TPFLAGS_TUPLE_SUBCLASS (1L<<26)
#define Py_TPFLAGS_STRING_SUBCLASS (1L<<27)
#define Py_TPFLAGS_BYTES_SUBCLASS (1L<<27)
#define Py_TPFLAGS_UNICODE_SUBCLASS (1L<<28)
#define Py_TPFLAGS_DICT_SUBCLASS (1L<<29)
#define Py_TPFLAGS_BASE_EXC_SUBCLASS (1L<<30)
Expand Down
2 changes: 1 addition & 1 deletion Include/py_curses.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ static PyObject *PyCurses_ ## X (PyObject *self) \
static PyObject *PyCurses_ ## X (PyObject *self) \
{ \
PyCursesInitialised \
return PyString_FromString(X()); }
return PyBytes_FromString(X()); }

#define NoArgTrueFalseFunction(X) \
static PyObject *PyCurses_ ## X (PyObject *self) \
Expand Down
4 changes: 2 additions & 2 deletions Include/pyport.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ typedef Py_intptr_t Py_ssize_t;
* all platforms (Python interprets the format string itself, and does whatever
* the platform C requires to convert a size_t/Py_ssize_t argument):
*
* PyString_FromFormat
* PyBytes_FromFormat
* PyErr_Format
* PyString_FromFormatV
* PyBytes_FromFormatV
* PyUnicode_FromFormatV
*
* Lower-level uses require that you interpolate the correct format modifier
Expand Down
2 changes: 1 addition & 1 deletion Include/pythonrun.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ PyAPI_FUNC(void) PyDict_Fini(void);
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
54 changes: 27 additions & 27 deletions Include/stringobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ extern "C" {
#include <stdarg.h>

/*
Type PyStringObject represents a character string. An extra zero byte is
Type PyBytesObject represents a character string. An extra zero byte is
reserved at the end to ensure it is zero-terminated, but a size is
present so strings with null bytes in them can be represented. This
is an immutable object type.
Expand All @@ -37,49 +37,49 @@ typedef struct {
* ob_sval[ob_size] == 0.
* ob_shash is the hash of the string or -1 if not computed yet.
*/
} PyStringObject;
} PyBytesObject;

PyAPI_DATA(PyTypeObject) PyString_Type;
PyAPI_DATA(PyTypeObject) PyStringIter_Type;
PyAPI_DATA(PyTypeObject) PyBytes_Type;
PyAPI_DATA(PyTypeObject) PyBytesIter_Type;

#define PyString_Check(op) \
PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_STRING_SUBCLASS)
#define PyString_CheckExact(op) (Py_TYPE(op) == &PyString_Type)
#define PyBytes_Check(op) \
PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_BYTES_SUBCLASS)
#define PyBytes_CheckExact(op) (Py_TYPE(op) == &PyBytes_Type)

PyAPI_FUNC(PyObject *) PyString_FromStringAndSize(const char *, Py_ssize_t);
PyAPI_FUNC(PyObject *) PyString_FromString(const char *);
PyAPI_FUNC(PyObject *) PyString_FromFormatV(const char*, va_list)
PyAPI_FUNC(PyObject *) PyBytes_FromStringAndSize(const char *, Py_ssize_t);
PyAPI_FUNC(PyObject *) PyBytes_FromString(const char *);
PyAPI_FUNC(PyObject *) PyBytes_FromFormatV(const char*, va_list)
Py_GCC_ATTRIBUTE((format(printf, 1, 0)));
PyAPI_FUNC(PyObject *) PyString_FromFormat(const char*, ...)
PyAPI_FUNC(PyObject *) PyBytes_FromFormat(const char*, ...)
Py_GCC_ATTRIBUTE((format(printf, 1, 2)));
PyAPI_FUNC(Py_ssize_t) PyString_Size(PyObject *);
PyAPI_FUNC(char *) PyString_AsString(PyObject *);
PyAPI_FUNC(PyObject *) PyString_Repr(PyObject *, int);
PyAPI_FUNC(void) PyString_Concat(PyObject **, PyObject *);
PyAPI_FUNC(void) PyString_ConcatAndDel(PyObject **, PyObject *);
PyAPI_FUNC(int) _PyString_Resize(PyObject **, Py_ssize_t);
PyAPI_FUNC(PyObject *) PyString_Format(PyObject *, PyObject *);
PyAPI_FUNC(PyObject *) _PyString_FormatLong(PyObject*, int, int,
PyAPI_FUNC(Py_ssize_t) PyBytes_Size(PyObject *);
PyAPI_FUNC(char *) PyBytes_AsString(PyObject *);
PyAPI_FUNC(PyObject *) PyBytes_Repr(PyObject *, int);
PyAPI_FUNC(void) PyBytes_Concat(PyObject **, PyObject *);
PyAPI_FUNC(void) PyBytes_ConcatAndDel(PyObject **, PyObject *);
PyAPI_FUNC(int) _PyBytes_Resize(PyObject **, Py_ssize_t);
PyAPI_FUNC(PyObject *) PyBytes_Format(PyObject *, PyObject *);
PyAPI_FUNC(PyObject *) _PyBytes_FormatLong(PyObject*, int, int,
int, char**, int*);
PyAPI_FUNC(PyObject *) PyString_DecodeEscape(const char *, Py_ssize_t,
PyAPI_FUNC(PyObject *) PyBytes_DecodeEscape(const char *, Py_ssize_t,
const char *, Py_ssize_t,
const char *);

/* Macro, trading safety for speed */
#define PyString_AS_STRING(op) (assert(PyString_Check(op)), \
(((PyStringObject *)(op))->ob_sval))
#define PyString_GET_SIZE(op) (assert(PyString_Check(op)),Py_SIZE(op))
#define PyBytes_AS_STRING(op) (assert(PyBytes_Check(op)), \
(((PyBytesObject *)(op))->ob_sval))
#define PyBytes_GET_SIZE(op) (assert(PyBytes_Check(op)),Py_SIZE(op))

/* _PyString_Join(sep, x) is like sep.join(x). sep must be PyStringObject*,
/* _PyBytes_Join(sep, x) is like sep.join(x). sep must be PyBytesObject*,
x must be an iterable object. */
PyAPI_FUNC(PyObject *) _PyString_Join(PyObject *sep, PyObject *x);
PyAPI_FUNC(PyObject *) _PyBytes_Join(PyObject *sep, PyObject *x);

/* Provides access to the internal data buffer and size of a string
object or the default encoded version of an Unicode object. Passing
NULL as *len parameter will force the string buffer to be
0-terminated (passing a string with embedded NULL characters will
cause an exception). */
PyAPI_FUNC(int) PyString_AsStringAndSize(
PyAPI_FUNC(int) PyBytes_AsStringAndSize(
register PyObject *obj, /* string or Unicode object */
register char **s, /* pointer to buffer variable */
register Py_ssize_t *len /* pointer to length variable or NULL
Expand All @@ -91,7 +91,7 @@ PyAPI_FUNC(int) PyString_AsStringAndSize(
into the string pointed to by buffer. For the argument descriptions,
see Objects/stringlib/localeutil.h */

PyAPI_FUNC(int) _PyString_InsertThousandsGrouping(char *buffer,
PyAPI_FUNC(int) _PyBytes_InsertThousandsGrouping(char *buffer,
Py_ssize_t len,
char *plast,
Py_ssize_t buf_size,
Expand Down
28 changes: 14 additions & 14 deletions Modules/_bsddb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,7 @@ _db_associateCallback(DB* db, const DBT* priKey, const DBT* priData,
else if (PyLong_Check(result)) {
retval = PyLong_AsLong(result);
}
else if (PyByteArray_Check(result) || PyString_Check(result)) {
else if (PyByteArray_Check(result) || PyBytes_Check(result)) {
char* data;
Py_ssize_t size;

Expand All @@ -1183,7 +1183,7 @@ _db_associateCallback(DB* db, const DBT* priKey, const DBT* priData,
if (PyByteArray_Check(result))
data = PyByteArray_AS_STRING(result);
else
data = PyString_AS_STRING(result);
data = PyBytes_AS_STRING(result);
secKey->flags = DB_DBT_APPMALLOC; /* DB will free */
secKey->data = malloc(size); /* TODO, check this */
if (secKey->data) {
Expand Down Expand Up @@ -1523,7 +1523,7 @@ DB_get(DBObject* self, PyObject* args, PyObject* kwargs)
retval = Py_BuildValue("y#y#", key.data, key.size, data.data,
data.size);
else /* return just the data */
retval = PyString_FromStringAndSize((char*)data.data, data.size);
retval = PyBytes_FromStringAndSize((char*)data.data, data.size);
free_dbt(&data);
}
FREE_DBT_VIEW(key, keyobj, key_buf_view);
Expand Down Expand Up @@ -1593,13 +1593,13 @@ DB_pget(DBObject* self, PyObject* args, PyObject* kwargs)
else if (!err) {
PyObject *pkeyObj;
PyObject *dataObj;
dataObj = PyString_FromStringAndSize(data.data, data.size);
dataObj = PyBytes_FromStringAndSize(data.data, data.size);

if (self->primaryDBType == DB_RECNO ||
self->primaryDBType == DB_QUEUE)
pkeyObj = PyLong_FromLong(*(int *)pkey.data);
else
pkeyObj = PyString_FromStringAndSize(pkey.data, pkey.size);
pkeyObj = PyBytes_FromStringAndSize(pkey.data, pkey.size);

if (flags & DB_SET_RECNO) /* return key , pkey and data */
{
Expand All @@ -1608,7 +1608,7 @@ DB_pget(DBObject* self, PyObject* args, PyObject* kwargs)
if (type == DB_RECNO || type == DB_QUEUE)
keyObj = PyLong_FromLong(*(int *)key.data);
else
keyObj = PyString_FromStringAndSize(key.data, key.size);
keyObj = PyBytes_FromStringAndSize(key.data, key.size);
#if (PY_VERSION_HEX >= 0x02040000)
retval = PyTuple_Pack(3, keyObj, pkeyObj, dataObj);
#else
Expand Down Expand Up @@ -1736,7 +1736,7 @@ DB_get_both(DBObject* self, PyObject* args, PyObject* kwargs)
/* XXX(nnorwitz): can we do: retval = dataobj; Py_INCREF(retval); */
/* XXX(gps) I think not: buffer API input vs. bytes object output. */
/* XXX(guido) But what if the input is PyString? */
retval = PyString_FromStringAndSize((char*)data.data, data.size);
retval = PyBytes_FromStringAndSize((char*)data.data, data.size);

/* Even though the flags require DB_DBT_MALLOC, data is not always
allocated. 4.4: allocated, 4.5: *not* allocated. :-( */
Expand Down Expand Up @@ -2780,7 +2780,7 @@ PyObject* DB_subscript(DBObject* self, PyObject* keyobj)
retval = NULL;
}
else {
retval = PyString_FromStringAndSize((char*)data.data, data.size);
retval = PyBytes_FromStringAndSize((char*)data.data, data.size);
free_dbt(&data);
}

Expand Down Expand Up @@ -2935,7 +2935,7 @@ _DB_make_list(DBObject* self, DB_TXN* txn, int type)
case DB_BTREE:
case DB_HASH:
default:
item = PyString_FromStringAndSize((char*)key.data, key.size);
item = PyBytes_FromStringAndSize((char*)key.data, key.size);
break;
case DB_RECNO:
case DB_QUEUE:
Expand All @@ -2945,7 +2945,7 @@ _DB_make_list(DBObject* self, DB_TXN* txn, int type)
break;

case _VALUES_LIST:
item = PyString_FromStringAndSize((char*)data.data, data.size);
item = PyBytes_FromStringAndSize((char*)data.data, data.size);
break;

case _ITEMS_LIST:
Expand Down Expand Up @@ -3293,13 +3293,13 @@ DBC_pget(DBCursorObject* self, PyObject* args, PyObject *kwargs)
else {
PyObject *pkeyObj;
PyObject *dataObj;
dataObj = PyString_FromStringAndSize(data.data, data.size);
dataObj = PyBytes_FromStringAndSize(data.data, data.size);

if (self->mydb->primaryDBType == DB_RECNO ||
self->mydb->primaryDBType == DB_QUEUE)
pkeyObj = PyLong_FromLong(*(int *)pkey.data);
else
pkeyObj = PyString_FromStringAndSize(pkey.data, pkey.size);
pkeyObj = PyBytes_FromStringAndSize(pkey.data, pkey.size);

if (key.data && key.size) /* return key, pkey and data */
{
Expand All @@ -3308,7 +3308,7 @@ DBC_pget(DBCursorObject* self, PyObject* args, PyObject *kwargs)
if (type == DB_RECNO || type == DB_QUEUE)
keyObj = PyLong_FromLong(*(int *)key.data);
else
keyObj = PyString_FromStringAndSize(key.data, key.size);
keyObj = PyBytes_FromStringAndSize(key.data, key.size);
retval = PyTuple_Pack(3, keyObj, pkeyObj, dataObj);
Py_DECREF(keyObj);
}
Expand Down Expand Up @@ -4916,7 +4916,7 @@ DBSequence_get_key(DBSequenceObject* self, PyObject* args)
MYDB_END_ALLOW_THREADS

if (!err)
retval = PyString_FromStringAndSize(key.data, key.size);
retval = PyBytes_FromStringAndSize(key.data, key.size);

free_dbt(&key);
RETURN_IF_ERR();
Expand Down
10 changes: 5 additions & 5 deletions Modules/_bytesio.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ static PyObject *
bytesio_getvalue(BytesIOObject *self)
{
CHECK_CLOSED(self);
return PyString_FromStringAndSize(self->buf, self->string_size);
return PyBytes_FromStringAndSize(self->buf, self->string_size);
}

PyDoc_STRVAR(isatty_doc,
Expand Down Expand Up @@ -244,7 +244,7 @@ bytesio_read(BytesIOObject *self, PyObject *args)
output = self->buf + self->pos;
self->pos += size;

return PyString_FromStringAndSize(output, size);
return PyBytes_FromStringAndSize(output, size);
}


Expand Down Expand Up @@ -307,7 +307,7 @@ bytesio_readline(BytesIOObject *self, PyObject *args)
self->pos -= size;
}

return PyString_FromStringAndSize(output, n);
return PyBytes_FromStringAndSize(output, n);
}

PyDoc_STRVAR(readlines_doc,
Expand Down Expand Up @@ -349,7 +349,7 @@ bytesio_readlines(BytesIOObject *self, PyObject *args)
return NULL;

while ((n = get_line(self, &output)) != 0) {
line = PyString_FromStringAndSize(output, n);
line = PyBytes_FromStringAndSize(output, n);
if (!line)
goto on_error;
if (PyList_Append(result, line) == -1) {
Expand Down Expand Up @@ -455,7 +455,7 @@ bytesio_iternext(BytesIOObject *self)
if (!next || n == 0)
return NULL;

return PyString_FromStringAndSize(next, n);
return PyBytes_FromStringAndSize(next, n);
}

PyDoc_STRVAR(seek_doc,
Expand Down
26 changes: 13 additions & 13 deletions Modules/_codecsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ escape_decode(PyObject *self,
if (!PyArg_ParseTuple(args, "s#|z:escape_decode",
&data, &size, &errors))
return NULL;
return codec_tuple(PyString_DecodeEscape(data, size, errors, 0, NULL),
return codec_tuple(PyBytes_DecodeEscape(data, size, errors, 0, NULL),
size);
}

Expand All @@ -170,30 +170,30 @@ escape_encode(PyObject *self,
PyObject *v;

if (!PyArg_ParseTuple(args, "O!|z:escape_encode",
&PyString_Type, &str, &errors))
&PyBytes_Type, &str, &errors))
return NULL;

size = PyString_GET_SIZE(str);
size = PyBytes_GET_SIZE(str);
newsize = 4*size;
if (newsize > PY_SSIZE_T_MAX || newsize / 4 != size) {
PyErr_SetString(PyExc_OverflowError,
"string is too large to encode");
return NULL;
}
v = PyString_FromStringAndSize(NULL, newsize);
v = PyBytes_FromStringAndSize(NULL, newsize);

if (v == NULL) {
return NULL;
}
else {
register Py_ssize_t i;
register char c;
register char *p = PyString_AS_STRING(v);
register char *p = PyBytes_AS_STRING(v);

for (i = 0; i < size; i++) {
/* There's at least enough room for a hex escape */
assert(newsize - (p - PyString_AS_STRING(v)) >= 4);
c = PyString_AS_STRING(str)[i];
assert(newsize - (p - PyBytes_AS_STRING(v)) >= 4);
c = PyBytes_AS_STRING(str)[i];
if (c == '\'' || c == '\\')
*p++ = '\\', *p++ = c;
else if (c == '\t')
Expand All @@ -212,12 +212,12 @@ escape_encode(PyObject *self,
*p++ = c;
}
*p = '\0';
if (_PyString_Resize(&v, (p - PyString_AS_STRING(v)))) {
if (_PyBytes_Resize(&v, (p - PyBytes_AS_STRING(v)))) {
return NULL;
}
}

return codec_tuple(v, PyString_Size(v));
return codec_tuple(v, PyBytes_Size(v));
}

/* --- Decoder ------------------------------------------------------------ */
Expand Down Expand Up @@ -660,7 +660,7 @@ readbuffer_encode(PyObject *self,
&data, &size, &errors))
return NULL;

return codec_tuple(PyString_FromStringAndSize(data, size), size);
return codec_tuple(PyBytes_FromStringAndSize(data, size), size);
}

static PyObject *
Expand All @@ -675,7 +675,7 @@ charbuffer_encode(PyObject *self,
&data, &size, &errors))
return NULL;

return codec_tuple(PyString_FromStringAndSize(data, size), size);
return codec_tuple(PyBytes_FromStringAndSize(data, size), size);
}

static PyObject *
Expand All @@ -694,12 +694,12 @@ unicode_internal_encode(PyObject *self,
if (PyUnicode_Check(obj)) {
data = PyUnicode_AS_DATA(obj);
size = PyUnicode_GET_DATA_SIZE(obj);
return codec_tuple(PyString_FromStringAndSize(data, size), size);
return codec_tuple(PyBytes_FromStringAndSize(data, size), size);
}
else {
if (PyObject_AsReadBuffer(obj, (const void **)&data, &size))
return NULL;
return codec_tuple(PyString_FromStringAndSize(data, size), size);
return codec_tuple(PyBytes_FromStringAndSize(data, size), size);
}
}

Expand Down
Loading

0 comments on commit 72b710a

Please sign in to comment.