summaryrefslogtreecommitdiff
path: root/Modules
diff options
context:
space:
mode:
authorChristian Heimes <christian@cheimes.de>2008-05-26 12:51:38 +0000
committerChristian Heimes <christian@cheimes.de>2008-05-26 12:51:38 +0000
commit593daf545bd9b7e7bcb27b498ecc6f36db9ae395 (patch)
treec0a57029b9ab0eb18a2bb4f8fd65f0817f1a1707 /Modules
parentc3cb683d638e9d660c18a05293a576f98965166e (diff)
downloadcpython-git-593daf545bd9b7e7bcb27b498ecc6f36db9ae395.tar.gz
Renamed PyString to PyBytes
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_bsddb.c28
-rw-r--r--Modules/_bytesio.c10
-rw-r--r--Modules/_codecsmodule.c22
-rw-r--r--Modules/_collectionsmodule.c18
-rw-r--r--Modules/_csv.c28
-rw-r--r--Modules/_ctypes/_ctypes.c110
-rw-r--r--Modules/_ctypes/callbacks.c10
-rw-r--r--Modules/_ctypes/callproc.c30
-rw-r--r--Modules/_ctypes/cfield.c36
-rw-r--r--Modules/_curses_panel.c2
-rw-r--r--Modules/_cursesmodule.c36
-rw-r--r--Modules/_elementtree.c52
-rw-r--r--Modules/_fileio.c24
-rw-r--r--Modules/_hashopenssl.c12
-rw-r--r--Modules/_heapqmodule.c2
-rw-r--r--Modules/_hotshot.c12
-rw-r--r--Modules/_json.c34
-rw-r--r--Modules/_localemodule.c38
-rw-r--r--Modules/_lsprof.c12
-rw-r--r--Modules/_sqlite/cache.c4
-rw-r--r--Modules/_sqlite/connection.c34
-rw-r--r--Modules/_sqlite/connection.h2
-rw-r--r--Modules/_sqlite/cursor.c30
-rw-r--r--Modules/_sqlite/module.c6
-rw-r--r--Modules/_sqlite/row.c6
-rw-r--r--Modules/_sqlite/statement.c18
-rw-r--r--Modules/_sre.c6
-rw-r--r--Modules/_ssl.c42
-rw-r--r--Modules/_struct.c38
-rw-r--r--Modules/_testcapimodule.c6
-rw-r--r--Modules/_tkinter.c82
-rw-r--r--Modules/almodule.c22
-rw-r--r--Modules/arraymodule.c18
-rw-r--r--Modules/audioop.c64
-rw-r--r--Modules/binascii.c84
-rw-r--r--Modules/bsddbmodule.c4
-rw-r--r--Modules/bz2module.c108
-rw-r--r--Modules/cPickle.c128
-rw-r--r--Modules/cStringIO.c14
-rw-r--r--Modules/cdmodule.c16
-rw-r--r--Modules/cgensupport.c4
-rw-r--r--Modules/cjkcodecs/cjkcodecs.h4
-rw-r--r--Modules/cjkcodecs/multibytecodec.c62
-rw-r--r--Modules/clmodule.c28
-rw-r--r--Modules/datetimemodule.c126
-rw-r--r--Modules/dbmmodule.c22
-rw-r--r--Modules/dlmodule.c12
-rw-r--r--Modules/errnomodule.c2
-rw-r--r--Modules/fcntlmodule.c6
-rw-r--r--Modules/flmodule.c20
-rw-r--r--Modules/fmmodule.c8
-rw-r--r--Modules/gcmodule.c8
-rw-r--r--Modules/gdbmmodule.c20
-rw-r--r--Modules/glmodule.c28
-rw-r--r--Modules/grpmodule.c8
-rw-r--r--Modules/imageop.c62
-rw-r--r--Modules/imgfile.c8
-rw-r--r--Modules/itertoolsmodule.c12
-rw-r--r--Modules/linuxaudiodev.c6
-rw-r--r--Modules/main.c2
-rw-r--r--Modules/md5module.c6
-rw-r--r--Modules/mmapmodule.c36
-rw-r--r--Modules/nismodule.c10
-rw-r--r--Modules/operator.c8
-rw-r--r--Modules/ossaudiodev.c18
-rw-r--r--Modules/parsermodule.c14
-rw-r--r--Modules/posixmodule.c68
-rw-r--r--Modules/pwdmodule.c2
-rw-r--r--Modules/pyexpat.c28
-rw-r--r--Modules/readline.c10
-rw-r--r--Modules/selectmodule.c2
-rw-r--r--Modules/sha256module.c10
-rw-r--r--Modules/sha512module.c10
-rw-r--r--Modules/shamodule.c8
-rw-r--r--Modules/socketmodule.c60
-rw-r--r--Modules/spwdmodule.c2
-rw-r--r--Modules/stropmodule.c92
-rw-r--r--Modules/sunaudiodev.c4
-rw-r--r--Modules/svmodule.c20
-rw-r--r--Modules/syslogmodule.c2
-rw-r--r--Modules/termios.c6
-rw-r--r--Modules/threadmodule.c2
-rw-r--r--Modules/timemodule.c6
-rw-r--r--Modules/unicodedata.c12
-rw-r--r--Modules/zipimport.c58
-rw-r--r--Modules/zlibmodule.c64
86 files changed, 1127 insertions, 1127 deletions
diff --git a/Modules/_bsddb.c b/Modules/_bsddb.c
index e2929ca7db..86b9839b39 100644
--- a/Modules/_bsddb.c
+++ b/Modules/_bsddb.c
@@ -398,7 +398,7 @@ make_key_dbt(DBObject* self, PyObject* keyobj, DBT* key, int* pflags)
/* no need to do anything, the structure has already been zeroed */
}
- else if (PyString_Check(keyobj)) {
+ else if (PyBytes_Check(keyobj)) {
/* verify access method type */
type = _DB_get_type(self);
if (type == -1)
@@ -417,15 +417,15 @@ make_key_dbt(DBObject* self, PyObject* keyobj, DBT* key, int* pflags)
* the code check for DB_THREAD and forceably set DBT_MALLOC
* when we otherwise would leave flags 0 to indicate that.
*/
- key->data = malloc(PyString_GET_SIZE(keyobj));
+ key->data = malloc(PyBytes_GET_SIZE(keyobj));
if (key->data == NULL) {
PyErr_SetString(PyExc_MemoryError, "Key memory allocation failed");
return 0;
}
- memcpy(key->data, PyString_AS_STRING(keyobj),
- PyString_GET_SIZE(keyobj));
+ memcpy(key->data, PyBytes_AS_STRING(keyobj),
+ PyBytes_GET_SIZE(keyobj));
key->flags = DB_DBT_REALLOC;
- key->size = PyString_GET_SIZE(keyobj);
+ key->size = PyBytes_GET_SIZE(keyobj);
}
else if (PyInt_Check(keyobj)) {
@@ -535,7 +535,7 @@ static PyObject *Build_PyString(const char *p,int s)
p=DummyString;
assert(s==0);
}
- return PyString_FromStringAndSize(p,s);
+ return PyBytes_FromStringAndSize(p,s);
}
static PyObject *BuildValue_S(const void *p,int s)
@@ -1291,12 +1291,12 @@ _db_associateCallback(DB* db, const DBT* priKey, const DBT* priData,
else if (PyInt_Check(result)) {
retval = PyInt_AsLong(result);
}
- else if (PyString_Check(result)) {
+ else if (PyBytes_Check(result)) {
char* data;
Py_ssize_t size;
CLEAR_DBT(*secKey);
- PyString_AsStringAndSize(result, &data, &size);
+ PyBytes_AsStringAndSize(result, &data, &size);
secKey->flags = DB_DBT_APPMALLOC; /* DB will free */
secKey->data = malloc(size); /* TODO, check this */
if (secKey->data) {
@@ -4412,7 +4412,7 @@ DBEnv_txn_recover(DBEnvObject* self, PyObject* args)
if (!retp) break;
flags=DB_NEXT; /* Prepare for next loop pass */
for (i=0; i<retp; i++) {
- gid=PyString_FromStringAndSize((char *)(preplist[i].gid),
+ gid=PyBytes_FromStringAndSize((char *)(preplist[i].gid),
DB_XIDDATASIZE);
if (!gid) {
Py_DECREF(list);
@@ -4870,7 +4870,7 @@ DBEnv_log_archive(DBEnvObject* self, PyObject* args)
if (log_list) {
char **log_list_start;
for (log_list_start = log_list; *log_list != NULL; ++log_list) {
- item = PyString_FromString (*log_list);
+ item = PyBytes_FromString (*log_list);
if (item == NULL) {
Py_DECREF(list);
list = NULL;
@@ -6296,7 +6296,7 @@ DBEnv_getattr(DBEnvObject* self, char *name)
if (home == NULL) {
RETURN_NONE();
}
- return PyString_FromString(home);
+ return PyBytes_FromString(home);
}
return Py_FindMethod(DBEnv_methods, (PyObject* )self, name);
@@ -6612,9 +6612,9 @@ DL_EXPORT(void) init_bsddb(void)
{
PyObject* m;
PyObject* d;
- PyObject* pybsddb_version_s = PyString_FromString( PY_BSDDB_VERSION );
- PyObject* db_version_s = PyString_FromString( DB_VERSION_STRING );
- PyObject* cvsid_s = PyString_FromString( rcs_id );
+ PyObject* pybsddb_version_s = PyBytes_FromString( PY_BSDDB_VERSION );
+ PyObject* db_version_s = PyBytes_FromString( DB_VERSION_STRING );
+ PyObject* cvsid_s = PyBytes_FromString( rcs_id );
PyObject* py_api;
/* Initialize the type of the new type objects here; doing it here
diff --git a/Modules/_bytesio.c b/Modules/_bytesio.c
index 8c5bb82de3..88511c6fe5 100644
--- a/Modules/_bytesio.c
+++ b/Modules/_bytesio.c
@@ -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,
@@ -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);
}
@@ -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,
@@ -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) {
@@ -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,
diff --git a/Modules/_codecsmodule.c b/Modules/_codecsmodule.c
index d4eb0d5b9c..e374766727 100644
--- a/Modules/_codecsmodule.c
+++ b/Modules/_codecsmodule.c
@@ -168,7 +168,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);
}
@@ -182,21 +182,21 @@ escape_encode(PyObject *self,
Py_ssize_t len;
if (!PyArg_ParseTuple(args, "O!|z:escape_encode",
- &PyString_Type, &str, &errors))
+ &PyBytes_Type, &str, &errors))
return NULL;
- str = PyString_Repr(str, 0);
+ str = PyBytes_Repr(str, 0);
if (!str)
return NULL;
/* The string will be quoted. Unquote, similar to unicode-escape. */
- buf = PyString_AS_STRING (str);
- len = PyString_GET_SIZE (str);
+ buf = PyBytes_AS_STRING (str);
+ len = PyBytes_GET_SIZE (str);
memmove(buf, buf+1, len-2);
- if (_PyString_Resize(&str, len-2) < 0)
+ if (_PyBytes_Resize(&str, len-2) < 0)
return NULL;
- return codec_tuple(str, PyString_Size(str));
+ return codec_tuple(str, PyBytes_Size(str));
}
#ifdef Py_USING_UNICODE
@@ -640,7 +640,7 @@ readbuffer_encode(PyObject *self,
&data, &size, &errors))
return NULL;
- return codec_tuple(PyString_FromStringAndSize(data, size),
+ return codec_tuple(PyBytes_FromStringAndSize(data, size),
size);
}
@@ -656,7 +656,7 @@ charbuffer_encode(PyObject *self,
&data, &size, &errors))
return NULL;
- return codec_tuple(PyString_FromStringAndSize(data, size),
+ return codec_tuple(PyBytes_FromStringAndSize(data, size),
size);
}
@@ -676,13 +676,13 @@ 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),
+ 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),
+ return codec_tuple(PyBytes_FromStringAndSize(data, size),
size);
}
}
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c
index 67700de728..f7d8d771c5 100644
--- a/Modules/_collectionsmodule.c
+++ b/Modules/_collectionsmodule.c
@@ -668,7 +668,7 @@ deque_repr(PyObject *deque)
if (i != 0) {
if (i < 0)
return NULL;
- return PyString_FromString("[...]");
+ return PyBytes_FromString("[...]");
}
aslist = PySequence_List(deque);
@@ -677,16 +677,16 @@ deque_repr(PyObject *deque)
return NULL;
}
if (((dequeobject *)deque)->maxlen != -1)
- fmt = PyString_FromFormat("deque(%%r, maxlen=%i)",
+ fmt = PyBytes_FromFormat("deque(%%r, maxlen=%i)",
((dequeobject *)deque)->maxlen);
else
- fmt = PyString_FromString("deque(%r)");
+ fmt = PyBytes_FromString("deque(%r)");
if (fmt == NULL) {
Py_DECREF(aslist);
Py_ReprLeave(deque);
return NULL;
}
- result = PyString_Format(fmt, aslist);
+ result = PyBytes_Format(fmt, aslist);
Py_DECREF(fmt);
Py_DECREF(aslist);
Py_ReprLeave(deque);
@@ -1298,14 +1298,14 @@ defdict_repr(defdictobject *dd)
if (baserepr == NULL)
return NULL;
if (dd->default_factory == NULL)
- defrepr = PyString_FromString("None");
+ defrepr = PyBytes_FromString("None");
else
{
int status = Py_ReprEnter(dd->default_factory);
if (status != 0) {
if (status < 0)
return NULL;
- defrepr = PyString_FromString("...");
+ defrepr = PyBytes_FromString("...");
}
else
defrepr = PyObject_Repr(dd->default_factory);
@@ -1315,9 +1315,9 @@ defdict_repr(defdictobject *dd)
Py_DECREF(baserepr);
return NULL;
}
- result = PyString_FromFormat("defaultdict(%s, %s)",
- PyString_AS_STRING(defrepr),
- PyString_AS_STRING(baserepr));
+ result = PyBytes_FromFormat("defaultdict(%s, %s)",
+ PyBytes_AS_STRING(defrepr),
+ PyBytes_AS_STRING(baserepr));
Py_DECREF(defrepr);
Py_DECREF(baserepr);
return result;
diff --git a/Modules/_csv.c b/Modules/_csv.c
index c628927b53..ba9057afc0 100644
--- a/Modules/_csv.c
+++ b/Modules/_csv.c
@@ -176,7 +176,7 @@ get_nullchar_as_None(char c)
return Py_None;
}
else
- return PyString_FromStringAndSize((char*)&c, 1);
+ return PyBytes_FromStringAndSize((char*)&c, 1);
}
static PyObject *
@@ -235,16 +235,16 @@ _set_char(const char *name, char *target, PyObject *src, char dflt)
if (src == NULL)
*target = dflt;
else {
- if (src == Py_None || PyString_Size(src) == 0)
+ if (src == Py_None || PyBytes_Size(src) == 0)
*target = '\0';
- else if (!PyString_Check(src) || PyString_Size(src) != 1) {
+ else if (!PyBytes_Check(src) || PyBytes_Size(src) != 1) {
PyErr_Format(PyExc_TypeError,
"\"%s\" must be an 1-character string",
name);
return -1;
}
else {
- char *s = PyString_AsString(src);
+ char *s = PyBytes_AsString(src);
if (s == NULL)
return -1;
*target = s[0];
@@ -257,7 +257,7 @@ static int
_set_str(const char *name, PyObject **target, PyObject *src, const char *dflt)
{
if (src == NULL)
- *target = PyString_FromString(dflt);
+ *target = PyBytes_FromString(dflt);
else {
if (src == Py_None)
*target = NULL;
@@ -528,7 +528,7 @@ parse_save_field(ReaderObj *self)
{
PyObject *field;
- field = PyString_FromStringAndSize(self->field, self->field_len);
+ field = PyBytes_FromStringAndSize(self->field, self->field_len);
if (field == NULL)
return -1;
self->field_len = 0;
@@ -787,8 +787,8 @@ Reader_iternext(ReaderObj *self)
}
++self->line_num;
- line = PyString_AsString(lineobj);
- linelen = PyString_Size(lineobj);
+ line = PyBytes_AsString(lineobj);
+ linelen = PyBytes_Size(lineobj);
if (line == NULL || linelen < 0) {
Py_DECREF(lineobj);
@@ -976,7 +976,7 @@ join_append_data(WriterObj *self, char *field, int quote_empty,
rec_len++;\
} while(0)
- lineterm = PyString_AsString(dialect->lineterminator);
+ lineterm = PyBytes_AsString(dialect->lineterminator);
if (lineterm == NULL)
return -1;
@@ -1101,7 +1101,7 @@ join_append_lineterminator(WriterObj *self)
int terminator_len;
char *terminator;
- terminator_len = PyString_Size(self->dialect->lineterminator);
+ terminator_len = PyBytes_Size(self->dialect->lineterminator);
if (terminator_len == -1)
return 0;
@@ -1109,7 +1109,7 @@ join_append_lineterminator(WriterObj *self)
if (!join_check_rec_size(self, self->rec_len + terminator_len))
return 0;
- terminator = PyString_AsString(self->dialect->lineterminator);
+ terminator = PyBytes_AsString(self->dialect->lineterminator);
if (terminator == NULL)
return 0;
memmove(self->rec + self->rec_len, terminator, terminator_len);
@@ -1161,9 +1161,9 @@ csv_writerow(WriterObj *self, PyObject *seq)
break;
}
- if (PyString_Check(field)) {
+ if (PyBytes_Check(field)) {
append_ok = join_append(self,
- PyString_AS_STRING(field),
+ PyBytes_AS_STRING(field),
&quoted, len == 1);
Py_DECREF(field);
}
@@ -1179,7 +1179,7 @@ csv_writerow(WriterObj *self, PyObject *seq)
if (str == NULL)
return NULL;
- append_ok = join_append(self, PyString_AS_STRING(str),
+ append_ok = join_append(self, PyBytes_AS_STRING(str),
&quoted, len == 1);
Py_DECREF(str);
}
diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c
index 1bb76e38c3..cce986d1b3 100644
--- a/Modules/_ctypes/_ctypes.c
+++ b/Modules/_ctypes/_ctypes.c
@@ -684,8 +684,8 @@ StructType_setattro(PyObject *self, PyObject *key, PyObject *value)
if (-1 == PyType_Type.tp_setattro(self, key, value))
return -1;
- if (value && PyString_Check(key) &&
- 0 == strcmp(PyString_AS_STRING(key), "_fields_"))
+ if (value && PyBytes_Check(key) &&
+ 0 == strcmp(PyBytes_AS_STRING(key), "_fields_"))
return StructUnionType_update_stgdict(self, value, 1);
return 0;
}
@@ -698,8 +698,8 @@ UnionType_setattro(PyObject *self, PyObject *key, PyObject *value)
if (-1 == PyObject_GenericSetAttr(self, key, value))
return -1;
- if (PyString_Check(key) &&
- 0 == strcmp(PyString_AS_STRING(key), "_fields_"))
+ if (PyBytes_Check(key) &&
+ 0 == strcmp(PyBytes_AS_STRING(key), "_fields_"))
return StructUnionType_update_stgdict(self, value, 0);
return 0;
}
@@ -1025,7 +1025,7 @@ CharArray_set_raw(CDataObject *self, PyObject *value)
size = Py_TYPE(value)->tp_as_buffer->bf_getreadbuffer(value, 0, (void *)&ptr);
if (size < 0)
return -1;
- } else if (-1 == PyString_AsStringAndSize(value, &ptr, &size)) {
+ } else if (-1 == PyBytes_AsStringAndSize(value, &ptr, &size)) {
return -1;
}
if (size > self->b_size) {
@@ -1042,7 +1042,7 @@ CharArray_set_raw(CDataObject *self, PyObject *value)
static PyObject *
CharArray_get_raw(CDataObject *self)
{
- return PyString_FromStringAndSize(self->b_ptr, self->b_size);
+ return PyBytes_FromStringAndSize(self->b_ptr, self->b_size);
}
static PyObject *
@@ -1053,7 +1053,7 @@ CharArray_get_value(CDataObject *self)
for (i = 0; i < self->b_size; ++i)
if (*ptr++ == '\0')
break;
- return PyString_FromStringAndSize(self->b_ptr, i);
+ return PyBytes_FromStringAndSize(self->b_ptr, i);
}
static int
@@ -1074,14 +1074,14 @@ CharArray_set_value(CDataObject *self, PyObject *value)
conversion_mode_errors);
if (!value)
return -1;
- } else if (!PyString_Check(value)) {
+ } else if (!PyBytes_Check(value)) {
PyErr_Format(PyExc_TypeError,
"string expected instead of %s instance",
Py_TYPE(value)->tp_name);
return -1;
} else
Py_INCREF(value);
- size = PyString_GET_SIZE(value);
+ size = PyBytes_GET_SIZE(value);
if (size > self->b_size) {
PyErr_SetString(PyExc_ValueError,
"string too long");
@@ -1089,7 +1089,7 @@ CharArray_set_value(CDataObject *self, PyObject *value)
return -1;
}
- ptr = PyString_AS_STRING(value);
+ ptr = PyBytes_AS_STRING(value);
memcpy(self->b_ptr, ptr, size);
if (size < self->b_size)
self->b_ptr[size] = '\0';
@@ -1128,7 +1128,7 @@ WCharArray_set_value(CDataObject *self, PyObject *value)
"can't delete attribute");
return -1;
}
- if (PyString_Check(value)) {
+ if (PyBytes_Check(value)) {
value = PyUnicode_FromEncodedObject(value,
conversion_mode_encoding,
conversion_mode_errors);
@@ -1402,7 +1402,7 @@ c_wchar_p_from_param(PyObject *type, PyObject *value)
Py_INCREF(Py_None);
return Py_None;
}
- if (PyUnicode_Check(value) || PyString_Check(value)) {
+ if (PyUnicode_Check(value) || PyBytes_Check(value)) {
PyCArgObject *parg;
struct fielddesc *fd = getentry("Z");
@@ -1466,7 +1466,7 @@ c_char_p_from_param(PyObject *type, PyObject *value)
Py_INCREF(Py_None);
return Py_None;
}
- if (PyString_Check(value) || PyUnicode_Check(value)) {
+ if (PyBytes_Check(value) || PyUnicode_Check(value)) {
PyCArgObject *parg;
struct fielddesc *fd = getentry("z");
@@ -1552,7 +1552,7 @@ c_void_p_from_param(PyObject *type, PyObject *value)
return (PyObject *)parg;
}
/* string */
- if (PyString_Check(value)) {
+ if (PyBytes_Check(value)) {
PyCArgObject *parg;
struct fielddesc *fd = getentry("z");
@@ -1623,10 +1623,10 @@ c_void_p_from_param(PyObject *type, PyObject *value)
}
/* c_char_p, c_wchar_p */
stgd = PyObject_stgdict(value);
- if (stgd && CDataObject_Check(value) && stgd->proto && PyString_Check(stgd->proto)) {
+ if (stgd && CDataObject_Check(value) && stgd->proto && PyBytes_Check(stgd->proto)) {
PyCArgObject *parg;
- switch (PyString_AS_STRING(stgd->proto)[0]) {
+ switch (PyBytes_AS_STRING(stgd->proto)[0]) {
case 'z': /* c_char_p */
case 'Z': /* c_wchar_p */
parg = new_CArgObject();
@@ -1683,13 +1683,13 @@ static PyObject *CreateSwappedType(PyTypeObject *type, PyObject *args, PyObject
if (suffix == NULL)
#ifdef WORDS_BIGENDIAN
- suffix = PyString_InternFromString("_le");
+ suffix = PyBytes_InternFromString("_le");
#else
- suffix = PyString_InternFromString("_be");
+ suffix = PyBytes_InternFromString("_be");
#endif
Py_INCREF(name);
- PyString_Concat(&name, suffix);
+ PyBytes_Concat(&name, suffix);
if (name == NULL)
return NULL;
@@ -1744,7 +1744,7 @@ SimpleType_paramfunc(CDataObject *self)
dict = PyObject_stgdict((PyObject *)self);
assert(dict); /* Cannot be NULL for CDataObject instances */
- fmt = PyString_AsString(dict->proto);
+ fmt = PyBytes_AsString(dict->proto);
assert(fmt);
fd = getentry(fmt);
@@ -1779,9 +1779,9 @@ SimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
proto = PyObject_GetAttrString((PyObject *)result, "_type_"); /* new ref */
if (!proto
- || !PyString_Check(proto)
- || 1 != strlen(PyString_AS_STRING(proto))
- || !strchr(SIMPLE_TYPE_CHARS, PyString_AS_STRING(proto)[0])) {
+ || !PyBytes_Check(proto)
+ || 1 != strlen(PyBytes_AS_STRING(proto))
+ || !strchr(SIMPLE_TYPE_CHARS, PyBytes_AS_STRING(proto)[0])) {
PyErr_Format(PyExc_AttributeError,
"class must define a '_type_' attribute which must be\n"
"a single character string containing one of '%s'.",
@@ -1790,12 +1790,12 @@ SimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
Py_DECREF(result);
return NULL;
}
- fmt = getentry(PyString_AS_STRING(proto));
+ fmt = getentry(PyBytes_AS_STRING(proto));
if (fmt == NULL) {
Py_DECREF(result);
PyErr_Format(PyExc_ValueError,
"_type_ '%s' not supported",
- PyString_AS_STRING(proto));
+ PyBytes_AS_STRING(proto));
return NULL;
}
@@ -1835,7 +1835,7 @@ SimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
Overrides the SimpleType_from_param generic method.
*/
if (result->tp_base == &Simple_Type) {
- switch (PyString_AS_STRING(proto)[0]) {
+ switch (PyBytes_AS_STRING(proto)[0]) {
case 'z': /* c_char_p */
ml = &c_char_p_method;
stgdict->flags |= TYPEFLAG_ISPOINTER;
@@ -1940,7 +1940,7 @@ SimpleType_from_param(PyObject *type, PyObject *value)
assert(dict);
/* I think we can rely on this being a one-character string */
- fmt = PyString_AsString(dict->proto);
+ fmt = PyBytes_AsString(dict->proto);
assert(fmt);
fd = getentry(fmt);
@@ -2290,7 +2290,7 @@ unique_key(CDataObject *target, Py_ssize_t index)
#endif
target = target->b_base;
}
- return PyString_FromStringAndSize(string, cp-string);
+ return PyBytes_FromStringAndSize(string, cp-string);
}
/*
@@ -2435,7 +2435,7 @@ CData_reduce(PyObject *_self, PyObject *args)
_unpickle,
Py_TYPE(_self),
PyObject_GetAttrString(_self, "__dict__"),
- PyString_FromStringAndSize(self->b_ptr, self->b_size));
+ PyBytes_FromStringAndSize(self->b_ptr, self->b_size));
}
static PyObject *
@@ -2984,9 +2984,9 @@ _check_outarg_type(PyObject *arg, Py_ssize_t index)
dict = PyType_stgdict(arg);
if (dict
/* simple pointer types, c_void_p, c_wchar_p, BSTR, ... */
- && PyString_Check(dict->proto)
+ && PyBytes_Check(dict->proto)
/* We only allow c_void_p, c_char_p and c_wchar_p as a simple output parameter type */
- && (strchr("PzZ", PyString_AS_STRING(dict->proto)[0]))) {
+ && (strchr("PzZ", PyBytes_AS_STRING(dict->proto)[0]))) {
return 1;
}
@@ -3071,8 +3071,8 @@ _get_name(PyObject *obj, char **pname)
return 1;
}
#endif
- if (PyString_Check(obj) || PyUnicode_Check(obj)) {
- *pname = PyString_AsString(obj);
+ if (PyBytes_Check(obj) || PyUnicode_Check(obj)) {
+ *pname = PyBytes_AsString(obj);
return *pname ? 1 : 0;
}
PyErr_SetString(PyExc_TypeError,
@@ -3422,7 +3422,7 @@ _build_callargs(CFuncPtrObject *self, PyObject *argtypes,
/* We HAVE already checked that the tuple can be parsed with "i|zO", so... */
Py_ssize_t tsize = PyTuple_GET_SIZE(item);
flag = PyInt_AS_LONG(PyTuple_GET_ITEM(item, 0));
- name = tsize > 1 ? PyString_AS_STRING(PyTuple_GET_ITEM(item, 1)) : NULL;
+ name = tsize > 1 ? PyBytes_AS_STRING(PyTuple_GET_ITEM(item, 1)) : NULL;
defval = tsize > 2 ? PyTuple_GET_ITEM(item, 2) : NULL;
switch (flag & (PARAMFLAG_FIN | PARAMFLAG_FOUT | PARAMFLAG_FLCID)) {
@@ -3476,7 +3476,7 @@ _build_callargs(CFuncPtrObject *self, PyObject *argtypes,
"NULL stgdict unexpected");
goto error;
}
- if (PyString_Check(dict->proto)) {
+ if (PyBytes_Check(dict->proto)) {
PyErr_Format(
PyExc_TypeError,
"%s 'out' parameter must be passed as default value",
@@ -3774,12 +3774,12 @@ CFuncPtr_repr(CFuncPtrObject *self)
{
#ifdef MS_WIN32
if (self->index)
- return PyString_FromFormat("<COM method offset %d: %s at %p>",
+ return PyBytes_FromFormat("<COM method offset %d: %s at %p>",
self->index - 0x1000,
Py_TYPE(self)->tp_name,
self);
#endif
- return PyString_FromFormat("<%s object at %p>",
+ return PyBytes_FromFormat("<%s object at %p>",
Py_TYPE(self)->tp_name,
self);
}
@@ -3888,7 +3888,7 @@ Struct_init(PyObject *self, PyObject *args, PyObject *kwds)
}
if (kwds && PyDict_GetItem(kwds, name)) {
- char *field = PyString_AsString(name);
+ char *field = PyBytes_AsString(name);
if (field == NULL) {
PyErr_Clear();
field = "???";
@@ -4090,7 +4090,7 @@ Array_slice(PyObject *_self, Py_ssize_t ilow, Py_ssize_t ihigh)
type, so this cannot be NULL */
if (itemdict->getfunc == getentry("c")->getfunc) {
char *ptr = (char *)self->b_ptr;
- return PyString_FromStringAndSize(ptr + ilow, len);
+ return PyBytes_FromStringAndSize(ptr + ilow, len);
#ifdef CTYPES_UNICODE
} else if (itemdict->getfunc == getentry("u")->getfunc) {
wchar_t *ptr = (wchar_t *)self->b_ptr;
@@ -4147,9 +4147,9 @@ Array_subscript(PyObject *_self, PyObject *item)
char *dest;
if (slicelen <= 0)
- return PyString_FromString("");
+ return PyBytes_FromString("");
if (step == 1) {
- return PyString_FromStringAndSize(ptr + start,
+ return PyBytes_FromStringAndSize(ptr + start,
slicelen);
}
dest = (char *)PyMem_Malloc(slicelen);
@@ -4162,7 +4162,7 @@ Array_subscript(PyObject *_self, PyObject *item)
dest[i] = ptr[cur];
}
- np = PyString_FromStringAndSize(dest, slicelen);
+ np = PyBytes_FromStringAndSize(dest, slicelen);
PyMem_Free(dest);
return np;
}
@@ -4572,12 +4572,12 @@ Simple_repr(CDataObject *self)
static PyObject *format;
if (Py_TYPE(self)->tp_base != &Simple_Type) {
- return PyString_FromFormat("<%s object at %p>",
+ return PyBytes_FromFormat("<%s object at %p>",
Py_TYPE(self)->tp_name, self);
}
if (format == NULL) {
- format = PyString_InternFromString("%s(%r)");
+ format = PyBytes_InternFromString("%s(%r)");
if (format == NULL)
return NULL;
}
@@ -4586,7 +4586,7 @@ Simple_repr(CDataObject *self)
if (val == NULL)
return NULL;
- name = PyString_FromString(Py_TYPE(self)->tp_name);
+ name = PyBytes_FromString(Py_TYPE(self)->tp_name);
if (name == NULL) {
Py_DECREF(val);
return NULL;
@@ -4598,7 +4598,7 @@ Simple_repr(CDataObject *self)
if (args == NULL)
return NULL;
- result = PyString_Format(format, args);
+ result = PyBytes_Format(format, args);
Py_DECREF(args);
return result;
}
@@ -4832,7 +4832,7 @@ Pointer_slice(PyObject *_self, Py_ssize_t ilow, Py_ssize_t ihigh)
assert(itemdict);
if (itemdict->getfunc == getentry("c")->getfunc) {
char *ptr = *(char **)self->b_ptr;
- return PyString_FromStringAndSize(ptr + ilow, len);
+ return PyBytes_FromStringAndSize(ptr + ilow, len);
#ifdef CTYPES_UNICODE
} else if (itemdict->getfunc == getentry("u")->getfunc) {
wchar_t *ptr = *(wchar_t **)self->b_ptr;
@@ -4929,9 +4929,9 @@ Pointer_subscript(PyObject *_self, PyObject *item)
char *dest;
if (len <= 0)
- return PyString_FromString("");
+ return PyBytes_FromString("");
if (step == 1) {
- return PyString_FromStringAndSize(ptr + start,
+ return PyBytes_FromStringAndSize(ptr + start,
len);
}
dest = (char *)PyMem_Malloc(len);
@@ -4940,7 +4940,7 @@ Pointer_subscript(PyObject *_self, PyObject *item)
for (cur = start, i = 0; i < len; cur += step, i++) {
dest[i] = ptr[cur];
}
- np = PyString_FromStringAndSize(dest, len);
+ np = PyBytes_FromStringAndSize(dest, len);
PyMem_Free(dest);
return np;
}
@@ -5140,7 +5140,7 @@ create_comerror(void)
++methods;
}
- s = PyString_FromString(comerror_doc);
+ s = PyBytes_FromString(comerror_doc);
if (s == NULL)
goto error;
status = PyDict_SetItemString(dict, "__doc__", s);
@@ -5166,8 +5166,8 @@ static PyObject *
string_at(const char *ptr, int size)
{
if (size == -1)
- return PyString_FromString(ptr);
- return PyString_FromStringAndSize(ptr, size);
+ return PyBytes_FromString(ptr);
+ return PyBytes_FromStringAndSize(ptr, size);
}
static int
@@ -5181,8 +5181,8 @@ cast_check_pointertype(PyObject *arg)
return 1;
dict = PyType_stgdict(arg);
if (dict) {
- if (PyString_Check(dict->proto)
- && (strchr("sPzUZXO", PyString_AS_STRING(dict->proto)[0]))) {
+ if (PyBytes_Check(dict->proto)
+ && (strchr("sPzUZXO", PyBytes_AS_STRING(dict->proto)[0]))) {
/* simple pointer types, c_void_p, c_wchar_p, BSTR, ... */
return 1;
}
diff --git a/Modules/_ctypes/callbacks.c b/Modules/_ctypes/callbacks.c
index 09bcbc2a66..b78c5282c8 100644
--- a/Modules/_ctypes/callbacks.c
+++ b/Modules/_ctypes/callbacks.c
@@ -107,15 +107,15 @@ void _AddTraceback(char *funcname, char *filename, int lineno)
PyCodeObject *py_code = 0;
PyFrameObject *py_frame = 0;
- py_srcfile = PyString_FromString(filename);
+ py_srcfile = PyBytes_FromString(filename);
if (!py_srcfile) goto bad;
- py_funcname = PyString_FromString(funcname);
+ py_funcname = PyBytes_FromString(funcname);
if (!py_funcname) goto bad;
py_globals = PyDict_New();
if (!py_globals) goto bad;
empty_tuple = PyTuple_New(0);
if (!empty_tuple) goto bad;
- empty_string = PyString_FromString("");
+ empty_string = PyBytes_FromString("");
if (!empty_string) goto bad;
py_code = PyCode_New(
0, /*int argcount,*/
@@ -460,7 +460,7 @@ long Call_GetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
static PyObject *context;
if (context == NULL)
- context = PyString_InternFromString("_ctypes.DllGetClassObject");
+ context = PyBytes_InternFromString("_ctypes.DllGetClassObject");
mod = PyImport_ImportModuleNoBlock("ctypes");
if (!mod) {
@@ -539,7 +539,7 @@ long Call_CanUnloadNow(void)
static PyObject *context;
if (context == NULL)
- context = PyString_InternFromString("_ctypes.DllCanUnloadNow");
+ context = PyBytes_InternFromString("_ctypes.DllCanUnloadNow");
mod = PyImport_ImportModuleNoBlock("ctypes");
if (!mod) {
diff --git a/Modules/_ctypes/callproc.c b/Modules/_ctypes/callproc.c
index c5281799de..95b2709e79 100644
--- a/Modules/_ctypes/callproc.c
+++ b/Modules/_ctypes/callproc.c
@@ -370,7 +370,7 @@ PyCArg_repr(PyCArgObject *self)
self->tag, self);
break;
}
- return PyString_FromString(buffer);
+ return PyBytes_FromString(buffer);
}
static PyMemberDef PyCArgType_members[] = {
@@ -518,9 +518,9 @@ static int ConvParam(PyObject *obj, Py_ssize_t index, struct argument *pa)
return 0;
}
- if (PyString_Check(obj)) {
+ if (PyBytes_Check(obj)) {
pa->ffi_type = &ffi_type_pointer;
- pa->value.p = PyString_AS_STRING(obj);
+ pa->value.p = PyBytes_AS_STRING(obj);
Py_INCREF(obj);
pa->keep = obj;
return 0;
@@ -781,7 +781,7 @@ void Extend_Error_Info(PyObject *exc_class, char *fmt, ...)
PyObject *tp, *v, *tb, *s, *cls_str, *msg_str;
va_start(vargs, fmt);
- s = PyString_FromFormatV(fmt, vargs);
+ s = PyBytes_FromFormatV(fmt, vargs);
va_end(vargs);
if (!s)
return;
@@ -790,18 +790,18 @@ void Extend_Error_Info(PyObject *exc_class, char *fmt, ...)
PyErr_NormalizeException(&tp, &v, &tb);
cls_str = PyObject_Str(tp);
if (cls_str) {
- PyString_ConcatAndDel(&s, cls_str);
- PyString_ConcatAndDel(&s, PyString_FromString(": "));
+ PyBytes_ConcatAndDel(&s, cls_str);
+ PyBytes_ConcatAndDel(&s, PyBytes_FromString(": "));
if (s == NULL)
goto error;
} else
PyErr_Clear();
msg_str = PyObject_Str(v);
if (msg_str)
- PyString_ConcatAndDel(&s, msg_str);
+ PyBytes_ConcatAndDel(&s, msg_str);
else {
PyErr_Clear();
- PyString_ConcatAndDel(&s, PyString_FromString("???"));
+ PyBytes_ConcatAndDel(&s, PyBytes_FromString("???"));
if (s == NULL)
goto error;
}
@@ -1105,7 +1105,7 @@ static PyObject *load_library(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "O|O:LoadLibrary", &nameobj, &ignored))
return NULL;
#ifdef _UNICODE
- name = alloca((PyString_Size(nameobj) + 1) * sizeof(WCHAR));
+ name = alloca((PyBytes_Size(nameobj) + 1) * sizeof(WCHAR));
if (!name) {
PyErr_NoMemory();
return NULL;
@@ -1113,14 +1113,14 @@ static PyObject *load_library(PyObject *self, PyObject *args)
{
int r;
- char *aname = PyString_AsString(nameobj);
+ char *aname = PyBytes_AsString(nameobj);
if(!aname)
return NULL;
- r = MultiByteToWideChar(CP_ACP, 0, aname, -1, name, PyString_Size(nameobj) + 1);
+ r = MultiByteToWideChar(CP_ACP, 0, aname, -1, name, PyBytes_Size(nameobj) + 1);
name[r] = 0;
}
#else
- name = PyString_AsString(nameobj);
+ name = PyBytes_AsString(nameobj);
if(!name)
return NULL;
#endif
@@ -1613,9 +1613,9 @@ POINTER(PyObject *self, PyObject *cls)
Py_INCREF(result);
return result;
}
- if (PyString_CheckExact(cls)) {
- buf = alloca(strlen(PyString_AS_STRING(cls)) + 3 + 1);
- sprintf(buf, "LP_%s", PyString_AS_STRING(cls));
+ if (PyBytes_CheckExact(cls)) {
+ buf = alloca(strlen(PyBytes_AS_STRING(cls)) + 3 + 1);
+ sprintf(buf, "LP_%s", PyBytes_AS_STRING(cls));
result = PyObject_CallFunction((PyObject *)Py_TYPE(&Pointer_Type),
"s(O){}",
buf,
diff --git a/Modules/_ctypes/cfield.c b/Modules/_ctypes/cfield.c
index 3fd7756793..6cf5443638 100644
--- a/Modules/_ctypes/cfield.c
+++ b/Modules/_ctypes/cfield.c
@@ -272,7 +272,7 @@ CField_repr(CFieldObject *self)
name = ((PyTypeObject *)self->proto)->tp_name;
if (bits)
- result = PyString_FromFormat(
+ result = PyBytes_FromFormat(
#if (PY_VERSION_HEX < 0x02050000)
"<Field type=%s, ofs=%d:%d, bits=%d>",
#else
@@ -280,7 +280,7 @@ CField_repr(CFieldObject *self)
#endif
name, self->offset, size, bits);
else
- result = PyString_FromFormat(
+ result = PyBytes_FromFormat(
#if (PY_VERSION_HEX < 0x02050000)
"<Field type=%s, ofs=%d, size=%d>",
#else
@@ -1164,12 +1164,12 @@ O_set(void *ptr, PyObject *value, Py_ssize_t size)
static PyObject *
c_set(void *ptr, PyObject *value, Py_ssize_t size)
{
- if (!PyString_Check(value) || (1 != PyString_Size(value))) {
+ if (!PyBytes_Check(value) || (1 != PyBytes_Size(value))) {
PyErr_Format(PyExc_TypeError,
"one character string expected");
return NULL;
}
- *(char *)ptr = PyString_AS_STRING(value)[0];
+ *(char *)ptr = PyBytes_AS_STRING(value)[0];
_RET(value);
}
@@ -1177,7 +1177,7 @@ c_set(void *ptr, PyObject *value, Py_ssize_t size)
static PyObject *
c_get(void *ptr, Py_ssize_t size)
{
- return PyString_FromStringAndSize((char *)ptr, 1);
+ return PyBytes_FromStringAndSize((char *)ptr, 1);
}
#ifdef CTYPES_UNICODE
@@ -1187,7 +1187,7 @@ u_set(void *ptr, PyObject *value, Py_ssize_t size)
{
Py_ssize_t len;
- if (PyString_Check(value)) {
+ if (PyBytes_Check(value)) {
value = PyUnicode_FromEncodedObject(value,
conversion_mode_encoding,
conversion_mode_errors);
@@ -1262,7 +1262,7 @@ U_set(void *ptr, PyObject *value, Py_ssize_t length)
/* It's easier to calculate in characters than in bytes */
length /= sizeof(wchar_t);
- if (PyString_Check(value)) {
+ if (PyBytes_Check(value)) {
value = PyUnicode_FromEncodedObject(value,
conversion_mode_encoding,
conversion_mode_errors);
@@ -1301,21 +1301,21 @@ s_get(void *ptr, Py_ssize_t size)
PyObject *result;
size_t slen;
- result = PyString_FromString((char *)ptr);
+ result = PyBytes_FromString((char *)ptr);
if (!result)
return NULL;
/* chop off at the first NUL character, if any.
* On error, result will be deallocated and set to NULL.
*/
- slen = strlen(PyString_AS_STRING(result));
+ slen = strlen(PyBytes_AS_STRING(result));
size = min(size, (Py_ssize_t)slen);
if (result->ob_refcnt == 1) {
/* shorten the result */
- _PyString_Resize(&result, size);
+ _PyBytes_Resize(&result, size);
return result;
} else
/* cannot shorten the result */
- return PyString_FromStringAndSize(ptr, size);
+ return PyBytes_FromStringAndSize(ptr, size);
}
static PyObject *
@@ -1324,7 +1324,7 @@ s_set(void *ptr, PyObject *value, Py_ssize_t length)
char *data;
Py_ssize_t size;
- data = PyString_AsString(value);
+ data = PyBytes_AsString(value);
if (!data)
return NULL;
size = strlen(data);
@@ -1356,8 +1356,8 @@ z_set(void *ptr, PyObject *value, Py_ssize_t size)
Py_INCREF(value);
return value;
}
- if (PyString_Check(value)) {
- *(char **)ptr = PyString_AS_STRING(value);
+ if (PyBytes_Check(value)) {
+ *(char **)ptr = PyBytes_AS_STRING(value);
Py_INCREF(value);
return value;
} else if (PyUnicode_Check(value)) {
@@ -1366,7 +1366,7 @@ z_set(void *ptr, PyObject *value, Py_ssize_t size)
conversion_mode_errors);
if (str == NULL)
return NULL;
- *(char **)ptr = PyString_AS_STRING(str);
+ *(char **)ptr = PyBytes_AS_STRING(str);
return str;
} else if (PyInt_Check(value) || PyLong_Check(value)) {
#if SIZEOF_VOID_P == SIZEOF_LONG_LONG
@@ -1395,7 +1395,7 @@ z_get(void *ptr, Py_ssize_t size)
return NULL;
}
#endif
- return PyString_FromString(*(char **)ptr);
+ return PyBytes_FromString(*(char **)ptr);
} else {
Py_INCREF(Py_None);
return Py_None;
@@ -1411,7 +1411,7 @@ Z_set(void *ptr, PyObject *value, Py_ssize_t size)
Py_INCREF(value);
return value;
}
- if (PyString_Check(value)) {
+ if (PyBytes_Check(value)) {
value = PyUnicode_FromEncodedObject(value,
conversion_mode_encoding,
conversion_mode_errors);
@@ -1502,7 +1502,7 @@ BSTR_set(void *ptr, PyObject *value, Py_ssize_t size)
/* convert value into a PyUnicodeObject or NULL */
if (Py_None == value) {
value = NULL;
- } else if (PyString_Check(value)) {
+ } else if (PyBytes_Check(value)) {
value = PyUnicode_FromEncodedObject(value,
conversion_mode_encoding,
conversion_mode_errors);
diff --git a/Modules/_curses_panel.c b/Modules/_curses_panel.c
index 6831473b06..6b618ac535 100644
--- a/Modules/_curses_panel.c
+++ b/Modules/_curses_panel.c
@@ -472,7 +472,7 @@ init_curses_panel(void)
PyDict_SetItemString(d, "error", PyCursesError);
/* Make the version available */
- v = PyString_FromString(PyCursesVersion);
+ v = PyBytes_FromString(PyCursesVersion);
PyDict_SetItemString(d, "version", v);
PyDict_SetItemString(d, "__version__", v);
Py_DECREF(v);
diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c
index 137c580731..964a260bb2 100644
--- a/Modules/_cursesmodule.c
+++ b/Modules/_cursesmodule.c
@@ -198,9 +198,9 @@ PyCurses_ConvertToChtype(PyObject *obj, chtype *ch)
{
if (PyInt_Check(obj)) {
*ch = (chtype) PyInt_AsLong(obj);
- } else if(PyString_Check(obj)
- && (PyString_Size(obj) == 1)) {
- *ch = (chtype) *PyString_AsString(obj);
+ } else if(PyBytes_Check(obj)
+ && (PyBytes_Size(obj) == 1)) {
+ *ch = (chtype) *PyBytes_AsString(obj);
} else {
return 0;
}
@@ -886,9 +886,9 @@ PyCursesWindow_GetKey(PyCursesWindowObject *self, PyObject *args)
return Py_BuildValue("c", rtn);
else
#if defined(__NetBSD__)
- return PyString_FromString(unctrl(rtn));
+ return PyBytes_FromString(unctrl(rtn));
#else
- return PyString_FromString((char *)keyname(rtn));
+ return PyBytes_FromString((char *)keyname(rtn));
#endif
}
@@ -943,7 +943,7 @@ PyCursesWindow_GetStr(PyCursesWindowObject *self, PyObject *args)
}
if (rtn2 == ERR)
rtn[0] = 0;
- return PyString_FromString(rtn);
+ return PyBytes_FromString(rtn);
}
static PyObject *
@@ -1095,7 +1095,7 @@ PyCursesWindow_InStr(PyCursesWindowObject *self, PyObject *args)
}
if (rtn2 == ERR)
rtn[0] = 0;
- return PyString_FromString(rtn);
+ return PyBytes_FromString(rtn);
}
static PyObject *
@@ -1757,7 +1757,7 @@ PyCurses_EraseChar(PyObject *self)
ch = erasechar();
- return PyString_FromStringAndSize(&ch, 1);
+ return PyBytes_FromStringAndSize(&ch, 1);
}
static PyObject *
@@ -2114,7 +2114,7 @@ PyCurses_KeyName(PyObject *self, PyObject *args)
}
knp = keyname(ch);
- return PyString_FromString((knp == NULL) ? "" : (char *)knp);
+ return PyBytes_FromString((knp == NULL) ? "" : (char *)knp);
}
#endif
@@ -2125,7 +2125,7 @@ PyCurses_KillChar(PyObject *self)
ch = killchar();
- return PyString_FromStringAndSize(&ch, 1);
+ return PyBytes_FromStringAndSize(&ch, 1);
}
static PyObject *
@@ -2496,7 +2496,7 @@ PyCurses_tigetstr(PyObject *self, PyObject *args)
Py_INCREF(Py_None);
return Py_None;
}
- return PyString_FromString( capname );
+ return PyBytes_FromString( capname );
}
static PyObject *
@@ -2520,7 +2520,7 @@ PyCurses_tparm(PyObject *self, PyObject *args)
return NULL;
}
- return PyString_FromString(result);
+ return PyBytes_FromString(result);
}
static PyObject *
@@ -2547,14 +2547,14 @@ PyCurses_UnCtrl(PyObject *self, PyObject *args)
if (PyInt_Check(temp))
ch = (chtype) PyInt_AsLong(temp);
- else if (PyString_Check(temp))
- ch = (chtype) *PyString_AsString(temp);
+ else if (PyBytes_Check(temp))
+ ch = (chtype) *PyBytes_AsString(temp);
else {
PyErr_SetString(PyExc_TypeError, "argument must be a ch or an int");
return NULL;
}
- return PyString_FromString(unctrl(ch));
+ return PyBytes_FromString(unctrl(ch));
}
static PyObject *
@@ -2569,8 +2569,8 @@ PyCurses_UngetCh(PyObject *self, PyObject *args)
if (PyInt_Check(temp))
ch = (int) PyInt_AsLong(temp);
- else if (PyString_Check(temp))
- ch = (int) *PyString_AsString(temp);
+ else if (PyBytes_Check(temp))
+ ch = (int) *PyBytes_AsString(temp);
else {
PyErr_SetString(PyExc_TypeError, "argument must be a ch or an int");
return NULL;
@@ -2753,7 +2753,7 @@ init_curses(void)
PyDict_SetItemString(d, "error", PyCursesError);
/* Make the version available */
- v = PyString_FromString(PyCursesVersion);
+ v = PyBytes_FromString(PyCursesVersion);
PyDict_SetItemString(d, "version", v);
PyDict_SetItemString(d, "__version__", v);
Py_DECREF(v);
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c
index 684081c7c9..e368b317a0 100644
--- a/Modules/_elementtree.c
+++ b/Modules/_elementtree.c
@@ -103,7 +103,7 @@ typedef int Py_ssize_t;
#define PyDict_CheckExact PyDict_Check
#if (PY_VERSION_HEX < 0x02020000)
#define PyList_CheckExact PyList_Check
-#define PyString_CheckExact PyString_Check
+#define PyBytes_CheckExact PyBytes_Check
#if (PY_VERSION_HEX >= 0x01060000)
#define Py_USING_UNICODE /* always enabled for 2.0 and 2.1 */
#endif
@@ -173,7 +173,7 @@ list_join(PyObject* list)
switch (PyList_GET_SIZE(list)) {
case 0:
Py_DECREF(list);
- return PyString_FromString("");
+ return PyBytes_FromString("");
case 1:
result = PyList_GET_ITEM(list, 0);
Py_INCREF(result);
@@ -748,9 +748,9 @@ checkpath(PyObject* tag)
return 0;
}
#endif
- if (PyString_Check(tag)) {
- char *p = PyString_AS_STRING(tag);
- for (i = 0; i < PyString_GET_SIZE(tag); i++) {
+ if (PyBytes_Check(tag)) {
+ char *p = PyBytes_AS_STRING(tag);
+ for (i = 0; i < PyBytes_GET_SIZE(tag); i++) {
if (p[i] == '{')
check = 0;
else if (p[i] == '}')
@@ -818,7 +818,7 @@ element_findtext(ElementObject* self, PyObject* args)
if (Element_CheckExact(item) && !PyObject_Compare(item->tag, tag)) {
PyObject* text = element_get_text(item);
if (text == Py_None)
- return PyString_FromString("");
+ return PyBytes_FromString("");
Py_XINCREF(text);
return text;
}
@@ -1154,12 +1154,12 @@ element_repr(ElementObject* self)
PyObject* repr;
char buffer[100];
- repr = PyString_FromString("<Element ");
+ repr = PyBytes_FromString("<Element ");
- PyString_ConcatAndDel(&repr, PyObject_Repr(self->tag));
+ PyBytes_ConcatAndDel(&repr, PyObject_Repr(self->tag));
sprintf(buffer, " at %p>", self);
- PyString_ConcatAndDel(&repr, PyString_FromString(buffer));
+ PyBytes_ConcatAndDel(&repr, PyBytes_FromString(buffer));
return repr;
}
@@ -1617,14 +1617,14 @@ treebuilder_handle_data(TreeBuilderObject* self, PyObject* data)
Py_INCREF(data); self->data = data;
} else {
/* more than one item; use a list to collect items */
- if (PyString_CheckExact(self->data) && Py_REFCNT(self->data) == 1 &&
- PyString_CheckExact(data) && PyString_GET_SIZE(data) == 1) {
+ if (PyBytes_CheckExact(self->data) && Py_REFCNT(self->data) == 1 &&
+ PyBytes_CheckExact(data) && PyBytes_GET_SIZE(data) == 1) {
/* expat often generates single character data sections; handle
the most common case by resizing the existing string... */
- Py_ssize_t size = PyString_GET_SIZE(self->data);
- if (_PyString_Resize(&self->data, size + 1) < 0)
+ Py_ssize_t size = PyBytes_GET_SIZE(self->data);
+ if (_PyBytes_Resize(&self->data, size + 1) < 0)
return NULL;
- PyString_AS_STRING(self->data)[size] = PyString_AS_STRING(data)[0];
+ PyBytes_AS_STRING(self->data)[size] = PyBytes_AS_STRING(data)[0];
} else if (PyList_CheckExact(self->data)) {
if (PyList_Append(self->data, data) < 0)
return NULL;
@@ -1896,7 +1896,7 @@ makestring(const char* string, int size)
return PyUnicode_DecodeUTF8(string, size, "strict");
#endif
- return PyString_FromStringAndSize(string, size);
+ return PyBytes_FromStringAndSize(string, size);
}
LOCAL(PyObject*)
@@ -1910,7 +1910,7 @@ makeuniversal(XMLParserObject* self, const char* string)
PyObject* value;
/* look the 'raw' name up in the names dictionary */
- key = PyString_FromStringAndSize(string, size);
+ key = PyBytes_FromStringAndSize(string, size);
if (!key)
return NULL;
@@ -1932,8 +1932,8 @@ makeuniversal(XMLParserObject* self, const char* string)
break;
if (i != size) {
/* convert to universal name */
- tag = PyString_FromStringAndSize(NULL, size+1);
- p = PyString_AS_STRING(tag);
+ tag = PyBytes_FromStringAndSize(NULL, size+1);
+ p = PyBytes_AS_STRING(tag);
p[0] = '{';
memcpy(p+1, string, size);
size++;
@@ -1947,7 +1947,7 @@ makeuniversal(XMLParserObject* self, const char* string)
#if defined(Py_USING_UNICODE)
/* inline makestring, to avoid duplicating the source string if
it's not an utf-8 string */
- p = PyString_AS_STRING(tag);
+ p = PyBytes_AS_STRING(tag);
if (checkstring(p, size)) {
value = PyUnicode_DecodeUTF8(p, size, "strict");
Py_DECREF(tag);
@@ -2004,7 +2004,7 @@ expat_default_handler(XMLParserObject* self, const XML_Char* data_in,
} else {
PyErr_Format(
PyExc_SyntaxError, "undefined entity &%s;: line %ld, column %ld",
- PyString_AS_STRING(key),
+ PyBytes_AS_STRING(key),
EXPAT(GetErrorLineNumber)(self->parser),
EXPAT(GetErrorColumnNumber)(self->parser)
);
@@ -2435,13 +2435,13 @@ xmlparser_parse(XMLParserObject* self, PyObject* args)
return NULL;
}
- if (!PyString_CheckExact(buffer) || PyString_GET_SIZE(buffer) == 0) {
+ if (!PyBytes_CheckExact(buffer) || PyBytes_GET_SIZE(buffer) == 0) {
Py_DECREF(buffer);
break;
}
res = expat_parse(
- self, PyString_AS_STRING(buffer), PyString_GET_SIZE(buffer), 0
+ self, PyBytes_AS_STRING(buffer), PyBytes_GET_SIZE(buffer), 0
);
Py_DECREF(buffer);
@@ -2503,7 +2503,7 @@ xmlparser_setevents(XMLParserObject* self, PyObject* args)
if (event_set == Py_None) {
/* default is "end" only */
- target->end_event_obj = PyString_FromString("end");
+ target->end_event_obj = PyBytes_FromString("end");
Py_RETURN_NONE;
}
@@ -2513,9 +2513,9 @@ xmlparser_setevents(XMLParserObject* self, PyObject* args)
for (i = 0; i < PyTuple_GET_SIZE(event_set); i++) {
PyObject* item = PyTuple_GET_ITEM(event_set, i);
char* event;
- if (!PyString_Check(item))
+ if (!PyBytes_Check(item))
goto error;
- event = PyString_AS_STRING(item);
+ event = PyBytes_AS_STRING(item);
if (strcmp(event, "start") == 0) {
Py_INCREF(item);
target->start_event_obj = item;
@@ -2587,7 +2587,7 @@ xmlparser_getattr(XMLParserObject* self, char* name)
char buffer[100];
sprintf(buffer, "Expat %d.%d.%d", XML_MAJOR_VERSION,
XML_MINOR_VERSION, XML_MICRO_VERSION);
- return PyString_FromString(buffer);
+ return PyBytes_FromString(buffer);
} else {
PyErr_SetString(PyExc_AttributeError, name);
return NULL;
diff --git a/Modules/_fileio.c b/Modules/_fileio.c
index 1cb697bb39..aa5b59fb3f 100644
--- a/Modules/_fileio.c
+++ b/Modules/_fileio.c
@@ -392,14 +392,14 @@ fileio_readall(PyFileIOObject *self)
Py_ssize_t total = 0;
int n;
- result = PyString_FromStringAndSize(NULL, DEFAULT_BUFFER_SIZE);
+ result = PyBytes_FromStringAndSize(NULL, DEFAULT_BUFFER_SIZE);
if (result == NULL)
return NULL;
while (1) {
Py_ssize_t newsize = total + DEFAULT_BUFFER_SIZE;
- if (PyString_GET_SIZE(result) < newsize) {
- if (_PyString_Resize(&result, newsize) < 0) {
+ if (PyBytes_GET_SIZE(result) < newsize) {
+ if (_PyBytes_Resize(&result, newsize) < 0) {
if (total == 0) {
Py_DECREF(result);
return NULL;
@@ -411,7 +411,7 @@ fileio_readall(PyFileIOObject *self)
Py_BEGIN_ALLOW_THREADS
errno = 0;
n = read(self->fd,
- PyString_AS_STRING(result) + total,
+ PyBytes_AS_STRING(result) + total,
newsize - total);
Py_END_ALLOW_THREADS
if (n == 0)
@@ -430,8 +430,8 @@ fileio_readall(PyFileIOObject *self)
total += n;
}
- if (PyString_GET_SIZE(result) > total) {
- if (_PyString_Resize(&result, total) < 0) {
+ if (PyBytes_GET_SIZE(result) > total) {
+ if (_PyBytes_Resize(&result, total) < 0) {
/* This should never happen, but just in case */
Py_DECREF(result);
return NULL;
@@ -460,10 +460,10 @@ fileio_read(PyFileIOObject *self, PyObject *args)
return fileio_readall(self);
}
- bytes = PyString_FromStringAndSize(NULL, size);
+ bytes = PyBytes_FromStringAndSize(NULL, size);
if (bytes == NULL)
return NULL;
- ptr = PyString_AS_STRING(bytes);
+ ptr = PyBytes_AS_STRING(bytes);
Py_BEGIN_ALLOW_THREADS
errno = 0;
@@ -478,7 +478,7 @@ fileio_read(PyFileIOObject *self, PyObject *args)
}
if (n != size) {
- if (_PyString_Resize(&bytes, n) < 0) {
+ if (_PyBytes_Resize(&bytes, n) < 0) {
Py_DECREF(bytes);
return NULL;
}
@@ -690,9 +690,9 @@ static PyObject *
fileio_repr(PyFileIOObject *self)
{
if (self->fd < 0)
- return PyString_FromFormat("_fileio._FileIO(-1)");
+ return PyBytes_FromFormat("_fileio._FileIO(-1)");
- return PyString_FromFormat("_fileio._FileIO(%d, '%s')",
+ return PyBytes_FromFormat("_fileio._FileIO(%d, '%s')",
self->fd, mode_string(self));
}
@@ -816,7 +816,7 @@ get_closed(PyFileIOObject *self, void *closure)
static PyObject *
get_mode(PyFileIOObject *self, void *closure)
{
- return PyString_FromString(mode_string(self));
+ return PyBytes_FromString(mode_string(self));
}
static PyGetSetDef fileio_getsetlist[] = {
diff --git a/Modules/_hashopenssl.c b/Modules/_hashopenssl.c
index 8e5121f12e..7bca2daa22 100644
--- a/Modules/_hashopenssl.c
+++ b/Modules/_hashopenssl.c
@@ -103,7 +103,7 @@ EVP_digest(EVPobject *self, PyObject *unused)
digest_size = EVP_MD_CTX_size(&temp_ctx);
EVP_DigestFinal(&temp_ctx, digest, NULL);
- retval = PyString_FromStringAndSize((const char *)digest, digest_size);
+ retval = PyBytes_FromStringAndSize((const char *)digest, digest_size);
EVP_MD_CTX_cleanup(&temp_ctx);
return retval;
}
@@ -130,10 +130,10 @@ EVP_hexdigest(EVPobject *self, PyObject *unused)
/* Create a new string */
/* NOTE: not thread safe! modifying an already created string object */
/* (not a problem because we hold the GIL by default) */
- retval = PyString_FromStringAndSize(NULL, digest_size * 2);
+ retval = PyBytes_FromStringAndSize(NULL, digest_size * 2);
if (!retval)
return NULL;
- hex_digest = PyString_AsString(retval);
+ hex_digest = PyBytes_AsString(retval);
if (!hex_digest) {
Py_DECREF(retval);
return NULL;
@@ -220,8 +220,8 @@ EVP_repr(PyObject *self)
{
char buf[100];
PyOS_snprintf(buf, sizeof(buf), "<%s HASH object @ %p>",
- PyString_AsString(((EVPobject *)self)->name), self);
- return PyString_FromString(buf);
+ PyBytes_AsString(((EVPobject *)self)->name), self);
+ return PyBytes_FromString(buf);
}
#if HASH_OBJ_CONSTRUCTOR
@@ -421,7 +421,7 @@ EVP_new(PyObject *self, PyObject *args, PyObject *kwdict)
/* used in the init function to setup a constructor */
#define INIT_CONSTRUCTOR_CONSTANTS(NAME) do { \
- CONST_ ## NAME ## _name_obj = PyString_FromString(#NAME); \
+ CONST_ ## NAME ## _name_obj = PyBytes_FromString(#NAME); \
if (EVP_get_digestbyname(#NAME)) { \
CONST_new_ ## NAME ## _ctx_p = &CONST_new_ ## NAME ## _ctx; \
EVP_DigestInit(CONST_new_ ## NAME ## _ctx_p, EVP_get_digestbyname(#NAME)); \
diff --git a/Modules/_heapqmodule.c b/Modules/_heapqmodule.c
index 06ed74320a..1482b5a62a 100644
--- a/Modules/_heapqmodule.c
+++ b/Modules/_heapqmodule.c
@@ -658,6 +658,6 @@ init_heapq(void)
m = Py_InitModule3("_heapq", heapq_methods, module_doc);
if (m == NULL)
return;
- PyModule_AddObject(m, "__about__", PyString_FromString(__about__));
+ PyModule_AddObject(m, "__about__", PyBytes_FromString(__about__));
}
diff --git a/Modules/_hotshot.c b/Modules/_hotshot.c
index 4c66e2a6a3..7c8bdd9630 100644
--- a/Modules/_hotshot.c
+++ b/Modules/_hotshot.c
@@ -326,7 +326,7 @@ unpack_string(LogReaderObject *self, PyObject **pvalue)
return ERR_EOF;
}
}
- *pvalue = PyString_FromStringAndSize(buf, len);
+ *pvalue = PyBytes_FromStringAndSize(buf, len);
free(buf);
if (*pvalue == NULL) {
return ERR_EXCEPTION;
@@ -562,7 +562,7 @@ flush_data(ProfilerObject *self)
self->index - written);
self->index -= written;
if (written == 0) {
- char *s = PyString_AsString(self->logfilename);
+ char *s = PyBytes_AsString(self->logfilename);
PyErr_SetFromErrnoWithFilename(PyExc_IOError, s);
do_stop(self);
return -1;
@@ -570,7 +570,7 @@ flush_data(ProfilerObject *self)
}
if (written > 0) {
if (fflush(self->logfp)) {
- char *s = PyString_AsString(self->logfilename);
+ char *s = PyBytes_AsString(self->logfilename);
PyErr_SetFromErrnoWithFilename(PyExc_IOError, s);
do_stop(self);
return -1;
@@ -792,7 +792,7 @@ get_fileno(ProfilerObject *self, PyCodeObject *fcode)
self->next_fileno++;
Py_DECREF(obj);
if (pack_define_file(self, fileno,
- PyString_AS_STRING(fcode->co_filename)) < 0)
+ PyBytes_AS_STRING(fcode->co_filename)) < 0)
return -1;
}
else {
@@ -810,7 +810,7 @@ get_fileno(ProfilerObject *self, PyCodeObject *fcode)
PyObject *name = PyDict_GetItem(dict, obj);
if (name == NULL) {
if (pack_define_func(self, fileno, fcode->co_firstlineno,
- PyString_AS_STRING(fcode->co_name)) < 0) {
+ PyBytes_AS_STRING(fcode->co_name)) < 0) {
Py_DECREF(obj);
return -1;
}
@@ -1471,7 +1471,7 @@ write_header(ProfilerObject *self)
len = PyList_GET_SIZE(temp);
for (i = 0; i < len; ++i) {
PyObject *item = PyList_GET_ITEM(temp, i);
- buffer = PyString_AsString(item);
+ buffer = PyBytes_AsString(item);
if (buffer == NULL) {
pack_add_info(self, "sys-path-entry", "<non-string-path-entry>");
PyErr_Clear();
diff --git a/Modules/_json.c b/Modules/_json.c
index ea6d66f60c..30cdc0f207 100644
--- a/Modules/_json.c
+++ b/Modules/_json.c
@@ -70,11 +70,11 @@ ascii_escape_unicode(PyObject *pystr)
input_unicode = PyUnicode_AS_UNICODE(pystr);
/* One char input can be up to 6 chars output, estimate 4 of these */
output_size = 2 + (MIN_EXPANSION * 4) + input_chars;
- rval = PyString_FromStringAndSize(NULL, output_size);
+ rval = PyBytes_FromStringAndSize(NULL, output_size);
if (rval == NULL) {
return NULL;
}
- output = PyString_AS_STRING(rval);
+ output = PyBytes_AS_STRING(rval);
chars = 0;
output[chars++] = '"';
for (i = 0; i < input_chars; i++) {
@@ -92,14 +92,14 @@ ascii_escape_unicode(PyObject *pystr)
if (output_size > 2 + (input_chars * MAX_EXPANSION)) {
output_size = 2 + (input_chars * MAX_EXPANSION);
}
- if (_PyString_Resize(&rval, output_size) == -1) {
+ if (_PyBytes_Resize(&rval, output_size) == -1) {
return NULL;
}
- output = PyString_AS_STRING(rval);
+ output = PyBytes_AS_STRING(rval);
}
}
output[chars++] = '"';
- if (_PyString_Resize(&rval, chars) == -1) {
+ if (_PyBytes_Resize(&rval, chars) == -1) {
return NULL;
}
return rval;
@@ -116,15 +116,15 @@ ascii_escape_str(PyObject *pystr)
char *output;
char *input_str;
- input_chars = PyString_GET_SIZE(pystr);
- input_str = PyString_AS_STRING(pystr);
+ input_chars = PyBytes_GET_SIZE(pystr);
+ input_str = PyBytes_AS_STRING(pystr);
/* One char input can be up to 6 chars output, estimate 4 of these */
output_size = 2 + (MIN_EXPANSION * 4) + input_chars;
- rval = PyString_FromStringAndSize(NULL, output_size);
+ rval = PyBytes_FromStringAndSize(NULL, output_size);
if (rval == NULL) {
return NULL;
}
- output = PyString_AS_STRING(rval);
+ output = PyBytes_AS_STRING(rval);
chars = 0;
output[chars++] = '"';
for (i = 0; i < input_chars; i++) {
@@ -154,14 +154,14 @@ ascii_escape_str(PyObject *pystr)
if (output_size > 2 + (input_chars * MIN_EXPANSION)) {
output_size = 2 + (input_chars * MIN_EXPANSION);
}
- if (_PyString_Resize(&rval, output_size) == -1) {
+ if (_PyBytes_Resize(&rval, output_size) == -1) {
return NULL;
}
- output = PyString_AS_STRING(rval);
+ output = PyBytes_AS_STRING(rval);
}
}
output[chars++] = '"';
- if (_PyString_Resize(&rval, chars) == -1) {
+ if (_PyBytes_Resize(&rval, chars) == -1) {
return NULL;
}
return rval;
@@ -215,7 +215,7 @@ join_list_unicode(PyObject *lst)
ustr = PyUnicode_FromUnicode(&c, 0);
}
if (joinstr == NULL) {
- joinstr = PyString_InternFromString("join");
+ joinstr = PyBytes_InternFromString("join");
}
if (joinstr == NULL || ustr == NULL) {
return NULL;
@@ -227,10 +227,10 @@ static PyObject *
scanstring_str(PyObject *pystr, Py_ssize_t end, char *encoding, int strict)
{
PyObject *rval;
- Py_ssize_t len = PyString_GET_SIZE(pystr);
+ Py_ssize_t len = PyBytes_GET_SIZE(pystr);
Py_ssize_t begin = end - 1;
Py_ssize_t next = begin;
- char *buf = PyString_AS_STRING(pystr);
+ char *buf = PyBytes_AS_STRING(pystr);
PyObject *chunks = PyList_New(0);
if (chunks == NULL) {
goto bail;
@@ -555,7 +555,7 @@ py_scanstring(PyObject* self, PyObject *args)
if (encoding == NULL) {
encoding = DEFAULT_ENCODING;
}
- if (PyString_Check(pystr)) {
+ if (PyBytes_Check(pystr)) {
return scanstring_str(pystr, end, encoding, strict);
}
else if (PyUnicode_Check(pystr)) {
@@ -576,7 +576,7 @@ static PyObject *
py_encode_basestring_ascii(PyObject* self, PyObject *pystr)
{
/* METH_O */
- if (PyString_Check(pystr)) {
+ if (PyBytes_Check(pystr)) {
return ascii_escape_str(pystr);
}
else if (PyUnicode_Check(pystr)) {
diff --git a/Modules/_localemodule.c b/Modules/_localemodule.c
index 02e9e53b27..ce84b2756b 100644
--- a/Modules/_localemodule.c
+++ b/Modules/_localemodule.c
@@ -119,7 +119,7 @@ fixup_ulcase(void)
if (isupper(c))
ul[n++] = c;
}
- ulo = PyString_FromStringAndSize((const char *)ul, n);
+ ulo = PyBytes_FromStringAndSize((const char *)ul, n);
if (!ulo)
return;
if (string)
@@ -134,7 +134,7 @@ fixup_ulcase(void)
if (islower(c))
ul[n++] = c;
}
- ulo = PyString_FromStringAndSize((const char *)ul, n);
+ ulo = PyBytes_FromStringAndSize((const char *)ul, n);
if (!ulo)
return;
if (string)
@@ -149,7 +149,7 @@ fixup_ulcase(void)
if (isalpha(c))
ul[n++] = c;
}
- ulo = PyString_FromStringAndSize((const char *)ul, n);
+ ulo = PyBytes_FromStringAndSize((const char *)ul, n);
if (!ulo)
return;
if (string)
@@ -175,7 +175,7 @@ PyLocale_setlocale(PyObject* self, PyObject* args)
PyErr_SetString(Error, "unsupported locale setting");
return NULL;
}
- result_object = PyString_FromString(result);
+ result_object = PyBytes_FromString(result);
if (!result_object)
return NULL;
/* record changes to LC_CTYPE */
@@ -190,7 +190,7 @@ PyLocale_setlocale(PyObject* self, PyObject* args)
PyErr_SetString(Error, "locale query failed");
return NULL;
}
- result_object = PyString_FromString(result);
+ result_object = PyBytes_FromString(result);
}
return result_object;
}
@@ -216,7 +216,7 @@ PyLocale_localeconv(PyObject* self)
involved herein */
#define RESULT_STRING(s)\
- x = PyString_FromString(l->s);\
+ x = PyBytes_FromString(l->s);\
if (!x) goto failed;\
PyDict_SetItemString(result, #s, x);\
Py_XDECREF(x)
@@ -284,9 +284,9 @@ PyLocale_strcoll(PyObject* self, PyObject* args)
if (!PyArg_UnpackTuple(args, "strcoll", 2, 2, &os1, &os2))
return NULL;
/* If both arguments are byte strings, use strcoll. */
- if (PyString_Check(os1) && PyString_Check(os2))
- return PyInt_FromLong(strcoll(PyString_AS_STRING(os1),
- PyString_AS_STRING(os2)));
+ if (PyBytes_Check(os1) && PyBytes_Check(os2))
+ return PyInt_FromLong(strcoll(PyBytes_AS_STRING(os1),
+ PyBytes_AS_STRING(os2)));
/* If neither argument is unicode, it's an error. */
if (!PyUnicode_Check(os1) && !PyUnicode_Check(os2)) {
PyErr_SetString(PyExc_ValueError, "strcoll arguments must be strings");
@@ -368,7 +368,7 @@ PyLocale_strxfrm(PyObject* self, PyObject* args)
return PyErr_NoMemory();
strxfrm(buf, s, n2);
}
- result = PyString_FromString(buf);
+ result = PyBytes_FromString(buf);
PyMem_Free(buf);
return result;
}
@@ -563,13 +563,13 @@ PyLocale_nl_langinfo(PyObject* self, PyObject* args)
return NULL;
/* Check whether this is a supported constant. GNU libc sometimes
returns numeric values in the char* return value, which would
- crash PyString_FromString. */
+ crash PyBytes_FromString. */
for (i = 0; langinfo_constants[i].name; i++)
if (langinfo_constants[i].value == item) {
/* Check NULL as a workaround for GNU libc's returning NULL
instead of an empty string for nl_langinfo(ERA). */
const char *result = nl_langinfo(item);
- return PyString_FromString(result != NULL ? result : "");
+ return PyBytes_FromString(result != NULL ? result : "");
}
PyErr_SetString(PyExc_ValueError, "unsupported langinfo constant");
return NULL;
@@ -588,7 +588,7 @@ PyIntl_gettext(PyObject* self, PyObject *args)
char *in;
if (!PyArg_ParseTuple(args, "z", &in))
return 0;
- return PyString_FromString(gettext(in));
+ return PyBytes_FromString(gettext(in));
}
PyDoc_STRVAR(dgettext__doc__,
@@ -601,7 +601,7 @@ PyIntl_dgettext(PyObject* self, PyObject *args)
char *domain, *in;
if (!PyArg_ParseTuple(args, "zz", &domain, &in))
return 0;
- return PyString_FromString(dgettext(domain, in));
+ return PyBytes_FromString(dgettext(domain, in));
}
PyDoc_STRVAR(dcgettext__doc__,
@@ -615,7 +615,7 @@ PyIntl_dcgettext(PyObject *self, PyObject *args)
int category;
if (!PyArg_ParseTuple(args, "zzi", &domain, &msgid, &category))
return 0;
- return PyString_FromString(dcgettext(domain,msgid,category));
+ return PyBytes_FromString(dcgettext(domain,msgid,category));
}
PyDoc_STRVAR(textdomain__doc__,
@@ -633,7 +633,7 @@ PyIntl_textdomain(PyObject* self, PyObject* args)
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
}
- return PyString_FromString(domain);
+ return PyBytes_FromString(domain);
}
PyDoc_STRVAR(bindtextdomain__doc__,
@@ -651,7 +651,7 @@ PyIntl_bindtextdomain(PyObject* self,PyObject*args)
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
}
- return PyString_FromString(dirname);
+ return PyBytes_FromString(dirname);
}
#ifdef HAVE_BIND_TEXTDOMAIN_CODESET
@@ -667,7 +667,7 @@ PyIntl_bind_textdomain_codeset(PyObject* self,PyObject*args)
return NULL;
codeset = bind_textdomain_codeset(domain, codeset);
if (codeset)
- return PyString_FromString(codeset);
+ return PyBytes_FromString(codeset);
Py_RETURN_NONE;
}
#endif
@@ -760,7 +760,7 @@ init_locale(void)
Error = PyErr_NewException("locale.Error", NULL, NULL);
PyDict_SetItemString(d, "Error", Error);
- x = PyString_FromString(locale__doc__);
+ x = PyBytes_FromString(locale__doc__);
PyDict_SetItemString(d, "__doc__", x);
Py_XDECREF(x);
diff --git a/Modules/_lsprof.c b/Modules/_lsprof.c
index 5d18c3370d..2b80a00382 100644
--- a/Modules/_lsprof.c
+++ b/Modules/_lsprof.c
@@ -179,8 +179,8 @@ normalizeUserObj(PyObject *obj)
/* built-in function: look up the module name */
PyObject *mod = fn->m_module;
char *modname;
- if (mod && PyString_Check(mod)) {
- modname = PyString_AS_STRING(mod);
+ if (mod && PyBytes_Check(mod)) {
+ modname = PyBytes_AS_STRING(mod);
}
else if (mod && PyModule_Check(mod)) {
modname = PyModule_GetName(mod);
@@ -193,11 +193,11 @@ normalizeUserObj(PyObject *obj)
modname = "__builtin__";
}
if (strcmp(modname, "__builtin__") != 0)
- return PyString_FromFormat("<%s.%s>",
+ return PyBytes_FromFormat("<%s.%s>",
modname,
fn->m_ml->ml_name);
else
- return PyString_FromFormat("<%s>",
+ return PyBytes_FromFormat("<%s>",
fn->m_ml->ml_name);
}
else {
@@ -205,7 +205,7 @@ normalizeUserObj(PyObject *obj)
repr(getattr(type(__self__), __name__))
*/
PyObject *self = fn->m_self;
- PyObject *name = PyString_FromString(fn->m_ml->ml_name);
+ PyObject *name = PyBytes_FromString(fn->m_ml->ml_name);
if (name != NULL) {
PyObject *mo = _PyType_Lookup(Py_TYPE(self), name);
Py_XINCREF(mo);
@@ -218,7 +218,7 @@ normalizeUserObj(PyObject *obj)
}
}
PyErr_Clear();
- return PyString_FromFormat("<built-in method %s>",
+ return PyBytes_FromFormat("<built-in method %s>",
fn->m_ml->ml_name);
}
}
diff --git a/Modules/_sqlite/cache.c b/Modules/_sqlite/cache.c
index 85118fc78e..3362a5cd9a 100644
--- a/Modules/_sqlite/cache.c
+++ b/Modules/_sqlite/cache.c
@@ -241,12 +241,12 @@ PyObject* pysqlite_cache_display(pysqlite_Cache* self, PyObject* args)
if (!fmt_args) {
return NULL;
}
- template = PyString_FromString("%s <- %s ->%s\n");
+ template = PyBytes_FromString("%s <- %s ->%s\n");
if (!template) {
Py_DECREF(fmt_args);
return NULL;
}
- display_str = PyString_Format(template, fmt_args);
+ display_str = PyBytes_Format(template, fmt_args);
Py_DECREF(template);
Py_DECREF(fmt_args);
if (!display_str) {
diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c
index 8269e0b1fb..927c983f7d 100644
--- a/Modules/_sqlite/connection.c
+++ b/Modules/_sqlite/connection.c
@@ -84,8 +84,8 @@ int pysqlite_connection_init(pysqlite_Connection* self, PyObject* args, PyObject
Py_INCREF(&PyUnicode_Type);
self->text_factory = (PyObject*)&PyUnicode_Type;
- if (PyString_Check(database) || PyUnicode_Check(database)) {
- if (PyString_Check(database)) {
+ if (PyBytes_Check(database) || PyUnicode_Check(database)) {
+ if (PyBytes_Check(database)) {
database_utf8 = database;
Py_INCREF(database_utf8);
} else {
@@ -96,7 +96,7 @@ int pysqlite_connection_init(pysqlite_Connection* self, PyObject* args, PyObject
}
Py_BEGIN_ALLOW_THREADS
- rc = sqlite3_open(PyString_AsString(database_utf8), &self->db);
+ rc = sqlite3_open(PyBytes_AsString(database_utf8), &self->db);
Py_END_ALLOW_THREADS
Py_DECREF(database_utf8);
@@ -111,7 +111,7 @@ int pysqlite_connection_init(pysqlite_Connection* self, PyObject* args, PyObject
if (class_attr) {
class_attr_str = PyObject_Str(class_attr);
if (class_attr_str) {
- if (strcmp(PyString_AsString(class_attr_str), "<type 'apsw.Connection'>") == 0) {
+ if (strcmp(PyBytes_AsString(class_attr_str), "<type 'apsw.Connection'>") == 0) {
/* In the APSW Connection object, the first entry after
* PyObject_HEAD is the sqlite3* we want to get hold of.
* Luckily, this is the same layout as we have in our
@@ -134,7 +134,7 @@ int pysqlite_connection_init(pysqlite_Connection* self, PyObject* args, PyObject
}
if (!isolation_level) {
- isolation_level = PyString_FromString("");
+ isolation_level = PyBytes_FromString("");
if (!isolation_level) {
return -1;
}
@@ -499,12 +499,12 @@ void _pysqlite_set_result(sqlite3_context* context, PyObject* py_val)
} else {
sqlite3_result_blob(context, buffer, buflen, SQLITE_TRANSIENT);
}
- } else if (PyString_Check(py_val)) {
- sqlite3_result_text(context, PyString_AsString(py_val), -1, SQLITE_TRANSIENT);
+ } else if (PyBytes_Check(py_val)) {
+ sqlite3_result_text(context, PyBytes_AsString(py_val), -1, SQLITE_TRANSIENT);
} else if (PyUnicode_Check(py_val)) {
stringval = PyUnicode_AsUTF8String(py_val);
if (stringval) {
- sqlite3_result_text(context, PyString_AsString(stringval), -1, SQLITE_TRANSIENT);
+ sqlite3_result_text(context, PyBytes_AsString(stringval), -1, SQLITE_TRANSIENT);
Py_DECREF(stringval);
}
} else {
@@ -963,21 +963,21 @@ static int pysqlite_connection_set_isolation_level(pysqlite_Connection* self, Py
Py_INCREF(isolation_level);
self->isolation_level = isolation_level;
- begin_statement = PyString_FromString("BEGIN ");
+ begin_statement = PyBytes_FromString("BEGIN ");
if (!begin_statement) {
return -1;
}
- PyString_Concat(&begin_statement, isolation_level);
+ PyBytes_Concat(&begin_statement, isolation_level);
if (!begin_statement) {
return -1;
}
- self->begin_statement = PyMem_Malloc(PyString_Size(begin_statement) + 2);
+ self->begin_statement = PyMem_Malloc(PyBytes_Size(begin_statement) + 2);
if (!self->begin_statement) {
return -1;
}
- strcpy(self->begin_statement, PyString_AsString(begin_statement));
+ strcpy(self->begin_statement, PyBytes_AsString(begin_statement));
Py_DECREF(begin_statement);
}
@@ -1152,8 +1152,8 @@ pysqlite_collation_callback(
goto finally;
}
- string1 = PyString_FromStringAndSize((const char*)text1_data, text1_length);
- string2 = PyString_FromStringAndSize((const char*)text2_data, text2_length);
+ string1 = PyBytes_FromStringAndSize((const char*)text1_data, text1_length);
+ string2 = PyBytes_FromStringAndSize((const char*)text2_data, text2_length);
if (!string1 || !string2) {
goto finally; /* failed to allocate strings */
@@ -1259,7 +1259,7 @@ pysqlite_connection_create_collation(pysqlite_Connection* self, PyObject* args)
goto finally;
}
- if (!PyArg_ParseTuple(args, "O!O:create_collation(name, callback)", &PyString_Type, &name, &callable)) {
+ if (!PyArg_ParseTuple(args, "O!O:create_collation(name, callback)", &PyBytes_Type, &name, &callable)) {
goto finally;
}
@@ -1268,7 +1268,7 @@ pysqlite_connection_create_collation(pysqlite_Connection* self, PyObject* args)
goto finally;
}
- chk = PyString_AsString(uppercase_name);
+ chk = PyBytes_AsString(uppercase_name);
while (*chk) {
if ((*chk >= '0' && *chk <= '9')
|| (*chk >= 'A' && *chk <= 'Z')
@@ -1293,7 +1293,7 @@ pysqlite_connection_create_collation(pysqlite_Connection* self, PyObject* args)
}
rc = sqlite3_create_collation(self->db,
- PyString_AsString(uppercase_name),
+ PyBytes_AsString(uppercase_name),
SQLITE_UTF8,
(callable != Py_None) ? callable : NULL,
(callable != Py_None) ? pysqlite_collation_callback : NULL);
diff --git a/Modules/_sqlite/connection.h b/Modules/_sqlite/connection.h
index 3b1c632db8..c5d0fd061b 100644
--- a/Modules/_sqlite/connection.h
+++ b/Modules/_sqlite/connection.h
@@ -80,7 +80,7 @@ typedef struct
/* Determines how bytestrings from SQLite are converted to Python objects:
* - PyUnicode_Type: Python Unicode objects are constructed from UTF-8 bytestrings
* - OptimizedUnicode: Like before, but for ASCII data, only PyStrings are created.
- * - PyString_Type: PyStrings are created as-is.
+ * - PyBytes_Type: PyStrings are created as-is.
* - Any custom callable: Any object returned from the callable called with the bytestring
* as single parameter.
*/
diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c
index 308823c50d..2321fa8334 100644
--- a/Modules/_sqlite/cursor.c
+++ b/Modules/_sqlite/cursor.c
@@ -182,7 +182,7 @@ int pysqlite_build_row_cast_map(pysqlite_Cursor* self)
if (*pos == '[') {
type_start = pos + 1;
} else if (*pos == ']' && type_start != (const char*)-1) {
- key = PyString_FromStringAndSize(type_start, pos - type_start);
+ key = PyBytes_FromStringAndSize(type_start, pos - type_start);
if (!key) {
/* creating a string failed, but it is too complicated
* to propagate the error here, we just assume there is
@@ -207,7 +207,7 @@ int pysqlite_build_row_cast_map(pysqlite_Cursor* self)
* 'NUMBER(10)' to be treated as 'NUMBER', for example.
* In other words, it will work as people expect it to work.*/
if (*pos == ' ' || *pos == '(' || *pos == 0) {
- py_decltype = PyString_FromStringAndSize(decltype, pos - decltype);
+ py_decltype = PyBytes_FromStringAndSize(decltype, pos - decltype);
if (!py_decltype) {
return -1;
}
@@ -252,7 +252,7 @@ PyObject* _pysqlite_build_column_name(const char* colname)
if ((*pos == '[') && (pos > colname) && (*(pos-1) == ' ')) {
pos--;
}
- return PyString_FromStringAndSize(colname, pos - colname);
+ return PyBytes_FromStringAndSize(colname, pos - colname);
}
}
}
@@ -277,7 +277,7 @@ PyObject* pysqlite_unicode_from_string(const char* val_str, int optimize)
}
if (is_ascii) {
- return PyString_FromString(val_str);
+ return PyBytes_FromString(val_str);
} else {
return PyUnicode_DecodeUTF8(val_str, strlen(val_str), NULL);
}
@@ -331,7 +331,7 @@ PyObject* _pysqlite_fetch_one_row(pysqlite_Cursor* self)
Py_INCREF(Py_None);
converted = Py_None;
} else {
- item = PyString_FromStringAndSize(val_str, nbytes);
+ item = PyBytes_FromStringAndSize(val_str, nbytes);
if (!item) {
return NULL;
}
@@ -374,8 +374,8 @@ PyObject* _pysqlite_fetch_one_row(pysqlite_Cursor* self)
colname , val_str);
PyErr_SetString(pysqlite_OperationalError, buf);
}
- } 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_FromString(val_str);
} else {
converted = PyObject_CallFunction(self->connection->text_factory, "s", val_str);
}
@@ -446,7 +446,7 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
return NULL;
}
- if (!PyString_Check(operation) && !PyUnicode_Check(operation)) {
+ if (!PyBytes_Check(operation) && !PyUnicode_Check(operation)) {
PyErr_SetString(PyExc_ValueError, "operation parameter must be str or unicode");
return NULL;
}
@@ -468,7 +468,7 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
return NULL;
}
- if (!PyString_Check(operation) && !PyUnicode_Check(operation)) {
+ if (!PyBytes_Check(operation) && !PyUnicode_Check(operation)) {
PyErr_SetString(PyExc_ValueError, "operation parameter must be str or unicode");
return NULL;
}
@@ -503,15 +503,15 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
rc = pysqlite_statement_reset(self->statement);
}
- if (PyString_Check(operation)) {
- operation_cstr = PyString_AsString(operation);
+ if (PyBytes_Check(operation)) {
+ operation_cstr = PyBytes_AsString(operation);
} else {
operation_bytestr = PyUnicode_AsUTF8String(operation);
if (!operation_bytestr) {
goto error;
}
- operation_cstr = PyString_AsString(operation_bytestr);
+ operation_cstr = PyBytes_AsString(operation_bytestr);
}
/* reset description */
@@ -768,15 +768,15 @@ PyObject* pysqlite_cursor_executescript(pysqlite_Cursor* self, PyObject* args)
return NULL;
}
- if (PyString_Check(script_obj)) {
- script_cstr = PyString_AsString(script_obj);
+ if (PyBytes_Check(script_obj)) {
+ script_cstr = PyBytes_AsString(script_obj);
} else if (PyUnicode_Check(script_obj)) {
script_str = PyUnicode_AsUTF8String(script_obj);
if (!script_str) {
return NULL;
}
- script_cstr = PyString_AsString(script_str);
+ script_cstr = PyBytes_AsString(script_str);
} else {
PyErr_SetString(PyExc_ValueError, "script argument must be unicode or string.");
return NULL;
diff --git a/Modules/_sqlite/module.c b/Modules/_sqlite/module.c
index af7eace685..f77452c701 100644
--- a/Modules/_sqlite/module.c
+++ b/Modules/_sqlite/module.c
@@ -137,7 +137,7 @@ static PyObject* module_register_adapter(PyObject* self, PyObject* args, PyObjec
/* a basic type is adapted; there's a performance optimization if that's not the case
* (99 % of all usages) */
if (type == &PyInt_Type || type == &PyLong_Type || type == &PyFloat_Type
- || type == &PyString_Type || type == &PyUnicode_Type || type == &PyBuffer_Type) {
+ || type == &PyBytes_Type || type == &PyUnicode_Type || type == &PyBuffer_Type) {
pysqlite_BaseTypeAdapted = 1;
}
@@ -367,13 +367,13 @@ PyMODINIT_FUNC init_sqlite3(void)
Py_DECREF(tmp_obj);
}
- if (!(tmp_obj = PyString_FromString(PYSQLITE_VERSION))) {
+ if (!(tmp_obj = PyBytes_FromString(PYSQLITE_VERSION))) {
goto error;
}
PyDict_SetItemString(dict, "version", tmp_obj);
Py_DECREF(tmp_obj);
- if (!(tmp_obj = PyString_FromString(sqlite3_libversion()))) {
+ if (!(tmp_obj = PyBytes_FromString(sqlite3_libversion()))) {
goto error;
}
PyDict_SetItemString(dict, "sqlite_version", tmp_obj);
diff --git a/Modules/_sqlite/row.c b/Modules/_sqlite/row.c
index 34192673a6..8815116eac 100644
--- a/Modules/_sqlite/row.c
+++ b/Modules/_sqlite/row.c
@@ -86,13 +86,13 @@ PyObject* pysqlite_row_subscript(pysqlite_Row* self, PyObject* idx)
item = PyTuple_GetItem(self->data, _idx);
Py_XINCREF(item);
return item;
- } else if (PyString_Check(idx)) {
- key = PyString_AsString(idx);
+ } else if (PyBytes_Check(idx)) {
+ key = PyBytes_AsString(idx);
nitems = PyTuple_Size(self->description);
for (i = 0; i < nitems; i++) {
- compare_key = PyString_AsString(PyTuple_GET_ITEM(PyTuple_GET_ITEM(self->description, i), 0));
+ compare_key = PyBytes_AsString(PyTuple_GET_ITEM(PyTuple_GET_ITEM(self->description, i), 0));
if (!compare_key) {
return NULL;
}
diff --git a/Modules/_sqlite/statement.c b/Modules/_sqlite/statement.c
index 0e7766804d..b9245f7323 100644
--- a/Modules/_sqlite/statement.c
+++ b/Modules/_sqlite/statement.c
@@ -60,7 +60,7 @@ int pysqlite_statement_create(pysqlite_Statement* self, pysqlite_Connection* con
self->st = NULL;
self->in_use = 0;
- if (PyString_Check(sql)) {
+ if (PyBytes_Check(sql)) {
sql_str = sql;
Py_INCREF(sql_str);
} else if (PyUnicode_Check(sql)) {
@@ -77,7 +77,7 @@ int pysqlite_statement_create(pysqlite_Statement* self, pysqlite_Connection* con
self->in_weakreflist = NULL;
self->sql = sql_str;
- sql_cstr = PyString_AsString(sql_str);
+ sql_cstr = PyBytes_AsString(sql_str);
rc = sqlite3_prepare(connection->db,
sql_cstr,
@@ -119,7 +119,7 @@ int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObjec
paramtype = TYPE_LONG;
} else if (PyFloat_CheckExact(parameter)) {
paramtype = TYPE_FLOAT;
- } else if (PyString_CheckExact(parameter)) {
+ } else if (PyBytes_CheckExact(parameter)) {
paramtype = TYPE_STRING;
} else if (PyUnicode_CheckExact(parameter)) {
paramtype = TYPE_UNICODE;
@@ -131,7 +131,7 @@ int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObjec
paramtype = TYPE_LONG;
} else if (PyFloat_Check(parameter)) {
paramtype = TYPE_FLOAT;
- } else if (PyString_Check(parameter)) {
+ } else if (PyBytes_Check(parameter)) {
paramtype = TYPE_STRING;
} else if (PyUnicode_Check(parameter)) {
paramtype = TYPE_UNICODE;
@@ -140,7 +140,7 @@ int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObjec
}
if (paramtype == TYPE_STRING && !allow_8bit_chars) {
- string = PyString_AS_STRING(parameter);
+ string = PyBytes_AS_STRING(parameter);
for (c = string; *c != 0; c++) {
if (*c & 0x80) {
PyErr_SetString(pysqlite_ProgrammingError, "You must not use 8-bit bytestrings unless you use a text_factory that can interpret 8-bit bytestrings (like text_factory = str). It is highly recommended that you instead just switch your application to Unicode strings.");
@@ -164,12 +164,12 @@ int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObjec
rc = sqlite3_bind_double(self->st, pos, PyFloat_AsDouble(parameter));
break;
case TYPE_STRING:
- string = PyString_AS_STRING(parameter);
+ string = PyBytes_AS_STRING(parameter);
rc = sqlite3_bind_text(self->st, pos, string, -1, SQLITE_TRANSIENT);
break;
case TYPE_UNICODE:
stringval = PyUnicode_AsUTF8String(parameter);
- string = PyString_AsString(stringval);
+ string = PyBytes_AsString(stringval);
rc = sqlite3_bind_text(self->st, pos, string, -1, SQLITE_TRANSIENT);
Py_DECREF(stringval);
break;
@@ -197,7 +197,7 @@ static int _need_adapt(PyObject* obj)
}
if (PyInt_CheckExact(obj) || PyLong_CheckExact(obj)
- || PyFloat_CheckExact(obj) || PyString_CheckExact(obj)
+ || PyFloat_CheckExact(obj) || PyBytes_CheckExact(obj)
|| PyUnicode_CheckExact(obj) || PyBuffer_Check(obj)) {
return 0;
} else {
@@ -326,7 +326,7 @@ int pysqlite_statement_recompile(pysqlite_Statement* self, PyObject* params)
char* sql_cstr;
sqlite3_stmt* new_st;
- sql_cstr = PyString_AsString(self->sql);
+ sql_cstr = PyBytes_AsString(self->sql);
rc = sqlite3_prepare(self->db,
sql_cstr,
diff --git a/Modules/_sre.c b/Modules/_sre.c
index 808fb57528..342f9a04be 100644
--- a/Modules/_sre.c
+++ b/Modules/_sre.c
@@ -1715,7 +1715,7 @@ getstring(PyObject* string, Py_ssize_t* p_length, int* p_charsize)
size = PyObject_Length(string);
#endif
- if (PyString_Check(string) || bytes == size)
+ if (PyBytes_Check(string) || bytes == size)
charsize = 1;
#if defined(HAVE_UNICODE)
else if (bytes == (Py_ssize_t) (size * sizeof(Py_UNICODE)))
@@ -1949,7 +1949,7 @@ call(char* module, char* function, PyObject* args)
if (!args)
return NULL;
- name = PyString_FromString(module);
+ name = PyBytes_FromString(module);
if (!name)
return NULL;
mod = PyImport_Import(name);
@@ -3416,7 +3416,7 @@ PyMODINIT_FUNC init_sre(void)
Py_DECREF(x);
}
- x = PyString_FromString(copyright);
+ x = PyBytes_FromString(copyright);
if (x) {
PyDict_SetItemString(d, "copyright", x);
Py_DECREF(x);
diff --git a/Modules/_ssl.c b/Modules/_ssl.c
index 3f167b32ca..91f16e6e11 100644
--- a/Modules/_ssl.c
+++ b/Modules/_ssl.c
@@ -491,13 +491,13 @@ PyDoc_STRVAR(ssl_doc,
static PyObject *
PySSL_server(PySSLObject *self)
{
- return PyString_FromString(self->server);
+ return PyBytes_FromString(self->server);
}
static PyObject *
PySSL_issuer(PySSLObject *self)
{
- return PyString_FromString(self->issuer);
+ return PyBytes_FromString(self->issuer);
}
static PyObject *
@@ -515,7 +515,7 @@ _create_tuple_for_attribute (ASN1_OBJECT *name, ASN1_STRING *value) {
_setSSLError(NULL, 0, __FILE__, __LINE__);
goto fail;
}
- name_obj = PyString_FromStringAndSize(namebuf, buflen);
+ name_obj = PyBytes_FromStringAndSize(namebuf, buflen);
if (name_obj == NULL)
goto fail;
@@ -603,8 +603,8 @@ _create_tuple_for_X509_NAME (X509_NAME *xname)
/*
fprintf(stderr, "RDN level %d, attribute %s: %s\n",
entry->set,
- PyString_AS_STRING(PyTuple_GET_ITEM(attr, 0)),
- PyString_AS_STRING(PyTuple_GET_ITEM(attr, 1)));
+ PyBytes_AS_STRING(PyTuple_GET_ITEM(attr, 0)),
+ PyBytes_AS_STRING(PyTuple_GET_ITEM(attr, 1)));
*/
if (attr == NULL)
goto fail1;
@@ -711,7 +711,7 @@ _get_peer_alt_names (X509 *certificate) {
goto fail;
}
- v = PyString_FromString("DirName");
+ v = PyBytes_FromString("DirName");
if (v == NULL) {
Py_DECREF(t);
goto fail;
@@ -742,13 +742,13 @@ _get_peer_alt_names (X509 *certificate) {
t = PyTuple_New(2);
if (t == NULL)
goto fail;
- v = PyString_FromStringAndSize(buf, (vptr - buf));
+ v = PyBytes_FromStringAndSize(buf, (vptr - buf));
if (v == NULL) {
Py_DECREF(t);
goto fail;
}
PyTuple_SET_ITEM(t, 0, v);
- v = PyString_FromStringAndSize((vptr + 1), (len - (vptr - buf + 1)));
+ v = PyBytes_FromStringAndSize((vptr + 1), (len - (vptr - buf + 1)));
if (v == NULL) {
Py_DECREF(t);
goto fail;
@@ -849,7 +849,7 @@ _decode_certificate (X509 *certificate, int verbose) {
_setSSLError(NULL, 0, __FILE__, __LINE__);
goto fail1;
}
- sn_obj = PyString_FromStringAndSize(buf, len);
+ sn_obj = PyBytes_FromStringAndSize(buf, len);
if (sn_obj == NULL)
goto fail1;
if (PyDict_SetItemString(retval, "serialNumber", sn_obj) < 0) {
@@ -866,7 +866,7 @@ _decode_certificate (X509 *certificate, int verbose) {
_setSSLError(NULL, 0, __FILE__, __LINE__);
goto fail1;
}
- pnotBefore = PyString_FromStringAndSize(buf, len);
+ pnotBefore = PyBytes_FromStringAndSize(buf, len);
if (pnotBefore == NULL)
goto fail1;
if (PyDict_SetItemString(retval, "notBefore", pnotBefore) < 0) {
@@ -884,7 +884,7 @@ _decode_certificate (X509 *certificate, int verbose) {
_setSSLError(NULL, 0, __FILE__, __LINE__);
goto fail1;
}
- pnotAfter = PyString_FromStringAndSize(buf, len);
+ pnotAfter = PyBytes_FromStringAndSize(buf, len);
if (pnotAfter == NULL)
goto fail1;
if (PyDict_SetItemString(retval, "notAfter", pnotAfter) < 0) {
@@ -981,7 +981,7 @@ PySSL_peercert(PySSLObject *self, PyObject *args)
PySSL_SetError(self, len, __FILE__, __LINE__);
return NULL;
}
- retval = PyString_FromStringAndSize((const char *) bytes_buf, len);
+ retval = PyBytes_FromStringAndSize((const char *) bytes_buf, len);
OPENSSL_free(bytes_buf);
return retval;
@@ -1028,7 +1028,7 @@ static PyObject *PySSL_cipher (PySSLObject *self) {
if (cipher_name == NULL) {
PyTuple_SET_ITEM(retval, 0, Py_None);
} else {
- v = PyString_FromString(cipher_name);
+ v = PyBytes_FromString(cipher_name);
if (v == NULL)
goto fail0;
PyTuple_SET_ITEM(retval, 0, v);
@@ -1037,7 +1037,7 @@ static PyObject *PySSL_cipher (PySSLObject *self) {
if (cipher_protocol == NULL) {
PyTuple_SET_ITEM(retval, 1, Py_None);
} else {
- v = PyString_FromString(cipher_protocol);
+ v = PyBytes_FromString(cipher_protocol);
if (v == NULL)
goto fail0;
PyTuple_SET_ITEM(retval, 1, v);
@@ -1211,7 +1211,7 @@ static PyObject *PySSL_SSLread(PySSLObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "|i:read", &len))
return NULL;
- if (!(buf = PyString_FromStringAndSize((char *) 0, len)))
+ if (!(buf = PyBytes_FromStringAndSize((char *) 0, len)))
return NULL;
/* first check if there are bytes ready to be read */
@@ -1233,14 +1233,14 @@ static PyObject *PySSL_SSLread(PySSLObject *self, PyObject *args)
return NULL;
} else if (sockstate == SOCKET_HAS_BEEN_CLOSED) {
/* should contain a zero-length string */
- _PyString_Resize(&buf, 0);
+ _PyBytes_Resize(&buf, 0);
return buf;
}
}
do {
err = 0;
PySSL_BEGIN_ALLOW_THREADS
- count = SSL_read(self->ssl, PyString_AsString(buf), len);
+ count = SSL_read(self->ssl, PyBytes_AsString(buf), len);
err = SSL_get_error(self->ssl, count);
PySSL_END_ALLOW_THREADS
if(PyErr_CheckSignals()) {
@@ -1257,7 +1257,7 @@ static PyObject *PySSL_SSLread(PySSLObject *self, PyObject *args)
(SSL_get_shutdown(self->ssl) ==
SSL_RECEIVED_SHUTDOWN))
{
- _PyString_Resize(&buf, 0);
+ _PyBytes_Resize(&buf, 0);
return buf;
} else {
sockstate = SOCKET_OPERATION_OK;
@@ -1276,7 +1276,7 @@ static PyObject *PySSL_SSLread(PySSLObject *self, PyObject *args)
return PySSL_SetError(self, count, __FILE__, __LINE__);
}
if (count != len)
- _PyString_Resize(&buf, count);
+ _PyBytes_Resize(&buf, count);
return buf;
}
@@ -1362,11 +1362,11 @@ PySSL_RAND_egd(PyObject *self, PyObject *arg)
{
int bytes;
- if (!PyString_Check(arg))
+ if (!PyBytes_Check(arg))
return PyErr_Format(PyExc_TypeError,
"RAND_egd() expected string, found %s",
Py_TYPE(arg)->tp_name);
- bytes = RAND_egd(PyString_AS_STRING(arg));
+ bytes = RAND_egd(PyBytes_AS_STRING(arg));
if (bytes == -1) {
PyErr_SetString(PySSLErrorObject,
"EGD connection failed or EGD did not return "
diff --git a/Modules/_struct.c b/Modules/_struct.c
index e5fe211f29..b0351f1c69 100644
--- a/Modules/_struct.c
+++ b/Modules/_struct.c
@@ -413,7 +413,7 @@ _range_error(const formatdef *f, int is_unsigned)
if (msg == NULL)
return -1;
rval = PyErr_WarnEx(PyExc_DeprecationWarning,
- PyString_AS_STRING(msg), 2);
+ PyBytes_AS_STRING(msg), 2);
Py_DECREF(msg);
if (rval == 0)
return 0;
@@ -446,7 +446,7 @@ _range_error(const formatdef *f, int is_unsigned)
static PyObject *
nu_char(const char *p, const formatdef *f)
{
- return PyString_FromStringAndSize(p, 1);
+ return PyBytes_FromStringAndSize(p, 1);
}
static PyObject *
@@ -610,12 +610,12 @@ np_ubyte(char *p, PyObject *v, const formatdef *f)
static int
np_char(char *p, PyObject *v, const formatdef *f)
{
- if (!PyString_Check(v) || PyString_Size(v) != 1) {
+ if (!PyBytes_Check(v) || PyBytes_Size(v) != 1) {
PyErr_SetString(StructError,
"char format require string of length 1");
return -1;
}
- *p = *PyString_AsString(v);
+ *p = *PyBytes_AsString(v);
return 0;
}
@@ -1335,7 +1335,7 @@ prepare_s(PyStructObject *self)
char c;
Py_ssize_t size, len, num, itemsize, x;
- fmt = PyString_AS_STRING(self->s_format);
+ fmt = PyBytes_AS_STRING(self->s_format);
f = whichtable((char **)&fmt);
@@ -1503,12 +1503,12 @@ s_unpack_internal(PyStructObject *soself, char *startfrom) {
const formatdef *e = code->fmtdef;
const char *res = startfrom + code->offset;
if (e->format == 's') {
- v = PyString_FromStringAndSize(res, code->size);
+ v = PyBytes_FromStringAndSize(res, code->size);
} else if (e->format == 'p') {
Py_ssize_t n = *(unsigned char*)res;
if (n >= code->size)
n = code->size - 1;
- v = PyString_FromStringAndSize(res + 1, n);
+ v = PyBytes_FromStringAndSize(res + 1, n);
} else {
v = e->unpack(res, e);
}
@@ -1542,9 +1542,9 @@ s_unpack(PyObject *self, PyObject *inputstr)
assert(soself->s_codes != NULL);
if (inputstr == NULL)
goto fail;
- if (PyString_Check(inputstr) &&
- PyString_GET_SIZE(inputstr) == soself->s_size) {
- return s_unpack_internal(soself, PyString_AS_STRING(inputstr));
+ if (PyBytes_Check(inputstr) &&
+ PyBytes_GET_SIZE(inputstr) == soself->s_size) {
+ return s_unpack_internal(soself, PyBytes_AS_STRING(inputstr));
}
args = PyTuple_Pack(1, inputstr);
if (args == NULL)
@@ -1637,27 +1637,27 @@ s_pack_internal(PyStructObject *soself, PyObject *args, int offset, char* buf)
const formatdef *e = code->fmtdef;
char *res = buf + code->offset;
if (e->format == 's') {
- if (!PyString_Check(v)) {
+ if (!PyBytes_Check(v)) {
PyErr_SetString(StructError,
"argument for 's' must be a string");
return -1;
}
- n = PyString_GET_SIZE(v);
+ n = PyBytes_GET_SIZE(v);
if (n > code->size)
n = code->size;
if (n > 0)
- memcpy(res, PyString_AS_STRING(v), n);
+ memcpy(res, PyBytes_AS_STRING(v), n);
} else if (e->format == 'p') {
- if (!PyString_Check(v)) {
+ if (!PyBytes_Check(v)) {
PyErr_SetString(StructError,
"argument for 'p' must be a string");
return -1;
}
- n = PyString_GET_SIZE(v);
+ n = PyBytes_GET_SIZE(v);
if (n > (code->size - 1))
n = code->size - 1;
if (n > 0)
- memcpy(res + 1, PyString_AS_STRING(v), n);
+ memcpy(res + 1, PyBytes_AS_STRING(v), n);
if (n > 255)
n = 255;
*res = Py_SAFE_DOWNCAST(n, Py_ssize_t, unsigned char);
@@ -1700,12 +1700,12 @@ s_pack(PyObject *self, PyObject *args)
}
/* Allocate a new string */
- result = PyString_FromStringAndSize((char *)NULL, soself->s_size);
+ result = PyBytes_FromStringAndSize((char *)NULL, soself->s_size);
if (result == NULL)
return NULL;
/* Call the guts */
- if ( s_pack_internal(soself, args, 0, PyString_AS_STRING(result)) != 0 ) {
+ if ( s_pack_internal(soself, args, 0, PyBytes_AS_STRING(result)) != 0 ) {
Py_DECREF(result);
return NULL;
}
@@ -2061,7 +2061,7 @@ init_struct(void)
{
PyObject *ver, *m;
- ver = PyString_FromString("0.2");
+ ver = PyBytes_FromString("0.2");
if (ver == NULL)
return;
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index 4a00fb1975..15bd899352 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -691,7 +691,7 @@ test_thread_state(PyObject *self, PyObject *args)
}
#endif
-/* Some tests of PyString_FromFormat(). This needs more tests. */
+/* Some tests of PyBytes_FromFormat(). This needs more tests. */
static PyObject *
test_string_from_format(PyObject *self, PyObject *args)
{
@@ -699,10 +699,10 @@ test_string_from_format(PyObject *self, PyObject *args)
char *msg;
#define CHECK_1_FORMAT(FORMAT, TYPE) \
- result = PyString_FromFormat(FORMAT, (TYPE)1); \
+ result = PyBytes_FromFormat(FORMAT, (TYPE)1); \
if (result == NULL) \
return NULL; \
- if (strcmp(PyString_AsString(result), "1")) { \
+ if (strcmp(PyBytes_AsString(result), "1")) { \
msg = FORMAT " failed at 1"; \
goto Fail; \
} \
diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c
index 4308773419..eb671289b5 100644
--- a/Modules/_tkinter.c
+++ b/Modules/_tkinter.c
@@ -335,8 +335,8 @@ WaitForMainloop(TkappObject* self)
static char *
AsString(PyObject *value, PyObject *tmp)
{
- if (PyString_Check(value))
- return PyString_AsString(value);
+ if (PyBytes_Check(value))
+ return PyBytes_AsString(value);
#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(value)) {
PyObject *v = PyUnicode_AsUTF8String(value);
@@ -347,7 +347,7 @@ AsString(PyObject *value, PyObject *tmp)
return NULL;
}
Py_DECREF(v);
- return PyString_AsString(v);
+ return PyBytes_AsString(v);
}
#endif
else {
@@ -359,7 +359,7 @@ AsString(PyObject *value, PyObject *tmp)
return NULL;
}
Py_DECREF(v);
- return PyString_AsString(v);
+ return PyBytes_AsString(v);
}
}
@@ -462,13 +462,13 @@ Split(char *list)
* Could be a quoted string containing funnies, e.g. {"}.
* Return the string itself.
*/
- return PyString_FromString(list);
+ return PyBytes_FromString(list);
}
if (argc == 0)
- v = PyString_FromString("");
+ v = PyBytes_FromString("");
else if (argc == 1)
- v = PyString_FromString(argv[0]);
+ v = PyBytes_FromString(argv[0]);
else if ((v = PyTuple_New(argc)) != NULL) {
int i;
PyObject *w;
@@ -530,10 +530,10 @@ SplitObj(PyObject *arg)
return result;
/* Fall through, returning arg. */
}
- else if (PyString_Check(arg)) {
+ else if (PyBytes_Check(arg)) {
int argc;
char **argv;
- char *list = PyString_AsString(arg);
+ char *list = PyBytes_AsString(arg);
if (Tcl_SplitList((Tcl_Interp *)NULL, list, &argc, &argv) != TCL_OK) {
Py_INCREF(arg);
@@ -541,7 +541,7 @@ SplitObj(PyObject *arg)
}
Tcl_Free(FREECAST argv);
if (argc > 1)
- return Split(PyString_AsString(arg));
+ return Split(PyBytes_AsString(arg));
/* Fall through, returning arg. */
}
Py_INCREF(arg);
@@ -747,12 +747,12 @@ PyTclObject_dealloc(PyTclObject *self)
static PyObject *
PyTclObject_str(PyTclObject *self)
{
- if (self->string && PyString_Check(self->string)) {
+ if (self->string && PyBytes_Check(self->string)) {
Py_INCREF(self->string);
return self->string;
}
/* XXX Could cache value if it is an ASCII string. */
- return PyString_FromString(Tcl_GetString(self->value));
+ return PyBytes_FromString(Tcl_GetString(self->value));
}
static char*
@@ -778,16 +778,16 @@ PyTclObject_string(PyTclObject *self, void *ignored)
#ifdef Py_USING_UNICODE
if (i == len)
/* It is an ASCII string. */
- self->string = PyString_FromStringAndSize(s, len);
+ self->string = PyBytes_FromStringAndSize(s, len);
else {
self->string = PyUnicode_DecodeUTF8(s, len, "strict");
if (!self->string) {
PyErr_Clear();
- self->string = PyString_FromStringAndSize(s, len);
+ self->string = PyBytes_FromStringAndSize(s, len);
}
}
#else
- self->string = PyString_FromStringAndSize(s, len);
+ self->string = PyBytes_FromStringAndSize(s, len);
#endif
if (!self->string)
return NULL;
@@ -820,7 +820,7 @@ PyTclObject_repr(PyTclObject *self)
char buf[50];
PyOS_snprintf(buf, 50, "<%s object at %p>",
self->value->typePtr->name, self->value);
- return PyString_FromString(buf);
+ return PyBytes_FromString(buf);
}
static int
@@ -839,7 +839,7 @@ PyDoc_STRVAR(get_typename__doc__, "name of the Tcl type");
static PyObject*
get_typename(PyTclObject* obj, void* ignored)
{
- return PyString_FromString(obj->value->typePtr->name);
+ return PyBytes_FromString(obj->value->typePtr->name);
}
@@ -908,9 +908,9 @@ AsObj(PyObject *value)
{
Tcl_Obj *result;
- if (PyString_Check(value))
- return Tcl_NewStringObj(PyString_AS_STRING(value),
- PyString_GET_SIZE(value));
+ if (PyBytes_Check(value))
+ return Tcl_NewStringObj(PyBytes_AS_STRING(value),
+ PyBytes_GET_SIZE(value));
else if (PyBool_Check(value))
return Tcl_NewBooleanObj(PyObject_IsTrue(value));
else if (PyInt_Check(value))
@@ -999,17 +999,17 @@ FromObj(PyObject* tkapp, Tcl_Obj *value)
}
if (i == value->length)
- result = PyString_FromStringAndSize(s, len);
+ result = PyBytes_FromStringAndSize(s, len);
else {
/* Convert UTF-8 to Unicode string */
result = PyUnicode_DecodeUTF8(s, len, "strict");
if (result == NULL) {
PyErr_Clear();
- result = PyString_FromStringAndSize(s, len);
+ result = PyBytes_FromStringAndSize(s, len);
}
}
#else
- result = PyString_FromStringAndSize(value->bytes, value->length);
+ result = PyBytes_FromStringAndSize(value->bytes, value->length);
#endif
return result;
}
@@ -1023,7 +1023,7 @@ FromObj(PyObject* tkapp, Tcl_Obj *value)
if (value->typePtr == app->ByteArrayType) {
int size;
char *data = (char*)Tcl_GetByteArrayFromObj(value, &size);
- return PyString_FromStringAndSize(data, size);
+ return PyBytes_FromStringAndSize(data, size);
}
if (value->typePtr == app->DoubleType) {
@@ -1092,7 +1092,7 @@ FromObj(PyObject* tkapp, Tcl_Obj *value)
int size;
char *c;
c = Tcl_GetStringFromObj(value, &size);
- return PyString_FromStringAndSize(c, size);
+ return PyBytes_FromStringAndSize(c, size);
#endif
}
@@ -1204,19 +1204,19 @@ Tkapp_CallResult(TkappObject *self)
}
if (*p == '\0')
- res = PyString_FromStringAndSize(s, (int)(p-s));
+ res = PyBytes_FromStringAndSize(s, (int)(p-s));
else {
/* Convert UTF-8 to Unicode string */
p = strchr(p, '\0');
res = PyUnicode_DecodeUTF8(s, (int)(p-s), "strict");
if (res == NULL) {
PyErr_Clear();
- res = PyString_FromStringAndSize(s, (int)(p-s));
+ res = PyBytes_FromStringAndSize(s, (int)(p-s));
}
}
#else
p = strchr(p, '\0');
- res = PyString_FromStringAndSize(s, (int)(p-s));
+ res = PyBytes_FromStringAndSize(s, (int)(p-s));
#endif
}
return res;
@@ -1370,7 +1370,7 @@ Tkapp_GlobalCall(PyObject *self, PyObject *args)
if (err == TCL_ERROR)
res = Tkinter_Error(self);
else
- res = PyString_FromString(Tkapp_Result(self));
+ res = PyBytes_FromString(Tkapp_Result(self));
LEAVE_OVERLAP_TCL
ckfree(cmd);
}
@@ -1396,7 +1396,7 @@ Tkapp_Eval(PyObject *self, PyObject *args)
if (err == TCL_ERROR)
res = Tkinter_Error(self);
else
- res = PyString_FromString(Tkapp_Result(self));
+ res = PyBytes_FromString(Tkapp_Result(self));
LEAVE_OVERLAP_TCL
return res;
}
@@ -1419,7 +1419,7 @@ Tkapp_GlobalEval(PyObject *self, PyObject *args)
if (err == TCL_ERROR)
res = Tkinter_Error(self);
else
- res = PyString_FromString(Tkapp_Result(self));
+ res = PyBytes_FromString(Tkapp_Result(self));
LEAVE_OVERLAP_TCL
return res;
}
@@ -1443,7 +1443,7 @@ Tkapp_EvalFile(PyObject *self, PyObject *args)
res = Tkinter_Error(self);
else
- res = PyString_FromString(Tkapp_Result(self));
+ res = PyBytes_FromString(Tkapp_Result(self));
LEAVE_OVERLAP_TCL
return res;
}
@@ -1466,7 +1466,7 @@ Tkapp_Record(PyObject *self, PyObject *args)
if (err == TCL_ERROR)
res = Tkinter_Error(self);
else
- res = PyString_FromString(Tkapp_Result(self));
+ res = PyBytes_FromString(Tkapp_Result(self));
LEAVE_OVERLAP_TCL
return res;
}
@@ -1511,8 +1511,8 @@ static int
varname_converter(PyObject *in, void *_out)
{
char **out = (char**)_out;
- if (PyString_Check(in)) {
- *out = PyString_AsString(in);
+ if (PyBytes_Check(in)) {
+ *out = PyBytes_AsString(in);
return 1;
}
if (PyTclObject_Check(in)) {
@@ -1676,7 +1676,7 @@ GetVar(PyObject *self, PyObject *args, int flags)
res = FromObj(self, tres);
}
else {
- res = PyString_FromString(Tcl_GetString(tres));
+ res = PyBytes_FromString(Tcl_GetString(tres));
}
}
LEAVE_OVERLAP_TCL
@@ -1920,7 +1920,7 @@ Tkapp_SplitList(PyObject *self, PyObject *args)
goto finally;
for (i = 0; i < argc; i++) {
- PyObject *s = PyString_FromString(argv[i]);
+ PyObject *s = PyBytes_FromString(argv[i]);
if (!s || PyTuple_SetItem(v, i, s)) {
Py_DECREF(v);
v = NULL;
@@ -1961,7 +1961,7 @@ Tkapp_Merge(PyObject *self, PyObject *args)
PyObject *res = NULL;
if (s) {
- res = PyString_FromString(s);
+ res = PyBytes_FromString(s);
ckfree(s);
}
@@ -2011,7 +2011,7 @@ PythonCmd(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[])
return PythonCmd_Error(interp);
for (i = 0; i < (argc - 1); i++) {
- PyObject *s = PyString_FromString(argv[i + 1]);
+ PyObject *s = PyBytes_FromString(argv[i + 1]);
if (!s || PyTuple_SetItem(arg, i, s)) {
Py_DECREF(arg);
return PythonCmd_Error(interp);
@@ -2406,7 +2406,7 @@ Tktt_Repr(PyObject *self)
PyOS_snprintf(buf, sizeof(buf), "<tktimertoken at %p%s>", v,
v->func == NULL ? ", handler deleted" : "");
- return PyString_FromString(buf);
+ return PyBytes_FromString(buf);
}
static PyObject *
@@ -3087,7 +3087,7 @@ ins_long(PyObject *d, char *name, long val)
static void
ins_string(PyObject *d, char *name, char *val)
{
- PyObject *v = PyString_FromString(val);
+ PyObject *v = PyBytes_FromString(val);
if (v) {
PyDict_SetItemString(d, name, v);
Py_DECREF(v);
diff --git a/Modules/almodule.c b/Modules/almodule.c
index 7f48fffed4..60140aea31 100644
--- a/Modules/almodule.c
+++ b/Modules/almodule.c
@@ -84,7 +84,7 @@ param2python(int resource, int param, ALvalue value, ALparamInfo *pinfo)
Py_INCREF(Py_None);
return Py_None;
}
- return PyString_FromString((char *) value.ptr);
+ return PyBytes_FromString((char *) value.ptr);
default:
PyErr_SetString(ErrorObject, "unknown element type");
return NULL;
@@ -149,12 +149,12 @@ python2param(int resource, ALpv *param, PyObject *value, ALparamInfo *pinfo)
PyErr_SetString(ErrorObject, "unknown element type");
return -1;
}
- if (!PyString_Check(value)) {
+ if (!PyBytes_Check(value)) {
PyErr_BadArgument();
return -1;
}
- param->value.ptr = PyString_AS_STRING(value);
- param->sizeIn = PyString_GET_SIZE(value)+1; /*account for NUL*/
+ param->value.ptr = PyBytes_AS_STRING(value);
+ param->sizeIn = PyBytes_GET_SIZE(value)+1; /*account for NUL*/
break;
case AL_SET_VAL:
case AL_VECTOR_VAL:
@@ -765,12 +765,12 @@ alp_ReadFrames(alpobject *self, PyObject *args)
return NULL;
}
size *= ch;
- v = PyString_FromStringAndSize((char *) NULL, size * framecount);
+ v = PyBytes_FromStringAndSize((char *) NULL, size * framecount);
if (v == NULL)
return NULL;
Py_BEGIN_ALLOW_THREADS
- alReadFrames(self->port, (void *) PyString_AS_STRING(v), framecount);
+ alReadFrames(self->port, (void *) PyBytes_AS_STRING(v), framecount);
Py_END_ALLOW_THREADS
return v;
@@ -1068,12 +1068,12 @@ alp_readsamps(alpobject *self, PyObject *args)
width = ALgetwidth(c);
#endif /* AL_405 */
ALfreeconfig(c);
- v = PyString_FromStringAndSize((char *)NULL, width * count);
+ v = PyBytes_FromStringAndSize((char *)NULL, width * count);
if (v == NULL)
return NULL;
Py_BEGIN_ALLOW_THREADS
- ret = ALreadsamps(self->port, (void *) PyString_AsString(v), count);
+ ret = ALreadsamps(self->port, (void *) PyBytes_AsString(v), count);
Py_END_ALLOW_THREADS
if (ret == -1) {
Py_DECREF(v);
@@ -1498,7 +1498,7 @@ al_GetParams(PyObject *self, PyObject *args)
Py_INCREF(item);
break;
case AL_STRING_VAL:
- item = PyString_FromString(pvs[i].value.ptr);
+ item = PyBytes_FromString(pvs[i].value.ptr);
PyMem_DEL(pvs[i].value.ptr);
break;
case AL_MATRIX_VAL:
@@ -1725,7 +1725,7 @@ al_GetParamInfo(PyObject *self, PyObject *args)
PyDict_SetItemString(v, "elementType", item);
Py_DECREF(item);
- item = PyString_FromString(pinfo.name);
+ item = PyBytes_FromString(pinfo.name);
PyDict_SetItemString(v, "name", item);
Py_DECREF(item);
@@ -1920,7 +1920,7 @@ al_getname(PyObject *self, PyObject *args)
return NULL;
if ((name = ALgetname(device, descriptor)) == NULL)
return NULL;
- return PyString_FromString(name);
+ return PyBytes_FromString(name);
}
static PyObject *
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
index 89ed27a0b7..32d34c7452 100644
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -104,7 +104,7 @@ in bounds; that's the responsibility of the caller.
static PyObject *
c_getitem(arrayobject *ap, Py_ssize_t i)
{
- return PyString_FromStringAndSize(&((char *)ap->ob_item)[i], 1);
+ return PyBytes_FromStringAndSize(&((char *)ap->ob_item)[i], 1);
}
static int
@@ -1414,7 +1414,7 @@ values,as if it had been read from a file using the fromfile() method).");
static PyObject *
array_tostring(arrayobject *self, PyObject *unused)
{
- return PyString_FromStringAndSize(self->ob_item,
+ return PyBytes_FromStringAndSize(self->ob_item,
Py_SIZE(self) * self->ob_descr->itemsize);
}
@@ -1494,7 +1494,7 @@ static PyObject *
array_get_typecode(arrayobject *a, void *closure)
{
char tc = a->ob_descr->typecode;
- return PyString_FromStringAndSize(&tc, 1);
+ return PyBytes_FromStringAndSize(&tc, 1);
}
static PyObject *
@@ -1578,7 +1578,7 @@ array_repr(arrayobject *a)
typecode = a->ob_descr->typecode;
if (len == 0) {
PyOS_snprintf(buf, sizeof(buf), "array('%c')", typecode);
- return PyString_FromString(buf);
+ return PyBytes_FromString(buf);
}
if (typecode == 'c')
@@ -1593,9 +1593,9 @@ array_repr(arrayobject *a)
Py_XDECREF(v);
PyOS_snprintf(buf, sizeof(buf), "array('%c', ", typecode);
- s = PyString_FromString(buf);
- PyString_ConcatAndDel(&s, t);
- PyString_ConcatAndDel(&s, PyString_FromString(")"));
+ s = PyBytes_FromString(buf);
+ PyBytes_ConcatAndDel(&s, t);
+ PyBytes_ConcatAndDel(&s, PyBytes_FromString(")"));
return s;
}
@@ -1881,7 +1881,7 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return NULL;
if (!(initial == NULL || PyList_Check(initial)
- || PyString_Check(initial) || PyTuple_Check(initial)
+ || PyBytes_Check(initial) || PyTuple_Check(initial)
|| (c == 'u' && PyUnicode_Check(initial)))) {
it = PyObject_GetIter(initial);
if (it == NULL)
@@ -1924,7 +1924,7 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
}
Py_DECREF(v);
}
- } else if (initial != NULL && PyString_Check(initial)) {
+ } else if (initial != NULL && PyBytes_Check(initial)) {
PyObject *t_initial, *v;
t_initial = PyTuple_Pack(1, initial);
if (t_initial == NULL) {
diff --git a/Modules/audioop.c b/Modules/audioop.c
index ce009758de..9eb684b5ee 100644
--- a/Modules/audioop.c
+++ b/Modules/audioop.c
@@ -474,7 +474,7 @@ audioop_findfit(PyObject *self, PyObject *args)
/* Passing a short** for an 's' argument is correct only
if the string contents is aligned for interpretation
- as short[]. Due to the definition of PyStringObject,
+ as short[]. Due to the definition of PyBytesObject,
this is currently (Python 2.6) the case. */
if ( !PyArg_ParseTuple(args, "s#s#:findfit",
(char**)&cp1, &len1, (char**)&cp2, &len2) )
@@ -759,10 +759,10 @@ audioop_mul(PyObject *self, PyObject *args)
return 0;
}
- rv = PyString_FromStringAndSize(NULL, len);
+ rv = PyBytes_FromStringAndSize(NULL, len);
if ( rv == 0 )
return 0;
- ncp = (signed char *)PyString_AsString(rv);
+ ncp = (signed char *)PyBytes_AsString(rv);
for ( i=0; i < len; i += size ) {
@@ -801,10 +801,10 @@ audioop_tomono(PyObject *self, PyObject *args)
return 0;
}
- rv = PyString_FromStringAndSize(NULL, len/2);
+ rv = PyBytes_FromStringAndSize(NULL, len/2);
if ( rv == 0 )
return 0;
- ncp = (signed char *)PyString_AsString(rv);
+ ncp = (signed char *)PyBytes_AsString(rv);
for ( i=0; i < len; i += size*2 ) {
@@ -846,10 +846,10 @@ audioop_tostereo(PyObject *self, PyObject *args)
return 0;
}
- rv = PyString_FromStringAndSize(NULL, len*2);
+ rv = PyBytes_FromStringAndSize(NULL, len*2);
if ( rv == 0 )
return 0;
- ncp = (signed char *)PyString_AsString(rv);
+ ncp = (signed char *)PyBytes_AsString(rv);
for ( i=0; i < len; i += size ) {
@@ -903,10 +903,10 @@ audioop_add(PyObject *self, PyObject *args)
return 0;
}
- rv = PyString_FromStringAndSize(NULL, len1);
+ rv = PyBytes_FromStringAndSize(NULL, len1);
if ( rv == 0 )
return 0;
- ncp = (signed char *)PyString_AsString(rv);
+ ncp = (signed char *)PyBytes_AsString(rv);
for ( i=0; i < len1; i += size ) {
if ( size == 1 ) val1 = (int)*CHARP(cp1, i);
@@ -949,10 +949,10 @@ audioop_bias(PyObject *self, PyObject *args)
return 0;
}
- rv = PyString_FromStringAndSize(NULL, len);
+ rv = PyBytes_FromStringAndSize(NULL, len);
if ( rv == 0 )
return 0;
- ncp = (signed char *)PyString_AsString(rv);
+ ncp = (signed char *)PyBytes_AsString(rv);
for ( i=0; i < len; i += size ) {
@@ -985,10 +985,10 @@ audioop_reverse(PyObject *self, PyObject *args)
return 0;
}
- rv = PyString_FromStringAndSize(NULL, len);
+ rv = PyBytes_FromStringAndSize(NULL, len);
if ( rv == 0 )
return 0;
- ncp = (unsigned char *)PyString_AsString(rv);
+ ncp = (unsigned char *)PyBytes_AsString(rv);
for ( i=0; i < len; i += size ) {
if ( size == 1 ) val = ((int)*CHARP(cp, i)) << 8;
@@ -1023,10 +1023,10 @@ audioop_lin2lin(PyObject *self, PyObject *args)
return 0;
}
- rv = PyString_FromStringAndSize(NULL, (len/size)*size2);
+ rv = PyBytes_FromStringAndSize(NULL, (len/size)*size2);
if ( rv == 0 )
return 0;
- ncp = (unsigned char *)PyString_AsString(rv);
+ ncp = (unsigned char *)PyBytes_AsString(rv);
for ( i=0, j=0; i < len; i += size, j += size2 ) {
if ( size == 1 ) val = ((int)*CHARP(cp, i)) << 8;
@@ -1157,7 +1157,7 @@ audioop_ratecv(PyObject *self, PyObject *args)
nbytes / bytes_per_frame != ceiling)
str = NULL;
else
- str = PyString_FromStringAndSize(NULL, nbytes);
+ str = PyBytes_FromStringAndSize(NULL, nbytes);
if (str == NULL) {
PyErr_SetString(PyExc_MemoryError,
@@ -1165,7 +1165,7 @@ audioop_ratecv(PyObject *self, PyObject *args)
goto exit;
}
}
- ncp = PyString_AsString(str);
+ ncp = PyBytes_AsString(str);
for (;;) {
while (d < 0) {
@@ -1182,13 +1182,13 @@ audioop_ratecv(PyObject *self, PyObject *args)
goto exit;
/* We have checked before that the length
* of the string fits into int. */
- len = (int)(ncp - PyString_AsString(str));
+ len = (int)(ncp - PyBytes_AsString(str));
if (len == 0) {
/*don't want to resize to zero length*/
- rv = PyString_FromStringAndSize("", 0);
+ rv = PyBytes_FromStringAndSize("", 0);
Py_DECREF(str);
str = rv;
- } else if (_PyString_Resize(&str, len) < 0)
+ } else if (_PyBytes_Resize(&str, len) < 0)
goto exit;
rv = Py_BuildValue("(O(iO))", str, d, samps);
Py_DECREF(samps);
@@ -1255,10 +1255,10 @@ audioop_lin2ulaw(PyObject *self, PyObject *args)
return 0;
}
- rv = PyString_FromStringAndSize(NULL, len/size);
+ rv = PyBytes_FromStringAndSize(NULL, len/size);
if ( rv == 0 )
return 0;
- ncp = (unsigned char *)PyString_AsString(rv);
+ ncp = (unsigned char *)PyBytes_AsString(rv);
for ( i=0; i < len; i += size ) {
if ( size == 1 ) val = ((int)*CHARP(cp, i)) << 8;
@@ -1289,10 +1289,10 @@ audioop_ulaw2lin(PyObject *self, PyObject *args)
return 0;
}
- rv = PyString_FromStringAndSize(NULL, len*size);
+ rv = PyBytes_FromStringAndSize(NULL, len*size);
if ( rv == 0 )
return 0;
- ncp = (signed char *)PyString_AsString(rv);
+ ncp = (signed char *)PyBytes_AsString(rv);
for ( i=0; i < len*size; i += size ) {
cval = *cp++;
@@ -1323,10 +1323,10 @@ audioop_lin2alaw(PyObject *self, PyObject *args)
return 0;
}
- rv = PyString_FromStringAndSize(NULL, len/size);
+ rv = PyBytes_FromStringAndSize(NULL, len/size);
if ( rv == 0 )
return 0;
- ncp = (unsigned char *)PyString_AsString(rv);
+ ncp = (unsigned char *)PyBytes_AsString(rv);
for ( i=0; i < len; i += size ) {
if ( size == 1 ) val = ((int)*CHARP(cp, i)) << 8;
@@ -1357,10 +1357,10 @@ audioop_alaw2lin(PyObject *self, PyObject *args)
return 0;
}
- rv = PyString_FromStringAndSize(NULL, len*size);
+ rv = PyBytes_FromStringAndSize(NULL, len*size);
if ( rv == 0 )
return 0;
- ncp = (signed char *)PyString_AsString(rv);
+ ncp = (signed char *)PyBytes_AsString(rv);
for ( i=0; i < len*size; i += size ) {
cval = *cp++;
@@ -1393,10 +1393,10 @@ audioop_lin2adpcm(PyObject *self, PyObject *args)
return 0;
}
- str = PyString_FromStringAndSize(NULL, len/(size*2));
+ str = PyBytes_FromStringAndSize(NULL, len/(size*2));
if ( str == 0 )
return 0;
- ncp = (signed char *)PyString_AsString(str);
+ ncp = (signed char *)PyBytes_AsString(str);
/* Decode state, should have (value, step) */
if ( state == Py_None ) {
@@ -1509,10 +1509,10 @@ audioop_adpcm2lin(PyObject *self, PyObject *args)
} else if ( !PyArg_ParseTuple(state, "ii", &valpred, &index) )
return 0;
- str = PyString_FromStringAndSize(NULL, len*size*2);
+ str = PyBytes_FromStringAndSize(NULL, len*size*2);
if ( str == 0 )
return 0;
- ncp = (signed char *)PyString_AsString(str);
+ ncp = (signed char *)PyBytes_AsString(str);
step = stepsizeTable[index];
bufferstep = 0;
diff --git a/Modules/binascii.c b/Modules/binascii.c
index c1fc675cf1..f9df6252ba 100644
--- a/Modules/binascii.c
+++ b/Modules/binascii.c
@@ -141,7 +141,7 @@ static char table_a2b_base64[] = {
#define BASE64_PAD '='
/* Max binary chunk size; limited only by available memory */
-#define BASE64_MAXBIN (INT_MAX/2 - sizeof(PyStringObject) - 3)
+#define BASE64_MAXBIN (INT_MAX/2 - sizeof(PyBytesObject) - 3)
static unsigned char table_b2a_base64[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
@@ -203,9 +203,9 @@ binascii_a2b_uu(PyObject *self, PyObject *args)
ascii_len--;
/* Allocate the buffer */
- if ( (rv=PyString_FromStringAndSize(NULL, bin_len)) == NULL )
+ if ( (rv=PyBytes_FromStringAndSize(NULL, bin_len)) == NULL )
return NULL;
- bin_data = (unsigned char *)PyString_AsString(rv);
+ bin_data = (unsigned char *)PyBytes_AsString(rv);
for( ; bin_len > 0 ; ascii_len--, ascii_data++ ) {
/* XXX is it really best to add NULs if there's no more data */
@@ -280,9 +280,9 @@ binascii_b2a_uu(PyObject *self, PyObject *args)
}
/* We're lazy and allocate to much (fixed up later) */
- if ( (rv=PyString_FromStringAndSize(NULL, bin_len*2+2)) == NULL )
+ if ( (rv=PyBytes_FromStringAndSize(NULL, bin_len*2+2)) == NULL )
return NULL;
- ascii_data = (unsigned char *)PyString_AsString(rv);
+ ascii_data = (unsigned char *)PyBytes_AsString(rv);
/* Store the length */
*ascii_data++ = ' ' + (bin_len & 077);
@@ -304,8 +304,8 @@ binascii_b2a_uu(PyObject *self, PyObject *args)
}
*ascii_data++ = '\n'; /* Append a courtesy newline */
- _PyString_Resize(&rv, (ascii_data -
- (unsigned char *)PyString_AsString(rv)));
+ _PyBytes_Resize(&rv, (ascii_data -
+ (unsigned char *)PyBytes_AsString(rv)));
return rv;
}
@@ -354,9 +354,9 @@ binascii_a2b_base64(PyObject *self, PyObject *args)
bin_len = ((ascii_len+3)/4)*3; /* Upper bound, corrected later */
/* Allocate the buffer */
- if ( (rv=PyString_FromStringAndSize(NULL, bin_len)) == NULL )
+ if ( (rv=PyBytes_FromStringAndSize(NULL, bin_len)) == NULL )
return NULL;
- bin_data = (unsigned char *)PyString_AsString(rv);
+ bin_data = (unsigned char *)PyBytes_AsString(rv);
bin_len = 0;
for( ; ascii_len > 0; ascii_len--, ascii_data++) {
@@ -415,13 +415,13 @@ binascii_a2b_base64(PyObject *self, PyObject *args)
/* And set string size correctly. If the result string is empty
** (because the input was all invalid) return the shared empty
- ** string instead; _PyString_Resize() won't do this for us.
+ ** string instead; _PyBytes_Resize() won't do this for us.
*/
if (bin_len > 0)
- _PyString_Resize(&rv, bin_len);
+ _PyBytes_Resize(&rv, bin_len);
else {
Py_DECREF(rv);
- rv = PyString_FromString("");
+ rv = PyBytes_FromString("");
}
return rv;
}
@@ -448,9 +448,9 @@ binascii_b2a_base64(PyObject *self, PyObject *args)
/* We're lazy and allocate too much (fixed up later).
"+3" leaves room for up to two pad characters and a trailing
newline. Note that 'b' gets encoded as 'Yg==\n' (1 in, 5 out). */
- if ( (rv=PyString_FromStringAndSize(NULL, bin_len*2 + 3)) == NULL )
+ if ( (rv=PyBytes_FromStringAndSize(NULL, bin_len*2 + 3)) == NULL )
return NULL;
- ascii_data = (unsigned char *)PyString_AsString(rv);
+ ascii_data = (unsigned char *)PyBytes_AsString(rv);
for( ; bin_len > 0 ; bin_len--, bin_data++ ) {
/* Shift the data into our buffer */
@@ -474,8 +474,8 @@ binascii_b2a_base64(PyObject *self, PyObject *args)
}
*ascii_data++ = '\n'; /* Append a courtesy newline */
- _PyString_Resize(&rv, (ascii_data -
- (unsigned char *)PyString_AsString(rv)));
+ _PyBytes_Resize(&rv, (ascii_data -
+ (unsigned char *)PyBytes_AsString(rv)));
return rv;
}
@@ -498,9 +498,9 @@ binascii_a2b_hqx(PyObject *self, PyObject *args)
/* Allocate a string that is too big (fixed later)
Add two to the initial length to prevent interning which
would preclude subsequent resizing. */
- if ( (rv=PyString_FromStringAndSize(NULL, len+2)) == NULL )
+ if ( (rv=PyBytes_FromStringAndSize(NULL, len+2)) == NULL )
return NULL;
- bin_data = (unsigned char *)PyString_AsString(rv);
+ bin_data = (unsigned char *)PyBytes_AsString(rv);
for( ; len > 0 ; len--, ascii_data++ ) {
/* Get the byte and look it up */
@@ -534,8 +534,8 @@ binascii_a2b_hqx(PyObject *self, PyObject *args)
Py_DECREF(rv);
return NULL;
}
- _PyString_Resize(
- &rv, (bin_data - (unsigned char *)PyString_AsString(rv)));
+ _PyBytes_Resize(
+ &rv, (bin_data - (unsigned char *)PyBytes_AsString(rv)));
if (rv) {
PyObject *rrv = Py_BuildValue("Oi", rv, done);
Py_DECREF(rv);
@@ -559,9 +559,9 @@ binascii_rlecode_hqx(PyObject *self, PyObject *args)
return NULL;
/* Worst case: output is twice as big as input (fixed later) */
- if ( (rv=PyString_FromStringAndSize(NULL, len*2+2)) == NULL )
+ if ( (rv=PyBytes_FromStringAndSize(NULL, len*2+2)) == NULL )
return NULL;
- out_data = (unsigned char *)PyString_AsString(rv);
+ out_data = (unsigned char *)PyBytes_AsString(rv);
for( in=0; in<len; in++) {
ch = in_data[in];
@@ -587,8 +587,8 @@ binascii_rlecode_hqx(PyObject *self, PyObject *args)
}
}
}
- _PyString_Resize(&rv, (out_data -
- (unsigned char *)PyString_AsString(rv)));
+ _PyBytes_Resize(&rv, (out_data -
+ (unsigned char *)PyBytes_AsString(rv)));
return rv;
}
@@ -608,9 +608,9 @@ binascii_b2a_hqx(PyObject *self, PyObject *args)
return NULL;
/* Allocate a buffer that is at least large enough */
- if ( (rv=PyString_FromStringAndSize(NULL, len*2+2)) == NULL )
+ if ( (rv=PyBytes_FromStringAndSize(NULL, len*2+2)) == NULL )
return NULL;
- ascii_data = (unsigned char *)PyString_AsString(rv);
+ ascii_data = (unsigned char *)PyBytes_AsString(rv);
for( ; len > 0 ; len--, bin_data++ ) {
/* Shift into our buffer, and output any 6bits ready */
@@ -627,8 +627,8 @@ binascii_b2a_hqx(PyObject *self, PyObject *args)
leftchar <<= (6-leftbits);
*ascii_data++ = table_b2a_hqx[leftchar & 0x3f];
}
- _PyString_Resize(&rv, (ascii_data -
- (unsigned char *)PyString_AsString(rv)));
+ _PyBytes_Resize(&rv, (ascii_data -
+ (unsigned char *)PyBytes_AsString(rv)));
return rv;
}
@@ -647,14 +647,14 @@ binascii_rledecode_hqx(PyObject *self, PyObject *args)
/* Empty string is a special case */
if ( in_len == 0 )
- return PyString_FromString("");
+ return PyBytes_FromString("");
/* Allocate a buffer of reasonable size. Resized when needed */
out_len = in_len*2;
- if ( (rv=PyString_FromStringAndSize(NULL, out_len)) == NULL )
+ if ( (rv=PyBytes_FromStringAndSize(NULL, out_len)) == NULL )
return NULL;
out_len_left = out_len;
- out_data = (unsigned char *)PyString_AsString(rv);
+ out_data = (unsigned char *)PyBytes_AsString(rv);
/*
** We need two macros here to get/put bytes and handle
@@ -673,9 +673,9 @@ binascii_rledecode_hqx(PyObject *self, PyObject *args)
#define OUTBYTE(b) \
do { \
if ( --out_len_left < 0 ) { \
- _PyString_Resize(&rv, 2*out_len); \
+ _PyBytes_Resize(&rv, 2*out_len); \
if ( rv == NULL ) return NULL; \
- out_data = (unsigned char *)PyString_AsString(rv) \
+ out_data = (unsigned char *)PyBytes_AsString(rv) \
+ out_len; \
out_len_left = out_len-1; \
out_len = out_len * 2; \
@@ -723,8 +723,8 @@ binascii_rledecode_hqx(PyObject *self, PyObject *args)
OUTBYTE(in_byte);
}
}
- _PyString_Resize(&rv, (out_data -
- (unsigned char *)PyString_AsString(rv)));
+ _PyBytes_Resize(&rv, (out_data -
+ (unsigned char *)PyBytes_AsString(rv)));
return rv;
}
@@ -923,10 +923,10 @@ binascii_hexlify(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "s#:b2a_hex", &argbuf, &arglen))
return NULL;
- retval = PyString_FromStringAndSize(NULL, arglen*2);
+ retval = PyBytes_FromStringAndSize(NULL, arglen*2);
if (!retval)
return NULL;
- retbuf = PyString_AsString(retval);
+ retbuf = PyBytes_AsString(retval);
if (!retbuf)
goto finally;
@@ -989,10 +989,10 @@ binascii_unhexlify(PyObject *self, PyObject *args)
return NULL;
}
- retval = PyString_FromStringAndSize(NULL, (arglen/2));
+ retval = PyBytes_FromStringAndSize(NULL, (arglen/2));
if (!retval)
return NULL;
- retbuf = PyString_AsString(retval);
+ retbuf = PyBytes_AsString(retval);
if (!retbuf)
goto finally;
@@ -1106,7 +1106,7 @@ binascii_a2b_qp(PyObject *self, PyObject *args, PyObject *kwargs)
out++;
}
}
- if ((rv = PyString_FromStringAndSize((char *)odata, out)) == NULL) {
+ if ((rv = PyBytes_FromStringAndSize((char *)odata, out)) == NULL) {
PyMem_Free(odata);
return NULL;
}
@@ -1306,7 +1306,7 @@ binascii_b2a_qp (PyObject *self, PyObject *args, PyObject *kwargs)
}
}
}
- if ((rv = PyString_FromStringAndSize((char *)odata, out)) == NULL) {
+ if ((rv = PyBytes_FromStringAndSize((char *)odata, out)) == NULL) {
PyMem_Free(odata);
return NULL;
}
@@ -1354,7 +1354,7 @@ initbinascii(void)
return;
d = PyModule_GetDict(m);
- x = PyString_FromString(doc_binascii);
+ x = PyBytes_FromString(doc_binascii);
PyDict_SetItemString(d, "__doc__", x);
Py_XDECREF(x);
diff --git a/Modules/bsddbmodule.c b/Modules/bsddbmodule.c
index 09728821e3..aca591e266 100644
--- a/Modules/bsddbmodule.c
+++ b/Modules/bsddbmodule.c
@@ -312,7 +312,7 @@ bsddb_subscript(bsddbobject *dp, PyObject *key)
return NULL;
}
- result = PyString_FromStringAndSize(data, (int)drec.size);
+ result = PyBytes_FromStringAndSize(data, (int)drec.size);
if (data != buf) free(data);
return result;
}
@@ -424,7 +424,7 @@ bsddb_keys(bsddbobject *dp)
if (dp->di_type == DB_RECNO)
item = PyInt_FromLong(*((int*)data));
else
- item = PyString_FromStringAndSize(data,
+ item = PyBytes_FromStringAndSize(data,
(int)krec.size);
if (data != buf) free(data);
if (item == NULL) {
diff --git a/Modules/bz2module.c b/Modules/bz2module.c
index bbabe101e5..ee24b5d7af 100644
--- a/Modules/bz2module.c
+++ b/Modules/bz2module.c
@@ -34,7 +34,7 @@ typedef fpos_t Py_off_t;
#error "Large file support, but neither off_t nor fpos_t is large enough."
#endif
-#define BUF(v) PyString_AS_STRING((PyStringObject *)v)
+#define BUF(v) PyBytes_AS_STRING((PyBytesObject *)v)
#define MODE_CLOSED 0
#define MODE_READ 1
@@ -241,7 +241,7 @@ Util_GetLine(BZ2FileObject *f, int n)
int univ_newline = f->f_univ_newline;
total_v_size = n > 0 ? n : 100;
- v = PyString_FromStringAndSize((char *)NULL, total_v_size);
+ v = PyBytes_FromStringAndSize((char *)NULL, total_v_size);
if (v == NULL)
return NULL;
@@ -307,7 +307,7 @@ Util_GetLine(BZ2FileObject *f, int n)
Py_DECREF(v);
return NULL;
}
- if (_PyString_Resize(&v, total_v_size) < 0)
+ if (_PyBytes_Resize(&v, total_v_size) < 0)
return NULL;
buf = BUF(v) + used_v_size;
end = BUF(v) + total_v_size;
@@ -315,7 +315,7 @@ Util_GetLine(BZ2FileObject *f, int n)
used_v_size = buf - BUF(v);
if (used_v_size != total_v_size)
- _PyString_Resize(&v, used_v_size);
+ _PyBytes_Resize(&v, used_v_size);
return v;
}
@@ -438,10 +438,10 @@ Util_ReadAhead(BZ2FileObject *f, int bufsize)
/* This is a hacked version of Python's
* fileobject.c:readahead_get_line_skip(). */
-static PyStringObject *
+static PyBytesObject *
Util_ReadAheadGetLineSkip(BZ2FileObject *f, int skip, int bufsize)
{
- PyStringObject* s;
+ PyBytesObject* s;
char *bufptr;
char *buf;
int len;
@@ -452,17 +452,17 @@ Util_ReadAheadGetLineSkip(BZ2FileObject *f, int skip, int bufsize)
len = f->f_bufend - f->f_bufptr;
if (len == 0)
- return (PyStringObject *)
- PyString_FromStringAndSize(NULL, skip);
+ return (PyBytesObject *)
+ PyBytes_FromStringAndSize(NULL, skip);
bufptr = memchr(f->f_bufptr, '\n', len);
if (bufptr != NULL) {
bufptr++; /* Count the '\n' */
len = bufptr - f->f_bufptr;
- s = (PyStringObject *)
- PyString_FromStringAndSize(NULL, skip+len);
+ s = (PyBytesObject *)
+ PyBytes_FromStringAndSize(NULL, skip+len);
if (s == NULL)
return NULL;
- memcpy(PyString_AS_STRING(s)+skip, f->f_bufptr, len);
+ memcpy(PyBytes_AS_STRING(s)+skip, f->f_bufptr, len);
f->f_bufptr = bufptr;
if (bufptr == f->f_bufend)
Util_DropReadAhead(f);
@@ -476,7 +476,7 @@ Util_ReadAheadGetLineSkip(BZ2FileObject *f, int skip, int bufsize)
PyMem_Free(buf);
return NULL;
}
- memcpy(PyString_AS_STRING(s)+skip, bufptr, len);
+ memcpy(PyBytes_AS_STRING(s)+skip, bufptr, len);
PyMem_Free(buf);
}
return s;
@@ -509,7 +509,7 @@ BZ2File_read(BZ2FileObject *self, PyObject *args)
case MODE_READ:
break;
case MODE_READ_EOF:
- ret = PyString_FromString("");
+ ret = PyBytes_FromString("");
goto cleanup;
case MODE_CLOSED:
PyErr_SetString(PyExc_ValueError,
@@ -531,7 +531,7 @@ BZ2File_read(BZ2FileObject *self, PyObject *args)
"more than a Python string can hold");
goto cleanup;
}
- ret = PyString_FromStringAndSize((char *)NULL, buffersize);
+ ret = PyBytes_FromStringAndSize((char *)NULL, buffersize);
if (ret == NULL)
goto cleanup;
bytesread = 0;
@@ -557,14 +557,14 @@ BZ2File_read(BZ2FileObject *self, PyObject *args)
}
if (bytesrequested < 0) {
buffersize = Util_NewBufferSize(buffersize);
- if (_PyString_Resize(&ret, buffersize) < 0)
+ if (_PyBytes_Resize(&ret, buffersize) < 0)
goto cleanup;
} else {
break;
}
}
if (bytesread != buffersize)
- _PyString_Resize(&ret, bytesread);
+ _PyBytes_Resize(&ret, bytesread);
cleanup:
RELEASE_LOCK(self);
@@ -594,7 +594,7 @@ BZ2File_readline(BZ2FileObject *self, PyObject *args)
case MODE_READ:
break;
case MODE_READ_EOF:
- ret = PyString_FromString("");
+ ret = PyBytes_FromString("");
goto cleanup;
case MODE_CLOSED:
PyErr_SetString(PyExc_ValueError,
@@ -607,7 +607,7 @@ BZ2File_readline(BZ2FileObject *self, PyObject *args)
}
if (sizehint == 0)
- ret = PyString_FromString("");
+ ret = PyBytes_FromString("");
else
ret = Util_GetLine(self, (sizehint < 0) ? 0 : sizehint);
@@ -701,17 +701,17 @@ BZ2File_readlines(BZ2FileObject *self, PyObject *args)
}
if (big_buffer == NULL) {
/* Create the big buffer */
- big_buffer = PyString_FromStringAndSize(
+ big_buffer = PyBytes_FromStringAndSize(
NULL, buffersize);
if (big_buffer == NULL)
goto error;
- buffer = PyString_AS_STRING(big_buffer);
+ buffer = PyBytes_AS_STRING(big_buffer);
memcpy(buffer, small_buffer, nfilled);
}
else {
/* Grow the big buffer */
- _PyString_Resize(&big_buffer, buffersize);
- buffer = PyString_AS_STRING(big_buffer);
+ _PyBytes_Resize(&big_buffer, buffersize);
+ buffer = PyBytes_AS_STRING(big_buffer);
}
continue;
}
@@ -720,7 +720,7 @@ BZ2File_readlines(BZ2FileObject *self, PyObject *args)
while (p != NULL) {
/* Process complete lines */
p++;
- line = PyString_FromStringAndSize(q, p-q);
+ line = PyBytes_FromStringAndSize(q, p-q);
if (line == NULL)
goto error;
err = PyList_Append(list, line);
@@ -743,7 +743,7 @@ BZ2File_readlines(BZ2FileObject *self, PyObject *args)
}
if (nfilled != 0) {
/* Partial last line */
- line = PyString_FromStringAndSize(buffer, nfilled);
+ line = PyBytes_FromStringAndSize(buffer, nfilled);
if (line == NULL)
goto error;
if (sizehint > 0) {
@@ -753,7 +753,7 @@ BZ2File_readlines(BZ2FileObject *self, PyObject *args)
Py_DECREF(line);
goto error;
}
- PyString_Concat(&line, rest);
+ PyBytes_Concat(&line, rest);
Py_DECREF(rest);
if (line == NULL)
goto error;
@@ -915,7 +915,7 @@ BZ2File_writelines(BZ2FileObject *self, PyObject *seq)
could potentially execute Python code. */
for (i = 0; i < j; i++) {
PyObject *v = PyList_GET_ITEM(list, i);
- if (!PyString_Check(v)) {
+ if (!PyBytes_Check(v)) {
const char *buffer;
Py_ssize_t len;
if (PyObject_AsCharBuffer(v, &buffer, &len)) {
@@ -926,7 +926,7 @@ BZ2File_writelines(BZ2FileObject *self, PyObject *seq)
"strings");
goto error;
}
- line = PyString_FromStringAndSize(buffer,
+ line = PyBytes_FromStringAndSize(buffer,
len);
if (line == NULL)
goto error;
@@ -942,9 +942,9 @@ BZ2File_writelines(BZ2FileObject *self, PyObject *seq)
Py_BEGIN_ALLOW_THREADS
for (i = 0; i < j; i++) {
line = PyList_GET_ITEM(list, i);
- len = PyString_GET_SIZE(line);
+ len = PyBytes_GET_SIZE(line);
BZ2_bzWrite (&bzerror, self->fp,
- PyString_AS_STRING(line), len);
+ PyBytes_AS_STRING(line), len);
if (bzerror != BZ_OK) {
Py_BLOCK_THREADS
Util_CatchBZ2Error(bzerror);
@@ -1224,13 +1224,13 @@ BZ2File_get_newlines(BZ2FileObject *self, void *closure)
Py_INCREF(Py_None);
return Py_None;
case NEWLINE_CR:
- return PyString_FromString("\r");
+ return PyBytes_FromString("\r");
case NEWLINE_LF:
- return PyString_FromString("\n");
+ return PyBytes_FromString("\n");
case NEWLINE_CR|NEWLINE_LF:
return Py_BuildValue("(ss)", "\r", "\n");
case NEWLINE_CRLF:
- return PyString_FromString("\r\n");
+ return PyBytes_FromString("\r\n");
case NEWLINE_CR|NEWLINE_CRLF:
return Py_BuildValue("(ss)", "\r", "\r\n");
case NEWLINE_LF|NEWLINE_CRLF:
@@ -1448,7 +1448,7 @@ BZ2File_getiter(BZ2FileObject *self)
static PyObject *
BZ2File_iternext(BZ2FileObject *self)
{
- PyStringObject* ret;
+ PyBytesObject* ret;
ACQUIRE_LOCK(self);
if (self->mode == MODE_CLOSED) {
PyErr_SetString(PyExc_ValueError,
@@ -1457,7 +1457,7 @@ BZ2File_iternext(BZ2FileObject *self)
}
ret = Util_ReadAheadGetLineSkip(self, 0, READAHEAD_BUFSIZE);
RELEASE_LOCK(self);
- if (ret == NULL || PyString_GET_SIZE(ret) == 0) {
+ if (ret == NULL || PyBytes_GET_SIZE(ret) == 0) {
Py_XDECREF(ret);
return NULL;
}
@@ -1559,7 +1559,7 @@ BZ2Comp_compress(BZ2CompObject *self, PyObject *args)
return NULL;
if (datasize == 0)
- return PyString_FromString("");
+ return PyBytes_FromString("");
ACQUIRE_LOCK(self);
if (!self->running) {
@@ -1568,7 +1568,7 @@ BZ2Comp_compress(BZ2CompObject *self, PyObject *args)
goto error;
}
- ret = PyString_FromStringAndSize(NULL, bufsize);
+ ret = PyBytes_FromStringAndSize(NULL, bufsize);
if (!ret)
goto error;
@@ -1591,7 +1591,7 @@ BZ2Comp_compress(BZ2CompObject *self, PyObject *args)
break; /* no more input data */
if (bzs->avail_out == 0) {
bufsize = Util_NewBufferSize(bufsize);
- if (_PyString_Resize(&ret, bufsize) < 0) {
+ if (_PyBytes_Resize(&ret, bufsize) < 0) {
BZ2_bzCompressEnd(bzs);
goto error;
}
@@ -1601,7 +1601,7 @@ BZ2Comp_compress(BZ2CompObject *self, PyObject *args)
}
}
- _PyString_Resize(&ret, (Py_ssize_t)(BZS_TOTAL_OUT(bzs) - totalout));
+ _PyBytes_Resize(&ret, (Py_ssize_t)(BZS_TOTAL_OUT(bzs) - totalout));
RELEASE_LOCK(self);
return ret;
@@ -1636,7 +1636,7 @@ BZ2Comp_flush(BZ2CompObject *self)
}
self->running = 0;
- ret = PyString_FromStringAndSize(NULL, bufsize);
+ ret = PyBytes_FromStringAndSize(NULL, bufsize);
if (!ret)
goto error;
@@ -1657,7 +1657,7 @@ BZ2Comp_flush(BZ2CompObject *self)
}
if (bzs->avail_out == 0) {
bufsize = Util_NewBufferSize(bufsize);
- if (_PyString_Resize(&ret, bufsize) < 0)
+ if (_PyBytes_Resize(&ret, bufsize) < 0)
goto error;
bzs->next_out = BUF(ret);
bzs->next_out = BUF(ret) + (BZS_TOTAL_OUT(bzs)
@@ -1667,7 +1667,7 @@ BZ2Comp_flush(BZ2CompObject *self)
}
if (bzs->avail_out != 0)
- _PyString_Resize(&ret, (Py_ssize_t)(BZS_TOTAL_OUT(bzs) - totalout));
+ _PyBytes_Resize(&ret, (Py_ssize_t)(BZS_TOTAL_OUT(bzs) - totalout));
RELEASE_LOCK(self);
return ret;
@@ -1849,7 +1849,7 @@ BZ2Decomp_decompress(BZ2DecompObject *self, PyObject *args)
goto error;
}
- ret = PyString_FromStringAndSize(NULL, bufsize);
+ ret = PyBytes_FromStringAndSize(NULL, bufsize);
if (!ret)
goto error;
@@ -1868,7 +1868,7 @@ BZ2Decomp_decompress(BZ2DecompObject *self, PyObject *args)
if (bzs->avail_in != 0) {
Py_DECREF(self->unused_data);
self->unused_data =
- PyString_FromStringAndSize(bzs->next_in,
+ PyBytes_FromStringAndSize(bzs->next_in,
bzs->avail_in);
}
self->running = 0;
@@ -1882,7 +1882,7 @@ BZ2Decomp_decompress(BZ2DecompObject *self, PyObject *args)
break; /* no more input data */
if (bzs->avail_out == 0) {
bufsize = Util_NewBufferSize(bufsize);
- if (_PyString_Resize(&ret, bufsize) < 0) {
+ if (_PyBytes_Resize(&ret, bufsize) < 0) {
BZ2_bzDecompressEnd(bzs);
goto error;
}
@@ -1894,7 +1894,7 @@ BZ2Decomp_decompress(BZ2DecompObject *self, PyObject *args)
}
if (bzs->avail_out != 0)
- _PyString_Resize(&ret, (Py_ssize_t)(BZS_TOTAL_OUT(bzs) - totalout));
+ _PyBytes_Resize(&ret, (Py_ssize_t)(BZS_TOTAL_OUT(bzs) - totalout));
RELEASE_LOCK(self);
return ret;
@@ -1930,7 +1930,7 @@ BZ2Decomp_init(BZ2DecompObject *self, PyObject *args, PyObject *kwargs)
}
#endif
- self->unused_data = PyString_FromString("");
+ self->unused_data = PyBytes_FromString("");
if (!self->unused_data)
goto error;
@@ -2063,7 +2063,7 @@ bz2_compress(PyObject *self, PyObject *args, PyObject *kwargs)
* data in one shot. We will check it later anyway. */
bufsize = datasize + (datasize/100+1) + 600;
- ret = PyString_FromStringAndSize(NULL, bufsize);
+ ret = PyBytes_FromStringAndSize(NULL, bufsize);
if (!ret)
return NULL;
@@ -2095,7 +2095,7 @@ bz2_compress(PyObject *self, PyObject *args, PyObject *kwargs)
}
if (bzs->avail_out == 0) {
bufsize = Util_NewBufferSize(bufsize);
- if (_PyString_Resize(&ret, bufsize) < 0) {
+ if (_PyBytes_Resize(&ret, bufsize) < 0) {
BZ2_bzCompressEnd(bzs);
Py_DECREF(ret);
return NULL;
@@ -2106,7 +2106,7 @@ bz2_compress(PyObject *self, PyObject *args, PyObject *kwargs)
}
if (bzs->avail_out != 0)
- _PyString_Resize(&ret, (Py_ssize_t)BZS_TOTAL_OUT(bzs));
+ _PyBytes_Resize(&ret, (Py_ssize_t)BZS_TOTAL_OUT(bzs));
BZ2_bzCompressEnd(bzs);
return ret;
@@ -2134,9 +2134,9 @@ bz2_decompress(PyObject *self, PyObject *args)
return NULL;
if (datasize == 0)
- return PyString_FromString("");
+ return PyBytes_FromString("");
- ret = PyString_FromStringAndSize(NULL, bufsize);
+ ret = PyBytes_FromStringAndSize(NULL, bufsize);
if (!ret)
return NULL;
@@ -2175,7 +2175,7 @@ bz2_decompress(PyObject *self, PyObject *args)
}
if (bzs->avail_out == 0) {
bufsize = Util_NewBufferSize(bufsize);
- if (_PyString_Resize(&ret, bufsize) < 0) {
+ if (_PyBytes_Resize(&ret, bufsize) < 0) {
BZ2_bzDecompressEnd(bzs);
Py_DECREF(ret);
return NULL;
@@ -2186,7 +2186,7 @@ bz2_decompress(PyObject *self, PyObject *args)
}
if (bzs->avail_out != 0)
- _PyString_Resize(&ret, (Py_ssize_t)BZS_TOTAL_OUT(bzs));
+ _PyBytes_Resize(&ret, (Py_ssize_t)BZS_TOTAL_OUT(bzs));
BZ2_bzDecompressEnd(bzs);
return ret;
@@ -2223,7 +2223,7 @@ initbz2(void)
if (m == NULL)
return;
- PyModule_AddObject(m, "__author__", PyString_FromString(__author__));
+ PyModule_AddObject(m, "__author__", PyBytes_FromString(__author__));
Py_INCREF(&BZ2File_Type);
PyModule_AddObject(m, "BZ2File", (PyObject *)&BZ2File_Type);
diff --git a/Modules/cPickle.c b/Modules/cPickle.c
index f13008783e..4413272be5 100644
--- a/Modules/cPickle.c
+++ b/Modules/cPickle.c
@@ -393,13 +393,13 @@ cPickle_ErrFormat(PyObject *ErrType, char *stringformat, char *format, ...)
if (format) args = Py_VaBuildValue(format, va);
va_end(va);
if (format && ! args) return NULL;
- if (stringformat && !(retval=PyString_FromString(stringformat)))
+ if (stringformat && !(retval=PyBytes_FromString(stringformat)))
return NULL;
if (retval) {
if (args) {
PyObject *v;
- v=PyString_Format(retval, args);
+ v=PyBytes_Format(retval, args);
Py_DECREF(retval);
Py_DECREF(args);
if (! v) return NULL;
@@ -477,7 +477,7 @@ write_other(Picklerobject *self, const char *s, Py_ssize_t _n)
n = (int)_n;
if (s == NULL) {
if (!( self->buf_size )) return 0;
- py_str = PyString_FromStringAndSize(self->write_buf,
+ py_str = PyBytes_FromStringAndSize(self->write_buf,
self->buf_size);
if (!py_str)
return -1;
@@ -490,7 +490,7 @@ write_other(Picklerobject *self, const char *s, Py_ssize_t _n)
if (n > WRITE_BUF_SIZE) {
if (!( py_str =
- PyString_FromStringAndSize(s, n)))
+ PyBytes_FromStringAndSize(s, n)))
return -1;
}
else {
@@ -655,7 +655,7 @@ read_other(Unpicklerobject *self, char **s, Py_ssize_t n)
Py_XDECREF(self->last_string);
self->last_string = str;
- if (! (*s = PyString_AsString(str))) return -1;
+ if (! (*s = PyBytes_AsString(str))) return -1;
return n;
}
@@ -670,13 +670,13 @@ readline_other(Unpicklerobject *self, char **s)
return -1;
}
- if ((str_size = PyString_Size(str)) < 0)
+ if ((str_size = PyBytes_Size(str)) < 0)
return -1;
Py_XDECREF(self->last_string);
self->last_string = str;
- if (! (*s = PyString_AsString(str)))
+ if (! (*s = PyBytes_AsString(str)))
return -1;
return str_size;
@@ -1078,9 +1078,9 @@ save_long(Picklerobject *self, PyObject *args)
"to pickle");
goto finally;
}
- repr = PyString_FromStringAndSize(NULL, (int)nbytes);
+ repr = PyBytes_FromStringAndSize(NULL, (int)nbytes);
if (repr == NULL) goto finally;
- pdata = (unsigned char *)PyString_AS_STRING(repr);
+ pdata = (unsigned char *)PyBytes_AS_STRING(repr);
i = _PyLong_AsByteArray((PyLongObject *)args,
pdata, nbytes,
1 /* little endian */, 1 /* signed */);
@@ -1121,14 +1121,14 @@ save_long(Picklerobject *self, PyObject *args)
if (!( repr = PyObject_Repr(args)))
goto finally;
- if ((size = PyString_Size(repr)) < 0)
+ if ((size = PyBytes_Size(repr)) < 0)
goto finally;
if (self->write_func(self, &l, 1) < 0)
goto finally;
if (self->write_func(self,
- PyString_AS_STRING((PyStringObject *)repr),
+ PyBytes_AS_STRING((PyBytesObject *)repr),
size) < 0)
goto finally;
@@ -1177,7 +1177,7 @@ save_string(Picklerobject *self, PyObject *args, int doput)
int size, len;
PyObject *repr=0;
- if ((size = PyString_Size(args)) < 0)
+ if ((size = PyBytes_Size(args)) < 0)
return -1;
if (!self->bin) {
@@ -1188,9 +1188,9 @@ save_string(Picklerobject *self, PyObject *args, int doput)
if (!( repr = PyObject_Repr(args)))
return -1;
- if ((len = PyString_Size(repr)) < 0)
+ if ((len = PyBytes_Size(repr)) < 0)
goto err;
- repr_str = PyString_AS_STRING((PyStringObject *)repr);
+ repr_str = PyBytes_AS_STRING((PyBytesObject *)repr);
if (self->write_func(self, &string, 1) < 0)
goto err;
@@ -1207,7 +1207,7 @@ save_string(Picklerobject *self, PyObject *args, int doput)
int i;
char c_str[5];
- if ((size = PyString_Size(args)) < 0)
+ if ((size = PyBytes_Size(args)) < 0)
return -1;
if (size < 256) {
@@ -1233,8 +1233,8 @@ save_string(Picklerobject *self, PyObject *args, int doput)
}
else {
if (self->write_func(self,
- PyString_AS_STRING(
- (PyStringObject *)args),
+ PyBytes_AS_STRING(
+ (PyBytesObject *)args),
size) < 0)
return -1;
}
@@ -1264,13 +1264,13 @@ modified_EncodeRawUnicodeEscape(const Py_UNICODE *s, int size)
static const char *hexdigit = "0123456789ABCDEF";
- repr = PyString_FromStringAndSize(NULL, 6 * size);
+ repr = PyBytes_FromStringAndSize(NULL, 6 * size);
if (repr == NULL)
return NULL;
if (size == 0)
return repr;
- p = q = PyString_AS_STRING(repr);
+ p = q = PyBytes_AS_STRING(repr);
while (size-- > 0) {
Py_UNICODE ch = *s++;
/* Map 16-bit characters to '\uxxxx' */
@@ -1287,7 +1287,7 @@ modified_EncodeRawUnicodeEscape(const Py_UNICODE *s, int size)
*p++ = (char) ch;
}
*p = '\0';
- _PyString_Resize(&repr, p - q);
+ _PyBytes_Resize(&repr, p - q);
return repr;
}
@@ -1310,9 +1310,9 @@ save_unicode(Picklerobject *self, PyObject *args, int doput)
if (!repr)
return -1;
- if ((len = PyString_Size(repr)) < 0)
+ if ((len = PyBytes_Size(repr)) < 0)
goto err;
- repr_str = PyString_AS_STRING((PyStringObject *)repr);
+ repr_str = PyBytes_AS_STRING((PyBytesObject *)repr);
if (self->write_func(self, &string, 1) < 0)
goto err;
@@ -1332,7 +1332,7 @@ save_unicode(Picklerobject *self, PyObject *args, int doput)
if (!( repr = PyUnicode_AsUTF8String(args)))
return -1;
- if ((size = PyString_Size(repr)) < 0)
+ if ((size = PyBytes_Size(repr)) < 0)
goto err;
if (size > INT_MAX)
return -1; /* string too large */
@@ -1351,7 +1351,7 @@ save_unicode(Picklerobject *self, PyObject *args, int doput)
PDATA_APPEND(self->file, repr, -1);
}
else {
- if (self->write_func(self, PyString_AS_STRING(repr),
+ if (self->write_func(self, PyBytes_AS_STRING(repr),
size) < 0)
goto err;
}
@@ -1861,12 +1861,12 @@ save_inst(Picklerobject *self, PyObject *args)
goto finally;
- if ((module_size = PyString_Size(module)) < 0 ||
- (name_size = PyString_Size(name)) < 0)
+ if ((module_size = PyBytes_Size(module)) < 0 ||
+ (name_size = PyBytes_Size(name)) < 0)
goto finally;
- module_str = PyString_AS_STRING((PyStringObject *)module);
- name_str = PyString_AS_STRING((PyStringObject *)name);
+ module_str = PyBytes_AS_STRING((PyBytesObject *)module);
+ name_str = PyBytes_AS_STRING((PyBytesObject *)name);
if (self->write_func(self, &inst, 1) < 0)
goto finally;
@@ -1961,12 +1961,12 @@ save_global(Picklerobject *self, PyObject *args, PyObject *name)
if (!( module = whichmodule(args, global_name)))
goto finally;
- if ((module_size = PyString_Size(module)) < 0 ||
- (name_size = PyString_Size(global_name)) < 0)
+ if ((module_size = PyBytes_Size(module)) < 0 ||
+ (name_size = PyBytes_Size(global_name)) < 0)
goto finally;
- module_str = PyString_AS_STRING((PyStringObject *)module);
- name_str = PyString_AS_STRING((PyStringObject *)global_name);
+ module_str = PyBytes_AS_STRING((PyBytesObject *)module);
+ name_str = PyBytes_AS_STRING((PyBytesObject *)global_name);
/* XXX This can be doing a relative import. Clearly it shouldn't,
but I don't know how to stop it. :-( */
@@ -2099,7 +2099,7 @@ save_pers(Picklerobject *self, PyObject *args, PyObject *f)
if (pid != Py_None) {
if (!self->bin) {
- if (!PyString_Check(pid)) {
+ if (!PyBytes_Check(pid)) {
PyErr_SetString(PicklingError,
"persistent id must be string");
goto finally;
@@ -2108,12 +2108,12 @@ save_pers(Picklerobject *self, PyObject *args, PyObject *f)
if (self->write_func(self, &persid, 1) < 0)
goto finally;
- if ((size = PyString_Size(pid)) < 0)
+ if ((size = PyBytes_Size(pid)) < 0)
goto finally;
if (self->write_func(self,
- PyString_AS_STRING(
- (PyStringObject *)pid),
+ PyBytes_AS_STRING(
+ (PyBytesObject *)pid),
size) < 0)
goto finally;
@@ -2194,8 +2194,8 @@ save_reduce(Picklerobject *self, PyObject *args, PyObject *ob)
use_newobj = 0;
}
else {
- use_newobj = PyString_Check(temp) &&
- strcmp(PyString_AS_STRING(temp),
+ use_newobj = PyBytes_Check(temp) &&
+ strcmp(PyBytes_AS_STRING(temp),
"__newobj__") == 0;
Py_DECREF(temp);
}
@@ -2362,14 +2362,14 @@ save(Picklerobject *self, PyObject *args, int pers_save)
break;
case 's':
- if ((type == &PyString_Type) && (PyString_GET_SIZE(args) < 2)) {
+ if ((type == &PyBytes_Type) && (PyBytes_GET_SIZE(args) < 2)) {
res = save_string(self, args, 0);
goto finally;
}
#ifdef Py_USING_UNICODE
case 'u':
- if ((type == &PyUnicode_Type) && (PyString_GET_SIZE(args) < 2)) {
+ if ((type == &PyUnicode_Type) && (PyBytes_GET_SIZE(args) < 2)) {
res = save_unicode(self, args, 0);
goto finally;
}
@@ -2391,7 +2391,7 @@ save(Picklerobject *self, PyObject *args, int pers_save)
switch (type->tp_name[0]) {
case 's':
- if (type == &PyString_Type) {
+ if (type == &PyBytes_Type) {
res = save_string(self, args, 1);
goto finally;
}
@@ -2526,7 +2526,7 @@ save(Picklerobject *self, PyObject *args, int pers_save)
if (t == NULL)
goto finally;
- if (PyString_Check(t)) {
+ if (PyBytes_Check(t)) {
res = save_global(self, args, t);
goto finally;
}
@@ -2640,8 +2640,8 @@ Pickle_getvalue(Picklerobject *self, PyObject *args)
for (rsize = 0, i = l; --i >= 0; ) {
k = data->data[i];
- if (PyString_Check(k))
- rsize += PyString_GET_SIZE(k);
+ if (PyBytes_Check(k))
+ rsize += PyBytes_GET_SIZE(k);
else if (PyInt_Check(k)) { /* put */
ik = PyInt_AS_LONG((PyIntObject*)k);
@@ -2676,17 +2676,17 @@ Pickle_getvalue(Picklerobject *self, PyObject *args)
}
/* Now generate the result */
- r = PyString_FromStringAndSize(NULL, rsize);
+ r = PyBytes_FromStringAndSize(NULL, rsize);
if (r == NULL) goto err;
- s = PyString_AS_STRING((PyStringObject *)r);
+ s = PyBytes_AS_STRING((PyBytesObject *)r);
for (i = 0; i < l; i++) {
k = data->data[i];
- if (PyString_Check(k)) {
- ssize = PyString_GET_SIZE(k);
+ if (PyBytes_Check(k)) {
+ ssize = PyBytes_GET_SIZE(k);
if (ssize) {
- p=PyString_AS_STRING((PyStringObject *)k);
+ p=PyBytes_AS_STRING((PyBytesObject *)k);
while (--ssize >= 0)
*s++ = *p++;
}
@@ -3410,7 +3410,7 @@ load_string(Unpicklerobject *self)
goto insecure;
/********************************************/
- str = PyString_DecodeEscape(p, len, NULL, 0, NULL);
+ str = PyBytes_DecodeEscape(p, len, NULL, 0, NULL);
free(s);
if (str) {
PDATA_PUSH(self->stack, str, -1);
@@ -3439,7 +3439,7 @@ load_binstring(Unpicklerobject *self)
if (self->read_func(self, &s, l) < 0)
return -1;
- if (!( py_string = PyString_FromStringAndSize(s, l)))
+ if (!( py_string = PyBytes_FromStringAndSize(s, l)))
return -1;
PDATA_PUSH(self->stack, py_string, -1);
@@ -3461,7 +3461,7 @@ load_short_binstring(Unpicklerobject *self)
if (self->read_func(self, &s, l) < 0) return -1;
- if (!( py_string = PyString_FromStringAndSize(s, l))) return -1;
+ if (!( py_string = PyBytes_FromStringAndSize(s, l))) return -1;
PDATA_PUSH(self->stack, py_string, -1);
return 0;
@@ -3688,12 +3688,12 @@ load_inst(Unpicklerobject *self)
if ((len = self->readline_func(self, &s)) < 0) return -1;
if (len < 2) return bad_readline();
- module_name = PyString_FromStringAndSize(s, len - 1);
+ module_name = PyBytes_FromStringAndSize(s, len - 1);
if (!module_name) return -1;
if ((len = self->readline_func(self, &s)) >= 0) {
if (len < 2) return bad_readline();
- if ((class_name = PyString_FromStringAndSize(s, len - 1))) {
+ if ((class_name = PyBytes_FromStringAndSize(s, len - 1))) {
class = find_class(module_name, class_name,
self->find_class);
Py_DECREF(class_name);
@@ -3772,7 +3772,7 @@ load_global(Unpicklerobject *self)
if ((len = self->readline_func(self, &s)) < 0) return -1;
if (len < 2) return bad_readline();
- module_name = PyString_FromStringAndSize(s, len - 1);
+ module_name = PyBytes_FromStringAndSize(s, len - 1);
if (!module_name) return -1;
if ((len = self->readline_func(self, &s)) >= 0) {
@@ -3780,7 +3780,7 @@ load_global(Unpicklerobject *self)
Py_DECREF(module_name);
return bad_readline();
}
- if ((class_name = PyString_FromStringAndSize(s, len - 1))) {
+ if ((class_name = PyBytes_FromStringAndSize(s, len - 1))) {
class = find_class(module_name, class_name,
self->find_class);
Py_DECREF(class_name);
@@ -3805,7 +3805,7 @@ load_persid(Unpicklerobject *self)
if ((len = self->readline_func(self, &s)) < 0) return -1;
if (len < 2) return bad_readline();
- pid = PyString_FromStringAndSize(s, len - 1);
+ pid = PyBytes_FromStringAndSize(s, len - 1);
if (!pid) return -1;
if (PyList_Check(self->pers_func)) {
@@ -3938,7 +3938,7 @@ load_get(Unpicklerobject *self)
if ((len = self->readline_func(self, &s)) < 0) return -1;
if (len < 2) return bad_readline();
- if (!( py_str = PyString_FromStringAndSize(s, len - 1))) return -1;
+ if (!( py_str = PyBytes_FromStringAndSize(s, len - 1))) return -1;
value = PyDict_GetItem(self->memo, py_str);
if (! value) {
@@ -4064,8 +4064,8 @@ load_extension(Unpicklerobject *self, int nbytes)
* confirm that pair is really a 2-tuple of strings.
*/
if (!PyTuple_Check(pair) || PyTuple_Size(pair) != 2 ||
- !PyString_Check(module_name = PyTuple_GET_ITEM(pair, 0)) ||
- !PyString_Check(class_name = PyTuple_GET_ITEM(pair, 1))) {
+ !PyBytes_Check(module_name = PyTuple_GET_ITEM(pair, 0)) ||
+ !PyBytes_Check(class_name = PyTuple_GET_ITEM(pair, 1))) {
Py_DECREF(py_code);
PyErr_Format(PyExc_ValueError, "_inverted_registry[%ld] "
"isn't a 2-tuple of strings", code);
@@ -4098,7 +4098,7 @@ load_put(Unpicklerobject *self)
if ((l = self->readline_func(self, &s)) < 0) return -1;
if (l < 2) return bad_readline();
if (!( len=self->stack->length )) return stackUnderflow();
- if (!( py_str = PyString_FromStringAndSize(s, l - 1))) return -1;
+ if (!( py_str = PyBytes_FromStringAndSize(s, l - 1))) return -1;
value=self->stack->data[len-1];
l=PyDict_SetItem(self->memo, py_str, value);
Py_DECREF(py_str);
@@ -5568,7 +5568,7 @@ init_stuff(PyObject *module_dict)
{
PyObject *copyreg, *t, *r;
-#define INIT_STR(S) if (!( S ## _str=PyString_InternFromString(#S))) return -1;
+#define INIT_STR(S) if (!( S ## _str=PyBytes_InternFromString(#S))) return -1;
if (PyType_Ready(&Unpicklertype) < 0)
return -1;
@@ -5736,7 +5736,7 @@ initcPickle(void)
/* Add some symbolic constants to the module */
d = PyModule_GetDict(m);
- v = PyString_FromString(rev);
+ v = PyBytes_FromString(rev);
PyDict_SetItemString(d, "__version__", v);
Py_XDECREF(v);
@@ -5755,7 +5755,7 @@ initcPickle(void)
/* These are purely informational; no code uses them. */
/* File format version we write. */
- format_version = PyString_FromString("2.0");
+ format_version = PyBytes_FromString("2.0");
/* Format versions we can read. */
compatible_formats = Py_BuildValue("[sssss]",
"1.0", /* Original protocol 0 */
diff --git a/Modules/cStringIO.c b/Modules/cStringIO.c
index 139a4a8391..576a17622d 100644
--- a/Modules/cStringIO.c
+++ b/Modules/cStringIO.c
@@ -119,7 +119,7 @@ PyDoc_STRVAR(IO_getval__doc__,
static PyObject *
IO_cgetval(PyObject *self) {
if (!IO__opencheck(IOOOBJECT(self))) return NULL;
- return PyString_FromStringAndSize(((IOobject*)self)->buf,
+ return PyBytes_FromStringAndSize(((IOobject*)self)->buf,
((IOobject*)self)->pos);
}
@@ -137,7 +137,7 @@ IO_getval(IOobject *self, PyObject *args) {
}
else
s=self->string_size;
- return PyString_FromStringAndSize(self->buf, s);
+ return PyBytes_FromStringAndSize(self->buf, s);
}
PyDoc_STRVAR(IO_isatty__doc__, "isatty(): always returns 0");
@@ -177,7 +177,7 @@ IO_read(IOobject *self, PyObject *args) {
if ( (n=IO_cread((PyObject*)self,&output,n)) < 0) return NULL;
- return PyString_FromStringAndSize(output, n);
+ return PyBytes_FromStringAndSize(output, n);
}
PyDoc_STRVAR(IO_readline__doc__, "readline() -- Read one line");
@@ -215,7 +215,7 @@ IO_readline(IOobject *self, PyObject *args) {
n -= m;
self->pos -= m;
}
- return PyString_FromStringAndSize(output, n);
+ return PyBytes_FromStringAndSize(output, n);
}
PyDoc_STRVAR(IO_readlines__doc__, "readlines() -- Read all lines");
@@ -238,7 +238,7 @@ IO_readlines(IOobject *self, PyObject *args) {
goto err;
if (n == 0)
break;
- line = PyString_FromStringAndSize (output, n);
+ line = PyBytes_FromStringAndSize (output, n);
if (!line)
goto err;
if (PyList_Append (result, line) == -1) {
@@ -315,7 +315,7 @@ IO_iternext(Iobject *self)
next = IO_readline((IOobject *)self, NULL);
if (!next)
return NULL;
- if (!PyString_GET_SIZE(next)) {
+ if (!PyBytes_GET_SIZE(next)) {
Py_DECREF(next);
PyErr_SetNone(PyExc_StopIteration);
return NULL;
@@ -456,7 +456,7 @@ O_writelines(Oobject *self, PyObject *args) {
while ((s = PyIter_Next(it)) != NULL) {
Py_ssize_t n;
char *c;
- if (PyString_AsStringAndSize(s, &c, &n) == -1) {
+ if (PyBytes_AsStringAndSize(s, &c, &n) == -1) {
Py_DECREF(it);
Py_DECREF(s);
return NULL;
diff --git a/Modules/cdmodule.c b/Modules/cdmodule.c
index f09b0a4adf..8602d5dfb4 100644
--- a/Modules/cdmodule.c
+++ b/Modules/cdmodule.c
@@ -239,19 +239,19 @@ CD_readda(cdplayerobject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "i:readda", &numframes))
return NULL;
- result = PyString_FromStringAndSize(NULL, numframes * sizeof(CDFRAME));
+ result = PyBytes_FromStringAndSize(NULL, numframes * sizeof(CDFRAME));
if (result == NULL)
return NULL;
n = CDreadda(self->ob_cdplayer,
- (CDFRAME *) PyString_AsString(result), numframes);
+ (CDFRAME *) PyBytes_AsString(result), numframes);
if (n == -1) {
Py_DECREF(result);
PyErr_SetFromErrno(CdError);
return NULL;
}
if (n < numframes)
- _PyString_Resize(&result, n * sizeof(CDFRAME));
+ _PyBytes_Resize(&result, n * sizeof(CDFRAME));
return result;
}
@@ -468,7 +468,7 @@ CD_callback(void *arg, CDDATATYPES type, void *data)
PyTuple_SetItem(args, 1, PyInt_FromLong((long) type));
switch (type) {
case cd_audio:
- v = PyString_FromStringAndSize(data, CDDA_DATASIZE);
+ v = PyBytes_FromStringAndSize(data, CDDA_DATASIZE);
break;
case cd_pnum:
case cd_index:
@@ -484,15 +484,15 @@ CD_callback(void *arg, CDDATATYPES type, void *data)
#undef ptr
break;
case cd_catalog:
- v = PyString_FromStringAndSize(NULL, 13);
- p = PyString_AsString(v);
+ v = PyBytes_FromStringAndSize(NULL, 13);
+ p = PyBytes_AsString(v);
for (i = 0; i < 13; i++)
*p++ = ((char *) data)[i] + '0';
break;
case cd_ident:
#define ptr ((struct cdident *) data)
- v = PyString_FromStringAndSize(NULL, 12);
- p = PyString_AsString(v);
+ v = PyBytes_FromStringAndSize(NULL, 12);
+ p = PyBytes_AsString(v);
CDsbtoa(p, ptr->country, 2);
p += 2;
CDsbtoa(p, ptr->owner, 3);
diff --git a/Modules/cgensupport.c b/Modules/cgensupport.c
index 7e7d0ff9f4..965f7b427b 100644
--- a/Modules/cgensupport.c
+++ b/Modules/cgensupport.c
@@ -119,10 +119,10 @@ PyArg_GetString(PyObject *args, int nargs, int i, string *p_arg)
PyObject *v;
if (!PyArg_GetObject(args, nargs, i, &v))
return 0;
- if (!PyString_Check(v)) {
+ if (!PyBytes_Check(v)) {
return PyErr_BadArgument();
}
- *p_arg = PyString_AsString(v);
+ *p_arg = PyBytes_AsString(v);
return 1;
}
diff --git a/Modules/cjkcodecs/cjkcodecs.h b/Modules/cjkcodecs/cjkcodecs.h
index 4005bcfe34..c06319ec5a 100644
--- a/Modules/cjkcodecs/cjkcodecs.h
+++ b/Modules/cjkcodecs/cjkcodecs.h
@@ -261,7 +261,7 @@ getcodec(PyObject *self, PyObject *encoding)
const MultibyteCodec *codec;
const char *enc;
- if (!PyString_Check(encoding)) {
+ if (!PyBytes_Check(encoding)) {
PyErr_SetString(PyExc_TypeError,
"encoding name must be a string.");
return NULL;
@@ -271,7 +271,7 @@ getcodec(PyObject *self, PyObject *encoding)
if (cofunc == NULL)
return NULL;
- enc = PyString_AS_STRING(encoding);
+ enc = PyBytes_AS_STRING(encoding);
for (codec = codec_list; codec->encoding[0]; codec++)
if (strcmp(codec->encoding, enc) == 0)
break;
diff --git a/Modules/cjkcodecs/multibytecodec.c b/Modules/cjkcodecs/multibytecodec.c
index bbd4c1a04c..e70ec53516 100644
--- a/Modules/cjkcodecs/multibytecodec.c
+++ b/Modules/cjkcodecs/multibytecodec.c
@@ -85,7 +85,7 @@ internal_error_callback(const char *errors)
else if (strcmp(errors, "replace") == 0)
return ERROR_REPLACE;
else
- return PyString_FromString(errors);
+ return PyBytes_FromString(errors);
}
static PyObject *
@@ -93,8 +93,8 @@ call_error_callback(PyObject *errors, PyObject *exc)
{
PyObject *args, *cb, *r;
- assert(PyString_Check(errors));
- cb = PyCodec_LookupError(PyString_AS_STRING(errors));
+ assert(PyBytes_Check(errors));
+ cb = PyCodec_LookupError(PyBytes_AS_STRING(errors));
if (cb == NULL)
return NULL;
@@ -129,7 +129,7 @@ codecctx_errors_get(MultibyteStatefulCodecContext *self)
return self->errors;
}
- return PyString_FromString(errors);
+ return PyBytes_FromString(errors);
}
static int
@@ -138,12 +138,12 @@ codecctx_errors_set(MultibyteStatefulCodecContext *self, PyObject *value,
{
PyObject *cb;
- if (!PyString_Check(value)) {
+ if (!PyBytes_Check(value)) {
PyErr_SetString(PyExc_TypeError, "errors must be a string");
return -1;
}
- cb = internal_error_callback(PyString_AS_STRING(value));
+ cb = internal_error_callback(PyBytes_AS_STRING(value));
if (cb == NULL)
return -1;
@@ -166,15 +166,15 @@ expand_encodebuffer(MultibyteEncodeBuffer *buf, Py_ssize_t esize)
Py_ssize_t orgpos, orgsize;
orgpos = (Py_ssize_t)((char *)buf->outbuf -
- PyString_AS_STRING(buf->outobj));
- orgsize = PyString_GET_SIZE(buf->outobj);
- if (_PyString_Resize(&buf->outobj, orgsize + (
+ PyBytes_AS_STRING(buf->outobj));
+ orgsize = PyBytes_GET_SIZE(buf->outobj);
+ if (_PyBytes_Resize(&buf->outobj, orgsize + (
esize < (orgsize >> 1) ? (orgsize >> 1) | 1 : esize)) == -1)
return -1;
- buf->outbuf = (unsigned char *)PyString_AS_STRING(buf->outobj) +orgpos;
- buf->outbuf_end = (unsigned char *)PyString_AS_STRING(buf->outobj)
- + PyString_GET_SIZE(buf->outobj);
+ buf->outbuf = (unsigned char *)PyBytes_AS_STRING(buf->outobj) +orgpos;
+ buf->outbuf_end = (unsigned char *)PyBytes_AS_STRING(buf->outobj)
+ + PyBytes_GET_SIZE(buf->outobj);
return 0;
}
@@ -322,10 +322,10 @@ multibytecodec_encerror(MultibyteCodec *codec,
goto errorexit;
}
- retstrsize = PyString_GET_SIZE(retstr);
+ retstrsize = PyBytes_GET_SIZE(retstr);
REQUIRE_ENCODEBUFFER(buf, retstrsize);
- memcpy(buf->outbuf, PyString_AS_STRING(retstr), retstrsize);
+ memcpy(buf->outbuf, PyBytes_AS_STRING(retstr), retstrsize);
buf->outbuf += retstrsize;
newpos = PyInt_AsSsize_t(PyTuple_GET_ITEM(retobj, 1));
@@ -468,16 +468,16 @@ multibytecodec_encode(MultibyteCodec *codec,
Py_ssize_t finalsize, r = 0;
if (datalen == 0)
- return PyString_FromString("");
+ return PyBytes_FromString("");
buf.excobj = NULL;
buf.inbuf = buf.inbuf_top = *data;
buf.inbuf_end = buf.inbuf_top + datalen;
- buf.outobj = PyString_FromStringAndSize(NULL, datalen * 2 + 16);
+ buf.outobj = PyBytes_FromStringAndSize(NULL, datalen * 2 + 16);
if (buf.outobj == NULL)
goto errorexit;
- buf.outbuf = (unsigned char *)PyString_AS_STRING(buf.outobj);
- buf.outbuf_end = buf.outbuf + PyString_GET_SIZE(buf.outobj);
+ buf.outbuf = (unsigned char *)PyBytes_AS_STRING(buf.outobj);
+ buf.outbuf_end = buf.outbuf + PyBytes_GET_SIZE(buf.outobj);
while (buf.inbuf < buf.inbuf_end) {
Py_ssize_t inleft, outleft;
@@ -512,10 +512,10 @@ multibytecodec_encode(MultibyteCodec *codec,
}
finalsize = (Py_ssize_t)((char *)buf.outbuf -
- PyString_AS_STRING(buf.outobj));
+ PyBytes_AS_STRING(buf.outobj));
- if (finalsize != PyString_GET_SIZE(buf.outobj))
- if (_PyString_Resize(&buf.outobj, finalsize) == -1)
+ if (finalsize != PyBytes_GET_SIZE(buf.outobj))
+ if (_PyBytes_Resize(&buf.outobj, finalsize) == -1)
goto errorexit;
Py_XDECREF(buf.excobj);
@@ -1222,35 +1222,35 @@ mbstreamreader_iread(MultibyteStreamReaderObject *self,
if (cres == NULL)
goto errorexit;
- if (!PyString_Check(cres)) {
+ if (!PyBytes_Check(cres)) {
PyErr_SetString(PyExc_TypeError,
"stream function returned a "
"non-string object");
goto errorexit;
}
- endoffile = (PyString_GET_SIZE(cres) == 0);
+ endoffile = (PyBytes_GET_SIZE(cres) == 0);
if (self->pendingsize > 0) {
PyObject *ctr;
char *ctrdata;
- rsize = PyString_GET_SIZE(cres) + self->pendingsize;
- ctr = PyString_FromStringAndSize(NULL, rsize);
+ rsize = PyBytes_GET_SIZE(cres) + self->pendingsize;
+ ctr = PyBytes_FromStringAndSize(NULL, rsize);
if (ctr == NULL)
goto errorexit;
- ctrdata = PyString_AS_STRING(ctr);
+ ctrdata = PyBytes_AS_STRING(ctr);
memcpy(ctrdata, self->pending, self->pendingsize);
memcpy(ctrdata + self->pendingsize,
- PyString_AS_STRING(cres),
- PyString_GET_SIZE(cres));
+ PyBytes_AS_STRING(cres),
+ PyBytes_GET_SIZE(cres));
Py_DECREF(cres);
cres = ctr;
self->pendingsize = 0;
}
- rsize = PyString_GET_SIZE(cres);
- if (decoder_prepare_buffer(&buf, PyString_AS_STRING(cres),
+ rsize = PyBytes_GET_SIZE(cres);
+ if (decoder_prepare_buffer(&buf, PyBytes_AS_STRING(cres),
rsize) != 0)
goto errorexit;
@@ -1585,7 +1585,7 @@ mbstreamwriter_reset(MultibyteStreamWriterObject *self)
if (pwrt == NULL)
return NULL;
- if (PyString_Size(pwrt) > 0) {
+ if (PyBytes_Size(pwrt) > 0) {
PyObject *wr;
wr = PyObject_CallMethod(self->stream, "write", "O", pwrt);
if (wr == NULL) {
diff --git a/Modules/clmodule.c b/Modules/clmodule.c
index d3e0edf3e5..b504eed931 100644
--- a/Modules/clmodule.c
+++ b/Modules/clmodule.c
@@ -111,7 +111,7 @@ cl_CompressImage(PyObject *self, PyObject *args)
return NULL;
retry:
- compressedBuffer = PyString_FromStringAndSize(NULL, frameBufferSize);
+ compressedBuffer = PyBytes_FromStringAndSize(NULL, frameBufferSize);
if (compressedBuffer == NULL)
return NULL;
@@ -120,7 +120,7 @@ cl_CompressImage(PyObject *self, PyObject *args)
if (clCompressImage(compressionScheme, width, height, originalFormat,
compressionRatio, (void *) frameBuffer,
&compressedBufferSize,
- (void *) PyString_AsString(compressedBuffer))
+ (void *) PyBytes_AsString(compressedBuffer))
== FAILURE || error_handler_called) {
Py_DECREF(compressedBuffer);
if (!error_handler_called)
@@ -135,7 +135,7 @@ cl_CompressImage(PyObject *self, PyObject *args)
}
if (compressedBufferSize < frameBufferSize)
- _PyString_Resize(&compressedBuffer, compressedBufferSize);
+ _PyBytes_Resize(&compressedBuffer, compressedBufferSize);
return compressedBuffer;
}
@@ -155,14 +155,14 @@ cl_DecompressImage(PyObject *self, PyObject *args)
frameBufferSize = width * height * CL_BytesPerPixel(originalFormat);
- frameBuffer = PyString_FromStringAndSize(NULL, frameBufferSize);
+ frameBuffer = PyBytes_FromStringAndSize(NULL, frameBufferSize);
if (frameBuffer == NULL)
return NULL;
error_handler_called = 0;
if (clDecompressImage(compressionScheme, width, height, originalFormat,
compressedBufferSize, compressedBuffer,
- (void *) PyString_AsString(frameBuffer))
+ (void *) PyBytes_AsString(frameBuffer))
== FAILURE || error_handler_called) {
Py_DECREF(frameBuffer);
if (!error_handler_called)
@@ -236,14 +236,14 @@ clm_Compress(PyObject *self, PyObject *args)
if (error_handler_called)
return NULL;
- data = PyString_FromStringAndSize(NULL, size);
+ data = PyBytes_FromStringAndSize(NULL, size);
if (data == NULL)
return NULL;
error_handler_called = 0;
if (clCompress(SELF->ob_compressorHdl, numberOfFrames,
(void *) frameBuffer, &compressedBufferSize,
- (void *) PyString_AsString(data)) == FAILURE ||
+ (void *) PyBytes_AsString(data)) == FAILURE ||
error_handler_called) {
Py_DECREF(data);
if (!error_handler_called)
@@ -252,7 +252,7 @@ clm_Compress(PyObject *self, PyObject *args)
}
if (compressedBufferSize < size)
- if (_PyString_Resize(&data, compressedBufferSize))
+ if (_PyBytes_Resize(&data, compressedBufferSize))
return NULL;
if (compressedBufferSize > size) {
@@ -285,14 +285,14 @@ clm_Decompress(PyObject *self, PyObject *args)
if (error_handler_called)
return NULL;
- data = PyString_FromStringAndSize(NULL, dataSize);
+ data = PyBytes_FromStringAndSize(NULL, dataSize);
if (data == NULL)
return NULL;
error_handler_called = 0;
if (clDecompress(SELF->ob_compressorHdl, numberOfFrames,
compressedDataSize, (void *) compressedData,
- (void *) PyString_AsString(data)) == FAILURE ||
+ (void *) PyBytes_AsString(data)) == FAILURE ||
error_handler_called) {
Py_DECREF(data);
if (!error_handler_called)
@@ -514,7 +514,7 @@ clm_QueryParams(PyObject *self)
PyList_SetItem(list, i, Py_None);
} else
PyList_SetItem(list, i,
- PyString_FromString((char *) PVbuffer[i]));
+ PyBytes_FromString((char *) PVbuffer[i]));
}
PyMem_DEL(PVbuffer);
@@ -563,7 +563,7 @@ clm_GetName(PyObject *self, PyObject *args)
return NULL;
}
- return PyString_FromString(name);
+ return PyBytes_FromString(name);
}
static PyObject *
@@ -775,7 +775,7 @@ cl_QueryAlgorithms(PyObject *self, PyObject *args)
PyList_SetItem(list, i, Py_None);
} else
PyList_SetItem(list, i,
- PyString_FromString((char *) PVbuffer[i]));
+ PyBytes_FromString((char *) PVbuffer[i]));
}
PyMem_DEL(PVbuffer);
@@ -818,7 +818,7 @@ cl_GetAlgorithmName(PyObject *self, PyObject *args)
return NULL;
}
- return PyString_FromString(name);
+ return PyBytes_FromString(name);
}
static PyObject *
diff --git a/Modules/datetimemodule.c b/Modules/datetimemodule.c
index 3f9e78b0ab..be6e43aa9d 100644
--- a/Modules/datetimemodule.c
+++ b/Modules/datetimemodule.c
@@ -945,7 +945,7 @@ call_tzname(PyObject *tzinfo, PyObject *tzinfoarg)
else
result = PyObject_CallMethod(tzinfo, "tzname", "O", tzinfoarg);
- if (result != NULL && result != Py_None && ! PyString_Check(result)) {
+ if (result != NULL && result != Py_None && ! PyBytes_Check(result)) {
PyErr_Format(PyExc_TypeError, "tzinfo.tzname() must "
"return None or a string, not '%s'",
Py_TYPE(result)->tp_name);
@@ -1044,27 +1044,27 @@ append_keyword_tzinfo(PyObject *repr, PyObject *tzinfo)
{
PyObject *temp;
- assert(PyString_Check(repr));
+ assert(PyBytes_Check(repr));
assert(tzinfo);
if (tzinfo == Py_None)
return repr;
/* Get rid of the trailing ')'. */
- assert(PyString_AsString(repr)[PyString_Size(repr)-1] == ')');
- temp = PyString_FromStringAndSize(PyString_AsString(repr),
- PyString_Size(repr) - 1);
+ assert(PyBytes_AsString(repr)[PyBytes_Size(repr)-1] == ')');
+ temp = PyBytes_FromStringAndSize(PyBytes_AsString(repr),
+ PyBytes_Size(repr) - 1);
Py_DECREF(repr);
if (temp == NULL)
return NULL;
repr = temp;
/* Append ", tzinfo=". */
- PyString_ConcatAndDel(&repr, PyString_FromString(", tzinfo="));
+ PyBytes_ConcatAndDel(&repr, PyBytes_FromString(", tzinfo="));
/* Append repr(tzinfo). */
- PyString_ConcatAndDel(&repr, PyObject_Repr(tzinfo));
+ PyBytes_ConcatAndDel(&repr, PyObject_Repr(tzinfo));
/* Add a closing paren. */
- PyString_ConcatAndDel(&repr, PyString_FromString(")"));
+ PyBytes_ConcatAndDel(&repr, PyBytes_FromString(")"));
return repr;
}
@@ -1090,7 +1090,7 @@ format_ctime(PyDateTime_Date *date, int hours, int minutes, int seconds)
DayNames[wday], MonthNames[GET_MONTH(date) - 1],
GET_DAY(date), hours, minutes, seconds,
GET_YEAR(date));
- return PyString_FromString(buffer);
+ return PyBytes_FromString(buffer);
}
/* Add an hours & minutes UTC offset string to buf. buf has no more than
@@ -1141,7 +1141,7 @@ make_freplacement(PyObject *object)
else
sprintf(freplacement, "%06d", 0);
- return PyString_FromStringAndSize(freplacement, strlen(freplacement));
+ return PyBytes_FromStringAndSize(freplacement, strlen(freplacement));
}
/* I sure don't want to reproduce the strftime code from the time module,
@@ -1174,7 +1174,7 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
int ntoappend; /* # of bytes to append to output buffer */
assert(object && format && timetuple);
- assert(PyString_Check(format));
+ assert(PyBytes_Check(format));
/* Give up if the year is before 1900.
* Python strftime() plays games with the year, and different
@@ -1205,13 +1205,13 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
* a new format. Since computing the replacements for those codes
* is expensive, don't unless they're actually used.
*/
- totalnew = PyString_Size(format) + 1; /* realistic if no %z/%Z/%f */
- newfmt = PyString_FromStringAndSize(NULL, totalnew);
+ totalnew = PyBytes_Size(format) + 1; /* realistic if no %z/%Z/%f */
+ newfmt = PyBytes_FromStringAndSize(NULL, totalnew);
if (newfmt == NULL) goto Done;
- pnew = PyString_AsString(newfmt);
+ pnew = PyBytes_AsString(newfmt);
usednew = 0;
- pin = PyString_AsString(format);
+ pin = PyBytes_AsString(format);
while ((ch = *pin++) != '\0') {
if (ch != '%') {
ptoappend = pin - 1;
@@ -1229,7 +1229,7 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
/* format utcoffset */
char buf[100];
PyObject *tzinfo = get_tzinfo_member(object);
- zreplacement = PyString_FromString("");
+ zreplacement = PyBytes_FromString("");
if (zreplacement == NULL) goto Done;
if (tzinfo != Py_None && tzinfo != NULL) {
assert(tzinfoarg != NULL);
@@ -1240,19 +1240,19 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
tzinfoarg) < 0)
goto Done;
Py_DECREF(zreplacement);
- zreplacement = PyString_FromString(buf);
+ zreplacement = PyBytes_FromString(buf);
if (zreplacement == NULL) goto Done;
}
}
assert(zreplacement != NULL);
- ptoappend = PyString_AS_STRING(zreplacement);
- ntoappend = PyString_GET_SIZE(zreplacement);
+ ptoappend = PyBytes_AS_STRING(zreplacement);
+ ntoappend = PyBytes_GET_SIZE(zreplacement);
}
else if (ch == 'Z') {
/* format tzname */
if (Zreplacement == NULL) {
PyObject *tzinfo = get_tzinfo_member(object);
- Zreplacement = PyString_FromString("");
+ Zreplacement = PyBytes_FromString("");
if (Zreplacement == NULL) goto Done;
if (tzinfo != Py_None && tzinfo != NULL) {
PyObject *temp;
@@ -1260,7 +1260,7 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
temp = call_tzname(tzinfo, tzinfoarg);
if (temp == NULL) goto Done;
if (temp != Py_None) {
- assert(PyString_Check(temp));
+ assert(PyBytes_Check(temp));
/* Since the tzname is getting
* stuffed into the format, we
* have to double any % signs
@@ -1274,7 +1274,7 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
Py_DECREF(temp);
if (Zreplacement == NULL)
goto Done;
- if (!PyString_Check(Zreplacement)) {
+ if (!PyBytes_Check(Zreplacement)) {
PyErr_SetString(PyExc_TypeError, "tzname.replace() did not return a string");
goto Done;
}
@@ -1284,8 +1284,8 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
}
}
assert(Zreplacement != NULL);
- ptoappend = PyString_AS_STRING(Zreplacement);
- ntoappend = PyString_GET_SIZE(Zreplacement);
+ ptoappend = PyBytes_AS_STRING(Zreplacement);
+ ntoappend = PyBytes_GET_SIZE(Zreplacement);
}
else if (ch == 'f') {
/* format microseconds */
@@ -1295,9 +1295,9 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
goto Done;
}
assert(freplacement != NULL);
- assert(PyString_Check(freplacement));
- ptoappend = PyString_AS_STRING(freplacement);
- ntoappend = PyString_GET_SIZE(freplacement);
+ assert(PyBytes_Check(freplacement));
+ ptoappend = PyBytes_AS_STRING(freplacement);
+ ntoappend = PyBytes_GET_SIZE(freplacement);
}
else {
/* percent followed by neither z nor Z */
@@ -1318,10 +1318,10 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
PyErr_NoMemory();
goto Done;
}
- if (_PyString_Resize(&newfmt, bigger) < 0)
+ if (_PyBytes_Resize(&newfmt, bigger) < 0)
goto Done;
totalnew = bigger;
- pnew = PyString_AsString(newfmt) + usednew;
+ pnew = PyBytes_AsString(newfmt) + usednew;
}
memcpy(pnew, ptoappend, ntoappend);
pnew += ntoappend;
@@ -1329,7 +1329,7 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
assert(usednew <= totalnew);
} /* end while() */
- if (_PyString_Resize(&newfmt, usednew) < 0)
+ if (_PyBytes_Resize(&newfmt, usednew) < 0)
goto Done;
{
PyObject *time = PyImport_ImportModuleNoBlock("time");
@@ -2007,18 +2007,18 @@ static PyObject *
delta_repr(PyDateTime_Delta *self)
{
if (GET_TD_MICROSECONDS(self) != 0)
- return PyString_FromFormat("%s(%d, %d, %d)",
+ return PyBytes_FromFormat("%s(%d, %d, %d)",
Py_TYPE(self)->tp_name,
GET_TD_DAYS(self),
GET_TD_SECONDS(self),
GET_TD_MICROSECONDS(self));
if (GET_TD_SECONDS(self) != 0)
- return PyString_FromFormat("%s(%d, %d)",
+ return PyBytes_FromFormat("%s(%d, %d)",
Py_TYPE(self)->tp_name,
GET_TD_DAYS(self),
GET_TD_SECONDS(self));
- return PyString_FromFormat("%s(%d)",
+ return PyBytes_FromFormat("%s(%d)",
Py_TYPE(self)->tp_name,
GET_TD_DAYS(self));
}
@@ -2062,7 +2062,7 @@ delta_str(PyDateTime_Delta *self)
pbuf += n;
}
- return PyString_FromStringAndSize(buf, pbuf - buf);
+ return PyBytes_FromStringAndSize(buf, pbuf - buf);
Fail:
PyErr_SetString(PyExc_SystemError, "goofy result from PyOS_snprintf");
@@ -2241,15 +2241,15 @@ date_new(PyTypeObject *type, PyObject *args, PyObject *kw)
/* Check for invocation from pickle with __getstate__ state */
if (PyTuple_GET_SIZE(args) == 1 &&
- PyString_Check(state = PyTuple_GET_ITEM(args, 0)) &&
- PyString_GET_SIZE(state) == _PyDateTime_DATE_DATASIZE &&
- MONTH_IS_SANE(PyString_AS_STRING(state)[2]))
+ PyBytes_Check(state = PyTuple_GET_ITEM(args, 0)) &&
+ PyBytes_GET_SIZE(state) == _PyDateTime_DATE_DATASIZE &&
+ MONTH_IS_SANE(PyBytes_AS_STRING(state)[2]))
{
PyDateTime_Date *me;
me = (PyDateTime_Date *) (type->tp_alloc(type, 0));
if (me != NULL) {
- char *pdata = PyString_AS_STRING(state);
+ char *pdata = PyBytes_AS_STRING(state);
memcpy(me->data, pdata, _PyDateTime_DATE_DATASIZE);
me->hashcode = -1;
}
@@ -2447,7 +2447,7 @@ date_repr(PyDateTime_Date *self)
type_name,
GET_YEAR(self), GET_MONTH(self), GET_DAY(self));
- return PyString_FromString(buffer);
+ return PyBytes_FromString(buffer);
}
static PyObject *
@@ -2456,7 +2456,7 @@ date_isoformat(PyDateTime_Date *self)
char buffer[128];
isoformat_date(self, buffer, sizeof(buffer));
- return PyString_FromString(buffer);
+ return PyBytes_FromString(buffer);
}
/* str() calls the appropriate isoformat() method. */
@@ -2485,7 +2485,7 @@ date_strftime(PyDateTime_Date *self, PyObject *args, PyObject *kw)
static char *keywords[] = {"format", NULL};
if (! PyArg_ParseTupleAndKeywords(args, kw, "O!:strftime", keywords,
- &PyString_Type, &format))
+ &PyBytes_Type, &format))
return NULL;
tuple = PyObject_CallMethod((PyObject *)self, "timetuple", "()");
@@ -2506,9 +2506,9 @@ date_format(PyDateTime_Date *self, PyObject *args)
return NULL;
/* Check for str or unicode */
- if (PyString_Check(format)) {
+ if (PyBytes_Check(format)) {
/* If format is zero length, return str(self) */
- if (PyString_GET_SIZE(format) == 0)
+ if (PyBytes_GET_SIZE(format) == 0)
return PyObject_Str((PyObject *)self);
} else if (PyUnicode_Check(format)) {
/* If format is zero length, return str(self) */
@@ -2651,7 +2651,7 @@ date_getstate(PyDateTime_Date *self)
{
return Py_BuildValue(
"(N)",
- PyString_FromStringAndSize((char *)self->data,
+ PyBytes_FromStringAndSize((char *)self->data,
_PyDateTime_DATE_DATASIZE));
}
@@ -3107,9 +3107,9 @@ time_new(PyTypeObject *type, PyObject *args, PyObject *kw)
/* Check for invocation from pickle with __getstate__ state */
if (PyTuple_GET_SIZE(args) >= 1 &&
PyTuple_GET_SIZE(args) <= 2 &&
- PyString_Check(state = PyTuple_GET_ITEM(args, 0)) &&
- PyString_GET_SIZE(state) == _PyDateTime_TIME_DATASIZE &&
- ((unsigned char) (PyString_AS_STRING(state)[0])) < 24)
+ PyBytes_Check(state = PyTuple_GET_ITEM(args, 0)) &&
+ PyBytes_GET_SIZE(state) == _PyDateTime_TIME_DATASIZE &&
+ ((unsigned char) (PyBytes_AS_STRING(state)[0])) < 24)
{
PyDateTime_Time *me;
char aware;
@@ -3125,7 +3125,7 @@ time_new(PyTypeObject *type, PyObject *args, PyObject *kw)
aware = (char)(tzinfo != Py_None);
me = (PyDateTime_Time *) (type->tp_alloc(type, aware));
if (me != NULL) {
- char *pdata = PyString_AS_STRING(state);
+ char *pdata = PyBytes_AS_STRING(state);
memcpy(me->data, pdata, _PyDateTime_TIME_DATASIZE);
me->hashcode = -1;
@@ -3211,7 +3211,7 @@ time_repr(PyDateTime_Time *self)
else
PyOS_snprintf(buffer, sizeof(buffer),
"%s(%d, %d)", type_name, h, m);
- result = PyString_FromString(buffer);
+ result = PyBytes_FromString(buffer);
if (result != NULL && HASTZINFO(self))
result = append_keyword_tzinfo(result, self->tzinfo);
return result;
@@ -3238,7 +3238,7 @@ time_isoformat(PyDateTime_Time *self, PyObject *unused)
_PyDateTime_TIME_DATASIZE);
isoformat_time(pdatetime, buf, sizeof(buf));
- result = PyString_FromString(buf);
+ result = PyBytes_FromString(buf);
if (result == NULL || ! HASTZINFO(self) || self->tzinfo == Py_None)
return result;
@@ -3248,7 +3248,7 @@ time_isoformat(PyDateTime_Time *self, PyObject *unused)
Py_DECREF(result);
return NULL;
}
- PyString_ConcatAndDel(&result, PyString_FromString(buf));
+ PyBytes_ConcatAndDel(&result, PyBytes_FromString(buf));
return result;
}
@@ -3261,7 +3261,7 @@ time_strftime(PyDateTime_Time *self, PyObject *args, PyObject *kw)
static char *keywords[] = {"format", NULL};
if (! PyArg_ParseTupleAndKeywords(args, kw, "O!:strftime", keywords,
- &PyString_Type, &format))
+ &PyBytes_Type, &format))
return NULL;
/* Python's strftime does insane things with the year part of the
@@ -3360,7 +3360,7 @@ time_hash(PyDateTime_Time *self)
/* Reduce this to a hash of another object. */
if (offset == 0)
- temp = PyString_FromStringAndSize((char *)self->data,
+ temp = PyBytes_FromStringAndSize((char *)self->data,
_PyDateTime_TIME_DATASIZE);
else {
int hour;
@@ -3448,7 +3448,7 @@ time_getstate(PyDateTime_Time *self)
PyObject *basestate;
PyObject *result = NULL;
- basestate = PyString_FromStringAndSize((char *)self->data,
+ basestate = PyBytes_FromStringAndSize((char *)self->data,
_PyDateTime_TIME_DATASIZE);
if (basestate != NULL) {
if (! HASTZINFO(self) || self->tzinfo == Py_None)
@@ -3635,9 +3635,9 @@ datetime_new(PyTypeObject *type, PyObject *args, PyObject *kw)
/* Check for invocation from pickle with __getstate__ state */
if (PyTuple_GET_SIZE(args) >= 1 &&
PyTuple_GET_SIZE(args) <= 2 &&
- PyString_Check(state = PyTuple_GET_ITEM(args, 0)) &&
- PyString_GET_SIZE(state) == _PyDateTime_DATETIME_DATASIZE &&
- MONTH_IS_SANE(PyString_AS_STRING(state)[2]))
+ PyBytes_Check(state = PyTuple_GET_ITEM(args, 0)) &&
+ PyBytes_GET_SIZE(state) == _PyDateTime_DATETIME_DATASIZE &&
+ MONTH_IS_SANE(PyBytes_AS_STRING(state)[2]))
{
PyDateTime_DateTime *me;
char aware;
@@ -3653,7 +3653,7 @@ datetime_new(PyTypeObject *type, PyObject *args, PyObject *kw)
aware = (char)(tzinfo != Py_None);
me = (PyDateTime_DateTime *) (type->tp_alloc(type , aware));
if (me != NULL) {
- char *pdata = PyString_AS_STRING(state);
+ char *pdata = PyBytes_AS_STRING(state);
memcpy(me->data, pdata, _PyDateTime_DATETIME_DATASIZE);
me->hashcode = -1;
@@ -4162,7 +4162,7 @@ datetime_repr(PyDateTime_DateTime *self)
GET_YEAR(self), GET_MONTH(self), GET_DAY(self),
DATE_GET_HOUR(self), DATE_GET_MINUTE(self));
}
- baserepr = PyString_FromString(buffer);
+ baserepr = PyBytes_FromString(buffer);
if (baserepr == NULL || ! HASTZINFO(self))
return baserepr;
return append_keyword_tzinfo(baserepr, self->tzinfo);
@@ -4190,7 +4190,7 @@ datetime_isoformat(PyDateTime_DateTime *self, PyObject *args, PyObject *kw)
assert(cp != NULL);
*cp++ = sep;
isoformat_time(self, cp, sizeof(buffer) - (cp - buffer));
- result = PyString_FromString(buffer);
+ result = PyBytes_FromString(buffer);
if (result == NULL || ! HASTZINFO(self))
return result;
@@ -4200,7 +4200,7 @@ datetime_isoformat(PyDateTime_DateTime *self, PyObject *args, PyObject *kw)
Py_DECREF(result);
return NULL;
}
- PyString_ConcatAndDel(&result, PyString_FromString(buffer));
+ PyBytes_ConcatAndDel(&result, PyBytes_FromString(buffer));
return result;
}
@@ -4306,7 +4306,7 @@ datetime_hash(PyDateTime_DateTime *self)
/* Reduce this to a hash of another object. */
if (n == OFFSET_NAIVE)
- temp = PyString_FromStringAndSize(
+ temp = PyBytes_FromStringAndSize(
(char *)self->data,
_PyDateTime_DATETIME_DATASIZE);
else {
@@ -4529,7 +4529,7 @@ datetime_getstate(PyDateTime_DateTime *self)
PyObject *basestate;
PyObject *result = NULL;
- basestate = PyString_FromStringAndSize((char *)self->data,
+ basestate = PyBytes_FromStringAndSize((char *)self->data,
_PyDateTime_DATETIME_DATASIZE);
if (basestate != NULL) {
if (! HASTZINFO(self) || self->tzinfo == Py_None)
diff --git a/Modules/dbmmodule.c b/Modules/dbmmodule.c
index c91ea471a0..d5b518af11 100644
--- a/Modules/dbmmodule.c
+++ b/Modules/dbmmodule.c
@@ -104,7 +104,7 @@ dbm_subscript(dbmobject *dp, register PyObject *key)
drec = dbm_fetch(dp->di_dbm, krec);
if ( drec.dptr == 0 ) {
PyErr_SetString(PyExc_KeyError,
- PyString_AS_STRING((PyStringObject *)key));
+ PyBytes_AS_STRING((PyBytesObject *)key));
return NULL;
}
if ( dbm_error(dp->di_dbm) ) {
@@ -112,7 +112,7 @@ dbm_subscript(dbmobject *dp, register PyObject *key)
PyErr_SetString(DbmError, "");
return NULL;
}
- return PyString_FromStringAndSize(drec.dptr, drec.dsize);
+ return PyBytes_FromStringAndSize(drec.dptr, drec.dsize);
}
static int
@@ -136,7 +136,7 @@ dbm_ass_sub(dbmobject *dp, PyObject *v, PyObject *w)
if ( dbm_delete(dp->di_dbm, krec) < 0 ) {
dbm_clearerr(dp->di_dbm);
PyErr_SetString(PyExc_KeyError,
- PyString_AS_STRING((PyStringObject *)v));
+ PyBytes_AS_STRING((PyBytesObject *)v));
return -1;
}
} else {
@@ -166,7 +166,7 @@ dbm_contains(register dbmobject *dp, PyObject *v)
{
datum key, val;
- if (PyString_AsStringAndSize(v, (char **)&key.dptr,
+ if (PyBytes_AsStringAndSize(v, (char **)&key.dptr,
(Py_ssize_t *)&key.dsize)) {
return -1;
}
@@ -222,7 +222,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 = PyString_FromStringAndSize(key.dptr, key.dsize);
+ item = PyBytes_FromStringAndSize(key.dptr, key.dsize);
if (item == NULL) {
Py_DECREF(v);
return NULL;
@@ -269,7 +269,7 @@ dbm_get(register dbmobject *dp, PyObject *args)
check_dbmobject_open(dp);
val = dbm_fetch(dp->di_dbm, key);
if (val.dptr != NULL)
- return PyString_FromStringAndSize(val.dptr, val.dsize);
+ return PyBytes_FromStringAndSize(val.dptr, val.dsize);
else {
Py_INCREF(defvalue);
return defvalue;
@@ -292,16 +292,16 @@ dbm_setdefault(register dbmobject *dp, PyObject *args)
check_dbmobject_open(dp);
val = dbm_fetch(dp->di_dbm, key);
if (val.dptr != NULL)
- return PyString_FromStringAndSize(val.dptr, val.dsize);
+ return PyBytes_FromStringAndSize(val.dptr, val.dsize);
if (defvalue == NULL) {
- defvalue = PyString_FromStringAndSize(NULL, 0);
+ defvalue = PyBytes_FromStringAndSize(NULL, 0);
if (defvalue == NULL)
return NULL;
}
else
Py_INCREF(defvalue);
- val.dptr = PyString_AS_STRING(defvalue);
- val.dsize = PyString_GET_SIZE(defvalue);
+ val.dptr = PyBytes_AS_STRING(defvalue);
+ val.dsize = PyBytes_GET_SIZE(defvalue);
if (dbm_store(dp->di_dbm, key, val, DBM_INSERT) < 0) {
dbm_clearerr(dp->di_dbm);
PyErr_SetString(DbmError, "cannot add item to database");
@@ -404,7 +404,7 @@ initdbm(void) {
d = PyModule_GetDict(m);
if (DbmError == NULL)
DbmError = PyErr_NewException("dbm.error", NULL, NULL);
- s = PyString_FromString(which_dbm);
+ s = PyBytes_FromString(which_dbm);
if (s != NULL) {
PyDict_SetItemString(d, "library", s);
Py_DECREF(s);
diff --git a/Modules/dlmodule.c b/Modules/dlmodule.c
index ccf1cb1835..e633fe97e6 100644
--- a/Modules/dlmodule.c
+++ b/Modules/dlmodule.c
@@ -58,8 +58,8 @@ dl_sym(dlobject *xp, PyObject *args)
{
char *name;
PyUnivPtr *func;
- if (PyString_Check(args)) {
- name = PyString_AS_STRING(args);
+ if (PyBytes_Check(args)) {
+ name = PyBytes_AS_STRING(args);
} else {
PyErr_Format(PyExc_TypeError, "expected string, found %.200s",
Py_TYPE(args)->tp_name);
@@ -88,14 +88,14 @@ dl_call(dlobject *xp, PyObject *args)
return NULL;
}
name = PyTuple_GetItem(args, 0);
- if (!PyString_Check(name)) {
+ if (!PyBytes_Check(name)) {
PyErr_SetString(PyExc_TypeError,
"function name must be a string");
return NULL;
}
func = (long (*)(long, long, long, long, long,
long, long, long, long, long))
- dlsym(xp->dl_handle, PyString_AsString(name));
+ dlsym(xp->dl_handle, PyBytes_AsString(name));
if (func == NULL) {
PyErr_SetString(PyExc_ValueError, dlerror());
return NULL;
@@ -109,8 +109,8 @@ dl_call(dlobject *xp, PyObject *args)
PyObject *v = PyTuple_GetItem(args, i);
if (PyInt_Check(v))
alist[i-1] = PyInt_AsLong(v);
- else if (PyString_Check(v))
- alist[i-1] = (long)PyString_AsString(v);
+ else if (PyBytes_Check(v))
+ alist[i-1] = (long)PyBytes_AsString(v);
else if (v == Py_None)
alist[i-1] = (long) ((char *)NULL);
else {
diff --git a/Modules/errnomodule.c b/Modules/errnomodule.c
index 696d396b07..df2ceffe19 100644
--- a/Modules/errnomodule.c
+++ b/Modules/errnomodule.c
@@ -21,7 +21,7 @@ static PyMethodDef errno_methods[] = {
static void
_inscode(PyObject *d, PyObject *de, char *name, int code)
{
- PyObject *u = PyString_FromString(name);
+ PyObject *u = PyBytes_FromString(name);
PyObject *v = PyInt_FromLong((long) code);
/* Don't bother checking for errors; they'll be caught at the end
diff --git a/Modules/fcntlmodule.c b/Modules/fcntlmodule.c
index 0c85f477e9..7658be0a5b 100644
--- a/Modules/fcntlmodule.c
+++ b/Modules/fcntlmodule.c
@@ -55,7 +55,7 @@ fcntl_fcntl(PyObject *self, PyObject *args)
PyErr_SetFromErrno(PyExc_IOError);
return NULL;
}
- return PyString_FromStringAndSize(buf, len);
+ return PyBytes_FromStringAndSize(buf, len);
}
PyErr_Clear();
@@ -164,7 +164,7 @@ fcntl_ioctl(PyObject *self, PyObject *args)
return PyInt_FromLong(ret);
}
else {
- return PyString_FromStringAndSize(buf, len);
+ return PyBytes_FromStringAndSize(buf, len);
}
}
@@ -185,7 +185,7 @@ fcntl_ioctl(PyObject *self, PyObject *args)
PyErr_SetFromErrno(PyExc_IOError);
return NULL;
}
- return PyString_FromStringAndSize(buf, len);
+ return PyBytes_FromStringAndSize(buf, len);
}
PyErr_Clear();
diff --git a/Modules/flmodule.c b/Modules/flmodule.c
index 20e74e9306..800aebb8b5 100644
--- a/Modules/flmodule.c
+++ b/Modules/flmodule.c
@@ -324,7 +324,7 @@ generic_getattr(genericobject *g, char *name)
/* "label" is an exception, getmember only works for char pointers,
not for char arrays */
if (strcmp(name, "label") == 0)
- return PyString_FromString(g->ob_generic->label);
+ return PyBytes_FromString(g->ob_generic->label);
return PyMember_Get((char *)g->ob_generic, generic_memberlist, name);
}
@@ -343,12 +343,12 @@ generic_setattr(genericobject *g, char *name, PyObject *v)
/* "label" is an exception: setmember doesn't set strings;
and FORMS wants you to call a function to set the label */
if (strcmp(name, "label") == 0) {
- if (!PyString_Check(v)) {
+ if (!PyBytes_Check(v)) {
PyErr_SetString(PyExc_TypeError,
"label attr must be string");
return -1;
}
- fl_set_object_label(g->ob_generic, PyString_AsString(v));
+ fl_set_object_label(g->ob_generic, PyBytes_AsString(v));
return 0;
}
@@ -369,7 +369,7 @@ generic_repr(genericobject *g)
char buf[100];
PyOS_snprintf(buf, sizeof(buf), "<FORMS_object at %p, objclass=%d>",
g, g->ob_generic->objclass);
- return PyString_FromString(buf);
+ return PyBytes_FromString(buf);
}
static PyTypeObject GenericObjecttype = {
@@ -530,7 +530,7 @@ call_forms_Rstr (char * (*func)(FL_OBJECT *), FL_OBJECT *obj)
Py_INCREF(Py_None);
return Py_None;
}
- return PyString_FromString (str);
+ return PyBytes_FromString (str);
}
/* int func (object) */
@@ -628,7 +628,7 @@ get_browser_line(genericobject *g, PyObject *args)
Py_INCREF(Py_None);
return Py_None;
}
- return PyString_FromString (str);
+ return PyBytes_FromString (str);
}
static PyObject *
@@ -1594,7 +1594,7 @@ form_repr(formobject *f)
char buf[100];
PyOS_snprintf(buf, sizeof(buf), "<FORMS_form at %p, window=%ld>",
f, f->ob_form->window);
- return PyString_FromString(buf);
+ return PyBytes_FromString(buf);
}
static PyTypeObject Formtype = {
@@ -2027,7 +2027,7 @@ forms_show_input(PyObject *f, PyObject *args)
Py_INCREF(Py_None);
return Py_None;
}
- return PyString_FromString(str);
+ return PyBytes_FromString(str);
}
static PyObject *
@@ -2046,7 +2046,7 @@ forms_file_selector(PyObject *f, PyObject *args)
Py_INCREF(Py_None);
return Py_None;
}
- return PyString_FromString(str);
+ return PyBytes_FromString(str);
}
@@ -2061,7 +2061,7 @@ forms_file_selector_func(PyObject *args, char *(*func)(void))
Py_INCREF(Py_None);
return Py_None;
}
- return PyString_FromString(str);
+ return PyBytes_FromString(str);
}
static PyObject *
diff --git a/Modules/fmmodule.c b/Modules/fmmodule.c
index f3f0dc516c..73b8c05d81 100644
--- a/Modules/fmmodule.c
+++ b/Modules/fmmodule.c
@@ -66,7 +66,7 @@ fh_getfontname(fhobject *self)
PyErr_SetString(PyExc_RuntimeError, "error in fmgetfontname");
return NULL;
}
- return PyString_FromStringAndSize(fontname, len);
+ return PyBytes_FromStringAndSize(fontname, len);
}
static PyObject *
@@ -79,7 +79,7 @@ fh_getcomment(fhobject *self)
PyErr_SetString(PyExc_RuntimeError, "error in fmgetcomment");
return NULL;
}
- return PyString_FromStringAndSize(comment, len);
+ return PyBytes_FromStringAndSize(comment, len);
}
static PyObject *
@@ -200,7 +200,7 @@ clientproc(char *fontname)
PyObject *v;
if (fontlist == NULL)
return;
- v = PyString_FromString(fontname);
+ v = PyBytes_FromString(fontname);
if (v == NULL)
err = -1;
else {
@@ -240,7 +240,7 @@ fm_setpath(PyObject *self, PyObject *args)
static PyObject *
fm_fontpath(PyObject *self)
{
- return PyString_FromString(fmfontpath());
+ return PyBytes_FromString(fmfontpath());
}
static PyMethodDef fm_methods[] = {
diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c
index 4f8c85ffd9..c3ee96f4d2 100644
--- a/Modules/gcmodule.c
+++ b/Modules/gcmodule.c
@@ -639,8 +639,8 @@ debug_instance(char *msg, PyInstanceObject *inst)
char *cname;
/* simple version of instance_repr */
PyObject *classname = inst->in_class->cl_name;
- if (classname != NULL && PyString_Check(classname))
- cname = PyString_AsString(classname);
+ if (classname != NULL && PyBytes_Check(classname))
+ cname = PyBytes_AsString(classname);
else
cname = "?";
PySys_WriteStderr("gc: %.100s <%.100s instance at %p>\n",
@@ -754,7 +754,7 @@ collect(int generation)
double t1 = 0.0;
if (delstr == NULL) {
- delstr = PyString_InternFromString("__del__");
+ delstr = PyBytes_InternFromString("__del__");
if (delstr == NULL)
Py_FatalError("gc couldn't allocate \"__del__\"");
}
@@ -898,7 +898,7 @@ collect(int generation)
if (PyErr_Occurred()) {
if (gc_str == NULL)
- gc_str = PyString_FromString("garbage collection");
+ gc_str = PyBytes_FromString("garbage collection");
PyErr_WriteUnraisable(gc_str);
Py_FatalError("unexpected exception during garbage collection");
}
diff --git a/Modules/gdbmmodule.c b/Modules/gdbmmodule.c
index 04b3332bb8..89d9a3c668 100644
--- a/Modules/gdbmmodule.c
+++ b/Modules/gdbmmodule.c
@@ -128,10 +128,10 @@ dbm_subscript(dbmobject *dp, register PyObject *key)
drec = gdbm_fetch(dp->di_dbm, krec);
if (drec.dptr == 0) {
PyErr_SetString(PyExc_KeyError,
- PyString_AS_STRING((PyStringObject *)key));
+ PyBytes_AS_STRING((PyBytesObject *)key));
return NULL;
}
- v = PyString_FromStringAndSize(drec.dptr, drec.dsize);
+ v = PyBytes_FromStringAndSize(drec.dptr, drec.dsize);
free(drec.dptr);
return v;
}
@@ -155,7 +155,7 @@ dbm_ass_sub(dbmobject *dp, PyObject *v, PyObject *w)
if (w == NULL) {
if (gdbm_delete(dp->di_dbm, krec) < 0) {
PyErr_SetString(PyExc_KeyError,
- PyString_AS_STRING((PyStringObject *)v));
+ PyBytes_AS_STRING((PyBytesObject *)v));
return -1;
}
}
@@ -188,14 +188,14 @@ dbm_contains(register dbmobject *dp, PyObject *arg)
"GDBM object has already been closed");
return -1;
}
- if (!PyString_Check(arg)) {
+ if (!PyBytes_Check(arg)) {
PyErr_Format(PyExc_TypeError,
"gdbm key must be string, not %.100s",
arg->ob_type->tp_name);
return -1;
}
- key.dptr = PyString_AS_STRING(arg);
- key.dsize = PyString_GET_SIZE(arg);
+ key.dptr = PyBytes_AS_STRING(arg);
+ key.dsize = PyBytes_GET_SIZE(arg);
return gdbm_exists(dp->di_dbm, key);
}
@@ -255,7 +255,7 @@ dbm_keys(register dbmobject *dp, PyObject *unused)
key = gdbm_firstkey(dp->di_dbm);
while (key.dptr) {
- item = PyString_FromStringAndSize(key.dptr, key.dsize);
+ item = PyBytes_FromStringAndSize(key.dptr, key.dsize);
if (item == NULL) {
free(key.dptr);
Py_DECREF(v);
@@ -306,7 +306,7 @@ dbm_firstkey(register dbmobject *dp, PyObject *unused)
check_dbmobject_open(dp);
key = gdbm_firstkey(dp->di_dbm);
if (key.dptr) {
- v = PyString_FromStringAndSize(key.dptr, key.dsize);
+ v = PyBytes_FromStringAndSize(key.dptr, key.dsize);
free(key.dptr);
return v;
}
@@ -338,7 +338,7 @@ dbm_nextkey(register dbmobject *dp, PyObject *args)
check_dbmobject_open(dp);
nextkey = gdbm_nextkey(dp->di_dbm, key);
if (nextkey.dptr) {
- v = PyString_FromStringAndSize(nextkey.dptr, nextkey.dsize);
+ v = PyBytes_FromStringAndSize(nextkey.dptr, nextkey.dsize);
free(nextkey.dptr);
return v;
}
@@ -541,7 +541,7 @@ initgdbm(void) {
DbmError = PyErr_NewException("gdbm.error", NULL, NULL);
if (DbmError != NULL) {
PyDict_SetItemString(d, "error", DbmError);
- s = PyString_FromString(dbmmodule_open_flags);
+ s = PyBytes_FromString(dbmmodule_open_flags);
PyDict_SetItemString(d, "open_flags", s);
Py_DECREF(s);
}
diff --git a/Modules/glmodule.c b/Modules/glmodule.c
index 01db9fcb28..301a59362f 100644
--- a/Modules/glmodule.c
+++ b/Modules/glmodule.c
@@ -593,7 +593,7 @@ gl_lrectwrite(PyObject *self, PyObject *args)
#if 0
/* Don't check this, it breaks experiments with pixmode(PM_SIZE, ...) */
pixcount = (long)(x2+1-x1) * (long)(y2+1-y1);
- if (!PyString_Check(s) || PyString_Size(s) != pixcount*sizeof(long)) {
+ if (!PyBytes_Check(s) || PyBytes_Size(s) != pixcount*sizeof(long)) {
PyErr_SetString(PyExc_RuntimeError,
"string arg to lrectwrite has wrong size");
return NULL;
@@ -623,10 +623,10 @@ gl_lrectread(PyObject *self, PyObject *args)
if (!PyArg_GetShort(args, 4, 3, &y2))
return NULL;
pixcount = (long)(x2+1-x1) * (long)(y2+1-y1);
- parray = PyString_FromStringAndSize((char *)NULL, pixcount*sizeof(long));
+ parray = PyBytes_FromStringAndSize((char *)NULL, pixcount*sizeof(long));
if (parray == NULL)
return NULL; /* No memory */
- lrectread(x1, y1, x2, y2, (unsigned long *) PyString_AsString(parray));
+ lrectread(x1, y1, x2, y2, (unsigned long *) PyBytes_AsString(parray));
return parray;
}
@@ -642,10 +642,10 @@ gl_readdisplay(PyObject *self, PyObject *args)
if ( !PyArg_Parse(args, "hhhhl", &x1, &y1, &x2, &y2, &hints) )
return 0;
size = (long)(x2+1-x1) * (long)(y2+1-y1);
- rv = PyString_FromStringAndSize((char *)NULL, size*sizeof(long));
+ rv = PyBytes_FromStringAndSize((char *)NULL, size*sizeof(long));
if ( rv == NULL )
return NULL;
- parray = (unsigned long *)PyString_AsString(rv);
+ parray = (unsigned long *)PyBytes_AsString(rv);
size_ret = readdisplay(x1, y1, x2, y2, parray, hints);
if ( size_ret != size ) {
printf("gl_readdisplay: got %ld pixels, expected %ld\n",
@@ -700,16 +700,16 @@ gl_packrect(PyObject *self, PyObject *args)
pixcount = width*height;
packedcount = ((width+packfactor-1)/packfactor) *
((height+packfactor-1)/packfactor);
- if (PyString_Size(unpacked) != pixcount*sizeof(long)) {
+ if (PyBytes_Size(unpacked) != pixcount*sizeof(long)) {
PyErr_SetString(PyExc_RuntimeError,
"string arg to packrect has wrong size");
return NULL;
}
- packed = PyString_FromStringAndSize((char *)NULL, packedcount);
+ packed = PyBytes_FromStringAndSize((char *)NULL, packedcount);
if (packed == NULL)
return NULL;
- parray = (unsigned long *) PyString_AsString(unpacked);
- p = (unsigned char *) PyString_AsString(packed);
+ parray = (unsigned long *) PyBytes_AsString(unpacked);
+ p = (unsigned char *) PyBytes_AsString(packed);
for (y = 0; y < height; y += packfactor, parray += packfactor*width) {
for (x = 0; x < width; x += packfactor) {
pixel = parray[x];
@@ -758,16 +758,16 @@ gl_unpackrect(PyObject *self, PyObject *args)
pixcount = width*height;
packedcount = ((width+packfactor-1)/packfactor) *
((height+packfactor-1)/packfactor);
- if (PyString_Size(packed) != packedcount) {
+ if (PyBytes_Size(packed) != packedcount) {
PyErr_SetString(PyExc_RuntimeError,
"string arg to unpackrect has wrong size");
return NULL;
}
- unpacked = PyString_FromStringAndSize((char *)NULL, pixcount*sizeof(long));
+ unpacked = PyBytes_FromStringAndSize((char *)NULL, pixcount*sizeof(long));
if (unpacked == NULL)
return NULL;
- parray = (unsigned long *) PyString_AsString(unpacked);
- p = (unsigned char *) PyString_AsString(packed);
+ parray = (unsigned long *) PyBytes_AsString(unpacked);
+ p = (unsigned char *) PyBytes_AsString(packed);
if (packfactor == 1 && width*height > 0) {
/* Just expand bytes to longs */
register int x = width * height;
@@ -799,7 +799,7 @@ gl_gversion(PyObject *self, PyObject *args)
{
char buf[20];
gversion(buf);
- return PyString_FromString(buf);
+ return PyBytes_FromString(buf);
}
diff --git a/Modules/grpmodule.c b/Modules/grpmodule.c
index e5b9f4708c..74bf0dc7c1 100644
--- a/Modules/grpmodule.c
+++ b/Modules/grpmodule.c
@@ -47,7 +47,7 @@ mkgrent(struct group *p)
return NULL;
}
for (member = p->gr_mem; *member != NULL; member++) {
- PyObject *x = PyString_FromString(*member);
+ PyObject *x = PyBytes_FromString(*member);
if (x == NULL || PyList_Append(w, x) != 0) {
Py_XDECREF(x);
Py_DECREF(w);
@@ -58,13 +58,13 @@ mkgrent(struct group *p)
}
#define SET(i,val) PyStructSequence_SET_ITEM(v, i, val)
- SET(setIndex++, PyString_FromString(p->gr_name));
+ SET(setIndex++, PyBytes_FromString(p->gr_name));
#ifdef __VMS
SET(setIndex++, Py_None);
Py_INCREF(Py_None);
#else
if (p->gr_passwd)
- SET(setIndex++, PyString_FromString(p->gr_passwd));
+ SET(setIndex++, PyBytes_FromString(p->gr_passwd));
else {
SET(setIndex++, Py_None);
Py_INCREF(Py_None);
@@ -113,7 +113,7 @@ grp_getgrnam(PyObject *self, PyObject *pyo_name)
py_str_name = PyObject_Str(pyo_name);
if (!py_str_name)
return NULL;
- name = PyString_AS_STRING(py_str_name);
+ name = PyBytes_AS_STRING(py_str_name);
if ((p = getgrnam(name)) == NULL) {
PyErr_Format(PyExc_KeyError, "getgrnam(): name not found: %s", name);
diff --git a/Modules/imageop.c b/Modules/imageop.c
index f67cd60dd4..105bedcf11 100644
--- a/Modules/imageop.c
+++ b/Modules/imageop.c
@@ -54,7 +54,7 @@ imageop_backward_compatible(void)
return 1;
if (bcos == NULL) {
/* cache string object for future use */
- bcos = PyString_FromString("backward_compatible");
+ bcos = PyBytes_FromString("backward_compatible");
if (bcos == NULL)
return 1;
}
@@ -97,11 +97,11 @@ imageop_crop(PyObject *self, PyObject *args)
xstep = (newx1 < newx2)? 1 : -1;
ystep = (newy1 < newy2)? 1 : -1;
- rv = PyString_FromStringAndSize(NULL,
+ rv = PyBytes_FromStringAndSize(NULL,
(abs(newx2-newx1)+1)*(abs(newy2-newy1)+1)*size);
if ( rv == 0 )
return 0;
- ncp = (char *)PyString_AsString(rv);
+ ncp = (char *)PyBytes_AsString(rv);
nsp = (short *)ncp;
nlp = (Py_Int32 *)ncp;
newy2 += ystep;
@@ -150,10 +150,10 @@ imageop_scale(PyObject *self, PyObject *args)
return 0;
}
- rv = PyString_FromStringAndSize(NULL, newx*newy*size);
+ rv = PyBytes_FromStringAndSize(NULL, newx*newy*size);
if ( rv == 0 )
return 0;
- ncp = (char *)PyString_AsString(rv);
+ ncp = (char *)PyBytes_AsString(rv);
nsp = (short *)ncp;
nlp = (Py_Int32 *)ncp;
for( iy = 0; iy < newy; iy++ ) {
@@ -195,10 +195,10 @@ imageop_tovideo(PyObject *self, PyObject *args)
return 0;
}
- rv = PyString_FromStringAndSize(NULL, len);
+ rv = PyBytes_FromStringAndSize(NULL, len);
if ( rv == 0 )
return 0;
- ncp = (unsigned char *)PyString_AsString(rv);
+ ncp = (unsigned char *)PyBytes_AsString(rv);
if ( width == 1 ) {
memcpy(ncp, cp, maxx); /* Copy first line */
@@ -245,10 +245,10 @@ imageop_grey2mono(PyObject *self, PyObject *args)
return 0;
}
- rv = PyString_FromStringAndSize(NULL, (len+7)/8);
+ rv = PyBytes_FromStringAndSize(NULL, (len+7)/8);
if ( rv == 0 )
return 0;
- ncp = (unsigned char *)PyString_AsString(rv);
+ ncp = (unsigned char *)PyBytes_AsString(rv);
bit = 0x80;
ovalue = 0;
@@ -286,10 +286,10 @@ imageop_grey2grey4(PyObject *self, PyObject *args)
return 0;
}
- rv = PyString_FromStringAndSize(NULL, (len+1)/2);
+ rv = PyBytes_FromStringAndSize(NULL, (len+1)/2);
if ( rv == 0 )
return 0;
- ncp = (unsigned char *)PyString_AsString(rv);
+ ncp = (unsigned char *)PyBytes_AsString(rv);
pos = 0;
ovalue = 0;
for ( i=0; i < len; i++ ) {
@@ -325,10 +325,10 @@ imageop_grey2grey2(PyObject *self, PyObject *args)
return 0;
}
- rv = PyString_FromStringAndSize(NULL, (len+3)/4);
+ rv = PyBytes_FromStringAndSize(NULL, (len+3)/4);
if ( rv == 0 )
return 0;
- ncp = (unsigned char *)PyString_AsString(rv);
+ ncp = (unsigned char *)PyBytes_AsString(rv);
pos = 0;
ovalue = 0;
for ( i=0; i < len; i++ ) {
@@ -363,10 +363,10 @@ imageop_dither2mono(PyObject *self, PyObject *args)
return 0;
}
- rv = PyString_FromStringAndSize(NULL, (len+7)/8);
+ rv = PyBytes_FromStringAndSize(NULL, (len+7)/8);
if ( rv == 0 )
return 0;
- ncp = (unsigned char *)PyString_AsString(rv);
+ ncp = (unsigned char *)PyBytes_AsString(rv);
bit = 0x80;
ovalue = 0;
@@ -409,10 +409,10 @@ imageop_dither2grey2(PyObject *self, PyObject *args)
return 0;
}
- rv = PyString_FromStringAndSize(NULL, (len+3)/4);
+ rv = PyBytes_FromStringAndSize(NULL, (len+3)/4);
if ( rv == 0 )
return 0;
- ncp = (unsigned char *)PyString_AsString(rv);
+ ncp = (unsigned char *)PyBytes_AsString(rv);
pos = 1;
ovalue = 0;
for ( i=0; i < len; i++ ) {
@@ -449,10 +449,10 @@ imageop_mono2grey(PyObject *self, PyObject *args)
return 0;
}
- rv = PyString_FromStringAndSize(NULL, nlen);
+ rv = PyBytes_FromStringAndSize(NULL, nlen);
if ( rv == 0 )
return 0;
- ncp = (unsigned char *)PyString_AsString(rv);
+ ncp = (unsigned char *)PyBytes_AsString(rv);
bit = 0x80;
for ( i=0; i < nlen; i++ ) {
@@ -486,10 +486,10 @@ imageop_grey22grey(PyObject *self, PyObject *args)
return 0;
}
- rv = PyString_FromStringAndSize(NULL, nlen);
+ rv = PyBytes_FromStringAndSize(NULL, nlen);
if ( rv == 0 )
return 0;
- ncp = (unsigned char *)PyString_AsString(rv);
+ ncp = (unsigned char *)PyBytes_AsString(rv);
pos = 0;
for ( i=0; i < nlen; i++ ) {
@@ -522,10 +522,10 @@ imageop_grey42grey(PyObject *self, PyObject *args)
return 0;
}
- rv = PyString_FromStringAndSize(NULL, nlen);
+ rv = PyBytes_FromStringAndSize(NULL, nlen);
if ( rv == 0 )
return 0;
- ncp = (unsigned char *)PyString_AsString(rv);
+ ncp = (unsigned char *)PyBytes_AsString(rv);
pos = 0;
for ( i=0; i < nlen; i++ ) {
@@ -559,10 +559,10 @@ imageop_rgb2rgb8(PyObject *self, PyObject *args)
return 0;
}
- rv = PyString_FromStringAndSize(NULL, nlen);
+ rv = PyBytes_FromStringAndSize(NULL, nlen);
if ( rv == 0 )
return 0;
- ncp = (unsigned char *)PyString_AsString(rv);
+ ncp = (unsigned char *)PyBytes_AsString(rv);
for ( i=0; i < nlen; i++ ) {
/* Bits in source: aaaaaaaa BBbbbbbb GGGggggg RRRrrrrr */
@@ -603,10 +603,10 @@ imageop_rgb82rgb(PyObject *self, PyObject *args)
return 0;
}
- rv = PyString_FromStringAndSize(NULL, nlen*4);
+ rv = PyBytes_FromStringAndSize(NULL, nlen*4);
if ( rv == 0 )
return 0;
- ncp = (unsigned char *)PyString_AsString(rv);
+ ncp = (unsigned char *)PyBytes_AsString(rv);
for ( i=0; i < nlen; i++ ) {
/* Bits in source: RRRBBGGG
@@ -653,10 +653,10 @@ imageop_rgb2grey(PyObject *self, PyObject *args)
return 0;
}
- rv = PyString_FromStringAndSize(NULL, nlen);
+ rv = PyBytes_FromStringAndSize(NULL, nlen);
if ( rv == 0 )
return 0;
- ncp = (unsigned char *)PyString_AsString(rv);
+ ncp = (unsigned char *)PyBytes_AsString(rv);
for ( i=0; i < nlen; i++ ) {
if (backward_compatible) {
@@ -698,10 +698,10 @@ imageop_grey2rgb(PyObject *self, PyObject *args)
return 0;
}
- rv = PyString_FromStringAndSize(NULL, nlen*4);
+ rv = PyBytes_FromStringAndSize(NULL, nlen*4);
if ( rv == 0 )
return 0;
- ncp = (unsigned char *)PyString_AsString(rv);
+ ncp = (unsigned char *)PyBytes_AsString(rv);
for ( i=0; i < nlen; i++ ) {
value = *cp++;
diff --git a/Modules/imgfile.c b/Modules/imgfile.c
index baa6eadb4a..5a8adf2f91 100644
--- a/Modules/imgfile.c
+++ b/Modules/imgfile.c
@@ -130,12 +130,12 @@ imgfile_read(PyObject *self, PyObject *args)
}
if ( zsize == 3 ) zsize = 4;
- rv = PyString_FromStringAndSize((char *)NULL, xsize*ysize*zsize);
+ rv = PyBytes_FromStringAndSize((char *)NULL, xsize*ysize*zsize);
if ( rv == NULL ) {
iclose(image);
return NULL;
}
- cdatap = PyString_AsString(rv);
+ cdatap = PyBytes_AsString(rv);
idatap = (long *)cdatap;
if (top_to_bottom) {
@@ -319,7 +319,7 @@ imgfile_readscaled(PyObject *self, PyObject *args)
}
if ( zsize == 3 ) zsize = 4;
- rv = PyString_FromStringAndSize(NULL, xwtd*ywtd*zsize);
+ rv = PyBytes_FromStringAndSize(NULL, xwtd*ywtd*zsize);
if ( rv == NULL ) {
iclose(image);
return NULL;
@@ -328,7 +328,7 @@ imgfile_readscaled(PyObject *self, PyObject *args)
xfac = (float)xsize/(float)xwtd;
yfac = (float)ysize/(float)ywtd;
PyFPE_END_PROTECT(yfac)
- cdatap = PyString_AsString(rv);
+ cdatap = PyBytes_AsString(rv);
idatap = (long *)cdatap;
if ( extended ) {
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c
index 261e8f1b6f..f466b914e4 100644
--- a/Modules/itertoolsmodule.c
+++ b/Modules/itertoolsmodule.c
@@ -2904,12 +2904,12 @@ count_repr(countobject *lz)
PyObject *result;
if (lz->cnt != PY_SSIZE_T_MAX)
- return PyString_FromFormat("count(%zd)", lz->cnt);
+ return PyBytes_FromFormat("count(%zd)", lz->cnt);
cnt_repr = PyObject_Repr(lz->long_cnt);
if (cnt_repr == NULL)
return NULL;
- result = PyString_FromFormat("count(%s)", PyString_AS_STRING(cnt_repr));
+ result = PyBytes_FromFormat("count(%s)", PyBytes_AS_STRING(cnt_repr));
Py_DECREF(cnt_repr);
return result;
}
@@ -3221,11 +3221,11 @@ repeat_repr(repeatobject *ro)
return NULL;
if (ro->cnt == -1)
- result = PyString_FromFormat("repeat(%s)",
- PyString_AS_STRING(objrepr));
+ result = PyBytes_FromFormat("repeat(%s)",
+ PyBytes_AS_STRING(objrepr));
else
- result = PyString_FromFormat("repeat(%s, %zd)",
- PyString_AS_STRING(objrepr), ro->cnt);
+ result = PyBytes_FromFormat("repeat(%s, %zd)",
+ PyBytes_AS_STRING(objrepr), ro->cnt);
Py_DECREF(objrepr);
return result;
}
diff --git a/Modules/linuxaudiodev.c b/Modules/linuxaudiodev.c
index 80077c6f1e..bde6e4992d 100644
--- a/Modules/linuxaudiodev.c
+++ b/Modules/linuxaudiodev.c
@@ -162,17 +162,17 @@ lad_read(lad_t *self, PyObject *args)
if (!PyArg_ParseTuple(args, "i:read", &size))
return NULL;
- rv = PyString_FromStringAndSize(NULL, size);
+ rv = PyBytes_FromStringAndSize(NULL, size);
if (rv == NULL)
return NULL;
- cp = PyString_AS_STRING(rv);
+ cp = PyBytes_AS_STRING(rv);
if ((count = read(self->x_fd, cp, size)) < 0) {
PyErr_SetFromErrno(LinuxAudioError);
Py_DECREF(rv);
return NULL;
}
self->x_icount += count;
- _PyString_Resize(&rv, count);
+ _PyBytes_Resize(&rv, count);
return rv;
}
diff --git a/Modules/main.c b/Modules/main.c
index 3a8a5cb856..dc94a092ef 100644
--- a/Modules/main.c
+++ b/Modules/main.c
@@ -195,7 +195,7 @@ static int RunMainFromImporter(char *filename)
{
PyObject *argv0 = NULL, *importer = NULL;
- if ((argv0 = PyString_FromString(filename)) &&
+ if ((argv0 = PyBytes_FromString(filename)) &&
(importer = PyImport_GetImporter(argv0)) &&
(importer->ob_type != &PyNullImporter_Type))
{
diff --git a/Modules/md5module.c b/Modules/md5module.c
index 1e2e6e3ee8..70952028dd 100644
--- a/Modules/md5module.c
+++ b/Modules/md5module.c
@@ -80,7 +80,7 @@ md5_digest(md5object *self)
mdContext = self->md5;
md5_finish(&mdContext, aDigest);
- return PyString_FromStringAndSize((char *)aDigest, 16);
+ return PyBytes_FromStringAndSize((char *)aDigest, 16);
}
PyDoc_STRVAR(digest_doc,
@@ -113,7 +113,7 @@ md5_hexdigest(md5object *self)
c = (c>9) ? c+'a'-10 : c + '0';
hexdigest[j++] = c;
}
- return PyString_FromStringAndSize((char*)hexdigest, 32);
+ return PyBytes_FromStringAndSize((char*)hexdigest, 32);
}
@@ -165,7 +165,7 @@ md5_get_digest_size(PyObject *self, void *closure)
static PyObject *
md5_get_name(PyObject *self, void *closure)
{
- return PyString_FromStringAndSize("MD5", 3);
+ return PyBytes_FromStringAndSize("MD5", 3);
}
static PyGetSetDef md5_getseters[] = {
diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c
index c71d8402cb..73fdf6d838 100644
--- a/Modules/mmapmodule.c
+++ b/Modules/mmapmodule.c
@@ -222,7 +222,7 @@ mmap_read_line_method(mmap_object *self,
else
++eol; /* we're interested in the position after the
newline. */
- result = PyString_FromStringAndSize(start, (eol - start));
+ result = PyBytes_FromStringAndSize(start, (eol - start));
self->pos += (eol - start);
return result;
}
@@ -700,7 +700,7 @@ mmap_item(mmap_object *self, Py_ssize_t i)
PyErr_SetString(PyExc_IndexError, "mmap index out of range");
return NULL;
}
- return PyString_FromStringAndSize(self->data + i, 1);
+ return PyBytes_FromStringAndSize(self->data + i, 1);
}
static PyObject *
@@ -718,7 +718,7 @@ mmap_slice(mmap_object *self, Py_ssize_t ilow, Py_ssize_t ihigh)
else if ((size_t)ihigh > self->size)
ihigh = self->size;
- return PyString_FromStringAndSize(self->data + ilow, ihigh-ilow);
+ return PyBytes_FromStringAndSize(self->data + ilow, ihigh-ilow);
}
static PyObject *
@@ -736,7 +736,7 @@ mmap_subscript(mmap_object *self, PyObject *item)
"mmap index out of range");
return NULL;
}
- return PyString_FromStringAndSize(self->data + i, 1);
+ return PyBytes_FromStringAndSize(self->data + i, 1);
}
else if (PySlice_Check(item)) {
Py_ssize_t start, stop, step, slicelen;
@@ -747,9 +747,9 @@ mmap_subscript(mmap_object *self, PyObject *item)
}
if (slicelen <= 0)
- return PyString_FromStringAndSize("", 0);
+ return PyBytes_FromStringAndSize("", 0);
else if (step == 1)
- return PyString_FromStringAndSize(self->data + start,
+ return PyBytes_FromStringAndSize(self->data + start,
slicelen);
else {
char *result_buf = (char *)PyMem_Malloc(slicelen);
@@ -762,7 +762,7 @@ mmap_subscript(mmap_object *self, PyObject *item)
cur += step, i++) {
result_buf[i] = self->data[cur];
}
- result = PyString_FromStringAndSize(result_buf,
+ result = PyBytes_FromStringAndSize(result_buf,
slicelen);
PyMem_Free(result_buf);
return result;
@@ -815,19 +815,19 @@ mmap_ass_slice(mmap_object *self, Py_ssize_t ilow, Py_ssize_t ihigh, PyObject *v
"mmap object doesn't support slice deletion");
return -1;
}
- if (! (PyString_Check(v)) ) {
+ if (! (PyBytes_Check(v)) ) {
PyErr_SetString(PyExc_IndexError,
"mmap slice assignment must be a string");
return -1;
}
- if (PyString_Size(v) != (ihigh - ilow)) {
+ if (PyBytes_Size(v) != (ihigh - ilow)) {
PyErr_SetString(PyExc_IndexError,
"mmap slice assignment is wrong size");
return -1;
}
if (!is_writeable(self))
return -1;
- buf = PyString_AsString(v);
+ buf = PyBytes_AsString(v);
memcpy(self->data + ilow, buf, ihigh-ilow);
return 0;
}
@@ -847,14 +847,14 @@ mmap_ass_item(mmap_object *self, Py_ssize_t i, PyObject *v)
"mmap object doesn't support item deletion");
return -1;
}
- if (! (PyString_Check(v) && PyString_Size(v)==1) ) {
+ if (! (PyBytes_Check(v) && PyBytes_Size(v)==1) ) {
PyErr_SetString(PyExc_IndexError,
"mmap assignment must be single-character string");
return -1;
}
if (!is_writeable(self))
return -1;
- buf = PyString_AsString(v);
+ buf = PyBytes_AsString(v);
self->data[i] = buf[0];
return 0;
}
@@ -882,14 +882,14 @@ mmap_ass_subscript(mmap_object *self, PyObject *item, PyObject *value)
"mmap object doesn't support item deletion");
return -1;
}
- if (!PyString_Check(value) || PyString_Size(value) != 1) {
+ if (!PyBytes_Check(value) || PyBytes_Size(value) != 1) {
PyErr_SetString(PyExc_IndexError,
"mmap assignment must be single-character string");
return -1;
}
if (!is_writeable(self))
return -1;
- buf = PyString_AsString(value);
+ buf = PyBytes_AsString(value);
self->data[i] = buf[0];
return 0;
}
@@ -906,12 +906,12 @@ mmap_ass_subscript(mmap_object *self, PyObject *item, PyObject *value)
"mmap object doesn't support slice deletion");
return -1;
}
- if (!PyString_Check(value)) {
+ if (!PyBytes_Check(value)) {
PyErr_SetString(PyExc_IndexError,
"mmap slice assignment must be a string");
return -1;
}
- if (PyString_Size(value) != slicelen) {
+ if (PyBytes_Size(value) != slicelen) {
PyErr_SetString(PyExc_IndexError,
"mmap slice assignment is wrong size");
return -1;
@@ -922,7 +922,7 @@ mmap_ass_subscript(mmap_object *self, PyObject *item, PyObject *value)
if (slicelen == 0)
return 0;
else if (step == 1) {
- const char *buf = PyString_AsString(value);
+ const char *buf = PyBytes_AsString(value);
if (buf == NULL)
return -1;
@@ -931,7 +931,7 @@ mmap_ass_subscript(mmap_object *self, PyObject *item, PyObject *value)
}
else {
Py_ssize_t cur, i;
- const char *buf = PyString_AsString(value);
+ const char *buf = PyBytes_AsString(value);
if (buf == NULL)
return -1;
diff --git a/Modules/nismodule.c b/Modules/nismodule.c
index 0811430cf0..8dd1d96733 100644
--- a/Modules/nismodule.c
+++ b/Modules/nismodule.c
@@ -115,8 +115,8 @@ nis_foreach (int instatus, char *inkey, int inkeylen, char *inval,
if (invallen > 0 && inval[invallen-1] == '\0')
invallen--;
}
- key = PyString_FromStringAndSize(inkey, inkeylen);
- val = PyString_FromStringAndSize(inval, invallen);
+ key = PyBytes_FromStringAndSize(inkey, inkeylen);
+ val = PyBytes_FromStringAndSize(inval, invallen);
if (key == NULL || val == NULL) {
/* XXX error -- don't know how to handle */
PyErr_Clear();
@@ -146,7 +146,7 @@ nis_get_default_domain (PyObject *self)
if ((err = yp_get_default_domain(&domain)) != 0)
return nis_error(err);
- res = PyString_FromStringAndSize (domain, strlen(domain));
+ res = PyBytes_FromStringAndSize (domain, strlen(domain));
return res;
}
@@ -178,7 +178,7 @@ nis_match (PyObject *self, PyObject *args, PyObject *kwdict)
len--;
if (err != 0)
return nis_error(err);
- res = PyString_FromStringAndSize (match, len);
+ res = PyBytes_FromStringAndSize (match, len);
free (match);
return res;
}
@@ -398,7 +398,7 @@ nis_maps (PyObject *self, PyObject *args, PyObject *kwdict)
if ((list = PyList_New(0)) == NULL)
return NULL;
for (maps = maps; maps; maps = maps->next) {
- PyObject *str = PyString_FromString(maps->map);
+ PyObject *str = PyBytes_FromString(maps->map);
if (!str || PyList_Append(list, str) < 0)
{
Py_DECREF(list);
diff --git a/Modules/operator.c b/Modules/operator.c
index fd98efdbe7..7e44739705 100644
--- a/Modules/operator.c
+++ b/Modules/operator.c
@@ -508,19 +508,19 @@ dotted_getattr(PyObject *obj, PyObject *attr)
}
#endif
- if (!PyString_Check(attr)) {
+ if (!PyBytes_Check(attr)) {
PyErr_SetString(PyExc_TypeError,
"attribute name must be a string");
return NULL;
}
- s = PyString_AS_STRING(attr);
+ s = PyBytes_AS_STRING(attr);
Py_INCREF(obj);
for (;;) {
PyObject *newobj, *str;
p = strchr(s, '.');
- str = p ? PyString_FromStringAndSize(s, (p-s)) :
- PyString_FromString(s);
+ str = p ? PyBytes_FromStringAndSize(s, (p-s)) :
+ PyBytes_FromString(s);
if (str == NULL) {
Py_DECREF(obj);
return NULL;
diff --git a/Modules/ossaudiodev.c b/Modules/ossaudiodev.c
index ebf101a200..75f6c157ef 100644
--- a/Modules/ossaudiodev.c
+++ b/Modules/ossaudiodev.c
@@ -366,10 +366,10 @@ oss_read(oss_audio_t *self, PyObject *args)
if (!PyArg_ParseTuple(args, "i:read", &size))
return NULL;
- rv = PyString_FromStringAndSize(NULL, size);
+ rv = PyBytes_FromStringAndSize(NULL, size);
if (rv == NULL)
return NULL;
- cp = PyString_AS_STRING(rv);
+ cp = PyBytes_AS_STRING(rv);
Py_BEGIN_ALLOW_THREADS
count = read(self->fd, cp, size);
@@ -381,7 +381,7 @@ oss_read(oss_audio_t *self, PyObject *args)
return NULL;
}
self->icount += count;
- _PyString_Resize(&rv, count);
+ _PyBytes_Resize(&rv, count);
return rv;
}
@@ -811,20 +811,20 @@ oss_getattr(oss_audio_t *self, char *name)
Py_INCREF(rval);
}
else if (strcmp(name, "name") == 0) {
- rval = PyString_FromString(self->devicename);
+ rval = PyBytes_FromString(self->devicename);
}
else if (strcmp(name, "mode") == 0) {
/* No need for a "default" in this switch: from newossobject(),
self->mode can only be one of these three values. */
switch(self->mode) {
case O_RDONLY:
- rval = PyString_FromString("r");
+ rval = PyBytes_FromString("r");
break;
case O_RDWR:
- rval = PyString_FromString("rw");
+ rval = PyBytes_FromString("rw");
break;
case O_WRONLY:
- rval = PyString_FromString("w");
+ rval = PyBytes_FromString("w");
break;
}
}
@@ -913,12 +913,12 @@ build_namelists (PyObject *module)
if (labels == NULL || names == NULL)
goto error2;
for (i = 0; i < num_controls; i++) {
- s = PyString_FromString(control_labels[i]);
+ s = PyBytes_FromString(control_labels[i]);
if (s == NULL)
goto error2;
PyList_SET_ITEM(labels, i, s);
- s = PyString_FromString(control_names[i]);
+ s = PyBytes_FromString(control_names[i]);
if (s == NULL)
goto error2;
PyList_SET_ITEM(names, i, s);
diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c
index 6e52343e0d..2ff67f2216 100644
--- a/Modules/parsermodule.c
+++ b/Modules/parsermodule.c
@@ -105,14 +105,14 @@ node2tuple(node *n, /* node to convert */
}
if (TYPE(n) == encoding_decl)
- (void) addelem(v, i+1, PyString_FromString(STR(n)));
+ (void) addelem(v, i+1, PyBytes_FromString(STR(n)));
return (v);
}
else if (ISTERMINAL(TYPE(n))) {
PyObject *result = mkseq(2 + lineno + col_offset);
if (result != NULL) {
(void) addelem(result, 0, PyInt_FromLong(TYPE(n)));
- (void) addelem(result, 1, PyString_FromString(STR(n)));
+ (void) addelem(result, 1, PyBytes_FromString(STR(n)));
if (lineno == 1)
(void) addelem(result, 2, PyInt_FromLong(n->n_lineno));
if (col_offset == 1)
@@ -689,7 +689,7 @@ build_node_children(PyObject *tuple, node *root, int *line_num)
temp = PySequence_GetItem(elem, 1);
if (temp == NULL)
return 0;
- if (!PyString_Check(temp)) {
+ if (!PyBytes_Check(temp)) {
PyErr_Format(parser_error,
"second item in terminal node must be a string,"
" found %s",
@@ -714,10 +714,10 @@ build_node_children(PyObject *tuple, node *root, int *line_num)
Py_DECREF(o);
}
}
- len = PyString_GET_SIZE(temp) + 1;
+ len = PyBytes_GET_SIZE(temp) + 1;
strn = (char *)PyObject_MALLOC(len);
if (strn != NULL)
- (void) memcpy(strn, PyString_AS_STRING(temp), len);
+ (void) memcpy(strn, PyBytes_AS_STRING(temp), len);
Py_DECREF(temp);
}
else if (!ISNONTERMINAL(type)) {
@@ -800,10 +800,10 @@ build_node_tree(PyObject *tuple)
}
if (res && encoding) {
Py_ssize_t len;
- len = PyString_GET_SIZE(encoding) + 1;
+ len = PyBytes_GET_SIZE(encoding) + 1;
res->n_str = (char *)PyObject_MALLOC(len);
if (res->n_str != NULL)
- (void) memcpy(res->n_str, PyString_AS_STRING(encoding), len);
+ (void) memcpy(res->n_str, PyBytes_AS_STRING(encoding), len);
Py_DECREF(encoding);
Py_DECREF(tuple);
}
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index a4bbac556a..57fe088cc7 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -375,12 +375,12 @@ convertenviron(void)
char *p = strchr(*e, '=');
if (p == NULL)
continue;
- k = PyString_FromStringAndSize(*e, (int)(p-*e));
+ k = PyBytes_FromStringAndSize(*e, (int)(p-*e));
if (k == NULL) {
PyErr_Clear();
continue;
}
- v = PyString_FromString(p+1);
+ v = PyBytes_FromString(p+1);
if (v == NULL) {
PyErr_Clear();
Py_DECREF(k);
@@ -400,13 +400,13 @@ convertenviron(void)
rc = DosQueryExtLIBPATH(buffer, BEGIN_LIBPATH);
if (rc == NO_ERROR) { /* (not a type, envname is NOT 'BEGIN_LIBPATH') */
- PyObject *v = PyString_FromString(buffer);
+ PyObject *v = PyBytes_FromString(buffer);
PyDict_SetItemString(d, "BEGINLIBPATH", v);
Py_DECREF(v);
}
rc = DosQueryExtLIBPATH(buffer, END_LIBPATH);
if (rc == NO_ERROR) { /* (not a typo, envname is NOT 'END_LIBPATH') */
- PyObject *v = PyString_FromString(buffer);
+ PyObject *v = PyBytes_FromString(buffer);
PyDict_SetItemString(d, "ENDLIBPATH", v);
Py_DECREF(v);
}
@@ -1598,7 +1598,7 @@ posix_ttyname(PyObject *self, PyObject *args)
#endif
if (ret == NULL)
return posix_error();
- return PyString_FromString(ret);
+ return PyBytes_FromString(ret);
}
#endif
@@ -1620,7 +1620,7 @@ posix_ctermid(PyObject *self, PyObject *noargs)
#endif
if (ret == NULL)
return posix_error();
- return PyString_FromString(buffer);
+ return PyBytes_FromString(buffer);
}
#endif
@@ -1968,7 +1968,7 @@ posix_getcwd(PyObject *self, PyObject *noargs)
Py_END_ALLOW_THREADS
if (res == NULL)
return posix_error();
- return PyString_FromString(buf);
+ return PyBytes_FromString(buf);
}
#ifdef Py_USING_UNICODE
@@ -2174,7 +2174,7 @@ posix_listdir(PyObject *self, PyObject *args)
/* Skip over . and .. */
if (strcmp(FileData.cFileName, ".") != 0 &&
strcmp(FileData.cFileName, "..") != 0) {
- v = PyString_FromString(FileData.cFileName);
+ v = PyBytes_FromString(FileData.cFileName);
if (v == NULL) {
Py_DECREF(d);
d = NULL;
@@ -2262,7 +2262,7 @@ posix_listdir(PyObject *self, PyObject *args)
/* Leave Case of Name Alone -- In Native Form */
/* (Removed Forced Lowercasing Code) */
- v = PyString_FromString(namebuf);
+ v = PyBytes_FromString(namebuf);
if (v == NULL) {
Py_DECREF(d);
d = NULL;
@@ -2312,7 +2312,7 @@ posix_listdir(PyObject *self, PyObject *args)
(NAMLEN(ep) == 1 ||
(ep->d_name[1] == '.' && NAMLEN(ep) == 2)))
continue;
- v = PyString_FromStringAndSize(ep->d_name, NAMLEN(ep));
+ v = PyBytes_FromStringAndSize(ep->d_name, NAMLEN(ep));
if (v == NULL) {
Py_DECREF(d);
d = NULL;
@@ -2397,7 +2397,7 @@ posix__getfullpathname(PyObject *self, PyObject *args)
return PyUnicode_Decode(outbuf, strlen(outbuf),
Py_FileSystemDefaultEncoding, NULL);
}
- return PyString_FromString(outbuf);
+ return PyBytes_FromString(outbuf);
} /* end of posix__getfullpathname */
#endif /* MS_WINDOWS */
@@ -3062,7 +3062,7 @@ posix_execve(PyObject *self, PyObject *args)
/* Omit Pseudo-Env Vars that Would Confuse Programs if Passed On */
if (stricmp(k, "BEGINLIBPATH") != 0 && stricmp(k, "ENDLIBPATH") != 0) {
#endif
- len = PyString_Size(key) + PyString_Size(val) + 2;
+ len = PyBytes_Size(key) + PyBytes_Size(val) + 2;
p = PyMem_NEW(char, len);
if (p == NULL) {
PyErr_NoMemory();
@@ -3292,7 +3292,7 @@ posix_spawnve(PyObject *self, PyObject *args)
{
goto fail_2;
}
- len = PyString_Size(key) + PyString_Size(val) + 2;
+ len = PyBytes_Size(key) + PyBytes_Size(val) + 2;
p = PyMem_NEW(char, len);
if (p == NULL) {
PyErr_NoMemory();
@@ -3525,7 +3525,7 @@ posix_spawnvpe(PyObject *self, PyObject *args)
{
goto fail_2;
}
- len = PyString_Size(key) + PyString_Size(val) + 2;
+ len = PyBytes_Size(key) + PyBytes_Size(val) + 2;
p = PyMem_NEW(char, len);
if (p == NULL) {
PyErr_NoMemory();
@@ -3895,7 +3895,7 @@ posix_getlogin(PyObject *self, PyObject *noargs)
"unable to determine login name");
}
else
- result = PyString_FromString(name);
+ result = PyBytes_FromString(name);
errno = old_errno;
return result;
@@ -5884,7 +5884,7 @@ posix_readlink(PyObject *self, PyObject *args)
return posix_error_with_allocated_filename(path);
PyMem_Free(path);
- v = PyString_FromStringAndSize(buf, n);
+ v = PyBytes_FromStringAndSize(buf, n);
#ifdef Py_USING_UNICODE
if (arg_is_unicode) {
PyObject *w;
@@ -6289,18 +6289,18 @@ posix_read(PyObject *self, PyObject *args)
errno = EINVAL;
return posix_error();
}
- buffer = PyString_FromStringAndSize((char *)NULL, size);
+ buffer = PyBytes_FromStringAndSize((char *)NULL, size);
if (buffer == NULL)
return NULL;
Py_BEGIN_ALLOW_THREADS
- n = read(fd, PyString_AsString(buffer), size);
+ n = read(fd, PyBytes_AsString(buffer), size);
Py_END_ALLOW_THREADS
if (n < 0) {
Py_DECREF(buffer);
return posix_error();
}
if (n != size)
- _PyString_Resize(&buffer, n);
+ _PyBytes_Resize(&buffer, n);
return buffer;
}
@@ -6647,11 +6647,11 @@ posix_putenv(PyObject *self, PyObject *args)
/* XXX This can leak memory -- not easy to fix :-( */
len = strlen(s1) + strlen(s2) + 2;
/* len includes space for a trailing \0; the size arg to
- PyString_FromStringAndSize does not count that */
- newstr = PyString_FromStringAndSize(NULL, (int)len - 1);
+ PyBytes_FromStringAndSize does not count that */
+ newstr = PyBytes_FromStringAndSize(NULL, (int)len - 1);
if (newstr == NULL)
return PyErr_NoMemory();
- newenv = PyString_AS_STRING(newstr);
+ newenv = PyBytes_AS_STRING(newstr);
PyOS_snprintf(newenv, len, "%s=%s", s1, s2);
if (putenv(newenv)) {
Py_DECREF(newstr);
@@ -6727,7 +6727,7 @@ posix_strerror(PyObject *self, PyObject *args)
"strerror() argument out of range");
return NULL;
}
- return PyString_FromString(message);
+ return PyBytes_FromString(message);
}
@@ -7009,7 +7009,7 @@ posix_tempnam(PyObject *self, PyObject *args)
#endif
if (name == NULL)
return PyErr_NoMemory();
- result = PyString_FromString(name);
+ result = PyBytes_FromString(name);
free(name);
return result;
}
@@ -7066,7 +7066,7 @@ posix_tmpnam(PyObject *self, PyObject *noargs)
Py_XDECREF(err);
return NULL;
}
- return PyString_FromString(buffer);
+ return PyBytes_FromString(buffer);
}
#endif
@@ -7095,13 +7095,13 @@ conv_confname(PyObject *arg, int *valuep, struct constdef *table,
*valuep = PyInt_AS_LONG(arg);
return 1;
}
- if (PyString_Check(arg)) {
+ if (PyBytes_Check(arg)) {
/* look up the value in the table using a binary search */
size_t lo = 0;
size_t mid;
size_t hi = tablesize;
int cmp;
- char *confname = PyString_AS_STRING(arg);
+ char *confname = PyBytes_AS_STRING(arg);
while (lo < hi) {
mid = (lo + hi) / 2;
cmp = strcmp(confname, table[mid].name);
@@ -7431,12 +7431,12 @@ posix_confstr(PyObject *self, PyObject *args)
}
else {
if ((unsigned int)len >= sizeof(buffer)) {
- result = PyString_FromStringAndSize(NULL, len-1);
+ result = PyBytes_FromStringAndSize(NULL, len-1);
if (result != NULL)
- confstr(name, PyString_AS_STRING(result), len);
+ confstr(name, PyBytes_AS_STRING(result), len);
}
else
- result = PyString_FromStringAndSize(buffer, len-1);
+ result = PyBytes_FromStringAndSize(buffer, len-1);
}
}
return result;
@@ -8225,11 +8225,11 @@ win32_urandom(PyObject *self, PyObject *args)
}
/* Allocate bytes */
- result = PyString_FromStringAndSize(NULL, howMany);
+ result = PyBytes_FromStringAndSize(NULL, howMany);
if (result != NULL) {
/* Get random data */
if (! pCryptGenRandom(hCryptProv, howMany, (unsigned char*)
- PyString_AS_STRING(result))) {
+ PyBytes_AS_STRING(result))) {
Py_DECREF(result);
return win32_error("CryptGenRandom", NULL);
}
@@ -8259,11 +8259,11 @@ vms_urandom(PyObject *self, PyObject *args)
"negative argument not allowed");
/* Allocate bytes */
- result = PyString_FromStringAndSize(NULL, howMany);
+ result = PyBytes_FromStringAndSize(NULL, howMany);
if (result != NULL) {
/* Get random data */
if (RAND_pseudo_bytes((unsigned char*)
- PyString_AS_STRING(result),
+ PyBytes_AS_STRING(result),
howMany) < 0) {
Py_DECREF(result);
return PyErr_Format(PyExc_ValueError,
diff --git a/Modules/pwdmodule.c b/Modules/pwdmodule.c
index 9e01f48757..dff1bcbc52 100644
--- a/Modules/pwdmodule.c
+++ b/Modules/pwdmodule.c
@@ -49,7 +49,7 @@ static void
sets(PyObject *v, int i, char* val)
{
if (val)
- PyStructSequence_SET_ITEM(v, i, PyString_FromString(val));
+ PyStructSequence_SET_ITEM(v, i, PyBytes_FromString(val));
else {
PyStructSequence_SET_ITEM(v, i, Py_None);
Py_INCREF(Py_None);
diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c
index 01971b78ed..f85b2efa16 100644
--- a/Modules/pyexpat.c
+++ b/Modules/pyexpat.c
@@ -153,7 +153,7 @@ get_handler_name(struct HandlerInfo *hinfo)
{
PyObject *name = hinfo->nameobj;
if (name == NULL) {
- name = PyString_FromString(hinfo->name);
+ name = PyBytes_FromString(hinfo->name);
hinfo->nameobj = name;
}
Py_XINCREF(name);
@@ -205,7 +205,7 @@ conv_string_to_utf8(const XML_Char *str)
Py_INCREF(Py_None);
return Py_None;
}
- return PyString_FromString(str);
+ return PyBytes_FromString(str);
}
static PyObject *
@@ -218,7 +218,7 @@ conv_string_len_to_utf8(const XML_Char *str, int len)
Py_INCREF(Py_None);
return Py_None;
}
- return PyString_FromStringAndSize((const char *)str, len);
+ return PyBytes_FromStringAndSize((const char *)str, len);
}
/* Callback routines */
@@ -267,16 +267,16 @@ getcode(enum HandlerTypes slot, char* func_name, int lineno)
PyObject *filename = NULL;
if (handler_info[slot].tb_code == NULL) {
- code = PyString_FromString("");
+ code = PyBytes_FromString("");
if (code == NULL)
goto failed;
- name = PyString_FromString(func_name);
+ name = PyBytes_FromString(func_name);
if (name == NULL)
goto failed;
nulltuple = PyTuple_New(0);
if (nulltuple == NULL)
goto failed;
- filename = PyString_FromString(__FILE__);
+ filename = PyBytes_FromString(__FILE__);
handler_info[slot].tb_code =
PyCode_New(0, /* argcount */
0, /* nlocals */
@@ -971,13 +971,13 @@ readinst(char *buf, int buf_size, PyObject *meth)
goto finally;
/* XXX what to do if it returns a Unicode string? */
- if (!PyString_Check(str)) {
+ if (!PyBytes_Check(str)) {
PyErr_Format(PyExc_TypeError,
"read() did not return a string object (type=%.400s)",
Py_TYPE(str)->tp_name);
goto finally;
}
- len = PyString_GET_SIZE(str);
+ len = PyBytes_GET_SIZE(str);
if (len > buf_size) {
PyErr_Format(PyExc_ValueError,
"read() returned too much data: "
@@ -985,7 +985,7 @@ readinst(char *buf, int buf_size, PyObject *meth)
buf_size, len);
goto finally;
}
- memcpy(buf, PyString_AsString(str), len);
+ memcpy(buf, PyBytes_AsString(str), len);
finally:
Py_XDECREF(arg);
Py_XDECREF(str);
@@ -1094,7 +1094,7 @@ xmlparse_GetInputContext(xmlparseobject *self, PyObject *unused)
= XML_GetInputContext(self->itself, &offset, &size);
if (buffer != NULL)
- return PyString_FromStringAndSize(buffer + offset,
+ return PyBytes_FromStringAndSize(buffer + offset,
size - offset);
else
Py_RETURN_NONE;
@@ -1511,7 +1511,7 @@ xmlparse_getattr(xmlparseobject *self, char *name)
#define APPEND(list, str) \
do { \
- PyObject *o = PyString_FromString(str); \
+ PyObject *o = PyBytes_FromString(str); \
if (o != NULL) \
PyList_Append(list, o); \
Py_XDECREF(o); \
@@ -1862,7 +1862,7 @@ get_version_string(void)
while (rev[i] != ' ' && rev[i] != '\0')
++i;
- return PyString_FromStringAndSize(rev, i);
+ return PyBytes_FromStringAndSize(rev, i);
}
/* Initialization function for the module */
@@ -1889,7 +1889,7 @@ PyMODINIT_FUNC
MODULE_INITFUNC(void)
{
PyObject *m, *d;
- PyObject *errmod_name = PyString_FromString(MODULE_NAME ".errors");
+ PyObject *errmod_name = PyBytes_FromString(MODULE_NAME ".errors");
PyObject *errors_module;
PyObject *modelmod_name;
PyObject *model_module;
@@ -1899,7 +1899,7 @@ MODULE_INITFUNC(void)
if (errmod_name == NULL)
return;
- modelmod_name = PyString_FromString(MODULE_NAME ".model");
+ modelmod_name = PyBytes_FromString(MODULE_NAME ".model");
if (modelmod_name == NULL)
return;
diff --git a/Modules/readline.c b/Modules/readline.c
index 90904ab434..f988d5001a 100644
--- a/Modules/readline.c
+++ b/Modules/readline.c
@@ -421,7 +421,7 @@ add a line to the history buffer");
static PyObject *
get_completer_delims(PyObject *self, PyObject *noarg)
{
- return PyString_FromString(rl_completer_word_break_characters);
+ return PyBytes_FromString(rl_completer_word_break_characters);
}
PyDoc_STRVAR(doc_get_completer_delims,
@@ -471,7 +471,7 @@ get_history_item(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "i:index", &idx))
return NULL;
if ((hist_ent = history_get(idx)))
- return PyString_FromString(hist_ent->line);
+ return PyBytes_FromString(hist_ent->line);
else {
Py_RETURN_NONE;
}
@@ -503,7 +503,7 @@ return the current (not the maximum) length of history.");
static PyObject *
get_line_buffer(PyObject *self, PyObject *noarg)
{
- return PyString_FromString(rl_line_buffer);
+ return PyBytes_FromString(rl_line_buffer);
}
PyDoc_STRVAR(doc_get_line_buffer,
@@ -676,7 +676,7 @@ on_completion_display_matches_hook(char **matches,
if (m == NULL)
goto error;
for (i = 0; i < num_matches; i++) {
- s = PyString_FromString(matches[i+1]);
+ s = PyBytes_FromString(matches[i+1]);
if (s == NULL)
goto error;
if (PyList_SetItem(m, i, s) == -1)
@@ -725,7 +725,7 @@ on_completion(const char *text, int state)
result = NULL;
}
else {
- char *s = PyString_AsString(r);
+ char *s = PyBytes_AsString(r);
if (s == NULL)
goto error;
result = strdup(s);
diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c
index 83a6538a41..252332dc6b 100644
--- a/Modules/selectmodule.c
+++ b/Modules/selectmodule.c
@@ -1219,7 +1219,7 @@ kqueue_event_repr(kqueue_event_Object *s)
"data=0x%lx udata=%p>",
(unsigned long)(s->e.ident), s->e.filter, s->e.flags,
s->e.fflags, (long)(s->e.data), s->e.udata);
- return PyString_FromString(buf);
+ return PyBytes_FromString(buf);
}
static int
diff --git a/Modules/sha256module.c b/Modules/sha256module.c
index 7d56900201..d2eefa4429 100644
--- a/Modules/sha256module.c
+++ b/Modules/sha256module.c
@@ -432,7 +432,7 @@ SHA256_digest(SHAobject *self, PyObject *unused)
SHAcopy(self, &temp);
sha_final(digest, &temp);
- return PyString_FromStringAndSize((const char *)digest, self->digestsize);
+ return PyBytes_FromStringAndSize((const char *)digest, self->digestsize);
}
PyDoc_STRVAR(SHA256_hexdigest__doc__,
@@ -452,10 +452,10 @@ SHA256_hexdigest(SHAobject *self, PyObject *unused)
sha_final(digest, &temp);
/* Create a new string */
- retval = PyString_FromStringAndSize(NULL, self->digestsize * 2);
+ retval = PyBytes_FromStringAndSize(NULL, self->digestsize * 2);
if (!retval)
return NULL;
- hex_digest = PyString_AsString(retval);
+ hex_digest = PyBytes_AsString(retval);
if (!hex_digest) {
Py_DECREF(retval);
return NULL;
@@ -510,9 +510,9 @@ static PyObject *
SHA256_get_name(PyObject *self, void *closure)
{
if (((SHAobject *)self)->digestsize == 32)
- return PyString_FromStringAndSize("SHA256", 6);
+ return PyBytes_FromStringAndSize("SHA256", 6);
else
- return PyString_FromStringAndSize("SHA224", 6);
+ return PyBytes_FromStringAndSize("SHA224", 6);
}
static PyGetSetDef SHA_getseters[] = {
diff --git a/Modules/sha512module.c b/Modules/sha512module.c
index f2c230b3fa..1a2b145aa5 100644
--- a/Modules/sha512module.c
+++ b/Modules/sha512module.c
@@ -498,7 +498,7 @@ SHA512_digest(SHAobject *self, PyObject *unused)
SHAcopy(self, &temp);
sha512_final(digest, &temp);
- return PyString_FromStringAndSize((const char *)digest, self->digestsize);
+ return PyBytes_FromStringAndSize((const char *)digest, self->digestsize);
}
PyDoc_STRVAR(SHA512_hexdigest__doc__,
@@ -518,10 +518,10 @@ SHA512_hexdigest(SHAobject *self, PyObject *unused)
sha512_final(digest, &temp);
/* Create a new string */
- retval = PyString_FromStringAndSize(NULL, self->digestsize * 2);
+ retval = PyBytes_FromStringAndSize(NULL, self->digestsize * 2);
if (!retval)
return NULL;
- hex_digest = PyString_AsString(retval);
+ hex_digest = PyBytes_AsString(retval);
if (!hex_digest) {
Py_DECREF(retval);
return NULL;
@@ -576,9 +576,9 @@ static PyObject *
SHA512_get_name(PyObject *self, void *closure)
{
if (((SHAobject *)self)->digestsize == 64)
- return PyString_FromStringAndSize("SHA512", 6);
+ return PyBytes_FromStringAndSize("SHA512", 6);
else
- return PyString_FromStringAndSize("SHA384", 6);
+ return PyBytes_FromStringAndSize("SHA384", 6);
}
static PyGetSetDef SHA_getseters[] = {
diff --git a/Modules/shamodule.c b/Modules/shamodule.c
index 1a7fc2c5ee..0cb8784048 100644
--- a/Modules/shamodule.c
+++ b/Modules/shamodule.c
@@ -380,7 +380,7 @@ SHA_digest(SHAobject *self, PyObject *unused)
SHAcopy(self, &temp);
sha_final(digest, &temp);
- return PyString_FromStringAndSize((const char *)digest, sizeof(digest));
+ return PyBytes_FromStringAndSize((const char *)digest, sizeof(digest));
}
PyDoc_STRVAR(SHA_hexdigest__doc__,
@@ -400,10 +400,10 @@ SHA_hexdigest(SHAobject *self, PyObject *unused)
sha_final(digest, &temp);
/* Create a new string */
- retval = PyString_FromStringAndSize(NULL, sizeof(digest) * 2);
+ retval = PyBytes_FromStringAndSize(NULL, sizeof(digest) * 2);
if (!retval)
return NULL;
- hex_digest = PyString_AsString(retval);
+ hex_digest = PyBytes_AsString(retval);
if (!hex_digest) {
Py_DECREF(retval);
return NULL;
@@ -463,7 +463,7 @@ SHA_get_digest_size(PyObject *self, void *closure)
static PyObject *
SHA_get_name(PyObject *self, void *closure)
{
- return PyString_FromStringAndSize("SHA1", 4);
+ return PyBytes_FromStringAndSize("SHA1", 4);
}
static PyGetSetDef SHA_getseters[] = {
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index e9568315d4..fd6b5531ba 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -911,7 +911,7 @@ makeipaddr(struct sockaddr *addr, int addrlen)
set_gaierror(error);
return NULL;
}
- return PyString_FromString(buf);
+ return PyBytes_FromString(buf);
}
@@ -955,7 +955,7 @@ makebdaddr(bdaddr_t *bdaddr)
sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X",
bdaddr->b[5], bdaddr->b[4], bdaddr->b[3],
bdaddr->b[2], bdaddr->b[1], bdaddr->b[0]);
- return PyString_FromString(buf);
+ return PyBytes_FromString(buf);
}
#endif
@@ -1002,14 +1002,14 @@ makesockaddr(int sockfd, struct sockaddr *addr, int addrlen, int proto)
#ifdef linux
if (a->sun_path[0] == 0) { /* Linux abstract namespace */
addrlen -= offsetof(struct sockaddr_un, sun_path);
- return PyString_FromStringAndSize(a->sun_path,
+ return PyBytes_FromStringAndSize(a->sun_path,
addrlen);
}
else
#endif /* linux */
{
/* regular NULL-terminated string */
- return PyString_FromString(a->sun_path);
+ return PyBytes_FromString(a->sun_path);
}
}
#endif /* AF_UNIX */
@@ -1362,7 +1362,7 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
addr = (struct sockaddr_sco *)addr_ret;
_BT_SCO_MEMB(addr, family) = AF_BLUETOOTH;
- straddr = PyString_AsString(args);
+ straddr = PyBytes_AsString(args);
if (straddr == NULL) {
PyErr_SetString(socket_error, "getsockaddrarg: "
"wrong format");
@@ -1854,16 +1854,16 @@ sock_getsockopt(PySocketSockObject *s, PyObject *args)
"getsockopt buflen out of range");
return NULL;
}
- buf = PyString_FromStringAndSize((char *)NULL, buflen);
+ buf = PyBytes_FromStringAndSize((char *)NULL, buflen);
if (buf == NULL)
return NULL;
res = getsockopt(s->sock_fd, level, optname,
- (void *)PyString_AS_STRING(buf), &buflen);
+ (void *)PyBytes_AS_STRING(buf), &buflen);
if (res < 0) {
Py_DECREF(buf);
return s->errorhandler();
}
- _PyString_Resize(&buf, buflen);
+ _PyBytes_Resize(&buf, buflen);
return buf;
#endif /* __BEOS__ */
}
@@ -2386,12 +2386,12 @@ sock_recv(PySocketSockObject *s, PyObject *args)
}
/* Allocate a new string. */
- buf = PyString_FromStringAndSize((char *) 0, recvlen);
+ buf = PyBytes_FromStringAndSize((char *) 0, recvlen);
if (buf == NULL)
return NULL;
/* Call the guts */
- outlen = sock_recv_guts(s, PyString_AS_STRING(buf), recvlen, flags);
+ outlen = sock_recv_guts(s, PyBytes_AS_STRING(buf), recvlen, flags);
if (outlen < 0) {
/* An error occurred, release the string and return an
error. */
@@ -2401,7 +2401,7 @@ sock_recv(PySocketSockObject *s, PyObject *args)
if (outlen != recvlen) {
/* We did not read as many bytes as we anticipated, resize the
string if possible and be succesful. */
- if (_PyString_Resize(&buf, outlen) < 0)
+ if (_PyBytes_Resize(&buf, outlen) < 0)
/* Oopsy, not so succesful after all. */
return NULL;
}
@@ -2560,11 +2560,11 @@ sock_recvfrom(PySocketSockObject *s, PyObject *args)
return NULL;
}
- buf = PyString_FromStringAndSize((char *) 0, recvlen);
+ buf = PyBytes_FromStringAndSize((char *) 0, recvlen);
if (buf == NULL)
return NULL;
- outlen = sock_recvfrom_guts(s, PyString_AS_STRING(buf),
+ outlen = sock_recvfrom_guts(s, PyBytes_AS_STRING(buf),
recvlen, flags, &addr);
if (outlen < 0) {
goto finally;
@@ -2573,7 +2573,7 @@ sock_recvfrom(PySocketSockObject *s, PyObject *args)
if (outlen != recvlen) {
/* We did not read as many bytes as we anticipated, resize the
string if possible and be succesful. */
- if (_PyString_Resize(&buf, outlen) < 0)
+ if (_PyBytes_Resize(&buf, outlen) < 0)
/* Oopsy, not so succesful after all. */
goto finally;
}
@@ -2941,7 +2941,7 @@ sock_repr(PySocketSockObject *s)
(long)s->sock_fd, s->sock_family,
s->sock_type,
s->sock_proto);
- return PyString_FromString(buf);
+ return PyBytes_FromString(buf);
}
@@ -3057,7 +3057,7 @@ socket_gethostname(PyObject *self, PyObject *unused)
if (res < 0)
return set_error();
buf[sizeof buf - 1] = '\0';
- return PyString_FromString(buf);
+ return PyBytes_FromString(buf);
}
PyDoc_STRVAR(gethostname_doc,
@@ -3143,7 +3143,7 @@ gethost_common(struct hostent *h, struct sockaddr *addr, int alen, int af)
if (h->h_aliases) {
for (pch = h->h_aliases; *pch != NULL; pch++) {
int status;
- tmp = PyString_FromString(*pch);
+ tmp = PyBytes_FromString(*pch);
if (tmp == NULL)
goto err;
@@ -3432,7 +3432,7 @@ socket_getservbyport(PyObject *self, PyObject *args)
PyErr_SetString(socket_error, "port/proto not found");
return NULL;
}
- return PyString_FromString(sp->s_name);
+ return PyBytes_FromString(sp->s_name);
}
PyDoc_STRVAR(getservbyport_doc,
@@ -3734,7 +3734,7 @@ socket_inet_aton(PyObject *self, PyObject *args)
if (inet_aton != NULL) {
#endif
if (inet_aton(ip_addr, &buf))
- return PyString_FromStringAndSize((char *)(&buf),
+ return PyBytes_FromStringAndSize((char *)(&buf),
sizeof(buf));
PyErr_SetString(socket_error,
@@ -3763,7 +3763,7 @@ socket_inet_aton(PyObject *self, PyObject *args)
return NULL;
}
}
- return PyString_FromStringAndSize((char *) &packed_addr,
+ return PyBytes_FromStringAndSize((char *) &packed_addr,
sizeof(packed_addr));
#ifdef USE_INET_ATON_WEAKLINK
@@ -3797,7 +3797,7 @@ socket_inet_ntoa(PyObject *self, PyObject *args)
memcpy(&packed_addr, packed_str, addr_len);
- return PyString_FromString(inet_ntoa(packed_addr));
+ return PyBytes_FromString(inet_ntoa(packed_addr));
}
#ifdef HAVE_INET_PTON
@@ -3840,11 +3840,11 @@ socket_inet_pton(PyObject *self, PyObject *args)
"illegal IP address string passed to inet_pton");
return NULL;
} else if (af == AF_INET) {
- return PyString_FromStringAndSize(packed,
+ return PyBytes_FromStringAndSize(packed,
sizeof(struct in_addr));
#ifdef ENABLE_IPV6
} else if (af == AF_INET6) {
- return PyString_FromStringAndSize(packed,
+ return PyBytes_FromStringAndSize(packed,
sizeof(struct in6_addr));
#endif
} else {
@@ -3871,7 +3871,7 @@ socket_inet_ntop(PyObject *self, PyObject *args)
char ip[INET_ADDRSTRLEN + 1];
#endif
- /* Guarantee NUL-termination for PyString_FromString() below */
+ /* Guarantee NUL-termination for PyBytes_FromString() below */
memset((void *) &ip[0], '\0', sizeof(ip));
if (!PyArg_ParseTuple(args, "is#:inet_ntop", &af, &packed, &len)) {
@@ -3903,7 +3903,7 @@ socket_inet_ntop(PyObject *self, PyObject *args)
PyErr_SetFromErrno(socket_error);
return NULL;
} else {
- return PyString_FromString(retval);
+ return PyBytes_FromString(retval);
}
/* NOTREACHED */
@@ -3944,9 +3944,9 @@ socket_getaddrinfo(PyObject *self, PyObject *args)
idna = PyObject_CallMethod(hobj, "encode", "s", "idna");
if (!idna)
return NULL;
- hptr = PyString_AsString(idna);
- } else if (PyString_Check(hobj)) {
- hptr = PyString_AsString(hobj);
+ hptr = PyBytes_AsString(idna);
+ } else if (PyBytes_Check(hobj)) {
+ hptr = PyBytes_AsString(hobj);
} else {
PyErr_SetString(PyExc_TypeError,
"getaddrinfo() argument 1 must be string or None");
@@ -3955,8 +3955,8 @@ socket_getaddrinfo(PyObject *self, PyObject *args)
if (PyInt_Check(pobj)) {
PyOS_snprintf(pbuf, sizeof(pbuf), "%ld", PyInt_AsLong(pobj));
pptr = pbuf;
- } else if (PyString_Check(pobj)) {
- pptr = PyString_AsString(pobj);
+ } else if (PyBytes_Check(pobj)) {
+ pptr = PyBytes_AsString(pobj);
} else if (pobj == Py_None) {
pptr = (char *)NULL;
} else {
diff --git a/Modules/spwdmodule.c b/Modules/spwdmodule.c
index d3f309afa8..221223ec25 100644
--- a/Modules/spwdmodule.c
+++ b/Modules/spwdmodule.c
@@ -60,7 +60,7 @@ static void
sets(PyObject *v, int i, char* val)
{
if (val)
- PyStructSequence_SET_ITEM(v, i, PyString_FromString(val));
+ PyStructSequence_SET_ITEM(v, i, PyBytes_FromString(val));
else {
PyStructSequence_SET_ITEM(v, i, Py_None);
Py_INCREF(Py_None);
diff --git a/Modules/stropmodule.c b/Modules/stropmodule.c
index 8b00fed69a..e0e5ad0d6f 100644
--- a/Modules/stropmodule.c
+++ b/Modules/stropmodule.c
@@ -47,7 +47,7 @@ split_whitespace(char *s, Py_ssize_t len, Py_ssize_t maxsplit)
i = i+1;
}
if (j < i) {
- item = PyString_FromStringAndSize(s+j, i-j);
+ item = PyBytes_FromStringAndSize(s+j, i-j);
if (item == NULL)
goto finally;
@@ -61,7 +61,7 @@ split_whitespace(char *s, Py_ssize_t len, Py_ssize_t maxsplit)
i = i+1;
}
if (maxsplit && (countsplit >= maxsplit) && i < len) {
- item = PyString_FromStringAndSize(
+ item = PyBytes_FromStringAndSize(
s+i, len - i);
if (item == NULL)
goto finally;
@@ -122,7 +122,7 @@ strop_splitfields(PyObject *self, PyObject *args)
i = j = 0;
while (i+n <= len) {
if (s[i] == sub[0] && (n == 1 || memcmp(s+i, sub, n) == 0)) {
- item = PyString_FromStringAndSize(s+j, i-j);
+ item = PyBytes_FromStringAndSize(s+j, i-j);
if (item == NULL)
goto fail;
err = PyList_Append(list, item);
@@ -137,7 +137,7 @@ strop_splitfields(PyObject *self, PyObject *args)
else
i++;
}
- item = PyString_FromStringAndSize(s+j, len-j);
+ item = PyBytes_FromStringAndSize(s+j, len-j);
if (item == NULL)
goto fail;
err = PyList_Append(list, item);
@@ -189,7 +189,7 @@ strop_joinfields(PyObject *self, PyObject *args)
if (seqlen == 1) {
/* Optimization if there's only one item */
PyObject *item = PySequence_GetItem(seq, 0);
- if (item && !PyString_Check(item)) {
+ if (item && !PyBytes_Check(item)) {
PyErr_SetString(PyExc_TypeError,
"first argument must be sequence of strings");
Py_DECREF(item);
@@ -198,9 +198,9 @@ strop_joinfields(PyObject *self, PyObject *args)
return item;
}
- if (!(res = PyString_FromStringAndSize((char*)NULL, sz)))
+ if (!(res = PyBytes_FromStringAndSize((char*)NULL, sz)))
return NULL;
- p = PyString_AsString(res);
+ p = PyBytes_AsString(res);
/* optimize for lists, since it's the most common case. all others
* (tuples and arbitrary sequences) just use the sequence abstract
@@ -209,29 +209,29 @@ strop_joinfields(PyObject *self, PyObject *args)
if (PyList_Check(seq)) {
for (i = 0; i < seqlen; i++) {
PyObject *item = PyList_GET_ITEM(seq, i);
- if (!PyString_Check(item)) {
+ if (!PyBytes_Check(item)) {
PyErr_SetString(PyExc_TypeError,
"first argument must be sequence of strings");
Py_DECREF(res);
return NULL;
}
- slen = PyString_GET_SIZE(item);
+ slen = PyBytes_GET_SIZE(item);
while (reslen + slen + seplen >= sz) {
- if (_PyString_Resize(&res, sz * 2) < 0)
+ if (_PyBytes_Resize(&res, sz * 2) < 0)
return NULL;
sz *= 2;
- p = PyString_AsString(res) + reslen;
+ p = PyBytes_AsString(res) + reslen;
}
if (i > 0) {
memcpy(p, sep, seplen);
p += seplen;
reslen += seplen;
}
- memcpy(p, PyString_AS_STRING(item), slen);
+ memcpy(p, PyBytes_AS_STRING(item), slen);
p += slen;
reslen += slen;
}
- _PyString_Resize(&res, reslen);
+ _PyBytes_Resize(&res, reslen);
return res;
}
@@ -245,33 +245,33 @@ strop_joinfields(PyObject *self, PyObject *args)
/* This is now type safe */
for (i = 0; i < seqlen; i++) {
PyObject *item = getitemfunc(seq, i);
- if (!item || !PyString_Check(item)) {
+ if (!item || !PyBytes_Check(item)) {
PyErr_SetString(PyExc_TypeError,
"first argument must be sequence of strings");
Py_DECREF(res);
Py_XDECREF(item);
return NULL;
}
- slen = PyString_GET_SIZE(item);
+ slen = PyBytes_GET_SIZE(item);
while (reslen + slen + seplen >= sz) {
- if (_PyString_Resize(&res, sz * 2) < 0) {
+ if (_PyBytes_Resize(&res, sz * 2) < 0) {
Py_DECREF(item);
return NULL;
}
sz *= 2;
- p = PyString_AsString(res) + reslen;
+ p = PyBytes_AsString(res) + reslen;
}
if (i > 0) {
memcpy(p, sep, seplen);
p += seplen;
reslen += seplen;
}
- memcpy(p, PyString_AS_STRING(item), slen);
+ memcpy(p, PyBytes_AS_STRING(item), slen);
p += slen;
reslen += slen;
Py_DECREF(item);
}
- _PyString_Resize(&res, reslen);
+ _PyBytes_Resize(&res, reslen);
return res;
}
@@ -369,7 +369,7 @@ do_strip(PyObject *args, int striptype)
Py_ssize_t len, i, j;
- if (PyString_AsStringAndSize(args, &s, &len))
+ if (PyBytes_AsStringAndSize(args, &s, &len))
return NULL;
i = 0;
@@ -392,7 +392,7 @@ do_strip(PyObject *args, int striptype)
return args;
}
else
- return PyString_FromStringAndSize(s+i, j-i);
+ return PyBytes_FromStringAndSize(s+i, j-i);
}
@@ -450,12 +450,12 @@ strop_lower(PyObject *self, PyObject *args)
int changed;
WARN;
- if (PyString_AsStringAndSize(args, &s, &n))
+ if (PyBytes_AsStringAndSize(args, &s, &n))
return NULL;
- newstr = PyString_FromStringAndSize(NULL, n);
+ newstr = PyBytes_FromStringAndSize(NULL, n);
if (newstr == NULL)
return NULL;
- s_new = PyString_AsString(newstr);
+ s_new = PyBytes_AsString(newstr);
changed = 0;
for (i = 0; i < n; i++) {
int c = Py_CHARMASK(*s++);
@@ -489,12 +489,12 @@ strop_upper(PyObject *self, PyObject *args)
int changed;
WARN;
- if (PyString_AsStringAndSize(args, &s, &n))
+ if (PyBytes_AsStringAndSize(args, &s, &n))
return NULL;
- newstr = PyString_FromStringAndSize(NULL, n);
+ newstr = PyBytes_FromStringAndSize(NULL, n);
if (newstr == NULL)
return NULL;
- s_new = PyString_AsString(newstr);
+ s_new = PyBytes_AsString(newstr);
changed = 0;
for (i = 0; i < n; i++) {
int c = Py_CHARMASK(*s++);
@@ -529,12 +529,12 @@ strop_capitalize(PyObject *self, PyObject *args)
int changed;
WARN;
- if (PyString_AsStringAndSize(args, &s, &n))
+ if (PyBytes_AsStringAndSize(args, &s, &n))
return NULL;
- newstr = PyString_FromStringAndSize(NULL, n);
+ newstr = PyBytes_FromStringAndSize(NULL, n);
if (newstr == NULL)
return NULL;
- s_new = PyString_AsString(newstr);
+ s_new = PyBytes_AsString(newstr);
changed = 0;
if (0 < n) {
int c = Py_CHARMASK(*s++);
@@ -610,12 +610,12 @@ strop_expandtabs(PyObject *self, PyObject *args)
}
/* Second pass: create output string and fill it */
- out = PyString_FromStringAndSize(NULL, i+j);
+ out = PyBytes_FromStringAndSize(NULL, i+j);
if (out == NULL)
return NULL;
i = 0;
- q = PyString_AS_STRING(out);
+ q = PyBytes_AS_STRING(out);
for (p = string; p < e; p++) {
if (*p == '\t') {
@@ -695,12 +695,12 @@ strop_swapcase(PyObject *self, PyObject *args)
int changed;
WARN;
- if (PyString_AsStringAndSize(args, &s, &n))
+ if (PyBytes_AsStringAndSize(args, &s, &n))
return NULL;
- newstr = PyString_FromStringAndSize(NULL, n);
+ newstr = PyBytes_FromStringAndSize(NULL, n);
if (newstr == NULL)
return NULL;
- s_new = PyString_AsString(newstr);
+ s_new = PyBytes_AsString(newstr);
changed = 0;
for (i = 0; i < n; i++) {
int c = Py_CHARMASK(*s++);
@@ -898,10 +898,10 @@ strop_maketrans(PyObject *self, PyObject *args)
return NULL;
}
- result = PyString_FromStringAndSize((char *)NULL, 256);
+ result = PyBytes_FromStringAndSize((char *)NULL, 256);
if (result == NULL)
return NULL;
- c = (unsigned char *) PyString_AS_STRING((PyStringObject *)result);
+ c = (unsigned char *) PyBytes_AS_STRING((PyBytesObject *)result);
for (i = 0; i < 256; i++)
c[i]=(unsigned char)i;
for (i = 0; i < fromlen; i++)
@@ -942,12 +942,12 @@ strop_translate(PyObject *self, PyObject *args)
}
table = table1;
- inlen = PyString_GET_SIZE(input_obj);
- result = PyString_FromStringAndSize((char *)NULL, inlen);
+ inlen = PyBytes_GET_SIZE(input_obj);
+ result = PyBytes_FromStringAndSize((char *)NULL, inlen);
if (result == NULL)
return NULL;
- output_start = output = PyString_AsString(result);
- input = PyString_AsString(input_obj);
+ output_start = output = PyBytes_AsString(result);
+ input = PyBytes_AsString(input_obj);
if (dellen == 0) {
/* If no deletions are required, use faster code */
@@ -983,7 +983,7 @@ strop_translate(PyObject *self, PyObject *args)
}
/* Fix the size of the resulting string */
if (inlen > 0)
- _PyString_Resize(&result, output - output_start);
+ _PyBytes_Resize(&result, output - output_start);
return result;
}
@@ -1169,7 +1169,7 @@ strop_replace(PyObject *self, PyObject *args)
Py_XINCREF(newstr);
}
else {
- newstr = PyString_FromStringAndSize(new_s, out_len);
+ newstr = PyBytes_FromStringAndSize(new_s, out_len);
PyMem_FREE(new_s);
}
return newstr;
@@ -1222,7 +1222,7 @@ initstrop(void)
if (isspace(c))
buf[n++] = c;
}
- s = PyString_FromStringAndSize(buf, n);
+ s = PyBytes_FromStringAndSize(buf, n);
if (s)
PyModule_AddObject(m, "whitespace", s);
@@ -1232,7 +1232,7 @@ initstrop(void)
if (islower(c))
buf[n++] = c;
}
- s = PyString_FromStringAndSize(buf, n);
+ s = PyBytes_FromStringAndSize(buf, n);
if (s)
PyModule_AddObject(m, "lowercase", s);
@@ -1242,7 +1242,7 @@ initstrop(void)
if (isupper(c))
buf[n++] = c;
}
- s = PyString_FromStringAndSize(buf, n);
+ s = PyBytes_FromStringAndSize(buf, n);
if (s)
PyModule_AddObject(m, "uppercase", s);
}
diff --git a/Modules/sunaudiodev.c b/Modules/sunaudiodev.c
index 285dc66ddd..f4b430e207 100644
--- a/Modules/sunaudiodev.c
+++ b/Modules/sunaudiodev.c
@@ -135,11 +135,11 @@ sad_read(sadobject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "i:read", &size))
return NULL;
- rv = PyString_FromStringAndSize(NULL, size);
+ rv = PyBytes_FromStringAndSize(NULL, size);
if (rv == NULL)
return NULL;
- if (!(cp = PyString_AsString(rv)))
+ if (!(cp = PyBytes_AsString(rv)))
goto finally;
count = read(self->x_fd, cp, size);
diff --git a/Modules/svmodule.c b/Modules/svmodule.c
index 3845e20f62..485259fa7e 100644
--- a/Modules/svmodule.c
+++ b/Modules/svmodule.c
@@ -47,13 +47,13 @@ svc_conversion(captureobject *self, PyObject *args, void (*function)(), float fa
if (!PyArg_Parse(args, "i", &invert))
return NULL;
- if (!(output = PyString_FromStringAndSize(
+ if (!(output = PyBytes_FromStringAndSize(
NULL,
(int)(self->ob_info.width * self->ob_info.height * factor))))
{
return NULL;
}
- if (!(outstr = PyString_AsString(output))) {
+ if (!(outstr = PyBytes_AsString(output))) {
Py_DECREF(output);
return NULL;
}
@@ -152,9 +152,9 @@ svc_GetFields(captureobject *self, PyObject *args)
fieldsize = self->ob_info.width * self->ob_info.height / 2;
obcapture = (char*)self->ob_capture;
- if (!(f1 = PyString_FromStringAndSize(obcapture, fieldsize)))
+ if (!(f1 = PyBytes_FromStringAndSize(obcapture, fieldsize)))
goto finally;
- if (!(f2 = PyString_FromStringAndSize(obcapture + fieldsize,
+ if (!(f2 = PyBytes_FromStringAndSize(obcapture + fieldsize,
fieldsize)))
goto finally;
ret = PyTuple_Pack(2, f1, f2);
@@ -535,12 +535,12 @@ sv_CaptureBurst(svobject *self, PyObject *args)
goto finally;
}
- if (!(videodata = PyString_FromStringAndSize(NULL, bytes)))
+ if (!(videodata = PyBytes_FromStringAndSize(NULL, bytes)))
goto finally;
/* XXX -- need to do something about the bitvector */
{
- char* str = PyString_AsString(videodata);
+ char* str = PyBytes_AsString(videodata);
if (!str)
goto finally;
@@ -615,10 +615,10 @@ sv_CaptureOneFrame(svobject *self, PyObject *args)
if (svQueryCaptureBufferSize(self->ob_svideo, &info, &bytes))
return sv_error();
- if (!(videodata = PyString_FromStringAndSize(NULL, bytes)))
+ if (!(videodata = PyBytes_FromStringAndSize(NULL, bytes)))
return NULL;
- str = PyString_AsString(videodata);
+ str = PyBytes_AsString(videodata);
if (!str)
goto finally;
@@ -849,11 +849,11 @@ sv_conversion(PyObject *self, PyObject *args, void (*function)(),
return NULL;
}
- if (!(output = PyString_FromStringAndSize(NULL,
+ if (!(output = PyBytes_FromStringAndSize(NULL,
(int)(width * height * factor))))
return NULL;
- str = PyString_AsString(output);
+ str = PyBytes_AsString(output);
if (!str) {
Py_DECREF(output);
return NULL;
diff --git a/Modules/syslogmodule.c b/Modules/syslogmodule.c
index 9e1ed0619f..a515a178b0 100644
--- a/Modules/syslogmodule.c
+++ b/Modules/syslogmodule.c
@@ -71,7 +71,7 @@ syslog_openlog(PyObject * self, PyObject * args)
S_ident_o = new_S_ident_o;
Py_INCREF(S_ident_o);
- openlog(PyString_AsString(S_ident_o), logopt, facility);
+ openlog(PyBytes_AsString(S_ident_o), logopt, facility);
Py_INCREF(Py_None);
return Py_None;
diff --git a/Modules/termios.c b/Modules/termios.c
index c53566c12b..c6d05cef8b 100644
--- a/Modules/termios.c
+++ b/Modules/termios.c
@@ -91,7 +91,7 @@ termios_tcgetattr(PyObject *self, PyObject *args)
return NULL;
for (i = 0; i < NCCS; i++) {
ch = (char)mode.c_cc[i];
- v = PyString_FromStringAndSize(&ch, 1);
+ v = PyBytes_FromStringAndSize(&ch, 1);
if (v == NULL)
goto err;
PyList_SetItem(cc, i, v);
@@ -183,8 +183,8 @@ termios_tcsetattr(PyObject *self, PyObject *args)
for (i = 0; i < NCCS; i++) {
v = PyList_GetItem(cc, i);
- if (PyString_Check(v) && PyString_Size(v) == 1)
- mode.c_cc[i] = (cc_t) * PyString_AsString(v);
+ if (PyBytes_Check(v) && PyBytes_Size(v) == 1)
+ mode.c_cc[i] = (cc_t) * PyBytes_AsString(v);
else if (PyInt_Check(v))
mode.c_cc[i] = (cc_t) PyInt_AsLong(v);
else {
diff --git a/Modules/threadmodule.c b/Modules/threadmodule.c
index 81bf288204..7b52f727e2 100644
--- a/Modules/threadmodule.c
+++ b/Modules/threadmodule.c
@@ -190,7 +190,7 @@ local_new(PyTypeObject *type, PyObject *args, PyObject *kw)
Py_XINCREF(kw);
self->kw = kw;
self->dict = NULL; /* making sure */
- self->key = PyString_FromFormat("thread.local.%p", self);
+ self->key = PyBytes_FromFormat("thread.local.%p", self);
if (self->key == NULL)
goto err;
diff --git a/Modules/timemodule.c b/Modules/timemodule.c
index c6f68f8e23..92c47cb603 100644
--- a/Modules/timemodule.c
+++ b/Modules/timemodule.c
@@ -488,7 +488,7 @@ time_strftime(PyObject *self, PyObject *args)
e.g. an empty format, or %Z when the timezone
is unknown. */
PyObject *ret;
- ret = PyString_FromStringAndSize(outbuf, buflen);
+ ret = PyBytes_FromStringAndSize(outbuf, buflen);
free(outbuf);
return ret;
}
@@ -548,7 +548,7 @@ time_asctime(PyObject *self, PyObject *args)
p = asctime(&buf);
if (p[24] == '\n')
p[24] = '\0';
- return PyString_FromString(p);
+ return PyBytes_FromString(p);
}
PyDoc_STRVAR(asctime_doc,
@@ -584,7 +584,7 @@ time_ctime(PyObject *self, PyObject *args)
}
if (p[24] == '\n')
p[24] = '\0';
- return PyString_FromString(p);
+ return PyBytes_FromString(p);
}
PyDoc_STRVAR(ctime_doc,
diff --git a/Modules/unicodedata.c b/Modules/unicodedata.c
index 42990f8436..cd61819023 100644
--- a/Modules/unicodedata.c
+++ b/Modules/unicodedata.c
@@ -258,7 +258,7 @@ unicodedata_category(PyObject *self, PyObject *args)
if (old->category_changed != 0xFF)
index = old->category_changed;
}
- return PyString_FromString(_PyUnicode_CategoryNames[index]);
+ return PyBytes_FromString(_PyUnicode_CategoryNames[index]);
}
PyDoc_STRVAR(unicodedata_bidirectional__doc__,
@@ -290,7 +290,7 @@ unicodedata_bidirectional(PyObject *self, PyObject *args)
else if (old->bidir_changed != 0xFF)
index = old->bidir_changed;
}
- return PyString_FromString(_PyUnicode_BidirectionalNames[index]);
+ return PyBytes_FromString(_PyUnicode_BidirectionalNames[index]);
}
PyDoc_STRVAR(unicodedata_combining__doc__,
@@ -379,7 +379,7 @@ unicodedata_east_asian_width(PyObject *self, PyObject *args)
if (old->category_changed == 0)
index = 0; /* unassigned */
}
- return PyString_FromString(_PyUnicode_EastAsianWidthNames[index]);
+ return PyBytes_FromString(_PyUnicode_EastAsianWidthNames[index]);
}
PyDoc_STRVAR(unicodedata_decomposition__doc__,
@@ -411,7 +411,7 @@ unicodedata_decomposition(PyObject *self, PyObject *args)
if (self) {
const change_record *old = get_old_record(self, *PyUnicode_AS_UNICODE(v));
if (old->category_changed == 0)
- return PyString_FromString(""); /* unassigned */
+ return PyBytes_FromString(""); /* unassigned */
}
if (code < 0 || code >= 0x110000)
@@ -450,7 +450,7 @@ unicodedata_decomposition(PyObject *self, PyObject *args)
decomp[i] = '\0';
- return PyString_FromString(decomp);
+ return PyBytes_FromString(decomp);
}
static void
@@ -515,7 +515,7 @@ nfd_nfkd(PyObject *self, PyObject *input, int k)
/* Hangul Decomposition adds three characters in
a single step, so we need atleast that much room. */
if (space < 3) {
- Py_ssize_t newsize = PyString_GET_SIZE(result) + 10;
+ Py_ssize_t newsize = PyBytes_GET_SIZE(result) + 10;
space += 10;
if (PyUnicode_Resize(&result, newsize) == -1)
return NULL;
diff --git a/Modules/zipimport.c b/Modules/zipimport.c
index d3cd4ad61a..bd1348798f 100644
--- a/Modules/zipimport.c
+++ b/Modules/zipimport.c
@@ -154,11 +154,11 @@ zipimporter_init(ZipImporter *self, PyObject *args, PyObject *kwds)
}
}
- self->archive = PyString_FromString(buf);
+ self->archive = PyBytes_FromString(buf);
if (self->archive == NULL)
return -1;
- self->prefix = PyString_FromString(prefix);
+ self->prefix = PyBytes_FromString(prefix);
if (self->prefix == NULL)
return -1;
@@ -191,10 +191,10 @@ zipimporter_repr(ZipImporter *self)
char *archive = "???";
char *prefix = "";
- if (self->archive != NULL && PyString_Check(self->archive))
- archive = PyString_AsString(self->archive);
- if (self->prefix != NULL && PyString_Check(self->prefix))
- prefix = PyString_AsString(self->prefix);
+ if (self->archive != NULL && PyBytes_Check(self->archive))
+ archive = PyBytes_AsString(self->archive);
+ if (self->prefix != NULL && PyBytes_Check(self->prefix))
+ prefix = PyBytes_AsString(self->prefix);
if (prefix != NULL && *prefix)
PyOS_snprintf(buf, sizeof(buf),
"<zipimporter object \"%.300s%c%.150s\">",
@@ -203,7 +203,7 @@ zipimporter_repr(ZipImporter *self)
PyOS_snprintf(buf, sizeof(buf),
"<zipimporter object \"%.300s\">",
archive);
- return PyString_FromString(buf);
+ return PyBytes_FromString(buf);
}
/* return fullname.split(".")[-1] */
@@ -263,7 +263,7 @@ get_module_info(ZipImporter *self, char *fullname)
subname = get_subname(fullname);
- len = make_filename(PyString_AsString(self->prefix), subname, path);
+ len = make_filename(PyBytes_AsString(self->prefix), subname, path);
if (len < 0)
return MI_ERROR;
@@ -336,12 +336,12 @@ zipimporter_load_module(PyObject *obj, PyObject *args)
/* add __path__ to the module *before* the code gets
executed */
PyObject *pkgpath, *fullpath;
- char *prefix = PyString_AsString(self->prefix);
+ char *prefix = PyBytes_AsString(self->prefix);
char *subname = get_subname(fullname);
int err;
- fullpath = PyString_FromFormat("%s%c%s%s",
- PyString_AsString(self->archive),
+ fullpath = PyBytes_FromFormat("%s%c%s%s",
+ PyBytes_AsString(self->archive),
SEP,
*prefix ? prefix : "",
subname);
@@ -418,9 +418,9 @@ zipimporter_get_data(PyObject *obj, PyObject *args)
}
path = buf;
#endif
- len = PyString_Size(self->archive);
+ len = PyBytes_Size(self->archive);
if ((size_t)len < strlen(path) &&
- strncmp(path, PyString_AsString(self->archive), len) == 0 &&
+ strncmp(path, PyBytes_AsString(self->archive), len) == 0 &&
path[len] == SEP) {
path = path + len + 1;
}
@@ -430,7 +430,7 @@ zipimporter_get_data(PyObject *obj, PyObject *args)
PyErr_SetFromErrnoWithFilename(PyExc_IOError, path);
return NULL;
}
- return get_data(PyString_AsString(self->archive), toc_entry);
+ return get_data(PyBytes_AsString(self->archive), toc_entry);
}
static PyObject *
@@ -467,7 +467,7 @@ zipimporter_get_source(PyObject *obj, PyObject *args)
}
subname = get_subname(fullname);
- len = make_filename(PyString_AsString(self->prefix), subname, path);
+ len = make_filename(PyBytes_AsString(self->prefix), subname, path);
if (len < 0)
return NULL;
@@ -480,7 +480,7 @@ zipimporter_get_source(PyObject *obj, PyObject *args)
toc_entry = PyDict_GetItemString(self->files, path);
if (toc_entry != NULL)
- return get_data(PyString_AsString(self->archive), toc_entry);
+ return get_data(PyBytes_AsString(self->archive), toc_entry);
/* we have the module, but no source */
Py_INCREF(Py_None);
@@ -843,13 +843,13 @@ get_data(char *archive, PyObject *toc_entry)
PyMarshal_ReadShortFromFile(fp); /* local header size */
file_offset += l; /* Start of file data */
- raw_data = PyString_FromStringAndSize((char *)NULL, compress == 0 ?
+ raw_data = PyBytes_FromStringAndSize((char *)NULL, compress == 0 ?
data_size : data_size + 1);
if (raw_data == NULL) {
fclose(fp);
return NULL;
}
- buf = PyString_AsString(raw_data);
+ buf = PyBytes_AsString(raw_data);
err = fseek(fp, file_offset, 0);
if (err == 0)
@@ -907,8 +907,8 @@ static PyObject *
unmarshal_code(char *pathname, PyObject *data, time_t mtime)
{
PyObject *code;
- char *buf = PyString_AsString(data);
- Py_ssize_t size = PyString_Size(data);
+ char *buf = PyBytes_AsString(data);
+ Py_ssize_t size = PyBytes_Size(data);
if (size <= 9) {
PyErr_SetString(ZipImportError,
@@ -953,14 +953,14 @@ unmarshal_code(char *pathname, PyObject *data, time_t mtime)
static PyObject *
normalize_line_endings(PyObject *source)
{
- char *buf, *q, *p = PyString_AsString(source);
+ char *buf, *q, *p = PyBytes_AsString(source);
PyObject *fixed_source;
if (!p)
return NULL;
/* one char extra for trailing \n and one for terminating \0 */
- buf = (char *)PyMem_Malloc(PyString_Size(source) + 2);
+ buf = (char *)PyMem_Malloc(PyBytes_Size(source) + 2);
if (buf == NULL) {
PyErr_SetString(PyExc_MemoryError,
"zipimport: no memory to allocate "
@@ -979,7 +979,7 @@ normalize_line_endings(PyObject *source)
}
*q++ = '\n'; /* add trailing \n */
*q = '\0';
- fixed_source = PyString_FromString(buf);
+ fixed_source = PyBytes_FromString(buf);
PyMem_Free(buf);
return fixed_source;
}
@@ -995,7 +995,7 @@ compile_source(char *pathname, PyObject *source)
if (fixed_source == NULL)
return NULL;
- code = Py_CompileString(PyString_AsString(fixed_source), pathname,
+ code = Py_CompileString(PyBytes_AsString(fixed_source), pathname,
Py_file_input);
Py_DECREF(fixed_source);
return code;
@@ -1054,7 +1054,7 @@ get_code_from_data(ZipImporter *self, int ispackage, int isbytecode,
{
PyObject *data, *code;
char *modpath;
- char *archive = PyString_AsString(self->archive);
+ char *archive = PyBytes_AsString(self->archive);
if (archive == NULL)
return NULL;
@@ -1063,7 +1063,7 @@ get_code_from_data(ZipImporter *self, int ispackage, int isbytecode,
if (data == NULL)
return NULL;
- modpath = PyString_AsString(PyTuple_GetItem(toc_entry, 0));
+ modpath = PyBytes_AsString(PyTuple_GetItem(toc_entry, 0));
if (isbytecode) {
code = unmarshal_code(modpath, data, mtime);
@@ -1088,7 +1088,7 @@ get_module_code(ZipImporter *self, char *fullname,
subname = get_subname(fullname);
- len = make_filename(PyString_AsString(self->prefix), subname, path);
+ len = make_filename(PyBytes_AsString(self->prefix), subname, path);
if (len < 0)
return NULL;
@@ -1098,7 +1098,7 @@ get_module_code(ZipImporter *self, char *fullname,
strcpy(path + len, zso->suffix);
if (Py_VerboseFlag > 1)
PySys_WriteStderr("# trying %s%c%s\n",
- PyString_AsString(self->archive),
+ PyBytes_AsString(self->archive),
SEP, path);
toc_entry = PyDict_GetItemString(self->files, path);
if (toc_entry != NULL) {
@@ -1120,7 +1120,7 @@ get_module_code(ZipImporter *self, char *fullname,
continue;
}
if (code != NULL && p_modpath != NULL)
- *p_modpath = PyString_AsString(
+ *p_modpath = PyBytes_AsString(
PyTuple_GetItem(toc_entry, 0));
return code;
}
diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c
index 4f78dbcb15..590ab5fb55 100644
--- a/Modules/zlibmodule.c
+++ b/Modules/zlibmodule.c
@@ -96,12 +96,12 @@ newcompobject(PyTypeObject *type)
if (self == NULL)
return NULL;
self->is_initialised = 0;
- self->unused_data = PyString_FromString("");
+ self->unused_data = PyBytes_FromString("");
if (self->unused_data == NULL) {
Py_DECREF(self);
return NULL;
}
- self->unconsumed_tail = PyString_FromString("");
+ self->unconsumed_tail = PyBytes_FromString("");
if (self->unconsumed_tail == NULL) {
Py_DECREF(self);
return NULL;
@@ -174,7 +174,7 @@ PyZlib_compress(PyObject *self, PyObject *args)
err=deflateEnd(&zst);
if (err == Z_OK)
- ReturnVal = PyString_FromStringAndSize((char *)output,
+ ReturnVal = PyBytes_FromStringAndSize((char *)output,
zst.total_out);
else
zlib_error(zst, err, "while finishing compression");
@@ -211,12 +211,12 @@ PyZlib_decompress(PyObject *self, PyObject *args)
zst.avail_in = length;
zst.avail_out = r_strlen;
- if (!(result_str = PyString_FromStringAndSize(NULL, r_strlen)))
+ if (!(result_str = PyBytes_FromStringAndSize(NULL, r_strlen)))
return NULL;
zst.zalloc = (alloc_func)NULL;
zst.zfree = (free_func)Z_NULL;
- zst.next_out = (Byte *)PyString_AS_STRING(result_str);
+ zst.next_out = (Byte *)PyBytes_AS_STRING(result_str);
zst.next_in = (Byte *)input;
err = inflateInit2(&zst, wsize);
@@ -256,11 +256,11 @@ PyZlib_decompress(PyObject *self, PyObject *args)
/* fall through */
case(Z_OK):
/* need more memory */
- if (_PyString_Resize(&result_str, r_strlen << 1) < 0) {
+ if (_PyBytes_Resize(&result_str, r_strlen << 1) < 0) {
inflateEnd(&zst);
goto error;
}
- zst.next_out = (unsigned char *)PyString_AS_STRING(result_str) \
+ zst.next_out = (unsigned char *)PyBytes_AS_STRING(result_str) \
+ r_strlen;
zst.avail_out = r_strlen;
r_strlen = r_strlen << 1;
@@ -278,7 +278,7 @@ PyZlib_decompress(PyObject *self, PyObject *args)
goto error;
}
- _PyString_Resize(&result_str, zst.total_out);
+ _PyBytes_Resize(&result_str, zst.total_out);
return result_str;
error:
@@ -400,7 +400,7 @@ PyZlib_objcompress(compobject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "s#:compress", &input, &inplen))
return NULL;
- if (!(RetVal = PyString_FromStringAndSize(NULL, length)))
+ if (!(RetVal = PyBytes_FromStringAndSize(NULL, length)))
return NULL;
ENTER_ZLIB
@@ -409,7 +409,7 @@ PyZlib_objcompress(compobject *self, PyObject *args)
self->zst.avail_in = inplen;
self->zst.next_in = input;
self->zst.avail_out = length;
- self->zst.next_out = (unsigned char *)PyString_AS_STRING(RetVal);
+ self->zst.next_out = (unsigned char *)PyBytes_AS_STRING(RetVal);
Py_BEGIN_ALLOW_THREADS
err = deflate(&(self->zst), Z_NO_FLUSH);
@@ -418,9 +418,9 @@ PyZlib_objcompress(compobject *self, PyObject *args)
/* while Z_OK and the output buffer is full, there might be more output,
so extend the output buffer and try again */
while (err == Z_OK && self->zst.avail_out == 0) {
- if (_PyString_Resize(&RetVal, length << 1) < 0)
+ if (_PyBytes_Resize(&RetVal, length << 1) < 0)
goto error;
- self->zst.next_out = (unsigned char *)PyString_AS_STRING(RetVal) \
+ self->zst.next_out = (unsigned char *)PyBytes_AS_STRING(RetVal) \
+ length;
self->zst.avail_out = length;
length = length << 1;
@@ -440,7 +440,7 @@ PyZlib_objcompress(compobject *self, PyObject *args)
RetVal = NULL;
goto error;
}
- _PyString_Resize(&RetVal, self->zst.total_out - start_total_out);
+ _PyBytes_Resize(&RetVal, self->zst.total_out - start_total_out);
error:
LEAVE_ZLIB
@@ -479,7 +479,7 @@ PyZlib_objdecompress(compobject *self, PyObject *args)
/* limit amount of data allocated to max_length */
if (max_length && length > max_length)
length = max_length;
- if (!(RetVal = PyString_FromStringAndSize(NULL, length)))
+ if (!(RetVal = PyBytes_FromStringAndSize(NULL, length)))
return NULL;
ENTER_ZLIB
@@ -488,7 +488,7 @@ PyZlib_objdecompress(compobject *self, PyObject *args)
self->zst.avail_in = inplen;
self->zst.next_in = input;
self->zst.avail_out = length;
- self->zst.next_out = (unsigned char *)PyString_AS_STRING(RetVal);
+ self->zst.next_out = (unsigned char *)PyBytes_AS_STRING(RetVal);
Py_BEGIN_ALLOW_THREADS
err = inflate(&(self->zst), Z_SYNC_FLUSH);
@@ -510,9 +510,9 @@ PyZlib_objdecompress(compobject *self, PyObject *args)
if (max_length && length > max_length)
length = max_length;
- if (_PyString_Resize(&RetVal, length) < 0)
+ if (_PyBytes_Resize(&RetVal, length) < 0)
goto error;
- self->zst.next_out = (unsigned char *)PyString_AS_STRING(RetVal) \
+ self->zst.next_out = (unsigned char *)PyBytes_AS_STRING(RetVal) \
+ old_length;
self->zst.avail_out = length - old_length;
@@ -525,7 +525,7 @@ PyZlib_objdecompress(compobject *self, PyObject *args)
of specified size. Return the unconsumed tail in an attribute.*/
if(max_length) {
Py_DECREF(self->unconsumed_tail);
- self->unconsumed_tail = PyString_FromStringAndSize((char *)self->zst.next_in,
+ self->unconsumed_tail = PyBytes_FromStringAndSize((char *)self->zst.next_in,
self->zst.avail_in);
if(!self->unconsumed_tail) {
Py_DECREF(RetVal);
@@ -542,7 +542,7 @@ PyZlib_objdecompress(compobject *self, PyObject *args)
*/
if (err == Z_STREAM_END) {
Py_XDECREF(self->unused_data); /* Free original empty string */
- self->unused_data = PyString_FromStringAndSize(
+ self->unused_data = PyBytes_FromStringAndSize(
(char *)self->zst.next_in, self->zst.avail_in);
if (self->unused_data == NULL) {
Py_DECREF(RetVal);
@@ -559,7 +559,7 @@ PyZlib_objdecompress(compobject *self, PyObject *args)
goto error;
}
- _PyString_Resize(&RetVal, self->zst.total_out - start_total_out);
+ _PyBytes_Resize(&RetVal, self->zst.total_out - start_total_out);
error:
LEAVE_ZLIB
@@ -589,10 +589,10 @@ PyZlib_flush(compobject *self, PyObject *args)
/* Flushing with Z_NO_FLUSH is a no-op, so there's no point in
doing any work at all; just return an empty string. */
if (flushmode == Z_NO_FLUSH) {
- return PyString_FromStringAndSize(NULL, 0);
+ return PyBytes_FromStringAndSize(NULL, 0);
}
- if (!(RetVal = PyString_FromStringAndSize(NULL, length)))
+ if (!(RetVal = PyBytes_FromStringAndSize(NULL, length)))
return NULL;
ENTER_ZLIB
@@ -600,7 +600,7 @@ PyZlib_flush(compobject *self, PyObject *args)
start_total_out = self->zst.total_out;
self->zst.avail_in = 0;
self->zst.avail_out = length;
- self->zst.next_out = (unsigned char *)PyString_AS_STRING(RetVal);
+ self->zst.next_out = (unsigned char *)PyBytes_AS_STRING(RetVal);
Py_BEGIN_ALLOW_THREADS
err = deflate(&(self->zst), flushmode);
@@ -609,9 +609,9 @@ PyZlib_flush(compobject *self, PyObject *args)
/* while Z_OK and the output buffer is full, there might be more output,
so extend the output buffer and try again */
while (err == Z_OK && self->zst.avail_out == 0) {
- if (_PyString_Resize(&RetVal, length << 1) < 0)
+ if (_PyBytes_Resize(&RetVal, length << 1) < 0)
goto error;
- self->zst.next_out = (unsigned char *)PyString_AS_STRING(RetVal) \
+ self->zst.next_out = (unsigned char *)PyBytes_AS_STRING(RetVal) \
+ length;
self->zst.avail_out = length;
length = length << 1;
@@ -646,7 +646,7 @@ PyZlib_flush(compobject *self, PyObject *args)
goto error;
}
- _PyString_Resize(&RetVal, self->zst.total_out - start_total_out);
+ _PyBytes_Resize(&RetVal, self->zst.total_out - start_total_out);
error:
LEAVE_ZLIB
@@ -778,7 +778,7 @@ PyZlib_unflush(compobject *self, PyObject *args)
PyErr_SetString(PyExc_ValueError, "length must be greater than zero");
return NULL;
}
- if (!(retval = PyString_FromStringAndSize(NULL, length)))
+ if (!(retval = PyBytes_FromStringAndSize(NULL, length)))
return NULL;
@@ -786,7 +786,7 @@ PyZlib_unflush(compobject *self, PyObject *args)
start_total_out = self->zst.total_out;
self->zst.avail_out = length;
- self->zst.next_out = (Byte *)PyString_AS_STRING(retval);
+ self->zst.next_out = (Byte *)PyBytes_AS_STRING(retval);
Py_BEGIN_ALLOW_THREADS
err = inflate(&(self->zst), Z_FINISH);
@@ -795,9 +795,9 @@ PyZlib_unflush(compobject *self, PyObject *args)
/* while Z_OK and the output buffer is full, there might be more output,
so extend the output buffer and try again */
while ((err == Z_OK || err == Z_BUF_ERROR) && self->zst.avail_out == 0) {
- if (_PyString_Resize(&retval, length << 1) < 0)
+ if (_PyBytes_Resize(&retval, length << 1) < 0)
goto error;
- self->zst.next_out = (Byte *)PyString_AS_STRING(retval) + length;
+ self->zst.next_out = (Byte *)PyBytes_AS_STRING(retval) + length;
self->zst.avail_out = length;
length = length << 1;
@@ -819,7 +819,7 @@ PyZlib_unflush(compobject *self, PyObject *args)
goto error;
}
}
- _PyString_Resize(&retval, self->zst.total_out - start_total_out);
+ _PyBytes_Resize(&retval, self->zst.total_out - start_total_out);
error:
@@ -1027,7 +1027,7 @@ PyInit_zlib(void)
PyModule_AddIntConstant(m, "Z_SYNC_FLUSH", Z_SYNC_FLUSH);
PyModule_AddIntConstant(m, "Z_FULL_FLUSH", Z_FULL_FLUSH);
- ver = PyString_FromString(ZLIB_VERSION);
+ ver = PyBytes_FromString(ZLIB_VERSION);
if (ver != NULL)
PyModule_AddObject(m, "ZLIB_VERSION", ver);