Skip to content

Commit 72b710a

Browse files
committed
Renamed PyString to PyBytes
1 parent 9c4756e commit 72b710a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+983
-983
lines changed

Include/object.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ given type object has a specified feature.
540540
#define Py_TPFLAGS_LONG_SUBCLASS (1L<<24)
541541
#define Py_TPFLAGS_LIST_SUBCLASS (1L<<25)
542542
#define Py_TPFLAGS_TUPLE_SUBCLASS (1L<<26)
543-
#define Py_TPFLAGS_STRING_SUBCLASS (1L<<27)
543+
#define Py_TPFLAGS_BYTES_SUBCLASS (1L<<27)
544544
#define Py_TPFLAGS_UNICODE_SUBCLASS (1L<<28)
545545
#define Py_TPFLAGS_DICT_SUBCLASS (1L<<29)
546546
#define Py_TPFLAGS_BASE_EXC_SUBCLASS (1L<<30)

Include/py_curses.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ static PyObject *PyCurses_ ## X (PyObject *self) \
146146
static PyObject *PyCurses_ ## X (PyObject *self) \
147147
{ \
148148
PyCursesInitialised \
149-
return PyString_FromString(X()); }
149+
return PyBytes_FromString(X()); }
150150

151151
#define NoArgTrueFalseFunction(X) \
152152
static PyObject *PyCurses_ ## X (PyObject *self) \

Include/pyport.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ typedef Py_intptr_t Py_ssize_t;
124124
* all platforms (Python interprets the format string itself, and does whatever
125125
* the platform C requires to convert a size_t/Py_ssize_t argument):
126126
*
127-
* PyString_FromFormat
127+
* PyBytes_FromFormat
128128
* PyErr_Format
129-
* PyString_FromFormatV
129+
* PyBytes_FromFormatV
130130
* PyUnicode_FromFormatV
131131
*
132132
* Lower-level uses require that you interpolate the correct format modifier

Include/pythonrun.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ PyAPI_FUNC(void) PyDict_Fini(void);
138138
PyAPI_FUNC(void) PyTuple_Fini(void);
139139
PyAPI_FUNC(void) PyList_Fini(void);
140140
PyAPI_FUNC(void) PySet_Fini(void);
141-
PyAPI_FUNC(void) PyString_Fini(void);
141+
PyAPI_FUNC(void) PyBytes_Fini(void);
142142
PyAPI_FUNC(void) PyByteArray_Fini(void);
143143
PyAPI_FUNC(void) PyFloat_Fini(void);
144144
PyAPI_FUNC(void) PyOS_FiniInterrupts(void);

Include/stringobject.h

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ extern "C" {
1010
#include <stdarg.h>
1111

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

42-
PyAPI_DATA(PyTypeObject) PyString_Type;
43-
PyAPI_DATA(PyTypeObject) PyStringIter_Type;
42+
PyAPI_DATA(PyTypeObject) PyBytes_Type;
43+
PyAPI_DATA(PyTypeObject) PyBytesIter_Type;
4444

45-
#define PyString_Check(op) \
46-
PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_STRING_SUBCLASS)
47-
#define PyString_CheckExact(op) (Py_TYPE(op) == &PyString_Type)
45+
#define PyBytes_Check(op) \
46+
PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_BYTES_SUBCLASS)
47+
#define PyBytes_CheckExact(op) (Py_TYPE(op) == &PyBytes_Type)
4848

49-
PyAPI_FUNC(PyObject *) PyString_FromStringAndSize(const char *, Py_ssize_t);
50-
PyAPI_FUNC(PyObject *) PyString_FromString(const char *);
51-
PyAPI_FUNC(PyObject *) PyString_FromFormatV(const char*, va_list)
49+
PyAPI_FUNC(PyObject *) PyBytes_FromStringAndSize(const char *, Py_ssize_t);
50+
PyAPI_FUNC(PyObject *) PyBytes_FromString(const char *);
51+
PyAPI_FUNC(PyObject *) PyBytes_FromFormatV(const char*, va_list)
5252
Py_GCC_ATTRIBUTE((format(printf, 1, 0)));
53-
PyAPI_FUNC(PyObject *) PyString_FromFormat(const char*, ...)
53+
PyAPI_FUNC(PyObject *) PyBytes_FromFormat(const char*, ...)
5454
Py_GCC_ATTRIBUTE((format(printf, 1, 2)));
55-
PyAPI_FUNC(Py_ssize_t) PyString_Size(PyObject *);
56-
PyAPI_FUNC(char *) PyString_AsString(PyObject *);
57-
PyAPI_FUNC(PyObject *) PyString_Repr(PyObject *, int);
58-
PyAPI_FUNC(void) PyString_Concat(PyObject **, PyObject *);
59-
PyAPI_FUNC(void) PyString_ConcatAndDel(PyObject **, PyObject *);
60-
PyAPI_FUNC(int) _PyString_Resize(PyObject **, Py_ssize_t);
61-
PyAPI_FUNC(PyObject *) PyString_Format(PyObject *, PyObject *);
62-
PyAPI_FUNC(PyObject *) _PyString_FormatLong(PyObject*, int, int,
55+
PyAPI_FUNC(Py_ssize_t) PyBytes_Size(PyObject *);
56+
PyAPI_FUNC(char *) PyBytes_AsString(PyObject *);
57+
PyAPI_FUNC(PyObject *) PyBytes_Repr(PyObject *, int);
58+
PyAPI_FUNC(void) PyBytes_Concat(PyObject **, PyObject *);
59+
PyAPI_FUNC(void) PyBytes_ConcatAndDel(PyObject **, PyObject *);
60+
PyAPI_FUNC(int) _PyBytes_Resize(PyObject **, Py_ssize_t);
61+
PyAPI_FUNC(PyObject *) PyBytes_Format(PyObject *, PyObject *);
62+
PyAPI_FUNC(PyObject *) _PyBytes_FormatLong(PyObject*, int, int,
6363
int, char**, int*);
64-
PyAPI_FUNC(PyObject *) PyString_DecodeEscape(const char *, Py_ssize_t,
64+
PyAPI_FUNC(PyObject *) PyBytes_DecodeEscape(const char *, Py_ssize_t,
6565
const char *, Py_ssize_t,
6666
const char *);
6767

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

73-
/* _PyString_Join(sep, x) is like sep.join(x). sep must be PyStringObject*,
73+
/* _PyBytes_Join(sep, x) is like sep.join(x). sep must be PyBytesObject*,
7474
x must be an iterable object. */
75-
PyAPI_FUNC(PyObject *) _PyString_Join(PyObject *sep, PyObject *x);
75+
PyAPI_FUNC(PyObject *) _PyBytes_Join(PyObject *sep, PyObject *x);
7676

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

94-
PyAPI_FUNC(int) _PyString_InsertThousandsGrouping(char *buffer,
94+
PyAPI_FUNC(int) _PyBytes_InsertThousandsGrouping(char *buffer,
9595
Py_ssize_t len,
9696
char *plast,
9797
Py_ssize_t buf_size,

Modules/_bsddb.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,7 +1174,7 @@ _db_associateCallback(DB* db, const DBT* priKey, const DBT* priData,
11741174
else if (PyLong_Check(result)) {
11751175
retval = PyLong_AsLong(result);
11761176
}
1177-
else if (PyByteArray_Check(result) || PyString_Check(result)) {
1177+
else if (PyByteArray_Check(result) || PyBytes_Check(result)) {
11781178
char* data;
11791179
Py_ssize_t size;
11801180

@@ -1183,7 +1183,7 @@ _db_associateCallback(DB* db, const DBT* priKey, const DBT* priData,
11831183
if (PyByteArray_Check(result))
11841184
data = PyByteArray_AS_STRING(result);
11851185
else
1186-
data = PyString_AS_STRING(result);
1186+
data = PyBytes_AS_STRING(result);
11871187
secKey->flags = DB_DBT_APPMALLOC; /* DB will free */
11881188
secKey->data = malloc(size); /* TODO, check this */
11891189
if (secKey->data) {
@@ -1523,7 +1523,7 @@ DB_get(DBObject* self, PyObject* args, PyObject* kwargs)
15231523
retval = Py_BuildValue("y#y#", key.data, key.size, data.data,
15241524
data.size);
15251525
else /* return just the data */
1526-
retval = PyString_FromStringAndSize((char*)data.data, data.size);
1526+
retval = PyBytes_FromStringAndSize((char*)data.data, data.size);
15271527
free_dbt(&data);
15281528
}
15291529
FREE_DBT_VIEW(key, keyobj, key_buf_view);
@@ -1593,13 +1593,13 @@ DB_pget(DBObject* self, PyObject* args, PyObject* kwargs)
15931593
else if (!err) {
15941594
PyObject *pkeyObj;
15951595
PyObject *dataObj;
1596-
dataObj = PyString_FromStringAndSize(data.data, data.size);
1596+
dataObj = PyBytes_FromStringAndSize(data.data, data.size);
15971597

15981598
if (self->primaryDBType == DB_RECNO ||
15991599
self->primaryDBType == DB_QUEUE)
16001600
pkeyObj = PyLong_FromLong(*(int *)pkey.data);
16011601
else
1602-
pkeyObj = PyString_FromStringAndSize(pkey.data, pkey.size);
1602+
pkeyObj = PyBytes_FromStringAndSize(pkey.data, pkey.size);
16031603

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

17411741
/* Even though the flags require DB_DBT_MALLOC, data is not always
17421742
allocated. 4.4: allocated, 4.5: *not* allocated. :-( */
@@ -2780,7 +2780,7 @@ PyObject* DB_subscript(DBObject* self, PyObject* keyobj)
27802780
retval = NULL;
27812781
}
27822782
else {
2783-
retval = PyString_FromStringAndSize((char*)data.data, data.size);
2783+
retval = PyBytes_FromStringAndSize((char*)data.data, data.size);
27842784
free_dbt(&data);
27852785
}
27862786

@@ -2935,7 +2935,7 @@ _DB_make_list(DBObject* self, DB_TXN* txn, int type)
29352935
case DB_BTREE:
29362936
case DB_HASH:
29372937
default:
2938-
item = PyString_FromStringAndSize((char*)key.data, key.size);
2938+
item = PyBytes_FromStringAndSize((char*)key.data, key.size);
29392939
break;
29402940
case DB_RECNO:
29412941
case DB_QUEUE:
@@ -2945,7 +2945,7 @@ _DB_make_list(DBObject* self, DB_TXN* txn, int type)
29452945
break;
29462946

29472947
case _VALUES_LIST:
2948-
item = PyString_FromStringAndSize((char*)data.data, data.size);
2948+
item = PyBytes_FromStringAndSize((char*)data.data, data.size);
29492949
break;
29502950

29512951
case _ITEMS_LIST:
@@ -3293,13 +3293,13 @@ DBC_pget(DBCursorObject* self, PyObject* args, PyObject *kwargs)
32933293
else {
32943294
PyObject *pkeyObj;
32953295
PyObject *dataObj;
3296-
dataObj = PyString_FromStringAndSize(data.data, data.size);
3296+
dataObj = PyBytes_FromStringAndSize(data.data, data.size);
32973297

32983298
if (self->mydb->primaryDBType == DB_RECNO ||
32993299
self->mydb->primaryDBType == DB_QUEUE)
33003300
pkeyObj = PyLong_FromLong(*(int *)pkey.data);
33013301
else
3302-
pkeyObj = PyString_FromStringAndSize(pkey.data, pkey.size);
3302+
pkeyObj = PyBytes_FromStringAndSize(pkey.data, pkey.size);
33033303

33043304
if (key.data && key.size) /* return key, pkey and data */
33053305
{
@@ -3308,7 +3308,7 @@ DBC_pget(DBCursorObject* self, PyObject* args, PyObject *kwargs)
33083308
if (type == DB_RECNO || type == DB_QUEUE)
33093309
keyObj = PyLong_FromLong(*(int *)key.data);
33103310
else
3311-
keyObj = PyString_FromStringAndSize(key.data, key.size);
3311+
keyObj = PyBytes_FromStringAndSize(key.data, key.size);
33123312
retval = PyTuple_Pack(3, keyObj, pkeyObj, dataObj);
33133313
Py_DECREF(keyObj);
33143314
}
@@ -4916,7 +4916,7 @@ DBSequence_get_key(DBSequenceObject* self, PyObject* args)
49164916
MYDB_END_ALLOW_THREADS
49174917

49184918
if (!err)
4919-
retval = PyString_FromStringAndSize(key.data, key.size);
4919+
retval = PyBytes_FromStringAndSize(key.data, key.size);
49204920

49214921
free_dbt(&key);
49224922
RETURN_IF_ERR();

Modules/_bytesio.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ static PyObject *
175175
bytesio_getvalue(BytesIOObject *self)
176176
{
177177
CHECK_CLOSED(self);
178-
return PyString_FromStringAndSize(self->buf, self->string_size);
178+
return PyBytes_FromStringAndSize(self->buf, self->string_size);
179179
}
180180

181181
PyDoc_STRVAR(isatty_doc,
@@ -244,7 +244,7 @@ bytesio_read(BytesIOObject *self, PyObject *args)
244244
output = self->buf + self->pos;
245245
self->pos += size;
246246

247-
return PyString_FromStringAndSize(output, size);
247+
return PyBytes_FromStringAndSize(output, size);
248248
}
249249

250250

@@ -307,7 +307,7 @@ bytesio_readline(BytesIOObject *self, PyObject *args)
307307
self->pos -= size;
308308
}
309309

310-
return PyString_FromStringAndSize(output, n);
310+
return PyBytes_FromStringAndSize(output, n);
311311
}
312312

313313
PyDoc_STRVAR(readlines_doc,
@@ -349,7 +349,7 @@ bytesio_readlines(BytesIOObject *self, PyObject *args)
349349
return NULL;
350350

351351
while ((n = get_line(self, &output)) != 0) {
352-
line = PyString_FromStringAndSize(output, n);
352+
line = PyBytes_FromStringAndSize(output, n);
353353
if (!line)
354354
goto on_error;
355355
if (PyList_Append(result, line) == -1) {
@@ -455,7 +455,7 @@ bytesio_iternext(BytesIOObject *self)
455455
if (!next || n == 0)
456456
return NULL;
457457

458-
return PyString_FromStringAndSize(next, n);
458+
return PyBytes_FromStringAndSize(next, n);
459459
}
460460

461461
PyDoc_STRVAR(seek_doc,

Modules/_codecsmodule.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ escape_decode(PyObject *self,
154154
if (!PyArg_ParseTuple(args, "s#|z:escape_decode",
155155
&data, &size, &errors))
156156
return NULL;
157-
return codec_tuple(PyString_DecodeEscape(data, size, errors, 0, NULL),
157+
return codec_tuple(PyBytes_DecodeEscape(data, size, errors, 0, NULL),
158158
size);
159159
}
160160

@@ -170,30 +170,30 @@ escape_encode(PyObject *self,
170170
PyObject *v;
171171

172172
if (!PyArg_ParseTuple(args, "O!|z:escape_encode",
173-
&PyString_Type, &str, &errors))
173+
&PyBytes_Type, &str, &errors))
174174
return NULL;
175175

176-
size = PyString_GET_SIZE(str);
176+
size = PyBytes_GET_SIZE(str);
177177
newsize = 4*size;
178178
if (newsize > PY_SSIZE_T_MAX || newsize / 4 != size) {
179179
PyErr_SetString(PyExc_OverflowError,
180180
"string is too large to encode");
181181
return NULL;
182182
}
183-
v = PyString_FromStringAndSize(NULL, newsize);
183+
v = PyBytes_FromStringAndSize(NULL, newsize);
184184

185185
if (v == NULL) {
186186
return NULL;
187187
}
188188
else {
189189
register Py_ssize_t i;
190190
register char c;
191-
register char *p = PyString_AS_STRING(v);
191+
register char *p = PyBytes_AS_STRING(v);
192192

193193
for (i = 0; i < size; i++) {
194194
/* There's at least enough room for a hex escape */
195-
assert(newsize - (p - PyString_AS_STRING(v)) >= 4);
196-
c = PyString_AS_STRING(str)[i];
195+
assert(newsize - (p - PyBytes_AS_STRING(v)) >= 4);
196+
c = PyBytes_AS_STRING(str)[i];
197197
if (c == '\'' || c == '\\')
198198
*p++ = '\\', *p++ = c;
199199
else if (c == '\t')
@@ -212,12 +212,12 @@ escape_encode(PyObject *self,
212212
*p++ = c;
213213
}
214214
*p = '\0';
215-
if (_PyString_Resize(&v, (p - PyString_AS_STRING(v)))) {
215+
if (_PyBytes_Resize(&v, (p - PyBytes_AS_STRING(v)))) {
216216
return NULL;
217217
}
218218
}
219219

220-
return codec_tuple(v, PyString_Size(v));
220+
return codec_tuple(v, PyBytes_Size(v));
221221
}
222222

223223
/* --- Decoder ------------------------------------------------------------ */
@@ -660,7 +660,7 @@ readbuffer_encode(PyObject *self,
660660
&data, &size, &errors))
661661
return NULL;
662662

663-
return codec_tuple(PyString_FromStringAndSize(data, size), size);
663+
return codec_tuple(PyBytes_FromStringAndSize(data, size), size);
664664
}
665665

666666
static PyObject *
@@ -675,7 +675,7 @@ charbuffer_encode(PyObject *self,
675675
&data, &size, &errors))
676676
return NULL;
677677

678-
return codec_tuple(PyString_FromStringAndSize(data, size), size);
678+
return codec_tuple(PyBytes_FromStringAndSize(data, size), size);
679679
}
680680

681681
static PyObject *
@@ -694,12 +694,12 @@ unicode_internal_encode(PyObject *self,
694694
if (PyUnicode_Check(obj)) {
695695
data = PyUnicode_AS_DATA(obj);
696696
size = PyUnicode_GET_DATA_SIZE(obj);
697-
return codec_tuple(PyString_FromStringAndSize(data, size), size);
697+
return codec_tuple(PyBytes_FromStringAndSize(data, size), size);
698698
}
699699
else {
700700
if (PyObject_AsReadBuffer(obj, (const void **)&data, &size))
701701
return NULL;
702-
return codec_tuple(PyString_FromStringAndSize(data, size), size);
702+
return codec_tuple(PyBytes_FromStringAndSize(data, size), size);
703703
}
704704
}
705705

0 commit comments

Comments
 (0)