diff options
author | Christian Heimes <christian@cheimes.de> | 2008-05-26 13:28:38 +0000 |
---|---|---|
committer | Christian Heimes <christian@cheimes.de> | 2008-05-26 13:28:38 +0000 |
commit | b37744af205715d70800c424df04b7da36923603 (patch) | |
tree | 182c4e69a9afdd2ac164b3b00961ba273f41190d /Modules | |
parent | 7f6f3da7105c7fc7d0d29f8ccb30c65edeaddb65 (diff) | |
download | cpython-b37744af205715d70800c424df04b7da36923603.tar.gz |
Renamed PyString to PyBytes
Diffstat (limited to 'Modules')
40 files changed, 436 insertions, 436 deletions
diff --git a/Modules/_bsddb.c b/Modules/_bsddb.c index 28f2cafbbd..04c3835664 100644 --- a/Modules/_bsddb.c +++ b/Modules/_bsddb.c @@ -1174,7 +1174,7 @@ _db_associateCallback(DB* db, const DBT* priKey, const DBT* priData, else if (PyLong_Check(result)) { retval = PyLong_AsLong(result); } - else if (PyByteArray_Check(result) || PyString_Check(result)) { + else if (PyByteArray_Check(result) || PyBytes_Check(result)) { char* data; Py_ssize_t size; @@ -1183,7 +1183,7 @@ _db_associateCallback(DB* db, const DBT* priKey, const DBT* priData, if (PyByteArray_Check(result)) data = PyByteArray_AS_STRING(result); else - data = PyString_AS_STRING(result); + data = PyBytes_AS_STRING(result); secKey->flags = DB_DBT_APPMALLOC; /* DB will free */ secKey->data = malloc(size); /* TODO, check this */ if (secKey->data) { @@ -1523,7 +1523,7 @@ DB_get(DBObject* self, PyObject* args, PyObject* kwargs) retval = Py_BuildValue("y#y#", key.data, key.size, data.data, data.size); else /* return just the data */ - retval = PyString_FromStringAndSize((char*)data.data, data.size); + retval = PyBytes_FromStringAndSize((char*)data.data, data.size); free_dbt(&data); } FREE_DBT_VIEW(key, keyobj, key_buf_view); @@ -1593,13 +1593,13 @@ DB_pget(DBObject* self, PyObject* args, PyObject* kwargs) else if (!err) { PyObject *pkeyObj; PyObject *dataObj; - dataObj = PyString_FromStringAndSize(data.data, data.size); + dataObj = PyBytes_FromStringAndSize(data.data, data.size); if (self->primaryDBType == DB_RECNO || self->primaryDBType == DB_QUEUE) pkeyObj = PyLong_FromLong(*(int *)pkey.data); else - pkeyObj = PyString_FromStringAndSize(pkey.data, pkey.size); + pkeyObj = PyBytes_FromStringAndSize(pkey.data, pkey.size); if (flags & DB_SET_RECNO) /* return key , pkey and data */ { @@ -1608,7 +1608,7 @@ DB_pget(DBObject* self, PyObject* args, PyObject* kwargs) if (type == DB_RECNO || type == DB_QUEUE) keyObj = PyLong_FromLong(*(int *)key.data); else - keyObj = PyString_FromStringAndSize(key.data, key.size); + keyObj = PyBytes_FromStringAndSize(key.data, key.size); #if (PY_VERSION_HEX >= 0x02040000) retval = PyTuple_Pack(3, keyObj, pkeyObj, dataObj); #else @@ -1736,7 +1736,7 @@ DB_get_both(DBObject* self, PyObject* args, PyObject* kwargs) /* XXX(nnorwitz): can we do: retval = dataobj; Py_INCREF(retval); */ /* XXX(gps) I think not: buffer API input vs. bytes object output. */ /* XXX(guido) But what if the input is PyString? */ - retval = PyString_FromStringAndSize((char*)data.data, data.size); + retval = PyBytes_FromStringAndSize((char*)data.data, data.size); /* Even though the flags require DB_DBT_MALLOC, data is not always allocated. 4.4: allocated, 4.5: *not* allocated. :-( */ @@ -2780,7 +2780,7 @@ PyObject* DB_subscript(DBObject* self, PyObject* keyobj) retval = NULL; } else { - retval = PyString_FromStringAndSize((char*)data.data, data.size); + retval = PyBytes_FromStringAndSize((char*)data.data, data.size); free_dbt(&data); } @@ -2935,7 +2935,7 @@ _DB_make_list(DBObject* self, DB_TXN* txn, int type) case DB_BTREE: case DB_HASH: default: - item = PyString_FromStringAndSize((char*)key.data, key.size); + item = PyBytes_FromStringAndSize((char*)key.data, key.size); break; case DB_RECNO: case DB_QUEUE: @@ -2945,7 +2945,7 @@ _DB_make_list(DBObject* self, DB_TXN* txn, int type) break; case _VALUES_LIST: - item = PyString_FromStringAndSize((char*)data.data, data.size); + item = PyBytes_FromStringAndSize((char*)data.data, data.size); break; case _ITEMS_LIST: @@ -3293,13 +3293,13 @@ DBC_pget(DBCursorObject* self, PyObject* args, PyObject *kwargs) else { PyObject *pkeyObj; PyObject *dataObj; - dataObj = PyString_FromStringAndSize(data.data, data.size); + dataObj = PyBytes_FromStringAndSize(data.data, data.size); if (self->mydb->primaryDBType == DB_RECNO || self->mydb->primaryDBType == DB_QUEUE) pkeyObj = PyLong_FromLong(*(int *)pkey.data); else - pkeyObj = PyString_FromStringAndSize(pkey.data, pkey.size); + pkeyObj = PyBytes_FromStringAndSize(pkey.data, pkey.size); if (key.data && key.size) /* return key, pkey and data */ { @@ -3308,7 +3308,7 @@ DBC_pget(DBCursorObject* self, PyObject* args, PyObject *kwargs) if (type == DB_RECNO || type == DB_QUEUE) keyObj = PyLong_FromLong(*(int *)key.data); else - keyObj = PyString_FromStringAndSize(key.data, key.size); + keyObj = PyBytes_FromStringAndSize(key.data, key.size); retval = PyTuple_Pack(3, keyObj, pkeyObj, dataObj); Py_DECREF(keyObj); } @@ -4916,7 +4916,7 @@ DBSequence_get_key(DBSequenceObject* self, PyObject* args) MYDB_END_ALLOW_THREADS if (!err) - retval = PyString_FromStringAndSize(key.data, key.size); + retval = PyBytes_FromStringAndSize(key.data, key.size); free_dbt(&key); RETURN_IF_ERR(); diff --git a/Modules/_bytesio.c b/Modules/_bytesio.c index 2e649d667c..455f9b1065 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 caaac5879b..efa4d806ec 100644 --- a/Modules/_codecsmodule.c +++ b/Modules/_codecsmodule.c @@ -154,7 +154,7 @@ escape_decode(PyObject *self, if (!PyArg_ParseTuple(args, "s#|z:escape_decode", &data, &size, &errors)) return NULL; - return codec_tuple(PyString_DecodeEscape(data, size, errors, 0, NULL), + return codec_tuple(PyBytes_DecodeEscape(data, size, errors, 0, NULL), size); } @@ -170,17 +170,17 @@ escape_encode(PyObject *self, PyObject *v; if (!PyArg_ParseTuple(args, "O!|z:escape_encode", - &PyString_Type, &str, &errors)) + &PyBytes_Type, &str, &errors)) return NULL; - size = PyString_GET_SIZE(str); + size = PyBytes_GET_SIZE(str); newsize = 4*size; if (newsize > PY_SSIZE_T_MAX || newsize / 4 != size) { PyErr_SetString(PyExc_OverflowError, "string is too large to encode"); return NULL; } - v = PyString_FromStringAndSize(NULL, newsize); + v = PyBytes_FromStringAndSize(NULL, newsize); if (v == NULL) { return NULL; @@ -188,12 +188,12 @@ escape_encode(PyObject *self, else { register Py_ssize_t i; register char c; - register char *p = PyString_AS_STRING(v); + register char *p = PyBytes_AS_STRING(v); for (i = 0; i < size; i++) { /* There's at least enough room for a hex escape */ - assert(newsize - (p - PyString_AS_STRING(v)) >= 4); - c = PyString_AS_STRING(str)[i]; + assert(newsize - (p - PyBytes_AS_STRING(v)) >= 4); + c = PyBytes_AS_STRING(str)[i]; if (c == '\'' || c == '\\') *p++ = '\\', *p++ = c; else if (c == '\t') @@ -212,12 +212,12 @@ escape_encode(PyObject *self, *p++ = c; } *p = '\0'; - if (_PyString_Resize(&v, (p - PyString_AS_STRING(v)))) { + if (_PyBytes_Resize(&v, (p - PyBytes_AS_STRING(v)))) { return NULL; } } - return codec_tuple(v, PyString_Size(v)); + return codec_tuple(v, PyBytes_Size(v)); } /* --- Decoder ------------------------------------------------------------ */ @@ -660,7 +660,7 @@ readbuffer_encode(PyObject *self, &data, &size, &errors)) return NULL; - return codec_tuple(PyString_FromStringAndSize(data, size), size); + return codec_tuple(PyBytes_FromStringAndSize(data, size), size); } static PyObject * @@ -675,7 +675,7 @@ charbuffer_encode(PyObject *self, &data, &size, &errors)) return NULL; - return codec_tuple(PyString_FromStringAndSize(data, size), size); + return codec_tuple(PyBytes_FromStringAndSize(data, size), size); } static PyObject * @@ -694,12 +694,12 @@ unicode_internal_encode(PyObject *self, if (PyUnicode_Check(obj)) { data = PyUnicode_AS_DATA(obj); size = PyUnicode_GET_DATA_SIZE(obj); - return codec_tuple(PyString_FromStringAndSize(data, size), size); + return codec_tuple(PyBytes_FromStringAndSize(data, size), size); } else { if (PyObject_AsReadBuffer(obj, (const void **)&data, &size)) return NULL; - return codec_tuple(PyString_FromStringAndSize(data, size), size); + return codec_tuple(PyBytes_FromStringAndSize(data, size), size); } } diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c index 1d548dc455..fe332533a7 100644 --- a/Modules/_ctypes/_ctypes.c +++ b/Modules/_ctypes/_ctypes.c @@ -1049,7 +1049,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 * @@ -1060,7 +1060,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 @@ -1081,14 +1081,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, "str/bytes 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"); @@ -1096,7 +1096,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'; @@ -1135,7 +1135,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); @@ -1434,7 +1434,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"); @@ -1495,7 +1495,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"); @@ -1579,7 +1579,7 @@ c_void_p_from_param(PyObject *type, PyObject *value) } /* XXX struni: remove later */ /* string */ - if (PyString_Check(value)) { + if (PyBytes_Check(value)) { PyCArgObject *parg; struct fielddesc *fd = getentry("z"); @@ -1828,8 +1828,8 @@ SimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds) PyObject *v = _PyUnicode_AsDefaultEncodedString(proto, NULL); if (!v) goto error; - proto_str = PyString_AS_STRING(v); - proto_len = PyString_GET_SIZE(v); + proto_str = PyBytes_AS_STRING(v); + proto_len = PyBytes_GET_SIZE(v); } else { PyErr_SetString(PyExc_TypeError, "class must define a '_type_' string attribute"); @@ -2501,7 +2501,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 * @@ -3137,8 +3137,8 @@ _get_name(PyObject *obj, char **pname) return 1; } #endif - if (PyString_Check(obj)) { - *pname = PyString_AS_STRING(obj); + if (PyBytes_Check(obj)) { + *pname = PyBytes_AS_STRING(obj); return *pname ? 1 : 0; } if (PyUnicode_Check(obj)) { @@ -3953,7 +3953,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 = "???"; @@ -4166,9 +4166,9 @@ Array_subscript(PyObject *_self, PyObject *item) char *dest; if (slicelen <= 0) - return PyString_FromStringAndSize("", 0); + return PyBytes_FromStringAndSize("", 0); if (step == 1) { - return PyString_FromStringAndSize(ptr + start, + return PyBytes_FromStringAndSize(ptr + start, slicelen); } dest = (char *)PyMem_Malloc(slicelen); @@ -4181,7 +4181,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; } @@ -4859,9 +4859,9 @@ Pointer_subscript(PyObject *_self, PyObject *item) char *dest; if (len <= 0) - return PyString_FromStringAndSize("", 0); + return PyBytes_FromStringAndSize("", 0); if (step == 1) { - return PyString_FromStringAndSize(ptr + start, + return PyBytes_FromStringAndSize(ptr + start, len); } dest = (char *)PyMem_Malloc(len); @@ -4870,7 +4870,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; } @@ -5105,8 +5105,8 @@ static PyObject * string_at(const char *ptr, int size) { if (size == -1) - return PyString_FromStringAndSize(ptr, strlen(ptr)); - return PyString_FromStringAndSize(ptr, size); + return PyBytes_FromStringAndSize(ptr, strlen(ptr)); + return PyBytes_FromStringAndSize(ptr, size); } static int diff --git a/Modules/_ctypes/callbacks.c b/Modules/_ctypes/callbacks.c index 94c6096316..87e3df7cb3 100644 --- a/Modules/_ctypes/callbacks.c +++ b/Modules/_ctypes/callbacks.c @@ -110,7 +110,7 @@ void _AddTraceback(char *funcname, char *filename, int lineno) 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,*/ diff --git a/Modules/_ctypes/callproc.c b/Modules/_ctypes/callproc.c index 437cce710f..fd662160c3 100644 --- a/Modules/_ctypes/callproc.c +++ b/Modules/_ctypes/callproc.c @@ -507,9 +507,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_AsString(obj); + pa->value.p = PyBytes_AsString(obj); Py_INCREF(obj); pa->keep = obj; return 0; diff --git a/Modules/_ctypes/cfield.c b/Modules/_ctypes/cfield.c index 86f6b5383b..6cf56a8dac 100644 --- a/Modules/_ctypes/cfield.c +++ b/Modules/_ctypes/cfield.c @@ -1160,16 +1160,16 @@ c_set(void *ptr, PyObject *value, Py_ssize_t size) conversion_mode_errors); if (value == NULL) return NULL; - if (PyString_GET_SIZE(value) != 1) { + if (PyBytes_GET_SIZE(value) != 1) { Py_DECREF(value); goto error; } - *(char *)ptr = PyString_AS_STRING(value)[0]; + *(char *)ptr = PyBytes_AS_STRING(value)[0]; Py_DECREF(value); _RET(value); } - if (PyString_Check(value) && PyString_GET_SIZE(value) == 1) { - *(char *)ptr = PyString_AS_STRING(value)[0]; + if (PyBytes_Check(value) && PyBytes_GET_SIZE(value) == 1) { + *(char *)ptr = PyBytes_AS_STRING(value)[0]; _RET(value); } if (PyByteArray_Check(value) && PyByteArray_GET_SIZE(value) == 1) { @@ -1194,7 +1194,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 @@ -1203,7 +1203,7 @@ static PyObject * 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); @@ -1278,7 +1278,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); @@ -1334,8 +1334,8 @@ s_set(void *ptr, PyObject *value, Py_ssize_t length) conversion_mode_errors); if (value == NULL) return NULL; - assert(PyString_Check(value)); - } else if(PyString_Check(value)) { + assert(PyBytes_Check(value)); + } else if(PyBytes_Check(value)) { Py_INCREF(value); } else { PyErr_Format(PyExc_TypeError, @@ -1344,7 +1344,7 @@ s_set(void *ptr, PyObject *value, Py_ssize_t length) return NULL; } - data = PyString_AS_STRING(value); + data = PyBytes_AS_STRING(value); if (!data) return NULL; size = strlen(data); /* XXX Why not Py_SIZE(value)? */ @@ -1375,8 +1375,8 @@ z_set(void *ptr, PyObject *value, Py_ssize_t size) Py_INCREF(value); return value; } - if (PyString_Check(value)) { - *(char **)ptr = PyString_AsString(value); + if (PyBytes_Check(value)) { + *(char **)ptr = PyBytes_AsString(value); Py_INCREF(value); return value; } else if (PyUnicode_Check(value)) { @@ -1385,7 +1385,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 (PyLong_Check(value)) { #if SIZEOF_VOID_P == SIZEOF_LONG_LONG @@ -1439,7 +1439,7 @@ Z_set(void *ptr, PyObject *value, Py_ssize_t size) Py_INCREF(Py_None); return Py_None; } - if (PyString_Check(value)) { + if (PyBytes_Check(value)) { value = PyUnicode_FromEncodedObject(value, conversion_mode_encoding, conversion_mode_errors); @@ -1522,7 +1522,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/_cursesmodule.c b/Modules/_cursesmodule.c index 06202e0bce..bde086da07 100644 --- a/Modules/_cursesmodule.c +++ b/Modules/_cursesmodule.c @@ -203,9 +203,9 @@ PyCurses_ConvertToChtype(PyObject *obj, chtype *ch) *ch = (chtype) PyLong_AsLongAndOverflow(obj, &overflow); if (overflow) return 0; - } 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 if (PyUnicode_Check(obj) && PyUnicode_GetSize(obj) == 1) { *ch = (chtype) *PyUnicode_AS_UNICODE(obj); } else { @@ -950,7 +950,7 @@ PyCursesWindow_GetStr(PyCursesWindowObject *self, PyObject *args) } if (rtn2 == ERR) rtn[0] = 0; - return PyString_FromString(rtn); + return PyBytes_FromString(rtn); } static PyObject * @@ -1102,7 +1102,7 @@ PyCursesWindow_InStr(PyCursesWindowObject *self, PyObject *args) } if (rtn2 == ERR) rtn[0] = 0; - return PyString_FromString(rtn); + return PyBytes_FromString(rtn); } static PyObject * @@ -1791,7 +1791,7 @@ PyCurses_EraseChar(PyObject *self) ch = erasechar(); - return PyString_FromStringAndSize(&ch, 1); + return PyBytes_FromStringAndSize(&ch, 1); } static PyObject * @@ -1869,7 +1869,7 @@ PyCurses_GetWin(PyCursesWindowObject *self, PyObject *stream) remove(fn); return NULL; } - if (!PyString_Check(data)) { + if (!PyBytes_Check(data)) { PyErr_Format(PyExc_TypeError, "f.read() returned %.100s instead of bytes", data->ob_type->tp_name); @@ -1878,7 +1878,7 @@ PyCurses_GetWin(PyCursesWindowObject *self, PyObject *stream) remove(fn); return NULL; } - fwrite(PyString_AS_STRING(data), 1, PyString_GET_SIZE(data), fp); + fwrite(PyBytes_AS_STRING(data), 1, PyBytes_GET_SIZE(data), fp); Py_DECREF(data); fseek(fp, 0, 0); win = getwin(fp); @@ -2175,7 +2175,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 @@ -2186,7 +2186,7 @@ PyCurses_KillChar(PyObject *self) ch = killchar(); - return PyString_FromStringAndSize(&ch, 1); + return PyBytes_FromStringAndSize(&ch, 1); } static PyObject * @@ -2557,7 +2557,7 @@ PyCurses_tigetstr(PyObject *self, PyObject *args) Py_INCREF(Py_None); return Py_None; } - return PyString_FromString( capname ); + return PyBytes_FromString( capname ); } static PyObject * @@ -2581,7 +2581,7 @@ PyCurses_tparm(PyObject *self, PyObject *args) return NULL; } - return PyString_FromString(result); + return PyBytes_FromString(result); } static PyObject * @@ -2611,7 +2611,7 @@ PyCurses_UnCtrl(PyObject *self, PyObject *args) return NULL; } - return PyString_FromString(unctrl(ch)); + return PyBytes_FromString(unctrl(ch)); } static PyObject * @@ -2806,7 +2806,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/_dbmmodule.c b/Modules/_dbmmodule.c index 8484d94553..ddfd4cd759 100644 --- a/Modules/_dbmmodule.c +++ b/Modules/_dbmmodule.c @@ -219,14 +219,14 @@ dbm_contains(PyObject *self, PyObject *arg) if (arg == NULL) return -1; } - if (!PyString_Check(arg)) { + if (!PyBytes_Check(arg)) { PyErr_Format(PyExc_TypeError, "dbm 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); val = dbm_fetch(dp->di_dbm, key); return val.dptr != NULL; } diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c index d237cbb75b..0c8bf2a26d 100644 --- a/Modules/_elementtree.c +++ b/Modules/_elementtree.c @@ -152,7 +152,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); @@ -725,9 +725,9 @@ checkpath(PyObject* tag) } return 0; } - 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] == '}') @@ -795,7 +795,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; } @@ -1584,14 +1584,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; @@ -1848,7 +1848,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; @@ -1870,8 +1870,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++; @@ -1882,7 +1882,7 @@ makeuniversal(XMLParserObject* self, const char* string) } /* decode universal name */ - p = PyString_AS_STRING(tag); + p = PyBytes_AS_STRING(tag); value = PyUnicode_DecodeUTF8(p, size, "strict"); Py_DECREF(tag); if (!value) { @@ -1935,7 +1935,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) ); @@ -2362,13 +2362,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); @@ -2430,7 +2430,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; } @@ -2440,9 +2440,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; @@ -2514,7 +2514,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 7966878e53..1a78f60c23 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; } diff --git a/Modules/_gdbmmodule.c b/Modules/_gdbmmodule.c index 4404d2f348..6c7581969a 100644 --- a/Modules/_gdbmmodule.c +++ b/Modules/_gdbmmodule.c @@ -130,7 +130,7 @@ dbm_subscript(dbmobject *dp, register PyObject *key) PyErr_SetObject(PyExc_KeyError, key); return NULL; } - v = PyString_FromStringAndSize(drec.dptr, drec.dsize); + v = PyBytes_FromStringAndSize(drec.dptr, drec.dsize); free(drec.dptr); return v; } @@ -220,7 +220,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); @@ -251,14 +251,14 @@ dbm_contains(PyObject *self, 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 bytes, 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); } @@ -291,7 +291,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; } @@ -323,7 +323,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; } diff --git a/Modules/_hashopenssl.c b/Modules/_hashopenssl.c index 1791efeddf..ecbe01c9db 100644 --- a/Modules/_hashopenssl.c +++ b/Modules/_hashopenssl.c @@ -108,7 +108,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; } diff --git a/Modules/_json.c b/Modules/_json.c index 890d27e977..cc52ff6e64 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; @@ -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); Py_buffer info; PyObject *chunks = PyList_New(0); if (chunks == NULL) { @@ -560,7 +560,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)) { @@ -582,7 +582,7 @@ py_encode_basestring_ascii(PyObject* self, PyObject *pystr) { PyObject *rval; /* METH_O */ - if (PyString_Check(pystr)) { + if (PyBytes_Check(pystr)) { rval = ascii_escape_str(pystr); } else if (PyUnicode_Check(pystr)) { @@ -594,8 +594,8 @@ py_encode_basestring_ascii(PyObject* self, PyObject *pystr) Py_TYPE(pystr)->tp_name); return NULL; } - if (PyString_Check(rval)) { - PyObject *urval = PyUnicode_DecodeASCII(PyString_AS_STRING(rval), PyString_GET_SIZE(rval), NULL); + if (PyBytes_Check(rval)) { + PyObject *urval = PyUnicode_DecodeASCII(PyBytes_AS_STRING(rval), PyBytes_GET_SIZE(rval), NULL); Py_DECREF(rval); return urval; } diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c index 667c3f00a3..2d1b8220d0 100644 --- a/Modules/_sqlite/connection.c +++ b/Modules/_sqlite/connection.c @@ -483,7 +483,7 @@ PyObject* _pysqlite_build_py_params(sqlite3_context *context, int argc, sqlite3_ break; case SQLITE_BLOB: buflen = sqlite3_value_bytes(cur_value); - cur_py_value = PyString_FromStringAndSize( + cur_py_value = PyBytes_FromStringAndSize( sqlite3_value_blob(cur_value), buflen); break; case SQLITE_NULL: diff --git a/Modules/_sqlite/connection.h b/Modules/_sqlite/connection.h index dd177aedfe..af414a0c38 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 4ab84616a2..243b0b66cc 100644 --- a/Modules/_sqlite/cursor.c +++ b/Modules/_sqlite/cursor.c @@ -311,7 +311,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; } @@ -366,8 +366,8 @@ PyObject* _pysqlite_fetch_one_row(pysqlite_Cursor* self) Py_DECREF(buf_bytes); } } - } 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 if (self->connection->text_factory == (PyObject*)&PyByteArray_Type) { converted = PyByteArray_FromStringAndSize(val_str, strlen(val_str)); } else { @@ -376,7 +376,7 @@ PyObject* _pysqlite_fetch_one_row(pysqlite_Cursor* self) } else { /* coltype == SQLITE_BLOB */ nbytes = sqlite3_column_bytes(self->statement->st, i); - buffer = PyString_FromStringAndSize( + buffer = PyBytes_FromStringAndSize( sqlite3_column_blob(self->statement->st, i), nbytes); if (!buffer) { break; diff --git a/Modules/_sqlite/statement.c b/Modules/_sqlite/statement.c index ddbb85e1ff..fb1eec7c0f 100644 --- a/Modules/_sqlite/statement.c +++ b/Modules/_sqlite/statement.c @@ -120,7 +120,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."); diff --git a/Modules/_sre.c b/Modules/_sre.c index bfe4ae93d9..22aff76e3c 100644 --- a/Modules/_sre.c +++ b/Modules/_sre.c @@ -1714,7 +1714,7 @@ getstring(PyObject* string, Py_ssize_t* p_length, int* p_charsize) /* determine character size */ size = PyObject_Size(string); - 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))) diff --git a/Modules/_ssl.c b/Modules/_ssl.c index beb212fb94..af8df9c8ea 100644 --- a/Modules/_ssl.c +++ b/Modules/_ssl.c @@ -599,8 +599,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; @@ -987,7 +987,7 @@ PySSL_peercert(PySSLObject *self, PyObject *args) return NULL; } /* this is actually an immutable bytes sequence */ - retval = PyString_FromStringAndSize + retval = PyBytes_FromStringAndSize ((const char *) bytes_buf, len); OPENSSL_free(bytes_buf); return retval; @@ -1356,7 +1356,7 @@ static PyObject *PySSL_SSLread(PySSLObject *self, PyObject *args) } done: if (!buf_passed) { - PyObject *res = PyString_FromStringAndSize( + PyObject *res = PyBytes_FromStringAndSize( PyByteArray_AS_STRING(buf), count); Py_DECREF(buf); return res; diff --git a/Modules/_struct.c b/Modules/_struct.c index c162e6dd3a..ae8a160434 100644 --- a/Modules/_struct.c +++ b/Modules/_struct.c @@ -439,7 +439,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 * @@ -608,12 +608,12 @@ np_char(char *p, PyObject *v, const formatdef *f) if (v == NULL) return -1; } - if (!PyString_Check(v) || PyString_Size(v) != 1) { + if (!PyBytes_Check(v) || PyBytes_Size(v) != 1) { PyErr_SetString(StructError, "char format requires string of length 1"); return -1; } - *p = *PyString_AsString(v); + *p = *PyBytes_AsString(v); return 0; } @@ -1333,7 +1333,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); @@ -1478,7 +1478,7 @@ s_init(PyObject *self, PyObject *args, PyObject *kwds) Py_INCREF(o_format); } - if (!PyString_Check(o_format)) { + if (!PyBytes_Check(o_format)) { Py_DECREF(o_format); PyErr_Format(PyExc_TypeError, "Struct() argument 1 must be bytes, not %.200s", @@ -1518,12 +1518,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); } @@ -1645,15 +1645,15 @@ s_pack_internal(PyStructObject *soself, PyObject *args, int offset, char* buf) if (v == NULL) return -1; } - isstring = PyString_Check(v); + isstring = PyBytes_Check(v); if (!isstring && !PyByteArray_Check(v)) { PyErr_SetString(StructError, "argument for 's' must be a string"); return -1; } if (isstring) { - n = PyString_GET_SIZE(v); - p = PyString_AS_STRING(v); + n = PyBytes_GET_SIZE(v); + p = PyBytes_AS_STRING(v); } else { n = PyByteArray_GET_SIZE(v); @@ -1671,15 +1671,15 @@ s_pack_internal(PyStructObject *soself, PyObject *args, int offset, char* buf) if (v == NULL) return -1; } - isstring = PyString_Check(v); + isstring = PyBytes_Check(v); if (!isstring && !PyByteArray_Check(v)) { PyErr_SetString(StructError, "argument for 'p' must be a string"); return -1; } if (isstring) { - n = PyString_GET_SIZE(v); - p = PyString_AS_STRING(v); + n = PyBytes_GET_SIZE(v); + p = PyBytes_AS_STRING(v); } else { n = PyByteArray_GET_SIZE(v); @@ -1731,12 +1731,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; } @@ -2092,7 +2092,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/_tkinter.c b/Modules/_tkinter.c index 33efaffa6e..5002f4a001 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); else if (PyUnicode_Check(value)) { PyObject *v = PyUnicode_AsUTF8String(value); if (v == NULL) @@ -346,7 +346,7 @@ AsString(PyObject *value, PyObject *tmp) return NULL; } Py_DECREF(v); - return PyString_AsString(v); + return PyBytes_AsString(v); } else { PyObject *v = PyObject_Str(value); @@ -357,7 +357,7 @@ AsString(PyObject *value, PyObject *tmp) return NULL; } Py_DECREF(v); - return PyString_AsString(v); + return PyBytes_AsString(v); } } @@ -528,10 +528,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); @@ -539,7 +539,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); @@ -866,9 +866,9 @@ AsObj(PyObject *value) long longVal; int overflow; - 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 (PyLong_CheckExact(value) && @@ -961,7 +961,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) { @@ -1419,8 +1419,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 (PyUnicode_Check(in)) { @@ -3071,7 +3071,7 @@ init_tkinter(void) Py_FileSystemDefaultEncoding, NULL); if (cexe) - Tcl_FindExecutable(PyString_AsString(cexe)); + Tcl_FindExecutable(PyBytes_AsString(cexe)); Py_XDECREF(cexe); Py_DECREF(uexe); } diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c index a851212582..a84126d12b 100644 --- a/Modules/arraymodule.c +++ b/Modules/arraymodule.c @@ -1212,14 +1212,14 @@ array_fromfile(arrayobject *self, PyObject *args) if (b == NULL) return NULL; - if (!PyString_Check(b)) { + if (!PyBytes_Check(b)) { PyErr_SetString(PyExc_TypeError, "read() didn't return bytes"); Py_DECREF(b); return NULL; } - if (PyString_GET_SIZE(b) != nbytes) { + if (PyBytes_GET_SIZE(b) != nbytes) { PyErr_SetString(PyExc_EOFError, "read() didn't return enough bytes"); Py_DECREF(b); @@ -1263,7 +1263,7 @@ array_tofile(arrayobject *self, PyObject *f) PyObject *bytes, *res; if (i*BLOCKSIZE + size > nbytes) size = nbytes - i*BLOCKSIZE; - bytes = PyString_FromStringAndSize(ptr, size); + bytes = PyBytes_FromStringAndSize(ptr, size); if (bytes == NULL) return NULL; res = PyObject_CallMethod(f, "write", "O", bytes); @@ -1394,7 +1394,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); } @@ -1856,7 +1856,7 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds) if (!(initial == NULL || PyList_Check(initial) || PyByteArray_Check(initial) - || PyString_Check(initial) + || PyBytes_Check(initial) || PyTuple_Check(initial) || ((c=='u') && PyUnicode_Check(initial)))) { it = PyObject_GetIter(initial); @@ -1902,7 +1902,7 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds) } } else if (initial != NULL && (PyByteArray_Check(initial) || - PyString_Check(initial))) { + 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 eb380821d0..7f1e34b030 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,9 +1182,9 @@ 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)); - rv = PyString_FromStringAndSize - (PyString_AsString(str), len); + len = (int)(ncp - PyBytes_AsString(str)); + rv = PyBytes_FromStringAndSize + (PyBytes_AsString(str), len); Py_DECREF(str); str = rv; if (str == NULL) @@ -1254,10 +1254,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; @@ -1288,10 +1288,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++; @@ -1322,10 +1322,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; @@ -1356,10 +1356,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++; @@ -1392,10 +1392,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 ) { @@ -1508,10 +1508,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 b65bdab786..62b86a82df 100644 --- a/Modules/binascii.c +++ b/Modules/binascii.c @@ -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_AS_STRING(rv); + bin_data = (unsigned char *)PyBytes_AS_STRING(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_AS_STRING(rv); + ascii_data = (unsigned char *)PyBytes_AS_STRING(rv); /* Store the length */ *ascii_data++ = ' ' + (bin_len & 077); @@ -304,9 +304,9 @@ binascii_b2a_uu(PyObject *self, PyObject *args) } *ascii_data++ = '\n'; /* Append a courtesy newline */ - if (_PyString_Resize(&rv, + if (_PyBytes_Resize(&rv, (ascii_data - - (unsigned char *)PyString_AS_STRING(rv))) < 0) { + (unsigned char *)PyBytes_AS_STRING(rv))) < 0) { Py_DECREF(rv); rv = NULL; } @@ -358,9 +358,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_AS_STRING(rv); + bin_data = (unsigned char *)PyBytes_AS_STRING(rv); bin_len = 0; for( ; ascii_len > 0; ascii_len--, ascii_data++) { @@ -419,17 +419,17 @@ 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) { - if (_PyString_Resize(&rv, bin_len) < 0) { + if (_PyBytes_Resize(&rv, bin_len) < 0) { Py_DECREF(rv); rv = NULL; } } else { Py_DECREF(rv); - rv = PyString_FromStringAndSize("", 0); + rv = PyBytes_FromStringAndSize("", 0); } return rv; } @@ -456,9 +456,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_AS_STRING(rv); + ascii_data = (unsigned char *)PyBytes_AS_STRING(rv); for( ; bin_len > 0 ; bin_len--, bin_data++ ) { /* Shift the data into our buffer */ @@ -482,9 +482,9 @@ binascii_b2a_base64(PyObject *self, PyObject *args) } *ascii_data++ = '\n'; /* Append a courtesy newline */ - if (_PyString_Resize(&rv, + if (_PyBytes_Resize(&rv, (ascii_data - - (unsigned char *)PyString_AS_STRING(rv))) < 0) { + (unsigned char *)PyBytes_AS_STRING(rv))) < 0) { Py_DECREF(rv); rv = NULL; } @@ -510,9 +510,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_AS_STRING(rv); + bin_data = (unsigned char *)PyBytes_AS_STRING(rv); for( ; len > 0 ; len--, ascii_data++ ) { /* Get the byte and look it up */ @@ -546,9 +546,9 @@ binascii_a2b_hqx(PyObject *self, PyObject *args) Py_DECREF(rv); return NULL; } - if (_PyString_Resize(&rv, + if (_PyBytes_Resize(&rv, (bin_data - - (unsigned char *)PyString_AS_STRING(rv))) < 0) { + (unsigned char *)PyBytes_AS_STRING(rv))) < 0) { Py_DECREF(rv); rv = NULL; } @@ -575,9 +575,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_AS_STRING(rv); + out_data = (unsigned char *)PyBytes_AS_STRING(rv); for( in=0; in<len; in++) { ch = in_data[in]; @@ -603,9 +603,9 @@ binascii_rlecode_hqx(PyObject *self, PyObject *args) } } } - if (_PyString_Resize(&rv, + if (_PyBytes_Resize(&rv, (out_data - - (unsigned char *)PyString_AS_STRING(rv))) < 0) { + (unsigned char *)PyBytes_AS_STRING(rv))) < 0) { Py_DECREF(rv); rv = NULL; } @@ -628,9 +628,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_AS_STRING(rv); + ascii_data = (unsigned char *)PyBytes_AS_STRING(rv); for( ; len > 0 ; len--, bin_data++ ) { /* Shift into our buffer, and output any 6bits ready */ @@ -647,9 +647,9 @@ binascii_b2a_hqx(PyObject *self, PyObject *args) leftchar <<= (6-leftbits); *ascii_data++ = table_b2a_hqx[leftchar & 0x3f]; } - if (_PyString_Resize(&rv, + if (_PyBytes_Resize(&rv, (ascii_data - - (unsigned char *)PyString_AS_STRING(rv))) < 0) { + (unsigned char *)PyBytes_AS_STRING(rv))) < 0) { Py_DECREF(rv); rv = NULL; } @@ -671,14 +671,14 @@ binascii_rledecode_hqx(PyObject *self, PyObject *args) /* Empty string is a special case */ if ( in_len == 0 ) - return PyString_FromStringAndSize("", 0); + return PyBytes_FromStringAndSize("", 0); /* 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_AS_STRING(rv); + out_data = (unsigned char *)PyBytes_AS_STRING(rv); /* ** We need two macros here to get/put bytes and handle @@ -697,9 +697,9 @@ binascii_rledecode_hqx(PyObject *self, PyObject *args) #define OUTBYTE(b) \ do { \ if ( --out_len_left < 0 ) { \ - if (_PyString_Resize(&rv, 2*out_len) < 0) \ + if (_PyBytes_Resize(&rv, 2*out_len) < 0) \ { Py_DECREF(rv); return NULL; } \ - out_data = (unsigned char *)PyString_AS_STRING(rv) \ + out_data = (unsigned char *)PyBytes_AS_STRING(rv) \ + out_len; \ out_len_left = out_len-1; \ out_len = out_len * 2; \ @@ -747,9 +747,9 @@ binascii_rledecode_hqx(PyObject *self, PyObject *args) OUTBYTE(in_byte); } } - if (_PyString_Resize(&rv, + if (_PyBytes_Resize(&rv, (out_data - - (unsigned char *)PyString_AS_STRING(rv))) < 0) { + (unsigned char *)PyBytes_AS_STRING(rv))) < 0) { Py_DECREF(rv); rv = NULL; } @@ -948,10 +948,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_AS_STRING(retval); + retbuf = PyBytes_AS_STRING(retval); /* make hex version of string, taken from shamodule.c */ for (i=j=0; i < arglen; i++) { @@ -1008,10 +1008,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_AS_STRING(retval); + retbuf = PyBytes_AS_STRING(retval); for (i=j=0; i < arglen; i += 2) { int top = to_int(Py_CHARMASK(argbuf[i])); @@ -1123,7 +1123,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; } @@ -1323,7 +1323,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; } diff --git a/Modules/bz2module.c b/Modules/bz2module.c index 89d35aa48c..4adf8264ef 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(v) +#define BUF(v) PyBytes_AS_STRING(v) #define MODE_CLOSED 0 #define MODE_READ 1 @@ -232,7 +232,7 @@ Util_GetLine(BZ2FileObject *f, int n) int bytes_read; 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; @@ -272,7 +272,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; @@ -281,7 +281,7 @@ Util_GetLine(BZ2FileObject *f, int n) used_v_size = buf - BUF(v); if (used_v_size != total_v_size) { - if (_PyString_Resize(&v, used_v_size) < 0) { + if (_PyBytes_Resize(&v, used_v_size) < 0) { v = NULL; } } @@ -338,10 +338,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; @@ -352,17 +352,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); @@ -376,7 +376,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; @@ -409,7 +409,7 @@ BZ2File_read(BZ2FileObject *self, PyObject *args) case MODE_READ: break; case MODE_READ_EOF: - ret = PyString_FromStringAndSize("", 0); + ret = PyBytes_FromStringAndSize("", 0); goto cleanup; case MODE_CLOSED: PyErr_SetString(PyExc_ValueError, @@ -431,7 +431,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 || buffersize == 0) goto cleanup; bytesread = 0; @@ -456,7 +456,7 @@ 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) { ret = NULL; goto cleanup; } @@ -465,7 +465,7 @@ BZ2File_read(BZ2FileObject *self, PyObject *args) } } if (bytesread != buffersize) { - if (_PyString_Resize(&ret, bytesread) < 0) { + if (_PyBytes_Resize(&ret, bytesread) < 0) { ret = NULL; } } @@ -498,7 +498,7 @@ BZ2File_readline(BZ2FileObject *self, PyObject *args) case MODE_READ: break; case MODE_READ_EOF: - ret = PyString_FromStringAndSize("", 0); + ret = PyBytes_FromStringAndSize("", 0); goto cleanup; case MODE_CLOSED: PyErr_SetString(PyExc_ValueError, @@ -511,7 +511,7 @@ BZ2File_readline(BZ2FileObject *self, PyObject *args) } if (sizehint == 0) - ret = PyString_FromStringAndSize("", 0); + ret = PyBytes_FromStringAndSize("", 0); else ret = Util_GetLine(self, (sizehint < 0) ? 0 : sizehint); @@ -604,20 +604,20 @@ 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 */ - if (_PyString_Resize(&big_buffer, buffersize) < 0){ + if (_PyBytes_Resize(&big_buffer, buffersize) < 0){ big_buffer = NULL; goto error; } - buffer = PyString_AS_STRING(big_buffer); + buffer = PyBytes_AS_STRING(big_buffer); } continue; } @@ -626,7 +626,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); @@ -649,7 +649,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) { @@ -659,7 +659,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; @@ -812,7 +812,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)) { @@ -823,7 +823,7 @@ BZ2File_writelines(BZ2FileObject *self, PyObject *seq) "bytes objects"); goto error; } - line = PyString_FromStringAndSize(buffer, + line = PyBytes_FromStringAndSize(buffer, len); if (line == NULL) goto error; @@ -837,9 +837,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); @@ -1261,7 +1261,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, @@ -1270,7 +1270,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; } @@ -1363,7 +1363,7 @@ BZ2Comp_compress(BZ2CompObject *self, PyObject *args) return NULL; if (datasize == 0) - return PyString_FromStringAndSize("", 0); + return PyBytes_FromStringAndSize("", 0); ACQUIRE_LOCK(self); if (!self->running) { @@ -1372,7 +1372,7 @@ BZ2Comp_compress(BZ2CompObject *self, PyObject *args) goto error; } - ret = PyString_FromStringAndSize(NULL, bufsize); + ret = PyBytes_FromStringAndSize(NULL, bufsize); if (!ret) goto error; @@ -1395,7 +1395,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; } @@ -1405,7 +1405,7 @@ BZ2Comp_compress(BZ2CompObject *self, PyObject *args) } } - if (_PyString_Resize(&ret, + if (_PyBytes_Resize(&ret, (Py_ssize_t)(BZS_TOTAL_OUT(bzs) - totalout)) < 0) goto error; @@ -1442,7 +1442,7 @@ BZ2Comp_flush(BZ2CompObject *self) } self->running = 0; - ret = PyString_FromStringAndSize(NULL, bufsize); + ret = PyBytes_FromStringAndSize(NULL, bufsize); if (!ret) goto error; @@ -1463,7 +1463,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) @@ -1473,7 +1473,7 @@ BZ2Comp_flush(BZ2CompObject *self) } if (bzs->avail_out != 0) { - if (_PyString_Resize(&ret, + if (_PyBytes_Resize(&ret, (Py_ssize_t)(BZS_TOTAL_OUT(bzs) - totalout)) < 0) goto error; } @@ -1658,7 +1658,7 @@ BZ2Decomp_decompress(BZ2DecompObject *self, PyObject *args) goto error; } - ret = PyString_FromStringAndSize(NULL, bufsize); + ret = PyBytes_FromStringAndSize(NULL, bufsize); if (!ret) goto error; @@ -1677,7 +1677,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; @@ -1691,7 +1691,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; } @@ -1703,7 +1703,7 @@ BZ2Decomp_decompress(BZ2DecompObject *self, PyObject *args) } if (bzs->avail_out != 0) { - if (_PyString_Resize(&ret, + if (_PyBytes_Resize(&ret, (Py_ssize_t)(BZS_TOTAL_OUT(bzs) - totalout)) < 0) goto error; } @@ -1742,7 +1742,7 @@ BZ2Decomp_init(BZ2DecompObject *self, PyObject *args, PyObject *kwargs) } #endif - self->unused_data = PyString_FromStringAndSize("", 0); + self->unused_data = PyBytes_FromStringAndSize("", 0); if (!self->unused_data) goto error; @@ -1875,7 +1875,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; @@ -1907,7 +1907,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); return NULL; } @@ -1917,7 +1917,7 @@ bz2_compress(PyObject *self, PyObject *args, PyObject *kwargs) } if (bzs->avail_out != 0) { - if (_PyString_Resize(&ret, (Py_ssize_t)BZS_TOTAL_OUT(bzs)) < 0) { + if (_PyBytes_Resize(&ret, (Py_ssize_t)BZS_TOTAL_OUT(bzs)) < 0) { ret = NULL; } } @@ -1948,9 +1948,9 @@ bz2_decompress(PyObject *self, PyObject *args) return NULL; if (datasize == 0) - return PyString_FromStringAndSize("", 0); + return PyBytes_FromStringAndSize("", 0); - ret = PyString_FromStringAndSize(NULL, bufsize); + ret = PyBytes_FromStringAndSize(NULL, bufsize); if (!ret) return NULL; @@ -1989,7 +1989,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); return NULL; } @@ -1999,7 +1999,7 @@ bz2_decompress(PyObject *self, PyObject *args) } if (bzs->avail_out != 0) { - if (_PyString_Resize(&ret, (Py_ssize_t)BZS_TOTAL_OUT(bzs)) < 0) { + if (_PyBytes_Resize(&ret, (Py_ssize_t)BZS_TOTAL_OUT(bzs)) < 0) { ret = NULL; } } diff --git a/Modules/cStringIO.c b/Modules/cStringIO.c index 64e2146934..8929500fdf 100644 --- a/Modules/cStringIO.c +++ b/Modules/cStringIO.c @@ -118,7 +118,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); } @@ -136,7 +136,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"); @@ -176,7 +176,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"); @@ -214,7 +214,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"); @@ -237,7 +237,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) { @@ -314,7 +314,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; @@ -455,7 +455,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/cjkcodecs/multibytecodec.c b/Modules/cjkcodecs/multibytecodec.c index 4371db42ab..26dd8ddab0 100644 --- a/Modules/cjkcodecs/multibytecodec.c +++ b/Modules/cjkcodecs/multibytecodec.c @@ -175,15 +175,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; } @@ -330,11 +330,11 @@ multibytecodec_encerror(MultibyteCodec *codec, goto errorexit; } - assert(PyString_Check(retstr)); - retstrsize = PyString_GET_SIZE(retstr); + assert(PyBytes_Check(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 = PyLong_AsSsize_t(PyTuple_GET_ITEM(retobj, 1)); @@ -476,16 +476,16 @@ multibytecodec_encode(MultibyteCodec *codec, Py_ssize_t finalsize, r = 0; if (datalen == 0) - return PyString_FromStringAndSize(NULL, 0); + return PyBytes_FromStringAndSize(NULL, 0); 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; @@ -520,10 +520,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); @@ -1230,7 +1230,7 @@ mbstreamreader_iread(MultibyteStreamReaderObject *self, if (cres == NULL) goto errorexit; - if (!PyString_Check(cres)) { + if (!PyBytes_Check(cres)) { PyErr_Format(PyExc_TypeError, "stream function returned a " "non-bytes object (%.100s)", @@ -1238,28 +1238,28 @@ mbstreamreader_iread(MultibyteStreamReaderObject *self, 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; @@ -1603,8 +1603,8 @@ mbstreamwriter_reset(MultibyteStreamWriterObject *self) if (pwrt == NULL) return NULL; - assert(PyString_Check(pwrt)); - if (PyString_Size(pwrt) > 0) { + assert(PyBytes_Check(pwrt)); + if (PyBytes_Size(pwrt) > 0) { PyObject *wr; wr = PyObject_CallMethod(self->stream, "write", "O", pwrt); if (wr == NULL) { diff --git a/Modules/datetimemodule.c b/Modules/datetimemodule.c index e64b230a43..0ad5b91062 100644 --- a/Modules/datetimemodule.c +++ b/Modules/datetimemodule.c @@ -1181,7 +1181,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, @@ -1251,9 +1251,9 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple, * is expensive, don't unless they're actually used. */ totalnew = flen + 1; /* realistic if no %z/%Z */ - newfmt = PyString_FromStringAndSize(NULL, totalnew); + newfmt = PyBytes_FromStringAndSize(NULL, totalnew); if (newfmt == NULL) goto Done; - pnew = PyString_AsString(newfmt); + pnew = PyBytes_AsString(newfmt); usednew = 0; while ((ch = *pin++) != '\0') { @@ -1273,7 +1273,7 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple, /* format utcoffset */ char buf[100]; PyObject *tzinfo = get_tzinfo_member(object); - zreplacement = PyString_FromStringAndSize("", 0); + zreplacement = PyBytes_FromStringAndSize("", 0); if (zreplacement == NULL) goto Done; if (tzinfo != Py_None && tzinfo != NULL) { assert(tzinfoarg != NULL); @@ -1285,15 +1285,15 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple, goto Done; Py_DECREF(zreplacement); zreplacement = - PyString_FromStringAndSize(buf, + PyBytes_FromStringAndSize(buf, strlen(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 */ @@ -1317,9 +1317,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 */ @@ -1340,10 +1340,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; @@ -1351,14 +1351,14 @@ 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 *format; PyObject *time = PyImport_ImportModuleNoBlock("time"); if (time == NULL) goto Done; - format = PyUnicode_FromString(PyString_AS_STRING(newfmt)); + format = PyUnicode_FromString(PyBytes_AS_STRING(newfmt)); if (format != NULL) { result = PyObject_CallMethod(time, "strftime", "OO", format, timetuple); @@ -2213,15 +2213,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; } @@ -2609,7 +2609,7 @@ static PyObject * date_getstate(PyDateTime_Date *self) { PyObject* field; - field = PyString_FromStringAndSize((char*)self->data, + field = PyBytes_FromStringAndSize((char*)self->data, _PyDateTime_DATE_DATASIZE); return Py_BuildValue("(N)", field); } @@ -3062,9 +3062,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; @@ -3080,7 +3080,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; @@ -3397,7 +3397,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) @@ -3581,9 +3581,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; @@ -3599,7 +3599,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; @@ -4478,7 +4478,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/fcntlmodule.c b/Modules/fcntlmodule.c index c5d41f29cd..9acfece0c0 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 PyLong_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/md5module.c b/Modules/md5module.c index 833eb813ef..6a18a13b05 100644 --- a/Modules/md5module.c +++ b/Modules/md5module.c @@ -363,7 +363,7 @@ MD5_digest(MD5object *self, PyObject *unused) temp = self->hash_state; md5_done(&temp, digest); - return PyString_FromStringAndSize((const char *)digest, MD5_DIGESTSIZE); + return PyBytes_FromStringAndSize((const char *)digest, MD5_DIGESTSIZE); } PyDoc_STRVAR(MD5_hexdigest__doc__, diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index a6cd50b460..3600c983b6 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -708,9 +708,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); @@ -723,7 +723,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; diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 7020d8eb8b..f6bb023bc0 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -425,13 +425,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); } @@ -2197,7 +2197,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; @@ -2289,7 +2289,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; @@ -2340,7 +2340,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; @@ -2423,7 +2423,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 */ @@ -4445,7 +4445,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); if (arg_is_unicode) { PyObject *w; @@ -4849,18 +4849,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_AS_STRING(buffer), size); + n = read(fd, PyBytes_AS_STRING(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; } @@ -5160,13 +5160,13 @@ posix_putenv(PyObject *self, PyObject *args) #endif /* XXX This can leak memory -- not easy to fix :-( */ /* len includes space for a trailing \0; the size arg to - PyString_FromStringAndSize does not count that */ + PyBytes_FromStringAndSize does not count that */ #ifdef MS_WINDOWS len = wcslen(s1) + wcslen(s2) + 2; newstr = PyUnicode_FromUnicode(NULL, (int)len - 1); #else len = strlen(s1) + strlen(s2) + 2; - newstr = PyString_FromStringAndSize(NULL, (int)len - 1); + newstr = PyBytes_FromStringAndSize(NULL, (int)len - 1); #endif if (newstr == NULL) return PyErr_NoMemory(); @@ -5179,7 +5179,7 @@ posix_putenv(PyObject *self, PyObject *args) return NULL; } #else - newenv = PyString_AS_STRING(newstr); + newenv = PyBytes_AS_STRING(newstr); PyOS_snprintf(newenv, len, "%s=%s", s1, s2); if (putenv(newenv)) { Py_DECREF(newstr); @@ -6667,11 +6667,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); } @@ -6738,11 +6738,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/pyexpat.c b/Modules/pyexpat.c index 852d093889..fcd44c3d90 100644 --- a/Modules/pyexpat.c +++ b/Modules/pyexpat.c @@ -215,7 +215,7 @@ 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 = PyUnicode_FromString(func_name); @@ -864,8 +864,8 @@ readinst(char *buf, int buf_size, PyObject *meth) if (str == NULL) goto finally; - if (PyString_Check(str)) - ptr = PyString_AS_STRING(str); + if (PyBytes_Check(str)) + ptr = PyBytes_AS_STRING(str); else if (PyByteArray_Check(str)) ptr = PyByteArray_AS_STRING(str); else { @@ -988,7 +988,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; diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c index 653b713de5..56acf60491 100644 --- a/Modules/selectmodule.c +++ b/Modules/selectmodule.c @@ -1216,7 +1216,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/sha1module.c b/Modules/sha1module.c index 9b4d8e5173..1d5f070524 100644 --- a/Modules/sha1module.c +++ b/Modules/sha1module.c @@ -339,7 +339,7 @@ SHA1_digest(SHA1object *self, PyObject *unused) temp = self->hash_state; sha1_done(&temp, digest); - return PyString_FromStringAndSize((const char *)digest, SHA1_DIGESTSIZE); + return PyBytes_FromStringAndSize((const char *)digest, SHA1_DIGESTSIZE); } PyDoc_STRVAR(SHA1_hexdigest__doc__, diff --git a/Modules/sha256module.c b/Modules/sha256module.c index f31013452c..162a905477 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__, diff --git a/Modules/sha512module.c b/Modules/sha512module.c index 3e32132dcc..3fe5a1b2fc 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__, diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index e2f384b839..b2cd9a28d5 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -967,7 +967,7 @@ 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, addrlen); + return PyBytes_FromStringAndSize(a->sun_path, addrlen); } else #endif /* linux */ @@ -1326,12 +1326,12 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args, addr = (struct sockaddr_sco *)addr_ret; _BT_SCO_MEMB(addr, family) = AF_BLUETOOTH; - if (!PyString_Check(args)) { + if (!PyBytes_Check(args)) { PyErr_SetString(socket_error, "getsockaddrarg: " "wrong format"); return 0; } - straddr = PyString_AS_STRING(args); + straddr = PyBytes_AS_STRING(args); if (setbdaddr(straddr, &_BT_SCO_MEMB(addr, bdaddr)) < 0) return 0; @@ -1773,16 +1773,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; } @@ -2212,12 +2212,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. */ @@ -2227,7 +2227,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 successful. */ - _PyString_Resize(&buf, outlen); + _PyBytes_Resize(&buf, outlen); } return buf; @@ -2383,11 +2383,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; @@ -2396,7 +2396,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; } @@ -3519,7 +3519,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, @@ -3548,7 +3548,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 @@ -3625,11 +3625,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 { @@ -3728,10 +3728,10 @@ socket_getaddrinfo(PyObject *self, PyObject *args) idna = PyObject_CallMethod(hobj, "encode", "s", "idna"); if (!idna) return NULL; - assert(PyString_Check(idna)); - hptr = PyString_AS_STRING(idna); - } else if (PyString_Check(hobj)) { - hptr = PyString_AsString(hobj); + assert(PyBytes_Check(idna)); + hptr = PyBytes_AS_STRING(idna); + } else if (PyBytes_Check(hobj)) { + hptr = PyBytes_AsString(hobj); } else { PyErr_SetString(PyExc_TypeError, "getaddrinfo() argument 1 must be string or None"); @@ -3745,8 +3745,8 @@ socket_getaddrinfo(PyObject *self, PyObject *args) pptr = pbuf; } else if (PyUnicode_Check(pobj)) { pptr = PyUnicode_AsString(pobj); - } 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/termios.c b/Modules/termios.c index 0707ad9330..ff69c92f53 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 (PyLong_Check(v)) mode.c_cc[i] = (cc_t) PyLong_AsLong(v); else { |