summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGregory P. Smith <greg@mad-scientist.com>2008-06-10 17:42:36 (GMT)
committerGregory P. Smith <greg@mad-scientist.com>2008-06-10 17:42:36 (GMT)
commit99a3dce92decb4c43888faf6bffcbe1632657e60 (patch)
treea693b76fc0cbfa6cb676be1f8dbca2c7314664f1
parentb67b53db51b470ba0740c97abc16e095ec0cfd28 (diff)
downloadcpython-99a3dce92decb4c43888faf6bffcbe1632657e60.zip
cpython-99a3dce92decb4c43888faf6bffcbe1632657e60.tar.gz
cpython-99a3dce92decb4c43888faf6bffcbe1632657e60.tar.bz2
More reverting of r63675 per the mailing list discussions. This restores
occurances of PyBytes_ in the code to their original PyString_ names. The bytesobject.c file will be renamed back to stringobject.c in a future checkin.
-rw-r--r--Modules/datetimemodule.c4
-rw-r--r--Objects/bytesobject.c952
-rw-r--r--Objects/fileobject.c6
3 files changed, 481 insertions, 481 deletions
diff --git a/Modules/datetimemodule.c b/Modules/datetimemodule.c
index 3adf0e2..3443b42 100644
--- a/Modules/datetimemodule.c
+++ b/Modules/datetimemodule.c
@@ -1207,9 +1207,9 @@ wrap_strftime(PyObject *object, const char *format, size_t format_len,
* is expensive, don't unless they're actually used.
*/
totalnew = format_len + 1; /* realistic if no %z/%Z/%f */
- newfmt = PyBytes_FromStringAndSize(NULL, totalnew);
+ newfmt = PyString_FromStringAndSize(NULL, totalnew);
if (newfmt == NULL) goto Done;
- pnew = PyBytes_AsString(newfmt);
+ pnew = PyString_AsString(newfmt);
usednew = 0;
pin = format;
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c
index d0e4e26..793cc88 100644
--- a/Objects/bytesobject.c
+++ b/Objects/bytesobject.c
@@ -1,4 +1,4 @@
-/* String object implementation */
+/* String (str/bytes) object implementation */
#define PY_SSIZE_T_CLEAN
@@ -9,8 +9,8 @@
int null_strings, one_strings;
#endif
-static PyBytesObject *characters[UCHAR_MAX + 1];
-static PyBytesObject *nullstring;
+static PyStringObject *characters[UCHAR_MAX + 1];
+static PyStringObject *nullstring;
/* This dictionary holds all interned strings. Note that references to
strings in this dictionary are *not* counted in the string's ob_refcnt.
@@ -23,19 +23,19 @@ static PyBytesObject *nullstring;
static PyObject *interned;
/*
- For both PyBytes_FromString() and PyBytes_FromStringAndSize(), the
+ For both PyString_FromString() and PyString_FromStringAndSize(), the
parameter `size' denotes number of characters to allocate, not counting any
null terminating character.
- For PyBytes_FromString(), the parameter `str' points to a null-terminated
+ For PyString_FromString(), the parameter `str' points to a null-terminated
string containing exactly `size' bytes.
- For PyBytes_FromStringAndSize(), the parameter the parameter `str' is
+ For PyString_FromStringAndSize(), the parameter the parameter `str' is
either NULL or else points to a string containing at least `size' bytes.
- For PyBytes_FromStringAndSize(), the string in the `str' parameter does
+ For PyString_FromStringAndSize(), the string in the `str' parameter does
not have to be null-terminated. (Therefore it is safe to construct a
- substring by calling `PyBytes_FromStringAndSize(origstring, substrlen)'.)
- If `str' is NULL then PyBytes_FromStringAndSize() will allocate `size+1'
+ substring by calling `PyString_FromStringAndSize(origstring, substrlen)'.)
+ If `str' is NULL then PyString_FromStringAndSize() will allocate `size+1'
bytes (setting the last byte to the null terminating character) and you can
fill in the data yourself. If `str' is non-NULL then the resulting
PyString object must be treated as immutable and you must not fill in nor
@@ -45,16 +45,16 @@ static PyObject *interned;
items" in a variable-size object, will contain the number of bytes
allocated for string data, not counting the null terminating character. It
is therefore equal to the equal to the `size' parameter (for
- PyBytes_FromStringAndSize()) or the length of the string in the `str'
- parameter (for PyBytes_FromString()).
+ PyString_FromStringAndSize()) or the length of the string in the `str'
+ parameter (for PyString_FromString()).
*/
PyObject *
-PyBytes_FromStringAndSize(const char *str, Py_ssize_t size)
+PyString_FromStringAndSize(const char *str, Py_ssize_t size)
{
- register PyBytesObject *op;
+ register PyStringObject *op;
if (size < 0) {
PyErr_SetString(PyExc_SystemError,
- "Negative size passed to PyBytes_FromStringAndSize");
+ "Negative size passed to PyString_FromStringAndSize");
return NULL;
}
if (size == 0 && (op = nullstring) != NULL) {
@@ -75,10 +75,10 @@ PyBytes_FromStringAndSize(const char *str, Py_ssize_t size)
}
/* Inline PyObject_NewVar */
- op = (PyBytesObject *)PyObject_MALLOC(sizeof(PyBytesObject) + size);
+ op = (PyStringObject *)PyObject_MALLOC(sizeof(PyStringObject) + size);
if (op == NULL)
return PyErr_NoMemory();
- PyObject_INIT_VAR(op, &PyBytes_Type, size);
+ PyObject_INIT_VAR(op, &PyString_Type, size);
op->ob_shash = -1;
op->ob_sstate = SSTATE_NOT_INTERNED;
if (str != NULL)
@@ -88,13 +88,13 @@ PyBytes_FromStringAndSize(const char *str, Py_ssize_t size)
if (size == 0) {
PyObject *t = (PyObject *)op;
PyString_InternInPlace(&t);
- op = (PyBytesObject *)t;
+ op = (PyStringObject *)t;
nullstring = op;
Py_INCREF(op);
} else if (size == 1 && str != NULL) {
PyObject *t = (PyObject *)op;
PyString_InternInPlace(&t);
- op = (PyBytesObject *)t;
+ op = (PyStringObject *)t;
characters[*str & UCHAR_MAX] = op;
Py_INCREF(op);
}
@@ -102,10 +102,10 @@ PyBytes_FromStringAndSize(const char *str, Py_ssize_t size)
}
PyObject *
-PyBytes_FromString(const char *str)
+PyString_FromString(const char *str)
{
register size_t size;
- register PyBytesObject *op;
+ register PyStringObject *op;
assert(str != NULL);
size = strlen(str);
@@ -130,10 +130,10 @@ PyBytes_FromString(const char *str)
}
/* Inline PyObject_NewVar */
- op = (PyBytesObject *)PyObject_MALLOC(sizeof(PyBytesObject) + size);
+ op = (PyStringObject *)PyObject_MALLOC(sizeof(PyStringObject) + size);
if (op == NULL)
return PyErr_NoMemory();
- PyObject_INIT_VAR(op, &PyBytes_Type, size);
+ PyObject_INIT_VAR(op, &PyString_Type, size);
op->ob_shash = -1;
op->ob_sstate = SSTATE_NOT_INTERNED;
Py_MEMCPY(op->ob_sval, str, size+1);
@@ -141,13 +141,13 @@ PyBytes_FromString(const char *str)
if (size == 0) {
PyObject *t = (PyObject *)op;
PyString_InternInPlace(&t);
- op = (PyBytesObject *)t;
+ op = (PyStringObject *)t;
nullstring = op;
Py_INCREF(op);
} else if (size == 1) {
PyObject *t = (PyObject *)op;
PyString_InternInPlace(&t);
- op = (PyBytesObject *)t;
+ op = (PyStringObject *)t;
characters[*str & UCHAR_MAX] = op;
Py_INCREF(op);
}
@@ -155,7 +155,7 @@ PyBytes_FromString(const char *str)
}
PyObject *
-PyBytes_FromFormatV(const char *format, va_list vargs)
+PyString_FromFormatV(const char *format, va_list vargs)
{
va_list count;
Py_ssize_t n = 0;
@@ -230,11 +230,11 @@ PyBytes_FromFormatV(const char *format, va_list vargs)
/* step 2: fill the buffer */
/* Since we've analyzed how much space we need for the worst case,
use sprintf directly instead of the slower PyOS_snprintf. */
- string = PyBytes_FromStringAndSize(NULL, n);
+ string = PyString_FromStringAndSize(NULL, n);
if (!string)
return NULL;
- s = PyBytes_AsString(string);
+ s = PyString_AsString(string);
for (f = format; *f; f++) {
if (*f == '%') {
@@ -334,12 +334,12 @@ PyBytes_FromFormatV(const char *format, va_list vargs)
}
end:
- _PyBytes_Resize(&string, s - PyBytes_AS_STRING(string));
+ _PyString_Resize(&string, s - PyString_AS_STRING(string));
return string;
}
PyObject *
-PyBytes_FromFormat(const char *format, ...)
+PyString_FromFormat(const char *format, ...)
{
PyObject* ret;
va_list vargs;
@@ -349,34 +349,34 @@ PyBytes_FromFormat(const char *format, ...)
#else
va_start(vargs);
#endif
- ret = PyBytes_FromFormatV(format, vargs);
+ ret = PyString_FromFormatV(format, vargs);
va_end(vargs);
return ret;
}
-PyObject *PyBytes_Decode(const char *s,
+PyObject *PyString_Decode(const char *s,
Py_ssize_t size,
const char *encoding,
const char *errors)
{
PyObject *v, *str;
- str = PyBytes_FromStringAndSize(s, size);
+ str = PyString_FromStringAndSize(s, size);
if (str == NULL)
return NULL;
- v = PyBytes_AsDecodedString(str, encoding, errors);
+ v = PyString_AsDecodedString(str, encoding, errors);
Py_DECREF(str);
return v;
}
-PyObject *PyBytes_AsDecodedObject(PyObject *str,
+PyObject *PyString_AsDecodedObject(PyObject *str,
const char *encoding,
const char *errors)
{
PyObject *v;
- if (!PyBytes_Check(str)) {
+ if (!PyString_Check(str)) {
PyErr_BadArgument();
goto onError;
}
@@ -401,13 +401,13 @@ PyObject *PyBytes_AsDecodedObject(PyObject *str,
return NULL;
}
-PyObject *PyBytes_AsDecodedString(PyObject *str,
+PyObject *PyString_AsDecodedString(PyObject *str,
const char *encoding,
const char *errors)
{
PyObject *v;
- v = PyBytes_AsDecodedObject(str, encoding, errors);
+ v = PyString_AsDecodedObject(str, encoding, errors);
if (v == NULL)
goto onError;
@@ -421,7 +421,7 @@ PyObject *PyBytes_AsDecodedString(PyObject *str,
goto onError;
}
#endif
- if (!PyBytes_Check(v)) {
+ if (!PyString_Check(v)) {
PyErr_Format(PyExc_TypeError,
"decoder did not return a string object (type=%.400s)",
Py_TYPE(v)->tp_name);
@@ -435,28 +435,28 @@ PyObject *PyBytes_AsDecodedString(PyObject *str,
return NULL;
}
-PyObject *PyBytes_Encode(const char *s,
+PyObject *PyString_Encode(const char *s,
Py_ssize_t size,
const char *encoding,
const char *errors)
{
PyObject *v, *str;
- str = PyBytes_FromStringAndSize(s, size);
+ str = PyString_FromStringAndSize(s, size);
if (str == NULL)
return NULL;
- v = PyBytes_AsEncodedString(str, encoding, errors);
+ v = PyString_AsEncodedString(str, encoding, errors);
Py_DECREF(str);
return v;
}
-PyObject *PyBytes_AsEncodedObject(PyObject *str,
+PyObject *PyString_AsEncodedObject(PyObject *str,
const char *encoding,
const char *errors)
{
PyObject *v;
- if (!PyBytes_Check(str)) {
+ if (!PyString_Check(str)) {
PyErr_BadArgument();
goto onError;
}
@@ -481,13 +481,13 @@ PyObject *PyBytes_AsEncodedObject(PyObject *str,
return NULL;
}
-PyObject *PyBytes_AsEncodedString(PyObject *str,
+PyObject *PyString_AsEncodedString(PyObject *str,
const char *encoding,
const char *errors)
{
PyObject *v;
- v = PyBytes_AsEncodedObject(str, encoding, errors);
+ v = PyString_AsEncodedObject(str, encoding, errors);
if (v == NULL)
goto onError;
@@ -501,7 +501,7 @@ PyObject *PyBytes_AsEncodedString(PyObject *str,
goto onError;
}
#endif
- if (!PyBytes_Check(v)) {
+ if (!PyString_Check(v)) {
PyErr_Format(PyExc_TypeError,
"encoder did not return a string object (type=%.400s)",
Py_TYPE(v)->tp_name);
@@ -518,7 +518,7 @@ PyObject *PyBytes_AsEncodedString(PyObject *str,
static void
string_dealloc(PyObject *op)
{
- switch (PyBytes_CHECK_INTERNED(op)) {
+ switch (PyString_CHECK_INTERNED(op)) {
case SSTATE_NOT_INTERNED:
break;
@@ -544,7 +544,7 @@ string_dealloc(PyObject *op)
the string is UTF-8 encoded and should be re-encoded in the
specified encoding. */
-PyObject *PyBytes_DecodeEscape(const char *s,
+PyObject *PyString_DecodeEscape(const char *s,
Py_ssize_t len,
const char *errors,
Py_ssize_t unicode,
@@ -555,10 +555,10 @@ PyObject *PyBytes_DecodeEscape(const char *s,
const char *end;
PyObject *v;
Py_ssize_t newlen = recode_encoding ? 4*len:len;
- v = PyBytes_FromStringAndSize((char *)NULL, newlen);
+ v = PyString_FromStringAndSize((char *)NULL, newlen);
if (v == NULL)
return NULL;
- p = buf = PyBytes_AsString(v);
+ p = buf = PyString_AsString(v);
end = s + len;
while (s < end) {
if (*s != '\\') {
@@ -582,9 +582,9 @@ PyObject *PyBytes_DecodeEscape(const char *s,
if (!w) goto failed;
/* Append bytes to output buffer. */
- assert(PyBytes_Check(w));
- r = PyBytes_AS_STRING(w);
- rn = PyBytes_GET_SIZE(w);
+ assert(PyString_Check(w));
+ r = PyString_AS_STRING(w);
+ rn = PyString_GET_SIZE(w);
Py_MEMCPY(p, r, rn);
p += rn;
Py_DECREF(w);
@@ -687,7 +687,7 @@ PyObject *PyBytes_DecodeEscape(const char *s,
}
}
if (p-buf < newlen)
- _PyBytes_Resize(&v, p - buf);
+ _PyString_Resize(&v, p - buf);
return v;
failed:
Py_DECREF(v);
@@ -702,7 +702,7 @@ string_getsize(register PyObject *op)
{
char *s;
Py_ssize_t len;
- if (PyBytes_AsStringAndSize(op, &s, &len))
+ if (PyString_AsStringAndSize(op, &s, &len))
return -1;
return len;
}
@@ -712,29 +712,29 @@ string_getbuffer(register PyObject *op)
{
char *s;
Py_ssize_t len;
- if (PyBytes_AsStringAndSize(op, &s, &len))
+ if (PyString_AsStringAndSize(op, &s, &len))
return NULL;
return s;
}
Py_ssize_t
-PyBytes_Size(register PyObject *op)
+PyString_Size(register PyObject *op)
{
- if (!PyBytes_Check(op))
+ if (!PyString_Check(op))
return string_getsize(op);
return Py_SIZE(op);
}
/*const*/ char *
-PyBytes_AsString(register PyObject *op)
+PyString_AsString(register PyObject *op)
{
- if (!PyBytes_Check(op))
+ if (!PyString_Check(op))
return string_getbuffer(op);
- return ((PyBytesObject *)op) -> ob_sval;
+ return ((PyStringObject *)op) -> ob_sval;
}
int
-PyBytes_AsStringAndSize(register PyObject *obj,
+PyString_AsStringAndSize(register PyObject *obj,
register char **s,
register Py_ssize_t *len)
{
@@ -743,7 +743,7 @@ PyBytes_AsStringAndSize(register PyObject *obj,
return -1;
}
- if (!PyBytes_Check(obj)) {
+ if (!PyString_Check(obj)) {
#ifdef Py_USING_UNICODE
if (PyUnicode_Check(obj)) {
obj = _PyUnicode_AsDefaultEncodedString(obj, NULL);
@@ -760,10 +760,10 @@ PyBytes_AsStringAndSize(register PyObject *obj,
}
}
- *s = PyBytes_AS_STRING(obj);
+ *s = PyString_AS_STRING(obj);
if (len != NULL)
- *len = PyBytes_GET_SIZE(obj);
- else if (strlen(*s) != (size_t)PyBytes_GET_SIZE(obj)) {
+ *len = PyString_GET_SIZE(obj);
+ else if (strlen(*s) != (size_t)PyString_GET_SIZE(obj)) {
PyErr_SetString(PyExc_TypeError,
"expected string without null bytes");
return -1;
@@ -781,23 +781,23 @@ PyBytes_AsStringAndSize(register PyObject *obj,
#include "stringlib/find.h"
#include "stringlib/partition.h"
-#define _Py_InsertThousandsGrouping _PyBytes_InsertThousandsGrouping
+#define _Py_InsertThousandsGrouping _PyString_InsertThousandsGrouping
#include "stringlib/localeutil.h"
static int
-string_print(PyBytesObject *op, FILE *fp, int flags)
+string_print(PyStringObject *op, FILE *fp, int flags)
{
Py_ssize_t i, str_len;
char c;
int quote;
/* XXX Ought to check for interrupts when writing long strings */
- if (! PyBytes_CheckExact(op)) {
+ if (! PyString_CheckExact(op)) {
int ret;
/* A str subclass may have its own __str__ method. */
- op = (PyBytesObject *) PyObject_Str((PyObject *)op);
+ op = (PyStringObject *) PyObject_Str((PyObject *)op);
if (op == NULL)
return -1;
ret = string_print(op, fp, flags);
@@ -860,9 +860,9 @@ string_print(PyBytesObject *op, FILE *fp, int flags)
}
PyObject *
-PyBytes_Repr(PyObject *obj, int smartquotes)
+PyString_Repr(PyObject *obj, int smartquotes)
{
- register PyBytesObject* op = (PyBytesObject*) obj;
+ register PyStringObject* op = (PyStringObject*) obj;
size_t newsize = 2 + 4 * Py_SIZE(op);
PyObject *v;
if (newsize > PY_SSIZE_T_MAX || newsize / 4 != Py_SIZE(op)) {
@@ -870,7 +870,7 @@ PyBytes_Repr(PyObject *obj, int smartquotes)
"string is too large to make repr");
return NULL;
}
- v = PyBytes_FromStringAndSize((char *)NULL, newsize);
+ v = PyString_FromStringAndSize((char *)NULL, newsize);
if (v == NULL) {
return NULL;
}
@@ -887,12 +887,12 @@ PyBytes_Repr(PyObject *obj, int smartquotes)
!memchr(op->ob_sval, '"', Py_SIZE(op)))
quote = '"';
- p = PyBytes_AS_STRING(v);
+ p = PyString_AS_STRING(v);
*p++ = quote;
for (i = 0; i < Py_SIZE(op); i++) {
/* There's at least enough room for a hex escape
and a closing quote. */
- assert(newsize - (p - PyBytes_AS_STRING(v)) >= 5);
+ assert(newsize - (p - PyString_AS_STRING(v)) >= 5);
c = op->ob_sval[i];
if (c == quote || c == '\\')
*p++ = '\\', *p++ = c;
@@ -912,11 +912,11 @@ PyBytes_Repr(PyObject *obj, int smartquotes)
else
*p++ = c;
}
- assert(newsize - (p - PyBytes_AS_STRING(v)) >= 1);
+ assert(newsize - (p - PyString_AS_STRING(v)) >= 1);
*p++ = quote;
*p = '\0';
- _PyBytes_Resize(
- &v, (p - PyBytes_AS_STRING(v)));
+ _PyString_Resize(
+ &v, (p - PyString_AS_STRING(v)));
return v;
}
}
@@ -924,36 +924,36 @@ PyBytes_Repr(PyObject *obj, int smartquotes)
static PyObject *
string_repr(PyObject *op)
{
- return PyBytes_Repr(op, 1);
+ return PyString_Repr(op, 1);
}
static PyObject *
string_str(PyObject *s)
{
- assert(PyBytes_Check(s));
- if (PyBytes_CheckExact(s)) {
+ assert(PyString_Check(s));
+ if (PyString_CheckExact(s)) {
Py_INCREF(s);
return s;
}
else {
/* Subtype -- return genuine string with the same value. */
- PyBytesObject *t = (PyBytesObject *) s;
- return PyBytes_FromStringAndSize(t->ob_sval, Py_SIZE(t));
+ PyStringObject *t = (PyStringObject *) s;
+ return PyString_FromStringAndSize(t->ob_sval, Py_SIZE(t));
}
}
static Py_ssize_t
-string_length(PyBytesObject *a)
+string_length(PyStringObject *a)
{
return Py_SIZE(a);
}
static PyObject *
-string_concat(register PyBytesObject *a, register PyObject *bb)
+string_concat(register PyStringObject *a, register PyObject *bb)
{
register Py_ssize_t size;
- register PyBytesObject *op;
- if (!PyBytes_Check(bb)) {
+ register PyStringObject *op;
+ if (!PyString_Check(bb)) {
#ifdef Py_USING_UNICODE
if (PyUnicode_Check(bb))
return PyUnicode_Concat((PyObject *)a, bb);
@@ -965,10 +965,10 @@ string_concat(register PyBytesObject *a, register PyObject *bb)
Py_TYPE(bb)->tp_name);
return NULL;
}
-#define b ((PyBytesObject *)bb)
+#define b ((PyStringObject *)bb)
/* Optimize cases with empty left or right operand */
if ((Py_SIZE(a) == 0 || Py_SIZE(b) == 0) &&
- PyBytes_CheckExact(a) && PyBytes_CheckExact(b)) {
+ PyString_CheckExact(a) && PyString_CheckExact(b)) {
if (Py_SIZE(a) == 0) {
Py_INCREF(bb);
return bb;
@@ -984,10 +984,10 @@ string_concat(register PyBytesObject *a, register PyObject *bb)
}
/* Inline PyObject_NewVar */
- op = (PyBytesObject *)PyObject_MALLOC(sizeof(PyBytesObject) + size);
+ op = (PyStringObject *)PyObject_MALLOC(sizeof(PyStringObject) + size);
if (op == NULL)
return PyErr_NoMemory();
- PyObject_INIT_VAR(op, &PyBytes_Type, size);
+ PyObject_INIT_VAR(op, &PyString_Type, size);
op->ob_shash = -1;
op->ob_sstate = SSTATE_NOT_INTERNED;
Py_MEMCPY(op->ob_sval, a->ob_sval, Py_SIZE(a));
@@ -998,12 +998,12 @@ string_concat(register PyBytesObject *a, register PyObject *bb)
}
static PyObject *
-string_repeat(register PyBytesObject *a, register Py_ssize_t n)
+string_repeat(register PyStringObject *a, register Py_ssize_t n)
{
register Py_ssize_t i;
register Py_ssize_t j;
register Py_ssize_t size;
- register PyBytesObject *op;
+ register PyStringObject *op;
size_t nbytes;
if (n < 0)
n = 0;
@@ -1016,21 +1016,21 @@ string_repeat(register PyBytesObject *a, register Py_ssize_t n)
"repeated string is too long");
return NULL;
}
- if (size == Py_SIZE(a) && PyBytes_CheckExact(a)) {
+ if (size == Py_SIZE(a) && PyString_CheckExact(a)) {
Py_INCREF(a);
return (PyObject *)a;
}
nbytes = (size_t)size;
- if (nbytes + sizeof(PyBytesObject) <= nbytes) {
+ if (nbytes + sizeof(PyStringObject) <= nbytes) {
PyErr_SetString(PyExc_OverflowError,
"repeated string is too long");
return NULL;
}
- op = (PyBytesObject *)
- PyObject_MALLOC(sizeof(PyBytesObject) + nbytes);
+ op = (PyStringObject *)
+ PyObject_MALLOC(sizeof(PyStringObject) + nbytes);
if (op == NULL)
return PyErr_NoMemory();
- PyObject_INIT_VAR(op, &PyBytes_Type, size);
+ PyObject_INIT_VAR(op, &PyString_Type, size);
op->ob_shash = -1;
op->ob_sstate = SSTATE_NOT_INTERNED;
op->ob_sval[size] = '\0';
@@ -1054,7 +1054,7 @@ string_repeat(register PyBytesObject *a, register Py_ssize_t n)
/* String slice a[i:j] consists of characters a[i] ... a[j-1] */
static PyObject *
-string_slice(register PyBytesObject *a, register Py_ssize_t i,
+string_slice(register PyStringObject *a, register Py_ssize_t i,
register Py_ssize_t j)
/* j -- may be negative! */
{
@@ -1064,25 +1064,25 @@ string_slice(register PyBytesObject *a, register Py_ssize_t i,
j = 0; /* Avoid signed/unsigned bug in next line */
if (j > Py_SIZE(a))
j = Py_SIZE(a);
- if (i == 0 && j == Py_SIZE(a) && PyBytes_CheckExact(a)) {
+ if (i == 0 && j == Py_SIZE(a) && PyString_CheckExact(a)) {
/* It's the same as a */
Py_INCREF(a);
return (PyObject *)a;
}
if (j < i)
j = i;
- return PyBytes_FromStringAndSize(a->ob_sval + i, j-i);
+ return PyString_FromStringAndSize(a->ob_sval + i, j-i);
}
static int
string_contains(PyObject *str_obj, PyObject *sub_obj)
{
- if (!PyBytes_CheckExact(sub_obj)) {
+ if (!PyString_CheckExact(sub_obj)) {
#ifdef Py_USING_UNICODE
if (PyUnicode_Check(sub_obj))
return PyUnicode_Contains(str_obj, sub_obj);
#endif
- if (!PyBytes_Check(sub_obj)) {
+ if (!PyString_Check(sub_obj)) {
PyErr_Format(PyExc_TypeError,
"'in <string>' requires string as left operand, "
"not %.200s", Py_TYPE(sub_obj)->tp_name);
@@ -1094,7 +1094,7 @@ string_contains(PyObject *str_obj, PyObject *sub_obj)
}
static PyObject *
-string_item(PyBytesObject *a, register Py_ssize_t i)
+string_item(PyStringObject *a, register Py_ssize_t i)
{
char pchar;
PyObject *v;
@@ -1105,7 +1105,7 @@ string_item(PyBytesObject *a, register Py_ssize_t i)
pchar = a->ob_sval[i];
v = (PyObject *)characters[pchar & UCHAR_MAX];
if (v == NULL)
- v = PyBytes_FromStringAndSize(&pchar, 1);
+ v = PyString_FromStringAndSize(&pchar, 1);
else {
#ifdef COUNT_ALLOCS
one_strings++;
@@ -1116,7 +1116,7 @@ string_item(PyBytesObject *a, register Py_ssize_t i)
}
static PyObject*
-string_richcompare(PyBytesObject *a, PyBytesObject *b, int op)
+string_richcompare(PyStringObject *a, PyStringObject *b, int op)
{
int c;
Py_ssize_t len_a, len_b;
@@ -1124,7 +1124,7 @@ string_richcompare(PyBytesObject *a, PyBytesObject *b, int op)
PyObject *result;
/* Make sure both arguments are strings. */
- if (!(PyBytes_Check(a) && PyBytes_Check(b))) {
+ if (!(PyString_Check(a) && PyString_Check(b))) {
result = Py_NotImplemented;
goto out;
}
@@ -1178,17 +1178,17 @@ string_richcompare(PyBytesObject *a, PyBytesObject *b, int op)
}
int
-_PyBytes_Eq(PyObject *o1, PyObject *o2)
+_PyString_Eq(PyObject *o1, PyObject *o2)
{
- PyBytesObject *a = (PyBytesObject*) o1;
- PyBytesObject *b = (PyBytesObject*) o2;
+ PyStringObject *a = (PyStringObject*) o1;
+ PyStringObject *b = (PyStringObject*) o2;
return Py_SIZE(a) == Py_SIZE(b)
&& *a->ob_sval == *b->ob_sval
&& memcmp(a->ob_sval, b->ob_sval, Py_SIZE(a)) == 0;
}
static long
-string_hash(PyBytesObject *a)
+string_hash(PyStringObject *a)
{
register Py_ssize_t len;
register unsigned char *p;
@@ -1209,14 +1209,14 @@ string_hash(PyBytesObject *a)
}
static PyObject*
-string_subscript(PyBytesObject* self, PyObject* item)
+string_subscript(PyStringObject* self, PyObject* item)
{
if (PyIndex_Check(item)) {
Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError);
if (i == -1 && PyErr_Occurred())
return NULL;
if (i < 0)
- i += PyBytes_GET_SIZE(self);
+ i += PyString_GET_SIZE(self);
return string_item(self, i);
}
else if (PySlice_Check(item)) {
@@ -1226,27 +1226,27 @@ string_subscript(PyBytesObject* self, PyObject* item)
PyObject* result;
if (PySlice_GetIndicesEx((PySliceObject*)item,
- PyBytes_GET_SIZE(self),
+ PyString_GET_SIZE(self),
&start, &stop, &step, &slicelength) < 0) {
return NULL;
}
if (slicelength <= 0) {
- return PyBytes_FromStringAndSize("", 0);
+ return PyString_FromStringAndSize("", 0);
}
else if (start == 0 && step == 1 &&
- slicelength == PyBytes_GET_SIZE(self) &&
- PyBytes_CheckExact(self)) {
+ slicelength == PyString_GET_SIZE(self) &&
+ PyString_CheckExact(self)) {
Py_INCREF(self);
return (PyObject *)self;
}
else if (step == 1) {
- return PyBytes_FromStringAndSize(
- PyBytes_AS_STRING(self) + start,
+ return PyString_FromStringAndSize(
+ PyString_AS_STRING(self) + start,
slicelength);
}
else {
- source_buf = PyBytes_AsString((PyObject*)self);
+ source_buf = PyString_AsString((PyObject*)self);
result_buf = (char *)PyMem_Malloc(slicelength);
if (result_buf == NULL)
return PyErr_NoMemory();
@@ -1256,7 +1256,7 @@ string_subscript(PyBytesObject* self, PyObject* item)
result_buf[i] = source_buf[cur];
}
- result = PyBytes_FromStringAndSize(result_buf,
+ result = PyString_FromStringAndSize(result_buf,
slicelength);
PyMem_Free(result_buf);
return result;
@@ -1271,7 +1271,7 @@ string_subscript(PyBytesObject* self, PyObject* item)
}
static Py_ssize_t
-string_buffer_getreadbuf(PyBytesObject *self, Py_ssize_t index, const void **ptr)
+string_buffer_getreadbuf(PyStringObject *self, Py_ssize_t index, const void **ptr)
{
if ( index != 0 ) {
PyErr_SetString(PyExc_SystemError,
@@ -1283,7 +1283,7 @@ string_buffer_getreadbuf(PyBytesObject *self, Py_ssize_t index, const void **ptr
}
static Py_ssize_t
-string_buffer_getwritebuf(PyBytesObject *self, Py_ssize_t index, const void **ptr)
+string_buffer_getwritebuf(PyStringObject *self, Py_ssize_t index, const void **ptr)
{
PyErr_SetString(PyExc_TypeError,
"Cannot use string as modifiable buffer");
@@ -1291,7 +1291,7 @@ string_buffer_getwritebuf(PyBytesObject *self, Py_ssize_t index, const void **pt
}
static Py_ssize_t
-string_buffer_getsegcount(PyBytesObject *self, Py_ssize_t *lenp)
+string_buffer_getsegcount(PyStringObject *self, Py_ssize_t *lenp)
{
if ( lenp )
*lenp = Py_SIZE(self);
@@ -1299,7 +1299,7 @@ string_buffer_getsegcount(PyBytesObject *self, Py_ssize_t *lenp)
}
static Py_ssize_t
-string_buffer_getcharbuf(PyBytesObject *self, Py_ssize_t index, const char **ptr)
+string_buffer_getcharbuf(PyStringObject *self, Py_ssize_t index, const char **ptr)
{
if ( index != 0 ) {
PyErr_SetString(PyExc_SystemError,
@@ -1311,7 +1311,7 @@ string_buffer_getcharbuf(PyBytesObject *self, Py_ssize_t index, const char **ptr
}
static int
-string_buffer_getbuffer(PyBytesObject *self, Py_buffer *view, int flags)
+string_buffer_getbuffer(PyStringObject *self, Py_buffer *view, int flags)
{
return PyBuffer_FillInfo(view, (void *)self->ob_sval, Py_SIZE(self),
0, flags);
@@ -1376,7 +1376,7 @@ static const char *stripformat[] = {"|O:lstrip", "|O:rstrip", "|O:strip"};
(maxsplit >= MAX_PREALLOC ? MAX_PREALLOC : maxsplit+1)
#define SPLIT_APPEND(data, left, right) \
- str = PyBytes_FromStringAndSize((data) + (left), \
+ str = PyString_FromStringAndSize((data) + (left), \
(right) - (left)); \
if (str == NULL) \
goto onError; \
@@ -1388,7 +1388,7 @@ static const char *stripformat[] = {"|O:lstrip", "|O:rstrip", "|O:strip"};
Py_DECREF(str);
#define SPLIT_ADD(data, left, right) { \
- str = PyBytes_FromStringAndSize((data) + (left), \
+ str = PyString_FromStringAndSize((data) + (left), \
(right) - (left)); \
if (str == NULL) \
goto onError; \
@@ -1413,9 +1413,9 @@ static const char *stripformat[] = {"|O:lstrip", "|O:rstrip", "|O:strip"};
#define RSKIP_NONSPACE(s, i) { while (i>=0 && !isspace(Py_CHARMASK(s[i]))) i--; }
Py_LOCAL_INLINE(PyObject *)
-split_whitespace(PyBytesObject *self, Py_ssize_t len, Py_ssize_t maxsplit)
+split_whitespace(PyStringObject *self, Py_ssize_t len, Py_ssize_t maxsplit)
{
- const char *s = PyBytes_AS_STRING(self);
+ const char *s = PyString_AS_STRING(self);
Py_ssize_t i, j, count=0;
PyObject *str;
PyObject *list = PyList_New(PREALLOC_SIZE(maxsplit));
@@ -1430,7 +1430,7 @@ split_whitespace(PyBytesObject *self, Py_ssize_t len, Py_ssize_t maxsplit)
if (i==len) break;
j = i; i++;
SKIP_NONSPACE(s, i, len);
- if (j == 0 && i == len && PyBytes_CheckExact(self)) {
+ if (j == 0 && i == len && PyString_CheckExact(self)) {
/* No whitespace in self, so just use it as list[0] */
Py_INCREF(self);
PyList_SET_ITEM(list, 0, (PyObject *)self);
@@ -1455,9 +1455,9 @@ split_whitespace(PyBytesObject *self, Py_ssize_t len, Py_ssize_t maxsplit)
}
Py_LOCAL_INLINE(PyObject *)
-split_char(PyBytesObject *self, Py_ssize_t len, char ch, Py_ssize_t maxcount)
+split_char(PyStringObject *self, Py_ssize_t len, char ch, Py_ssize_t maxcount)
{
- const char *s = PyBytes_AS_STRING(self);
+ const char *s = PyString_AS_STRING(self);
register Py_ssize_t i, j, count=0;
PyObject *str;
PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
@@ -1476,7 +1476,7 @@ split_char(PyBytesObject *self, Py_ssize_t len, char ch, Py_ssize_t maxcount)
}
}
}
- if (i == 0 && count == 0 && PyBytes_CheckExact(self)) {
+ if (i == 0 && count == 0 && PyString_CheckExact(self)) {
/* ch not in self, so just use self as list[0] */
Py_INCREF(self);
PyList_SET_ITEM(list, 0, (PyObject *)self);
@@ -1503,11 +1503,11 @@ whitespace string is a separator and empty strings are removed\n\
from the result.");
static PyObject *
-string_split(PyBytesObject *self, PyObject *args)
+string_split(PyStringObject *self, PyObject *args)
{
- Py_ssize_t len = PyBytes_GET_SIZE(self), n, i, j;
+ Py_ssize_t len = PyString_GET_SIZE(self), n, i, j;
Py_ssize_t maxsplit = -1, count=0;
- const char *s = PyBytes_AS_STRING(self), *sub;
+ const char *s = PyString_AS_STRING(self), *sub;
PyObject *list, *str, *subobj = Py_None;
#ifdef USE_FAST
Py_ssize_t pos;
@@ -1519,9 +1519,9 @@ string_split(PyBytesObject *self, PyObject *args)
maxsplit = PY_SSIZE_T_MAX;
if (subobj == Py_None)
return split_whitespace(self, len, maxsplit);
- if (PyBytes_Check(subobj)) {
- sub = PyBytes_AS_STRING(subobj);
- n = PyBytes_GET_SIZE(subobj);
+ if (PyString_Check(subobj)) {
+ sub = PyString_AS_STRING(subobj);
+ n = PyString_GET_SIZE(subobj);
}
#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(subobj))
@@ -1580,14 +1580,14 @@ the separator itself, and the part after it. If the separator is not\n\
found, returns S and two empty strings.");
static PyObject *
-string_partition(PyBytesObject *self, PyObject *sep_obj)
+string_partition(PyStringObject *self, PyObject *sep_obj)
{
const char *sep;
Py_ssize_t sep_len;
- if (PyBytes_Check(sep_obj)) {
- sep = PyBytes_AS_STRING(sep_obj);
- sep_len = PyBytes_GET_SIZE(sep_obj);
+ if (PyString_Check(sep_obj)) {
+ sep = PyString_AS_STRING(sep_obj);
+ sep_len = PyString_GET_SIZE(sep_obj);
}
#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(sep_obj))
@@ -1598,7 +1598,7 @@ string_partition(PyBytesObject *self, PyObject *sep_obj)
return stringlib_partition(
(PyObject*) self,
- PyBytes_AS_STRING(self), PyBytes_GET_SIZE(self),
+ PyString_AS_STRING(self), PyString_GET_SIZE(self),
sep_obj, sep, sep_len
);
}
@@ -1611,14 +1611,14 @@ the part before it, the separator itself, and the part after it. If the\n\
separator is not found, returns two empty strings and S.");
static PyObject *
-string_rpartition(PyBytesObject *self, PyObject *sep_obj)
+string_rpartition(PyStringObject *self, PyObject *sep_obj)
{
const char *sep;
Py_ssize_t sep_len;
- if (PyBytes_Check(sep_obj)) {
- sep = PyBytes_AS_STRING(sep_obj);
- sep_len = PyBytes_GET_SIZE(sep_obj);
+ if (PyString_Check(sep_obj)) {
+ sep = PyString_AS_STRING(sep_obj);
+ sep_len = PyString_GET_SIZE(sep_obj);
}
#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(sep_obj))
@@ -1629,15 +1629,15 @@ string_rpartition(PyBytesObject *self, PyObject *sep_obj)
return stringlib_rpartition(
(PyObject*) self,
- PyBytes_AS_STRING(self), PyBytes_GET_SIZE(self),
+ PyString_AS_STRING(self), PyString_GET_SIZE(self),
sep_obj, sep, sep_len
);
}
Py_LOCAL_INLINE(PyObject *)
-rsplit_whitespace(PyBytesObject *self, Py_ssize_t len, Py_ssize_t maxsplit)
+rsplit_whitespace(PyStringObject *self, Py_ssize_t len, Py_ssize_t maxsplit)
{
- const char *s = PyBytes_AS_STRING(self);
+ const char *s = PyString_AS_STRING(self);
Py_ssize_t i, j, count=0;
PyObject *str;
PyObject *list = PyList_New(PREALLOC_SIZE(maxsplit));
@@ -1652,7 +1652,7 @@ rsplit_whitespace(PyBytesObject *self, Py_ssize_t len, Py_ssize_t maxsplit)
if (i<0) break;
j = i; i--;
RSKIP_NONSPACE(s, i);
- if (j == len-1 && i < 0 && PyBytes_CheckExact(self)) {
+ if (j == len-1 && i < 0 && PyString_CheckExact(self)) {
/* No whitespace in self, so just use it as list[0] */
Py_INCREF(self);
PyList_SET_ITEM(list, 0, (PyObject *)self);
@@ -1679,9 +1679,9 @@ rsplit_whitespace(PyBytesObject *self, Py_ssize_t len, Py_ssize_t maxsplit)
}
Py_LOCAL_INLINE(PyObject *)
-rsplit_char(PyBytesObject *self, Py_ssize_t len, char ch, Py_ssize_t maxcount)
+rsplit_char(PyStringObject *self, Py_ssize_t len, char ch, Py_ssize_t maxcount)
{
- const char *s = PyBytes_AS_STRING(self);
+ const char *s = PyString_AS_STRING(self);
register Py_ssize_t i, j, count=0;
PyObject *str;
PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
@@ -1699,7 +1699,7 @@ rsplit_char(PyBytesObject *self, Py_ssize_t len, char ch, Py_ssize_t maxcount)
}
}
}
- if (i < 0 && count == 0 && PyBytes_CheckExact(self)) {
+ if (i < 0 && count == 0 && PyString_CheckExact(self)) {
/* ch not in self, so just use self as list[0] */
Py_INCREF(self);
PyList_SET_ITEM(list, 0, (PyObject *)self);
@@ -1728,9 +1728,9 @@ done. If sep is not specified or is None, any whitespace string\n\
is a separator.");
static PyObject *
-string_rsplit(PyBytesObject *self, PyObject *args)
+string_rsplit(PyStringObject *self, PyObject *args)
{
- Py_ssize_t len = PyBytes_GET_SIZE(self), n, i, j;
+ Py_ssize_t len = PyString_GET_SIZE(self), n, i, j;
Py_ssize_t maxsplit = -1, count=0;
const char *s, *sub;
PyObject *list, *str, *subobj = Py_None;
@@ -1741,9 +1741,9 @@ string_rsplit(PyBytesObject *self, PyObject *args)
maxsplit = PY_SSIZE_T_MAX;
if (subobj == Py_None)
return rsplit_whitespace(self, len, maxsplit);
- if (PyBytes_Check(subobj)) {
- sub = PyBytes_AS_STRING(subobj);
- n = PyBytes_GET_SIZE(subobj);
+ if (PyString_Check(subobj)) {
+ sub = PyString_AS_STRING(subobj);
+ n = PyString_GET_SIZE(subobj);
}
#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(subobj))
@@ -1766,7 +1766,7 @@ string_rsplit(PyBytesObject *self, PyObject *args)
j = len;
i = j - n;
- s = PyBytes_AS_STRING(self);
+ s = PyString_AS_STRING(self);
while ( (i >= 0) && (maxsplit-- > 0) ) {
for (; i>=0; i--) {
if (Py_STRING_MATCH(s, i, sub, n)) {
@@ -1796,10 +1796,10 @@ Return a string which is the concatenation of the strings in the\n\
sequence. The separator between elements is S.");
static PyObject *
-string_join(PyBytesObject *self, PyObject *orig)
+string_join(PyStringObject *self, PyObject *orig)
{
- char *sep = PyBytes_AS_STRING(self);
- const Py_ssize_t seplen = PyBytes_GET_SIZE(self);
+ char *sep = PyString_AS_STRING(self);
+ const Py_ssize_t seplen = PyString_GET_SIZE(self);
PyObject *res = NULL;
char *p;
Py_ssize_t seqlen = 0;
@@ -1815,11 +1815,11 @@ string_join(PyBytesObject *self, PyObject *orig)
seqlen = PySequence_Size(seq);
if (seqlen == 0) {
Py_DECREF(seq);
- return PyBytes_FromString("");
+ return PyString_FromString("");
}
if (seqlen == 1) {
item = PySequence_Fast_GET_ITEM(seq, 0);
- if (PyBytes_CheckExact(item) || PyUnicode_CheckExact(item)) {
+ if (PyString_CheckExact(item) || PyUnicode_CheckExact(item)) {
Py_INCREF(item);
Py_DECREF(seq);
return item;
@@ -1835,7 +1835,7 @@ string_join(PyBytesObject *self, PyObject *orig)
for (i = 0; i < seqlen; i++) {
const size_t old_sz = sz;
item = PySequence_Fast_GET_ITEM(seq, i);
- if (!PyBytes_Check(item)){
+ if (!PyString_Check(item)){
#ifdef Py_USING_UNICODE
if (PyUnicode_Check(item)) {
/* Defer to Unicode join.
@@ -1856,7 +1856,7 @@ string_join(PyBytesObject *self, PyObject *orig)
Py_DECREF(seq);
return NULL;
}
- sz += PyBytes_GET_SIZE(item);
+ sz += PyString_GET_SIZE(item);
if (i != 0)
sz += seplen;
if (sz < old_sz || sz > PY_SSIZE_T_MAX) {
@@ -1868,19 +1868,19 @@ string_join(PyBytesObject *self, PyObject *orig)
}
/* Allocate result space. */
- res = PyBytes_FromStringAndSize((char*)NULL, sz);
+ res = PyString_FromStringAndSize((char*)NULL, sz);
if (res == NULL) {
Py_DECREF(seq);
return NULL;
}
/* Catenate everything. */
- p = PyBytes_AS_STRING(res);
+ p = PyString_AS_STRING(res);
for (i = 0; i < seqlen; ++i) {
size_t n;
item = PySequence_Fast_GET_ITEM(seq, i);
- n = PyBytes_GET_SIZE(item);
- Py_MEMCPY(p, PyBytes_AS_STRING(item), n);
+ n = PyString_GET_SIZE(item);
+ Py_MEMCPY(p, PyString_AS_STRING(item), n);
p += n;
if (i < seqlen - 1) {
Py_MEMCPY(p, sep, seplen);
@@ -1893,11 +1893,11 @@ string_join(PyBytesObject *self, PyObject *orig)
}
PyObject *
-_PyBytes_Join(PyObject *sep, PyObject *x)
+_PyString_Join(PyObject *sep, PyObject *x)
{
- assert(sep != NULL && PyBytes_Check(sep));
+ assert(sep != NULL && PyString_Check(sep));
assert(x != NULL);
- return string_join((PyBytesObject *)sep, x);
+ return string_join((PyStringObject *)sep, x);
}
Py_LOCAL_INLINE(void)
@@ -1916,7 +1916,7 @@ string_adjust_indices(Py_ssize_t *start, Py_ssize_t *end, Py_ssize_t len)
}
Py_LOCAL_INLINE(Py_ssize_t)
-string_find_internal(PyBytesObject *self, PyObject *args, int dir)
+string_find_internal(PyStringObject *self, PyObject *args, int dir)
{
PyObject *subobj;
const char *sub;
@@ -1937,9 +1937,9 @@ string_find_internal(PyBytesObject *self, PyObject *args, int dir)
if (!_PyEval_SliceIndex(obj_end, &end))
return -2;
- if (PyBytes_Check(subobj)) {
- sub = PyBytes_AS_STRING(subobj);
- sub_len = PyBytes_GET_SIZE(subobj);
+ if (PyString_Check(subobj)) {
+ sub = PyString_AS_STRING(subobj);
+ sub_len = PyString_GET_SIZE(subobj);
}
#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(subobj))
@@ -1953,11 +1953,11 @@ string_find_internal(PyBytesObject *self, PyObject *args, int dir)
if (dir > 0)
return stringlib_find_slice(
- PyBytes_AS_STRING(self), PyBytes_GET_SIZE(self),
+ PyString_AS_STRING(self), PyString_GET_SIZE(self),
sub, sub_len, start, end);
else
return stringlib_rfind_slice(
- PyBytes_AS_STRING(self), PyBytes_GET_SIZE(self),
+ PyString_AS_STRING(self), PyString_GET_SIZE(self),
sub, sub_len, start, end);
}
@@ -1972,7 +1972,7 @@ arguments start and end are interpreted as in slice notation.\n\
Return -1 on failure.");
static PyObject *
-string_find(PyBytesObject *self, PyObject *args)
+string_find(PyStringObject *self, PyObject *args)
{
Py_ssize_t result = string_find_internal(self, args, +1);
if (result == -2)
@@ -1987,7 +1987,7 @@ PyDoc_STRVAR(index__doc__,
Like S.find() but raise ValueError when the substring is not found.");
static PyObject *
-string_index(PyBytesObject *self, PyObject *args)
+string_index(PyStringObject *self, PyObject *args)
{
Py_ssize_t result = string_find_internal(self, args, +1);
if (result == -2)
@@ -2011,7 +2011,7 @@ arguments start and end are interpreted as in slice notation.\n\
Return -1 on failure.");
static PyObject *
-string_rfind(PyBytesObject *self, PyObject *args)
+string_rfind(PyStringObject *self, PyObject *args)
{
Py_ssize_t result = string_find_internal(self, args, -1);
if (result == -2)
@@ -2026,7 +2026,7 @@ PyDoc_STRVAR(rindex__doc__,
Like S.rfind() but raise ValueError when the substring is not found.");
static PyObject *
-string_rindex(PyBytesObject *self, PyObject *args)
+string_rindex(PyStringObject *self, PyObject *args)
{
Py_ssize_t result = string_find_internal(self, args, -1);
if (result == -2)
@@ -2041,12 +2041,12 @@ string_rindex(PyBytesObject *self, PyObject *args)
Py_LOCAL_INLINE(PyObject *)
-do_xstrip(PyBytesObject *self, int striptype, PyObject *sepobj)
+do_xstrip(PyStringObject *self, int striptype, PyObject *sepobj)
{
- char *s = PyBytes_AS_STRING(self);
- Py_ssize_t len = PyBytes_GET_SIZE(self);
- char *sep = PyBytes_AS_STRING(sepobj);
- Py_ssize_t seplen = PyBytes_GET_SIZE(sepobj);
+ char *s = PyString_AS_STRING(self);
+ Py_ssize_t len = PyString_GET_SIZE(self);
+ char *sep = PyString_AS_STRING(sepobj);
+ Py_ssize_t seplen = PyString_GET_SIZE(sepobj);
Py_ssize_t i, j;
i = 0;
@@ -2064,20 +2064,20 @@ do_xstrip(PyBytesObject *self, int striptype, PyObject *sepobj)
j++;
}
- if (i == 0 && j == len && PyBytes_CheckExact(self)) {
+ if (i == 0 && j == len && PyString_CheckExact(self)) {
Py_INCREF(self);
return (PyObject*)self;
}
else
- return PyBytes_FromStringAndSize(s+i, j-i);
+ return PyString_FromStringAndSize(s+i, j-i);
}
Py_LOCAL_INLINE(PyObject *)
-do_strip(PyBytesObject *self, int striptype)
+do_strip(PyStringObject *self, int striptype)
{
- char *s = PyBytes_AS_STRING(self);
- Py_ssize_t len = PyBytes_GET_SIZE(self), i, j;
+ char *s = PyString_AS_STRING(self);
+ Py_ssize_t len = PyString_GET_SIZE(self), i, j;
i = 0;
if (striptype != RIGHTSTRIP) {
@@ -2094,17 +2094,17 @@ do_strip(PyBytesObject *self, int striptype)
j++;
}
- if (i == 0 && j == len && PyBytes_CheckExact(self)) {
+ if (i == 0 && j == len && PyString_CheckExact(self)) {
Py_INCREF(self);
return (PyObject*)self;
}
else
- return PyBytes_FromStringAndSize(s+i, j-i);
+ return PyString_FromStringAndSize(s+i, j-i);
}
Py_LOCAL_INLINE(PyObject *)
-do_argstrip(PyBytesObject *self, int striptype, PyObject *args)
+do_argstrip(PyStringObject *self, int striptype, PyObject *args)
{
PyObject *sep = NULL;
@@ -2112,7 +2112,7 @@ do_argstrip(PyBytesObject *self, int striptype, PyObject *args)
return NULL;
if (sep != NULL && sep != Py_None) {
- if (PyBytes_Check(sep))
+ if (PyString_Check(sep))
return do_xstrip(self, striptype, sep);
#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(sep)) {
@@ -2149,7 +2149,7 @@ If chars is given and not None, remove characters in chars instead.\n\
If chars is unicode, S will be converted to unicode before stripping");
static PyObject *
-string_strip(PyBytesObject *self, PyObject *args)
+string_strip(PyStringObject *self, PyObject *args)
{
if (PyTuple_GET_SIZE(args) == 0)
return do_strip(self, BOTHSTRIP); /* Common case */
@@ -2166,7 +2166,7 @@ If chars is given and not None, remove characters in chars instead.\n\
If chars is unicode, S will be converted to unicode before stripping");
static PyObject *
-string_lstrip(PyBytesObject *self, PyObject *args)
+string_lstrip(PyStringObject *self, PyObject *args)
{
if (PyTuple_GET_SIZE(args) == 0)
return do_strip(self, LEFTSTRIP); /* Common case */
@@ -2183,7 +2183,7 @@ If chars is given and not None, remove characters in chars instead.\n\
If chars is unicode, S will be converted to unicode before stripping");
static PyObject *
-string_rstrip(PyBytesObject *self, PyObject *args)
+string_rstrip(PyStringObject *self, PyObject *args)
{
if (PyTuple_GET_SIZE(args) == 0)
return do_strip(self, RIGHTSTRIP); /* Common case */
@@ -2203,19 +2203,19 @@ Return a copy of the string S converted to lowercase.");
#endif
static PyObject *
-string_lower(PyBytesObject *self)
+string_lower(PyStringObject *self)
{
char *s;
- Py_ssize_t i, n = PyBytes_GET_SIZE(self);
+ Py_ssize_t i, n = PyString_GET_SIZE(self);
PyObject *newobj;
- newobj = PyBytes_FromStringAndSize(NULL, n);
+ newobj = PyString_FromStringAndSize(NULL, n);
if (!newobj)
return NULL;
- s = PyBytes_AS_STRING(newobj);
+ s = PyString_AS_STRING(newobj);
- Py_MEMCPY(s, PyBytes_AS_STRING(self), n);
+ Py_MEMCPY(s, PyString_AS_STRING(self), n);
for (i = 0; i < n; i++) {
int c = Py_CHARMASK(s[i]);
@@ -2236,19 +2236,19 @@ Return a copy of the string S converted to uppercase.");
#endif
static PyObject *
-string_upper(PyBytesObject *self)
+string_upper(PyStringObject *self)
{
char *s;
- Py_ssize_t i, n = PyBytes_GET_SIZE(self);
+ Py_ssize_t i, n = PyString_GET_SIZE(self);
PyObject *newobj;
- newobj = PyBytes_FromStringAndSize(NULL, n);
+ newobj = PyString_FromStringAndSize(NULL, n);
if (!newobj)
return NULL;
- s = PyBytes_AS_STRING(newobj);
+ s = PyString_AS_STRING(newobj);
- Py_MEMCPY(s, PyBytes_AS_STRING(self), n);
+ Py_MEMCPY(s, PyString_AS_STRING(self), n);
for (i = 0; i < n; i++) {
int c = Py_CHARMASK(s[i]);
@@ -2266,17 +2266,17 @@ Return a titlecased version of S, i.e. words start with uppercase\n\
characters, all remaining cased characters have lowercase.");
static PyObject*
-string_title(PyBytesObject *self)
+string_title(PyStringObject *self)
{
- char *s = PyBytes_AS_STRING(self), *s_new;
- Py_ssize_t i, n = PyBytes_GET_SIZE(self);
+ char *s = PyString_AS_STRING(self), *s_new;
+ Py_ssize_t i, n = PyString_GET_SIZE(self);
int previous_is_cased = 0;
PyObject *newobj;
- newobj = PyBytes_FromStringAndSize(NULL, n);
+ newobj = PyString_FromStringAndSize(NULL, n);
if (newobj == NULL)
return NULL;
- s_new = PyBytes_AsString(newobj);
+ s_new = PyString_AsString(newobj);
for (i = 0; i < n; i++) {
int c = Py_CHARMASK(*s++);
if (islower(c)) {
@@ -2301,16 +2301,16 @@ Return a copy of the string S with only its first character\n\
capitalized.");
static PyObject *
-string_capitalize(PyBytesObject *self)
+string_capitalize(PyStringObject *self)
{
- char *s = PyBytes_AS_STRING(self), *s_new;
- Py_ssize_t i, n = PyBytes_GET_SIZE(self);
+ char *s = PyString_AS_STRING(self), *s_new;
+ Py_ssize_t i, n = PyString_GET_SIZE(self);
PyObject *newobj;
- newobj = PyBytes_FromStringAndSize(NULL, n);
+ newobj = PyString_FromStringAndSize(NULL, n);
if (newobj == NULL)
return NULL;
- s_new = PyBytes_AsString(newobj);
+ s_new = PyString_AsString(newobj);
if (0 < n) {
int c = Py_CHARMASK(*s++);
if (islower(c))
@@ -2339,10 +2339,10 @@ string S[start:end]. Optional arguments start and end are interpreted\n\
as in slice notation.");
static PyObject *
-string_count(PyBytesObject *self, PyObject *args)
+string_count(PyStringObject *self, PyObject *args)
{
PyObject *sub_obj;
- const char *str = PyBytes_AS_STRING(self), *sub;
+ const char *str = PyString_AS_STRING(self), *sub;
Py_ssize_t sub_len;
Py_ssize_t start = 0, end = PY_SSIZE_T_MAX;
@@ -2350,9 +2350,9 @@ string_count(PyBytesObject *self, PyObject *args)
_PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end))
return NULL;
- if (PyBytes_Check(sub_obj)) {
- sub = PyBytes_AS_STRING(sub_obj);
- sub_len = PyBytes_GET_SIZE(sub_obj);
+ if (PyString_Check(sub_obj)) {
+ sub = PyString_AS_STRING(sub_obj);
+ sub_len = PyString_GET_SIZE(sub_obj);
}
#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(sub_obj)) {
@@ -2367,7 +2367,7 @@ string_count(PyBytesObject *self, PyObject *args)
else if (PyObject_AsCharBuffer(sub_obj, &sub, &sub_len))
return NULL;
- string_adjust_indices(&start, &end, PyBytes_GET_SIZE(self));
+ string_adjust_indices(&start, &end, PyString_GET_SIZE(self));
return PyInt_FromSsize_t(
stringlib_count(str + start, end - start, sub, sub_len)
@@ -2381,16 +2381,16 @@ Return a copy of the string S with uppercase characters\n\
converted to lowercase and vice versa.");
static PyObject *
-string_swapcase(PyBytesObject *self)
+string_swapcase(PyStringObject *self)
{
- char *s = PyBytes_AS_STRING(self), *s_new;
- Py_ssize_t i, n = PyBytes_GET_SIZE(self);
+ char *s = PyString_AS_STRING(self), *s_new;
+ Py_ssize_t i, n = PyString_GET_SIZE(self);
PyObject *newobj;
- newobj = PyBytes_FromStringAndSize(NULL, n);
+ newobj = PyString_FromStringAndSize(NULL, n);
if (newobj == NULL)
return NULL;
- s_new = PyBytes_AsString(newobj);
+ s_new = PyString_AsString(newobj);
for (i = 0; i < n; i++) {
int c = Py_CHARMASK(*s++);
if (islower(c)) {
@@ -2416,7 +2416,7 @@ remaining characters have been mapped through the given\n\
translation table, which must be a string of length 256.");
static PyObject *
-string_translate(PyBytesObject *self, PyObject *args)
+string_translate(PyStringObject *self, PyObject *args)
{
register char *input, *output;
const char *table;
@@ -2432,9 +2432,9 @@ string_translate(PyBytesObject *self, PyObject *args)
&tableobj, &delobj))
return NULL;
- if (PyBytes_Check(tableobj)) {
- table = PyBytes_AS_STRING(tableobj);
- tablen = PyBytes_GET_SIZE(tableobj);
+ if (PyString_Check(tableobj)) {
+ table = PyString_AS_STRING(tableobj);
+ tablen = PyString_GET_SIZE(tableobj);
}
else if (tableobj == Py_None) {
table = NULL;
@@ -2463,9 +2463,9 @@ string_translate(PyBytesObject *self, PyObject *args)
}
if (delobj != NULL) {
- if (PyBytes_Check(delobj)) {
- del_table = PyBytes_AS_STRING(delobj);
- dellen = PyBytes_GET_SIZE(delobj);
+ if (PyString_Check(delobj)) {
+ del_table = PyString_AS_STRING(delobj);
+ dellen = PyString_GET_SIZE(delobj);
}
#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(delobj)) {
@@ -2482,12 +2482,12 @@ string_translate(PyBytesObject *self, PyObject *args)
dellen = 0;
}
- inlen = PyBytes_GET_SIZE(input_obj);
- result = PyBytes_FromStringAndSize((char *)NULL, inlen);
+ inlen = PyString_GET_SIZE(input_obj);
+ result = PyString_FromStringAndSize((char *)NULL, inlen);
if (result == NULL)
return NULL;
- output_start = output = PyBytes_AsString(result);
- input = PyBytes_AS_STRING(input_obj);
+ output_start = output = PyString_AsString(result);
+ input = PyString_AS_STRING(input_obj);
if (dellen == 0 && table != NULL) {
/* If no deletions are required, use faster code */
@@ -2496,7 +2496,7 @@ string_translate(PyBytesObject *self, PyObject *args)
if (Py_CHARMASK((*output++ = table[c])) != c)
changed = 1;
}
- if (changed || !PyBytes_CheckExact(input_obj))
+ if (changed || !PyString_CheckExact(input_obj))
return result;
Py_DECREF(result);
Py_INCREF(input_obj);
@@ -2521,14 +2521,14 @@ string_translate(PyBytesObject *self, PyObject *args)
continue;
changed = 1;
}
- if (!changed && PyBytes_CheckExact(input_obj)) {
+ if (!changed && PyString_CheckExact(input_obj)) {
Py_DECREF(result);
Py_INCREF(input_obj);
return input_obj;
}
/* Fix the size of the resulting string */
if (inlen > 0)
- _PyBytes_Resize(&result, output - output_start);
+ _PyString_Resize(&result, output - output_start);
return result;
}
@@ -2543,16 +2543,16 @@ string_translate(PyBytesObject *self, PyObject *args)
/* String ops must return a string. */
/* If the object is subclass of string, create a copy */
-Py_LOCAL(PyBytesObject *)
-return_self(PyBytesObject *self)
+Py_LOCAL(PyStringObject *)
+return_self(PyStringObject *self)
{
- if (PyBytes_CheckExact(self)) {
+ if (PyString_CheckExact(self)) {
Py_INCREF(self);
return self;
}
- return (PyBytesObject *)PyBytes_FromStringAndSize(
- PyBytes_AS_STRING(self),
- PyBytes_GET_SIZE(self));
+ return (PyStringObject *)PyString_FromStringAndSize(
+ PyString_AS_STRING(self),
+ PyString_GET_SIZE(self));
}
Py_LOCAL_INLINE(Py_ssize_t)
@@ -2662,17 +2662,17 @@ countstring(const char *target, Py_ssize_t target_len,
/* Algorithms for different cases of string replacement */
/* len(self)>=1, from="", len(to)>=1, maxcount>=1 */
-Py_LOCAL(PyBytesObject *)
-replace_interleave(PyBytesObject *self,
+Py_LOCAL(PyStringObject *)
+replace_interleave(PyStringObject *self,
const char *to_s, Py_ssize_t to_len,
Py_ssize_t maxcount)
{
char *self_s, *result_s;
Py_ssize_t self_len, result_len;
Py_ssize_t count, i, product;
- PyBytesObject *result;
+ PyStringObject *result;
- self_len = PyBytes_GET_SIZE(self);
+ self_len = PyString_GET_SIZE(self);
/* 1 at the end plus 1 after every character */
count = self_len+1;
@@ -2694,12 +2694,12 @@ replace_interleave(PyBytesObject *self,
return NULL;
}
- if (! (result = (PyBytesObject *)
- PyBytes_FromStringAndSize(NULL, result_len)) )
+ if (! (result = (PyStringObject *)
+ PyString_FromStringAndSize(NULL, result_len)) )
return NULL;
- self_s = PyBytes_AS_STRING(self);
- result_s = PyBytes_AS_STRING(result);
+ self_s = PyString_AS_STRING(self);
+ result_s = PyString_AS_STRING(result);
/* TODO: special case single character, which doesn't need memcpy */
@@ -2722,18 +2722,18 @@ replace_interleave(PyBytesObject *self,
/* Special case for deleting a single character */
/* len(self)>=1, len(from)==1, to="", maxcount>=1 */
-Py_LOCAL(PyBytesObject *)
-replace_delete_single_character(PyBytesObject *self,
+Py_LOCAL(PyStringObject *)
+replace_delete_single_character(PyStringObject *self,
char from_c, Py_ssize_t maxcount)
{
char *self_s, *result_s;
char *start, *next, *end;
Py_ssize_t self_len, result_len;
Py_ssize_t count;
- PyBytesObject *result;
+ PyStringObject *result;
- self_len = PyBytes_GET_SIZE(self);
- self_s = PyBytes_AS_STRING(self);
+ self_len = PyString_GET_SIZE(self);
+ self_s = PyString_AS_STRING(self);
count = countchar(self_s, self_len, from_c, maxcount);
if (count == 0) {
@@ -2743,10 +2743,10 @@ replace_delete_single_character(PyBytesObject *self,
result_len = self_len - count; /* from_len == 1 */
assert(result_len>=0);
- if ( (result = (PyBytesObject *)
- PyBytes_FromStringAndSize(NULL, result_len)) == NULL)
+ if ( (result = (PyStringObject *)
+ PyString_FromStringAndSize(NULL, result_len)) == NULL)
return NULL;
- result_s = PyBytes_AS_STRING(result);
+ result_s = PyString_AS_STRING(result);
start = self_s;
end = self_s + self_len;
@@ -2765,18 +2765,18 @@ replace_delete_single_character(PyBytesObject *self,
/* len(self)>=1, len(from)>=2, to="", maxcount>=1 */
-Py_LOCAL(PyBytesObject *)
-replace_delete_substring(PyBytesObject *self,
+Py_LOCAL(PyStringObject *)
+replace_delete_substring(PyStringObject *self,
const char *from_s, Py_ssize_t from_len,
Py_ssize_t maxcount) {
char *self_s, *result_s;
char *start, *next, *end;
Py_ssize_t self_len, result_len;
Py_ssize_t count, offset;
- PyBytesObject *result;
+ PyStringObject *result;
- self_len = PyBytes_GET_SIZE(self);
- self_s = PyBytes_AS_STRING(self);
+ self_len = PyString_GET_SIZE(self);
+ self_s = PyString_AS_STRING(self);
count = countstring(self_s, self_len,
from_s, from_len,
@@ -2791,11 +2791,11 @@ replace_delete_substring(PyBytesObject *self,
result_len = self_len - (count * from_len);
assert (result_len>=0);
- if ( (result = (PyBytesObject *)
- PyBytes_FromStringAndSize(NULL, result_len)) == NULL )
+ if ( (result = (PyStringObject *)
+ PyString_FromStringAndSize(NULL, result_len)) == NULL )
return NULL;
- result_s = PyBytes_AS_STRING(result);
+ result_s = PyString_AS_STRING(result);
start = self_s;
end = self_s + self_len;
@@ -2817,18 +2817,18 @@ replace_delete_substring(PyBytesObject *self,
}
/* len(self)>=1, len(from)==len(to)==1, maxcount>=1 */
-Py_LOCAL(PyBytesObject *)
-replace_single_character_in_place(PyBytesObject *self,
+Py_LOCAL(PyStringObject *)
+replace_single_character_in_place(PyStringObject *self,
char from_c, char to_c,
Py_ssize_t maxcount)
{
char *self_s, *result_s, *start, *end, *next;
Py_ssize_t self_len;
- PyBytesObject *result;
+ PyStringObject *result;
/* The result string will be the same size */
- self_s = PyBytes_AS_STRING(self);
- self_len = PyBytes_GET_SIZE(self);
+ self_s = PyString_AS_STRING(self);
+ self_len = PyString_GET_SIZE(self);
next = findchar(self_s, self_len, from_c);
@@ -2838,10 +2838,10 @@ replace_single_character_in_place(PyBytesObject *self,
}
/* Need to make a new string */
- result = (PyBytesObject *) PyBytes_FromStringAndSize(NULL, self_len);
+ result = (PyStringObject *) PyString_FromStringAndSize(NULL, self_len);
if (result == NULL)
return NULL;
- result_s = PyBytes_AS_STRING(result);
+ result_s = PyString_AS_STRING(result);
Py_MEMCPY(result_s, self_s, self_len);
/* change everything in-place, starting with this one */
@@ -2862,8 +2862,8 @@ replace_single_character_in_place(PyBytesObject *self,
}
/* len(self)>=1, len(from)==len(to)>=2, maxcount>=1 */
-Py_LOCAL(PyBytesObject *)
-replace_substring_in_place(PyBytesObject *self,
+Py_LOCAL(PyStringObject *)
+replace_substring_in_place(PyStringObject *self,
const char *from_s, Py_ssize_t from_len,
const char *to_s, Py_ssize_t to_len,
Py_ssize_t maxcount)
@@ -2871,12 +2871,12 @@ replace_substring_in_place(PyBytesObject *self,
char *result_s, *start, *end;
char *self_s;
Py_ssize_t self_len, offset;
- PyBytesObject *result;
+ PyStringObject *result;
/* The result string will be the same size */
- self_s = PyBytes_AS_STRING(self);
- self_len = PyBytes_GET_SIZE(self);
+ self_s = PyString_AS_STRING(self);
+ self_len = PyString_GET_SIZE(self);
offset = findstring(self_s, self_len,
from_s, from_len,
@@ -2887,10 +2887,10 @@ replace_substring_in_place(PyBytesObject *self,
}
/* Need to make a new string */
- result = (PyBytesObject *) PyBytes_FromStringAndSize(NULL, self_len);
+ result = (PyStringObject *) PyString_FromStringAndSize(NULL, self_len);
if (result == NULL)
return NULL;
- result_s = PyBytes_AS_STRING(result);
+ result_s = PyString_AS_STRING(result);
Py_MEMCPY(result_s, self_s, self_len);
/* change everything in-place, starting with this one */
@@ -2913,8 +2913,8 @@ replace_substring_in_place(PyBytesObject *self,
}
/* len(self)>=1, len(from)==1, len(to)>=2, maxcount>=1 */
-Py_LOCAL(PyBytesObject *)
-replace_single_character(PyBytesObject *self,
+Py_LOCAL(PyStringObject *)
+replace_single_character(PyStringObject *self,
char from_c,
const char *to_s, Py_ssize_t to_len,
Py_ssize_t maxcount)
@@ -2923,10 +2923,10 @@ replace_single_character(PyBytesObject *self,
char *start, *next, *end;
Py_ssize_t self_len, result_len;
Py_ssize_t count, product;
- PyBytesObject *result;
+ PyStringObject *result;
- self_s = PyBytes_AS_STRING(self);
- self_len = PyBytes_GET_SIZE(self);
+ self_s = PyString_AS_STRING(self);
+ self_len = PyString_GET_SIZE(self);
count = countchar(self_s, self_len, from_c, maxcount);
if (count == 0) {
@@ -2947,10 +2947,10 @@ replace_single_character(PyBytesObject *self,
return NULL;
}
- if ( (result = (PyBytesObject *)
- PyBytes_FromStringAndSize(NULL, result_len)) == NULL)
+ if ( (result = (PyStringObject *)
+ PyString_FromStringAndSize(NULL, result_len)) == NULL)
return NULL;
- result_s = PyBytes_AS_STRING(result);
+ result_s = PyString_AS_STRING(result);
start = self_s;
end = self_s + self_len;
@@ -2980,8 +2980,8 @@ replace_single_character(PyBytesObject *self,
}
/* len(self)>=1, len(from)>=2, len(to)>=2, maxcount>=1 */
-Py_LOCAL(PyBytesObject *)
-replace_substring(PyBytesObject *self,
+Py_LOCAL(PyStringObject *)
+replace_substring(PyStringObject *self,
const char *from_s, Py_ssize_t from_len,
const char *to_s, Py_ssize_t to_len,
Py_ssize_t maxcount) {
@@ -2989,10 +2989,10 @@ replace_substring(PyBytesObject *self,
char *start, *next, *end;
Py_ssize_t self_len, result_len;
Py_ssize_t count, offset, product;
- PyBytesObject *result;
+ PyStringObject *result;
- self_s = PyBytes_AS_STRING(self);
- self_len = PyBytes_GET_SIZE(self);
+ self_s = PyString_AS_STRING(self);
+ self_len = PyString_GET_SIZE(self);
count = countstring(self_s, self_len,
from_s, from_len,
@@ -3015,10 +3015,10 @@ replace_substring(PyBytesObject *self,
return NULL;
}
- if ( (result = (PyBytesObject *)
- PyBytes_FromStringAndSize(NULL, result_len)) == NULL)
+ if ( (result = (PyStringObject *)
+ PyString_FromStringAndSize(NULL, result_len)) == NULL)
return NULL;
- result_s = PyBytes_AS_STRING(result);
+ result_s = PyString_AS_STRING(result);
start = self_s;
end = self_s + self_len;
@@ -3050,15 +3050,15 @@ replace_substring(PyBytesObject *self,
}
-Py_LOCAL(PyBytesObject *)
-replace(PyBytesObject *self,
+Py_LOCAL(PyStringObject *)
+replace(PyStringObject *self,
const char *from_s, Py_ssize_t from_len,
const char *to_s, Py_ssize_t to_len,
Py_ssize_t maxcount)
{
if (maxcount < 0) {
maxcount = PY_SSIZE_T_MAX;
- } else if (maxcount == 0 || PyBytes_GET_SIZE(self) == 0) {
+ } else if (maxcount == 0 || PyString_GET_SIZE(self) == 0) {
/* nothing to do; return the original string */
return return_self(self);
}
@@ -3081,7 +3081,7 @@ replace(PyBytesObject *self,
/* Except for "".replace("", "A") == "A" there is no way beyond this */
/* point for an empty self string to generate a non-empty string */
/* Special case so the remaining code always gets a non-empty string */
- if (PyBytes_GET_SIZE(self) == 0) {
+ if (PyString_GET_SIZE(self) == 0) {
return return_self(self);
}
@@ -3128,7 +3128,7 @@ old replaced by new. If the optional argument count is\n\
given, only the first count occurrences are replaced.");
static PyObject *
-string_replace(PyBytesObject *self, PyObject *args)
+string_replace(PyStringObject *self, PyObject *args)
{
Py_ssize_t count = -1;
PyObject *from, *to;
@@ -3138,9 +3138,9 @@ string_replace(PyBytesObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "OO|n:replace", &from, &to, &count))
return NULL;
- if (PyBytes_Check(from)) {
- from_s = PyBytes_AS_STRING(from);
- from_len = PyBytes_GET_SIZE(from);
+ if (PyString_Check(from)) {
+ from_s = PyString_AS_STRING(from);
+ from_len = PyString_GET_SIZE(from);
}
#ifdef Py_USING_UNICODE
if (PyUnicode_Check(from))
@@ -3150,9 +3150,9 @@ string_replace(PyBytesObject *self, PyObject *args)
else if (PyObject_AsCharBuffer(from, &from_s, &from_len))
return NULL;
- if (PyBytes_Check(to)) {
- to_s = PyBytes_AS_STRING(to);
- to_len = PyBytes_GET_SIZE(to);
+ if (PyString_Check(to)) {
+ to_s = PyString_AS_STRING(to);
+ to_len = PyString_GET_SIZE(to);
}
#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(to))
@@ -3162,7 +3162,7 @@ string_replace(PyBytesObject *self, PyObject *args)
else if (PyObject_AsCharBuffer(to, &to_s, &to_len))
return NULL;
- return (PyObject *)replace((PyBytesObject *) self,
+ return (PyObject *)replace((PyStringObject *) self,
from_s, from_len,
to_s, to_len, count);
}
@@ -3174,17 +3174,17 @@ string_replace(PyBytesObject *self, PyObject *args)
* -1 on error, 0 if not found and 1 if found.
*/
Py_LOCAL(int)
-_string_tailmatch(PyBytesObject *self, PyObject *substr, Py_ssize_t start,
+_string_tailmatch(PyStringObject *self, PyObject *substr, Py_ssize_t start,
Py_ssize_t end, int direction)
{
- Py_ssize_t len = PyBytes_GET_SIZE(self);
+ Py_ssize_t len = PyString_GET_SIZE(self);
Py_ssize_t slen;
const char* sub;
const char* str;
- if (PyBytes_Check(substr)) {
- sub = PyBytes_AS_STRING(substr);
- slen = PyBytes_GET_SIZE(substr);
+ if (PyString_Check(substr)) {
+ sub = PyString_AS_STRING(substr);
+ slen = PyString_GET_SIZE(substr);
}
#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(substr))
@@ -3193,7 +3193,7 @@ _string_tailmatch(PyBytesObject *self, PyObject *substr, Py_ssize_t start,
#endif
else if (PyObject_AsCharBuffer(substr, &sub, &slen))
return -1;
- str = PyBytes_AS_STRING(self);
+ str = PyString_AS_STRING(self);
string_adjust_indices(&start, &end, len);
@@ -3224,7 +3224,7 @@ With optional end, stop comparing S at that position.\n\
prefix can also be a tuple of strings to try.");
static PyObject *
-string_startswith(PyBytesObject *self, PyObject *args)
+string_startswith(PyStringObject *self, PyObject *args)
{
Py_ssize_t start = 0;
Py_ssize_t end = PY_SSIZE_T_MAX;
@@ -3265,7 +3265,7 @@ With optional end, stop comparing S at that position.\n\
suffix can also be a tuple of strings to try.");
static PyObject *
-string_endswith(PyBytesObject *self, PyObject *args)
+string_endswith(PyStringObject *self, PyObject *args)
{
Py_ssize_t start = 0;
Py_ssize_t end = PY_SSIZE_T_MAX;
@@ -3308,7 +3308,7 @@ a UnicodeEncodeError. Other possible values are 'ignore', 'replace' and\n\
codecs.register_error that is able to handle UnicodeEncodeErrors.");
static PyObject *
-string_encode(PyBytesObject *self, PyObject *args)
+string_encode(PyStringObject *self, PyObject *args)
{
char *encoding = NULL;
char *errors = NULL;
@@ -3316,10 +3316,10 @@ string_encode(PyBytesObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "|ss:encode", &encoding, &errors))
return NULL;
- v = PyBytes_AsEncodedObject((PyObject *)self, encoding, errors);
+ v = PyString_AsEncodedObject((PyObject *)self, encoding, errors);
if (v == NULL)
goto onError;
- if (!PyBytes_Check(v) && !PyUnicode_Check(v)) {
+ if (!PyString_Check(v) && !PyUnicode_Check(v)) {
PyErr_Format(PyExc_TypeError,
"encoder did not return a string/unicode object "
"(type=%.400s)",
@@ -3345,7 +3345,7 @@ as well as any other name registerd with codecs.register_error that is\n\
able to handle UnicodeDecodeErrors.");
static PyObject *
-string_decode(PyBytesObject *self, PyObject *args)
+string_decode(PyStringObject *self, PyObject *args)
{
char *encoding = NULL;
char *errors = NULL;
@@ -3353,10 +3353,10 @@ string_decode(PyBytesObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "|ss:decode", &encoding, &errors))
return NULL;
- v = PyBytes_AsDecodedObject((PyObject *)self, encoding, errors);
+ v = PyString_AsDecodedObject((PyObject *)self, encoding, errors);
if (v == NULL)
goto onError;
- if (!PyBytes_Check(v) && !PyUnicode_Check(v)) {
+ if (!PyString_Check(v) && !PyUnicode_Check(v)) {
PyErr_Format(PyExc_TypeError,
"decoder did not return a string/unicode object "
"(type=%.400s)",
@@ -3378,7 +3378,7 @@ Return a copy of S where all tab characters are expanded using spaces.\n\
If tabsize is not given, a tab size of 8 characters is assumed.");
static PyObject*
-string_expandtabs(PyBytesObject *self, PyObject *args)
+string_expandtabs(PyStringObject *self, PyObject *args)
{
const char *e, *p, *qe;
char *q;
@@ -3392,8 +3392,8 @@ string_expandtabs(PyBytesObject *self, PyObject *args)
/* First pass: determine size of output string */
i = 0; /* chars up to and including most recent \n or \r */
j = 0; /* chars since most recent \n or \r (use in tab calculations) */
- e = PyBytes_AS_STRING(self) + PyBytes_GET_SIZE(self); /* end of input */
- for (p = PyBytes_AS_STRING(self); p < e; p++)
+ e = PyString_AS_STRING(self) + PyString_GET_SIZE(self); /* end of input */
+ for (p = PyString_AS_STRING(self); p < e; p++)
if (*p == '\t') {
if (tabsize > 0) {
incr = tabsize - (j % tabsize);
@@ -3418,15 +3418,15 @@ string_expandtabs(PyBytesObject *self, PyObject *args)
goto overflow1;
/* Second pass: create output string and fill it */
- u = PyBytes_FromStringAndSize(NULL, i + j);
+ u = PyString_FromStringAndSize(NULL, i + j);
if (!u)
return NULL;
j = 0; /* same as in first pass */
- q = PyBytes_AS_STRING(u); /* next output char */
- qe = PyBytes_AS_STRING(u) + PyBytes_GET_SIZE(u); /* end of output */
+ q = PyString_AS_STRING(u); /* next output char */
+ qe = PyString_AS_STRING(u) + PyString_GET_SIZE(u); /* end of output */
- for (p = PyBytes_AS_STRING(self); p < e; p++)
+ for (p = PyString_AS_STRING(self); p < e; p++)
if (*p == '\t') {
if (tabsize > 0) {
i = tabsize - (j % tabsize);
@@ -3457,7 +3457,7 @@ string_expandtabs(PyBytesObject *self, PyObject *args)
}
Py_LOCAL_INLINE(PyObject *)
-pad(PyBytesObject *self, Py_ssize_t left, Py_ssize_t right, char fill)
+pad(PyStringObject *self, Py_ssize_t left, Py_ssize_t right, char fill)
{
PyObject *u;
@@ -3466,21 +3466,21 @@ pad(PyBytesObject *self, Py_ssize_t left, Py_ssize_t right, char fill)
if (right < 0)
right = 0;
- if (left == 0 && right == 0 && PyBytes_CheckExact(self)) {
+ if (left == 0 && right == 0 && PyString_CheckExact(self)) {
Py_INCREF(self);
return (PyObject *)self;
}
- u = PyBytes_FromStringAndSize(NULL,
- left + PyBytes_GET_SIZE(self) + right);
+ u = PyString_FromStringAndSize(NULL,
+ left + PyString_GET_SIZE(self) + right);
if (u) {
if (left)
- memset(PyBytes_AS_STRING(u), fill, left);
- Py_MEMCPY(PyBytes_AS_STRING(u) + left,
- PyBytes_AS_STRING(self),
- PyBytes_GET_SIZE(self));
+ memset(PyString_AS_STRING(u), fill, left);
+ Py_MEMCPY(PyString_AS_STRING(u) + left,
+ PyString_AS_STRING(self),
+ PyString_GET_SIZE(self));
if (right)
- memset(PyBytes_AS_STRING(u) + left + PyBytes_GET_SIZE(self),
+ memset(PyString_AS_STRING(u) + left + PyString_GET_SIZE(self),
fill, right);
}
@@ -3494,7 +3494,7 @@ PyDoc_STRVAR(ljust__doc__,
"done using the specified fill character (default is a space).");
static PyObject *
-string_ljust(PyBytesObject *self, PyObject *args)
+string_ljust(PyStringObject *self, PyObject *args)
{
Py_ssize_t width;
char fillchar = ' ';
@@ -3502,12 +3502,12 @@ string_ljust(PyBytesObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "n|c:ljust", &width, &fillchar))
return NULL;
- if (PyBytes_GET_SIZE(self) >= width && PyBytes_CheckExact(self)) {
+ if (PyString_GET_SIZE(self) >= width && PyString_CheckExact(self)) {
Py_INCREF(self);
return (PyObject*) self;
}
- return pad(self, 0, width - PyBytes_GET_SIZE(self), fillchar);
+ return pad(self, 0, width - PyString_GET_SIZE(self), fillchar);
}
@@ -3518,7 +3518,7 @@ PyDoc_STRVAR(rjust__doc__,
"done using the specified fill character (default is a space)");
static PyObject *
-string_rjust(PyBytesObject *self, PyObject *args)
+string_rjust(PyStringObject *self, PyObject *args)
{
Py_ssize_t width;
char fillchar = ' ';
@@ -3526,12 +3526,12 @@ string_rjust(PyBytesObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "n|c:rjust", &width, &fillchar))
return NULL;
- if (PyBytes_GET_SIZE(self) >= width && PyBytes_CheckExact(self)) {
+ if (PyString_GET_SIZE(self) >= width && PyString_CheckExact(self)) {
Py_INCREF(self);
return (PyObject*) self;
}
- return pad(self, width - PyBytes_GET_SIZE(self), 0, fillchar);
+ return pad(self, width - PyString_GET_SIZE(self), 0, fillchar);
}
@@ -3542,7 +3542,7 @@ PyDoc_STRVAR(center__doc__,
"done using the specified fill character (default is a space)");
static PyObject *
-string_center(PyBytesObject *self, PyObject *args)
+string_center(PyStringObject *self, PyObject *args)
{
Py_ssize_t marg, left;
Py_ssize_t width;
@@ -3551,12 +3551,12 @@ string_center(PyBytesObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "n|c:center", &width, &fillchar))
return NULL;
- if (PyBytes_GET_SIZE(self) >= width && PyBytes_CheckExact(self)) {
+ if (PyString_GET_SIZE(self) >= width && PyString_CheckExact(self)) {
Py_INCREF(self);
return (PyObject*) self;
}
- marg = width - PyBytes_GET_SIZE(self);
+ marg = width - PyString_GET_SIZE(self);
left = marg / 2 + (marg & width & 1);
return pad(self, left, marg - left, fillchar);
@@ -3569,7 +3569,7 @@ PyDoc_STRVAR(zfill__doc__,
"of the specified width. The string S is never truncated.");
static PyObject *
-string_zfill(PyBytesObject *self, PyObject *args)
+string_zfill(PyStringObject *self, PyObject *args)
{
Py_ssize_t fill;
PyObject *s;
@@ -3579,26 +3579,26 @@ string_zfill(PyBytesObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "n:zfill", &width))
return NULL;
- if (PyBytes_GET_SIZE(self) >= width) {
- if (PyBytes_CheckExact(self)) {
+ if (PyString_GET_SIZE(self) >= width) {
+ if (PyString_CheckExact(self)) {
Py_INCREF(self);
return (PyObject*) self;
}
else
- return PyBytes_FromStringAndSize(
- PyBytes_AS_STRING(self),
- PyBytes_GET_SIZE(self)
+ return PyString_FromStringAndSize(
+ PyString_AS_STRING(self),
+ PyString_GET_SIZE(self)
);
}
- fill = width - PyBytes_GET_SIZE(self);
+ fill = width - PyString_GET_SIZE(self);
s = pad(self, fill, 0, '0');
if (s == NULL)
return NULL;
- p = PyBytes_AS_STRING(s);
+ p = PyString_AS_STRING(s);
if (p[fill] == '+' || p[fill] == '-') {
/* move sign to beginning of string */
p[0] = p[fill];
@@ -3615,22 +3615,22 @@ Return True if all characters in S are whitespace\n\
and there is at least one character in S, False otherwise.");
static PyObject*
-string_isspace(PyBytesObject *self)
+string_isspace(PyStringObject *self)
{
register const unsigned char *p
- = (unsigned char *) PyBytes_AS_STRING(self);
+ = (unsigned char *) PyString_AS_STRING(self);
register const unsigned char *e;
/* Shortcut for single character strings */
- if (PyBytes_GET_SIZE(self) == 1 &&
+ if (PyString_GET_SIZE(self) == 1 &&
isspace(*p))
return PyBool_FromLong(1);
/* Special case for empty strings */
- if (PyBytes_GET_SIZE(self) == 0)
+ if (PyString_GET_SIZE(self) == 0)
return PyBool_FromLong(0);
- e = p + PyBytes_GET_SIZE(self);
+ e = p + PyString_GET_SIZE(self);
for (; p < e; p++) {
if (!isspace(*p))
return PyBool_FromLong(0);
@@ -3646,22 +3646,22 @@ Return True if all characters in S are alphabetic\n\
and there is at least one character in S, False otherwise.");
static PyObject*
-string_isalpha(PyBytesObject *self)
+string_isalpha(PyStringObject *self)
{
register const unsigned char *p
- = (unsigned char *) PyBytes_AS_STRING(self);
+ = (unsigned char *) PyString_AS_STRING(self);
register const unsigned char *e;
/* Shortcut for single character strings */
- if (PyBytes_GET_SIZE(self) == 1 &&
+ if (PyString_GET_SIZE(self) == 1 &&
isalpha(*p))
return PyBool_FromLong(1);
/* Special case for empty strings */
- if (PyBytes_GET_SIZE(self) == 0)
+ if (PyString_GET_SIZE(self) == 0)
return PyBool_FromLong(0);
- e = p + PyBytes_GET_SIZE(self);
+ e = p + PyString_GET_SIZE(self);
for (; p < e; p++) {
if (!isalpha(*p))
return PyBool_FromLong(0);
@@ -3677,22 +3677,22 @@ Return True if all characters in S are alphanumeric\n\
and there is at least one character in S, False otherwise.");
static PyObject*
-string_isalnum(PyBytesObject *self)
+string_isalnum(PyStringObject *self)
{
register const unsigned char *p
- = (unsigned char *) PyBytes_AS_STRING(self);
+ = (unsigned char *) PyString_AS_STRING(self);
register const unsigned char *e;
/* Shortcut for single character strings */
- if (PyBytes_GET_SIZE(self) == 1 &&
+ if (PyString_GET_SIZE(self) == 1 &&
isalnum(*p))
return PyBool_FromLong(1);
/* Special case for empty strings */
- if (PyBytes_GET_SIZE(self) == 0)
+ if (PyString_GET_SIZE(self) == 0)
return PyBool_FromLong(0);
- e = p + PyBytes_GET_SIZE(self);
+ e = p + PyString_GET_SIZE(self);
for (; p < e; p++) {
if (!isalnum(*p))
return PyBool_FromLong(0);
@@ -3708,22 +3708,22 @@ Return True if all characters in S are digits\n\
and there is at least one character in S, False otherwise.");
static PyObject*
-string_isdigit(PyBytesObject *self)
+string_isdigit(PyStringObject *self)
{
register const unsigned char *p
- = (unsigned char *) PyBytes_AS_STRING(self);
+ = (unsigned char *) PyString_AS_STRING(self);
register const unsigned char *e;
/* Shortcut for single character strings */
- if (PyBytes_GET_SIZE(self) == 1 &&
+ if (PyString_GET_SIZE(self) == 1 &&
isdigit(*p))
return PyBool_FromLong(1);
/* Special case for empty strings */
- if (PyBytes_GET_SIZE(self) == 0)
+ if (PyString_GET_SIZE(self) == 0)
return PyBool_FromLong(0);
- e = p + PyBytes_GET_SIZE(self);
+ e = p + PyString_GET_SIZE(self);
for (; p < e; p++) {
if (!isdigit(*p))
return PyBool_FromLong(0);
@@ -3739,22 +3739,22 @@ Return True if all cased characters in S are lowercase and there is\n\
at least one cased character in S, False otherwise.");
static PyObject*
-string_islower(PyBytesObject *self)
+string_islower(PyStringObject *self)
{
register const unsigned char *p
- = (unsigned char *) PyBytes_AS_STRING(self);
+ = (unsigned char *) PyString_AS_STRING(self);
register const unsigned char *e;
int cased;
/* Shortcut for single character strings */
- if (PyBytes_GET_SIZE(self) == 1)
+ if (PyString_GET_SIZE(self) == 1)
return PyBool_FromLong(islower(*p) != 0);
/* Special case for empty strings */
- if (PyBytes_GET_SIZE(self) == 0)
+ if (PyString_GET_SIZE(self) == 0)
return PyBool_FromLong(0);
- e = p + PyBytes_GET_SIZE(self);
+ e = p + PyString_GET_SIZE(self);
cased = 0;
for (; p < e; p++) {
if (isupper(*p))
@@ -3773,22 +3773,22 @@ Return True if all cased characters in S are uppercase and there is\n\
at least one cased character in S, False otherwise.");
static PyObject*
-string_isupper(PyBytesObject *self)
+string_isupper(PyStringObject *self)
{
register const unsigned char *p
- = (unsigned char *) PyBytes_AS_STRING(self);
+ = (unsigned char *) PyString_AS_STRING(self);
register const unsigned char *e;
int cased;
/* Shortcut for single character strings */
- if (PyBytes_GET_SIZE(self) == 1)
+ if (PyString_GET_SIZE(self) == 1)
return PyBool_FromLong(isupper(*p) != 0);
/* Special case for empty strings */
- if (PyBytes_GET_SIZE(self) == 0)
+ if (PyString_GET_SIZE(self) == 0)
return PyBool_FromLong(0);
- e = p + PyBytes_GET_SIZE(self);
+ e = p + PyString_GET_SIZE(self);
cased = 0;
for (; p < e; p++) {
if (islower(*p))
@@ -3809,22 +3809,22 @@ characters and lowercase characters only cased ones. Return False\n\
otherwise.");
static PyObject*
-string_istitle(PyBytesObject *self, PyObject *uncased)
+string_istitle(PyStringObject *self, PyObject *uncased)
{
register const unsigned char *p
- = (unsigned char *) PyBytes_AS_STRING(self);
+ = (unsigned char *) PyString_AS_STRING(self);
register const unsigned char *e;
int cased, previous_is_cased;
/* Shortcut for single character strings */
- if (PyBytes_GET_SIZE(self) == 1)
+ if (PyString_GET_SIZE(self) == 1)
return PyBool_FromLong(isupper(*p) != 0);
/* Special case for empty strings */
- if (PyBytes_GET_SIZE(self) == 0)
+ if (PyString_GET_SIZE(self) == 0)
return PyBool_FromLong(0);
- e = p + PyBytes_GET_SIZE(self);
+ e = p + PyString_GET_SIZE(self);
cased = 0;
previous_is_cased = 0;
for (; p < e; p++) {
@@ -3857,7 +3857,7 @@ Line breaks are not included in the resulting list unless keepends\n\
is given and true.");
static PyObject*
-string_splitlines(PyBytesObject *self, PyObject *args)
+string_splitlines(PyStringObject *self, PyObject *args)
{
register Py_ssize_t i;
register Py_ssize_t j;
@@ -3870,8 +3870,8 @@ string_splitlines(PyBytesObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "|i:splitlines", &keepends))
return NULL;
- data = PyBytes_AS_STRING(self);
- len = PyBytes_GET_SIZE(self);
+ data = PyString_AS_STRING(self);
+ len = PyString_GET_SIZE(self);
/* This does not use the preallocated list because splitlines is
usually run with hundreds of newlines. The overhead of
@@ -3921,10 +3921,10 @@ PyDoc_STRVAR(sizeof__doc__,
"S.__sizeof__() -> size of S in memory, in bytes");
static PyObject *
-string_sizeof(PyBytesObject *v)
+string_sizeof(PyStringObject *v)
{
Py_ssize_t res;
- res = sizeof(PyBytesObject) + v->ob_size * v->ob_type->tp_itemsize;
+ res = sizeof(PyStringObject) + v->ob_size * v->ob_type->tp_itemsize;
return PyInt_FromSsize_t(res);
}
@@ -3934,7 +3934,7 @@ string_sizeof(PyBytesObject *v)
#undef PREALLOC_SIZE
static PyObject *
-string_getnewargs(PyBytesObject *v)
+string_getnewargs(PyStringObject *v)
{
return Py_BuildValue("(s#)", v->ob_sval, Py_SIZE(v));
}
@@ -3958,7 +3958,7 @@ string__format__(PyObject* self, PyObject* args)
/* This is to allow things like u''.format('') */
if (!PyArg_ParseTuple(args, "O:__format__", &format_spec))
goto done;
- if (!(PyBytes_Check(format_spec) || PyUnicode_Check(format_spec))) {
+ if (!(PyString_Check(format_spec) || PyUnicode_Check(format_spec))) {
PyErr_Format(PyExc_TypeError, "__format__ arg must be str "
"or unicode, not %s", Py_TYPE(format_spec)->tp_name);
goto done;
@@ -3969,8 +3969,8 @@ string__format__(PyObject* self, PyObject* args)
format_spec = tmp;
result = _PyBytes_FormatAdvanced(self,
- PyBytes_AS_STRING(format_spec),
- PyBytes_GET_SIZE(format_spec));
+ PyString_AS_STRING(format_spec),
+ PyString_GET_SIZE(format_spec));
done:
Py_XDECREF(tmp);
return result;
@@ -4050,12 +4050,12 @@ string_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
PyObject *x = NULL;
static char *kwlist[] = {"object", 0};
- if (type != &PyBytes_Type)
+ if (type != &PyString_Type)
return str_subtype_new(type, args, kwds);
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O:str", kwlist, &x))
return NULL;
if (x == NULL)
- return PyBytes_FromString("");
+ return PyString_FromString("");
return PyObject_Str(x);
}
@@ -4065,18 +4065,18 @@ str_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
PyObject *tmp, *pnew;
Py_ssize_t n;
- assert(PyType_IsSubtype(type, &PyBytes_Type));
- tmp = string_new(&PyBytes_Type, args, kwds);
+ assert(PyType_IsSubtype(type, &PyString_Type));
+ tmp = string_new(&PyString_Type, args, kwds);
if (tmp == NULL)
return NULL;
- assert(PyBytes_CheckExact(tmp));
- n = PyBytes_GET_SIZE(tmp);
+ assert(PyString_CheckExact(tmp));
+ n = PyString_GET_SIZE(tmp);
pnew = type->tp_alloc(type, n);
if (pnew != NULL) {
- Py_MEMCPY(PyBytes_AS_STRING(pnew), PyBytes_AS_STRING(tmp), n+1);
- ((PyBytesObject *)pnew)->ob_shash =
- ((PyBytesObject *)tmp)->ob_shash;
- ((PyBytesObject *)pnew)->ob_sstate = SSTATE_NOT_INTERNED;
+ Py_MEMCPY(PyString_AS_STRING(pnew), PyString_AS_STRING(tmp), n+1);
+ ((PyStringObject *)pnew)->ob_shash =
+ ((PyStringObject *)tmp)->ob_shash;
+ ((PyStringObject *)pnew)->ob_sstate = SSTATE_NOT_INTERNED;
}
Py_DECREF(tmp);
return pnew;
@@ -4093,11 +4093,11 @@ basestring_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
static PyObject *
string_mod(PyObject *v, PyObject *w)
{
- if (!PyBytes_Check(v)) {
+ if (!PyString_Check(v)) {
Py_INCREF(Py_NotImplemented);
return Py_NotImplemented;
}
- return PyBytes_Format(v, w);
+ return PyString_Format(v, w);
}
PyDoc_STRVAR(basestring_doc,
@@ -4160,10 +4160,10 @@ PyDoc_STRVAR(string_doc,
Return a nice string representation of the object.\n\
If the argument is a string, the return value is the same object.");
-PyTypeObject PyBytes_Type = {
+PyTypeObject PyString_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
"str",
- sizeof(PyBytesObject),
+ sizeof(PyStringObject),
sizeof(char),
string_dealloc, /* tp_dealloc */
(printfunc)string_print, /* tp_print */
@@ -4205,25 +4205,25 @@ PyTypeObject PyBytes_Type = {
};
void
-PyBytes_Concat(register PyObject **pv, register PyObject *w)
+PyString_Concat(register PyObject **pv, register PyObject *w)
{
register PyObject *v;
if (*pv == NULL)
return;
- if (w == NULL || !PyBytes_Check(*pv)) {
+ if (w == NULL || !PyString_Check(*pv)) {
Py_DECREF(*pv);
*pv = NULL;
return;
}
- v = string_concat((PyBytesObject *) *pv, w);
+ v = string_concat((PyStringObject *) *pv, w);
Py_DECREF(*pv);
*pv = v;
}
void
-PyBytes_ConcatAndDel(register PyObject **pv, register PyObject *w)
+PyString_ConcatAndDel(register PyObject **pv, register PyObject *w)
{
- PyBytes_Concat(pv, w);
+ PyString_Concat(pv, w);
Py_XDECREF(w);
}
@@ -4243,13 +4243,13 @@ PyBytes_ConcatAndDel(register PyObject **pv, register PyObject *w)
*/
int
-_PyBytes_Resize(PyObject **pv, Py_ssize_t newsize)
+_PyString_Resize(PyObject **pv, Py_ssize_t newsize)
{
register PyObject *v;
- register PyBytesObject *sv;
+ register PyStringObject *sv;
v = *pv;
- if (!PyBytes_Check(v) || Py_REFCNT(v) != 1 || newsize < 0 ||
- PyBytes_CHECK_INTERNED(v)) {
+ if (!PyString_Check(v) || Py_REFCNT(v) != 1 || newsize < 0 ||
+ PyString_CHECK_INTERNED(v)) {
*pv = 0;
Py_DECREF(v);
PyErr_BadInternalCall();
@@ -4259,14 +4259,14 @@ _PyBytes_Resize(PyObject **pv, Py_ssize_t newsize)
_Py_DEC_REFTOTAL;
_Py_ForgetReference(v);
*pv = (PyObject *)
- PyObject_REALLOC((char *)v, sizeof(PyBytesObject) + newsize);
+ PyObject_REALLOC((char *)v, sizeof(PyStringObject) + newsize);
if (*pv == NULL) {
PyObject_Del(v);
PyErr_NoMemory();
return -1;
}
_Py_NewReference(*pv);
- sv = (PyBytesObject *) *pv;
+ sv = (PyStringObject *) *pv;
Py_SIZE(sv) = newsize;
sv->ob_sval[newsize] = '\0';
sv->ob_shash = -1; /* invalidate cached hash value */
@@ -4352,7 +4352,7 @@ formatfloat(char *buf, size_t buflen, int flags,
return (int)strlen(buf);
}
-/* _PyBytes_FormatLong emulates the format codes d, u, o, x and X, and
+/* _PyString_FormatLong emulates the format codes d, u, o, x and X, and
* the F_ALT flag, for Python's long (unbounded) ints. It's not used for
* Python's regular ints.
* Return value: a new PyString*, or NULL if error.
@@ -4374,7 +4374,7 @@ formatfloat(char *buf, size_t buflen, int flags,
* produce a '-' sign, but can for Python's unbounded ints.
*/
PyObject*
-_PyBytes_FormatLong(PyObject *val, int flags, int prec, int type,
+_PyString_FormatLong(PyObject *val, int flags, int prec, int type,
char **pbuf, int *plen)
{
PyObject *result = NULL;
@@ -4405,7 +4405,7 @@ _PyBytes_FormatLong(PyObject *val, int flags, int prec, int type,
if (!result)
return NULL;
- buf = PyBytes_AsString(result);
+ buf = PyString_AsString(result);
if (!buf) {
Py_DECREF(result);
return NULL;
@@ -4416,9 +4416,9 @@ _PyBytes_FormatLong(PyObject *val, int flags, int prec, int type,
PyErr_BadInternalCall();
return NULL;
}
- llen = PyBytes_Size(result);
+ llen = PyString_Size(result);
if (llen > INT_MAX) {
- PyErr_SetString(PyExc_ValueError, "string too large in _PyBytes_FormatLong");
+ PyErr_SetString(PyExc_ValueError, "string too large in _PyString_FormatLong");
return NULL;
}
len = (int)llen;
@@ -4464,14 +4464,14 @@ _PyBytes_FormatLong(PyObject *val, int flags, int prec, int type,
/* Fill with leading zeroes to meet minimum width. */
if (prec > numdigits) {
- PyObject *r1 = PyBytes_FromStringAndSize(NULL,
+ PyObject *r1 = PyString_FromStringAndSize(NULL,
numnondigits + prec);
char *b1;
if (!r1) {
Py_DECREF(result);
return NULL;
}
- b1 = PyBytes_AS_STRING(r1);
+ b1 = PyString_AS_STRING(r1);
for (i = 0; i < numnondigits; ++i)
*b1++ = *buf++;
for (i = 0; i < prec - numdigits; i++)
@@ -4481,7 +4481,7 @@ _PyBytes_FormatLong(PyObject *val, int flags, int prec, int type,
*b1 = '\0';
Py_DECREF(result);
result = r1;
- buf = PyBytes_AS_STRING(result);
+ buf = PyString_AS_STRING(result);
len = numnondigits + prec;
}
@@ -4575,7 +4575,7 @@ Py_LOCAL_INLINE(int)
formatchar(char *buf, size_t buflen, PyObject *v)
{
/* presume that the buffer is at least 2 characters long */
- if (PyBytes_Check(v)) {
+ if (PyString_Check(v)) {
if (!PyArg_Parse(v, "c;%c requires int or char", &buf[0]))
return -1;
}
@@ -4598,7 +4598,7 @@ formatchar(char *buf, size_t buflen, PyObject *v)
#define FORMATBUFLEN (size_t)120
PyObject *
-PyBytes_Format(PyObject *format, PyObject *args)
+PyString_Format(PyObject *format, PyObject *args)
{
char *fmt, *res;
Py_ssize_t arglen, argidx;
@@ -4609,18 +4609,18 @@ PyBytes_Format(PyObject *format, PyObject *args)
PyObject *v, *w;
#endif
PyObject *dict = NULL;
- if (format == NULL || !PyBytes_Check(format) || args == NULL) {
+ if (format == NULL || !PyString_Check(format) || args == NULL) {
PyErr_BadInternalCall();
return NULL;
}
orig_args = args;
- fmt = PyBytes_AS_STRING(format);
- fmtcnt = PyBytes_GET_SIZE(format);
+ fmt = PyString_AS_STRING(format);
+ fmtcnt = PyString_GET_SIZE(format);
reslen = rescnt = fmtcnt + 100;
- result = PyBytes_FromStringAndSize((char *)NULL, reslen);
+ result = PyString_FromStringAndSize((char *)NULL, reslen);
if (result == NULL)
return NULL;
- res = PyBytes_AsString(result);
+ res = PyString_AsString(result);
if (PyTuple_Check(args)) {
arglen = PyTuple_GET_SIZE(args);
argidx = 0;
@@ -4637,9 +4637,9 @@ PyBytes_Format(PyObject *format, PyObject *args)
if (--rescnt < 0) {
rescnt = fmtcnt + 100;
reslen += rescnt;
- if (_PyBytes_Resize(&result, reslen) < 0)
+ if (_PyString_Resize(&result, reslen) < 0)
return NULL;
- res = PyBytes_AS_STRING(result)
+ res = PyString_AS_STRING(result)
+ reslen - rescnt;
--rescnt;
}
@@ -4694,7 +4694,7 @@ PyBytes_Format(PyObject *format, PyObject *args)
"incomplete format key");
goto error;
}
- key = PyBytes_FromStringAndSize(keystart,
+ key = PyString_FromStringAndSize(keystart,
keylen);
if (key == NULL)
goto error;
@@ -4835,14 +4835,14 @@ PyBytes_Format(PyObject *format, PyObject *args)
temp = PyObject_Repr(v);
if (temp == NULL)
goto error;
- if (!PyBytes_Check(temp)) {
+ if (!PyString_Check(temp)) {
PyErr_SetString(PyExc_TypeError,
"%s argument has non-string str()");
Py_DECREF(temp);
goto error;
}
- pbuf = PyBytes_AS_STRING(temp);
- len = PyBytes_GET_SIZE(temp);
+ pbuf = PyString_AS_STRING(temp);
+ len = PyString_GET_SIZE(temp);
if (prec >= 0 && len > prec)
len = prec;
break;
@@ -4882,7 +4882,7 @@ PyBytes_Format(PyObject *format, PyObject *args)
int ilen;
isnumok = 1;
- temp = _PyBytes_FormatLong(iobj, flags,
+ temp = _PyString_FormatLong(iobj, flags,
prec, c, &pbuf, &ilen);
Py_DECREF(iobj);
len = ilen;
@@ -4940,7 +4940,7 @@ PyBytes_Format(PyObject *format, PyObject *args)
"at index %zd",
c, c,
(Py_ssize_t)(fmt - 1 -
- PyBytes_AsString(format)));
+ PyString_AsString(format)));
goto error;
}
if (sign) {
@@ -4966,11 +4966,11 @@ PyBytes_Format(PyObject *format, PyObject *args)
Py_XDECREF(temp);
return PyErr_NoMemory();
}
- if (_PyBytes_Resize(&result, reslen) < 0) {
+ if (_PyString_Resize(&result, reslen) < 0) {
Py_XDECREF(temp);
return NULL;
}
- res = PyBytes_AS_STRING(result)
+ res = PyString_AS_STRING(result)
+ reslen - rescnt;
}
if (sign) {
@@ -5034,7 +5034,7 @@ PyBytes_Format(PyObject *format, PyObject *args)
if (args_owned) {
Py_DECREF(args);
}
- _PyBytes_Resize(&result, reslen - rescnt);
+ _PyString_Resize(&result, reslen - rescnt);
return result;
#ifdef Py_USING_UNICODE
@@ -5063,11 +5063,11 @@ PyBytes_Format(PyObject *format, PyObject *args)
args_owned = 1;
/* Take what we have of the result and let the Unicode formatting
function format the rest of the input. */
- rescnt = res - PyBytes_AS_STRING(result);
- if (_PyBytes_Resize(&result, rescnt))
+ rescnt = res - PyString_AS_STRING(result);
+ if (_PyString_Resize(&result, rescnt))
goto error;
- fmtcnt = PyBytes_GET_SIZE(format) - \
- (fmt - PyBytes_AS_STRING(format));
+ fmtcnt = PyString_GET_SIZE(format) - \
+ (fmt - PyString_AS_STRING(format));
format = PyUnicode_Decode(fmt, fmtcnt, NULL, NULL);
if (format == NULL)
goto error;
@@ -5095,15 +5095,15 @@ PyBytes_Format(PyObject *format, PyObject *args)
void
PyString_InternInPlace(PyObject **p)
{
- register PyBytesObject *s = (PyBytesObject *)(*p);
+ register PyStringObject *s = (PyStringObject *)(*p);
PyObject *t;
- if (s == NULL || !PyBytes_Check(s))
+ if (s == NULL || !PyString_Check(s))
Py_FatalError("PyString_InternInPlace: strings only please!");
/* If it's a string subclass, we don't really know what putting
it in the interned dict might do. */
- if (!PyBytes_CheckExact(s))
+ if (!PyString_CheckExact(s))
return;
- if (PyBytes_CHECK_INTERNED(s))
+ if (PyString_CHECK_INTERNED(s))
return;
if (interned == NULL) {
interned = PyDict_New();
@@ -5127,15 +5127,15 @@ PyString_InternInPlace(PyObject **p)
/* The two references in interned are not counted by refcnt.
The string deallocator will take care of this */
Py_REFCNT(s) -= 2;
- PyBytes_CHECK_INTERNED(s) = SSTATE_INTERNED_MORTAL;
+ PyString_CHECK_INTERNED(s) = SSTATE_INTERNED_MORTAL;
}
void
PyString_InternImmortal(PyObject **p)
{
PyString_InternInPlace(p);
- if (PyBytes_CHECK_INTERNED(*p) != SSTATE_INTERNED_IMMORTAL) {
- PyBytes_CHECK_INTERNED(*p) = SSTATE_INTERNED_IMMORTAL;
+ if (PyString_CHECK_INTERNED(*p) != SSTATE_INTERNED_IMMORTAL) {
+ PyString_CHECK_INTERNED(*p) = SSTATE_INTERNED_IMMORTAL;
Py_INCREF(*p);
}
}
@@ -5144,7 +5144,7 @@ PyString_InternImmortal(PyObject **p)
PyObject *
PyString_InternFromString(const char *cp)
{
- PyObject *s = PyBytes_FromString(cp);
+ PyObject *s = PyString_FromString(cp);
if (s == NULL)
return NULL;
PyString_InternInPlace(&s);
@@ -5166,7 +5166,7 @@ PyString_Fini(void)
void _Py_ReleaseInternedStrings(void)
{
PyObject *keys;
- PyBytesObject *s;
+ PyStringObject *s;
Py_ssize_t i, n;
Py_ssize_t immortal_size = 0, mortal_size = 0;
@@ -5187,7 +5187,7 @@ void _Py_ReleaseInternedStrings(void)
fprintf(stderr, "releasing %" PY_FORMAT_SIZE_T "d interned strings\n",
n);
for (i = 0; i < n; i++) {
- s = (PyBytesObject *) PyList_GET_ITEM(keys, i);
+ s = (PyStringObject *) PyList_GET_ITEM(keys, i);
switch (s->ob_sstate) {
case SSTATE_NOT_INTERNED:
/* XXX Shouldn't happen */
diff --git a/Objects/fileobject.c b/Objects/fileobject.c
index 8cc829b..7c49aff 100644
--- a/Objects/fileobject.c
+++ b/Objects/fileobject.c
@@ -453,7 +453,7 @@ PyFile_SetEncodingAndErrors(PyObject *f, const char *enc, char* errors)
PyObject *str, *oerrors;
assert(PyFile_Check(f));
- str = PyBytes_FromString(enc);
+ str = PyString_FromString(enc);
if (!str)
return 0;
if (errors) {
@@ -2321,9 +2321,9 @@ PyFile_WriteObject(PyObject *v, PyObject *f, int flags)
#ifdef Py_USING_UNICODE
if ((flags & Py_PRINT_RAW) &&
PyUnicode_Check(v) && enc != Py_None) {
- char *cenc = PyBytes_AS_STRING(enc);
+ char *cenc = PyString_AS_STRING(enc);
char *errors = fobj->f_errors == Py_None ?
- "strict" : PyBytes_AS_STRING(fobj->f_errors);
+ "strict" : PyString_AS_STRING(fobj->f_errors);
value = PyUnicode_AsEncodedString(v, cenc, errors);
if (value == NULL)
return -1;